Skip to content

Commit

Permalink
feat(storage/nvme): add create pcie controller cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <artsiom.koltun@intel.com>
  • Loading branch information
artek-koltun authored and sandersms committed Jan 11, 2024
1 parent 8dd6fab commit 264b7b8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cmd/storage-nvme-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func newCreateNvmeControllerCommand() *cobra.Command {
}

cmd.AddCommand(newCreateNvmeControllerTCPCommand())
cmd.AddCommand(newCreateNvmeControllerPcieCommand())

return cmd
}
Expand Down Expand Up @@ -71,6 +72,50 @@ func newCreateNvmeControllerTCPCommand() *cobra.Command {
return cmd
}

func newCreateNvmeControllerPcieCommand() *cobra.Command {
id := ""
subsystem := ""
var port uint
var pf uint
var vf uint
cmd := &cobra.Command{
Use: "pcie",
Aliases: []string{"p"},
Short: "Creates nvme PCIe controller",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
addr, err := c.Flags().GetString(addrCmdLineArg)
cobra.CheckErr(err)

timeout, err := c.Flags().GetDuration(timeoutCmdLineArg)
cobra.CheckErr(err)

client, err := storage.New(addr)
cobra.CheckErr(err)

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

response, err := client.CreateNvmePcieController(ctx, id, subsystem, port, pf, vf)
cobra.CheckErr(err)

printResponse(response.Name)
},
}

cmd.Flags().StringVar(&id, "id", "", "id for created resource. Assigned by server if omitted.")
cmd.Flags().StringVar(&subsystem, "subsystem", "", "subsystem name to attach the controller to")
cmd.Flags().UintVar(&port, "port", 0, "port_id address part of the created controller")
cmd.Flags().UintVar(&pf, "pf", 0, "physical_function address part of the created controller")
cmd.Flags().UintVar(&vf, "vf", 0, "virtual_function address part of the created controller")

cobra.CheckErr(cmd.MarkFlagRequired("subsystem"))
cobra.CheckErr(cmd.MarkFlagRequired("pf"))
cobra.CheckErr(cmd.MarkFlagRequired("vf"))

return cmd
}

func newDeleteNvmeControllerCommand() *cobra.Command {
name := ""
allowMissing := false
Expand Down
36 changes: 36 additions & 0 deletions storage/nvme_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"

pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"google.golang.org/protobuf/types/known/wrapperspb"
)

// CreateNvmeTCPController creates an nvme TCP controller
Expand Down Expand Up @@ -58,6 +59,41 @@ func (c *Client) CreateNvmeTCPController(
return response, err
}

// CreateNvmePcieController creates an nvme PCIe controller
func (c *Client) CreateNvmePcieController(
ctx context.Context,
id, subsystem string,
port, pf, vf uint,
) (*pb.NvmeController, error) {
conn, connClose, err := c.connector.NewConn()
if err != nil {
return nil, err
}
defer connClose()

client := c.createClient(conn)
response, err := client.CreateNvmeController(
ctx,
&pb.CreateNvmeControllerRequest{
Parent: subsystem,
NvmeControllerId: id,
NvmeController: &pb.NvmeController{
Spec: &pb.NvmeControllerSpec{
Trtype: pb.NvmeTransportType_NVME_TRANSPORT_PCIE,
Endpoint: &pb.NvmeControllerSpec_PcieId{
PcieId: &pb.PciEndpoint{
PortId: wrapperspb.Int32(int32(port)),
PhysicalFunction: wrapperspb.Int32(int32(pf)),
VirtualFunction: wrapperspb.Int32(int32(vf)),
},
},
},
},
})

return response, err
}

// DeleteNvmeController deletes an nvme controller
func (c *Client) DeleteNvmeController(
ctx context.Context,
Expand Down

0 comments on commit 264b7b8

Please sign in to comment.