qemu: domain: Add helper to look up disk soruce by the backing store string

This commit is contained in:
Peter Krempa 2017-02-23 19:14:47 +01:00
parent 97148962b5
commit 9b93c4c264
2 changed files with 40 additions and 0 deletions

View File

@ -8580,3 +8580,40 @@ qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
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;
}

View File

@ -887,4 +887,7 @@ char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
virStorageSourcePtr src,
unsigned int idx);
virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
virDomainDefPtr def);
#endif /* __QEMU_DOMAIN_H__ */