diff --git a/README.md b/README.md index 9bbab4d6..60219b16 100644 --- a/README.md +++ b/README.md @@ -275,14 +275,14 @@ See commands ```bash $ grpc_cli ls opi-spdk-server:50051 opi_api.storage.v1.NVMeControllerService -l -filename: frontend.proto +filename: frontend_nvme_pcie.proto package: opi_api.storage.v1; service NVMeControllerService { rpc NVMeControllerCreate(opi_api.storage.v1.NVMeControllerCreateRequest) returns (opi_api.storage.v1.NVMeController) {} rpc NVMeControllerDelete(opi_api.storage.v1.NVMeControllerDeleteRequest) returns (google.protobuf.Empty) {} - rpc NVMeControllerUpdate(opi_api.storage.v1.NVMeControllerUpdateRequest) returns (opi_api.storage.v1.NVMeControllerUpdateResponse) {} + rpc NVMeControllerUpdate(opi_api.storage.v1.NVMeControllerUpdateRequest) returns (opi_api.storage.v1.NVMeController) {} rpc NVMeControllerList(opi_api.storage.v1.NVMeControllerListRequest) returns (opi_api.storage.v1.NVMeControllerListResponse) {} - rpc NVMeControllerGet(opi_api.storage.v1.NVMeControllerGetRequest) returns (opi_api.storage.v1.NVMeControllerGetResponse) {} + rpc NVMeControllerGet(opi_api.storage.v1.NVMeControllerGetRequest) returns (opi_api.storage.v1.NVMeController) {} rpc NVMeControllerStats(opi_api.storage.v1.NVMeControllerStatsRequest) returns (opi_api.storage.v1.NVMeControllerStatsResponse) {} } ``` diff --git a/client/frontend.go b/client/frontend.go index 54ad04e5..203b6c8b 100644 --- a/client/frontend.go +++ b/client/frontend.go @@ -71,7 +71,7 @@ func executeVirtioScsiLun(ctx context.Context, conn grpc.ClientConnInterface, c5 if err != nil { log.Fatalf("could not get VirtioScsi subsystem: %v", err) } - log.Printf("Got: %v", rl5.Lun.Bdev) + log.Printf("Got: %v", rl5.Bdev) rl6, err := c6.VirtioScsiLunStats(ctx, &pb.VirtioScsiLunStatsRequest{ControllerId: 8}) if err != nil { log.Fatalf("could not stats VirtioScsi subsystem: %v", err) @@ -114,7 +114,7 @@ func executeVirtioScsiController(ctx context.Context, conn grpc.ClientConnInterf if err != nil { log.Fatalf("could not get VirtioScsi subsystem: %v", err) } - log.Printf("Got: %s", rss5.Controller.Name) + log.Printf("Got: %s", rss5.Name) rss6, err := c5.VirtioScsiControllerStats(ctx, &pb.VirtioScsiControllerStatsRequest{ControllerId: 8}) if err != nil { log.Fatalf("could not stats VirtioScsi subsystem: %v", err) @@ -146,7 +146,7 @@ func executeVirtioBlk(ctx context.Context, conn grpc.ClientConnInterface) error if err != nil { log.Fatalf("could not get VirtioBlk Controller: %v", err) } - log.Printf("Got: %v", rv5.Controller.Name) + log.Printf("Got: %v", rv5.Name) rv6, err := c4.VirtioBlkStats(ctx, &pb.VirtioBlkStatsRequest{ControllerId: 8}) if err != nil { log.Fatalf("could not stats VirtioBlk Controller: %v", err) @@ -219,7 +219,7 @@ func executeNVMeNamespace(ctx context.Context, conn grpc.ClientConnInterface) er if err != nil { log.Fatalf("could not get NVMe namespace: %v", err) } - log.Printf("Got: %v", rn5.Namespace.Id.Value) + log.Printf("Got: %v", rn5.Id.Value) rn6, err := c3.NVMeNamespaceStats(ctx, &pb.NVMeNamespaceStatsRequest{NamespaceId: &pbc.ObjectKey{Value: "namespace-test"}}) if err != nil { log.Fatalf("could not stats NVMe namespace: %v", err) @@ -295,7 +295,7 @@ func executeNVMeController(ctx context.Context, conn grpc.ClientConnInterface) e if err != nil { log.Fatalf("could not get NVMe controller: %v", err) } - log.Printf("Got: %s", rc5.Controller.Id.Value) + log.Printf("Got: %s", rc5.Id.Value) rc6, err := c2.NVMeControllerStats(ctx, &pb.NVMeControllerStatsRequest{Id: &pbc.ObjectKey{Value: "controller-test"}}) if err != nil { @@ -350,7 +350,7 @@ func executeNVMeSubsystem(ctx context.Context, conn grpc.ClientConnInterface) er if err != nil { log.Fatalf("could not get NVMe subsystem: %v", err) } - log.Printf("Got: %s", rs5.Subsystem.Nqn) + log.Printf("Got: %s", rs5.Nqn) rs6, err := c1.NVMeSubsystemStats(ctx, &pb.NVMeSubsystemStatsRequest{ SubsystemId: &pbc.ObjectKey{Value: "subsystem-test"}}) if err != nil { diff --git a/client/go.mod b/client/go.mod index 4bee2eb3..600d4896 100644 --- a/client/go.mod +++ b/client/go.mod @@ -3,7 +3,7 @@ module opi.storage.v1 go 1.19 require ( - github.com/opiproject/opi-api v0.0.0-20221102145024-1b5a67ca57ab + github.com/opiproject/opi-api v0.0.0-20221102184319-3c744e340157 google.golang.org/grpc v1.50.1 ) diff --git a/client/go.sum b/client/go.sum index bbeee06e..a340ebc1 100644 --- a/client/go.sum +++ b/client/go.sum @@ -3,8 +3,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/opiproject/opi-api v0.0.0-20221102145024-1b5a67ca57ab h1:U616PUfDkuIq0BMo91SW8rxDJ0LbX3RdML86m2DZ6D4= -github.com/opiproject/opi-api v0.0.0-20221102145024-1b5a67ca57ab/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= +github.com/opiproject/opi-api v0.0.0-20221102184319-3c744e340157 h1:bi+U9smq1BCeeYosan1pZZCZLkGMtgzkE1xaBr14VFI= +github.com/opiproject/opi-api v0.0.0-20221102184319-3c744e340157/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= diff --git a/server/frontend.go b/server/frontend.go index 502c6a41..f668d56b 100644 --- a/server/frontend.go +++ b/server/frontend.go @@ -67,9 +67,16 @@ func (s *server) NVMeSubsystemDelete(ctx context.Context, in *pb.NVMeSubsystemDe return &emptypb.Empty{}, nil } -func (s *server) NVMeSubsystemUpdate(ctx context.Context, in *pb.NVMeSubsystemUpdateRequest) (*pb.NVMeSubsystemUpdateResponse, error) { +func (s *server) NVMeSubsystemUpdate(ctx context.Context, in *pb.NVMeSubsystemUpdateRequest) (*pb.NVMeSubsystem, error) { log.Printf("NVMeSubsystemUpdate: Received from client: %v", in) - return &pb.NVMeSubsystemUpdateResponse{}, nil + subsystems[in.Subsystem.Id.Value] = in.Subsystem + response := &pb.NVMeSubsystem{} + err := deepcopier.Copy(in.Subsystem).To(response) + if err != nil { + log.Printf("error: %v", err) + return nil, err + } + return response, nil } func (s *server) NVMeSubsystemList(ctx context.Context, in *pb.NVMeSubsystemListRequest) (*pb.NVMeSubsystemListResponse, error) { @@ -89,7 +96,7 @@ func (s *server) NVMeSubsystemList(ctx context.Context, in *pb.NVMeSubsystemList return &pb.NVMeSubsystemListResponse{Subsystem: Blobarray}, nil } -func (s *server) NVMeSubsystemGet(ctx context.Context, in *pb.NVMeSubsystemGetRequest) (*pb.NVMeSubsystemGetResponse, error) { +func (s *server) NVMeSubsystemGet(ctx context.Context, in *pb.NVMeSubsystemGetRequest) (*pb.NVMeSubsystem, error) { log.Printf("NVMeSubsystemGet: Received from client: %v", in) subsys, ok := subsystems[in.SubsystemId.Value] if !ok { @@ -109,7 +116,7 @@ func (s *server) NVMeSubsystemGet(ctx context.Context, in *pb.NVMeSubsystemGetRe for i := range result { r := &result[i] if r.Nqn == subsys.Nqn { - return &pb.NVMeSubsystemGetResponse{Subsystem: &pb.NVMeSubsystem{Nqn: r.Nqn}}, nil + return &pb.NVMeSubsystem{Nqn: r.Nqn}, nil } } msg := fmt.Sprintf("Could not find NQN: %s", subsys.Nqn) @@ -154,10 +161,16 @@ func (s *server) NVMeControllerDelete(ctx context.Context, in *pb.NVMeController return &emptypb.Empty{}, nil } -func (s *server) NVMeControllerUpdate(ctx context.Context, in *pb.NVMeControllerUpdateRequest) (*pb.NVMeControllerUpdateResponse, error) { +func (s *server) NVMeControllerUpdate(ctx context.Context, in *pb.NVMeControllerUpdateRequest) (*pb.NVMeController, error) { log.Printf("Received from client: %v", in.Controller) controllers[in.Controller.Id.Value] = in.Controller - return &pb.NVMeControllerUpdateResponse{}, nil + response := &pb.NVMeController{} + err := deepcopier.Copy(in.Controller).To(response) + if err != nil { + log.Printf("error: %v", err) + return nil, err + } + return response, nil } func (s *server) NVMeControllerList(ctx context.Context, in *pb.NVMeControllerListRequest) (*pb.NVMeControllerListResponse, error) { @@ -169,13 +182,13 @@ func (s *server) NVMeControllerList(ctx context.Context, in *pb.NVMeControllerLi return &pb.NVMeControllerListResponse{Controller: Blobarray}, nil } -func (s *server) NVMeControllerGet(ctx context.Context, in *pb.NVMeControllerGetRequest) (*pb.NVMeControllerGetResponse, error) { +func (s *server) NVMeControllerGet(ctx context.Context, in *pb.NVMeControllerGetRequest) (*pb.NVMeController, error) { log.Printf("Received from client: %v", in.ControllerId) controller, ok := controllers[in.ControllerId.Value] if !ok { return nil, fmt.Errorf("error finding controller %s", in.ControllerId.Value) } - return &pb.NVMeControllerGetResponse{Controller: controller}, nil + return &pb.NVMeController{Id: in.ControllerId, NvmeControllerId: controller.NvmeControllerId}, nil } func (s *server) NVMeControllerStats(ctx context.Context, in *pb.NVMeControllerStatsRequest) (*pb.NVMeControllerStatsResponse, error) { @@ -250,10 +263,16 @@ func (s *server) NVMeNamespaceDelete(ctx context.Context, in *pb.NVMeNamespaceDe return &emptypb.Empty{}, nil } -func (s *server) NVMeNamespaceUpdate(ctx context.Context, in *pb.NVMeNamespaceUpdateRequest) (*pb.NVMeNamespaceUpdateResponse, error) { +func (s *server) NVMeNamespaceUpdate(ctx context.Context, in *pb.NVMeNamespaceUpdateRequest) (*pb.NVMeNamespace, error) { log.Printf("Received from client: %v", in.Namespace) namespaces[in.Namespace.Id.Value] = in.Namespace - return &pb.NVMeNamespaceUpdateResponse{}, nil + response := &pb.NVMeNamespace{} + err := deepcopier.Copy(in.Namespace).To(response) + if err != nil { + log.Printf("error: %v", err) + return nil, err + } + return response, nil } func (s *server) NVMeNamespaceList(ctx context.Context, in *pb.NVMeNamespaceListRequest) (*pb.NVMeNamespaceListResponse, error) { @@ -296,7 +315,7 @@ func (s *server) NVMeNamespaceList(ctx context.Context, in *pb.NVMeNamespaceList return nil, status.Errorf(codes.InvalidArgument, msg) } -func (s *server) NVMeNamespaceGet(ctx context.Context, in *pb.NVMeNamespaceGetRequest) (*pb.NVMeNamespaceGetResponse, error) { +func (s *server) NVMeNamespaceGet(ctx context.Context, in *pb.NVMeNamespaceGetRequest) (*pb.NVMeNamespace, error) { log.Printf("NVMeNamespaceGet: Received from client: %v", in) namespace, ok := namespaces[in.NamespaceId.Value] if !ok { @@ -305,7 +324,7 @@ func (s *server) NVMeNamespaceGet(ctx context.Context, in *pb.NVMeNamespaceGetRe return nil, err } // TODO: do we even query SPDK to confirm if namespace is present? - // return &pb.NVMeNamespaceGetResponse{Namespace: &namespace}, nil + // return namespace, nil // fetch subsystems -> namespaces from server, match the nsid to find the corresponding namespace subsys, ok := subsystems[namespace.SubsystemId.Value] @@ -328,7 +347,7 @@ func (s *server) NVMeNamespaceGet(ctx context.Context, in *pb.NVMeNamespaceGetRe for j := range rr.Namespaces { r := &rr.Namespaces[j] if uint32(r.Nsid) == namespace.HostNsid { - return &pb.NVMeNamespaceGetResponse{Namespace: namespace}, nil + return &pb.NVMeNamespace{Id: namespace.Id, HostNsid: namespace.HostNsid}, nil } } msg := fmt.Sprintf("Could not find NSID: %d", namespace.HostNsid) @@ -385,9 +404,9 @@ func (s *server) VirtioBlkDelete(ctx context.Context, in *pb.VirtioBlkDeleteRequ return &emptypb.Empty{}, nil } -func (s *server) VirtioBlkUpdate(ctx context.Context, in *pb.VirtioBlkUpdateRequest) (*pb.VirtioBlkUpdateResponse, error) { +func (s *server) VirtioBlkUpdate(ctx context.Context, in *pb.VirtioBlkUpdateRequest) (*pb.VirtioBlk, error) { log.Printf("Received from client: %v", in) - return &pb.VirtioBlkUpdateResponse{}, nil + return &pb.VirtioBlk{}, nil } func (s *server) VirtioBlkList(ctx context.Context, in *pb.VirtioBlkListRequest) (*pb.VirtioBlkListResponse, error) { @@ -407,7 +426,7 @@ func (s *server) VirtioBlkList(ctx context.Context, in *pb.VirtioBlkListRequest) return &pb.VirtioBlkListResponse{Controller: Blobarray}, nil } -func (s *server) VirtioBlkGet(ctx context.Context, in *pb.VirtioBlkGetRequest) (*pb.VirtioBlkGetResponse, error) { +func (s *server) VirtioBlkGet(ctx context.Context, in *pb.VirtioBlkGetRequest) (*pb.VirtioBlk, error) { log.Printf("VirtioBlkGet: Received from client: %v", in) params := VhostGetControllersParams{ Name: fmt.Sprint("VirtioBlk", in.GetControllerId()), @@ -424,7 +443,7 @@ func (s *server) VirtioBlkGet(ctx context.Context, in *pb.VirtioBlkGetRequest) ( log.Print(msg) return nil, status.Errorf(codes.InvalidArgument, msg) } - return &pb.VirtioBlkGetResponse{Controller: &pb.VirtioBlk{Name: result[0].Ctrlr}}, nil + return &pb.VirtioBlk{Name: result[0].Ctrlr}, nil } func (s *server) VirtioBlkStats(ctx context.Context, in *pb.VirtioBlkStatsRequest) (*pb.VirtioBlkStatsResponse, error) { @@ -470,9 +489,9 @@ func (s *server) VirtioScsiControllerDelete(ctx context.Context, in *pb.VirtioSc return &emptypb.Empty{}, nil } -func (s *server) VirtioScsiControllerUpdate(ctx context.Context, in *pb.VirtioScsiControllerUpdateRequest) (*pb.VirtioScsiControllerUpdateResponse, error) { +func (s *server) VirtioScsiControllerUpdate(ctx context.Context, in *pb.VirtioScsiControllerUpdateRequest) (*pb.VirtioScsiController, error) { log.Printf("Received from client: %v", in) - return &pb.VirtioScsiControllerUpdateResponse{}, nil + return &pb.VirtioScsiController{}, nil } func (s *server) VirtioScsiControllerList(ctx context.Context, in *pb.VirtioScsiControllerListRequest) (*pb.VirtioScsiControllerListResponse, error) { @@ -492,7 +511,7 @@ func (s *server) VirtioScsiControllerList(ctx context.Context, in *pb.VirtioScsi return &pb.VirtioScsiControllerListResponse{Controller: Blobarray}, nil } -func (s *server) VirtioScsiControllerGet(ctx context.Context, in *pb.VirtioScsiControllerGetRequest) (*pb.VirtioScsiControllerGetResponse, error) { +func (s *server) VirtioScsiControllerGet(ctx context.Context, in *pb.VirtioScsiControllerGetRequest) (*pb.VirtioScsiController, error) { log.Printf("VirtioScsiControllerGet: Received from client: %v", in) params := VhostGetControllersParams{ Name: fmt.Sprint("OPI-VirtioScsi", in.GetControllerId()), @@ -509,7 +528,7 @@ func (s *server) VirtioScsiControllerGet(ctx context.Context, in *pb.VirtioScsiC log.Print(msg) return nil, status.Errorf(codes.InvalidArgument, msg) } - return &pb.VirtioScsiControllerGetResponse{Controller: &pb.VirtioScsiController{Name: result[0].Ctrlr}}, nil + return &pb.VirtioScsiController{Name: result[0].Ctrlr}, nil } func (s *server) VirtioScsiControllerStats(ctx context.Context, in *pb.VirtioScsiControllerStatsRequest) (*pb.VirtioScsiControllerStatsResponse, error) { @@ -562,9 +581,9 @@ func (s *server) VirtioScsiLunDelete(ctx context.Context, in *pb.VirtioScsiLunDe return &emptypb.Empty{}, nil } -func (s *server) VirtioScsiLunUpdate(ctx context.Context, in *pb.VirtioScsiLunUpdateRequest) (*pb.VirtioScsiLunUpdateResponse, error) { +func (s *server) VirtioScsiLunUpdate(ctx context.Context, in *pb.VirtioScsiLunUpdateRequest) (*pb.VirtioScsiLun, error) { log.Printf("Received from client: %v", in) - return &pb.VirtioScsiLunUpdateResponse{}, nil + return &pb.VirtioScsiLun{}, nil } func (s *server) VirtioScsiLunList(ctx context.Context, in *pb.VirtioScsiLunListRequest) (*pb.VirtioScsiLunListResponse, error) { @@ -584,7 +603,7 @@ func (s *server) VirtioScsiLunList(ctx context.Context, in *pb.VirtioScsiLunList return &pb.VirtioScsiLunListResponse{Lun: Blobarray}, nil } -func (s *server) VirtioScsiLunGet(ctx context.Context, in *pb.VirtioScsiLunGetRequest) (*pb.VirtioScsiLunGetResponse, error) { +func (s *server) VirtioScsiLunGet(ctx context.Context, in *pb.VirtioScsiLunGetRequest) (*pb.VirtioScsiLun, error) { log.Printf("VirtioScsiLunGet: Received from client: %v", in) params := VhostGetControllersParams{ Name: fmt.Sprint("OPI-VirtioScsi", in.GetControllerId()), @@ -601,7 +620,7 @@ func (s *server) VirtioScsiLunGet(ctx context.Context, in *pb.VirtioScsiLunGetRe log.Print(msg) return nil, status.Errorf(codes.InvalidArgument, msg) } - return &pb.VirtioScsiLunGetResponse{Lun: &pb.VirtioScsiLun{Bdev: result[0].Ctrlr}}, nil + return &pb.VirtioScsiLun{Bdev: result[0].Ctrlr}, nil } func (s *server) VirtioScsiLunStats(ctx context.Context, in *pb.VirtioScsiLunStatsRequest) (*pb.VirtioScsiLunStatsResponse, error) { diff --git a/server/go.mod b/server/go.mod index f0b8f8f3..3b0d15cd 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,7 +3,7 @@ module opi.storage.v1 go 1.19 require ( - github.com/opiproject/opi-api v0.0.0-20221102145024-1b5a67ca57ab + github.com/opiproject/opi-api v0.0.0-20221102184319-3c744e340157 github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6 google.golang.org/grpc v1.50.1 google.golang.org/protobuf v1.28.1 diff --git a/server/go.sum b/server/go.sum index a0f7e971..055906a2 100644 --- a/server/go.sum +++ b/server/go.sum @@ -3,8 +3,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/opiproject/opi-api v0.0.0-20221102145024-1b5a67ca57ab h1:U616PUfDkuIq0BMo91SW8rxDJ0LbX3RdML86m2DZ6D4= -github.com/opiproject/opi-api v0.0.0-20221102145024-1b5a67ca57ab/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= +github.com/opiproject/opi-api v0.0.0-20221102184319-3c744e340157 h1:bi+U9smq1BCeeYosan1pZZCZLkGMtgzkE1xaBr14VFI= +github.com/opiproject/opi-api v0.0.0-20221102184319-3c744e340157/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6 h1:TtyC78WMafNW8QFfv3TeP3yWNDG+uxNkk9vOrnDu6JA= github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6/go.mod h1:h8272+G2omSmi30fBXiZDMkmHuOgonplfKIKjQWzlfs= golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=