]> git.proxmox.com Git - pve-storage.git/commitdiff
zfspoolplugin: check if imported before importing
authorStoiko Ivanov <s.ivanov@proxmox.com>
Fri, 19 Feb 2021 12:45:44 +0000 (13:45 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 19 Feb 2021 13:22:43 +0000 (14:22 +0100)
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>
PVE/Storage/ZFSPoolPlugin.pm

index a52451591ca6d2a1cbd44cb99e718b23088a32a5..4806ba5afdf4d651207a345293e2a2783b1a390c 100644 (file)
@@ -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 $@;