Have the call take a virNetworkDefPtr and save it in the object.
Have virNetworkObjNew return a locked obj
Avoids the need for a virNetworkObjSetDef type API for the one test need.
Update the test code and do some other name changes to make it look like
other code.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virnetworkobj.c | 10 +++++-----
src/conf/virnetworkobj.h | 2 +-
tests/networkxml2conftest.c | 13 +++++++------
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 4f32767..fa1e396 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -69,7 +69,7 @@ virNetworkObjOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virNetworkObj)
virNetworkObjPtr
-virNetworkObjNew(void)
+virNetworkObjNew(virNetworkDefPtr def)
{
virNetworkObjPtr obj;
@@ -87,6 +87,9 @@ virNetworkObjNew(void)
ignore_value(virBitmapSetBit(obj->classIdMap, 1));
ignore_value(virBitmapSetBit(obj->classIdMap, 2));
+ virObjectLock(obj);
+ obj->def = def;
+
return obj;
error:
@@ -650,16 +653,13 @@ virNetworkObjAssignDefLocked(virNetworkObjListPtr nets,
goto cleanup;
}
- if (!(obj = virNetworkObjNew()))
+ if (!(obj = virNetworkObjNew(def)))
goto cleanup;
- virObjectLock(obj);
-
virUUIDFormat(def->uuid, uuidstr);
if (virHashAddEntry(nets->objs, uuidstr, obj) < 0)
goto cleanup;
- obj->def = def;
obj->persistent = !(flags & VIR_NETWORK_OBJ_LIST_ADD_LIVE);
virObjectRef(obj);
}
diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h
index 666c2a5..b81ffa8 100644
--- a/src/conf/virnetworkobj.h
+++ b/src/conf/virnetworkobj.h
@@ -48,7 +48,7 @@ struct _virNetworkObj {
};
virNetworkObjPtr
-virNetworkObjNew(void);
+virNetworkObjNew(virNetworkDefPtr def);
virNetworkDefPtr
virNetworkObjGetDef(virNetworkObjPtr obj);
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index ab3c13a..6cbfa55 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -23,20 +23,21 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
dnsmasqCapsPtr
{
char *actual = NULL;
int ret = -1;
- virNetworkDefPtr dev = NULL;
+ virNetworkDefPtr def = NULL;
virNetworkObjPtr obj = NULL;
+ virNetworkDefPtr objdef;
virCommandPtr cmd = NULL;
char *pidfile = NULL;
dnsmasqContext *dctx = NULL;
- if (!(dev = virNetworkDefParseFile(inxml)))
+ if (!(def = virNetworkDefParseFile(inxml)))
goto fail;
- if (!(obj = virNetworkObjNew()))
+ if (!(obj = virNetworkObjNew(def)))
goto fail;
+ objdef = virNetworkObjGetDef(obj);
- obj->def = dev;
- dctx = dnsmasqContextNew(dev->name, "/var/lib/libvirt/dnsmasq");
+ dctx = dnsmasqContextNew(objdef->name, "/var/lib/libvirt/dnsmasq");
if (dctx == NULL)
goto fail;
@@ -66,7 +67,7 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
dnsmasqCapsPtr
VIR_FREE(actual);
VIR_FREE(pidfile);
virCommandFree(cmd);
- virObjectUnref(obj);
+ virNetworkObjEndAPI(&obj);
dnsmasqContextFree(dctx);
return ret;
}
--
2.9.3