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

fix(instances): attach a disk, NIC or guest agent to both definitions in one call

On an active VM a device was attached in two calls, running VM first.
When the persistent attach was refused, for example because a disk target
or an agent channel was already pending there, the device stayed in the
running VM only and was gone at the next start. A NIC added without a
MAC got a different generated MAC in each definition. One call with
AFFECT_LIVE|AFFECT_CONFIG lets QEMU check the persistent copy before the
hotplug and keeps one MAC. Detach and update still go per definition,
each from its own XML.
This commit is contained in:
catborise 2026-10-11 19:42:59 +03:00
parent e924f3e7a0
commit 87ffed66b9
4 changed files with 92 additions and 25 deletions

View file

@ -993,8 +993,7 @@ class wvmInstance(wvmConnect):
if serial is not None and serial != "None" and serial != "":
xml_disk += f"""<serial>{serial}</serial>"""
xml_disk += """</disk>"""
for _, affect in self._definitions():
self.instance.attachDeviceFlags(xml_disk, affect)
self._attach_device(xml_disk)
def detach_disk(self, target_dev):
"""Detach target_dev from each definition that has it, as that definition describes it."""
@ -1883,10 +1882,21 @@ class wvmInstance(wvmConnect):
etree.SubElement(iface, "model", type=model)
if nwfilter:
etree.SubElement(iface, "filterref", filter=nwfilter)
xml_iface = etree.tostring(iface).decode()
self._attach_device(etree.tostring(iface).decode())
for _, affect in self._definitions():
self.instance.attachDeviceFlags(xml_iface, affect)
def _attach_device(self, xml):
"""Attach to the persistent definition and, when the VM is active, to
the running one, in one call. QEMU checks a copy of the persistent
definition before the hotplug, so a conflict there (a disk target or
an agent channel already pending) changes neither, and a NIC without
a MAC gets the same one in both. Still possible: a failure after a
successful hotplug leaves the device in the running VM only, and a
SCSI controller added for a disk that then fails to plug stays. An
error never proves that a new volume is unused."""
flags = VIR_DOMAIN_AFFECT_CONFIG
if self.instance.isActive():
flags |= VIR_DOMAIN_AFFECT_LIVE
self.instance.attachDeviceFlags(xml, flags)
def _definitions(self):
"""(XMLDesc flags, affect flag) of the definitions a device edit applies to:
@ -2076,8 +2086,7 @@ class wvmInstance(wvmConnect):
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
"""
for _, affect in self._definitions():
self.instance.attachDeviceFlags(channel_xml, affect)
self._attach_device(channel_xml)
def remove_guest_agent(self):
for xml_flags, affect in self._definitions():