From 9b93c4c26483308371aae3ae30bf5536c88b7f4b Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 23 Feb 2017 19:14:47 +0100 Subject: [PATCH] qemu: domain: Add helper to look up disk soruce by the backing store string --- src/qemu/qemu_domain.c | 37 +++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 57b610c221..20999cd3df 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 74d76a88cd..7a9cfad52c 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -887,4 +887,7 @@ char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk, virStorageSourcePtr src, unsigned int idx); +virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr, + virDomainDefPtr def); + #endif /* __QEMU_DOMAIN_H__ */