my $msg = '';
my $output = sub { $msg .= "$_[0]\n" };
- $timeout = PVE::RPCEnvironment->is_worker() ? 60*60 : 5 if !$timeout;
+ if (PVE::RPCEnvironment->is_worker()) {
+ $timeout = 60*60 if !$timeout;
+ $timeout = 60*5 if $timeout < 60*5;
+ } else {
+ $timeout = 10 if !$timeout;
+ }
run_command($cmd, errmsg => "zfs error", outfunc => $output, timeout => $timeout);
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 $zfs_list = $class->zfs_list_zvol($scfg);
+
my $res = [];
- if (my $dat = $cache->{zfs}->{$zfspool}) {
+ if (my $dat = $zfs_list) {
foreach my $image (keys %$dat) {
sub zfs_list_zvol {
my ($class, $scfg) = @_;
- my $text = $class->zfs_request($scfg, 10, 'list', '-o', 'name,volsize,origin,type,refquota', '-t', 'volume,filesystem', '-Hrp');
+ my $text = $class->zfs_request(
+ $scfg,
+ 10,
+ 'list',
+ '-o',
+ 'name,volsize,origin,type,refquota',
+ '-t',
+ 'volume,filesystem',
+ '-Hrp',
+ $scfg->{pool},
+ );
my $zvols = zfs_parse_zvol_list($text);
return undef if !$zvols;
my $list = ();
foreach my $zvol (@$zvols) {
- my $pool = $zvol->{pool};
+ # 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+)$/){
$parent = $1;
}
- $list->{$pool}->{$name} = {
+ $list->{$name} = {
name => $name,
size => $zvol->{size},
parent => $parent,
sub zfs_get_sorted_snapshot_list {
my ($class, $scfg, $volname, $sort_params) = @_;
+ my @params = ('-H', '-r', '-t', 'snapshot', '-o', 'name', $sort_params->@*);
+
my $vname = ($class->parse_volname($volname))[1];
+ push @params, "$scfg->{pool}\/$vname";
- my @params = ('-H', '-t', 'snapshot', '-o', 'name', $sort_params->@*, "$scfg->{pool}\/$vname");
my $text = $class->zfs_request($scfg, undef, 'list', @params);
my @snapshots = split(/\n/, $text);
sub volume_snapshot_info {
my ($class, $scfg, $storeid, $volname) = @_;
+ my @params = ('-Hp', '-r', '-t', 'snapshot', '-o', 'name,guid,creation');
+
my $vname = ($class->parse_volname($volname))[1];
+ push @params, "$scfg->{pool}\/$vname";
- my @params = ('-Hp', '-t', 'snapshot', '-o', 'name,guid,creation', "$scfg->{pool}\/$vname");
my $text = $class->zfs_request($scfg, undef, 'list', @params);
my @lines = split(/\n/, $text);
die "internal error: invalid file handle for volume_import\n"
if !defined($fd);
- my (undef, $dataset, $vmid) = $class->parse_volname($volname);
+ my (undef, $dataset, $vmid, undef, undef, undef, $volume_format) =
+ $class->parse_volname($volname);
+
my $zfspath = "$scfg->{pool}/$dataset";
my $suffix = defined($base_snapshot) ? "\@$base_snapshot" : '';
my $exists = 0 == run_command(['zfs', 'get', '-H', 'name', $zfspath.$suffix],
} elsif ($exists) {
die "volume '$zfspath' already exists\n" if !$allow_rename;
warn "volume '$zfspath' already exists - importing with a different name\n";
- $dataset = $class->find_free_diskname($storeid, $scfg, $vmid, $format);
+ $dataset = $class->find_free_diskname($storeid, $scfg, $vmid, $volume_format);
$zfspath = "$scfg->{pool}/$dataset";
}