]>
git.proxmox.com Git - qemu-server.git/blob - PVE/QemuServer.pm
1 package PVE
:: QemuServer
;
20 use Storable
qw(dclone) ;
21 use PVE
:: Exception
qw(raise raise_param_exc) ;
23 use PVE
:: Tools
qw(run_command lock_file file_read_firstline) ;
24 use PVE
:: Cluster
qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file) ;
27 use Time
:: HiRes
qw(gettimeofday) ;
29 my $cpuinfo = PVE
:: ProcFSTools
:: read_cpuinfo
();
31 # Note about locking: we use flock on the config file protect
32 # against concurent actions.
33 # Aditionaly, we have a 'lock' setting in the config file. This
34 # can be set to 'migrate' or 'backup'. Most actions are not
35 # allowed when such lock is set. But you can ignore this kind of
36 # lock with the --skiplock flag.
38 cfs_register_file
( '/qemu-server/' ,
42 PVE
:: JSONSchema
:: register_standard_option
( 'skiplock' , {
43 description
=> "Ignore locks - only root is allowed to use this option." ,
48 PVE
:: JSONSchema
:: register_standard_option
( 'pve-qm-stateuri' , {
49 description
=> "Some command save/restore state from this location." ,
55 #no warnings 'redefine';
57 unless ( defined (& _VZSYSCALLS_H_
)) {
58 eval 'sub _VZSYSCALLS_H_ () {1;}' unless defined (& _VZSYSCALLS_H_
);
59 require 'sys/syscall.ph' ;
60 if ( defined (& __x86_64__
)) {
61 eval 'sub __NR_fairsched_vcpus () {499;}' unless defined (& __NR_fairsched_vcpus
);
62 eval 'sub __NR_fairsched_mknod () {504;}' unless defined (& __NR_fairsched_mknod
);
63 eval 'sub __NR_fairsched_rmnod () {505;}' unless defined (& __NR_fairsched_rmnod
);
64 eval 'sub __NR_fairsched_chwt () {506;}' unless defined (& __NR_fairsched_chwt
);
65 eval 'sub __NR_fairsched_mvpr () {507;}' unless defined (& __NR_fairsched_mvpr
);
66 eval 'sub __NR_fairsched_rate () {508;}' unless defined (& __NR_fairsched_rate
);
67 eval 'sub __NR_setluid () {501;}' unless defined (& __NR_setluid
);
68 eval 'sub __NR_setublimit () {502;}' unless defined (& __NR_setublimit
);
70 elsif ( defined ( & __i386__
) ) {
71 eval 'sub __NR_fairsched_mknod () {500;}' unless defined (& __NR_fairsched_mknod
);
72 eval 'sub __NR_fairsched_rmnod () {501;}' unless defined (& __NR_fairsched_rmnod
);
73 eval 'sub __NR_fairsched_chwt () {502;}' unless defined (& __NR_fairsched_chwt
);
74 eval 'sub __NR_fairsched_mvpr () {503;}' unless defined (& __NR_fairsched_mvpr
);
75 eval 'sub __NR_fairsched_rate () {504;}' unless defined (& __NR_fairsched_rate
);
76 eval 'sub __NR_fairsched_vcpus () {505;}' unless defined (& __NR_fairsched_vcpus
);
77 eval 'sub __NR_setluid () {511;}' unless defined (& __NR_setluid
);
78 eval 'sub __NR_setublimit () {512;}' unless defined (& __NR_setublimit
);
80 die ( "no fairsched syscall for this arch" );
82 require 'asm/ioctl.ph' ;
83 eval 'sub KVM_GET_API_VERSION () { &_IO(0xAE, 0x);}' unless defined (& KVM_GET_API_VERSION
);
87 my ( $parent, $weight, $desired ) = @_ ;
89 return syscall (& __NR_fairsched_mknod
, int ( $parent ), int ( $weight ), int ( $desired ));
95 return syscall (& __NR_fairsched_rmnod
, int ( $id ));
99 my ( $pid, $newid ) = @_ ;
101 return syscall (& __NR_fairsched_mvpr
, int ( $pid ), int ( $newid ));
104 sub fairsched_vcpus
{
105 my ( $id, $vcpus ) = @_ ;
107 return syscall (& __NR_fairsched_vcpus
, int ( $id ), int ( $vcpus ));
111 my ( $id, $op, $rate ) = @_ ;
113 return syscall (& __NR_fairsched_rate
, int ( $id ), int ( $op ), int ( $rate ));
116 use constant FAIRSCHED_SET_RATE
=> 0 ;
117 use constant FAIRSCHED_DROP_RATE
=> 1 ;
118 use constant FAIRSCHED_GET_RATE
=> 2 ;
120 sub fairsched_cpulimit
{
121 my ( $id, $limit ) = @_ ;
123 my $cpulim1024 = int ( $limit * 1024 / 100 );
124 my $op = $cpulim1024 ? FAIRSCHED_SET_RATE
: FAIRSCHED_DROP_RATE
;
126 return fairsched_rate
( $id, $op, $cpulim1024 );
129 my $nodename = PVE
:: INotify
:: nodename
();
131 mkdir "/etc/pve/nodes/ $nodename " ;
132 my $confdir = "/etc/pve/nodes/ $nodename/qemu -server" ;
135 my $var_run_tmpdir = "/var/run/qemu-server" ;
136 mkdir $var_run_tmpdir ;
138 my $lock_dir = "/var/lock/qemu-server" ;
141 my $pcisysfs = "/sys/bus/pci" ;
147 description
=> "Specifies whether a VM will be started during system bootup." ,
153 description
=> "Automatic restart after crash (currently ignored)." ,
159 description
=> "Activate hotplug for disk and network device" ,
165 description
=> "Allow reboot. If set to '0' the VM exit on reboot." ,
171 description
=> "Lock/unlock the VM." ,
172 enum
=> [ qw(migrate backup) ],
177 description
=> "Limit of CPU usage in per cent. Note if the computer has 2 CPUs, it has total of 200% CPU time. Value '0' indicates no CPU limit. \n\n NOTE: This option is currently ignored." ,
184 description
=> "CPU weight for a VM. Argument is used in the kernel fair scheduler. The larger the number is, the more CPU time this VM gets. Number is relative to weights of all the other running VMs. \n\n NOTE: You can disable fair-scheduler configuration by setting this to 0." ,
192 description
=> "Amount of RAM for the VM in MB. This is the maximum available memory when you use the balloon device." ,
199 description
=> "Amount of target RAM for the VM in MB." ,
205 description
=> "Keybord layout for vnc server. Default is read from the datacenter configuration file." ,
206 enum
=> PVE
:: Tools
:: kvmkeymaplist
(),
212 description
=> "Set a name for the VM. Only used on the configuration web interface." ,
217 description
=> "Description for the VM. Only used on the configuration web interface." ,
222 enum
=> [ qw(other wxp w2k w2k3 w2k8 wvista win7 l24 l26) ],
223 description
=> <<EODESC,
224 Used to enable special optimization/features for specific
227 other => unspecified OS
228 wxp => Microsoft Windows XP
229 w2k => Microsoft Windows 2000
230 w2k3 => Microsoft Windows 2003
231 w2k8 => Microsoft Windows 2008
232 wvista => Microsoft Windows Vista
233 win7 => Microsoft Windows 7
234 l24 => Linux 2.4 Kernel
235 l26 => Linux 2.6/3.X Kernel
237 other|l24|l26 ... no special behaviour
238 wxp|w2k|w2k3|w2k8|wvista|win7 ... use --localtime switch
244 description
=> "Boot on floppy (a), hard disk (c), CD-ROM (d), or network (n)." ,
245 pattern
=> '[acdn]{1,4}' ,
250 type
=> 'string' , format
=> 'pve-qm-bootdisk' ,
251 description
=> "Enable booting from specified disk." ,
252 pattern
=> '(ide|scsi|virtio)\d+' ,
257 description
=> "The number of CPUs. Please use option -sockets instead." ,
264 description
=> "The number of CPU sockets." ,
271 description
=> "The number of cores per socket." ,
278 description
=> "Enable/disable ACPI." ,
284 description
=> "Enable/disable KVM hardware virtualization." ,
290 description
=> "Enable/disable time drift fix." ,
296 description
=> "Set the real time clock to local time. This is enabled by default if ostype indicates a Microsoft OS." ,
301 description
=> "Freeze CPU at startup (use 'c' monitor command to start execution)." ,
306 description
=> "Select VGA type. If you want to use high resolution modes (>= 1280x1024x16) then you should use option 'std' or 'vmware'. Default is 'std' for win7/w2k8, and 'cirrur' for other OS types" ,
307 enum
=> [ qw(std cirrus vmware) ],
311 type
=> 'string' , format
=> 'pve-qm-watchdog' ,
312 typetext
=> '[[model=]i6300esb|ib700] [,[action=]reset|shutdown|poweroff|pause|debug|none]' ,
313 description
=> "Create a virtual hardware watchdog device. Once enabled (by a guest action), the watchdog must be periodically polled by an agent inside the guest or else the guest will be restarted (or execute the action specified)" ,
318 typetext
=> "(now | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS)" ,
319 description
=> "Set the initial date of the real time clock. Valid format for date are: 'now' or '2006-06-17T16:01:21' or '2006-06-17'." ,
320 pattern
=> '(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)' ,
326 description
=> <<EODESCR,
327 Note: this option is for experts only. It allows you to pass arbitrary arguments to kvm, for example:
329 args: -no-reboot -no-hpet
336 description
=> "Enable/disable the usb tablet device. This device is usually needed to allow absolute mouse positioning. Else the mouse runs out of sync with normal vnc clients. If you're running lots of console-only guests on one host, you may consider disabling this to save some context switches." ,
341 description
=> "Set maximum speed (in MB/s) for migrations. Value 0 is no limit." ,
345 migrate_downtime
=> {
348 description
=> "Set maximum tolerated downtime (in seconds) for migrations." ,
354 type
=> 'string' , format
=> 'pve-qm-drive' ,
355 typetext
=> 'volume' ,
356 description
=> "This is an alias for option -ide2" ,
360 description
=> "Emulated CPU type." ,
362 enum
=> [ qw(486 athlon pentium pentium2 pentium3 coreduo core2duo kvm32 kvm64 qemu32 qemu64 phenom host) ],
367 # what about other qemu settings ?
369 #machine => 'string',
382 ##soundhw => 'string',
384 while ( my ( $k, $v ) = each %$confdesc ) {
385 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm- $k " , $v );
388 my $MAX_IDE_DISKS = 4 ;
389 my $MAX_SCSI_DISKS = 14 ;
390 my $MAX_VIRTIO_DISKS = 6 ;
391 my $MAX_SATA_DISKS = 6 ;
392 my $MAX_USB_DEVICES = 5 ;
394 my $MAX_UNUSED_DISKS = 8 ;
395 my $MAX_HOSTPCI_DEVICES = 2 ;
396 my $MAX_SERIAL_PORTS = 4 ;
397 my $MAX_PARALLEL_PORTS = 3 ;
399 my $nic_model_list = [ 'rtl8139' , 'ne2k_pci' , 'e1000' , 'pcnet' , 'virtio' ,
400 'ne2k_isa' , 'i82551' , 'i82557b' , 'i82559er' ];
401 my $nic_model_list_txt = join ( ' ' , sort @$nic_model_list );
406 type
=> 'string' , format
=> 'pve-qm-net' ,
407 typetext
=> "MODEL=XX:XX:XX:XX:XX:XX [,bridge=<dev>][,rate=<mbps>]" ,
408 description
=> <<EODESCR,
409 Specify network devices.
411 MODEL is one of: $nic_model_list_txt
413 XX:XX:XX:XX:XX:XX should be an unique MAC address. This is
414 automatically generated if not specified.
416 The bridge parameter can be used to automatically add the interface to a bridge device. The Proxmox VE standard bridge is called 'vmbr0'.
418 Option 'rate' is used to limit traffic bandwidth from and to this interface. It is specified as floating point number, unit is 'Megabytes per second'.
420 If you specify no bridge, we create a kvm 'user' (NATed) network device, which provides DHCP and DNS services. The following addresses are used:
426 The DHCP server assign addresses to the guest starting from 10.0.2.15.
430 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-net" , $netdesc );
432 for ( my $i = 0 ; $i < $MAX_NETS ; $i++ ) {
433 $confdesc ->{ "net $i " } = $netdesc ;
440 type
=> 'string' , format
=> 'pve-qm-drive' ,
441 typetext
=> '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback|unsafe] [,format=f] [,backup=yes|no] [,aio=native|threads]' ,
442 description
=> "Use volume as IDE hard disk or CD-ROM (n is 0 to 3)." ,
444 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-ide" , $idedesc );
448 type
=> 'string' , format
=> 'pve-qm-drive' ,
449 typetext
=> '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback|unsafe] [,format=f] [,backup=yes|no] [,aio=native|threads]' ,
450 description
=> "Use volume as SCSI hard disk or CD-ROM (n is 0 to 13)." ,
452 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-scsi" , $scsidesc );
456 type
=> 'string' , format
=> 'pve-qm-drive' ,
457 typetext
=> '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback|unsafe] [,format=f] [,backup=yes|no] [,aio=native|threads]' ,
458 description
=> "Use volume as SATA hard disk or CD-ROM (n is 0 to 5)." ,
460 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-sata" , $satadesc );
464 type
=> 'string' , format
=> 'pve-qm-drive' ,
465 typetext
=> '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback|unsafe] [,format=f] [,backup=yes|no] [,aio=native|threads]' ,
466 description
=> "Use volume as VIRTIO hard disk (n is 0 to 5)." ,
468 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-virtio" , $virtiodesc );
472 type
=> 'string' , format
=> 'pve-qm-usb-device' ,
473 typetext
=> 'host=HOSTUSBDEVICE' ,
474 description
=> <<EODESCR,
475 Configure an USB device (n is 0 to 4). This can be used to
476 pass-through usb devices to the guest. HOSTUSBDEVICE syntax is:
478 'bus-port(.port)*' (decimal numbers) or
479 'vendor_id:product_id' (hexadeciaml numbers)
481 You can use the 'lsusb -t' command to list existing usb devices.
483 Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
487 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-usb" , $usbdesc );
491 type
=> 'string' , format
=> 'pve-qm-hostpci' ,
492 typetext
=> "HOSTPCIDEVICE" ,
493 description
=> <<EODESCR,
494 Map host pci devices. HOSTPCIDEVICE syntax is:
496 'bus:dev.func' (hexadecimal numbers)
498 You can us the 'lspci' command to list existing pci devices.
500 Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
502 Experimental: user reported problems with this option.
505 PVE
:: JSONSchema
:: register_standard_option
( "pve-qm-hostpci" , $hostpcidesc );
510 pattern
=> '/dev/ttyS\d+' ,
511 description
=> <<EODESCR,
512 Map host serial devices (n is 0 to 3).
514 Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
516 Experimental: user reported problems with this option.
523 pattern
=> '/dev/parport\d+' ,
524 description
=> <<EODESCR,
525 Map host parallel devices (n is 0 to 2).
527 Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
529 Experimental: user reported problems with this option.
533 for ( my $i = 0 ; $i < $MAX_PARALLEL_PORTS ; $i++ ) {
534 $confdesc ->{ "parallel $i " } = $paralleldesc ;
537 for ( my $i = 0 ; $i < $MAX_SERIAL_PORTS ; $i++ ) {
538 $confdesc ->{ "serial $i " } = $serialdesc ;
541 for ( my $i = 0 ; $i < $MAX_HOSTPCI_DEVICES ; $i++ ) {
542 $confdesc ->{ "hostpci $i " } = $hostpcidesc ;
545 for ( my $i = 0 ; $i < $MAX_IDE_DISKS ; $i++ ) {
546 $drivename_hash ->{ "ide $i " } = 1 ;
547 $confdesc ->{ "ide $i " } = $idedesc ;
550 for ( my $i = 0 ; $i < $MAX_SATA_DISKS ; $i++ ) {
551 $drivename_hash ->{ "sata $i " } = 1 ;
552 $confdesc ->{ "sata $i " } = $satadesc ;
555 for ( my $i = 0 ; $i < $MAX_SCSI_DISKS ; $i++ ) {
556 $drivename_hash ->{ "scsi $i " } = 1 ;
557 $confdesc ->{ "scsi $i " } = $scsidesc ;
560 for ( my $i = 0 ; $i < $MAX_VIRTIO_DISKS ; $i++ ) {
561 $drivename_hash ->{ "virtio $i " } = 1 ;
562 $confdesc ->{ "virtio $i " } = $virtiodesc ;
565 for ( my $i = 0 ; $i < $MAX_USB_DEVICES ; $i++ ) {
566 $confdesc ->{ "usb $i " } = $usbdesc ;
571 type
=> 'string' , format
=> 'pve-volume-id' ,
572 description
=> "Reference to unused volumes." ,
575 for ( my $i = 0 ; $i < $MAX_UNUSED_DISKS ; $i++ ) {
576 $confdesc ->{ "unused $i " } = $unuseddesc ;
579 my $kvm_api_version = 0 ;
583 return $kvm_api_version if $kvm_api_version ;
585 my $fh = IO
:: File-
> new ( "</dev/kvm" ) ||
588 if ( my $v = $fh -> ioctl ( KVM_GET_API_VERSION
(), 0 )) {
589 $kvm_api_version = $v ;
594 return $kvm_api_version ;
597 my $kvm_user_version ;
599 sub kvm_user_version
{
601 return $kvm_user_version if $kvm_user_version ;
603 $kvm_user_version = 'unknown' ;
605 my $tmp = `kvm -help 2>/dev/null` ;
607 if ( $tmp =~ m/^QEMU( PC)? emulator version (\d+\.\d+(\.\d+)?) / ) {
608 $kvm_user_version = $2 ;
611 return $kvm_user_version ;
615 my $kernel_has_vhost_net = - c
'/dev/vhost-net' ;
618 # order is important - used to autoselect boot disk
619 return (( map { "ide $_ " } ( 0 .. ( $MAX_IDE_DISKS - 1 ))),
620 ( map { "scsi $_ " } ( 0 .. ( $MAX_SCSI_DISKS - 1 ))),
621 ( map { "virtio $_ " } ( 0 .. ( $MAX_VIRTIO_DISKS - 1 ))),
622 ( map { "sata $_ " } ( 0 .. ( $MAX_SATA_DISKS - 1 ))));
625 sub valid_drivename
{
628 return defined ( $drivename_hash ->{ $dev });
633 return defined ( $confdesc ->{ $key });
637 return $nic_model_list ;
640 sub os_list_description
{
645 w2k
=> 'Windows 2000' ,
646 w2k3
=>, 'Windows 2003' ,
647 w2k8
=> 'Windows 2008' ,
648 wvista
=> 'Windows Vista' ,
655 sub disk_devive_info
{
658 die "unknown disk device format ' $dev '" if $dev !~ m/^(ide|scsi|virtio)(\d+)$/ ;
666 } elsif ( $bus eq 'scsi' ) {
670 my $controller = int ( $index / $maxdev );
671 my $unit = $index % $maxdev ;
674 return { bus
=> $bus, desc
=> uc ( $bus ) . " $controller : $unit " ,
675 controller
=> $controller, unit
=> $unit, index => $index };
679 sub qemu_drive_name
{
680 my ( $dev, $media ) = @_ ;
682 my $info = disk_devive_info
( $dev );
685 if (( $info ->{ bus
} eq 'ide' ) || ( $info ->{ bus
} eq 'scsi' )) {
686 $mediastr = ( $media eq 'cdrom' ) ?
"-cd" : "-hd" ;
687 return sprintf ( " %s%i%s%i " , $info ->{ bus
}, $info ->{ controller
},
688 $mediastr, $info ->{ unit
});
690 return sprintf ( " %s%i " , $info ->{ bus
}, $info ->{ index });
698 return $cdrom_path if $cdrom_path ;
700 return $cdrom_path = "/dev/cdrom" if - l
"/dev/cdrom" ;
701 return $cdrom_path = "/dev/cdrom1" if - l
"/dev/cdrom1" ;
702 return $cdrom_path = "/dev/cdrom2" if - l
"/dev/cdrom2" ;
706 my ( $storecfg, $vmid, $cdrom ) = @_ ;
708 if ( $cdrom eq 'cdrom' ) {
709 return get_cdrom_path
();
710 } elsif ( $cdrom eq 'none' ) {
712 } elsif ( $cdrom =~ m
|^/|) {
715 return PVE
:: Storage
:: path
( $storecfg, $cdrom );
719 # try to convert old style file names to volume IDs
720 sub filename_to_volume_id
{
721 my ( $vmid, $file, $media ) = @_ ;
723 if (!( $file eq 'none' || $file eq 'cdrom' ||
724 $file =~ m
|^ /dev/ .+| || $file =~ m/^([^:]+):(.+)$/ )) {
726 return undef if $file =~ m
|/|;
728 if ( $media && $media eq 'cdrom' ) {
729 $file = "local:iso/ $file " ;
731 $file = "local: $vmid/$file " ;
738 sub verify_media_type
{
739 my ( $opt, $vtype, $media ) = @_ ;
744 if ( $media eq 'disk' ) {
746 } elsif ( $media eq 'cdrom' ) {
749 die "internal error" ;
752 return if ( $vtype eq $etype );
754 raise_param_exc
({ $opt => "unexpected media type ( $vtype != $etype )" });
757 sub cleanup_drive_path
{
758 my ( $opt, $storecfg, $drive ) = @_ ;
760 # try to convert filesystem paths to volume IDs
762 if (( $drive ->{ file
} !~ m/^(cdrom|none)$/ ) &&
763 ( $drive ->{ file
} !~ m
|^ /dev/ .+|) &&
764 ( $drive ->{ file
} !~ m/^([^:]+):(.+)$/ ) &&
765 ( $drive ->{ file
} !~ m/^\d+$/ )) {
766 my ( $vtype, $volid ) = PVE
:: Storage
:: path_to_volume_id
( $storecfg, $drive ->{ file
});
767 raise_param_exc
({ $opt => "unable to associate path ' $drive ->{file}' to any storage" }) if ! $vtype ;
768 $drive ->{ media
} = 'cdrom' if ! $drive ->{ media
} && $vtype eq 'iso' ;
769 verify_media_type
( $opt, $vtype, $drive ->{ media
});
770 $drive ->{ file
} = $volid ;
773 $drive ->{ media
} = 'cdrom' if ! $drive ->{ media
} && $drive ->{ file
} =~ m/^(cdrom|none)$/ ;
776 sub create_conf_nolock
{
777 my ( $vmid, $settings ) = @_ ;
779 my $filename = config_file
( $vmid );
781 die "configuration file ' $filename ' already exists \n " if - f
$filename ;
783 my $defaults = load_defaults
();
785 $settings ->{ name
} = "vm $vmid " if ! $settings ->{ name
};
786 $settings ->{ memory
} = $defaults ->{ memory
} if ! $settings ->{ memory
};
789 foreach my $opt ( keys %$settings ) {
790 next if ! $confdesc ->{ $opt };
792 my $value = $settings ->{ $opt };
795 $data .= " $opt : $value\n " ;
798 PVE
:: Tools
:: file_set_contents
( $filename, $data );
801 # ideX = [volume=]volume-id[,media=d][,cyls=c,heads=h,secs=s[,trans=t]]
802 # [,snapshot=on|off][,cache=on|off][,format=f][,backup=yes|no]
803 # [,aio=native|threads]
806 my ( $key, $data ) = @_ ;
810 # $key may be undefined - used to verify JSON parameters
811 if (! defined ( $key )) {
812 $res ->{ interface
} = 'unknown' ; # should not harm when used to verify parameters
814 } elsif ( $key =~ m/^([^\d]+)(\d+)$/ ) {
815 $res ->{ interface
} = $1 ;
821 foreach my $p ( split ( /,/ , $data )) {
822 next if $p =~ m/^\s*$/ ;
824 if ( $p =~ m/^(file|volume|cyls|heads|secs|trans|media|snapshot|cache|format|rerror|werror|backup|aio)=(.+)$/ ) {
825 my ( $k, $v ) = ( $1, $2 );
827 $k = 'file' if $k eq 'volume' ;
829 return undef if defined $res ->{ $k };
833 if (! $res ->{ file
} && $p !~ m/=/ ) {
841 return undef if ! $res ->{ file
};
843 return undef if $res ->{ cache
} &&
844 $res ->{ cache
} !~ m/^(off|none|writethrough|writeback|unsafe)$/ ;
845 return undef if $res ->{ snapshot
} && $res ->{ snapshot
} !~ m/^(on|off)$/ ;
846 return undef if $res ->{ cyls
} && $res ->{ cyls
} !~ m/^\d+$/ ;
847 return undef if $res ->{ heads
} && $res ->{ heads
} !~ m/^\d+$/ ;
848 return undef if $res ->{ secs
} && $res ->{ secs
} !~ m/^\d+$/ ;
849 return undef if $res ->{ media
} && $res ->{ media
} !~ m/^(disk|cdrom)$/ ;
850 return undef if $res ->{ trans
} && $res ->{ trans
} !~ m/^(none|lba|auto)$/ ;
851 return undef if $res ->{ format
} && $res ->{ format
} !~ m/^(raw|cow|qcow|qcow2|vmdk|cloop)$/ ;
852 return undef if $res ->{ rerror
} && $res ->{ rerror
} !~ m/^(ignore|report|stop)$/ ;
853 return undef if $res ->{ werror
} && $res ->{ werror
} !~ m/^(enospc|ignore|report|stop)$/ ;
854 return undef if $res ->{ backup
} && $res ->{ backup
} !~ m/^(yes|no)$/ ;
855 return undef if $res ->{ aio
} && $res ->{ aio
} !~ m/^(native|threads)$/ ;
857 if ( $res ->{ media
} && ( $res ->{ media
} eq 'cdrom' )) {
858 return undef if $res ->{ snapshot
} || $res ->{ trans
} || $res ->{ format
};
859 return undef if $res ->{ heads
} || $res ->{ secs
} || $res ->{ cyls
};
860 return undef if $res ->{ interface
} eq 'virtio' ;
863 # rerror does not work with scsi drives
864 if ( $res ->{ rerror
}) {
865 return undef if $res ->{ interface
} eq 'scsi' ;
871 my @qemu_drive_options = qw(heads secs cyls trans media format cache snapshot rerror werror aio) ;
874 my ( $vmid, $drive ) = @_ ;
877 foreach my $o ( @qemu_drive_options, 'backup' ) {
878 $opts .= ", $o = $drive ->{ $o }" if $drive ->{ $o };
881 return " $drive ->{file} $opts " ;
884 sub print_drivedevice_full
{
885 my ( $storecfg, $vmid, $drive ) = @_ ;
890 if ( $drive ->{ interface
} eq 'virtio' ) {
891 my $pciaddr = print_pci_addr
( " $drive ->{interface} $drive ->{index}" );
892 $device = "virtio-blk-pci,drive=drive- $drive ->{interface} $drive ->{index},id= $drive ->{interface} $drive ->{index} $pciaddr " ;
893 } elsif ( $drive ->{ interface
} eq 'scsi' ) {
895 my $controller = int ( $drive ->{ index } / $maxdev );
896 my $unit = $drive ->{ index } % $maxdev ;
897 my $devicetype = 'hd' ;
899 if ( drive_is_cdrom
( $drive )) {
902 if ( $drive ->{ file
} =~ m
|^/|) {
903 $path = $drive ->{ file
};
905 $path = PVE
:: Storage
:: path
( $storecfg, $drive ->{ file
});
907 if ( $path =~ m
|^ /dev/ | ) {
908 $devicetype = 'block' ;
912 $device = "scsi- $devicetype,bus =lsi $controller .0,scsi-id= $unit,drive =drive- $drive ->{interface} $drive ->{index},id= $drive ->{interface} $drive ->{index}" ;
913 } elsif ( $drive ->{ interface
} eq 'ide' ){
915 my $controller = int ( $drive ->{ index } / $maxdev );
916 my $unit = $drive ->{ index } % $maxdev ;
917 my $devicetype = ( $drive ->{ media
} && $drive ->{ media
} eq 'cdrom' ) ?
"cd" : "hd" ;
919 $device = "ide- $devicetype,bus =ide. $controller,unit = $unit,drive =drive- $drive ->{interface} $drive ->{index},id= $drive ->{interface} $drive ->{index}" ;
920 } elsif ( $drive ->{ interface
} eq 'sata' ){
921 my $controller = int ( $drive ->{ index } / $MAX_SATA_DISKS );
922 my $unit = $drive ->{ index } % $MAX_SATA_DISKS ;
923 $device = "ide-drive,bus=ahci $controller . $unit,drive =drive- $drive ->{interface} $drive ->{index},id= $drive ->{interface} $drive ->{index}" ;
924 } elsif ( $drive ->{ interface
} eq 'usb' ) {
926 # -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
928 die "unsupported interface type" ;
931 $device .= ",bootindex= $drive ->{bootindex}" if $drive ->{ bootindex
};
936 sub print_drive_full
{
937 my ( $storecfg, $vmid, $drive ) = @_ ;
940 foreach my $o ( @qemu_drive_options ) {
941 next if $o eq 'bootindex' ;
942 $opts .= ", $o = $drive ->{ $o }" if $drive ->{ $o };
945 # use linux-aio by default (qemu default is threads)
946 $opts .= ",aio=native" if ! $drive ->{ aio
};
949 my $volid = $drive ->{ file
};
950 if ( drive_is_cdrom
( $drive )) {
951 $path = get_iso_path
( $storecfg, $vmid, $volid );
953 if ( $volid =~ m
|^/|) {
956 $path = PVE
:: Storage
:: path
( $storecfg, $volid );
958 if (! $drive ->{ cache
} && ( $path =~ m
|^ /dev/ | || $path =~ m
| \
. raw
$|)) {
959 $opts .= ",cache=none" ;
963 my $pathinfo = $path ?
"file= $path, " : '' ;
965 return "${pathinfo}if=none,id=drive- $drive ->{interface} $drive ->{index} $opts " ;
968 sub print_netdevice_full
{
969 my ( $vmid, $conf, $net, $netid ) = @_ ;
971 my $bootorder = $conf ->{ boot
} || $confdesc ->{ boot
}->{ default };
973 my $device = $net ->{ model
};
974 if ( $net ->{ model
} eq 'virtio' ) {
975 $device = 'virtio-net-pci' ;
978 # qemu > 0.15 always try to boot from network - we disable that by
979 # not loading the pxe rom file
980 my $extra = ( $bootorder !~ m/n/ ) ?
"romfile=," : '' ;
981 my $pciaddr = print_pci_addr
( " $netid " );
982 my $tmpstr = " $device,$ {extra}mac= $net ->{macaddr},netdev= $netid$pciaddr,id = $netid " ;
983 $tmpstr .= ",bootindex= $net ->{bootindex}" if $net ->{ bootindex
} ;
987 sub print_netdev_full
{
988 my ( $vmid, $conf, $net, $netid ) = @_ ;
991 if ( $netid =~ m/^net(\d+)$/ ) {
995 die "got strange net id ' $i ' \n " if $i >= ${ MAX_NETS
};
997 my $ifname = "tap${vmid}i $i " ;
999 # kvm uses TUNSETIFF ioctl, and that limits ifname length
1000 die "interface name ' $ifname ' is too long (max 15 character) \n "
1001 if length ( $ifname ) >= 16 ;
1003 my $vhostparam = '' ;
1004 $vhostparam = ',vhost=on' if $kernel_has_vhost_net && $net ->{ model
} eq 'virtio' ;
1006 my $vmname = $conf ->{ name
} || "vm $vmid " ;
1008 if ( $net ->{ bridge
}) {
1009 return "type=tap,id= $netid,ifname =${ifname},script=/var/lib/qemu-server/pve-bridge $vhostparam " ;
1011 return "type=user,id= $netid,hostname = $vmname " ;
1015 sub drive_is_cdrom
{
1018 return $drive && $drive ->{ media
} && ( $drive ->{ media
} eq 'cdrom' );
1025 return undef if ! $value ;
1029 if ( $value =~ m/^[a-f0-9]{2}:[a-f0-9]{2}\.[a-f0-9]$/ ) {
1030 $res ->{ pciid
} = $value ;
1038 # netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,rate=<mbps>
1044 foreach my $kvp ( split ( /,/ , $data )) {
1046 if ( $kvp =~ m/^(ne2k_pci|e1000|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i ) {
1048 my $mac = uc ( $3 ) || PVE
:: Tools
:: random_ether_addr
();
1049 $res ->{ model
} = $model ;
1050 $res ->{ macaddr
} = $mac ;
1051 } elsif ( $kvp =~ m/^bridge=(\S+)$/ ) {
1052 $res ->{ bridge
} = $1 ;
1053 } elsif ( $kvp =~ m/^rate=(\d+(\.\d+)?)$/ ) {
1061 return undef if ! $res ->{ model
};
1069 my $res = " $net ->{model}" ;
1070 $res .= "= $net ->{macaddr}" if $net ->{ macaddr
};
1071 $res .= ",bridge= $net ->{bridge}" if $net ->{ bridge
};
1072 $res .= ",rate= $net ->{rate}" if $net ->{ rate
};
1077 sub add_random_macs
{
1078 my ( $settings ) = @_ ;
1080 foreach my $opt ( keys %$settings ) {
1081 next if $opt !~ m/^net(\d+)$/ ;
1082 my $net = parse_net
( $settings ->{ $opt });
1084 $settings ->{ $opt } = print_net
( $net );
1088 sub add_unused_volume
{
1089 my ( $config, $volid ) = @_ ;
1092 for ( my $ind = $MAX_UNUSED_DISKS - 1 ; $ind >= 0 ; $ind --) {
1093 my $test = "unused $ind " ;
1094 if ( my $vid = $config ->{ $test }) {
1095 return if $vid eq $volid ; # do not add duplicates
1101 die "To many unused volume - please delete them first. \n " if ! $key ;
1103 $config ->{ $key } = $volid ;
1108 # fixme: remove all thos $noerr parameters?
1110 PVE
:: JSONSchema
:: register_format
( 'pve-qm-bootdisk' , \
& verify_bootdisk
);
1111 sub verify_bootdisk
{
1112 my ( $value, $noerr ) = @_ ;
1114 return $value if valid_drivename
( $value );
1116 return undef if $noerr ;
1118 die "invalid boot disk ' $value ' \n " ;
1121 PVE
:: JSONSchema
:: register_format
( 'pve-qm-net' , \
& verify_net
);
1123 my ( $value, $noerr ) = @_ ;
1125 return $value if parse_net
( $value );
1127 return undef if $noerr ;
1129 die "unable to parse network options \n " ;
1132 PVE
:: JSONSchema
:: register_format
( 'pve-qm-drive' , \
& verify_drive
);
1134 my ( $value, $noerr ) = @_ ;
1136 return $value if parse_drive
( undef , $value );
1138 return undef if $noerr ;
1140 die "unable to parse drive options \n " ;
1143 PVE
:: JSONSchema
:: register_format
( 'pve-qm-hostpci' , \
& verify_hostpci
);
1144 sub verify_hostpci
{
1145 my ( $value, $noerr ) = @_ ;
1147 return $value if parse_hostpci
( $value );
1149 return undef if $noerr ;
1151 die "unable to parse pci id \n " ;
1154 PVE
:: JSONSchema
:: register_format
( 'pve-qm-watchdog' , \
& verify_watchdog
);
1155 sub verify_watchdog
{
1156 my ( $value, $noerr ) = @_ ;
1158 return $value if parse_watchdog
( $value );
1160 return undef if $noerr ;
1162 die "unable to parse watchdog options \n " ;
1165 sub parse_watchdog
{
1168 return undef if ! $value ;
1172 foreach my $p ( split ( /,/ , $value )) {
1173 next if $p =~ m/^\s*$/ ;
1175 if ( $p =~ m/^(model=)?(i6300esb|ib700)$/ ) {
1177 } elsif ( $p =~ m/^(action=)?(reset|shutdown|poweroff|pause|debug|none)$/ ) {
1178 $res ->{ action
} = $2 ;
1187 sub parse_usb_device
{
1190 return undef if ! $value ;
1192 my @dl = split ( /,/ , $value );
1196 foreach my $v ( @dl ) {
1197 if ( $v =~ m/^host=([0-9A-Fa-f]{4}):([0-9A-Fa-f]{4})$/ ) {
1199 $res ->{ vendorid
} = $1 ;
1200 $res ->{ productid
} = $2 ;
1201 } elsif ( $v =~ m/^host=(\d+)\-(\d+(\.\d+)*)$/ ) {
1203 $res ->{ hostbus
} = $1 ;
1204 $res ->{ hostport
} = $2 ;
1209 return undef if ! $found ;
1214 PVE
:: JSONSchema
:: register_format
( 'pve-qm-usb-device' , \
& verify_usb_device
);
1215 sub verify_usb_device
{
1216 my ( $value, $noerr ) = @_ ;
1218 return $value if parse_usb_device
( $value );
1220 return undef if $noerr ;
1222 die "unable to parse usb device \n " ;
1225 # add JSON properties for create and set function
1226 sub json_config_properties
{
1229 foreach my $opt ( keys %$confdesc ) {
1230 $prop ->{ $opt } = $confdesc ->{ $opt };
1237 my ( $key, $value ) = @_ ;
1239 die "unknown setting ' $key ' \n " if ! $confdesc ->{ $key };
1241 my $type = $confdesc ->{ $key }->{ type
};
1243 if (! defined ( $value )) {
1244 die "got undefined value \n " ;
1247 if ( $value =~ m/[\n\r]/ ) {
1248 die "property contains a line feed \n " ;
1251 if ( $type eq 'boolean' ) {
1252 return 1 if ( $value eq '1' ) || ( $value =~ m/^(on|yes|true)$/i );
1253 return 0 if ( $value eq '0' ) || ( $value =~ m/^(off|no|false)$/i );
1254 die "type check ('boolean') failed - got ' $value ' \n " ;
1255 } elsif ( $type eq 'integer' ) {
1256 return int ( $1 ) if $value =~ m/^(\d+)$/ ;
1257 die "type check ('integer') failed - got ' $value ' \n " ;
1258 } elsif ( $type eq 'string' ) {
1259 if ( my $fmt = $confdesc ->{ $key }->{ format
}) {
1260 if ( $fmt eq 'pve-qm-drive' ) {
1261 # special case - we need to pass $key to parse_drive()
1262 my $drive = parse_drive
( $key, $value );
1263 return $value if $drive ;
1264 die "unable to parse drive options \n " ;
1266 PVE
:: JSONSchema
:: check_format
( $fmt, $value );
1269 $value =~ s/^\"(.*)\"$/$1/ ;
1272 die "internal error"
1277 my ( $vmid, $code, @param ) = @_ ;
1279 my $filename = config_file_lock
( $vmid );
1281 my $res = lock_file
( $filename, 10 , $code, @param );
1288 sub cfs_config_path
{
1289 my ( $vmid, $node ) = @_ ;
1291 $node = $nodename if ! $node ;
1292 return "nodes/ $node/qemu -server/ $vmid .conf" ;
1295 sub check_iommu_support
{
1296 #fixme : need to check IOMMU support
1297 #http://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM
1305 my ( $vmid, $node ) = @_ ;
1307 my $cfspath = cfs_config_path
( $vmid, $node );
1308 return "/etc/pve/ $cfspath " ;
1311 sub config_file_lock
{
1314 return " $lock_dir/lock - $vmid .conf" ;
1320 my $conf = config_file
( $vmid );
1321 utime undef , undef , $conf ;
1325 my ( $storecfg, $vmid, $keep_empty_config ) = @_ ;
1327 my $conffile = config_file
( $vmid );
1329 my $conf = load_config
( $vmid );
1333 # only remove disks owned by this VM
1334 foreach_drive
( $conf, sub {
1335 my ( $ds, $drive ) = @_ ;
1337 return if drive_is_cdrom
( $drive );
1339 my $volid = $drive ->{ file
};
1340 return if ! $volid || $volid =~ m
|^/|;
1342 my ( $path, $owner ) = PVE
:: Storage
:: path
( $storecfg, $volid );
1343 return if ! $path || ! $owner || ( $owner != $vmid );
1345 PVE
:: Storage
:: vdisk_free
( $storecfg, $volid );
1348 if ( $keep_empty_config ) {
1349 PVE
:: Tools
:: file_set_contents
( $conffile, "memory: 128 \n " );
1354 # also remove unused disk
1356 my $dl = PVE
:: Storage
:: vdisk_list
( $storecfg, undef , $vmid );
1359 PVE
:: Storage
:: foreach_volid
( $dl, sub {
1360 my ( $volid, $sid, $volname, $d ) = @_ ;
1361 PVE
:: Storage
:: vdisk_free
( $storecfg, $volid );
1371 sub load_diskinfo_old
{
1372 my ( $storecfg, $vmid, $conf ) = @_ ;
1378 foreach_drive
( $conf, sub {
1383 return if drive_is_cdrom
( $di );
1385 if ( $di ->{ file
} =~ m
|^ /dev/ .+|) {
1386 $info ->{ $di ->{ file
}}->{ size
} = PVE
:: Storage
:: file_size_info
( $di ->{ file
});
1388 push @$vollist, $di ->{ file
};
1393 my $dl = PVE
:: Storage
:: vdisk_list
( $storecfg, undef , $vmid, $vollist );
1395 PVE
:: Storage
:: foreach_volid
( $dl, sub {
1396 my ( $volid, $sid, $volname, $d ) = @_ ;
1397 $info ->{ $volid } = $d ;
1402 foreach my $ds ( keys %$res ) {
1403 my $di = $res ->{ $ds };
1405 $res ->{ $ds }->{ disksize
} = $info ->{ $di ->{ file
}} ?
1406 $info ->{ $di ->{ file
}}->{ size
} / ( 1024 * 1024 ) : 0 ;
1415 my $cfspath = cfs_config_path
( $vmid );
1417 my $conf = PVE
:: Cluster
:: cfs_read_file
( $cfspath );
1419 die "no such VM (' $vmid ') \n " if ! defined ( $conf );
1424 sub parse_vm_config
{
1425 my ( $filename, $raw ) = @_ ;
1427 return undef if ! defined ( $raw );
1430 digest
=> Digest
:: SHA1
:: sha1_hex
( $raw ),
1433 $filename =~ m
| /qemu-server/ ( \d
+) \
. conf
$|
1434 || die "got strange filename ' $filename '" ;
1438 while ( $raw && $raw =~ s/^(.*?)(\n|$)// ) {
1441 next if $line =~ m/^\#/ ;
1443 next if $line =~ m/^\s*$/ ;
1445 if ( $line =~ m/^(description):\s*(.*\S)\s*$/ ) {
1447 my $value = PVE
:: Tools
:: decode_text
( $2 );
1448 $res ->{ $key } = $value ;
1449 } elsif ( $line =~ m/^(args):\s*(.*\S)\s*$/ ) {
1452 $res ->{ $key } = $value ;
1453 } elsif ( $line =~ m/^([a-z][a-z_]*\d*):\s*(\S+)\s*$/ ) {
1456 eval { $value = check_type
( $key, $value ); };
1458 warn "vm $vmid - unable to parse value of ' $key ' - $@ " ;
1460 my $fmt = $confdesc ->{ $key }->{ format
};
1461 if ( $fmt && $fmt eq 'pve-qm-drive' ) {
1462 my $v = parse_drive
( $key, $value );
1463 if ( my $volid = filename_to_volume_id
( $vmid, $v ->{ file
}, $v ->{ media
})) {
1464 $v ->{ file
} = $volid ;
1465 $value = print_drive
( $vmid, $v );
1467 warn "vm $vmid - unable to parse value of ' $key ' \n " ;
1472 if ( $key eq 'cdrom' ) {
1473 $res ->{ ide2
} = $value ;
1475 $res ->{ $key } = $value ;
1481 # convert old smp to sockets
1482 if ( $res ->{ smp
} && ! $res ->{ sockets
}) {
1483 $res ->{ sockets
} = $res ->{ smp
};
1490 sub write_vm_config
{
1491 my ( $filename, $conf ) = @_ ;
1493 if ( $conf ->{ cdrom
}) {
1494 die "option ide2 conflicts with cdrom \n " if $conf ->{ ide2
};
1495 $conf ->{ ide2
} = $conf ->{ cdrom
};
1496 delete $conf ->{ cdrom
};
1499 # we do not use 'smp' any longer
1500 if ( $conf ->{ sockets
}) {
1501 delete $conf ->{ smp
};
1502 } elsif ( $conf ->{ smp
}) {
1503 $conf ->{ sockets
} = $conf ->{ smp
};
1504 delete $conf ->{ cores
};
1505 delete $conf ->{ smp
};
1508 my $new_volids = {};
1509 foreach my $key ( keys %$conf ) {
1510 next if $key eq 'digest' ;
1511 my $value = $conf ->{ $key };
1512 if ( $key eq 'description' ) {
1513 $value = PVE
:: Tools
:: encode_text
( $value );
1515 eval { $value = check_type
( $key, $value ); };
1516 die "unable to parse value of ' $key ' - $@ " if $@ ;
1518 $conf ->{ $key } = $value ;
1520 if ( valid_drivename
( $key )) {
1521 my $drive = PVE
:: QemuServer
:: parse_drive
( $key, $value );
1522 $new_volids ->{ $drive ->{ file
}} = 1 if $drive && $drive ->{ file
};
1526 # remove 'unusedX' settings if we re-add a volume
1527 foreach my $key ( keys %$conf ) {
1528 my $value = $conf ->{ $key };
1529 if ( $key =~ m/^unused/ && $new_volids ->{ $value }) {
1530 delete $conf ->{ $key };
1536 foreach my $key ( sort keys %$conf ) {
1537 next if $key eq 'digest' ;
1538 $raw .= " $key : $conf ->{ $key } \n " ;
1544 sub update_config_nolock
{
1545 my ( $vmid, $conf, $skiplock ) = @_ ;
1547 check_lock
( $conf ) if ! $skiplock ;
1549 my $cfspath = cfs_config_path
( $vmid );
1551 PVE
:: Cluster
:: cfs_write_file
( $cfspath, $conf );
1555 my ( $vmid, $conf, $skiplock ) = @_ ;
1557 lock_config
( $vmid, & update_config_nolock
, $conf, $skiplock );
1564 # we use static defaults from our JSON schema configuration
1565 foreach my $key ( keys %$confdesc ) {
1566 if ( defined ( my $default = $confdesc ->{ $key }->{ default })) {
1567 $res ->{ $key } = $default ;
1571 my $conf = PVE
:: Cluster
:: cfs_read_file
( 'datacenter.cfg' );
1572 $res ->{ keyboard
} = $conf ->{ keyboard
} if $conf ->{ keyboard
};
1578 my $vmlist = PVE
:: Cluster
:: get_vmlist
();
1580 return $res if ! $vmlist || ! $vmlist ->{ ids
};
1581 my $ids = $vmlist ->{ ids
};
1583 foreach my $vmid ( keys %$ids ) {
1584 my $d = $ids ->{ $vmid };
1585 next if ! $d ->{ node
} || $d ->{ node
} ne $nodename ;
1586 next if ! $d ->{ type
} || $d ->{ type
} ne 'qemu' ;
1587 $res ->{ $vmid }->{ exists } = 1 ;
1592 # test if VM uses local resources (to prevent migration)
1593 sub check_local_resources
{
1594 my ( $conf, $noerr ) = @_ ;
1598 $loc_res = 1 if $conf ->{ hostusb
}; # old syntax
1599 $loc_res = 1 if $conf ->{ hostpci
}; # old syntax
1601 foreach my $k ( keys %$conf ) {
1602 $loc_res = 1 if $k =~ m/^(usb|hostpci|serial|parallel)\d+$/ ;
1605 die "VM uses local resources \n " if $loc_res && ! $noerr ;
1613 die "VM is locked ( $conf ->{lock}) \n " if $conf ->{ lock };
1617 my ( $pidfile, $pid ) = @_ ;
1619 my $fh = IO
:: File-
> new ( "/proc/ $pid/cmdline " , "r" );
1623 return undef if ! $line ;
1624 my @param = split ( /\0/ , $line );
1626 my $cmd = $param [ 0 ];
1627 return if ! $cmd || ( $cmd !~ m
| kvm
$|);
1629 for ( my $i = 0 ; $i < scalar ( @param ); $i++ ) {
1632 if (( $p eq '-pidfile' ) || ( $p eq '--pidfile' )) {
1633 my $p = $param [ $i+1 ];
1634 return 1 if $p && ( $p eq $pidfile );
1643 my ( $vmid, $nocheck ) = @_ ;
1645 my $filename = config_file
( $vmid );
1647 die "unable to find configuration file for VM $vmid - no such machine \n "
1648 if ! $nocheck && ! - f
$filename ;
1650 my $pidfile = pidfile_name
( $vmid );
1652 if ( my $fd = IO
:: File-
> new ( "< $pidfile " )) {
1657 my $mtime = $st -> mtime ;
1658 if ( $mtime > time ()) {
1659 warn "file ' $filename ' modified in future \n " ;
1662 if ( $line =~ m/^(\d+)$/ ) {
1664 if ( check_cmdline
( $pidfile, $pid )) {
1665 if ( my $pinfo = PVE
:: ProcFSTools
:: check_process_running
( $pid )) {
1677 my $vzlist = config_list
();
1679 my $fd = IO
:: Dir-
> new ( $var_run_tmpdir ) || return $vzlist ;
1681 while ( defined ( my $de = $fd -> read )) {
1682 next if $de !~ m/^(\d+)\.pid$/ ;
1684 next if ! defined ( $vzlist ->{ $vmid });
1685 if ( my $pid = check_running
( $vmid )) {
1686 $vzlist ->{ $vmid }->{ pid
} = $pid ;
1693 my $storage_timeout_hash = {};
1696 my ( $storecfg, $conf ) = @_ ;
1698 my $bootdisk = $conf ->{ bootdisk
};
1699 return undef if ! $bootdisk ;
1700 return undef if ! valid_drivename
( $bootdisk );
1702 return undef if ! $conf ->{ $bootdisk };
1704 my $drive = parse_drive
( $bootdisk, $conf ->{ $bootdisk });
1705 return undef if ! defined ( $drive );
1707 return undef if drive_is_cdrom
( $drive );
1709 my $volid = $drive ->{ file
};
1710 return undef if ! $volid ;
1716 if ( $volid =~ m
|^/|) {
1717 $path = $timeoutid = $volid ;
1720 $storeid = $timeoutid = PVE
:: Storage
:: parse_volume_id
( $volid );
1721 $path = PVE
:: Storage
:: path
( $storecfg, $volid );
1729 my $last_timeout = $storage_timeout_hash ->{ $timeoutid };
1730 if ( $last_timeout ) {
1731 if (( time () - $last_timeout ) < 30 ) {
1732 # skip storage with errors
1735 delete $storage_timeout_hash ->{ $timeoutid };
1738 my ( $size, $format, $used );
1740 ( $size, $format, $used ) = PVE
:: Storage
:: file_size_info
( $path, 1 );
1742 if (! defined ( $format )) {
1744 $storage_timeout_hash ->{ $timeoutid } = time ();
1748 return wantarray ?
( $size, $used ) : $size ;
1751 my $last_proc_pid_stat ;
1754 my ( $opt_vmid ) = @_ ;
1758 my $storecfg = PVE
:: Storage
:: config
();
1760 my $list = vzlist
();
1761 my ( $uptime ) = PVE
:: ProcFSTools
:: read_proc_uptime
( 1 );
1763 my $cpucount = $cpuinfo ->{ cpus
} || 1 ;
1765 foreach my $vmid ( keys %$list ) {
1766 next if $opt_vmid && ( $vmid ne $opt_vmid );
1768 my $cfspath = cfs_config_path
( $vmid );
1769 my $conf = PVE
:: Cluster
:: cfs_read_file
( $cfspath ) || {};
1772 $d ->{ pid
} = $list ->{ $vmid }->{ pid
};
1774 # fixme: better status?
1775 $d ->{ status
} = $list ->{ $vmid }->{ pid
} ?
'running' : 'stopped' ;
1777 my ( $size, $used ) = disksize
( $storecfg, $conf );
1778 if ( defined ( $size ) && defined ( $used )) {
1780 $d ->{ maxdisk
} = $size ;
1786 $d ->{ cpus
} = ( $conf ->{ sockets
} || 1 ) * ( $conf ->{ cores
} || 1 );
1787 $d ->{ cpus
} = $cpucount if $d ->{ cpus
} > $cpucount ;
1789 $d ->{ name
} = $conf ->{ name
} || "VM $vmid " ;
1790 $d ->{ maxmem
} = $conf ->{ memory
} ?
$conf ->{ memory
}*( 1024 * 1024 ) : 0 ;
1800 $d ->{ diskwrite
} = 0 ;
1805 my $netdev = PVE
:: ProcFSTools
:: read_proc_net_dev
();
1806 foreach my $dev ( keys %$netdev ) {
1807 next if $dev !~ m/^tap([1-9]\d*)i/ ;
1809 my $d = $res ->{ $vmid };
1812 $d ->{ netout
} += $netdev ->{ $dev }->{ receive
};
1813 $d ->{ netin
} += $netdev ->{ $dev }->{ transmit
};
1816 my $ctime = gettimeofday
;
1818 foreach my $vmid ( keys %$list ) {
1820 my $d = $res ->{ $vmid };
1821 my $pid = $d ->{ pid
};
1824 if ( my $fh = IO
:: File-
> new ( "/proc/ $pid/io " , "r" )) {
1826 while ( defined ( my $line = < $fh >)) {
1827 if ( $line =~ m/^([rw]char):\s+(\d+)$/ ) {
1832 $d ->{ diskread
} = $data ->{ rchar
} || 0 ;
1833 $d ->{ diskwrite
} = $data ->{ wchar
} || 0 ;
1836 my $pstat = PVE
:: ProcFSTools
:: read_proc_pid_stat
( $pid );
1837 next if ! $pstat ; # not running
1839 my $used = $pstat ->{ utime } + $pstat ->{ stime
};
1841 $d ->{ uptime
} = int (( $uptime - $pstat ->{ starttime
})/ $cpuinfo ->{ user_hz
});
1843 if ( $pstat ->{ vsize
}) {
1844 $d ->{ mem
} = int (( $pstat ->{ rss
}/ $pstat ->{ vsize
})* $d ->{ maxmem
});
1847 my $old = $last_proc_pid_stat ->{ $pid };
1849 $last_proc_pid_stat ->{ $pid } = {
1857 my $dtime = ( $ctime - $old ->{ time }) * $cpucount * $cpuinfo ->{ user_hz
};
1859 if ( $dtime > 1000 ) {
1860 my $dutime = $used - $old ->{ used
};
1862 $d ->{ cpu
} = (( $dutime/$dtime )* $cpucount ) / $d ->{ cpus
};
1863 $last_proc_pid_stat ->{ $pid } = {
1869 $d ->{ cpu
} = $old ->{ cpu
};
1877 my ( $conf, $func ) = @_ ;
1879 foreach my $ds ( keys %$conf ) {
1880 next if ! valid_drivename
( $ds );
1882 my $drive = parse_drive
( $ds, $conf ->{ $ds });
1885 & $func ( $ds, $drive );
1889 sub config_to_command
{
1890 my ( $storecfg, $vmid, $conf, $defaults, $migrate_uri ) = @_ ;
1894 my $kvmver = kvm_user_version
();
1895 my $vernum = 0 ; # unknown
1896 if ( $kvmver =~ m/^(\d+)\.(\d+)$/ ) {
1897 $vernum = $1*1000000+$2*1000 ;
1898 } elsif ( $kvmver =~ m/^(\d+)\.(\d+)\.(\d+)$/ ) {
1899 $vernum = $1*1000000+$2*1000+$3 ;
1902 die "detected old qemu-kvm binary ( $kvmver ) \n " if $vernum < 15000 ;
1904 my $have_ovz = - f
'/proc/vz/vestat' ;
1906 push @$cmd, '/usr/bin/kvm' ;
1908 push @$cmd, '-id' , $vmid ;
1912 my $socket = monitor_socket
( $vmid );
1913 push @$cmd, '-chardev' , "socket,id=monitor,path= $socket,server,nowait " ;
1914 push @$cmd, '-mon' , "chardev=monitor,mode=readline" ;
1916 $socket = vnc_socket
( $vmid );
1917 push @$cmd, '-vnc' , "unix: $socket,x509,password " ;
1919 push @$cmd, '-pidfile' , pidfile_name
( $vmid );
1921 push @$cmd, '-daemonize' ;
1923 push @$cmd, '-incoming' , $migrate_uri if $migrate_uri ;
1926 for ( my $i = 0 ; $i < $MAX_USB_DEVICES ; $i++ ) {
1927 next if ! $conf ->{ "usb $i " };
1930 # include usb device config
1931 push @$cmd, '-readconfig' , '/usr/share/qemu-server/pve-usb.cfg' if $use_usb2 ;
1933 # enable absolute mouse coordinates (needed by vnc)
1934 my $tablet = defined ( $conf ->{ tablet
}) ?
$conf ->{ tablet
} : $defaults ->{ tablet
};
1937 push @$cmd, '-device' , 'usb-tablet,bus=ehci.0,port=6' ;
1939 push @$cmd, '-usbdevice' , 'tablet' ;
1944 for ( my $i = 0 ; $i < $MAX_HOSTPCI_DEVICES ; $i++ ) {
1945 my $d = parse_hostpci
( $conf ->{ "hostpci $i " });
1947 $pciaddr = print_pci_addr
( "hostpci $i " );
1948 push @$cmd, '-device' , "pci-assign,host= $d ->{pciid},id=hostpci $i$pciaddr " ;
1952 for ( my $i = 0 ; $i < $MAX_USB_DEVICES ; $i++ ) {
1953 my $d = parse_usb_device
( $conf ->{ "usb $i " });
1955 if ( $d ->{ vendorid
} && $d ->{ productid
}) {
1956 push @$cmd, '-device' , "usb-host,vendorid= $d ->{vendorid},productid= $d ->{productid}" ;
1957 } elsif ( defined ( $d ->{ hostbus
}) && defined ( $d ->{ hostport
})) {
1958 push @$cmd, '-device' , "usb-host,hostbus= $d ->{hostbus},hostport= $d ->{hostport}" ;
1963 for ( my $i = 0 ; $i < $MAX_SERIAL_PORTS ; $i++ ) {
1964 if ( my $path = $conf ->{ "serial $i " }) {
1965 die "no such serial device \n " if ! - c
$path ;
1966 push @$cmd, '-chardev' , "tty,id=serial $i,path = $path " ;
1967 push @$cmd, '-device' , "isa-serial,chardev=serial $i " ;
1972 for ( my $i = 0 ; $i < $MAX_PARALLEL_PORTS ; $i++ ) {
1973 if ( my $path = $conf ->{ "parallel $i " }) {
1974 die "no such parallel device \n " if ! - c
$path ;
1975 push @$cmd, '-chardev' , "parport,id=parallel $i,path = $path " ;
1976 push @$cmd, '-device' , "isa-parallel,chardev=parallel $i " ;
1980 my $vmname = $conf ->{ name
} || "vm $vmid " ;
1982 push @$cmd, '-name' , $vmname ;
1985 $sockets = $conf ->{ smp
} if $conf ->{ smp
}; # old style - no longer iused
1986 $sockets = $conf ->{ sockets
} if $conf ->{ sockets
};
1988 my $cores = $conf ->{ cores
} || 1 ;
1990 push @$cmd, '-smp' , "sockets= $sockets,cores = $cores " ;
1992 push @$cmd, '-cpu' , $conf ->{ cpu
} if $conf ->{ cpu
};
1994 push @$cmd, '-nodefaults' ;
1996 my $bootorder = $conf ->{ boot
} || $confdesc ->{ boot
}->{ default };
1998 my $bootindex_hash = {};
2000 foreach my $o ( split ( // , $bootorder )) {
2001 $bootindex_hash ->{ $o } = $i*100 ;
2005 push @$cmd, '-boot' , "menu=on" ;
2007 push @$cmd, '-no-acpi' if defined ( $conf ->{ acpi
}) && $conf ->{ acpi
} == 0 ;
2009 push @$cmd, '-no-reboot' if defined ( $conf ->{ reboot
}) && $conf ->{ reboot
} == 0 ;
2011 my $vga = $conf ->{ vga
};
2013 if ( $conf ->{ ostype
} && ( $conf ->{ ostype
} eq 'win7' || $conf ->{ ostype
} eq 'w2k8' )) {
2020 push @$cmd, '-vga' , $vga if $vga ; # for kvm 77 and later
2023 my $tdf = defined ( $conf ->{ tdf
}) ?
$conf ->{ tdf
} : $defaults ->{ tdf
};
2024 push @$cmd, '-tdf' if $tdf ;
2026 my $nokvm = defined ( $conf ->{ kvm
}) && $conf ->{ kvm
} == 0 ?
1 : 0 ;
2028 if ( my $ost = $conf ->{ ostype
}) {
2029 # other, wxp, w2k, w2k3, w2k8, wvista, win7, l24, l26
2031 if ( $ost =~ m/^w/ ) { # windows
2032 push @$cmd, '-localtime' if ! defined ( $conf ->{ localtime });
2034 # use rtc-td-hack when acpi is enabled
2035 if (!( defined ( $conf ->{ acpi
}) && $conf ->{ acpi
} == 0 )) {
2036 push @$cmd, '-rtc-td-hack' ;
2047 push @$cmd, '-no-kvm' ;
2049 die "No accelerator found! \n " if ! $cpuinfo ->{ hvm
};
2052 push @$cmd, '-localtime' if $conf ->{ localtime };
2054 push @$cmd, '-startdate' , $conf ->{ startdate
} if $conf ->{ startdate
};
2056 push @$cmd, '-S' if $conf ->{ freeze
};
2058 # set keyboard layout
2059 my $kb = $conf ->{ keyboard
} || $defaults ->{ keyboard
};
2060 push @$cmd, '-k' , $kb if $kb ;
2063 #my $soundhw = $conf->{soundhw} || $defaults->{soundhw};
2064 #push @$cmd, '-soundhw', 'es1370';
2065 #push @$cmd, '-soundhw', $soundhw if $soundhw;
2066 $pciaddr = print_pci_addr
( "balloon0" );
2067 push @$cmd, '-device' , "virtio-balloon-pci,id=balloon0 $pciaddr " if $conf ->{ balloon
};
2069 if ( $conf ->{ watchdog
}) {
2070 my $wdopts = parse_watchdog
( $conf ->{ watchdog
});
2071 $pciaddr = print_pci_addr
( "watchdog" );
2072 my $watchdog = $wdopts ->{ model
} || 'i6300esb' ;
2073 push @$cmd, '-device' , " $watchdog$pciaddr " ;
2074 push @$cmd, '-watchdog-action' , $wdopts ->{ action
} if $wdopts ->{ action
};
2078 my $scsicontroller = {};
2079 my $ahcicontroller = {};
2081 foreach_drive
( $conf, sub {
2082 my ( $ds, $drive ) = @_ ;
2084 if ( PVE
:: Storage
:: parse_volume_id
( $drive ->{ file
}, 1 )) {
2085 push @$vollist, $drive ->{ file
};
2088 $use_virtio = 1 if $ds =~ m/^virtio/ ;
2090 if ( drive_is_cdrom
( $drive )) {
2091 if ( $bootindex_hash ->{ d
}) {
2092 $drive ->{ bootindex
} = $bootindex_hash ->{ d
};
2093 $bootindex_hash ->{ d
} += 1 ;
2096 if ( $bootindex_hash ->{ c
}) {
2097 $drive ->{ bootindex
} = $bootindex_hash ->{ c
} if $conf ->{ bootdisk
} && ( $conf ->{ bootdisk
} eq $ds );
2098 $bootindex_hash ->{ c
} += 1 ;
2102 if ( $drive ->{ interface
} eq 'scsi' ) {
2104 my $controller = int ( $drive ->{ index } / $maxdev );
2105 $pciaddr = print_pci_addr
( "lsi $controller " );
2106 push @$cmd, '-device' , "lsi,id=lsi $controller$pciaddr " if ! $scsicontroller ->{ $controller };
2107 $scsicontroller ->{ $controller }= 1 ;
2110 if ( $drive ->{ interface
} eq 'sata' ) {
2111 my $controller = int ( $drive ->{ index } / $MAX_SATA_DISKS );
2112 $pciaddr = print_pci_addr
( "ahci $controller " );
2113 push @$cmd, '-device' , "ahci,id=ahci $controller,multifunction =on $pciaddr " if ! $ahcicontroller ->{ $controller };
2114 $ahcicontroller ->{ $controller }= 1 ;
2117 push @$cmd, '-drive' , print_drive_full
( $storecfg, $vmid, $drive );
2118 push @$cmd, '-device' , print_drivedevice_full
( $storecfg,$vmid, $drive );
2121 push @$cmd, '-m' , $conf ->{ memory
} || $defaults ->{ memory
};
2123 for ( my $i = 0 ; $i < $MAX_NETS ; $i++ ) {
2124 next if ! $conf ->{ "net $i " };
2125 my $d = parse_net
( $conf ->{ "net $i " });
2128 $use_virtio = 1 if $d ->{ model
} eq 'virtio' ;
2130 if ( $bootindex_hash ->{ n
}) {
2131 $d ->{ bootindex
} = $bootindex_hash ->{ n
};
2132 $bootindex_hash ->{ n
} += 1 ;
2135 my $netdevfull = print_netdev_full
( $vmid,$conf,$d, "net $i " );
2136 push @$cmd, '-netdev' , $netdevfull ;
2138 my $netdevicefull = print_netdevice_full
( $vmid,$conf,$d, "net $i " );
2139 push @$cmd, '-device' , $netdevicefull ;
2143 # hack: virtio with fairsched is unreliable, so we do not use fairsched
2144 # when the VM uses virtio devices.
2145 if (! $use_virtio && $have_ovz ) {
2147 my $cpuunits = defined ( $conf ->{ cpuunits
}) ?
2148 $conf ->{ cpuunits
} : $defaults ->{ cpuunits
};
2150 push @$cmd, '-cpuunits' , $cpuunits if $cpuunits ;
2152 # fixme: cpulimit is currently ignored
2153 #push @$cmd, '-cpulimit', $conf->{cpulimit} if $conf->{cpulimit};
2157 if ( $conf ->{ args
}) {
2158 my $aa = PVE
:: Tools
:: split_args
( $conf ->{ args
});
2162 return wantarray ?
( $cmd, $vollist ) : $cmd ;
2167 return "${var_run_tmpdir}/ $vmid .vnc" ;
2170 sub monitor_socket
{
2172 return "${var_run_tmpdir}/ $vmid .mon" ;
2177 return "${var_run_tmpdir}/ $vmid .pid" ;
2180 sub next_migrate_port
{
2182 for ( my $p = 60000 ; $p < 60010 ; $p++ ) {
2184 my $sock = IO
:: Socket
:: INET-
> new ( Listen
=> 5 ,
2185 LocalAddr
=> 'localhost' ,
2196 die "unable to find free migration port" ;
2199 sub vm_devices_list
{
2202 my $res = vm_monitor_command
( $vmid, "info pci" );
2204 my @lines = split ( " \n " , $res );
2210 foreach my $line ( @lines ) {
2212 if ( $line =~ m/^Bus (\d+), device (\d+), function (\d+):$/ ) {
2216 if ( $line =~ m/^id "([a-z][a-z_\-]*\d*)"$/ ) {
2218 $devices ->{ $id }->{ bus
}= $bus ;
2219 $devices ->{ $id }->{ addr
}= $addr ;
2227 my ( $storecfg, $conf, $vmid, $deviceid, $device ) = @_ ;
2228 return 1 if ! check_running
( $vmid ) || ! $conf ->{ hotplug
};
2230 if ( $deviceid =~ m/^(virtio)(\d+)$/ ) {
2231 return undef if ! qemu_driveadd
( $storecfg, $vmid, $device );
2232 my $devicefull = print_drivedevice_full
( $storecfg, $vmid, $device );
2233 qemu_deviceadd
( $vmid, $devicefull );
2234 if (! qemu_deviceaddverify
( $vmid, $deviceid )) {
2235 qemu_drivedel
( $vmid, $deviceid );
2240 if ( $deviceid =~ m/^(lsi)(\d+)$/ ) {
2241 my $pciaddr = print_pci_addr
( $deviceid );
2242 my $devicefull = "lsi,id= $deviceid$pciaddr " ;
2243 qemu_deviceadd
( $vmid, $devicefull );
2244 return undef if (! qemu_deviceaddverify
( $vmid, $deviceid ));
2247 if ( $deviceid =~ m/^(scsi)(\d+)$/ ) {
2248 return undef if ! qemu_findorcreatelsi
( $storecfg,$conf, $vmid, $device );
2249 return undef if ! qemu_driveadd
( $storecfg, $vmid, $device );
2250 my $devicefull = print_drivedevice_full
( $storecfg, $vmid, $device );
2251 if (! qemu_deviceadd
( $vmid, $devicefull )) {
2252 qemu_drivedel
( $vmid, $deviceid );
2257 if ( $deviceid =~ m/^(net)(\d+)$/ ) {
2258 return undef if ! qemu_netdevadd
( $vmid, $conf, $device, $deviceid );
2259 my $netdevicefull = print_netdevice_full
( $vmid, $conf, $device, $deviceid );
2260 qemu_deviceadd
( $vmid, $netdevicefull );
2261 if (! qemu_deviceaddverify
( $vmid, $deviceid )) {
2262 qemu_netdevdel
( $vmid, $deviceid );
2270 sub vm_deviceunplug
{
2271 my ( $vmid, $conf, $deviceid ) = @_ ;
2273 return 1 if ! check_running
( $vmid ) || ! $conf ->{ hotplug
};
2275 die "can't unplug bootdisk" if $conf ->{ bootdisk
} eq $deviceid ;
2277 if ( $deviceid =~ m/^(virtio)(\d+)$/ ) {
2278 return undef if ! qemu_drivedel
( $vmid, $deviceid );
2279 qemu_devicedel
( $vmid, $deviceid );
2280 return undef if ! qemu_devicedelverify
( $vmid, $deviceid );
2283 if ( $deviceid =~ m/^(lsi)(\d+)$/ ) {
2284 return undef if ! qemu_devicedel
( $vmid, $deviceid );
2287 if ( $deviceid =~ m/^(scsi)(\d+)$/ ) {
2288 return undef if ! qemu_devicedel
( $vmid, $deviceid );
2289 return undef if ! qemu_drivedel
( $vmid, $deviceid );
2292 if ( $deviceid =~ m/^(net)(\d+)$/ ) {
2293 return undef if ! qemu_netdevdel
( $vmid, $deviceid );
2294 qemu_devicedel
( $vmid, $deviceid );
2295 return undef if ! qemu_devicedelverify
( $vmid, $deviceid );
2301 sub qemu_deviceadd
{
2302 my ( $vmid, $devicefull ) = @_ ;
2304 my $ret = vm_monitor_command
( $vmid, "device_add $devicefull " );
2306 # Otherwise, if the command succeeds, no output is sent. So any non-empty string shows an error
2307 return 1 if $ret eq "" ;
2308 syslog
( "err" , "error on hotplug device : $ret " );
2313 sub qemu_devicedel
{
2314 my ( $vmid, $deviceid ) = @_ ;
2316 my $ret = vm_monitor_command
( $vmid, "device_del $deviceid " );
2318 return 1 if $ret eq "" ;
2319 syslog
( "err" , "detaching device $deviceid failed : $ret " );
2324 my ( $storecfg, $vmid, $device ) = @_ ;
2326 my $drive = print_drive_full
( $storecfg, $vmid, $device );
2327 my $ret = vm_monitor_command
( $vmid, "drive_add auto $drive " );
2328 # If the command succeeds qemu prints: "OK"
2329 if ( $ret !~ m/OK/s ) {
2330 syslog
( "err" , "adding drive failed: $ret " );
2337 my ( $vmid, $deviceid ) = @_ ;
2339 my $ret = vm_monitor_command
( $vmid, "drive_del drive- $deviceid " );
2341 if ( $ret =~ m/Device \'.*?\' not found/s ) {
2342 # NB: device not found errors mean the drive was auto-deleted and we ignore the error
2344 elsif ( $ret ne "" ) {
2345 syslog
( "err" , "deleting drive $deviceid failed : $ret " );
2351 sub qemu_deviceaddverify
{
2352 my ( $vmid,$deviceid ) = @_ ;
2354 for ( my $i = 0 ; $i <= 5 ; $i++ ) {
2355 my $devices_list = vm_devices_list
( $vmid );
2356 return 1 if defined ( $devices_list ->{ $deviceid });
2359 syslog
( "err" , "error on hotplug device $deviceid " );
2364 sub qemu_devicedelverify
{
2365 my ( $vmid,$deviceid ) = @_ ;
2367 #need to verify the device is correctly remove as device_del is async and empty return is not reliable
2368 for ( my $i = 0 ; $i <= 5 ; $i++ ) {
2369 my $devices_list = vm_devices_list
( $vmid );
2370 return 1 if ! defined ( $devices_list ->{ $deviceid });
2373 syslog
( "err" , "error on hot-unplugging device $deviceid " );
2377 sub qemu_findorcreatelsi
{
2378 my ( $storecfg, $conf, $vmid, $device ) = @_ ;
2381 my $controller = int ( $device ->{ index } / $maxdev );
2382 my $lsiid = "lsi $controller " ;
2383 my $devices_list = vm_devices_list
( $vmid );
2385 if (! defined ( $devices_list ->{ $lsiid })) {
2386 return undef if ! vm_deviceplug
( $storecfg, $conf, $vmid, $lsiid );
2391 sub qemu_netdevadd
{
2392 my ( $vmid, $conf, $device, $deviceid ) = @_ ;
2394 my $netdev = print_netdev_full
( $vmid, $conf, $device, $deviceid );
2395 my $ret = vm_monitor_command
( $vmid, "netdev_add $netdev " );
2398 #if the command succeeds, no output is sent. So any non-empty string shows an error
2399 return 1 if $ret eq "" ;
2400 syslog
( "err" , "adding netdev failed: $ret " );
2404 sub qemu_netdevdel
{
2405 my ( $vmid, $deviceid ) = @_ ;
2407 my $ret = vm_monitor_command
( $vmid, "netdev_del $deviceid " );
2409 #if the command succeeds, no output is sent. So any non-empty string shows an error
2410 return 1 if $ret eq "" ;
2411 syslog
( "err" , "deleting netdev failed: $ret " );
2416 my ( $storecfg, $vmid, $statefile, $skiplock ) = @_ ;
2418 lock_config
( $vmid, sub {
2419 my $conf = load_config
( $vmid );
2421 check_lock
( $conf ) if ! $skiplock ;
2423 die "VM $vmid already running \n " if check_running
( $vmid );
2426 my $migrate_port = 0 ;
2429 if ( $statefile eq 'tcp' ) {
2430 $migrate_port = next_migrate_port
();
2431 $migrate_uri = "tcp:localhost:${migrate_port}" ;
2433 if (- f
$statefile ) {
2434 $migrate_uri = "exec:cat $statefile " ;
2436 warn "state file ' $statefile ' does not exist - doing normal startup \n " ;
2441 my $defaults = load_defaults
();
2443 my ( $cmd, $vollist ) = config_to_command
( $storecfg, $vmid, $conf, $defaults, $migrate_uri );
2445 for ( my $i = 0 ; $i < $MAX_HOSTPCI_DEVICES ; $i++ ) {
2446 my $d = parse_hostpci
( $conf ->{ "hostpci $i " });
2448 my $info = pci_device_info
( "0000: $d ->{pciid}" );
2449 die "IOMMU not present \n " if ! check_iommu_support
();
2450 die "no pci device info for device ' $d ->{pciid}' \n " if ! $info ;
2451 die "can't unbind pci device ' $d ->{pciid}' \n " if ! pci_dev_bind_to_stub
( $info );
2452 die "can't reset pci device ' $d ->{pciid}' \n " if ! pci_dev_reset
( $info );
2455 PVE
:: Storage
:: activate_volumes
( $storecfg, $vollist );
2457 eval { run_command
( $cmd, timeout
=> $migrate_uri ?
undef : 30 ); };
2459 die "start failed: $err " if $err ;
2463 if ( $statefile eq 'tcp' ) {
2464 print "migration listens on port $migrate_port\n " ;
2467 # fixme: send resume - is that necessary ?
2468 eval { vm_monitor_command
( $vmid, "cont" ); };
2472 # always set migrate speed (overwrite kvm default of 32m)
2473 # we set a very hight default of 8192m which is basically unlimited
2474 my $migrate_speed = $defaults ->{ migrate_speed
} || 8192 ;
2475 $migrate_speed = $conf ->{ migrate_speed
} || $migrate_speed ;
2477 my $cmd = "migrate_set_speed ${migrate_speed}m" ;
2478 vm_monitor_command
( $vmid, $cmd );
2481 if ( my $migrate_downtime =
2482 $conf ->{ migrate_downtime
} || $defaults ->{ migrate_downtime
}) {
2483 my $cmd = "migrate_set_downtime ${migrate_downtime}" ;
2484 eval { vm_monitor_command
( $vmid, $cmd ); };
2487 vm_balloonset
( $vmid, $conf ->{ balloon
}) if $conf ->{ balloon
};
2492 my ( $fh, $timeout ) = @_ ;
2494 my $sel = new IO
:: Select
;
2501 while ( scalar ( @ready = $sel -> can_read ( $timeout ))) {
2503 if ( $count = $fh -> sysread ( $buf, 8192 )) {
2504 if ( $buf =~ /^(.*)\(qemu\) $/s ) {
2511 if (! defined ( $count )) {
2518 die "monitor read timeout \n " if ! scalar ( @ready );
2523 sub vm_monitor_command
{
2524 my ( $vmid, $cmdstr, $nocheck ) = @_ ;
2529 die "VM $vmid not running \n " if ! check_running
( $vmid, $nocheck );
2531 my $sname = monitor_socket
( $vmid );
2533 my $sock = IO
:: Socket
:: UNIX-
> new ( Peer
=> $sname ) ||
2534 die "unable to connect to VM $vmid socket - $!\n " ;
2538 # hack: migrate sometime blocks the monitor (when migrate_downtime
2540 if ( $cmdstr =~ m/^(info\s+migrate|migrate\s)/ ) {
2541 $timeout = 60 * 60 ; # 1 hour
2545 my $data = __read_avail
( $sock, $timeout );
2547 if ( $data !~ m/^QEMU\s+(\S+)\s+monitor\s/ ) {
2548 die "got unexpected qemu monitor banner \n " ;
2551 my $sel = new IO
:: Select
;
2554 if (! scalar ( my @ready = $sel -> can_write ( $timeout ))) {
2555 die "monitor write error - timeout" ;
2558 my $fullcmd = " $cmdstr\r " ;
2561 if (!( $b = $sock -> syswrite ( $fullcmd )) || ( $b != length ( $fullcmd ))) {
2562 die "monitor write error - $! " ;
2565 return if ( $cmdstr eq 'q' ) || ( $cmdstr eq 'quit' );
2569 if ( $cmdstr =~ m/^(info\s+migrate|migrate\s)/ ) {
2570 $timeout = 60 * 60 ; # 1 hour
2571 } elsif ( $cmdstr =~ m/^(eject|change)/ ) {
2572 $timeout = 60 ; # note: cdrom mount command is slow
2574 if ( $res = __read_avail
( $sock, $timeout )) {
2576 my @lines = split ( " \r ? \n " , $res );
2578 shift @lines if $lines [ 0 ] !~ m/^unknown command/ ; # skip echo
2580 $res = join ( " \n " , @lines );
2588 syslog
( "err" , "VM $vmid monitor command failed - $err " );
2595 sub vm_commandline
{
2596 my ( $storecfg, $vmid ) = @_ ;
2598 my $conf = load_config
( $vmid );
2600 my $defaults = load_defaults
();
2602 my $cmd = config_to_command
( $storecfg, $vmid, $conf, $defaults );
2604 return join ( ' ' , @$cmd );
2608 my ( $vmid, $skiplock ) = @_ ;
2610 lock_config
( $vmid, sub {
2612 my $conf = load_config
( $vmid );
2614 check_lock
( $conf ) if ! $skiplock ;
2616 vm_monitor_command
( $vmid, "system_reset" );
2620 sub get_vm_volumes
{
2624 foreach_drive
( $conf, sub {
2625 my ( $ds, $drive ) = @_ ;
2627 my ( $sid, $volname ) = PVE
:: Storage
:: parse_volume_id
( $drive ->{ file
}, 1 );
2630 my $volid = $drive ->{ file
};
2631 return if ! $volid || $volid =~ m
|^/|;
2633 push @$vollist, $volid ;
2639 sub vm_stop_cleanup
{
2640 my ( $storecfg, $vmid, $conf, $keepActive ) = @_ ;
2643 fairsched_rmnod
( $vmid ); # try to destroy group
2646 my $vollist = get_vm_volumes
( $conf );
2647 PVE
:: Storage
:: deactivate_volumes
( $storecfg, $vollist );
2650 warn $@ if $@ ; # avoid errors - just warn
2653 # Note: use $nockeck to skip tests if VM configuration file exists.
2654 # We need that when migration VMs to other nodes (files already moved)
2655 # Note: we set $keepActive in vzdump stop mode - volumes need to stay active
2657 my ( $storecfg, $vmid, $skiplock, $nocheck, $timeout, $shutdown, $force, $keepActive ) = @_ ;
2659 $timeout = 60 if ! defined ( $timeout );
2661 $force = 1 if ! defined ( $force ) && ! $shutdown ;
2663 lock_config
( $vmid, sub {
2665 my $pid = check_running
( $vmid, $nocheck );
2670 $conf = load_config
( $vmid );
2671 check_lock
( $conf ) if ! $skiplock ;
2676 vm_monitor_command
( $vmid, "system_powerdown" , $nocheck );
2678 vm_monitor_command
( $vmid, "quit" , $nocheck );
2685 while (( $count < $timeout ) && check_running
( $vmid, $nocheck )) {
2690 if ( $count >= $timeout ) {
2692 warn "VM still running - terminating now with SIGTERM \n " ;
2695 die "VM quit/powerdown failed - got timeout \n " ;
2698 vm_stop_cleanup
( $storecfg, $vmid, $conf, $keepActive ) if $conf ;
2703 warn "VM quit/powerdown failed - terminating now with SIGTERM \n " ;
2706 die "VM quit/powerdown failed \n " ;
2714 while (( $count < $timeout ) && check_running
( $vmid, $nocheck )) {
2719 if ( $count >= $timeout ) {
2720 warn "VM still running - terminating now with SIGKILL \n " ;
2725 vm_stop_cleanup
( $storecfg, $vmid, $conf, $keepActive ) if $conf ;
2730 my ( $vmid, $skiplock ) = @_ ;
2732 lock_config
( $vmid, sub {
2734 my $conf = load_config
( $vmid );
2736 check_lock
( $conf ) if ! $skiplock ;
2738 vm_monitor_command
( $vmid, "stop" );
2743 my ( $vmid, $skiplock ) = @_ ;
2745 lock_config
( $vmid, sub {
2747 my $conf = load_config
( $vmid );
2749 check_lock
( $conf ) if ! $skiplock ;
2751 vm_monitor_command
( $vmid, "cont" );
2756 my ( $vmid, $skiplock, $key ) = @_ ;
2758 lock_config
( $vmid, sub {
2760 my $conf = load_config
( $vmid );
2762 vm_monitor_command
( $vmid, "sendkey $key " );
2767 my ( $storecfg, $vmid, $skiplock ) = @_ ;
2769 lock_config
( $vmid, sub {
2771 my $conf = load_config
( $vmid );
2773 check_lock
( $conf ) if ! $skiplock ;
2775 if (! check_running
( $vmid )) {
2776 fairsched_rmnod
( $vmid ); # try to destroy group
2777 destroy_vm
( $storecfg, $vmid );
2779 die "VM $vmid is running - destroy failed \n " ;
2785 my ( $storecfg, $timeout ) = @_ ;
2787 $timeout = 3 * 60 if ! $timeout ;
2789 my $cleanuphash = {};
2791 my $vzlist = vzlist
();
2793 foreach my $vmid ( keys %$vzlist ) {
2794 next if ! $vzlist ->{ $vmid }->{ pid
};
2796 $cleanuphash ->{ $vmid } = 1 ;
2801 my $msg = "Stopping Qemu Server - sending shutdown requests to all VMs \n " ;
2802 syslog
( 'info' , $msg );
2805 foreach my $vmid ( keys %$vzlist ) {
2806 next if ! $vzlist ->{ $vmid }->{ pid
};
2807 eval { vm_monitor_command
( $vmid, "system_powerdown" ); };
2812 my $maxtries = int (( $timeout + $wt - 1 )/ $wt );
2814 while (( $try < $maxtries ) && $count ) {
2820 foreach my $vmid ( keys %$vzlist ) {
2821 next if ! $vzlist ->{ $vmid }->{ pid
};
2829 foreach my $vmid ( keys %$vzlist ) {
2830 next if ! $vzlist ->{ $vmid }->{ pid
};
2832 warn "VM $vmid still running - sending stop now \n " ;
2833 eval { vm_monitor_command
( $vmid, "quit" ); };
2838 $maxtries = int (( $timeout + $wt - 1 )/ $wt );
2840 while (( $try < $maxtries ) && $count ) {
2846 foreach my $vmid ( keys %$vzlist ) {
2847 next if ! $vzlist ->{ $vmid }->{ pid
};
2855 foreach my $vmid ( keys %$vzlist ) {
2856 next if ! $vzlist ->{ $vmid }->{ pid
};
2858 warn "VM $vmid still running - terminating now with SIGTERM \n " ;
2859 kill 15 , $vzlist ->{ $vmid }->{ pid
};
2864 # this is called by system shotdown scripts, so remaining
2865 # processes gets killed anyways (no need to send kill -9 here)
2869 foreach my $vmid ( keys %$cleanuphash ) {
2870 next if $vzlist ->{ $vmid }->{ pid
};
2872 my $conf = load_config
( $vmid );
2873 vm_stop_cleanup
( $storecfg, $vmid, $conf );
2878 $msg = "Qemu Server stopped \n " ;
2879 syslog
( 'info' , $msg );
2886 my ( $filename, $buf ) = @_ ;
2888 my $fh = IO
:: File-
> new ( $filename, "w" );
2889 return undef if ! $fh ;
2891 my $res = print $fh $buf ;
2898 sub pci_device_info
{
2903 return undef if $name !~ m/^([a-f0-9]{4}):([a-f0-9]{2}):([a-f0-9]{2})\.([a-f0-9])$/ ;
2904 my ( $domain, $bus, $slot, $func ) = ( $1, $2, $3, $4 );
2906 my $irq = file_read_firstline
( " $pcisysfs/devices/$name/irq " );
2907 return undef if ! defined ( $irq ) || $irq !~ m/^\d+$/ ;
2909 my $vendor = file_read_firstline
( " $pcisysfs/devices/$name/vendor " );
2910 return undef if ! defined ( $vendor ) || $vendor !~ s/^0x// ;
2912 my $product = file_read_firstline
( " $pcisysfs/devices/$name/device " );
2913 return undef if ! defined ( $product ) || $product !~ s/^0x// ;
2918 product
=> $product,
2924 has_fl_reset
=> - f
" $pcisysfs/devices/$name/reset " || 0 ,
2933 my $name = $dev ->{ name
};
2935 my $fn = " $pcisysfs/devices/$name/reset " ;
2937 return file_write
( $fn, "1" );
2940 sub pci_dev_bind_to_stub
{
2943 my $name = $dev ->{ name
};
2945 my $testdir = " $pcisysfs/drivers/pci -stub/ $name " ;
2946 return 1 if - d
$testdir ;
2948 my $data = " $dev ->{vendor} $dev ->{product}" ;
2949 return undef if ! file_write
( " $pcisysfs/drivers/pci -stub/new_id" , $data );
2951 my $fn = " $pcisysfs/devices/$name/driver/unbind " ;
2952 if (! file_write
( $fn, $name )) {
2953 return undef if - f
$fn ;
2956 $fn = " $pcisysfs/drivers/pci -stub/bind" ;
2957 if (! - d
$testdir ) {
2958 return undef if ! file_write
( $fn, $name );
2964 sub print_pci_addr
{
2969 #addr1 : ide,parallel,serial (motherboard)
2970 #addr2 : first videocard
2971 balloon0
=> { bus
=> 0 , addr
=> 3 },
2972 watchdog
=> { bus
=> 0 , addr
=> 4 },
2973 lsi0
=> { bus
=> 0 , addr
=> 5 },
2974 lsi1
=> { bus
=> 0 , addr
=> 6 },
2975 ahci0
=> { bus
=> 0 , addr
=> 7 },
2976 virtio0
=> { bus
=> 0 , addr
=> 10 },
2977 virtio1
=> { bus
=> 0 , addr
=> 11 },
2978 virtio2
=> { bus
=> 0 , addr
=> 12 },
2979 virtio3
=> { bus
=> 0 , addr
=> 13 },
2980 virtio4
=> { bus
=> 0 , addr
=> 14 },
2981 virtio5
=> { bus
=> 0 , addr
=> 15 },
2982 hostpci0
=> { bus
=> 0 , addr
=> 16 },
2983 hostpci1
=> { bus
=> 0 , addr
=> 17 },
2984 net0
=> { bus
=> 0 , addr
=> 18 },
2985 net1
=> { bus
=> 0 , addr
=> 19 },
2986 net2
=> { bus
=> 0 , addr
=> 20 },
2987 net3
=> { bus
=> 0 , addr
=> 21 },
2988 net4
=> { bus
=> 0 , addr
=> 22 },
2989 net5
=> { bus
=> 0 , addr
=> 23 },
2990 #addr29 : usb-host (pve-usb.cfg)
2993 if ( defined ( $devices ->{ $id }->{ bus
}) && defined ( $devices ->{ $id }->{ addr
})) {
2994 my $addr = sprintf ( "0x %x " , $devices ->{ $id }->{ addr
});
2995 $res = ",bus=pci. $devices ->{ $id }->{bus},addr= $addr " ;
3002 my ( $vmid, $value ) = @_ ;
3004 vm_monitor_command
( $vmid, "balloon $value " );
3007 # vzdump restore implementaion
3009 sub archive_read_firstfile
{
3010 my $archive = shift ;
3012 die "ERROR: file ' $archive ' does not exist \n " if ! - f
$archive ;
3014 # try to detect archive type first
3015 my $pid = open ( TMP
, "tar tf ' $archive '|" ) ||
3016 die "unable to open file ' $archive ' \n " ;
3017 my $firstfile = < TMP
>;
3021 die "ERROR: archive contaions no data \n " if ! $firstfile ;
3027 sub restore_cleanup
{
3028 my $statfile = shift ;
3030 print STDERR
"starting cleanup \n " ;
3032 if ( my $fd = IO
:: File-
> new ( $statfile, "r" )) {
3033 while ( defined ( my $line = < $fd >)) {
3034 if ( $line =~ m/vzdump:([^\s:]*):(\S+)$/ ) {
3037 if ( $volid =~ m
|^/|) {
3038 unlink $volid || die 'unlink failed \n ' ;
3040 my $cfg = cfs_read_file
( 'storage.cfg' );
3041 PVE
:: Storage
:: vdisk_free
( $cfg, $volid );
3043 print STDERR
"temporary volume ' $volid ' sucessfuly removed \n " ;
3045 print STDERR
"unable to cleanup ' $volid ' - $@ " if $@ ;
3047 print STDERR
"unable to parse line in statfile - $line " ;
3054 sub restore_archive
{
3055 my ( $archive, $vmid, $user, $opts ) = @_ ;
3057 if ( $archive ne '-' ) {
3058 my $firstfile = archive_read_firstfile
( $archive );
3059 die "ERROR: file ' $archive ' dos not lock like a QemuServer vzdump backup \n "
3060 if $firstfile ne 'qemu-server.conf' ;
3063 my $tocmd = "/usr/lib/qemu-server/qmextract" ;
3065 $tocmd .= " --storage " . PVE
:: Tools
:: shellquote
( $opts ->{ storage
}) if $opts ->{ storage
};
3066 $tocmd .= " --pool " . PVE
:: Tools
:: shellquote
( $opts ->{ pool
}) if $opts ->{ pool
};
3067 $tocmd .= ' --prealloc' if $opts ->{ prealloc
};
3068 $tocmd .= ' --info' if $opts ->{ info
};
3070 # tar option "xf" does not autodetect compression when read from STDIN,
3071 # so we pipe to zcat
3072 my $cmd = "zcat -f|tar xf " . PVE
:: Tools
:: shellquote
( $archive ) . " " .
3073 PVE
:: Tools
:: shellquote
( "--to-command= $tocmd " );
3075 my $tmpdir = "/var/tmp/vzdumptmp $$ " ;
3078 local $ENV { VZDUMP_TMPDIR
} = $tmpdir ;
3079 local $ENV { VZDUMP_VMID
} = $vmid ;
3080 local $ENV { VZDUMP_USER
} = $user ;
3082 my $conffile = PVE
:: QemuServer
:: config_file
( $vmid );
3083 my $tmpfn = " $conffile . $$ .tmp" ;
3085 # disable interrupts (always do cleanups)
3086 local $SIG { INT
} = $SIG { TERM
} = $SIG { QUIT
} = $SIG { HUP
} = sub {
3087 print STDERR
"got interrupt - ignored \n " ;
3092 local $SIG { INT
} = $SIG { TERM
} = $SIG { QUIT
} = $SIG { HUP
} = $SIG { PIPE
} = sub {
3093 die "interrupted by signal \n " ;
3096 if ( $archive eq '-' ) {
3097 print "extracting archive from STDIN \n " ;
3098 run_command
( $cmd, input
=> "<&STDIN" );
3100 print "extracting archive ' $archive ' \n " ;
3104 return if $opts ->{ info
};
3108 my $statfile = " $tmpdir/qmrestore .stat" ;
3109 if ( my $fd = IO
:: File-
> new ( $statfile, "r" )) {
3110 while ( defined ( my $line = < $fd >)) {
3111 if ( $line =~ m/vzdump:([^\s:]*):(\S+)$/ ) {
3112 $map ->{ $1 } = $2 if $1 ;
3114 print STDERR
"unable to parse line in statfile - $line\n " ;
3120 my $confsrc = " $tmpdir/qemu -server.conf" ;
3122 my $srcfd = new IO
:: File
( $confsrc, "r" ) ||
3123 die "unable to open file ' $confsrc ' \n " ;
3125 my $outfd = new IO
:: File
( $tmpfn, "w" ) ||
3126 die "unable to write config for VM $vmid\n " ;
3130 while ( defined ( my $line = < $srcfd >)) {
3131 next if $line =~ m/^\#vzdump\#/ ;
3132 next if $line =~ m/^lock:/ ;
3133 next if $line =~ m/^unused\d+:/ ;
3135 if (( $line =~ m/^(vlan(\d+)):\s*(\S+)\s*$/ )) {
3136 # try to convert old 1.X settings
3137 my ( $id, $ind, $ethcfg ) = ( $1, $2, $3 );
3138 foreach my $devconfig ( PVE
:: Tools
:: split_list
( $ethcfg )) {
3139 my ( $model, $macaddr ) = split ( /\=/ , $devconfig );
3140 $macaddr = PVE
:: Tools
:: random_ether_addr
() if ! $macaddr || $opts ->{ unique
};
3143 bridge
=> "vmbr $ind " ,
3144 macaddr
=> $macaddr,
3146 my $netstr = print_net
( $net );
3147 print $outfd "net${netcount}: $netstr\n " ;
3150 } elsif (( $line =~ m/^(net\d+):\s*(\S+)\s*$/ ) && ( $opts ->{ unique
})) {
3151 my ( $id, $netstr ) = ( $1, $2 );
3152 my $net = parse_net
( $netstr );
3153 $net ->{ macaddr
} = PVE
:: Tools
:: random_ether_addr
() if $net ->{ macaddr
};
3154 $netstr = print_net
( $net );
3155 print $outfd " $id : $netstr\n " ;
3156 } elsif ( $line =~ m/^((ide|scsi|virtio)\d+):\s*(\S+)\s*$/ ) {
3159 if ( $line =~ m/backup=no/ ) {
3160 print $outfd "# $line " ;
3161 } elsif ( $virtdev && $map ->{ $virtdev }) {
3162 my $di = PVE
:: QemuServer
:: parse_drive
( $virtdev, $value );
3163 $di ->{ file
} = $map ->{ $virtdev };
3164 $value = PVE
:: QemuServer
:: print_drive
( $vmid, $di );
3165 print $outfd " $virtdev : $value\n " ;
3183 restore_cleanup
( " $tmpdir/qmrestore .stat" ) if ! $opts ->{ info
};
3190 rename $tmpfn, $conffile ||
3191 die "unable to commit configuration file ' $conffile ' \n " ;