mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 07:05:28 +00:00
qemu: domain: Add helper to lookup disk by node name
Looks up a disk and its corresponding backing chain element by node name.
This commit is contained in:
parent
73d4b32427
commit
1a5e2a8098
@ -8515,3 +8515,46 @@ qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
|
||||
cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainDiskLookupByNodename:
|
||||
* @def: domain definition to look for the disk
|
||||
* @nodename: block backend node name to find
|
||||
* @src: filled with the specific backing store element if provided
|
||||
* @idx: index of @src in the backing chain, if provided
|
||||
*
|
||||
* Looks up the disk in the domain via @nodename and returns its definition.
|
||||
* Optionally fills @src and @idx if provided with the specific backing chain
|
||||
* element which corresponds to the node name.
|
||||
*/
|
||||
virDomainDiskDefPtr
|
||||
qemuDomainDiskLookupByNodename(virDomainDefPtr def,
|
||||
const char *nodename,
|
||||
virStorageSourcePtr *src,
|
||||
unsigned int *idx)
|
||||
{
|
||||
size_t i;
|
||||
unsigned int srcindex;
|
||||
virStorageSourcePtr tmp = NULL;
|
||||
|
||||
if (!idx)
|
||||
idx = &srcindex;
|
||||
|
||||
if (src)
|
||||
*src = NULL;
|
||||
|
||||
*idx = 0;
|
||||
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src,
|
||||
nodename, idx))) {
|
||||
if (src)
|
||||
*src = tmp;
|
||||
|
||||
return def->disks[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -877,4 +877,10 @@ int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
|
||||
int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virDomainRNGDefPtr rng);
|
||||
|
||||
virDomainDiskDefPtr qemuDomainDiskLookupByNodename(virDomainDefPtr def,
|
||||
const char *nodename,
|
||||
virStorageSourcePtr *src,
|
||||
unsigned int *idx);
|
||||
|
||||
#endif /* __QEMU_DOMAIN_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user