[libvirt] [PATCH 07/23] qemu: domain: Add helper to lookup disk by node name

Peter Krempa posted 23 patches 8 years, 11 months ago
[libvirt] [PATCH 07/23] qemu: domain: Add helper to lookup disk by node name
Posted by Peter Krempa 8 years, 11 months ago
Looks up a disk and it's corresponding backing chain element by node
name.
---
 src/qemu/qemu_domain.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  6 ++++++
 2 files changed, 49 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 07ce22417..95ea63615 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8369,3 +8369,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 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 (!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;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index c646828e6..15eb72a5c 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -852,4 +852,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.12.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 07/23] qemu: domain: Add helper to lookup disk by node name
Posted by Eric Blake 8 years, 10 months ago
On 03/15/2017 11:37 AM, Peter Krempa wrote:
> Looks up a disk and it's corresponding backing chain element by node

s/it's/its/  (remember, "it's" is only appropriate if "it is" or "it
has" can be used in its place)

> name.
> ---
>  src/qemu/qemu_domain.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_domain.h |  6 ++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 07ce22417..95ea63615 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -8369,3 +8369,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 it's definition.

s/it's/its/

> + * Optionally fills @src and @idx if provided with the specific backing chain
> + * element which corresponds to the node name.
> + */

ACK with typos fixed

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

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