the old code was way too broad here, this fixes at least the
following issues:
- importing of other/unconfigured zpools by "import -a"
- possible false positives if a pool name is a substring of
another pool name because of "list" without pool name,
potentially skipping activation for such pools
- not noticing failure to activate in activate_storage
because the success of "zpool import -a" does not tell us
anything about the pool we actually wanted to import
checking specifically for the pool to be activated when
calling "zpool list" gets rid of the second issue, and
trying to import only that pool fixes the other two.
if ($method eq 'zpool_list') {
push @$cmd, 'zpool', 'list';
if ($method eq 'zpool_list') {
push @$cmd, 'zpool', 'list';
+ } elsif ($method eq 'zpool_import') {
+ push @$cmd, 'zpool', 'import';
} else {
push @$cmd, 'zfs', $method;
}
} else {
push @$cmd, 'zfs', $method;
}
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;
- my @param = ('-o', 'name', '-H');
-
- my $text = $class->zfs_request($scfg, undef, 'zpool_list', @param);
-
# Note: $scfg->{pool} can include dataset <pool>/<dataset>
my $pool = $scfg->{pool};
$pool =~ s!/.*$!!;
# Note: $scfg->{pool} can include dataset <pool>/<dataset>
my $pool = $scfg->{pool};
$pool =~ s!/.*$!!;
- if ($text !~ $pool) {
- run_command("zpool import -d /dev/disk/by-id/ -a");
+ my @param = ('-o', 'name', '-H', "$pool");
+ my $res;
+ eval {
+ $res = $class->zfs_request($scfg, undef, 'zpool_list', @param);
+ };
+
+ if ($@ || !defined($res) || $res !~ $pool) {
+ eval {
+ @param = ('-d', '/dev/disk/by-id/', "$pool");
+ $class->zfs_request($scfg, undef, 'zpool_import', @param);
+ };
+ die "could not activate storage '$storeid', $@\n" if $@;