提交 65981c85 编写于 作者: J John Ferlan

nodedev: Introduce virNodeDeviceObjNew

Create an allocator for the virNodeDeviceObjPtr - include setting up
the mutex, saving the virNodeDeviceDefPtr, and locking the return object.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 aa6e856b
......@@ -33,6 +33,26 @@
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册