-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
CreateNVMeSubsystem RPC #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,7 @@ func NVMeControllerConnect(id int64, trAddr string, subnqn string, trSvcID int64 | |
return nil | ||
} | ||
log.Printf("Remote NVMf controller is already connected with SubNQN: %v", data.GetCtrl().Subnqn) | ||
|
||
defer disconnectConnection() | ||
return nil | ||
} | ||
|
@@ -225,6 +226,68 @@ func NVMeControllerDisconnect(id int64) error { | |
return nil | ||
} | ||
|
||
// ExposeRemoteNVMe creates a new NVMe Subsystem and NVMe controller | ||
func ExposeRemoteNVMe(subsystemID string, subsystemNQN string, maxNamespaces int64, controllerID string) error { | ||
if conn == nil { | ||
err := dialConnection() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
|
||
client := pb.NewFrontendNvmeServiceClient(conn) | ||
data1, err := client.GetNVMeSubsystem(ctx, &pb.GetNVMeSubsystemRequest{SubsystemId: &pbc.ObjectKey{Value: subsystemID}}) | ||
if err != nil { | ||
log.Printf("No existing NVMe Subsystem found with subsystemID: %v", subsystemID) | ||
} | ||
|
||
if data1 == nil { | ||
response1, err := client.CreateNVMeSubsystem(ctx, &pb.CreateNVMeSubsystemRequest{ | ||
Subsystem: &pb.NVMeSubsystem{ | ||
Spec: &pb.NVMeSubsystemSpec{ | ||
Id: &pbc.ObjectKey{Value: subsystemID}, | ||
Nqn: subsystemNQN, | ||
MaxNamespaces: maxNamespaces, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
log.Printf("NVMe Subsytem created: %v", response1) | ||
} else { | ||
log.Printf("NVMe Subsystem is already present with the subsytemID: %v", subsystemID) | ||
} | ||
|
||
data2, err := client.GetNVMeController(ctx, &pb.GetNVMeControllerRequest{ControllerId: &pbc.ObjectKey{Value: controllerID}}) | ||
if err != nil { | ||
log.Printf("No existing NVMe Controller found with controllerID %v:", controllerID) | ||
} | ||
if data2 == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why such a big There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if condition is when the controller is not found corresponding to the given controllerID and thus we create a new NVMe controller. In case the controller is found, we are just logging that in line 287 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what I say is just reverse the condition and return first...
do
|
||
response2, err := client.CreateNVMeController(ctx, &pb.CreateNVMeControllerRequest{ | ||
Controller: &pb.NVMeController{ | ||
Spec: &pb.NVMeControllerSpec{ | ||
Id: &pbc.ObjectKey{Value: controllerID}, | ||
SubsystemId: &pbc.ObjectKey{Value: subsystemID}, | ||
MaxNamespaces: int32(maxNamespaces), | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Println(err) | ||
return err | ||
} | ||
log.Printf("NVMe Controller created: %v", response2) | ||
return nil | ||
} | ||
log.Printf("NVMe Controller is already present with the controllerID: %v", controllerID) | ||
return nil | ||
} | ||
|
||
// CreateNVMeNamespace Creates a new NVMe namespace | ||
func CreateNVMeNamespace(id string, subSystemID string, nguid string, hostID int32) (string, error) { | ||
if conn == nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should generate subsystemID here using, for example
uuid.New()
user of the library should not care about IDs... he is only aware of NQN...