Skip to content

Commit 0560f96

Browse files
committed
nvmeof: adding namespace masking calls
added 3 grpc calls: 1. `NameSpaceAddHost()` - which is adding hostNQN for specific namespace (by given ns-id). 2. `NameSpaceRemoveHost()` - which is removing hostNQN for specific namespace (by given ns-id). 3. `NameSpaceChangeAutoVisibility()` - for adding host into specific namespace the namespace should be first non-auto-visible. So this called is added too. Signed-off-by: gadi-didi <gadi.didi@ibm.com>
1 parent d6f0ea8 commit 0560f96

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

internal/nvmeof/nvmeof.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,95 @@ func (gw *GatewayRpcClient) DeleteNamespace(ctx context.Context, subsystemNQN st
186186
}
187187
}
188188

189+
// NamespaceAddHost adds a host to a namespace (makes it accessible to the host).
190+
func (gw *GatewayRpcClient) NamespaceAddHost(
191+
ctx context.Context,
192+
subsystemNQN, hostNQN string,
193+
namespaceID uint32,
194+
) error {
195+
log.DebugLog(ctx, "Adding host %s access to namespace %d in subsystem %s", hostNQN, namespaceID, subsystemNQN)
196+
197+
req := &pb.NamespaceAddHostReq{
198+
SubsystemNqn: subsystemNQN,
199+
HostNqn: hostNQN,
200+
Nsid: namespaceID,
201+
}
202+
203+
status, err := gw.client.NamespaceAddHost(ctx, req)
204+
if err != nil {
205+
return fmt.Errorf("failed to add host access to namespace %d: %w", namespaceID, err)
206+
}
207+
if status.GetStatus() != 0 {
208+
return fmt.Errorf("gateway NamespaceAddHost returned error (status=%d): %s",
209+
status.GetStatus(), status.GetErrorMessage())
210+
}
211+
log.DebugLog(ctx, "Host access added successfully to namespace %d", namespaceID)
212+
213+
return nil
214+
}
215+
216+
// NameSpaceRemoveHost removes a host from a namespace (makes it inaccessible to the host).
217+
func (gw *GatewayRpcClient) NameSpaceRemoveHost(
218+
ctx context.Context,
219+
subsystemNQN, hostNqn string,
220+
namespaceID uint32,
221+
) error {
222+
log.DebugLog(ctx, "Removing host %s access to namespace %d in subsystem %s", hostNqn, namespaceID, subsystemNQN)
223+
224+
req := &pb.NamespaceDeleteHostReq{
225+
SubsystemNqn: subsystemNQN,
226+
HostNqn: hostNqn,
227+
Nsid: namespaceID,
228+
}
229+
230+
status, err := gw.client.NamespaceDeleteHost(ctx, req)
231+
if err != nil {
232+
return fmt.Errorf("failed to remove host access to namespace %d: %w", namespaceID, err)
233+
}
234+
if status.GetStatus() != 0 {
235+
return fmt.Errorf("gateway NamespaceDeleteHost returned error (status=%d): %s",
236+
status.GetStatus(), status.GetErrorMessage())
237+
}
238+
log.DebugLog(ctx, "Host access removed successfully from namespace %d", namespaceID)
239+
240+
return nil
241+
}
242+
243+
// NameSpaceChangeAutoVisibility changes the auto visibility setting of a namespace.
244+
// If this setting is true, the namespace will be automatically visible to
245+
// all hosts that have access to the subsystem where it resides.
246+
// If this setting is false, the namespace will not be visible to any host until it is manually made visible
247+
// via NameSpaceAddHost.
248+
//
249+
// (prerequisite: the host also needs to be added to the subsystem OR the subsystem open to any host).
250+
func (gw *GatewayRpcClient) NameSpaceChangeAutoVisibility(
251+
ctx context.Context,
252+
subsystemNQN string,
253+
namespaceID uint32,
254+
autoVisibility bool,
255+
) error {
256+
log.DebugLog(ctx, "Changing auto visibility of namespace %d in subsystem %s to %t",
257+
namespaceID, subsystemNQN, autoVisibility)
258+
259+
req := &pb.NamespaceChangeVisibilityReq{
260+
SubsystemNqn: subsystemNQN,
261+
Nsid: namespaceID,
262+
AutoVisible: autoVisibility,
263+
}
264+
265+
status, err := gw.client.NamespaceChangeVisibility(ctx, req)
266+
if err != nil {
267+
return fmt.Errorf("failed to change auto visibility of namespace %d: %w", namespaceID, err)
268+
}
269+
if status.GetStatus() != 0 {
270+
return fmt.Errorf("gateway NamespaceChangeVisibility returned error (status=%d): %s",
271+
status.GetStatus(), status.GetErrorMessage())
272+
}
273+
log.DebugLog(ctx, "Auto visibility changed successfully for namespace %d", namespaceID)
274+
275+
return nil
276+
}
277+
189278
// SetQoSLimitsForNamespace sets QoS limits on a namespace.
190279
func (gw *GatewayRpcClient) SetQoSLimitsForNamespace(
191280
ctx context.Context,

0 commit comments

Comments
 (0)