Skip to content

Commit 9af58c4

Browse files
gadididimergify[bot]
authored andcommitted
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 b1013db commit 9af58c4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

internal/nvmeof/nodeserver/nodeserver.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ func (ns *NodeServer) NodeExpandVolume(
421421
log.DebugLog(ctx, "nvmeof: resizing filesystem on device %s at mount path %s", devicePath, mountPath)
422422

423423
resizer := mount.NewResizeFs(utilexec.New())
424-
var ok bool
425424
ok, err := resizer.Resize(devicePath, mountPath)
426425
if !ok {
427426
return nil, status.Errorf(codes.Internal,
@@ -493,6 +492,10 @@ func (ns *NodeServer) stageTransaction(
493492
return transaction, nil
494493
}
495494

495+
// undoStagingTransaction rolls back a staging transaction based on the state of the transaction.
496+
// It attempts to unmount the staging path if it was mounted,
497+
// remove the staging path if it was created, and disconnect the NVMe device if it was connected
498+
// and it was the last mount for that device.
496499
func (ns *NodeServer) undoStagingTransaction(
497500
ctx context.Context,
498501
req *csi.NodeStageVolumeRequest,
@@ -505,8 +508,7 @@ func (ns *NodeServer) undoStagingTransaction(
505508
err = ns.Mounter.Unmount(stagingTargetPath)
506509
if err != nil {
507510
log.ErrorLog(ctx, "failed to unmount stagingtargetPath: %s with error: %v", stagingTargetPath, err)
508-
509-
return
511+
// Continue anyway - try to clean up what we can
510512
}
511513
}
512514

@@ -518,6 +520,18 @@ func (ns *NodeServer) undoStagingTransaction(
518520
// continue on failure to disconnect the image
519521
}
520522
}
523+
// disconnect if we connected
524+
if transaction.devicePath != "" {
525+
mountedDevices, err := getNVMeMountedDevices(ctx)
526+
if err != nil {
527+
log.WarningLog(ctx, "failed to get mounted devices during rollback: %v (skipping disconnect)", err)
528+
} else {
529+
if err := ns.initiator.DisconnectIfLastMount(ctx, transaction.devicePath, mountedDevices); err != nil {
530+
log.WarningLog(ctx, "failed to disconnect during rollback for device %s: %v",
531+
transaction.devicePath, err)
532+
}
533+
}
534+
}
521535
}
522536

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

0 commit comments

Comments
 (0)