[pve-devel] [PATCH] complete parse_volname in ZFSPoolPlugin

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Mar 18 09:57:16 CET 2016


On Fri, Mar 18, 2016 at 09:06:45AM +0100, Wolfgang Link wrote:
> No the plugin also returns the parent vmid and base volume when a link clone is used
> ---
>  PVE/Storage.pm               |  2 +-
>  PVE/Storage/ZFSPoolPlugin.pm | 17 +++++++++++++++--
>  2 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index e7ff5a0..3c233d3 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -295,7 +295,7 @@ sub parse_volname {
>  
>      # returns ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format)
>  
> -    return $plugin->parse_volname($volname);
> +    return $plugin->parse_volname($volname, $cfg->{ids}->{$storeid}->{pool});
>  }
>  
>  sub parse_volume_id {
> diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
> index 9f76cee..05920aa 100644
> --- a/PVE/Storage/ZFSPoolPlugin.pm
> +++ b/PVE/Storage/ZFSPoolPlugin.pm
> @@ -127,11 +127,24 @@ sub zfs_parse_zvol_list {
>  }
>  
>  sub parse_volname {
> -    my ($class, $volname) = @_;
> +    my ($class, $volname, $pool) = @_;
>  
>      if ($volname =~ m/^(((base|vm)-(\d+)-\S+)\/)?((base)?(vm|subvol)?-(\d+)-\S+)$/) {
***mark***

>  	my $format = $7 && $7 eq 'subvol' ? 'subvol' : 'raw';
> -	return ('images', $5, $8, $2, $4, $6, $format);
> +
> +	my $base;
> +	my $vmid;
> +	if ($pool) {
> +	    my $cfg = PVE::Cluster::cfs_read_file("storage.cfg");
> +	    my $res = zfs_request($class, $cfg, undef, 'get', ('-H', 'origin', "$pool\/$volname"));
> +
> +	    $base = $1 ne '-' ? $1 : undef if $res =~ m/\s+origin\s+(\S+)\s+/;
> +
> +	    if ($base) {
> +		$vmid = $1 ne '-' ? $1 : undef if $base =~ m/-(\d+)-disk-\d+/;
> +	    }
> +	}
> +	return ('images', $5, $8, $base, $vmid, $6, $format);

So $5, $6 and $8 refer to the marked regex above while in between there
are other regexes replacing $1. Feels... weird... :-\

>      }
>  
>      die "unable to parse zfs volume name '$volname'\n";
> -- 
> 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