]> git.proxmox.com Git - pve-storage.git/commitdiff
fix #585: remove leftover disks/directory after VM creation failed
authorChristian Ebner <c.ebner@proxmox.com>
Mon, 4 Mar 2019 15:47:06 +0000 (16:47 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 5 Mar 2019 09:36:51 +0000 (10:36 +0100)
When trying to create a qcow2 disk image with a size larger than available on the
storage, this will fail.
As qemu-img does not clean up the disk afterwards, it needs to be deleted
explicitly. Further, the vmid folder is cleaned up once it is empty.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
PVE/Storage/GlusterfsPlugin.pm
PVE/Storage/Plugin.pm

index 1f9465fda42cd193c9bda0718bfe958c890279bc..b3e5553416474eb812c4299c4b220c7ab43a422e 100644 (file)
@@ -274,7 +274,12 @@ sub alloc_image {
 
     push @$cmd, '-f', $fmt, $volumepath, "${size}K";
 
-    run_command($cmd, errmsg => "unable to create image");
+    eval { run_command($cmd, errmsg => "unable to create image"); };
+    if ($@) {
+       unlink $path;
+       rmdir $imagedir;
+       die "$@";
+    }
 
     return "$vmid/$name";
 }
index 10c2c734a2263c6abeb4fa7555f0fa6f1e7164bb..796444124b43c5fbc0b41ff59c6a4043ce002b6c 100644 (file)
@@ -665,7 +665,12 @@ sub alloc_image {
        
        push @$cmd, '-f', $fmt, $path, "${size}K";
 
-       run_command($cmd, errmsg => "unable to create image");
+       eval { run_command($cmd, errmsg => "unable to create image"); };
+       if ($@) {
+           unlink $path;
+           rmdir $imagedir;
+           die "$@";
+       }
     }
     
     return "$vmid/$name";