Skip to content

Commit

Permalink
lxd/storage/drivers/zfs: Round to zfs.blocksize or 16KiB
Browse files Browse the repository at this point in the history
Fixes #13420

Signed-off-by: Wesley Hershberger <wesley.hershberger@canonical.com>
  • Loading branch information
MggMuggins committed May 22, 2024
1 parent f2e07cc commit 39e5776
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lxd/storage/drivers/driver_zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,28 @@ func (d *zfs) patchDropBlockVolumeFilesystemExtension() error {

return nil
}

// roundVolumeBlockSizeBytes returns sizeBytes rounded up to the next multiple
// of `vol`'s "zfs.blocksize".
func (d *zfs) roundVolumeBlockSizeBytes(vol Volume, sizeBytes int64) int64 {
minBlockSize, err := units.ParseByteSizeString(vol.ExpandedConfig("zfs.blocksize"))

// minBlockSize will be 0 if zfs.blocksize=""
if minBlockSize <= 0 || err != nil {
// 16KiB is the default volblocksize
minBlockSize = 16 * 1024
}

if sizeBytes < minBlockSize {
sizeBytes = minBlockSize
}

roundedSizeBytes := int64(sizeBytes/minBlockSize) * minBlockSize

// Ensure the rounded size is at least the size specified in sizeBytes.
if roundedSizeBytes < sizeBytes {
roundedSizeBytes += minBlockSize
}

return roundedSizeBytes
}

0 comments on commit 39e5776

Please sign in to comment.