1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +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

@ -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"]