[pve-devel] [PATCH storage 2/5] move check for existing clones into own method

Dietmar Maurer dietmar at proxmox.com
Wed Sep 14 17:16:16 CEST 2016


I am  a bit unhappy with the function name:
  
> +sub volume_is_referenced_base {
> +    my ($cfg, $volid) = @_;
> +
> +    my ($storeid, $volname) = parse_volume_id($volid);
> +    my $scfg = storage_config($cfg, $storeid);
> +    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
> +
> +    my ($vtype, $name, $vmid, undef, undef, $isBase, undef) =
> +	$plugin->parse_volname($volname);
> +
> +    if ($isBase) {

return 1;

The following test is something completely different, and test
if a base volume is used.

> +	my $vollist = $plugin->list_images($storeid, $scfg);
> +	foreach my $info (@$vollist) {
> +	    my (undef, $tmpvolname) = parse_volume_id($info->{volid});
> +	    my $basename = undef;
> +	    my $basevmid = undef;
> +
> +	    eval{
> +		(undef, undef, undef, $basename, $basevmid) =
> +		    $plugin->parse_volname($tmpvolname);
> +	    };
> +
> +	    if ($basename && defined($basevmid) && $basevmid == $vmid && $basename
> eq $name) {
> +		return $tmpvolname;
> +	    }
> +	}
> +    }
> +    return undef;
> +}
> +
>  # try to map a filesystem path to a volume identifier
>  sub path_to_volume_id {
>      my ($cfg, $path) = @_;
> @@ -673,26 +703,12 @@ sub vdisk_free {
>      # lock shared storage
>      $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
>  
> -	my ($vtype, $name, $vmid, undef, undef, $isBase, $format) =
> +	my $clonevolname = volume_is_referenced_base($cfg, $volid);
> +	die "base volume '$volname' is still in use (by '$clonevolname')\n"
> +	    if $clonevolname;
> +
> +	my (undef, undef, undef, undef, undef, $isBase, $format) =
>  	    $plugin->parse_volname($volname);
> -	if ($isBase) {
> -	    my $vollist = $plugin->list_images($storeid, $scfg);
> -	    foreach my $info (@$vollist) {
> -		my (undef, $tmpvolname) = parse_volume_id($info->{volid});
> -		my $basename = undef;
> -		my $basevmid = undef;
> -
> -		eval{
> -		    (undef, undef, undef, $basename, $basevmid) =
> -			$plugin->parse_volname($tmpvolname);
> -		};
> -
> -		if ($basename && defined($basevmid) && $basevmid == $vmid && $basename eq
> $name) {
> -		    die "base volume '$volname' is still in use " .
> -			"(used by '$tmpvolname')\n";
> -		}
> -	    }
> -	}
>  	$cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase,
> $format);
>      });
>  
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list