diff --git a/cmd/storage/backend/nvme_path.go b/cmd/storage/backend/nvme_path.go index 9ad344f..282ba4c 100644 --- a/cmd/storage/backend/nvme_path.go +++ b/cmd/storage/backend/nvme_path.go @@ -26,6 +26,7 @@ func newCreateNvmePathCommand() *cobra.Command { } cmd.AddCommand(newCreateNvmePathTCPCommand()) + cmd.AddCommand(newCreateNvmePathPcieCommand()) return cmd } @@ -77,6 +78,45 @@ func newCreateNvmePathTCPCommand() *cobra.Command { return cmd } +func newCreateNvmePathPcieCommand() *cobra.Command { + id := "" + controller := "" + bdf := "" + cmd := &cobra.Command{ + Use: "pcie", + Aliases: []string{"p"}, + Short: "Creates nvme path to PCIe controller", + Args: cobra.NoArgs, + Run: func(c *cobra.Command, args []string) { + addr, err := c.Flags().GetString(common.AddrCmdLineArg) + cobra.CheckErr(err) + + timeout, err := c.Flags().GetDuration(common.TimeoutCmdLineArg) + cobra.CheckErr(err) + + client, err := backendclient.New(addr) + cobra.CheckErr(err) + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + response, err := client.CreateNvmePciePath(ctx, id, controller, bdf) + cobra.CheckErr(err) + + common.PrintResponse(response.Name) + }, + } + + cmd.Flags().StringVar(&id, "id", "", "id for created resource. Assigned by server if omitted.") + cmd.Flags().StringVar(&controller, "controller", "", "backend controller name for this path") + cmd.Flags().StringVar(&bdf, "bdf", "", "bdf PCI address of NVMe/PCIe controller") + + cobra.CheckErr(cmd.MarkFlagRequired("controller")) + cobra.CheckErr(cmd.MarkFlagRequired("bdf")) + + return cmd +} + func newDeleteNvmePathCommand() *cobra.Command { name := "" allowMissing := false diff --git a/storage/backend/nvme_path.go b/storage/backend/nvme_path.go index 0c5a75c..863a992 100644 --- a/storage/backend/nvme_path.go +++ b/storage/backend/nvme_path.go @@ -58,6 +58,34 @@ func (c *Client) CreateNvmeTCPPath( return response, err } +// CreateNvmePciePath creates a path to nvme PCIe controller +func (c *Client) CreateNvmePciePath( + ctx context.Context, + id string, + controller string, + bdf string, +) (*pb.NvmePath, error) { + conn, connClose, err := c.connector.NewConn() + if err != nil { + return nil, err + } + defer connClose() + + client := c.createNvmeClient(conn) + response, err := client.CreateNvmePath( + ctx, + &pb.CreateNvmePathRequest{ + NvmePathId: id, + Parent: controller, + NvmePath: &pb.NvmePath{ + Trtype: pb.NvmeTransportType_NVME_TRANSPORT_TYPE_PCIE, + Traddr: bdf, + }, + }) + + return response, err +} + // DeleteNvmePath deletes an nvme path to an external nvme controller func (c *Client) DeleteNvmePath( ctx context.Context,