Skip to content

Commit

Permalink
fix(store): add gomap to handle NQNs
Browse files Browse the repository at this point in the history
This is temp handler until gokv will add GetAll()

Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Oct 20, 2023
1 parent b0f53e6 commit e31f337
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type Server struct {
pb.UnimplementedFrontendNvmeServiceServer
VirtioCtrls map[string]*pb.VirtioBlk
NQNs map[string]bool
Pagination map[string]int
store gokv.Store
rpc spdk.JSONRPC
Expand All @@ -34,6 +35,7 @@ func NewServer(jsonRPC spdk.JSONRPC, store gokv.Store) *Server {
}
return &Server{
VirtioCtrls: make(map[string]*pb.VirtioBlk),
NQNs: make(map[string]bool),
Pagination: make(map[string]int),
store: store,
rpc: jsonRPC,
Expand Down
9 changes: 6 additions & 3 deletions pkg/frontend/nvme_subsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (s *Server) CreateNvmeSubsystem(ctx context.Context, in *pb.CreateNvmeSubsy
return subsys, nil
}
// check if another object exists with same NQN, it is not allowed
for _, item := range s.Subsystems {
if in.NvmeSubsystem.Spec.Nqn == item.Spec.Nqn {
msg := fmt.Sprintf("Could not create NQN: %s since object %s with same NQN already exists", in.NvmeSubsystem.Spec.Nqn, item.Name)
for nqn := range s.NQNs {
if in.NvmeSubsystem.Spec.Nqn == nqn {
msg := fmt.Sprintf("Could not create NQN: %s since object with same NQN already exists", nqn)
return nil, status.Errorf(codes.AlreadyExists, msg)
}
}
Expand Down Expand Up @@ -88,6 +88,8 @@ func (s *Server) CreateNvmeSubsystem(ctx context.Context, in *pb.CreateNvmeSubsy
log.Printf("Received from SPDK: %v", ver)
response := utils.ProtoClone(in.NvmeSubsystem)
response.Status = &pb.NvmeSubsystemStatus{FirmwareRevision: ver.Version}
// save object to the database
s.NQNs[in.NvmeSubsystem.Spec.Nqn] = false
err = s.store.Set(in.NvmeSubsystem.Name, response)
if err != nil {
return nil, err
Expand Down Expand Up @@ -128,6 +130,7 @@ func (s *Server) DeleteNvmeSubsystem(ctx context.Context, in *pb.DeleteNvmeSubsy
return nil, status.Errorf(codes.InvalidArgument, msg)
}
// remove from the Database
delete(s.NQNs, subsys.Spec.Nqn)
err = s.store.Delete(subsys.Name)
if err != nil {
return nil, err
Expand Down

0 comments on commit e31f337

Please sign in to comment.