]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: Introduce virNodeDeviceObjNew
authorJohn Ferlan <jferlan@redhat.com>
Fri, 12 May 2017 17:34:23 +0000 (13:34 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 17 Jul 2017 14:40:24 +0000 (10:40 -0400)
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@redhat.com>
src/conf/virnodedeviceobj.c

index 619c32df0eaa3ccc3b82292d81daf03f087d66b3..8645f80e54cbdcd47eb1714d580c8959a6ce41ea 100644 (file)
 VIR_LOG_INIT("conf.virnodedeviceobj");
 
 
+static virNodeDeviceObjPtr
+virNodeDeviceObjNew(void)
+{
+    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);
+
+    return obj;
+}
+
+
 virNodeDeviceDefPtr
 virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj)
 {
@@ -276,16 +296,8 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
         return 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);
+    if (!(obj = virNodeDeviceObjNew()))
         return NULL;
-    }
-    virNodeDeviceObjLock(obj);
 
     if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) {
         virNodeDeviceObjUnlock(obj);
@@ -295,7 +307,6 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
     obj->def = def;
 
     return obj;
-
 }