[pve-devel] [PATCH #1941 qemu-server] Clean up empty image subdirectories on dir based storage on VM destruction

Christian Ebner c.ebner at proxmox.com
Thu Jan 17 12:13:14 CET 2019


Fix #1941

Removes the empty vmid subdirectories when a VM gets destroyed and all the
contained image files are deleted.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 PVE/QemuServer.pm | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 1ccdccf..da4be85 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2502,6 +2502,8 @@ sub destroy_vm {
  	return if drive_is_cdrom($drive, 1);
 
 	my $volid = $drive->{file};
+	my $storeid = PVE::Storage::parse_volume_id($volid);
+	my $storetype = $storecfg->{ids}->{$storeid}->{type};
 
 	return if !$volid || $volid =~ m|^/|;
 
@@ -2513,6 +2515,12 @@ sub destroy_vm {
 	};
 	warn "Could not remove disk '$volid', check manually: $@" if $@;
 
+	# cleanup empty directroies on dir based storage
+	if ($storetype eq 'dir') {
+	    my $dir = dirname($path);
+	    rmdir($dir);
+	}
+
     });
 
     if ($keep_empty_config) {
-- 
2.11.0




More information about the pve-devel mailing list