From e5a41df7dcd81c240cad229ae6926c673b843139 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Fri, 1 Sep 2023 12:44:18 +0200 Subject: [PATCH] zfs: Disallow block.* settings for regular custom block volumes Fixes #12188 Signed-off-by: Thomas Hipp --- lxd/storage/drivers/driver_zfs_volumes.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go index e9d5b802ec33..ffcad7d97863 100644 --- a/lxd/storage/drivers/driver_zfs_volumes.go +++ b/lxd/storage/drivers/driver_zfs_volumes.go @@ -1525,7 +1525,15 @@ func (d *zfs) commonVolumeRules() map[string]func(value string) error { // ValidateVolume validates the supplied volume config. func (d *zfs) ValidateVolume(vol Volume, removeUnknownKeys bool) error { - return d.validateVolume(vol, d.commonVolumeRules(), removeUnknownKeys) + commonRules := d.commonVolumeRules() + + // Disallow block.* settings for regular custom block volumes. + if vol.volType == VolumeTypeCustom && (vol.contentType == ContentTypeBlock || !vol.IsBlockBacked()) { + delete(commonRules, "block.filesystem") + delete(commonRules, "block.mount_options") + } + + return d.validateVolume(vol, commonRules, removeUnknownKeys) } // UpdateVolume applies config changes to the volume. @@ -3330,6 +3338,8 @@ func (d *zfs) FillVolumeConfig(vol Volume) error { // If vol has a source, ignore the block mode related config keys from the pool. if vol.hasSource || vol.IsVMBlock() { excludedKeys = []string{"zfs.block_mode", "block.filesystem", "block.mount_options"} + } else if vol.volType == VolumeTypeCustom && (vol.contentType == ContentTypeBlock || !vol.IsBlockBacked()) { + excludedKeys = []string{"block.filesystem", "block.mount_options"} } err := d.fillVolumeConfig(&vol, excludedKeys...)