mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
nodedev: add helper functions to remove node devices
When a mediated device is stopped or undefined by an application outside of libvirt, we need to remove it from our list of node devices within libvirt. This patch introduces virNodeDeviceObjListRemoveLocked() and virNodeDeviceObjListForEachRemove() (which are analogous to other types of object lists in libvirt) to facilitate that. They will be used in coming commits. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
aa897d46d5
commit
00b649d0cf
@ -507,23 +507,29 @@ void
|
|||||||
virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
|
virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
|
||||||
virNodeDeviceObjPtr obj)
|
virNodeDeviceObjPtr obj)
|
||||||
{
|
{
|
||||||
virNodeDeviceDefPtr def;
|
|
||||||
|
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return;
|
return;
|
||||||
def = obj->def;
|
|
||||||
|
|
||||||
virObjectRef(obj);
|
virObjectRef(obj);
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
virObjectRWLockWrite(devs);
|
virObjectRWLockWrite(devs);
|
||||||
virObjectLock(obj);
|
virObjectLock(obj);
|
||||||
virHashRemoveEntry(devs->objs, def->name);
|
virNodeDeviceObjListRemoveLocked(devs, obj);
|
||||||
virObjectUnlock(obj);
|
virObjectUnlock(obj);
|
||||||
virObjectUnref(obj);
|
virObjectUnref(obj);
|
||||||
virObjectRWUnlock(devs);
|
virObjectRWUnlock(devs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The caller must hold lock on 'devs' */
|
||||||
|
void
|
||||||
|
virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs,
|
||||||
|
virNodeDeviceObj *dev)
|
||||||
|
{
|
||||||
|
virHashRemoveEntry(devs->objs, dev->def->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the NPIV dev's parent device name
|
* Return the NPIV dev's parent device name
|
||||||
*/
|
*/
|
||||||
@ -1019,3 +1025,47 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
|||||||
{
|
{
|
||||||
obj->persistent = persistent;
|
obj->persistent = persistent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct virNodeDeviceObjListRemoveHelperData
|
||||||
|
{
|
||||||
|
virNodeDeviceObjListRemoveIterator callback;
|
||||||
|
void *opaque;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int virNodeDeviceObjListRemoveHelper(void *key G_GNUC_UNUSED,
|
||||||
|
void *value,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
struct virNodeDeviceObjListRemoveHelperData *data = opaque;
|
||||||
|
|
||||||
|
return data->callback(value, data->opaque);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNodeDeviceObjListForEachRemove
|
||||||
|
* @devs: Pointer to object list
|
||||||
|
* @callback: function to call for each device object
|
||||||
|
* @opaque: Opaque data to use as argument to helper
|
||||||
|
*
|
||||||
|
* For each object in @devs, call the @callback helper using @opaque as
|
||||||
|
* an argument. If @callback returns true, that item will be removed from the
|
||||||
|
* object list.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
||||||
|
virNodeDeviceObjListRemoveIterator callback,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
struct virNodeDeviceObjListRemoveHelperData data = {
|
||||||
|
.callback = callback,
|
||||||
|
.opaque = opaque
|
||||||
|
};
|
||||||
|
|
||||||
|
virObjectRWLockWrite(devs);
|
||||||
|
g_hash_table_foreach_remove(devs->objs,
|
||||||
|
virNodeDeviceObjListRemoveHelper,
|
||||||
|
&data);
|
||||||
|
virObjectRWUnlock(devs);
|
||||||
|
}
|
||||||
|
@ -80,6 +80,10 @@ void
|
|||||||
virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
|
virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs,
|
||||||
virNodeDeviceObjPtr dev);
|
virNodeDeviceObjPtr dev);
|
||||||
|
|
||||||
|
void
|
||||||
|
virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs,
|
||||||
|
virNodeDeviceObj *dev);
|
||||||
|
|
||||||
int
|
int
|
||||||
virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs,
|
virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs,
|
||||||
virNodeDeviceDefPtr def);
|
virNodeDeviceDefPtr def);
|
||||||
@ -134,3 +138,10 @@ virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj);
|
|||||||
void
|
void
|
||||||
virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
||||||
bool persistent);
|
bool persistent);
|
||||||
|
|
||||||
|
typedef bool (*virNodeDeviceObjListRemoveIterator)(virNodeDeviceObj *obj,
|
||||||
|
const void *opaque);
|
||||||
|
|
||||||
|
void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
||||||
|
virNodeDeviceObjListRemoveIterator callback,
|
||||||
|
void *opaque);
|
||||||
|
@ -1280,12 +1280,14 @@ virNodeDeviceObjListFindByName;
|
|||||||
virNodeDeviceObjListFindBySysfsPath;
|
virNodeDeviceObjListFindBySysfsPath;
|
||||||
virNodeDeviceObjListFindMediatedDeviceByUUID;
|
virNodeDeviceObjListFindMediatedDeviceByUUID;
|
||||||
virNodeDeviceObjListFindSCSIHostByWWNs;
|
virNodeDeviceObjListFindSCSIHostByWWNs;
|
||||||
|
virNodeDeviceObjListForEachRemove;
|
||||||
virNodeDeviceObjListFree;
|
virNodeDeviceObjListFree;
|
||||||
virNodeDeviceObjListGetNames;
|
virNodeDeviceObjListGetNames;
|
||||||
virNodeDeviceObjListGetParentHost;
|
virNodeDeviceObjListGetParentHost;
|
||||||
virNodeDeviceObjListNew;
|
virNodeDeviceObjListNew;
|
||||||
virNodeDeviceObjListNumOfDevices;
|
virNodeDeviceObjListNumOfDevices;
|
||||||
virNodeDeviceObjListRemove;
|
virNodeDeviceObjListRemove;
|
||||||
|
virNodeDeviceObjListRemoveLocked;
|
||||||
virNodeDeviceObjSetActive;
|
virNodeDeviceObjSetActive;
|
||||||
virNodeDeviceObjSetPersistent;
|
virNodeDeviceObjSetPersistent;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user