From e31f33763500d72af59f74423dfa2c1829bab797 Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Fri, 20 Oct 2023 19:05:03 +0300 Subject: [PATCH] fix(store): add gomap to handle NQNs This is temp handler until gokv will add GetAll() Signed-off-by: Boris Glimcher --- pkg/frontend/frontend.go | 2 ++ pkg/frontend/nvme_subsystem.go | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/frontend/frontend.go b/pkg/frontend/frontend.go index c9cd0b42..48e29228 100644 --- a/pkg/frontend/frontend.go +++ b/pkg/frontend/frontend.go @@ -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 @@ -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, diff --git a/pkg/frontend/nvme_subsystem.go b/pkg/frontend/nvme_subsystem.go index 9ff0b163..5039d228 100644 --- a/pkg/frontend/nvme_subsystem.go +++ b/pkg/frontend/nvme_subsystem.go @@ -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) } } @@ -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 @@ -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