nodedev: add internal virNodeDeviceObjListFind()
This is a generic function that you can provide your own predicate function to search for a particular device. It will be used in an upcoming commit. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
1280a631ef
commit
fdfe4b2837
@ -1023,9 +1023,9 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct virNodeDeviceObjListRemoveHelperData
|
typedef struct _PredicateHelperData PredicateHelperData;
|
||||||
{
|
struct _PredicateHelperData {
|
||||||
virNodeDeviceObjListRemoveIterator callback;
|
virNodeDeviceObjListPredicate predicate;
|
||||||
void *opaque;
|
void *opaque;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1033,9 +1033,9 @@ static int virNodeDeviceObjListRemoveHelper(void *key G_GNUC_UNUSED,
|
|||||||
void *value,
|
void *value,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
struct virNodeDeviceObjListRemoveHelperData *data = opaque;
|
PredicateHelperData *data = opaque;
|
||||||
|
|
||||||
return data->callback(value, data->opaque);
|
return data->predicate(value, data->opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1051,11 +1051,11 @@ static int virNodeDeviceObjListRemoveHelper(void *key G_GNUC_UNUSED,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
||||||
virNodeDeviceObjListRemoveIterator callback,
|
virNodeDeviceObjListPredicate callback,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
struct virNodeDeviceObjListRemoveHelperData data = {
|
PredicateHelperData data = {
|
||||||
.callback = callback,
|
.predicate = callback,
|
||||||
.opaque = opaque
|
.opaque = opaque
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1065,3 +1065,40 @@ virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
|||||||
&data);
|
&data);
|
||||||
virObjectRWUnlock(devs);
|
virObjectRWUnlock(devs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int virNodeDeviceObjListFindHelper(const void *payload,
|
||||||
|
const char *name G_GNUC_UNUSED,
|
||||||
|
const void *opaque)
|
||||||
|
{
|
||||||
|
PredicateHelperData *data = (PredicateHelperData *) opaque;
|
||||||
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
||||||
|
|
||||||
|
return data->predicate(obj, data->opaque);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNodeDeviceObjListFind
|
||||||
|
* @devs: Pointer to object list
|
||||||
|
* @predicate: function to test the device for a certain property
|
||||||
|
* @opaque: Opaque data to use as argument to helper
|
||||||
|
*
|
||||||
|
* For each object in @devs, call the @predicate helper using @opaque as
|
||||||
|
* an argument until it returns TRUE. The list may not be modified while
|
||||||
|
* iterating.
|
||||||
|
*/
|
||||||
|
virNodeDeviceObj *
|
||||||
|
virNodeDeviceObjListFind(virNodeDeviceObjList *devs,
|
||||||
|
virNodeDeviceObjListPredicate predicate,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
PredicateHelperData data = {
|
||||||
|
.predicate = predicate,
|
||||||
|
.opaque = opaque
|
||||||
|
};
|
||||||
|
|
||||||
|
return virNodeDeviceObjListSearch(devs,
|
||||||
|
virNodeDeviceObjListFindHelper,
|
||||||
|
&data);
|
||||||
|
}
|
||||||
|
@ -136,9 +136,14 @@ void
|
|||||||
virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
||||||
bool persistent);
|
bool persistent);
|
||||||
|
|
||||||
typedef bool (*virNodeDeviceObjListRemoveIterator)(virNodeDeviceObj *obj,
|
typedef bool (*virNodeDeviceObjListPredicate)(virNodeDeviceObj *obj,
|
||||||
const void *opaque);
|
const void *opaque);
|
||||||
|
|
||||||
void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
||||||
virNodeDeviceObjListRemoveIterator callback,
|
virNodeDeviceObjListPredicate callback,
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
||||||
|
virNodeDeviceObj *
|
||||||
|
virNodeDeviceObjListFind(virNodeDeviceObjList *devs,
|
||||||
|
virNodeDeviceObjListPredicate callback,
|
||||||
|
void *opaque);
|
||||||
|
@ -1290,6 +1290,7 @@ virNodeDeviceObjIsActive;
|
|||||||
virNodeDeviceObjIsPersistent;
|
virNodeDeviceObjIsPersistent;
|
||||||
virNodeDeviceObjListAssignDef;
|
virNodeDeviceObjListAssignDef;
|
||||||
virNodeDeviceObjListExport;
|
virNodeDeviceObjListExport;
|
||||||
|
virNodeDeviceObjListFind;
|
||||||
virNodeDeviceObjListFindByName;
|
virNodeDeviceObjListFindByName;
|
||||||
virNodeDeviceObjListFindBySysfsPath;
|
virNodeDeviceObjListFindBySysfsPath;
|
||||||
virNodeDeviceObjListFindMediatedDeviceByUUID;
|
virNodeDeviceObjListFindMediatedDeviceByUUID;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user