libvirt/libvirt-conf-qemu-make-source-element-almost-optional-for-type-vhostuser.patch
Jiri Denemark 4a97ecd040 libvirt-10.10.0-7.el9
- qemu_migration: Refactor qemuMigrationSrcRestoreDomainState (RHEL-79168)
- qemu_migration: Do not automatically resume domain after I/O error (RHEL-79168)
- qemucapabilitiestest: Add data for the qemu-10.0 dev cycle on x86_64 (RHEL-79095)
- qemucapabilitiestest: Update 'caps_10.0.0_x86_64' to 'v9.2.0-1636-gffaf7f0376' (RHEL-79095)
- qemu: capabilies: Introduce QEMU_CAPS_BLOCKDEV_SET_ACTIVE (RHEL-79095)
- qemu: monitor: Add monitor backend for 'blockdev-set-active' (RHEL-79095)
- qemu: migration: Reactivate block nodes after migration if VM is left paused (RHEL-79095)
- conf: change virDomainHostdevInsert() to return void (RHEL-69455)
- qemu: fix qemu validation to forbid guest-side IP address for type='vdpa' (RHEL-69455)
- qemu: validate that model is virtio for vhostuser and vdpa interfaces in the same place (RHEL-69455)
- qemu: automatically set model type='virtio' for interface type='vhostuser' (RHEL-69455)
- qemu: do all vhostuser attribute validation in qemu driver (RHEL-69455)
- conf/qemu: make <source> element *almost* optional for type=vhostuser (RHEL-69455)
- qemu: use switch instead of if in qemuProcessPrepareDomainNetwork() (RHEL-69455)
- qemu: make qemuPasstCreateSocketPath() public (RHEL-69455)
- qemu: complete vhostuser + passt support (RHEL-69455)
- qemu: fail validation if a domain def has vhostuser/passt but no shared mem (RHEL-69455)
- docs: improve type='user' docs to higlight differences between SLIRP and passt (RHEL-69455)
- docs: document using passt backend with <interface type='vhostuser'> (RHEL-69455)
- utils: Canonicalize paths before comparing them (RHEL-79166)

Resolves: RHEL-69455, RHEL-79095, RHEL-79166, RHEL-79168
2025-02-17 21:30:50 +01:00

171 lines
7.2 KiB
Diff

