]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
reenable steal time
[qemu-server.git] / PVE / QemuServer.pm
index 8b6da2fcc108c981be84901f114f7a180f177e97..81f05843efdbbf681bb4be474d445bb5bc92269f 100644 (file)
@@ -558,7 +558,7 @@ my $serialdesc = {
        description =>  <<EODESCR,
 Create a serial device inside the VM (n is 0 to 3), and pass through a host serial device (i.e. /dev/ttyS0), or create a unix socket on the host side (use 'qm terminal' to open a terminal connection).
 
-Note: This option allows direct access to host hardware. So it is no longer possible to migrate such machines - use with special care.
+Note: If you pass through a host serial device, it is no longer possible to migrate such machines - use with special care.
 
 Experimental: user reported problems with this option.
 EODESCR
@@ -1257,7 +1257,7 @@ sub print_netdevice_full {
 }
 
 sub print_netdev_full {
-    my ($vmid, $conf, $net, $netid) = @_;
+    my ($vmid, $conf, $net, $netid, $hotplug) = @_;
 
     my $i = '';
     if ($netid =~ m/^net(\d+)$/) {
@@ -1278,9 +1278,10 @@ sub print_netdev_full {
     my $vmname = $conf->{name} || "vm$vmid";
 
     my $netdev = "";
+    my $script = $hotplug ? "pve-bridge-hotplug" : "pve-bridge";
 
     if ($net->{bridge}) {
-        $netdev = "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/pve-bridge,downscript=/var/lib/qemu-server/pve-bridgedown$vhostparam";
+        $netdev = "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/$script,downscript=/var/lib/qemu-server/pve-bridgedown$vhostparam";
     } else {
         $netdev = "type=user,id=$netid,hostname=$vmname";
     }
@@ -2157,6 +2158,8 @@ sub check_local_resources {
 
     foreach my $k (keys %$conf) {
        next if $k =~ m/^usb/ && ($conf->{$k} eq 'spice');
+       # sockets are safe: they will recreated be on the target side post-migrate
+       next if $k =~ m/^serial/ && ($conf->{$k} eq 'socket');
        $loc_res = 1 if $k =~ m/^(usb|hostpci|serial|parallel)\d+$/;
     }
 
@@ -2643,6 +2646,8 @@ sub config_to_command {
     my $q35 = machine_type_is_q35($conf);
     my $hotplug_features = parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
     my $machine_type = $forcemachine || $conf->{machine};
+    my $use_old_bios_files = undef;
+    ($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type);
 
     my $cpuunits = defined($conf->{cpuunits}) ?
             $conf->{cpuunits} : $defaults->{cpuunits};
@@ -2651,26 +2656,15 @@ sub config_to_command {
     push @$cmd, '--scope';
     push @$cmd, '--slice', "qemu";
     push @$cmd, '--unit', $vmid;
+    # set KillMode=none, so that systemd don't kill those scopes
+    # at shutdown (pve-manager service should stop the VMs instead)
+    push @$cmd, '-p', "KillMode=none";
     push @$cmd, '-p', "CPUShares=$cpuunits";
     if ($conf->{cpulimit}) {
        my $cpulimit = int($conf->{cpulimit} * 100);
        push @$cmd, '-p', "CPUQuota=$cpulimit\%";
     }
 
-
-    my $use_old_bios_files = undef;
-
-    if ($machine_type && $machine_type =~ m/^(\S+)\.pxe$/){
-       $machine_type = $1;
-       $use_old_bios_files = 1;
-    } else {
-       # Note: kvm version < 2.4 use non-efi pxe files, and have problems when we
-       # load new efi bios files on migration. So this hack is required to allow
-       # live migration from qemu-2.2 to qemu-2.4, which is sometimes used when
-       # updrading from proxmox-ve-3.X to proxmox-ve 4.0
-       $use_old_bios_files = !qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 4);
-    }
-
     push @$cmd, '/usr/bin/kvm';
 
     push @$cmd, '-id', $vmid;
@@ -2928,7 +2922,6 @@ sub config_to_command {
 
        push @$cpuFlags , '+kvm_pv_unhalt' if !$nokvm;
        push @$cpuFlags , '+kvm_pv_eoi' if !$nokvm;
-        push @$cpuFlags , '-kvm_steal_time' if !$nokvm;
     }
 
     push @$cpuFlags, 'enforce' if $cpu ne 'host' && !$nokvm;
@@ -3349,7 +3342,12 @@ sub vm_deviceplug {
     } elsif ($deviceid =~ m/^(net)(\d+)$/) {
 
         return undef if !qemu_netdevadd($vmid, $conf, $device, $deviceid);
-        my $netdevicefull = print_netdevice_full($vmid, $conf, $device, $deviceid);
+
+        my $machine_type = PVE::QemuServer::qemu_machine_pxe($vmid, $conf); 
+        my $use_old_bios_files = undef;
+        ($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type);
+
+        my $netdevicefull = print_netdevice_full($vmid, $conf, $device, $deviceid, undef, $use_old_bios_files);
         qemu_deviceadd($vmid, $netdevicefull);
         eval { qemu_deviceaddverify($vmid, $deviceid); };
        if (my $err = $@) {
@@ -3606,7 +3604,7 @@ sub qemu_set_link_status {
 sub qemu_netdevadd {
     my ($vmid, $conf, $device, $deviceid) = @_;
 
-    my $netdev = print_netdev_full($vmid, $conf, $device, $deviceid);
+    my $netdev = print_netdev_full($vmid, $conf, $device, $deviceid, 1);
     my %options =  split(/[=,]/, $netdev);
 
     vm_mon_cmd($vmid, "netdev_add",  %options);
@@ -6161,6 +6159,9 @@ sub qemu_img_convert {
     my ($dst_storeid, $dst_volname) = PVE::Storage::parse_volume_id($dst_volid, 1);
 
     if ($src_storeid && $dst_storeid) {
+
+       PVE::Storage::activate_volumes($storecfg, [$src_volid], $snapname);
+
        my $src_scfg = PVE::Storage::storage_config($storecfg, $src_storeid);
        my $dst_scfg = PVE::Storage::storage_config($storecfg, $dst_storeid);
 
@@ -6365,6 +6366,43 @@ sub qemu_machine_feature_enabled {
 
 }
 
+sub qemu_machine_pxe {
+    my ($vmid, $conf, $machine) = @_;
+
+    $machine =  PVE::QemuServer::get_current_qemu_machine($vmid) if !$machine;
+
+    foreach my $opt (keys %$conf) {
+       next if $opt !~ m/^net(\d+)$/;
+       my $net = PVE::QemuServer::parse_net($conf->{$opt});
+       next if !$net;
+       my $romfile = PVE::QemuServer::vm_mon_cmd_nocheck($vmid, 'qom-get', path => $opt, property => 'romfile');
+       return $machine.".pxe" if $romfile =~ m/pxe/;
+       last;
+    }
+
+}
+
+sub qemu_use_old_bios_files {
+    my ($machine_type) = @_;
+
+    return if !$machine_type;
+
+    my $use_old_bios_files = undef;
+
+    if ($machine_type =~ m/^(\S+)\.pxe$/) {
+        $machine_type = $1;
+        $use_old_bios_files = 1;
+    } else {
+        # Note: kvm version < 2.4 use non-efi pxe files, and have problems when we
+        # load new efi bios files on migration. So this hack is required to allow
+        # live migration from qemu-2.2 to qemu-2.4, which is sometimes used when
+        # updrading from proxmox-ve-3.X to proxmox-ve 4.0
+        $use_old_bios_files = !qemu_machine_feature_enabled ($machine_type, undef, 2, 4);
+    }
+
+    return ($use_old_bios_files, $machine_type);
+}
+
 sub lspci {
 
     my $devices = {};
@@ -6476,6 +6514,7 @@ sub complete_storage {
     my $res = [];
     foreach my $sid (keys %$ids) {
        next if !PVE::Storage::storage_check_enabled($cfg, $sid, undef, 1);
+       next if !$ids->{$sid}->{content}->{images};
        push @$res, $sid;
     }