mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-28 22:32:19 +00:00
conf/qemu: make <source> element *almost* optional for type=vhostuser
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>
This commit is contained in:
parent
56f4cc167a
commit
fb4bfa7858
@ -9776,51 +9776,39 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
|
||||
g_autofree char *vhostuser_type = NULL;
|
||||
virDomainNetVhostuserMode vhostuser_mode;
|
||||
|
||||
if (virDomainNetDefParseXMLRequireSource(def, source_node) < 0)
|
||||
if (!(def->data.vhostuser = virDomainChrSourceDefNew(xmlopt)))
|
||||
return NULL;
|
||||
|
||||
if (!(vhostuser_type = virXMLPropStringRequired(source_node, "type")))
|
||||
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 (STRNEQ_NULLABLE(vhostuser_type, "unix")) {
|
||||
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 (!(def->data.vhostuser = virDomainChrSourceDefNew(xmlopt)))
|
||||
return NULL;
|
||||
|
||||
def->data.vhostuser->type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||
|
||||
if (!(def->data.vhostuser->data.nix.path = virXMLPropStringRequired(source_node, "path")))
|
||||
return NULL;
|
||||
|
||||
if (virXMLPropEnum(source_node, "mode",
|
||||
virDomainNetVhostuserModeTypeFromString,
|
||||
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
||||
&vhostuser_mode) < 0)
|
||||
return NULL;
|
||||
|
||||
switch (vhostuser_mode) {
|
||||
case VIR_DOMAIN_NET_VHOSTUSER_MODE_CLIENT:
|
||||
def->data.vhostuser->data.nix.listen = false;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_VHOSTUSER_MODE_SERVER:
|
||||
def->data.vhostuser->data.nix.listen = true;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_VHOSTUSER_MODE_NONE:
|
||||
case VIR_DOMAIN_NET_VHOSTUSER_MODE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
def->data.vhostuser->data.nix.path = virXMLPropString(source_node, "path");
|
||||
|
||||
if (virXMLPropEnum(source_node, "mode", virDomainNetVhostuserModeTypeFromString,
|
||||
VIR_XML_PROP_NONZERO, &vhostuser_mode) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vhostuser_mode == VIR_DOMAIN_NET_VHOSTUSER_MODE_SERVER)
|
||||
def->data.vhostuser->data.nix.listen = true;
|
||||
|
||||
if (virDomainChrSourceReconnectDefParseXML(&def->data.vhostuser->data.nix.reconnect,
|
||||
source_node, ctxt) < 0)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_VDPA:
|
||||
|
@ -3485,7 +3485,9 @@
|
||||
<value>vhostuser</value>
|
||||
</attribute>
|
||||
<interleave>
|
||||
<optional>
|
||||
<ref name="unixSocketSource"/>
|
||||
</optional>
|
||||
<ref name="interface-options"/>
|
||||
</interleave>
|
||||
</group>
|
||||
|
@ -1825,13 +1825,21 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net,
|
||||
}
|
||||
}
|
||||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
|
||||
net->data.vhostuser->data.nix.listen &&
|
||||
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)) {
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_VDPA ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user