Skip to content

Commit

Permalink
improve: improve lvol snapshot checksum get
Browse files Browse the repository at this point in the history
Longhorn 8666, 9488

Signed-off-by: Shuo Wu <[email protected]>
  • Loading branch information
shuo-wu committed Dec 24, 2024
1 parent f0c0c2a commit bdf2c32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/cmd/basic/bdev_lvol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {

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

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L746

Added line #L746 was not covered by tests
return fmt.Errorf("no checksum found for snapshot %q", name)
}

return util.PrintObject(*checksum)
return util.PrintObject(checksum)

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

View check run for this annotation

Codecov / codecov/patch

app/cmd/basic/bdev_lvol.go#L750

Added line #L750 was not covered by tests
}
15 changes: 11 additions & 4 deletions pkg/spdk/client/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Xattr struct {
const (
UserCreated = "user_created"
SnapshotTimestamp = "snapshot_timestamp"
SnapshotChecksum = "snapshot_checksum"
)

// BdevGetBdevs get information about block devices (bdevs).
Expand Down Expand Up @@ -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
}

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

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L303-L304

Added lines #L303 - L304 were not covered by tests
}

bdevLvolInfoList = append(bdevLvolInfoList, b)
}
Expand Down Expand Up @@ -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 <LVSTORE NAME>/<SNAPSHOT NAME>.
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

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

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L544

Added line #L544 was not covered by tests
}

return &snapshotChecksum.Checksum, nil
return strconv.FormatUint(snapshotChecksum.Checksum, 10), nil

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

View check run for this annotation

Codecov / codecov/patch

pkg/spdk/client/basic.go#L547

Added line #L547 was not covered by tests
}

// BdevLvolRename renames a logical volume.
Expand Down

0 comments on commit bdf2c32

Please sign in to comment.