Skip to content

Commit f1c87e0

Browse files
committed
incusd/storage/lvm: Discard the new blocks on resize
Suggested-by: Takero Funaki <[email protected]> Signed-off-by: Stéphane Graber <[email protected]>
1 parent d619239 commit f1c87e0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/server/storage/drivers/driver_lvm_utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,22 @@ func (d *lvm) resizeLogicalVolume(lvPath string, sizeBytes int64) error {
573573
return err
574574
}
575575

576+
// On thick pools, discard the blocks in the additional space when the volume is grown.
577+
if !d.usesThinpool() {
578+
oldSizeBytes, err := d.logicalVolumeSize(lvPath)
579+
if err != nil {
580+
return err
581+
}
582+
583+
if oldSizeBytes < sizeBytes {
584+
// Discard the new blocks.
585+
err := linux.ClearBlock(lvPath, sizeBytes)
586+
if err != nil {
587+
return err
588+
}
589+
}
590+
}
591+
576592
d.logger.Debug("Logical volume resized", logger.Ctx{"dev": lvPath, "size": fmt.Sprintf("%db", sizeBytes)})
577593
return nil
578594
}

0 commit comments

Comments
 (0)