From bdf2c320df8de04c3095ae661dc8bfeff546891f Mon Sep 17 00:00:00 2001 From: Shuo Wu Date: Tue, 24 Dec 2024 00:12:07 -0800 Subject: [PATCH] improve: improve lvol snapshot checksum get Longhorn 8666, 9488 Signed-off-by: Shuo Wu --- app/cmd/basic/bdev_lvol.go | 4 ++-- pkg/spdk/client/basic.go | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/cmd/basic/bdev_lvol.go b/app/cmd/basic/bdev_lvol.go index e34954c..2ec7dc8 100644 --- a/app/cmd/basic/bdev_lvol.go +++ b/app/cmd/basic/bdev_lvol.go @@ -743,9 +743,9 @@ func bdevLvolGetSnapshotChecksum(c *cli.Context) error { if err != nil { return fmt.Errorf("failed to get checksum for snapshot %q: %v", name, err) } - if checksum == nil { + if checksum == "" { return fmt.Errorf("no checksum found for snapshot %q", name) } - return util.PrintObject(*checksum) + return util.PrintObject(checksum) } diff --git a/pkg/spdk/client/basic.go b/pkg/spdk/client/basic.go index 0d6f977..668b423 100644 --- a/pkg/spdk/client/basic.go +++ b/pkg/spdk/client/basic.go @@ -18,6 +18,7 @@ type Xattr struct { const ( UserCreated = "user_created" SnapshotTimestamp = "snapshot_timestamp" + SnapshotChecksum = "snapshot_checksum" ) // BdevGetBdevs get information about block devices (bdevs). @@ -296,6 +297,12 @@ func (c *Client) BdevLvolGetWithFilter(name string, timeout uint64, filter func( if err == nil { b.DriverSpecific.Lvol.Xattrs[SnapshotTimestamp] = snapshot_timestamp } + if b.DriverSpecific.Lvol.Snapshot { + checksum, err := c.BdevLvolGetSnapshotChecksum(b.Name) + if err == nil { + b.DriverSpecific.Lvol.Xattrs[SnapshotChecksum] = checksum + } + } bdevLvolInfoList = append(bdevLvolInfoList, b) } @@ -521,23 +528,23 @@ func (c *Client) BdevLvolRegisterSnapshotChecksum(name string) (registered bool, // BdevLvolGetSnapshotChecksum gets snapshot's stored checksum. The checksum must has been previously registered. // // "name": Required. UUID or alias of the snapshot. The alias of a snapshot is /. -func (c *Client) BdevLvolGetSnapshotChecksum(name string) (checksum *uint64, err error) { +func (c *Client) BdevLvolGetSnapshotChecksum(name string) (checksum string, err error) { req := spdktypes.BdevLvolGetSnapshotChecksumRequest{ Name: name, } cmdOutput, err := c.jsonCli.SendCommandWithLongTimeout("bdev_lvol_get_snapshot_checksum", req) if err != nil { - return nil, err + return "", err } var snapshotChecksum spdktypes.BdevLvolSnapshotChecksum err = json.Unmarshal(cmdOutput, &snapshotChecksum) if err != nil { - return nil, err + return "", err } - return &snapshotChecksum.Checksum, nil + return strconv.FormatUint(snapshotChecksum.Checksum, 10), nil } // BdevLvolRename renames a logical volume.