]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: domain: Add helper to lookup disk by node name
authorPeter Krempa <pkrempa@redhat.com>
Wed, 22 Feb 2017 16:51:05 +0000 (17:51 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Mar 2017 07:29:57 +0000 (09:29 +0200)
Looks up a disk and its corresponding backing chain element by node
name.

src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index f4636ed0b12f0dcb0a347f54079f8f57e945ae21..34f4d014ba4d326fe33f55bbba13cb13d2924e5a 100644 (file)
@@ -8515,3 +8515,46 @@ 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 its 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 (!idx)
+        idx = &srcindex;
+
+    if (src)
+        *src = NULL;
+
+    *idx = 0;
+
+    for (i = 0; i < def->ndisks; i++) {
+        if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src,
+                                                  nodename, idx))) {
+            if (src)
+                *src = tmp;
+
+            return def->disks[i];
+        }
+    }
+
+    return NULL;
+}
index 1dd3b1c39a86a7a90b79b0c3e59005a469e9d4e6..efdf3934869a465fe9b2aba53914d4deeb9d27d9 100644 (file)
@@ -877,4 +877,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__ */