Skip to content

Commit 3bda869

Browse files
committed
nvmeof: add disconnection step in undoStagingTransaction()
In case of NodeStageVolume got an issue, undoStagingTransaction should be run and roll back everything the NodeStageVolume did. disconnection (if last mount) operation is added. Signed-off-by: gadi-didi <gadi.didi@ibm.com>
1 parent d614570 commit 3bda869

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

internal/nvmeof/nodeserver/nodeserver.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ func (ns *NodeServer) stageTransaction(
485485
return transaction, nil
486486
}
487487

488+
// undoStagingTransaction rolls back a staging transaction based on the state of the transaction.
489+
// It attempts to unmount the staging path if it was mounted,
490+
// remove the staging path if it was created, and disconnect the NVMe device if it was connected
491+
// and it was the last mount for that device.
488492
func (ns *NodeServer) undoStagingTransaction(
489493
ctx context.Context,
490494
req *csi.NodeStageVolumeRequest,
@@ -497,8 +501,7 @@ func (ns *NodeServer) undoStagingTransaction(
497501
err = ns.Mounter.Unmount(stagingTargetPath)
498502
if err != nil {
499503
log.ErrorLog(ctx, "failed to unmount stagingtargetPath: %s with error: %v", stagingTargetPath, err)
500-
501-
return
504+
// Continue anyway - try to clean up what we can
502505
}
503506
}
504507

@@ -510,6 +513,18 @@ func (ns *NodeServer) undoStagingTransaction(
510513
// continue on failure to disconnect the image
511514
}
512515
}
516+
// disconnect if we connected
517+
if transaction.devicePath != "" {
518+
mountedDevices, err := getNVMeMountedDevices(ctx)
519+
if err != nil {
520+
log.WarningLog(ctx, "failed to get mounted devices during rollback: %v (skipping disconnect)", err)
521+
} else {
522+
if err := ns.initiator.DisconnectIfLastMount(ctx, transaction.devicePath, mountedDevices); err != nil {
523+
log.WarningLog(ctx, "failed to disconnect during rollback for device %s: %v",
524+
transaction.devicePath, err)
525+
}
526+
}
527+
}
513528
}
514529

515530
// createTargetMountPath check if the mountPath already has something mounted

0 commit comments

Comments
 (0)