[pve-devel] [PATCH] Change zfs path when link clone are used

Wolfgang Link w.link at proxmox.com
Mon Mar 21 16:12:10 CET 2016


The new naming is coherent to Dir plugin.

So if we make an licked clone the parent will be coded in the path of the storage.
---
 PVE/Storage/ZFSPoolPlugin.pm | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index 9f76cee..83b6bf7 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -151,7 +151,7 @@ sub path {
 	    # fixme: we currently assume standard mount point?!
 	    $path = "/$scfg->{pool}/$volname";
 	} else {
-	    $path = "/dev/zvol/$scfg->{pool}/$volname";
+	    $path = "/dev/zvol/$scfg->{pool}/$name";
 	}
 	$path .= "\@$snapname" if defined($snapname);
     } else {
@@ -402,6 +402,8 @@ sub zfs_find_free_diskname {
 sub zfs_get_latest_snapshot {
     my ($class, $scfg, $volname) = @_;
 
+    my $vname = ($class->parse_volname($volname))[1];
+
     # abort rollback if snapshot is not the latest
     my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
     my $text = $class->zfs_request($scfg, undef, 'list', @params);
@@ -409,7 +411,7 @@ sub zfs_get_latest_snapshot {
 
     my $recentsnap;
     foreach (@snapshots) {
-        if (/$scfg->{pool}\/$volname/) {
+        if (/$scfg->{pool}\/$vname/) {
             s/^.*@//;
             $recentsnap = $_;
         }
@@ -439,11 +441,11 @@ sub status {
 sub volume_size_info {
     my ($class, $scfg, $storeid, $volname, $timeout) = @_;
 
-    my (undef, undef, undef, undef, undef, undef, $format) =
+    my (undef, $vname, undef, undef, undef, undef, $format) =
         $class->parse_volname($volname);
 
     my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
-    my $text = $class->zfs_request($scfg, undef, 'get', '-Hp', $attr, "$scfg->{pool}/$volname");
+    my $text = $class->zfs_request($scfg, undef, 'get', '-Hp', $attr, "$scfg->{pool}/$vname");
 
     if ($text =~ /\s$attr\s(\d+)\s/) {
 	return $1;
@@ -455,20 +457,26 @@ sub volume_size_info {
 sub volume_snapshot {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
-    $class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$volname\@$snap");
+    my $vname = ($class->parse_volname($volname))[1];
+
+    $class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$vname\@$snap");
 }
 
 sub volume_snapshot_delete {
     my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
 
-    $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
-    $class->zfs_request($scfg, undef, 'destroy', "$scfg->{pool}/$volname\@$snap");
+    my $vname = ($class->parse_volname($volname))[1];
+
+    $class->deactivate_volume($storeid, $scfg, $vname, $snap, {});
+    $class->zfs_request($scfg, undef, 'destroy', "$scfg->{pool}/$vname\@$snap");
 }
 
 sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
-    $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
+    my $vname = ($class->parse_volname($volname))[1];
+
+    $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$vname\@$snap");
 }
 
 sub volume_rollback_is_possible {
@@ -528,7 +536,7 @@ sub clone_image {
 
     $class->zfs_request($scfg, undef, 'clone', "$scfg->{pool}/$basename\@$snap", "$scfg->{pool}/$name");
 
-    return $name;
+    return "$basename/$name";
 }
 
 sub create_base {
@@ -560,12 +568,12 @@ sub volume_resize {
 
     my $new_size = int($size/1024);
 
-    my (undef, undef, undef, undef, undef, undef, $format) =
+    my (undef, $vname, undef, undef, undef, undef, $format) =
         $class->parse_volname($volname);
 
     my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
 
-    $class->zfs_request($scfg, undef, 'set', "$attr=${new_size}k", "$scfg->{pool}/$volname");
+    $class->zfs_request($scfg, undef, 'set', "$attr=${new_size}k", "$scfg->{pool}/$vname");
 
     return $new_size;
 }
-- 
2.1.4





More information about the pve-devel mailing list