From a86bc17f0eae0f5e3d96fa11f3bc1ced4448653e Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Tue, 20 Sep 2022 21:55:18 +0300 Subject: [PATCH] add ConnectToRemoteAndExpose function Signed-off-by: Boris Glimcher --- go.sum | 2 ++ goopicsi.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/go.sum b/go.sum index 089e510..367f54a 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS 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-20220915151511-9e129b0e199f h1:/hV1v9PXPYR0Qf0T6huJBCt9vX+rYx/3KuTJu5EiaK8= github.com/opiproject/opi-api v0.0.0-20220915151511-9e129b0e199f/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI= @@ -11,6 +12,7 @@ golang.org/x/sys v0.0.0-20220913175220-63ea55921009/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= google.golang.org/genproto v0.0.0-20220915135415-7fd63a7952de h1:5ANeKFmGdtiputJJYeUVg8nTGA/1bEirx4CgzcnPSx8= google.golang.org/genproto v0.0.0-20220915135415-7fd63a7952de/go.mod h1:0Nb8Qy+Sk5eDzHnzlStwW3itdNaWoZA5XeSG+R3JHSo= google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= diff --git a/goopicsi.go b/goopicsi.go index 23b8631..9036789 100644 --- a/goopicsi.go +++ b/goopicsi.go @@ -14,3 +14,47 @@ import ( pb "github.com/opiproject/opi-api/storage/proto" ) +func ConnectToRemoteAndExpose(addr string) { + flag.Parse() + // Set up a connection to the server. + conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + + // Contact the server and print out its response. + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + // Connect to remote NVMe target from xPU + c4 := pb.NewNVMfRemoteControllerServiceClient(conn) + rr0, err := c4.NVMfRemoteControllerConnect(ctx, &pb.NVMfRemoteControllerConnectRequest{Ctrl: &pb.NVMfRemoteController{Id: 1}}) + if err != nil { + log.Fatalf("could not connect to Remote NVMf controller: %v", err) + } + log.Printf("Connected: %v", rr0) + + // Expose emulated NVMe device to the Host (Step 1: Subsystem) + c1 := pb.NewNVMeSubsystemServiceClient(conn) + rs1, err := c1.NVMeSubsystemCreate(ctx, &pb.NVMeSubsystemCreateRequest{Subsystem: &pb.NVMeSubsystem{Nqn: "OpiMalloc7"}}) + if err != nil { + log.Fatalf("could not create NVMe subsystem: %v", err) + } + log.Printf("Added: %v", rs1) + // Step2: NVMeController + c2 := pb.NewNVMeControllerServiceClient(conn) + rc1, err := c2.NVMeControllerCreate(ctx, &pb.NVMeControllerCreateRequest{Controller: &pb.NVMeController{Name: "OPI-Nvme"}}) + if err != nil { + log.Fatalf("could not create NVMe subsystem: %v", err) + } + log.Printf("Added: %v", rc1) + + // NVMeNamespace + c3 := pb.NewNVMeNamespaceServiceClient(conn) + rn1, err := c3.NVMeNamespaceCreate(ctx, &pb.NVMeNamespaceCreateRequest{Namespace: &pb.NVMeNamespace{Name: "OPI-Nvme"}}) + if err != nil { + log.Fatalf("could not create NVMe subsystem: %v", err) + } + log.Printf("Added: %v", rn1) +} \ No newline at end of file