[pve-devel] applied: [PATCH storage] fix #585: remove leftover disks/directory after VM creation failed

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Mar 5 13:40:31 CET 2019


On 3/4/19 4:47 PM, Christian Ebner wrote:
> 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 at proxmox.com>
> ---
>  PVE/Storage/GlusterfsPlugin.pm | 7 ++++++-
>  PVE/Storage/Plugin.pm          | 7 ++++++-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/PVE/Storage/GlusterfsPlugin.pm b/PVE/Storage/GlusterfsPlugin.pm
> index 1f9465f..b3e5553 100644
> --- a/PVE/Storage/GlusterfsPlugin.pm
> +++ b/PVE/Storage/GlusterfsPlugin.pm
> @@ -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";
>  }
> diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
> index 10c2c73..7964441 100644
> --- a/PVE/Storage/Plugin.pm
> +++ b/PVE/Storage/Plugin.pm
> @@ -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";
> 

applied, thanks!



More information about the pve-devel mailing list