[libvirt] [PATCH 13/13] nodedev: Introduce virNodeDeviceObjNew

John Ferlan jferlan at redhat.com
Fri May 19 13:08:53 UTC 2017


Create an allocator for the virNodeDeviceObjPtr - include setting up
the mutex, saving the virNodeDeviceDefPtr, and locking the return object.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/conf/virnodedeviceobj.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 86a552c..55d66f1 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -33,6 +33,27 @@
 VIR_LOG_INIT("conf.virnodedeviceobj");
 
 
+static virNodeDeviceObjPtr
+virNodeDeviceObjNew(virNodeDeviceDefPtr def)
+{
+    virNodeDeviceObjPtr obj;
+
+    if (VIR_ALLOC(obj) < 0)
+        return NULL;
+
+    if (virMutexInit(&obj->lock) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("cannot initialize mutex"));
+        VIR_FREE(obj);
+        return NULL;
+    }
+    virNodeDeviceObjLock(obj);
+    obj->def = def;
+
+    return obj;
+}
+
+
 virNodeDeviceDefPtr
 virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj)
 {
@@ -256,26 +277,16 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
         return obj;
     }
 
-    if (VIR_ALLOC(obj) < 0)
+    if (!(obj = virNodeDeviceObjNew(def)))
         return NULL;
 
-    if (virMutexInit(&obj->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("cannot initialize mutex"));
-        VIR_FREE(obj);
-        return NULL;
-    }
-    virNodeDeviceObjLock(obj);
-
     if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) {
         virNodeDeviceObjUnlock(obj);
         virNodeDeviceObjFree(obj);
         return NULL;
     }
-    obj->def = def;
 
     return obj;
-
 }
 
 
-- 
2.9.3




More information about the libvir-list mailing list