[pve-devel] [PATCH 2/2] Improve parsing of zfs volumes (ZVOLs) in order to avoid filtering of zvols nested under another ZFS dataset.

Pablo Ruiz García pablo.ruiz at gmail.com
Sun Feb 23 00:00:43 CET 2014


From: Pablo Ruiz Garcia <pablo.ruiz at gmail.com>

The actual code would only accept zvols like: POOL/vm-123-disk-1.
However, using POOL/DataSet/vm-123-disk-1 allows setting specific
proparties at POOL/DataSet level (like compression, etc.) which
would be inherited by any zvol created under such DataSet.

This allows more flexibility of zfs/zvol's management.

Signed-off-by: Pablo Ruiz García <pablo.ruiz at gmail.com>
---
 PVE/Storage/ZFSPlugin.pm |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm
index e89b131..873d67a 100644
--- a/PVE/Storage/ZFSPlugin.pm
+++ b/PVE/Storage/ZFSPlugin.pm
@@ -156,23 +156,22 @@ sub zfs_parse_zvol_list {
     foreach my $line (@lines) {
     if ($line =~ /^(.+)\s+([a-zA-Z0-9\.]+|\-)\s+(.+)$/) {
         my $zvol = {};
-        my $name;
-        my $disk;
-        my @zvols = split /\//, $1;
-        my $pool = $zvols[0];
-
-        if (scalar(@zvols) == 2 && $zvols[0] !~ /^rpool$/) {
-        $disk = $zvols[1];
-        next unless $disk =~ m!^(\w+)-(\d+)-(\w+)-(\d+)$!;
-        $name = $pool . '/' . $disk;
+        my @parts = split /\//, $1;
+        my $name = pop @parts;
+        my $pool = join('/', @parts);
+
+        if ($pool !~ /^rpool$/) {
+            next unless $name =~ m!^(\w+)-(\d+)-(\w+)-(\d+)$!;
+            $name = $pool . '/' . $name;
         } else {
-        next;
+            next;
         }
 
+        $zvol->{pool} = $pool;
         $zvol->{name} = $name;
         $zvol->{size} = zfs_parse_size($2);
         if ($3 !~ /^-$/) {
-        $zvol->{origin} = $3;
+            $zvol->{origin} = $3;
         }
         push @$list, $zvol;
     }
@@ -276,7 +275,7 @@ sub zfs_get_lun_number {
 sub zfs_list_zvol {
     my ($scfg) = @_;
 
-    my $text = zfs_request($scfg, 10, 'list', '-o', 'name,volsize,origin', '-Hr');
+    my $text = zfs_request($scfg, 10, 'list', '-o', 'name,volsize,origin', '-t', 'volume', '-Hr');
     my $zvols = zfs_parse_zvol_list($text);
     return undef if !$zvols;
 
@@ -284,8 +283,8 @@ sub zfs_list_zvol {
     foreach my $zvol (@$zvols) {
     my @values = split('/', $zvol->{name});
 
-    my $pool = $values[0];
-    my $image = $values[1];
+    my $image = pop @values;
+    my $pool = join('/', @values);
 
     next if $image !~ m/^((vm|base)-(\d+)-\S+)$/;
     my $owner = $3;
-- 
1.7.1




More information about the pve-devel mailing list