[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [RFC PATCH 10/12] 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 b8a65cfd5..1740a9d80 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8341,3 +8341,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 6e847c7ae..705a3ad59 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -859,4 +859,7 @@ char *qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
                                         virStorageSourcePtr src,
                                         unsigned int idx);

+virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr,
+                                                       virDomainDefPtr def);
+
 #endif /* __QEMU_DOMAIN_H__ */
-- 
2.11.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]