Skip to content

Commit 4292a1c

Browse files
author
Elliot Li
committed
Fix the multipath device discovering logic that a stale device may be found in sysfs, causing NodeUnstage failed.
Change-Id: I231d3cf9913e07947b3bf3e61591296f8373ac78
1 parent 32d798c commit 4292a1c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

utils/iscsi.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ func (h *IscsiReconcileHelper) GetMultipathDeviceDisks(ctx context.Context, mult
501501

502502
// GetMultipathDeviceBySerial find DM device whose UUID /sys/block/dmX/dm/uuid contains serial in hex format.
503503
func (h *IscsiReconcileHelper) GetMultipathDeviceBySerial(ctx context.Context, hexSerial string) (string, error) {
504-
sysPath := chrootPathPrefix + "/sys/block/"
504+
var (
505+
sysPath = chrootPathPrefix + "/sys/block/"
506+
multipathCMDTimeout = 10 * time.Second
507+
)
505508

506509
blockDirs, err := os.ReadDir(sysPath)
507510
if err != nil {
@@ -525,13 +528,27 @@ func (h *IscsiReconcileHelper) GetMultipathDeviceBySerial(ctx context.Context, h
525528
continue
526529
}
527530

528-
if strings.Contains(uuid, hexSerial) {
531+
if !strings.Contains(uuid, hexSerial) {
532+
continue
533+
}
534+
535+
// Use 'multipath -l' and check the exit code. A success return
536+
// indicates that it is a not a stale device. Noted that frequently
537+
// running this in a busy environment may time out, and lead to a
538+
// situation that the device is not properly discovered. But it will
539+
// fail the following operations and retries next time.
540+
if _, err := command.ExecuteWithTimeout(ctx, "multipath", multipathCMDTimeout, true, "-l", dmDeviceName); err != nil {
529541
Logc(ctx).WithFields(LogFields{
530-
"UUID": hexSerial,
531-
"multipathDevice": dmDeviceName,
532-
}).Debug("Found multipath device by UUID.")
533-
return dmDeviceName, nil
542+
"device": dmDeviceName,
543+
}).WithError(err).Warn("Candidate is not a valid map known to multipathd, ignoring stale entry.")
544+
continue
534545
}
546+
547+
Logc(ctx).WithFields(LogFields{
548+
"UUID": hexSerial,
549+
"multipathDevice": dmDeviceName,
550+
}).Debug("Found multipath device by UUID.")
551+
return dmDeviceName, nil
535552
}
536553

537554
return "", errors.NotFoundError("no multipath device found")

0 commit comments

Comments
 (0)