mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(storages): keep volumes a VM still needs
libvirt deletes any volume it is asked to. The storage page and the API deleted a VM's disk, the base image of another volume or the file a snapshot was taken on without a check, breaking the VM or its snapshots. wvmStorage.del_volume now refuses a volume a domain on the compute uses as a disk or a backing file of one, a file of a domain's snapshots, or the backing file of another volume. The check is the one destroy already used, moved to wvmConnect and extended to snapshot files, so destroy also keeps the files of another VM's snapshots. The storage page shows the refusal; the API answers 400 with it, as for other refusals. Deleting a disk from a VM refuses after the detach when the VM's own snapshots need the volume, and says the volume was kept. Network disks count by their source name, pool volume disks by their volume's path. A volume whose metadata cannot be read stops the check instead of counting as unused; only one removed meanwhile is skipped. The check and the delete hold the compute lock, so no VM operation attaches the volume in between; a busy compute is a message on the page and 409 in the API.
This commit is contained in:
parent
08cad04468
commit
c970f8e853
11 changed files with 345 additions and 30 deletions
|
|
@ -1,6 +1,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 django.shortcuts import get_object_or_404
|
||||
from drf_spectacular.utils import extend_schema, inline_serializer
|
||||
from rest_framework import serializers, status, viewsets
|
||||
|
|
@ -196,7 +197,9 @@ class VolumeViewSet(viewsets.ViewSet):
|
|||
)
|
||||
|
||||
if conn.is_active():
|
||||
conn.del_volume(pk)
|
||||
# no VM operation attaches it between the check and the delete
|
||||
with libvirt_compute_lock(compute):
|
||||
conn.del_volume(pk)
|
||||
conn.close()
|
||||
return Response({"status": "Volume: " + pk + " is deleted"})
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue