Skip to content

Commit e288497

Browse files
Fix NVMe subsystem disconnect logic
Signed-off-by: Meghna Singh <ms73385@netapp.com>
1 parent f36d8b3 commit e288497

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

frontend/csi/node_server.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,17 +3480,16 @@ func (p *Plugin) disconnectNVMeSubsystemIfNeeded(
34803480
defer locks.Unlock(ctx, lockContext, nvmeSubsystemDisconnectLock)
34813481

34823482
// Get the number of namespaces associated with the subsystem (inside lock to avoid race conditions)
3483-
numNs, err := nvmeSubsys.GetNamespaceCount(ctx)
3484-
if err != nil {
3485-
Logc(ctx).WithField(
3486-
"subsystem", publishInfo.NVMeSubsystemNQN,
3487-
).WithError(err).Debug("Error getting Namespace count.")
3488-
}
3483+
numNs := publishedNVMeSessions.GetNamespaceCountForSession(publishInfo.NVMeSubsystemNQN)
3484+
Logc(ctx).WithFields(LogFields{
3485+
"subsystem": publishInfo.NVMeSubsystemNQN,
3486+
"namespaceCount": numNs,
3487+
"disconnectFlag": disconnect,
3488+
}).Info("Checking if subsystem should be disconnected.")
34893489

3490-
// If number of namespaces is more than 1, don't disconnect the subsystem. If we get any issues while getting the
3491-
// number of namespaces through the CLI, we can rely on the disconnect flag from NVMe self-healing sessions (if
3490+
// If number of namespaces is 0, disconnect the subsystem. we can rely on the disconnect flag from NVMe self-healing sessions (if
34923491
// NVMe self-healing is enabled), which keeps track of namespaces associated with the subsystem.
3493-
if (err == nil && numNs <= 1) || (p.nvmeSelfHealingInterval > 0 && err != nil && disconnect) {
3492+
if (numNs == 0) || (p.nvmeSelfHealingInterval > 0 && disconnect) {
34943493
if err := nvmeSubsys.Disconnect(ctx); err != nil {
34953494
Logc(ctx).WithField(
34963495
"subsystem", publishInfo.NVMeSubsystemNQN,

frontend/csi/node_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12430,7 +12430,7 @@ func TestNodeUnStageVolume(t *testing.T) {
1243012430
setupNVMeHandler: func() nvme.NVMeInterface {
1243112431
mockNvmeHandler := mock_nvme.NewMockNVMeInterface(gomock.NewController(t))
1243212432
mockNvmeHandler.EXPECT().RemovePublishedNVMeSession(gomock.Any(), gomock.Any(), gomock.Any()).Return(false).AnyTimes()
12433-
mockNvmeHandler.EXPECT().NewNVMeSubsystem(gomock.Any(), gomock.Any()).Return(nvme.NewNVMeSubsystemDetailed("mock-nqn", "mock-name", []nvme.Path{{Address: "mock-address"}}, nil, afero.NewMemMapFs())).AnyTimes()
12433+
mockNvmeHandler.EXPECT().NewNVMeSubsystem(gomock.Any(), gomock.Any()).Return(nvme.NewNVMeSubsystemDetailed("mock-nqn", "mock-name", []nvme.Path{{Address: "mock-address"}}, execCmd.NewCommand(), afero.NewMemMapFs())).AnyTimes()
1243412434
return mockNvmeHandler
1243512435
},
1243612436
getDeviceClient: func() devices.Devices {

frontend/csi/plugin.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,7 @@ func (p *Plugin) Activate() error {
431431
Logc(ctx).WithError(err).Warn("Failed to clean node; self-healing features may be unreliable.")
432432
}
433433

434-
// Populate the published sessions IFF iSCSI/NVMe self-healing is enabled.
435-
if p.iSCSISelfHealingInterval > 0 || p.nvmeSelfHealingInterval > 0 {
436-
p.populatePublishedSessions(ctx)
437-
}
434+
p.populatePublishedSessions(ctx)
438435

439436
p.startISCSISelfHealingThread(ctx)
440437
p.startNVMeSelfHealingThread(ctx)

0 commit comments

Comments
 (0)