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

fix: a volume a job writes is not copied, attached or its pool stopped; download progress each second

A download into a pool listed its volume while it was written. The page
let a superuser copy it (the copy got a half-written file, live), attach
it to a VM, or stop the pool under it. Now:

- the copy job claims its source volume shared, and the worker refuses
  a copy whose name the source's format changed before the claim;
- attaching an existing volume holds it exclusive from its first read,
  so neither a download nor a copy is under way, and its format is read
  after the download ended;
- stopping or deleting a pool (page and API) holds the pool exclusive,
  and its backup target's claim if it is one; restores claim the pools
  they write into shared.

Each is refused with the job in the way named, as a volume delete
already was.

The download recorded its progress every 16 MiB, so a slow server's
bar stayed empty for a long time; it records it each second, with the
cancel check. The worker checks the name is still free before it
starts. A snapshot name or tag typed in the VM list's bulk form keeps
the list from reloading, as a chosen VM did.
This commit is contained in:
catborise 2026-11-20 15:12:20 +03:00
parent 7c8f5b3150
commit 7e70595fd2
19 changed files with 588 additions and 450 deletions

View file

@ -1016,6 +1016,7 @@ class RestoreBackup(Kind):
keys = vm_claims(compute, params["name"])
for name in volumes.values(): # no other job makes a volume of these names meanwhile
keys[claims.volume_key(compute.pk, params["pool"], name)] = Claim.EXCLUSIVE
keys[claims.pool_key(compute.pk, params["pool"])] = Claim.SHARED # not stopped under it
keys[claims.backup_key(backup.uuid)] = Claim.SHARED
keys[claims.backup_target_key(backup.target_id)] = Claim.EXCLUSIVE
if quota: # a VM owner's: no other increase of their quota is admitted until the VM is recorded
@ -1242,6 +1243,7 @@ class RestoreOver(Kind):
claims.backup_key(backup.uuid): Claim.SHARED, claims.backup_target_key(backup.target_id): Claim.EXCLUSIVE}
for dev, name in names.items(): # no other job makes a volume of these names meanwhile
keys[claims.volume_key(instance.compute_id, over["disks"][dev], name)] = Claim.EXCLUSIVE
keys[claims.pool_key(instance.compute_id, over["disks"][dev])] = Claim.SHARED # not stopped under it
return Plan(
claims=keys,
resource=claims.instance_key(instance.uuid),
@ -1428,6 +1430,7 @@ class RestoreDisk(Kind):
return Plan(
claims={claims.compute_key(compute.pk): Claim.SHARED,
claims.volume_key(compute.pk, params["pool"], params["name"]): Claim.EXCLUSIVE,
claims.pool_key(compute.pk, params["pool"]): Claim.SHARED, # not stopped under it
claims.backup_key(backup.uuid): Claim.SHARED,
claims.backup_target_key(backup.target_id): Claim.EXCLUSIVE},
resource=claims.backup_key(backup.uuid),

View file

@ -196,6 +196,8 @@ class RestoreTests(TransactionTestCase):
self.assertEqual(op.intent["volumes"], {"vda": "vm1-restored-vda.qcow2"})
self.assertTrue(Claim.objects.filter(operation=op, resource=f"volume:{self.compute.pk}:default/vm1-restored-vda.qcow2",
mode=Claim.EXCLUSIVE).exists())
# the pool written into, shared: not stopped under the restore
self.assertTrue(Claim.objects.filter(operation=op, resource=f"pool:{self.compute.pk}:default", mode=Claim.SHARED).exists())
def test_a_copy_in_flight_is_not_removed(self):
# its name may have been taken meanwhile by another volume: the job is left to the administrator

View file

@ -82,6 +82,8 @@ class RestoreDiskTests(TransactionTestCase):
op = self.submit()
self.assertTrue(Claim.objects.filter(operation=op, resource=f"volume:{self.compute.pk}:default/vm1-vdb-restored.raw",
mode=Claim.EXCLUSIVE).exists())
# the pool written into, shared: not stopped under the restore
self.assertTrue(Claim.objects.filter(operation=op, resource=f"pool:{self.compute.pk}:default", mode=Claim.SHARED).exists())
self.assertEqual(self.run_job(op), {"open": reverse("storage", args=[self.compute.pk, "default"])})
vol, name = self.storage.clone_volume.call_args.args
self.assertEqual((name, self.storage.clone_volume.call_args.kwargs["vol_fmt"]), ("vm1-vdb-restored.raw", "raw"))

View file

@ -151,6 +151,8 @@ class RestoreOverTests(TransactionTestCase):
self.assertEqual((op.intent["over"]["disks"], op.intent["names"]), ({"vda": "default"}, {"vda": "vm1-vda-20261117-1140.qcow2"}))
self.assertTrue(Claim.objects.filter(operation=op, resource=f"volume:{self.compute.pk}:default/vm1-vda-20261117-1140.qcow2",
mode=Claim.EXCLUSIVE).exists())
# the pool written into, shared: not stopped under the restore
self.assertTrue(Claim.objects.filter(operation=op, resource=f"pool:{self.compute.pk}:default", mode=Claim.SHARED).exists())
self.assertTrue(Claim.objects.filter(operation=op, resource=f"instance:{self.vm.uuid}", mode=Claim.EXCLUSIVE).exists())
self.run_job(op)
self.storage.clone_volume.assert_called_once()

View file

@ -3,6 +3,8 @@ from django.utils.translation import gettext, gettext_noop
from libvirt import libvirtError
from lxml import etree
from operations import claims
from operations.models import Claim
from storages.forms import inside
from vrtManager.backup import wvmBackup
from vrtManager.util import InUse
@ -49,6 +51,16 @@ def refuse_target_pool(compute, pool):
)
def pool_stop_claims(compute, pool):
"""The claims that keep out a pool's jobs while it is stopped or deleted: the pool's, and its
backup target's if it is one (backup jobs claim the target)."""
keys = {claims.pool_key(compute.pk, pool): Claim.EXCLUSIVE}
row = BackupTargetPool.objects.filter(compute=compute, pool=pool).first()
if row:
keys[claims.backup_target_key(row.target_id)] = Claim.EXCLUSIVE
return keys
def pending_deletes():
"""The UUIDs of the backups a deletion job was asked for and has not
finished: shown as being deleted before the job marks them."""