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 <noreply@anthropic.com>
This commit is contained in:
Kevin Adams 2026-05-23 22:28:26 -04:00
parent 835648fd69
commit c6f662b88c
1 changed files with 7 additions and 2 deletions

View File

@ -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";