A helper to allow initialization of virDomainNetDef.
Use it for all new network definitions and pass xmlopt
where applicable.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/bhyve/bhyve_parse_command.c | 2 +-
src/conf/domain_conf.c | 15 ++++++++++++++-
src/conf/domain_conf.h | 1 +
src/libvirt_private.syms | 1 +
src/openvz/openvz_conf.c | 4 ++--
src/qemu/qemu_parse_command.c | 2 +-
src/vbox/vbox_common.c | 2 +-
src/vmx/vmx.c | 2 +-
src/xenconfig/xen_common.c | 2 +-
src/xenconfig/xen_sxpr.c | 2 +-
10 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 14137d179b..476e8321bc 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -505,7 +505,7 @@ bhyveParsePCINet(virDomainDefPtr def,
const char *separator = NULL;
const char *mac = NULL;
- if (VIR_ALLOC(net) < 0)
+ if (!(net = virDomainNetDefNew(xmlopt))
goto cleanup;
/* As we only support interface type='bridge' and cannot
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c0a8ae7898..f58d354ddd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2027,6 +2027,19 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr def)
VIR_FREE(def);
}
+
+virDomainNetDefPtr
+virDomainNetDefNew(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED)
+{
+ virDomainNetDefPtr net;
+
+ if (VIR_ALLOC(net) < 0)
+ return NULL;
+
+ return net;
+}
+
+
void
virDomainNetDefClear(virDomainNetDefPtr def)
{
@@ -10941,7 +10954,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
virDomainChrSourceReconnectDef reconnect = {0};
int rv, val;
- if (VIR_ALLOC(def) < 0)
+ if (!(def = virDomainNetDefNew(xmlopt)))
return NULL;
ctxt->node = node;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a78fdee40c..5de058c64d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2788,6 +2788,7 @@ bool virDomainControllerIsPSeriesPHB(const virDomainControllerDef
*cont);
virDomainFSDefPtr virDomainFSDefNew(void);
void virDomainFSDefFree(virDomainFSDefPtr def);
void virDomainActualNetDefFree(virDomainActualNetDefPtr def);
+virDomainNetDefPtr virDomainNetDefNew(virDomainXMLOptionPtr xmlopt);
void virDomainNetDefClear(virDomainNetDefPtr def);
void virDomainNetDefFree(virDomainNetDefPtr def);
void virDomainSmartcardDefFree(virDomainSmartcardDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3dece252df..b4c86b60cc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -447,6 +447,7 @@ virDomainNetBandwidthUpdate;
virDomainNetDefClear;
virDomainNetDefFormat;
virDomainNetDefFree;
+virDomainNetDefNew;
virDomainNetFind;
virDomainNetFindByName;
virDomainNetFindIdx;
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 5ed2b423cb..28fd64895e 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -219,7 +219,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
} else if (ret > 0) {
token = strtok_r(temp, " ", &saveptr);
while (token != NULL) {
- if (VIR_ALLOC(net) < 0)
+ if (!(net = virDomainNetDefNew(NULL)))
goto error;
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
@@ -248,7 +248,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
token = strtok_r(temp, ";", &saveptr);
while (token != NULL) {
/*add new device to list*/
- if (VIR_ALLOC(net) < 0)
+ if (!(net = virDomainNetDefNew(NULL)))
goto error;
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 351425fedd..de349954cf 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -1037,7 +1037,7 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt,
nkeywords = 0;
}
- if (VIR_ALLOC(def) < 0)
+ if (!(def = virDomainNetDefNew(xmlopt)))
goto cleanup;
/* 'tap' could turn into libvirt type=ethernet, type=bridge or
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 72a24a3464..28a50b477b 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3690,7 +3690,7 @@ vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter)
char *utf8 = NULL;
virDomainNetDefPtr net = NULL;
- if (VIR_ALLOC(net) < 0)
+ if (!(net = virDomainNetDefNew(NULL)))
return NULL;
gVBoxAPI.UINetworkAdapter.GetAttachmentType(adapter, &attachmentType);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index df6a58a474..e6026edc56 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2628,7 +2628,7 @@ virVMXParseEthernet(virConfPtr conf, int controller,
virDomainNetDefPtr *def)
if (! present/* && ! startConnected*/)
return 0;
- if (VIR_ALLOC(*def) < 0)
+ if (!(*def = virDomainNetDefNew(NULL)))
return -1;
/* vmx:connectionType -> def:type */
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index a2b0708ee3..80bc267bbe 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -942,7 +942,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char
*vif_typename)
key = nextkey;
}
- if (VIR_ALLOC(net) < 0)
+ if (!(net = virDomainNetDefNew(NULL)))
goto cleanup;
if (mac[0]) {
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index e868c05695..54dd7fc3ed 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -600,7 +600,7 @@ xenParseSxprNets(virDomainDefPtr def,
model = sexpr_node(node, "device/vif/model");
type = sexpr_node(node, "device/vif/type");
- if (VIR_ALLOC(net) < 0)
+ if (!(net = virDomainNetDefNew(NULL)))
goto cleanup;
if (tmp != NULL ||
--
2.16.1