From 6f072aaaa82fd549ebf202673cc2256827b2c6d5 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 27 Oct 2023 13:42:46 +0200 Subject: [PATCH] iscsi: always recheck if iscsiadm binary is available this avoids the need for restarting all services that have pve-storage modules loaded after the admin installed open-iscsi. while at it make it a bit more clear that this might die by using assert in the method name. Signed-off-by: Thomas Lamprecht --- src/PVE/Storage/ISCSIPlugin.pm | 45 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index b4ab1dd..8b6cc87 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -16,35 +16,30 @@ use base qw(PVE::Storage::Plugin); # iscsi helper function my $ISCSIADM = '/usr/bin/iscsiadm'; -$ISCSIADM = undef if ! -X $ISCSIADM; -# Example: 192.168.122.252:3260,1 iqn.2003-01.org.linux-iscsi.proxmox-nfs.x8664:sn.00567885ba8f -my $ISCSI_TARGET_RE = qr/^((?:$IPV4RE|\[$IPV6RE\]):\d+)\,\S+\s+(\S+)\s*$/; +my $found_iscsi_adm_exe; +my sub assert_iscsi_support { + my ($noerr) = @_; + return $found_iscsi_adm_exe if $found_iscsi_adm_exe; # assume it won't be removed if ever found -sub check_iscsi_support { - my $noerr = shift; + $found_iscsi_adm_exe = -x $ISCSIADM; - if (!$ISCSIADM) { - my $msg = "no iscsi support - please install open-iscsi"; - if ($noerr) { - warn "warning: $msg\n"; - return 0; - } - - die "error: $msg\n"; + if (!$found_iscsi_adm_exe) { + die "error: no iscsi support - please install open-iscsi\n" if !$noerr; + warn "warning: no iscsi support - please install open-iscsi\n"; } - - return 1; + return $found_iscsi_adm_exe; } -sub iscsi_session_list { +# Example: 192.168.122.252:3260,1 iqn.2003-01.org.linux-iscsi.proxmox-nfs.x8664:sn.00567885ba8f +my $ISCSI_TARGET_RE = qr/^((?:$IPV4RE|\[$IPV6RE\]):\d+)\,\S+\s+(\S+)\s*$/; - check_iscsi_support (); +sub iscsi_session_list { + assert_iscsi_support(); my $cmd = [$ISCSIADM, '--mode', 'session']; my $res = {}; - eval { run_command($cmd, errmsg => 'iscsi session scan failed', outfunc => sub { my $line = shift; @@ -75,7 +70,7 @@ sub iscsi_test_portal { sub iscsi_portals { my ($target, $portal_in) = @_; - check_iscsi_support (); + assert_iscsi_support(); my $res = []; my $cmd = [$ISCSIADM, '--mode', 'node']; @@ -103,7 +98,7 @@ sub iscsi_portals { sub iscsi_discovery { my ($portals) = @_; - check_iscsi_support (); + assert_iscsi_support(); my $res = {}; for my $portal ($portals->@*) { @@ -133,7 +128,7 @@ sub iscsi_discovery { sub iscsi_login { my ($target, $portals) = @_; - check_iscsi_support(); + assert_iscsi_support(); eval { iscsi_discovery($portals); }; warn $@ if $@; @@ -144,7 +139,7 @@ sub iscsi_login { sub iscsi_logout { my ($target) = @_; - check_iscsi_support(); + assert_iscsi_support(); run_command([$ISCSIADM, '--mode', 'node', '--targetname', $target, '--logout']); } @@ -154,7 +149,7 @@ my $rescan_filename = "/var/run/pve-iscsi-rescan.lock"; sub iscsi_session_rescan { my $session_list = shift; - check_iscsi_support(); + assert_iscsi_support(); my $rstat = stat($rescan_filename); @@ -416,7 +411,7 @@ sub status { sub activate_storage { my ($class, $storeid, $scfg, $cache) = @_; - return if !check_iscsi_support(1); + return if !assert_iscsi_support(1); my $sessions = iscsi_session($cache, $scfg->{target}); my $portals = iscsi_portals($scfg->{target}, $scfg->{portal}); @@ -446,7 +441,7 @@ sub activate_storage { sub deactivate_storage { my ($class, $storeid, $scfg, $cache) = @_; - return if !check_iscsi_support(1); + return if !assert_iscsi_support(1); if (defined(iscsi_session($cache, $scfg->{target}))) { iscsi_logout($scfg->{target}); -- 2.39.2