@@ -186,6 +186,106 @@ 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 %s access to namespace %d: %w" , hostNQN , namespaceID , err )
206+ }
207+ if status .GetStatus () != 0 {
208+ return fmt .Errorf ("gateway NamespaceAddHost returned error for host %s and namespace %d (status=%d): %s" ,
209+ hostNQN , namespaceID , status .GetStatus (), status .GetErrorMessage ())
210+ }
211+ log .DebugLog (ctx , "Host %s access added successfully to namespace %d" , hostNQN , 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+ // If the host access does not exist, the gateway returns ENODEV.
236+ // We can treat this as success because the desired state is that the host
237+ // does not have access to the namespace.
238+ if status .GetStatus () == int32 (syscall .ENODEV ) {
239+ log .DebugLog (ctx , "Host access for host %s to namespace %d is already absent" , hostNQN , namespaceID )
240+
241+ return nil
242+ }
243+
244+ return fmt .Errorf ("gateway NamespaceDeleteHost returned error (status=%d): %s" ,
245+ status .GetStatus (), status .GetErrorMessage ())
246+ }
247+ log .DebugLog (ctx , "Host access removed successfully from namespace %d" , namespaceID )
248+
249+ return nil
250+ }
251+
252+ // NamespaceChangeAutoVisibility changes the auto visibility setting of a namespace.
253+ // If this setting is true, the namespace will be automatically visible to
254+ // all hosts that have access to the subsystem where it resides.
255+ // If this setting is false, the namespace will not be visible to any host until it is manually made visible
256+ // via NamespaceAddHost.
257+ //
258+ // (prerequisite: the host also needs to be added to the subsystem OR the subsystem open to any host).
259+ func (gw * GatewayRpcClient ) NamespaceChangeAutoVisibility (
260+ ctx context.Context ,
261+ subsystemNQN string ,
262+ namespaceID uint32 ,
263+ autoVisibility bool ,
264+ ) error {
265+ log .DebugLog (ctx , "Changing auto visibility of namespace %d in subsystem %s to %t" ,
266+ namespaceID , subsystemNQN , autoVisibility )
267+
268+ req := & pb.NamespaceChangeVisibilityReq {
269+ SubsystemNqn : subsystemNQN ,
270+ Nsid : namespaceID ,
271+ AutoVisible : autoVisibility ,
272+ }
273+
274+ status , err := gw .client .NamespaceChangeVisibility (ctx , req )
275+ if err != nil {
276+ return fmt .Errorf ("failed to change auto visibility of namespace %d in subsystem %s to %t: %w" ,
277+ namespaceID , subsystemNQN , autoVisibility , err )
278+ }
279+ if status .GetStatus () != 0 {
280+ return fmt .Errorf ("gateway NamespaceChangeVisibility returned error" +
281+ " for namespace %d in subsystem %s with autoVisibility=%t (status=%d): %s" ,
282+ namespaceID , subsystemNQN , autoVisibility , status .GetStatus (), status .GetErrorMessage ())
283+ }
284+ log .DebugLog (ctx , "Auto visibility changed successfully for namespace %d in subsystem %s" , namespaceID , subsystemNQN )
285+
286+ return nil
287+ }
288+
189289// SetQoSLimitsForNamespace sets QoS limits on a namespace.
190290func (gw * GatewayRpcClient ) SetQoSLimitsForNamespace (
191291 ctx context.Context ,
0 commit comments