From 8aac60b3f07513fea6968b1f9d340f7408a3a8e6 Mon Sep 17 00:00:00 2001
Message-ID: <8aac60b3f07513fea6968b1f9d340f7408a3a8e6.1739824249.git.jdenemar@redhat.com>
From: Laine Stump <laine@redhat.com>
Date: Sun, 9 Feb 2025 22:52:54 -0500
Subject: [PATCH] conf/qemu: make <source> element *almost* optional for
type=vhostuser
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
For some reason, when vhostuser interface support was added in 2014,
the parser required that the XML for the <interface> have a <source>
element with type, mode, and path, all 3 also required. This in spite
of the fact that 'unix' is the only possible valid setting for type,
and 95% of the time the mode is set to 'client' (as I understand from
comments in the code, normally a guest will use mode='client' to
connect to an existing socket that is precreated (by OVS?), and the
only use for mode='server' is for test setups where one guest is setup
with a listening vhostuser socket (i.e. 'server') and another guest
connects to that socket (i.e. 'client')). (or maybe one guest connects
to OVS in server mode, and all the others connect in client mode, not
sure - I don't claim to be an expert on vhost-user.)
So from the point of view of existing vhost-user functionality, it
seems reasonable to make 'type' and 'mode' optional, and by default
fill in the vhostuser part of the NetDef as if they were 'unix' and
'client'.
In theory, the <source> element itself is also not *directly* required
after this patch, however, the path attribute of <source> *is*
required (for now), so effectively the <source> element is still
required.
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit fb4bfa78589f7f556b6b0a176f109c94516d3cdd)
https://issues.redhat.com/browse/RHEL-69455
Signed-off-by: Laine Stump <laine@redhat.com>
---
src/conf/domain_conf.c | 56 ++++++++++++-------------------
src/conf/schemas/domaincommon.rng | 4 ++-
src/qemu/qemu_validate.c | 20 +++++++----
3 files changed, 39 insertions(+), 41 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cba0b162f4..b1e9dda80e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9767,50 +9767,38 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
g_autofree char *vhostuser_type = NULL;
virDomainNetVhostuserMode vhostuser_mode;
- if (virDomainNetDefParseXMLRequireSource(def, source_node) < 0)
- return NULL;
-
- if (!(vhostuser_type = virXMLPropStringRequired(source_node, "type")))
- return NULL;
-
- if (STRNEQ_NULLABLE(vhostuser_type, "unix")) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Type='%1$s' unsupported for <interface type='vhostuser'>"),
- vhostuser_type);
- return NULL;
- }
-
if (!(def->data.vhostuser = virDomainChrSourceDefNew(xmlopt)))
return NULL;
+ /* Default (and only valid) value of type is "unix".
+ * Everything else's default value is 0/NULL.
+ */
def->data.vhostuser->type = VIR_DOMAIN_CHR_TYPE_UNIX;
- if (!(def->data.vhostuser->data.nix.path = virXMLPropStringRequired(source_node, "path")))
- return NULL;
+ if (source_node) {
+ if ((vhostuser_type = virXMLPropString(source_node, "type"))) {
+ if (STRNEQ(vhostuser_type, "unix")) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Type='%1$s' unsupported for <interface type='vhostuser'>"),
+ vhostuser_type);
+ return NULL;
+ }
+ }
- if (virXMLPropEnum(source_node, "mode",
- virDomainNetVhostuserModeTypeFromString,
- VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
- &vhostuser_mode) < 0)
- return NULL;
+ def->data.vhostuser->data.nix.path = virXMLPropString(source_node, "path");
- switch (vhostuser_mode) {
- case VIR_DOMAIN_NET_VHOSTUSER_MODE_CLIENT:
- def->data.vhostuser->data.nix.listen = false;
- break;
+ if (virXMLPropEnum(source_node, "mode", virDomainNetVhostuserModeTypeFromString,
+ VIR_XML_PROP_NONZERO, &vhostuser_mode) < 0) {
+ return NULL;
+ }
- case VIR_DOMAIN_NET_VHOSTUSER_MODE_SERVER:
- def->data.vhostuser->data.nix.listen = true;
- break;
+ if (vhostuser_mode == VIR_DOMAIN_NET_VHOSTUSER_MODE_SERVER)
+ def->data.vhostuser->data.nix.listen = true;
- case VIR_DOMAIN_NET_VHOSTUSER_MODE_NONE:
- case VIR_DOMAIN_NET_VHOSTUSER_MODE_LAST:
- break;
+ if (virDomainChrSourceReconnectDefParseXML(&def->data.vhostuser->data.nix.reconnect,
+ source_node, ctxt) < 0)
+ return NULL;
}
-
- if (virDomainChrSourceReconnectDefParseXML(&def->data.vhostuser->data.nix.reconnect,
- source_node, ctxt) < 0)
- return NULL;
}
break;
diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng
index 7121519ca3..cbc093ca7b 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -3485,7 +3485,9 @@
<value>vhostuser</value>
</attribute>
<interleave>
- <ref name="unixSocketSource"/>
+ <optional>
+ <ref name="unixSocketSource"/>
+ </optional>
<ref name="interface-options"/>
</interleave>
</group>
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index b7b2e3d0af..eb8c5366f6 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1810,12 +1810,20 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net,
}
}
- if (net->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
- net->data.vhostuser->data.nix.listen &&
- net->data.vhostuser->data.nix.reconnect.enabled == VIR_TRISTATE_BOOL_YES) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("'reconnect' attribute is not supported when source mode='server' for <interface type='vhostuser'>"));
- return -1;
+ if (net->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
+ if (!net->data.vhostuser->data.nix.path) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Missing required attribute '%1$s' in element '%2$s'"),
+ "path", "source");
+ return -1;
+ }
+
+ if (net->data.vhostuser->data.nix.listen &&
+ net->data.vhostuser->data.nix.reconnect.enabled == VIR_TRISTATE_BOOL_YES) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("'reconnect' attribute is not supported when source mode='server' for <interface type='vhostuser'>"));
+ return -1;
+ }
}
if (!virDomainNetIsVirtioModel(net)) {
--
2.48.1