mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 06:25:19 +00:00
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: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
aa6e856b95
commit
65981c8596
@ -33,6 +33,26 @@
|
|||||||
VIR_LOG_INIT("conf.virnodedeviceobj");
|
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
|
virNodeDeviceDefPtr
|
||||||
virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj)
|
virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj)
|
||||||
{
|
{
|
||||||
@ -276,17 +296,9 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(obj) < 0)
|
if (!(obj = virNodeDeviceObjNew()))
|
||||||
return NULL;
|
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) {
|
if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) {
|
||||||
virNodeDeviceObjUnlock(obj);
|
virNodeDeviceObjUnlock(obj);
|
||||||
virNodeDeviceObjFree(obj);
|
virNodeDeviceObjFree(obj);
|
||||||
@ -295,7 +307,6 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs,
|
|||||||
obj->def = def;
|
obj->def = def;
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user