Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lvol): add lvol detach parent API #180

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
BdevLvolCloneBdevCmd(),
BdevLvolSetParentCmd(),
BdevLvolDecoupleParentCmd(),
BdevLvolDetachParentCmd(),

Check warning on line 30 in app/cmd/basic/bdev_lvol.go

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L30

Added line #L30 was not covered by tests
BdevLvolResizeCmd(),
BdevLvolStartShallowCopyCmd(),
BdevLvolCheckShallowCopyCmd(),
Expand Down Expand Up @@ -345,6 +346,47 @@
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: \"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")
}

Check warning on line 366 in app/cmd/basic/bdev_lvol.go

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L349-L366

Added lines #L349 - L366 were not covered by tests
},
}
}

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

Check warning on line 375 in app/cmd/basic/bdev_lvol.go

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L371-L375

Added lines #L371 - L375 were not covered by tests

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

Check warning on line 380 in app/cmd/basic/bdev_lvol.go

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L377-L380

Added lines #L377 - L380 were not covered by tests

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

Check warning on line 385 in app/cmd/basic/bdev_lvol.go

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L382-L385

Added lines #L382 - L385 were not covered by tests

return util.PrintObject(decoupled)

Check warning on line 387 in app/cmd/basic/bdev_lvol.go

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L387

Added line #L387 was not covered by tests
}

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 @@ -387,6 +387,24 @@
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
}

Check warning on line 403 in pkg/spdk/client/basic.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L395-L403

Added lines #L395 - L403 were not covered by tests

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

Check warning on line 405 in pkg/spdk/client/basic.go

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L405

Added line #L405 was not covered by tests
}

// 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
Loading