Skip to content

Commit

Permalink
lxd/storage/drivers/driver/btrfs/volumes: Enable compression on block…
Browse files Browse the repository at this point in the history
… raw files

This has the side effect of reducing the maximum extent size for compressible extents and reduces space waste
when partially rewriting extents that can cause the block file to end up exceeding the BTRFS volume quota.

Fixes canonical#9124

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
  • Loading branch information
tomponline committed Dec 3, 2021
1 parent 68cf3d0 commit 7a8158f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lxd/storage/drivers/driver_btrfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ func (d *btrfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Op
if err != nil {
return err
}

// Create empty file so we can set the compression property on it.
f, err := os.OpenFile(rootBlockPath, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return errors.Wrapf(err, "Failed to open %s", rootBlockPath)
}
f.Close()

// Use lzo as fastest, this will also reduce the maximum extent size for compressed extents from
// 128MiB to 128KiB. This means that if extents are partially written less space is wasted and
// doesn't end up exceeding the BTRFS quota.
_, err = shared.RunCommand("btrfs", "property", "set", rootBlockPath, "compression", "lzo")
if err != nil {
return err
}
}

err = d.runFiller(vol, rootBlockPath, filler)
Expand Down

0 comments on commit 7a8158f

Please sign in to comment.