1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

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.
This commit is contained in:
catborise 2026-11-14 15:26:50 +03:00
parent dd258888d2
commit 4aa78b6f1c
2 changed files with 17 additions and 6 deletions

View file

@ -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"""
<volume>
<name>{target_file}</name>
<capacity>0</capacity>
<allocation>0</allocation>
<capacity>{size}</capacity>
<allocation>{size}</allocation>
<target>
<format type='{vol_fmt}'/>
<permissions>

View file

@ -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"<volume><target><format type='{fmt}'/></target></volume>"
template.info.return_value = [0, 1 << 30, 0]
pool = get.return_value.storagePoolLookupByName.return_value
pool.XMLDesc.return_value = f"<pool type='{pool_type}'/>"
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"):