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

fix(vmbackups): an incremental backup needs room for its changed blocks only

The target space check asked for every disk's virtual capacity even when
the backup copies only the blocks changed since its parent. The checkpoint
already reports those bytes per disk (VIR_DOMAIN_CHECKPOINT_XML_SIZE), so
checkpoint_usable becomes checkpoint_sizes and the check runs after the
parent is chosen, with the changed bytes for an incremental backup and the
capacity for a full one. The margin (free_percent, free_min_gib) is kept.
This commit is contained in:
catborise 2026-11-18 13:38:27 +03:00
parent 132676a772
commit 8cd7aee19a
5 changed files with 49 additions and 30 deletions

View file

@ -163,18 +163,19 @@ class wvmBackup(wvmInstance):
vol = None # in no pool: counted by its own size only
return total
def checkpoint_usable(self, name, devs):
"""Whether the checkpoint name can be an incremental backup's base:
on this host, with a bitmap of known size for each disk of devs
(libvirt leaves the size out for a lost or invalid bitmap)."""
def checkpoint_sizes(self, name, devs):
"""The bytes each disk of devs changed since the checkpoint name,
{dev: size}, or None when it cannot be an incremental backup's base:
not on this host, or a disk without a bitmap of known size (libvirt
leaves the size out for a lost or invalid bitmap)."""
try:
xml = self.instance.checkpointLookupByName(name).getXMLDesc(libvirt.VIR_DOMAIN_CHECKPOINT_XML_SIZE)
except libvirt.libvirtError as err:
if err.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN_CHECKPOINT:
raise
return False
sized = set(etree.fromstring(xml).xpath("disks/disk[@checkpoint='bitmap' and @size]/@name"))
return set(devs) <= sized
return None
sizes = {d.get("name"): int(d.get("size")) for d in etree.fromstring(xml).xpath("disks/disk[@checkpoint='bitmap' and @size]")}
return {dev: sizes[dev] for dev in devs} if set(devs) <= set(sizes) else None
def prune_checkpoints(self, keep, known, devs):
"""Deletes the backups' checkpoints (wvc-) of a running VM but those

View file

@ -496,15 +496,15 @@ class CheckpointTestCase(unittest.TestCase):
self.deleted.append((name, flags))
checkpoints.pop(name)
def test_a_checkpoint_is_usable_only_with_a_size_for_every_disk(self):
def test_a_checkpoint_has_sizes_only_with_one_for_every_disk(self):
sized = ("<domaincheckpoint><disks><disk name='vda' checkpoint='bitmap' size='0'/>"
"<disk name='vdb' checkpoint='bitmap' size='4096'/></disks></domaincheckpoint>")
lost = sized.replace(" size='4096'", "") # libvirt leaves size out for a lost or invalid bitmap
p = self.proxy({"wvc-a": sized, "wvc-b": lost})
self.assertTrue(p.checkpoint_usable("wvc-a", ["vda", "vdb"]))
self.assertFalse(p.checkpoint_usable("wvc-b", ["vda", "vdb"]))
self.assertFalse(p.checkpoint_usable("wvc-a", ["vda", "vdb", "vdc"]))
self.assertFalse(p.checkpoint_usable("wvc-x", ["vda"])) # not on this host (after a migration)
self.assertEqual(p.checkpoint_sizes("wvc-a", ["vda", "vdb"]), {"vda": 0, "vdb": 4096})
self.assertIsNone(p.checkpoint_sizes("wvc-b", ["vda", "vdb"]))
self.assertIsNone(p.checkpoint_sizes("wvc-a", ["vda", "vdb", "vdc"]))
self.assertIsNone(p.checkpoint_sizes("wvc-x", ["vda"])) # not on this host (after a migration)
p.instance.checkpointLookupByName("wvc-a").getXMLDesc.assert_called_with(libvirt.VIR_DOMAIN_CHECKPOINT_XML_SIZE)
def test_pruning_keeps_the_anchors_and_removes_orphan_bitmaps(self):

View file

@ -82,7 +82,7 @@ class LiveIncrementalTestCase(SimpleTestCase):
self.write(dom, "0xdd", offset * MIB)
self.backup(proxy, NAME + "-full.qcow2", checkpoint="wvc-1")
self.write(dom, "0xbb", 2 * MIB)
self.assertTrue(proxy.checkpoint_usable("wvc-1", ["vda"]))
self.assertGreaterEqual(proxy.checkpoint_sizes("wvc-1", ["vda"])["vda"], MIB) # the block written since
self.backup(proxy, NAME + "-inc1.qcow2", incremental="wvc-1", checkpoint="wvc-2", backing=NAME + "-full.qcow2")
self.write(dom, "0xcc", 4 * MIB)
self.backup(proxy, NAME + "-inc2.qcow2", incremental="wvc-2", checkpoint="wvc-3", backing=NAME + "-inc1.qcow2")
@ -111,7 +111,7 @@ class LiveIncrementalTestCase(SimpleTestCase):
# after a migration the checkpoint's record is gone, its bitmap is not: the pruning finds it
dom.checkpointLookupByName("wvc-3").delete(libvirt.VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY)
self.assertFalse(proxy.checkpoint_usable("wvc-3", ["vda"]))
self.assertIsNone(proxy.checkpoint_sizes("wvc-3", ["vda"]))
proxy.prune_checkpoints(keep=set(), known={"wvc-3": 3}, devs=["vda"])
nodes = json.loads(libvirt_qemu.qemuMonitorCommand(
dom, json.dumps({"execute": "query-named-block-nodes", "arguments": {"flat": True}}), 0))["return"]