[pve-devel] [PATCH storage v2 3/3] zfspoolplugin: check if imported before importing
Stoiko Ivanov
s.ivanov at proxmox.com
Fri Feb 19 13:45:44 CET 2021
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 at proxmox.com>
---
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.20.1
More information about the pve-devel
mailing list