[pve-devel] [PATCH 05/12] delete_drive : implement pending change

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


if disk is unused:
 we delete it from conf, and also delete it from pending in case of a previous pending add

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

 #qm set 100 -delete unused0

 [CONF]
 [PENDING]

else
  if vm is running
       we register the disk in $conf->{pending}->{del}->{$key} = 1;

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

       #qm set 100 -delete virtio0

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

  else
       we simply put the disk as unused like before

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

       #qm set 100 -delete virtio0

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

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm  |   16 ++++++++++++++--
 PVE/QemuServer.pm |   12 ++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 40f6eb4..4541dbb 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -688,6 +688,8 @@ my $is_hotpluggable = sub {
 my $delete_drive = sub {
     my ($conf, $storecfg, $vmid, $key, $drive, $force) = @_;
 
+    my $running = PVE::QemuServer::check_running($vmid);
+
     if (!PVE::QemuServer::drive_is_cdrom($drive)) {
 	my $volid = $drive->{file};
 
@@ -702,17 +704,27 @@ my $delete_drive = sub {
 			if $used_paths->{$path};
 
 		    PVE::Storage::vdisk_free($storecfg, $volid);
+		    delete $conf->{$key};
+		    #delete if the disk also exist in pending
+        	    PVE::QemuServer::del_volume($conf->{pending}, $volid, $storecfg);
+
+
 		};
 		die $@ if $@;
 	    } else {
-		PVE::QemuServer::add_unused_volume($conf, $volid, $vmid);
+		    if($running){
+			$conf->{pending}->{del}->{$key} = 1;
+		    }else{
+			PVE::QemuServer::add_unused_volume($conf, $volid);
+			delete $conf->{$key};
+		    }
 	    }
 	}
     }
 
-    delete $conf->{$key};
 };
 
+
 my $vmconfig_delete_option = sub {
     my ($rpcenv, $authuser, $conf, $storecfg, $vmid, $opt, $force) = @_;
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 4916b8f..bf099b2 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1389,6 +1389,18 @@ sub add_unused_volume {
     return $key;
 }
 
+sub del_volume {
+    my ($conf, $volid, $storecfg) = @_;
+
+    foreach my $key (keys %$conf) {
+        my $confdrive = PVE::QemuServer::parse_drive($key, $conf->{$key});
+        if (!PVE::QemuServer::drive_is_cdrom($confdrive)) {
+            PVE::QemuServer::cleanup_drive_path($key, $storecfg, $confdrive);
+	    delete $conf->{$key} if $confdrive->{file} eq $volid;
+        }
+    }
+}
+
 my $valid_smbios1_options = {
     manufacturer => '\S+',
     product => '\S+',
-- 
1.7.10.4




More information about the pve-devel mailing list