mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-12 15:52:55 +00:00
qemu: domain: Add helper to look up disk soruce by the backing store string
This commit is contained in:
parent
97148962b5
commit
9b93c4c264
@ -8580,3 +8580,40 @@ qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virStorageSourcePtr
|
||||||
|
qemuDomainGetStorageSourceByDevstr(const char *devstr,
|
||||||
|
virDomainDefPtr def)
|
||||||
|
{
|
||||||
|
virDomainDiskDefPtr disk = NULL;
|
||||||
|
virStorageSourcePtr src = NULL;
|
||||||
|
char *target = NULL;
|
||||||
|
unsigned int idx;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (virStorageFileParseBackingStoreStr(devstr, &target, &idx) < 0) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("failed to parse block device '%s'"), devstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < def->ndisks; i++) {
|
||||||
|
if (STREQ(target, def->disks[i]->dst)) {
|
||||||
|
disk = def->disks[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!disk) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("failed to find disk '%s"), target);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
src = virStorageFileChainLookup(disk->src, NULL, NULL, idx, NULL);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(target);
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
@ -887,4 +887,7 @@ char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
|
|||||||
virStorageSourcePtr src,
|
virStorageSourcePtr src,
|
||||||
unsigned int idx);
|
unsigned int idx);
|
||||||
|
|
||||||
|
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
|
||||||
|
virDomainDefPtr def);
|
||||||
|
|
||||||
#endif /* __QEMU_DOMAIN_H__ */
|
#endif /* __QEMU_DOMAIN_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user