From 16a74264a90d5f2a896efcbee22946bc6b38eb5b Mon Sep 17 00:00:00 2001 From: hamistao Date: Sat, 18 Jan 2025 15:44:12 -0300 Subject: [PATCH] lxd/storage/drivers/volume: only apply `volume.size` on block volumes Signed-off-by: hamistao --- lxd/storage/drivers/volume.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go index 91dcadda9808..083528e1c0ce 100644 --- a/lxd/storage/drivers/volume.go +++ b/lxd/storage/drivers/volume.go @@ -470,16 +470,23 @@ func (v Volume) ConfigBlockMountOptions() string { // or pool's volume config, otherwise for block volumes and block-backed volumes the defaultBlockSize. For other // volumes an empty string is returned if no size is defined. func (v Volume) ConfigSize() string { - size := v.ExpandedConfig("size") + size, ok := v.config["size"] + if ok && size != "0" { + return size + } + + // If volume size isn't defined on the volume config, then for block volumes or block-backed + // volumes return the size from the pool config, if defined, or the driver's DefaultBlockSize. + if !(v.contentType == ContentTypeBlock || v.IsBlockBacked()) { + return size + } - // If volume size isn't defined in either volume or pool config, then for block volumes or block-backed - // volumes return the defaultBlockSize. - if (size == "" || size == "0") && (v.contentType == ContentTypeBlock || v.IsBlockBacked()) { - return v.driver.Info().DefaultBlockSize + size = v.ExpandedConfig("size") + if size != "" && size != "0" { + return size } - // Return defined size or empty string if not defined. - return size + return v.driver.Info().DefaultBlockSize } // ConfigSizeFromSource derives the volume size to use for a new volume when copying from a source volume.