From a7b6e49d00571b35703daf6e3b758474dbc41273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 26 Nov 2019 16:44:40 +0000 Subject: [PATCH] conf: pass netprefix in the domain parser config struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of using the virCapsPtr information, pass the driver specific netprefix in the domain parser struct. This eliminates one more use of virCapsPtr from the XML parsing/formatting code. Reviewed-by: Michal Privoznik Signed-off-by: Daniel P. Berrangé --- src/conf/domain_conf.c | 24 +++++++----------------- src/conf/domain_conf.h | 3 ++- src/libxl/libxl_domain.c | 1 + 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9be3ef7651..cedbe687ac 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11454,7 +11454,6 @@ static virDomainNetDefPtr virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, xmlXPathContextPtr ctxt, - char *prefix, unsigned int flags) { virDomainNetDefPtr def; @@ -11502,6 +11501,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, g_autofree char *vhostuser_type = NULL; g_autofree char *trustGuestRxFilters = NULL; g_autofree char *vhost_path = NULL; + const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; if (!(def = virDomainNetDefNew(xmlopt))) return NULL; @@ -16433,7 +16433,6 @@ virDomainDeviceDefParse(const char *xmlStr, xmlNodePtr node; g_autoptr(xmlXPathContext) ctxt = NULL; g_autofree virDomainDeviceDefPtr dev = NULL; - char *netprefix; if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), &ctxt))) return NULL; @@ -16476,9 +16475,7 @@ virDomainDeviceDefParse(const char *xmlStr, return NULL; break; case VIR_DOMAIN_DEVICE_NET: - netprefix = caps->host.netprefix; - if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt, - netprefix, flags))) + if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt, flags))) return NULL; break; case VIR_DOMAIN_DEVICE_INPUT: @@ -19807,7 +19804,6 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_none = false; bool usb_other = false; bool usb_master = false; - char *netprefix = NULL; g_autofree xmlNodePtr *nodes = NULL; g_autofree char *tmp = NULL; @@ -20920,12 +20916,10 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; if (n && VIR_ALLOC_N(def->nets, n) < 0) goto error; - netprefix = caps->host.netprefix; for (i = 0; i < n; i++) { virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt, nodes[i], ctxt, - netprefix, flags); if (!net) goto error; @@ -25410,7 +25404,7 @@ virDomainChrSourceReconnectDefFormat(virBufferPtr buf, int virDomainNetDefFormat(virBufferPtr buf, virDomainNetDefPtr def, - char *prefix, + virDomainXMLOptionPtr xmlopt, unsigned int flags) { virDomainNetType actualType = virDomainNetGetActualType(def); @@ -25420,6 +25414,7 @@ virDomainNetDefFormat(virBufferPtr buf, virDomainHostdevDefPtr hostdef = NULL; char macstr[VIR_MAC_STRING_BUFLEN]; g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; /* publicActual is true if we should report the current state in * def->data.network.actual *instead of* the config (*not* in @@ -28342,7 +28337,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, int virDomainDefFormatInternalSetRootName(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - virCapsPtr caps, + virCapsPtr caps G_GNUC_UNUSED, virBufferPtr buf, const char *rootname, unsigned int flags) @@ -28352,7 +28347,6 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, const char *type = NULL; int n; size_t i; - char *netprefix = NULL; virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS | VIR_DOMAIN_DEF_FORMAT_STATUS | @@ -28708,10 +28702,8 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, if (virDomainFSDefFormat(buf, def->fss[n], flags) < 0) goto error; - if (caps) - netprefix = caps->host.netprefix; for (n = 0; n < def->nnets; n++) - if (virDomainNetDefFormat(buf, def->nets[n], netprefix, flags) < 0) + if (virDomainNetDefFormat(buf, def->nets[n], xmlopt, flags) < 0) goto error; for (n = 0; n < def->nsmartcards; n++) @@ -29882,7 +29874,6 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; int flags = VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_SECURE; int rc = -1; - char *netprefix; g_autofree char *xmlStr = NULL; switch ((virDomainDeviceType) src->type) { @@ -29896,8 +29887,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, rc = virDomainFSDefFormat(&buf, src->data.fs, flags); break; case VIR_DOMAIN_DEVICE_NET: - netprefix = caps->host.netprefix; - rc = virDomainNetDefFormat(&buf, src->data.net, netprefix, flags); + rc = virDomainNetDefFormat(&buf, src->data.net, xmlopt, flags); break; case VIR_DOMAIN_DEVICE_INPUT: rc = virDomainInputDefFormat(&buf, src->data.input, flags); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 462323ec76..5a149792f3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2706,6 +2706,7 @@ struct _virDomainDefParserConfig { unsigned int features; /* virDomainDefFeatures */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; virArch defArch; + const char *netPrefix; }; typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *); @@ -3149,7 +3150,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, int virDomainNetDefFormat(virBufferPtr buf, virDomainNetDefPtr def, - char *prefix, + virDomainXMLOptionPtr xmlopt, unsigned int flags); typedef enum { diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f202f0fc3e..dfac04bf59 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -437,6 +437,7 @@ libxlDomainDefPostParse(virDomainDefPtr def, virDomainDefParserConfig libxlDomainDefParserConfig = { .macPrefix = { 0x00, 0x16, 0x3e }, + .netPrefix = LIBXL_GENERATED_PREFIX_XEN, .devicesPostParseCallback = libxlDomainDeviceDefPostParse, .domainPostParseCallback = libxlDomainDefPostParse, .features = VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING, -- GitLab