# static zfs helper methods
sub zfs_parse_zvol_list {
- my ($text) = @_;
+ my ($text, $pool) = @_;
my $list = ();
my @parts = split /\//, $dataset;
next if scalar(@parts) < 2; # we need pool/name
my $name = pop @parts;
- my $pool = join('/', @parts);
+ my $parsed_pool = join('/', @parts);
+ next if $parsed_pool ne $pool;
next unless $name =~ m!^(vm|base|subvol|basevol)-(\d+)-(\S+)$!;
$zvol->{owner} = $2;
- $zvol->{pool} = $pool;
$zvol->{name} = $name;
if ($type eq 'filesystem') {
if ($refquota eq 'none') {
sub list_images {
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
- $cache->{zfs}->{$storeid} = $class->zfs_list_zvol($scfg)
- if !$cache->{zfs}->{$storeid};
+ my $zfs_list = $class->zfs_list_zvol($scfg);
my $res = [];
- if (my $dat = $cache->{zfs}->{$storeid}) {
+ for my $info (values $zfs_list->%*) {
+ my $volname = $info->{name};
+ my $parent = $info->{parent};
+ my $owner = $info->{vmid};
- foreach my $image (keys %$dat) {
-
- my $info = $dat->{$image};
-
- my $volname = $info->{name};
- my $parent = $info->{parent};
- my $owner = $info->{vmid};
-
- if ($parent && $parent =~ m/^(\S+)\@__base__$/) {
- my ($basename) = ($1);
- $info->{volid} = "$storeid:$basename/$volname";
- } else {
- $info->{volid} = "$storeid:$volname";
- }
-
- if ($vollist) {
- my $found = grep { $_ eq $info->{volid} } @$vollist;
- next if !$found;
- } else {
- next if defined ($vmid) && ($owner ne $vmid);
- }
+ if ($parent && $parent =~ m/^(\S+)\@__base__$/) {
+ my ($basename) = ($1);
+ $info->{volid} = "$storeid:$basename/$volname";
+ } else {
+ $info->{volid} = "$storeid:$volname";
+ }
- push @$res, $info;
+ if ($vollist) {
+ my $found = grep { $_ eq $info->{volid} } @$vollist;
+ next if !$found;
+ } else {
+ next if defined ($vmid) && ($owner ne $vmid);
}
+
+ push @$res, $info;
}
return $res;
}
'name,volsize,origin,type,refquota',
'-t',
'volume,filesystem',
- '-Hrp',
+ '-d1',
+ '-Hp',
$scfg->{pool},
);
- my $zvols = zfs_parse_zvol_list($text);
- return undef if !$zvols;
+ # It's still required to have zfs_parse_zvol_list filter by pool, because -d1 lists
+ # $scfg->{pool} too and while unlikely, it could be named to be mistaken for a volume.
+ my $zvols = zfs_parse_zvol_list($text, $scfg->{pool});
+ return {} if !$zvols;
- my $list = ();
+ my $list = {};
foreach my $zvol (@$zvols) {
- # The "pool" in $scfg is not the same as ZFS pool, so it's necessary to filter here.
- next if $scfg->{pool} ne $zvol->{pool};
-
my $name = $zvol->{name};
my $parent = $zvol->{origin};
if($zvol->{origin} && $zvol->{origin} =~ m/^$scfg->{pool}\/(\S+)$/){