fix #585: remove leftover disks/directory after VM creation failed

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>
This commit is contained in:
Christian Ebner
2019-03-04 16:47:06 +01:00
committed by Thomas Lamprecht
parent deea35a2e7
commit a8ec2f0227
2 changed files with 12 additions and 2 deletions

View 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";
}

View 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";