[pve-devel] [PATCH 07/12] create_disk : implement pending change

Alexandre Derumier aderumier at odiso.com
Thu Oct 30 13:40:28 CET 2014


on vm update
   we create the disk and always set the it as unused after create
   and we register it also in device pending change

   [CONF]

   qm set 110 -virtio0 local:1

   [CONF]
   unused0: vm-disk-100-1.raw
   [PENDING]
   virtio0: vm-disk-100-1.raw

on vm create
   we simply register the disk in config like before

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

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 4541dbb..9c28eb5 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -102,7 +102,7 @@ my $check_storage_access_clone = sub {
 # Note: $pool is only needed when creating a VM, because pool permissions
 # are automatically inherited if VM already exists inside a pool.
 my $create_disks = sub {
-    my ($rpcenv, $authuser, $conf, $storecfg, $vmid, $pool, $settings, $default_storage) = @_;
+    my ($rpcenv, $authuser, $conf, $storecfg, $vmid, $pool, $settings, $default_storage, $update) = @_;
 
     my $vollist = [];
 
@@ -167,7 +167,18 @@ my $create_disks = sub {
 
     # modify vm config if everything went well
     foreach my $ds (keys %$res) {
-	$conf->{$ds} = $res->{$ds};
+	if($update){
+	    #set as unused. #fixme ? set it as unusused before try to free image on error ?
+	    my $drive = PVE::QemuServer::parse_drive($ds, $res->{$ds});
+	    my $volid = $drive->{file};
+	    if($volid && $volid ne 'none' && $volid ne 'cdrom'){
+		PVE::QemuServer::add_unused_volume($conf, $volid);
+	    }
+	    #set pending
+	    $conf->{pending}->{$ds} = $res->{$ds};
+	}else{
+	    $conf->{$ds} = $res->{$ds};
+	}
     }
 
     return $vollist;
-- 
1.7.10.4




More information about the pve-devel mailing list