[RFC PATCH 05/12] qemu: domain: Add helper to lookup disk by node name

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

 



Looks up a disk and it's corresponding backing chain element by node
name.
---
 src/qemu/qemu_domain.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  6 ++++++
 2 files changed, 50 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c187214dc..4b446f1e8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8275,3 +8275,47 @@ 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 it's 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 (src)
+        *src = NULL;
+
+    if (idx)
+        *idx = 0;
+
+    for (i = 0; i < def->ndisks; i++) {
+        if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src,
+                                                  nodename, &srcindex))) {
+            if (src)
+                *src = tmp;
+
+            if (idx)
+                *idx = srcindex;
+
+            return def->disks[i];
+        }
+    }
+
+    return NULL;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 72efa3336..03377645f 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -849,4 +849,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__ */
-- 
2.11.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux