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

fix(instances): a new VM's disk cache goes with the disk I/O of Settings

Settings refuse disk I/O native with a cache other than none or
directsync, which libvirt refuses. A new VM took the I/O from Settings
and its cache from the create form, unchecked: native I/O with a
writeback cache was queued, the disks were made, and libvirt then
refused the VM. The create job now refuses such a pair when it is asked
for, and again when it runs, before it makes a disk: Settings may have
changed meanwhile.

Two administrators saving the I/O and the cache at once each checked
the pair as their page read it, and both saves made one libvirt refuses.
The pair is now checked again as saved, with its rows locked, when a
change of it is saved; the log row keeps the reason in English.
This commit is contained in:
catborise 2026-11-13 12:37:54 +03:00
parent 7bbc951082
commit 5a52bcf43e
8 changed files with 207 additions and 122 deletions

View file

@ -11,6 +11,7 @@ from django.utils.translation import gettext as _
from django.utils.translation import gettext_noop
from logs.audit import audit
from operations.utils import BOUNDS
from vrtManager.util import OperationError
from appsettings.models import AppSettings
@ -75,10 +76,10 @@ def refusal(setting, value):
def combined_refusal(values):
"""Why settings that work only together cannot be saved as values
(key: value, saved or new), or None."""
(key: value, saved or new), untranslated, or None."""
# libvirt refuses such a disk: every new VM would fail
if values["INSTANCE_VOLUME_DEFAULT_IO"] == "native" and values["INSTANCE_VOLUME_DEFAULT_CACHE"] not in ("none", "directsync"):
return _("Disk I/O native needs disk cache none or directsync")
return gettext_noop("Disk I/O native needs disk cache none or directsync")
return None
@ -113,9 +114,10 @@ def appsettings(request):
refusals = [refused for refused in (refusal(s, value) for s, value in changed) if refused]
# checked only when the pair changes: a pair saved before does not block other settings
pair = {"INSTANCE_VOLUME_DEFAULT_IO", "INSTANCE_VOLUME_DEFAULT_CACHE"}
if not refusals and pair & {s.key for s, _v in changed} and (refused := combined_refusal(
pair_changed = bool(pair & {s.key for s, _v in changed})
if not refusals and pair_changed and (refused := combined_refusal(
{key: s.value for key, s in settings_by_key.items()} | {s.key: value for s, value in changed})):
refusals = [refused]
refusals = [_(refused)]
for refused in refusals:
messages.error(request, refused)
if changed and not refusals:
@ -123,10 +125,16 @@ def appsettings(request):
try:
# one row, and all of the group or none of it
with audit(request, None, "Settings", action), transaction.atomic():
# the pair as saved now, locked: another administrator's save of its other half
# since this page was read must not make it one libvirt refuses
if pair_changed:
saved = AppSettings.objects.select_for_update().filter(key__in=pair).values_list("key", "value")
if refused := combined_refusal(dict(saved) | {s.key: value for s, value in changed}):
raise OperationError(refused)
for setting, value in changed:
setting.value = value
setting.save()
except DatabaseError as err: # the audit row records it as failed
except (DatabaseError, OperationError) as err: # the audit row records it as failed
messages.error(request, err)
else:
messages.success(request, _("Saved: %(settings)s") % {"settings": ", ".join(s.name for s, _v in changed)})