[pve-devel] [PATCH] allow only hotpluggable|dynamics options to be change online

Alexandre Derumier aderumier at odiso.com
Thu Sep 4 15:50:24 CEST 2014


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 985a9f8..e0af841 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -173,6 +173,112 @@ my $create_disks = sub {
     return $vollist;
 };
 
+
+my $hotplug_options = { onboot => 1,
+			tablet => 1,
+			hotplug => 1,
+			smbios1 => 1,
+			bootdisk => 1,
+			name => 1,
+			startup => 1,
+			cpuunits => 1,
+			freeze => 1,
+			balloon => 1,
+			shares => 1
+			};
+
+
+my $check_vm_unplug_param = sub {
+    my ($vmid, $conf, $running, $param) = @_;
+
+    return if !$running;
+
+    foreach my $opt (@$param) {
+
+        if ($opt =~ m/^net\d+$/) {
+	    raise_param_exc({ $opt => "you need to enable hotplug option for online unplug nic"}) if !$conf->{hotplug};
+	    next;
+
+	} elsif (PVE::QemuServer::valid_drivename($opt)) {
+		    
+	    raise_param_exc({ $opt => "is not a hot-unplugable disk controller"}) if ($opt =~ m/^ide\d+$/ || $opt =~ m/^sata\d+$/);
+	    raise_param_exc({ $opt => "you need to enable hotplug option for hot-unplug disk"}) if !$conf->{hotplug}; 
+	    next;
+	} elsif( $hotplug_options->{$opt}) {
+	    next;
+	} else {
+	    raise_param_exc({ $opt => "can't be changed (delete) online"}) if $conf->{$opt};
+	}
+
+    }
+
+};
+
+my $check_vm_hotplug_param = sub {
+    my ($vmid, $conf, $running, $param) = @_;
+
+    return if !$running;
+
+    my $defaults = PVE::QemuServer::load_defaults();
+
+    foreach my $opt (keys %$param) {
+
+	$conf->{$opt} = $defaults->{$opt} if !$conf->{$opt};
+
+        if ($opt =~ m/^net\d+$/) {
+
+	    my $oldnet = PVE::QemuServer::parse_net($conf->{$opt});
+	    my $newnet = PVE::QemuServer::parse_net($param->{$opt});
+
+	    if($oldnet->{model} ne $newnet->{model}){
+		raise_param_exc({ $opt => "you need to enable hotplug option for online change nic model"}) if !$conf->{hotplug};
+	    } elsif ($oldnet->{macaddr} ne $newnet->{macaddr}) {
+		raise_param_exc({ $opt => "you can't change mac address online"});
+	    } elsif ($oldnet->{queues} ne $newnet->{queues}) {
+		raise_param_exc({ $opt => "you can't change queue online"});
+            } elsif (($newnet->{bridge} && !$oldnet->{bridge}) || (!$newnet->{bridge} && $oldnet->{bridge})) {
+                raise_param_exc({ $opt => "you need to enable hotplug option to online change bridge/nat mode"}) if !$conf->{hotplug};
+            }
+	    next;
+
+	}elsif (PVE::QemuServer::valid_drivename($opt)) {
+	    my $new_drive = PVE::QemuServer::parse_drive($opt, $param->{$opt});
+
+	    #update
+	    if ($conf->{$opt}) {
+		
+		my $old_drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
+		next if PVE::QemuServer::drive_is_cdrom($old_drive) && PVE::QemuServer::drive_is_cdrom($new_drive);
+		if($old_drive->{file} ne $new_drive->{file}) {
+		    
+		    raise_param_exc({ $opt => "is not a hotplugable disk controller"}) if ($opt =~ m/^ide\d+$/ || $opt =~ m/^sata\d+$/);
+		    raise_param_exc({ $opt => "you need to enable hotplug option for online swap"}) if !$conf->{hotplug};
+		}
+		raise_param_exc({ $opt => "discard option can't be changed online"}) if $new_drive->{discard} ne $old_drive->{discard};
+		raise_param_exc({ $opt => "cache option can't be changed online"}) if $new_drive->{cache} ne $old_drive->{cache};
+
+
+	    } else { #add
+		raise_param_exc({ $opt => "is not a hotplugable disk controller"}) if ($opt =~ m/^ide\d+$/ || $opt =~ m/^sata\d+$/);
+		raise_param_exc({ $opt => "you need to enable hotplug option for hotplug"}) if !$conf->{hotplug}; 
+	    }
+	    next;
+	} elsif ( $opt eq 'cores') {
+	   raise_param_exc({ $opt => "socket need to be equal 1 to hotplug cpu"}) if $conf->{$opt} ne $param->{$opt} && $conf->{sockets} && $conf->{sockets} > 1;
+	   raise_param_exc({ $opt => "maxcpus need to be defined to hotplug cpu"}) if $conf->{$opt} ne $param->{$opt} && !$conf->{maxcpus};
+	   raise_param_exc({ $opt => "cores can't be greater than maxcpus"}) if  $param->{$opt} > $conf->{maxcpus};
+	   raise_param_exc({ $opt => "unplug cores is not possible currently"}) if  $param->{$opt} < $conf->{$opt};
+
+	} elsif ( $hotplug_options->{$opt}) {
+	    next;
+	} else {
+	    raise_param_exc({ $opt => "can't be changed online"}) if $conf->{$opt} ne $param->{$opt};
+	}
+
+    }
+
+};
+
 my $check_vm_modify_config_perm = sub {
     my ($rpcenv, $authuser, $vmid, $pool, $key_list) = @_;
 
@@ -945,10 +1051,17 @@ my $update_vm_api  = sub {
 	}
     }
 
+    my $running = PVE::QemuServer::check_running($vmid);
+    my $conf = PVE::QemuServer::load_config($vmid);
+
     &$check_vm_modify_config_perm($rpcenv, $authuser, $vmid, undef, [@delete]);
 
     &$check_vm_modify_config_perm($rpcenv, $authuser, $vmid, undef, [keys %$param]);
 
+    &$check_vm_hotplug_param($vmid, $conf, $running, $param);
+
+    &$check_vm_unplug_param($vmid, $conf, $running, [@delete]);
+
     &$check_storage_access($rpcenv, $authuser, $storecfg, $vmid, $param);
 
     my $updatefn =  sub {
-- 
1.7.10.4




More information about the pve-devel mailing list