1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(storages): a volume another compute's VM uses on shared storage is not deleted

A pool on shared storage (an NFS share, or a directory mounted from one)
holds the same file at the same path on every host that mounts it. A
VM's delete checks the panel's other computes before it deletes its disk
files, but the pool page, its API and a VM's disk delete checked only
their own host: a disk of a VM on another compute could be deleted. They
now ask the other computes too, and refuse while one uses the file or
cannot be reached. The other computes are asked before this host's lock
is taken, and before a VM's disk is detached.
This commit is contained in:
catborise 2026-11-13 10:31:22 +03:00
parent fb3b2f479e
commit 143a74b145
11 changed files with 277 additions and 196 deletions

View file

@ -4,6 +4,7 @@ from admin.permissions import IsSuperUser
from appsettings.settings import app_settings
from computes.models import Compute
from computes.utils import libvirt_compute_lock
from instances.utils import paths_used_on_other_computes
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext as _
from drf_spectacular.utils import extend_schema, inline_serializer
@ -206,9 +207,11 @@ class VolumeViewSet(viewsets.ViewSet):
subject, action = f"Storage pool {storage_pk}", f"delete volume {pk}"
if conn.is_active():
# no VM operation attaches it between the check and the delete
with audit(request, compute, subject, action), libvirt_compute_lock(compute):
conn.del_volume(pk)
with audit(request, compute, subject, action):
conn.check_unused_elsewhere(pk, lambda paths: paths_used_on_other_computes(compute, paths))
# no VM operation attaches it between the check and the delete
with libvirt_compute_lock(compute):
conn.del_volume(pk)
return Response({"status": "Volume: " + pk + " is deleted"})
else:
failed(request, compute, subject, action, "pool is not active")