From e74b9dd79d12f0e796db30b4d1f7cb1c4d02f08a Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Fri, 19 Feb 2021 13:45:44 +0100 Subject: [PATCH] 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 --- PVE/Storage/ZFSPoolPlugin.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm index a524515..4806ba5 100644 --- a/PVE/Storage/ZFSPoolPlugin.pm +++ b/PVE/Storage/ZFSPoolPlugin.pm @@ -556,12 +556,14 @@ sub activate_storage { }; if (!$dataset_mounted->()) { - # import can only be done if not yet imported! - my @param = ('-d', '/dev/disk/by-id/', '-o', 'cachefile=none', $pool); - eval { $class->zfs_request($scfg, undef, 'zpool_import', @param) }; - if (my $err = $@) { - # just could've raced with another import, so recheck if it is imported - die "could not activate storage '$storeid', $err\n" if !$pool_imported->(); + if (!$pool_imported->()) { + # import can only be done if not yet imported! + my @param = ('-d', '/dev/disk/by-id/', '-o', 'cachefile=none', $pool); + eval { $class->zfs_request($scfg, undef, 'zpool_import', @param) }; + if (my $err = $@) { + # just could've raced with another import, so recheck if it is imported + die "could not activate storage '$storeid', $err\n" if !$pool_imported->(); + } } eval { $class->zfs_request($scfg, undef, 'mount', '-a') }; die "could not activate storage '$storeid', $@\n" if $@; -- 2.39.2