Skip to content

Commit

Permalink
feat(lvol): add lvol detach parent API
Browse files Browse the repository at this point in the history
Longhorn 9922

Signed-off-by: Damiano Cipriani <[email protected]>
Signed-off-by: Shuo Wu <[email protected]>
  • Loading branch information
DamiaSan authored and derekbit committed Dec 25, 2024
1 parent a58a028 commit e50a23d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV GOLANGCI_LINT_VERSION="v1.60.3"

WORKDIR ${DAPPER_SOURCE}

ENV SPDK_COMMIT_ID 002cd0679259c4e4b782d9540441a46e1228d484
ENV SPDK_COMMIT_ID a7421a6e59f1d099294af6f65d73ebec4afebfc5
ENV LIBJSONC_COMMIT_ID b4c371fa0cbc4dcbaccc359ce9e957a22988fb34
# Build nvme-cli 2.10.2
ENV NVME_CLI_COMMIT_ID eeaa08c9a0e9184f3889df0bff3d2a23db6d6294
Expand Down
42 changes: 42 additions & 0 deletions app/cmd/basic/bdev_lvol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func BdevLvolCmd() cli.Command {
BdevLvolCloneBdevCmd(),
BdevLvolSetParentCmd(),
BdevLvolDecoupleParentCmd(),
BdevLvolDetachParentCmd(),
BdevLvolResizeCmd(),
BdevLvolStartShallowCopyCmd(),
BdevLvolCheckShallowCopyCmd(),
Expand Down Expand Up @@ -347,6 +348,47 @@ func bdevLvolDecoupleParent(c *cli.Context) error {
return util.PrintObject(decoupled)
}

func BdevLvolDetachParentCmd() cli.Command {
return cli.Command{
Name: "detach",
Flags: []cli.Flag{
cli.StringFlag{
Name: "alias",
Usage: "The alias of a lvol is <LVSTORE NAME>/<LVOL NAME>. Specify this or uuid",
},
cli.StringFlag{
Name: "uuid",
Usage: "Specify this or alias",
},
},
Usage: "detach a lvol from its parent lvol without modifying lvol's data. The parent must be a standard snapshot, not an external snapshot: \"detach --alias <LVSTORE NAME>/<LVOL NAME>\", or \"detach --uuid <LVOL UUID>\"",
Action: func(c *cli.Context) {
if err := bdevLvolDetachParent(c); err != nil {
logrus.WithError(err).Fatalf("Failed to run detach parent bdev lvol command")
}
},
}
}

func bdevLvolDetachParent(c *cli.Context) error {
spdkCli, err := client.NewClient(context.Background())
if err != nil {
return err
}

name := c.String("alias")
if name == "" {
name = c.String("uuid")
}

decoupled, err := spdkCli.BdevLvolDetachParent(name)
if err != nil {
return err
}

return util.PrintObject(decoupled)
}

func BdevLvolSetParentCmd() cli.Command {
return cli.Command{
Name: "set-parent",
Expand Down
18 changes: 18 additions & 0 deletions pkg/spdk/client/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,24 @@ func (c *Client) BdevLvolDecoupleParent(name string) (decoupled bool, err error)
return decoupled, json.Unmarshal(cmdOutput, &decoupled)
}

// BdevLvolDetachParent detach the parent of a logical volume.
// No new clusters are allocated to the child blob, no data are copied from the parent to the child, so lvol's data are not modified.
// The parent must be a standard snapshot, not an external snapshot. All dependencies on the parent are removed
//
// "name": Required. UUID or alias of the logical volume to detach the parent of it. The alias of a lvol is <LVSTORE NAME>/<LVOL NAME>.
func (c *Client) BdevLvolDetachParent(name string) (decoupled bool, err error) {
req := spdktypes.BdevLvolDetachParentRequest{
Name: name,
}

cmdOutput, err := c.jsonCli.SendCommandWithLongTimeout("bdev_lvol_detach_parent", req)
if err != nil {
return false, err
}

return decoupled, json.Unmarshal(cmdOutput, &decoupled)
}

// BdevLvolSetParent sets a snapshot as the parent of a lvol, making the lvol a clone/child of this snapshot.
// The previous parent of the lvol can be another snapshot or an external snapshot, if the lvol is not a clone must be thin-provisioned.
// Lvol and parent snapshot must have the same size and must belong to the same lvol store.
Expand Down
4 changes: 4 additions & 0 deletions pkg/spdk/types/lvol.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ type BdevLvolDecoupleParentRequest struct {
Name string `json:"name"`
}

type BdevLvolDetachParentRequest struct {
Name string `json:"name"`
}

type BdevLvolSetParentRequest struct {
LvolName string `json:"lvol_name"`
ParentName string `json:"parent_name"`
Expand Down

0 comments on commit e50a23d

Please sign in to comment.