From e50a23ddfd64ebc267064e5aa07e0c3f9366ffbc Mon Sep 17 00:00:00 2001 From: Damiano Cipriani Date: Mon, 16 Dec 2024 13:37:08 +0100 Subject: [PATCH] feat(lvol): add lvol detach parent API Longhorn 9922 Signed-off-by: Damiano Cipriani Signed-off-by: Shuo Wu --- Dockerfile.dapper | 2 +- app/cmd/basic/bdev_lvol.go | 42 ++++++++++++++++++++++++++++++++++++++ pkg/spdk/client/basic.go | 18 ++++++++++++++++ pkg/spdk/types/lvol.go | 4 ++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Dockerfile.dapper b/Dockerfile.dapper index fce77e7..91f7f90 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -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 diff --git a/app/cmd/basic/bdev_lvol.go b/app/cmd/basic/bdev_lvol.go index 2ec7dc8..3cae807 100644 --- a/app/cmd/basic/bdev_lvol.go +++ b/app/cmd/basic/bdev_lvol.go @@ -27,6 +27,7 @@ func BdevLvolCmd() cli.Command { BdevLvolCloneBdevCmd(), BdevLvolSetParentCmd(), BdevLvolDecoupleParentCmd(), + BdevLvolDetachParentCmd(), BdevLvolResizeCmd(), BdevLvolStartShallowCopyCmd(), BdevLvolCheckShallowCopyCmd(), @@ -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 /. 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 /\", or \"detach --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", diff --git a/pkg/spdk/client/basic.go b/pkg/spdk/client/basic.go index 668b423..25b3835 100644 --- a/pkg/spdk/client/basic.go +++ b/pkg/spdk/client/basic.go @@ -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 /. +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. diff --git a/pkg/spdk/types/lvol.go b/pkg/spdk/types/lvol.go index ba1c1cc..0220244 100644 --- a/pkg/spdk/types/lvol.go +++ b/pkg/spdk/types/lvol.go @@ -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"`