提交 00a3f0d0 编写于 作者: J John Ferlan

secret: Introduce virSecretObjListFindBy{UUID|Usage} support

New API's including unlocked and Locked versions in order to be able
to use in either manner.

Support for searching hash object lists instead of linked lists will
replace existing secret_driver functions secretFindByUUID and
secretFindByUsage
上级 4652b158
......@@ -136,3 +136,143 @@ virSecretObjListDispose(void *obj)
virHashFree(secrets->objs);
}
/**
* virSecretObjFindByUUIDLocked:
* @secrets: list of secret objects
* @uuid: secret uuid to find
*
* This functions requires @secrets to be locked already!
*
* Returns: not locked, but ref'd secret object.
*/
virSecretObjPtr
virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets,
const unsigned char *uuid)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(uuid, uuidstr);
return virObjectRef(virHashLookup(secrets->objs, uuidstr));
}
/**
* virSecretObjFindByUUID:
* @secrets: list of secret objects
* @uuid: secret uuid to find
*
* This function locks @secrets and finds the secret object which
* corresponds to @uuid.
*
* Returns: locked and ref'd secret object.
*/
virSecretObjPtr
virSecretObjListFindByUUID(virSecretObjListPtr secrets,
const unsigned char *uuid)
{
virSecretObjPtr ret;
virObjectLock(secrets);
ret = virSecretObjListFindByUUIDLocked(secrets, uuid);
virObjectUnlock(secrets);
if (ret)
virObjectLock(ret);
return ret;
}
static int
virSecretObjSearchName(const void *payload,
const void *name ATTRIBUTE_UNUSED,
const void *opaque)
{
virSecretObjPtr secret = (virSecretObjPtr) payload;
struct virSecretSearchData *data = (struct virSecretSearchData *) opaque;
int found = 0;
virObjectLock(secret);
if (secret->def->usage_type != data->usageType)
goto cleanup;
switch (data->usageType) {
case VIR_SECRET_USAGE_TYPE_NONE:
/* never match this */
break;
case VIR_SECRET_USAGE_TYPE_VOLUME:
if (STREQ(secret->def->usage.volume, data->usageID))
found = 1;
break;
case VIR_SECRET_USAGE_TYPE_CEPH:
if (STREQ(secret->def->usage.ceph, data->usageID))
found = 1;
break;
case VIR_SECRET_USAGE_TYPE_ISCSI:
if (STREQ(secret->def->usage.target, data->usageID))
found = 1;
break;
}
cleanup:
virObjectUnlock(secret);
return found;
}
/**
* virSecretObjFindByUsageLocked:
* @secrets: list of secret objects
* @usageType: secret usageType to find
* @usageID: secret usage string
*
* This functions requires @secrets to be locked already!
*
* Returns: not locked, but ref'd secret object.
*/
virSecretObjPtr
virSecretObjListFindByUsageLocked(virSecretObjListPtr secrets,
int usageType,
const char *usageID)
{
virSecretObjPtr ret = NULL;
struct virSecretSearchData data = { .usageType = usageType,
.usageID = usageID };
ret = virHashSearch(secrets->objs, virSecretObjSearchName, &data);
if (ret)
virObjectRef(ret);
return ret;
}
/**
* virSecretObjFindByUsage:
* @secrets: list of secret objects
* @usageType: secret usageType to find
* @usageID: secret usage string
*
* This function locks @secrets and finds the secret object which
* corresponds to @usageID of @usageType.
*
* Returns: locked and ref'd secret object.
*/
virSecretObjPtr
virSecretObjListFindByUsage(virSecretObjListPtr secrets,
int usageType,
const char *usageID)
{
virSecretObjPtr ret;
virObjectLock(secrets);
ret = virSecretObjListFindByUsageLocked(secrets, usageType, usageID);
virObjectUnlock(secrets);
if (ret)
virObjectLock(ret);
return ret;
}
......@@ -46,4 +46,18 @@ typedef virSecretObjList *virSecretObjListPtr;
virSecretObjListPtr virSecretObjListNew(void);
virSecretObjPtr virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets,
const unsigned char *uuid);
virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets,
const unsigned char *uuid);
virSecretObjPtr virSecretObjListFindByUsageLocked(virSecretObjListPtr secrets,
int usageType,
const char *usageID);
virSecretObjPtr virSecretObjListFindByUsage(virSecretObjListPtr secrets,
int usageType,
const char *usageID);
#endif /* __VIRSECRETOBJ_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册