Skip to content

Commit c036cb5

Browse files
gadididimergify[bot]
authored andcommitted
nvmeof: fix DeleteNamespace to be idempotent
add another case, if the subsystem of the rquested ns (that we want to remove) does not exist, dont raise an error. Signed-off-by: gadi-didi <gadi.didi@ibm.com>
1 parent 982f093 commit c036cb5

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

internal/nvmeof/nvmeof.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,26 @@ func (gw *GatewayRpcClient) DeleteNamespace(ctx context.Context, subsystemNQN st
158158
if err != nil {
159159
return fmt.Errorf("failed to delete namespace %d: %w", namespaceID, err)
160160
}
161-
if status.GetStatus() == 0 {
161+
switch {
162+
case status.GetStatus() == 0:
162163
log.DebugLog(ctx, "Namespace deleted successfully: %d", namespaceID)
163164

164165
return nil
165-
}
166-
if status.GetStatus() == int32(syscall.ENOENT) { // ENOENT
167-
log.DebugLog(ctx, "Namespace %d already deleted (not found)", namespaceID)
168166

169-
return nil // Namespace already deleted, no error
170-
}
167+
case status.GetStatus() == int32(syscall.ENOENT):
168+
log.DebugLog(ctx, "The subsystem %s that contains namespace %d already deleted (not found)",
169+
subsystemNQN, namespaceID)
171170

172-
return fmt.Errorf("gateway NamespaceDelete returned error (status=%d): %s",
173-
status.GetStatus(), status.GetErrorMessage())
171+
return nil // Subsystem (and Namespace) are already deleted, no error
172+
case status.GetStatus() == int32(syscall.ENODEV):
173+
log.DebugLog(ctx, "The namespace %d already deleted (not found)",
174+
subsystemNQN, namespaceID)
175+
176+
return nil // Namespace is already deleted, no error
177+
default:
178+
return fmt.Errorf("gateway NamespaceDelete returned error (status=%d): %s",
179+
status.GetStatus(), status.GetErrorMessage())
180+
}
174181
}
175182

176183
// SetQoSLimitsForNamespace sets QoS limits on a namespace.
@@ -271,6 +278,8 @@ func (gw *GatewayRpcClient) CreateSubsystem(ctx context.Context, subsystemNQN, n
271278
return fmt.Errorf("failed to create subsystem %s: %w", subsystemNQN, err)
272279
case status.GetStatus() == int32(syscall.EEXIST):
273280
// subsystem was already created
281+
log.DebugLog(ctx, "Subsystem %s already exists", subsystemNQN)
282+
274283
return nil
275284
case status.GetStatus() != 0:
276285
return fmt.Errorf("gateway CreateSubsystem returned error: %s", status.GetErrorMessage())

0 commit comments

Comments
 (0)