mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
qemu: block: Add code to fetch block node data by node name
To allow updating stats based on the node name, add a helper function that will fetch the required data from 'query-named-block-nodes' and return it in hash table for easy lookup.
This commit is contained in:
parent
86e51d68f9
commit
51c4b744d8
@ -380,3 +380,49 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuBlockFillNodeData(size_t pos ATTRIBUTE_UNUSED,
|
||||||
|
virJSONValuePtr item,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
virHashTablePtr table = opaque;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
if (!(name = virJSONValueObjectGetString(item, "node-name")))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (virHashAddEntry(table, name, item) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuBlockGetNodeData:
|
||||||
|
* @data: JSON object returned from query-named-block-nodes
|
||||||
|
*
|
||||||
|
* Returns a hash table organized by the node name of the JSON value objects of
|
||||||
|
* data for given qemu block nodes.
|
||||||
|
*
|
||||||
|
* Returns a filled virHashTablePtr on success NULL on error.
|
||||||
|
*/
|
||||||
|
virHashTablePtr
|
||||||
|
qemuBlockGetNodeData(virJSONValuePtr data)
|
||||||
|
{
|
||||||
|
virHashTablePtr ret = NULL;
|
||||||
|
|
||||||
|
if (!(ret = virHashCreate(50, virJSONValueHashFree)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (virJSONValueArrayForeachSteal(data, qemuBlockFillNodeData, ret) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virHashFree(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -48,4 +48,7 @@ int
|
|||||||
qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
|
qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm);
|
virDomainObjPtr vm);
|
||||||
|
|
||||||
|
virHashTablePtr
|
||||||
|
qemuBlockGetNodeData(virJSONValuePtr data);
|
||||||
|
|
||||||
#endif /* __QEMU_BLOCK_H__ */
|
#endif /* __QEMU_BLOCK_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user