From c6f662b88ce9f40e84c2581dd0e81fd7d961453e Mon Sep 17 00:00:00 2001 From: Kevin Adams Date: Sat, 23 May 2026 22:28:26 -0400 Subject: [PATCH] fix: rescan iSCSI session in _wait_for_device to discover new LUNs After TrueNAS reloads its iSCSI service, the PVE host's existing session does not automatically pick up new LUNs. Adding iscsiadm --rescan every 5s during the device wait loop lets the kernel discover newly exported LUNs without requiring a full session logout/login. Fixes the 30s hotplug timeout seen when adding a disk to a running VM. Co-Authored-By: Claude Sonnet 4.6 --- perl5/PVE/Storage/Custom/TrueNAS.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/perl5/PVE/Storage/Custom/TrueNAS.pm b/perl5/PVE/Storage/Custom/TrueNAS.pm index 3c95f04..3e9f1c4 100644 --- a/perl5/PVE/Storage/Custom/TrueNAS.pm +++ b/perl5/PVE/Storage/Custom/TrueNAS.pm @@ -307,12 +307,17 @@ sub _dev_path { return "/dev/disk/by-path/ip-${portal}:3260-iscsi-${iqn}-lun-${lun_id}"; } -# Waits up to $timeout seconds for a block device node to appear +# Waits up to $timeout seconds for a block device node to appear. +# Rescans the iSCSI session periodically so the kernel discovers new LUNs +# that were added after the session was established. sub _wait_for_device { my ($dev_path, $timeout) = @_; $timeout //= 30; - for (1 .. $timeout) { + for my $i (1 .. $timeout) { return 1 if -b $dev_path; + # Rescan at t=1, 6, 11, 16 … to pick up newly exported LUNs + eval { run_command(['iscsiadm', '-m', 'session', '--rescan'], noerr => 1) } + if $i % 5 == 1; sleep 1; } die "Timed out after ${timeout}s waiting for device $dev_path\n";