zfspoolplugin: check if imported before importing

This commit is a small performance optimization to the previous one:
`zpool list` is cheaper than `zpool import -d /dev..` (the latter
scans the disks in the provided directory for zfs signatures,
unconditionally)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
This commit is contained in:
Stoiko Ivanov
2021-02-19 13:45:44 +01:00
committed by Thomas Lamprecht
parent 56a7637adb
commit e74b9dd79d

View File

@ -556,6 +556,7 @@ sub activate_storage {
}; };
if (!$dataset_mounted->()) { if (!$dataset_mounted->()) {
if (!$pool_imported->()) {
# import can only be done if not yet imported! # import can only be done if not yet imported!
my @param = ('-d', '/dev/disk/by-id/', '-o', 'cachefile=none', $pool); my @param = ('-d', '/dev/disk/by-id/', '-o', 'cachefile=none', $pool);
eval { $class->zfs_request($scfg, undef, 'zpool_import', @param) }; eval { $class->zfs_request($scfg, undef, 'zpool_import', @param) };
@ -563,6 +564,7 @@ sub activate_storage {
# just could've raced with another import, so recheck if it is imported # just could've raced with another import, so recheck if it is imported
die "could not activate storage '$storeid', $err\n" if !$pool_imported->(); die "could not activate storage '$storeid', $err\n" if !$pool_imported->();
} }
}
eval { $class->zfs_request($scfg, undef, 'mount', '-a') }; eval { $class->zfs_request($scfg, undef, 'mount', '-a') };
die "could not activate storage '$storeid', $@\n" if $@; die "could not activate storage '$storeid', $@\n" if $@;
} }