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

Wolfgang Link w.link at proxmox.com
Fri Mar 18 09:06:45 CET 2016


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





More information about the pve-devel mailing list