]> git.proxmox.com Git - qemu-server.git/commitdiff
implement trivial hotplug
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 17 Nov 2014 08:50:31 +0000 (09:50 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 7 Jan 2015 05:42:27 +0000 (06:42 +0100)
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
PVE/QemuServer.pm

index 8f3eb3da5dc08a56f3d97967f123c64daf882f02..f77da3b9bcab6a7d1acd9c9fff92cd2d4dda4b7a 100644 (file)
@@ -3547,11 +3547,56 @@ sub set_migration_caps {
     vm_mon_cmd_nocheck($vmid, "migrate-set-capabilities", capabilities => $cap_ref);
 }
 
+sub vmconfig_hotplug_pending {
+    my ($vmid, $conf, $storecfg) = @_;
+
+    my $defaults = PVE::QemuServer::load_defaults();
+
+    # commit values which do not have any impact on running VM first
+
+    my $changes = 0;
+    foreach my $opt (keys %{$conf->{pending}}) { # add/change
+       if ($opt eq 'name' || $opt eq 'hotplug' || $opt eq 'onboot' || $opt eq 'shares') {
+           $conf->{$opt} = $conf->{pending}->{$opt};
+           delete $conf->{pending}->{$opt};
+           $changes = 1;
+       }
+    }
+
+    if ($changes) {
+       update_config_nolock($vmid, $conf, 1);
+       $conf = load_config($vmid); # update/reload
+    }
+
+    $changes = 0;
+
+    # allow manual ballooning if shares is set to zero
+
+    if (defined($conf->{pending}->{balloon}) && defined($conf->{shares}) && ($conf->{shares} == 0)) {
+       my $balloon = $conf->{pending}->{balloon} || $conf->{memory} || $defaults->{memory};
+       vm_mon_cmd($vmid, "balloon", value => $balloon*1024*1024);
+       $conf->{balloon} = $conf->{pending}->{balloon};
+       delete $conf->{pending}->{balloon};
+       $changes = 1;
+    }
+
+    if ($changes) {
+       update_config_nolock($vmid, $conf, 1);
+       $conf = load_config($vmid); # update/reload
+    }
+
+    return if !$conf->{hotplug};
+
+    # fixme: implement disk/network hotplug here
+
+}
 
 sub vmconfig_apply_pending {
     my ($vmid, $conf, $storecfg, $running) = @_;
 
-    die "implement me - vm is running" if $running; # fixme: if $conf->{hotplug};
+    return vmconfig_hotplug_pending($vmid, $conf, $storecfg) if $running;
+
+    # cold plug
 
     my @delete = PVE::Tools::split_list($conf->{pending}->{delete});
     foreach my $opt (@delete) { # delete