From 4aa78b6f1c801ef6f70daa79a63f11e35f676b88 Mon Sep 17 00:00:00 2001 From: catborise Date: Sat, 14 Nov 2026 15:26:50 +0300 Subject: [PATCH] fix(vrtManager): a copy into an LVM or RBD pool is raw and allocated whole A new VM from a qcow2 template in an LVM pool failed: the copy asked for qcow2 with qcow2's options, which libvirt refuses there ("compatibility option only available with qcow2"). Made raw, it still failed: with no allocation an LVM volume is a sparse snapshot, which qemu-img's copy filled and the kernel invalidated (I/O error). A copy into a pool of no files is now raw, as big as its source and allocated whole, as a new empty volume there already is. Checked live: a qcow2 template copied into an LVM pool. --- vrtManager/storage.py | 11 ++++++++--- vrtManager/tests/test_volume_xml.py | 12 +++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/vrtManager/storage.py b/vrtManager/storage.py index 110995f4..a3b3384b 100644 --- a/vrtManager/storage.py +++ b/vrtManager/storage.py @@ -382,16 +382,21 @@ class wvmStorage(wvmConnect): """A copy in this pool of vol, a volume of this pool or another; its name.""" if not vol_fmt: vol_fmt = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type") + size = 0 # a file copy takes the source's size and grows as written if self.get_type() not in FILE_POOL_TYPES: - metadata = False # only a file has metadata to allocate + # a block device, an LVM volume or an RBD image is raw and allocated whole: + # a sparse LVM volume is a snapshot that fails once the copy fills it + vol_fmt = "raw" + size = vol.info()[1] + metadata = False target_file = self.clone_name(target_file, vol_fmt, file_suffix) xml = f""" {target_file} - 0 - 0 + {size} + {size} diff --git a/vrtManager/tests/test_volume_xml.py b/vrtManager/tests/test_volume_xml.py index 98b1f7d9..e4b75b22 100644 --- a/vrtManager/tests/test_volume_xml.py +++ b/vrtManager/tests/test_volume_xml.py @@ -47,6 +47,7 @@ class TemplateCopyTests(SimpleTestCase): with patch("vrtManager.connection.connection_manager.get_connection") as get: template = get.return_value.storageVolLookupByPath.return_value template.XMLDesc.return_value = f"" + template.info.return_value = [0, 1 << 30, 0] pool = get.return_value.storagePoolLookupByName.return_value pool.XMLDesc.return_value = f"" wvmCreate("host", "login", "pw", 1).clone_from_template("vm", "/t/base", "pool1", True) @@ -60,9 +61,14 @@ class TemplateCopyTests(SimpleTestCase): self.assertEqual((volume.findtext("name"), flags), ("vm.qcow2", True)) self.assertIsNotNone(volume.find("target/features/lazy_refcounts")) - def test_other_pools_take_no_metadata(self): - volume, flags = self.copied("logical", "raw") - self.assertEqual((volume.findtext("name"), flags), ("vm", False)) + def test_other_pools_take_a_raw_copy(self): + for pool_type in ("logical", "rbd"): + with self.subTest(pool_type): + volume, flags = self.copied(pool_type, "qcow2") + self.assertEqual((volume.findtext("name"), volume.find("target/format").get("type"), flags), + ("vm", "raw", False)) + self.assertEqual(volume.findtext("allocation"), str(1 << 30)) + self.assertIsNone(volume.find("target/compat")) def test_only_a_qcow2_copy_takes_its_options(self): for fmt in ("raw", "qcow"):