[lxc-devel] [lxd/master] VM: Block boundary size
tomponline on Github
lxc-bot at linuxcontainers.org
Mon Jan 20 09:18:49 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 528 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200120/0e772ca6/attachment.bin>
-------------- next part --------------
From db666fd8e07472af79afdbdb1be4f0cd329a1b2c Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 20 Jan 2020 09:09:46 +0000
Subject: [PATCH 1/2] lxd/storage/drivers/utils: Updates ensureVolumeBlockFile
to use minimum block boundary size of 8192 bytes
To avoid qemu issues when VM volume size is specified in metric sizes.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/utils.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 0cc9aed225..9d69e3b0e2 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -301,6 +301,16 @@ func ensureVolumeBlockFile(vol Volume, path string) error {
return err
}
+ // Qemu requires image files to be in traditial 1k, 4k or 8k block boundaries.
+ // We use 8k here to ensure our images are compatible with all of our backend drivers.
+ const minBlockBoundary = 8192
+ if blockSizeBytes < minBlockBoundary {
+ blockSizeBytes = minBlockBoundary
+ }
+
+ // Round the size to closest minBlockBoundary bytes to avoid qemu boundary issues.
+ blockSizeBytes = int64(blockSizeBytes/minBlockBoundary) * minBlockBoundary
+
if shared.PathExists(path) {
_, err = shared.RunCommand("qemu-img", "resize", "-f", "raw", path, fmt.Sprintf("%d", blockSizeBytes))
if err != nil {
From 240ffe16c7e0f5752765b4352091b519ecca71b0 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 20 Jan 2020 09:16:26 +0000
Subject: [PATCH 2/2] lxd/storage/drivers/driver/lvm/utils: Avoid repetition of
512 bytes in roundedSizeBytesString
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/driver_lvm_utils.go | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lxd/storage/drivers/driver_lvm_utils.go b/lxd/storage/drivers/driver_lvm_utils.go
index 77f717f31b..ea1999c18a 100644
--- a/lxd/storage/drivers/driver_lvm_utils.go
+++ b/lxd/storage/drivers/driver_lvm_utils.go
@@ -316,12 +316,14 @@ func (d *lvm) roundedSizeBytesString(size string) (int64, error) {
return 0, err
}
- if sizeBytes < 512 {
- sizeBytes = 512
+ // LVM tools require sizes in multiples of 512 bytes.
+ const minSizeBytes = 512
+ if sizeBytes < minSizeBytes {
+ sizeBytes = minSizeBytes
}
- // Round the size to closest 512 bytes as LVM tools require sizes in multiples of 512 bytes.
- sizeBytes = int64(sizeBytes/512) * 512
+ // Round the size to closest minSizeBytes bytes.
+ sizeBytes = int64(sizeBytes/minSizeBytes) * minSizeBytes
return sizeBytes, nil
}
More information about the lxc-devel
mailing list