zfs: move methode list_image

Signed-off-by: Wolfgang Link <w.link@proxmox.com>
This commit is contained in:
Wolfgang Link
2015-01-23 10:32:40 +01:00
committed by Dietmar Maurer
parent e9565df58e
commit ca04180f3b
2 changed files with 39 additions and 39 deletions

View File

@ -184,6 +184,45 @@ sub free_image {
return undef;
}
sub list_images {
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
$cache->{zfs} = $class->zfs_list_zvol($scfg) if !$cache->{zfs};
my $zfspool = $scfg->{pool};
my $res = [];
if (my $dat = $cache->{zfs}->{$zfspool}) {
foreach my $image (keys %$dat) {
my $volname = $dat->{$image}->{name};
my $parent = $dat->{$image}->{parent};
my $volid = undef;
if ($parent && $parent =~ m/^(\S+)@(\S+)$/) {
my ($basename) = ($1);
$volid = "$storeid:$basename/$volname";
} else {
$volid = "$storeid:$volname";
}
my $owner = $dat->{$volname}->{vmid};
if ($vollist) {
my $found = grep { $_ eq $volid } @$vollist;
next if !$found;
} else {
next if defined ($vmid) && ($owner ne $vmid);
}
my $info = $dat->{$volname};
$info->{volid} = $volid;
push @$res, $info;
}
}
return $res;
}
sub zfs_get_pool_stats {
my ($class, $scfg) = @_;

View File

@ -301,45 +301,6 @@ sub free_image {
return undef;
}
sub list_images {
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
$cache->{zfs} = $class->zfs_list_zvol($scfg) if !$cache->{zfs};
my $zfspool = $scfg->{pool};
my $res = [];
if (my $dat = $cache->{zfs}->{$zfspool}) {
foreach my $image (keys %$dat) {
my $volname = $dat->{$image}->{name};
my $parent = $dat->{$image}->{parent};
my $volid = undef;
if ($parent && $parent =~ m/^(\S+)@(\S+)$/) {
my ($basename) = ($1);
$volid = "$storeid:$basename/$volname";
} else {
$volid = "$storeid:$volname";
}
my $owner = $dat->{$volname}->{vmid};
if ($vollist) {
my $found = grep { $_ eq $volid } @$vollist;
next if !$found;
} else {
next if defined ($vmid) && ($owner ne $vmid);
}
my $info = $dat->{$volname};
$info->{volid} = $volid;
push @$res, $info;
}
}
return $res;
}
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;
return 1;