Skip to content

Commit

Permalink
feat(storage/nvme): add create backend pcie path 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 committed Jan 22, 2024
1 parent ee5fcdb commit 03bedcd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/storage/backend/nvme_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func newCreateNvmePathCommand() *cobra.Command {
}

cmd.AddCommand(newCreateNvmePathTCPCommand())
cmd.AddCommand(newCreateNvmePathPcieCommand())

return cmd
}
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions storage/backend/nvme_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 03bedcd

Please sign in to comment.