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

fix: improve lvol snapshot checksum get #185

Merged
merged 1 commit into from
Dec 25, 2024
Merged
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
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 @@
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 @@
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 @@
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 @@
// 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
Loading