[PATCH 2/3] qemu: block: Add code to fetch block node data by node name

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

 



To allow updating stats based on the node name, add a helper function
that will fetch the required data from 'query-named-block-nodes' and
return it in hash table for easy lookup.
---
 src/qemu/qemu_block.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_block.h |  3 +++
 2 files changed, 49 insertions(+)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index e31907842..586d56809 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -380,3 +380,49 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,

     return ret;
 }
+
+
+static int
+qemuBlockFillNodeData(size_t pos ATTRIBUTE_UNUSED,
+                      virJSONValuePtr item,
+                      void *opaque)
+{
+    virHashTablePtr table = opaque;
+    const char *name;
+
+    if (!(name = virJSONValueObjectGetString(item, "node-name")))
+        return 1;
+
+    if (virHashAddEntry(table, name, item) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+/**
+ * qemuBlockGetNodeData:
+ * @data: JSON object returned from query-named-block-nodes
+ *
+ * Returns a hash table organized by the node name of the JSON value objects of
+ * data for given qemu block nodes.
+ *
+ * Returns a filled virHashTablePtr on success NULL on error.
+ */
+virHashTablePtr
+qemuBlockGetNodeData(virJSONValuePtr data)
+{
+    virHashTablePtr ret = NULL;
+
+    if (!(ret = virHashCreate(50, virJSONValueHashFree)))
+        return NULL;
+
+    if (virJSONValueArrayForeachSteal(data, qemuBlockFillNodeData, ret) < 0)
+        goto error;
+
+    return ret;
+
+ error:
+    virHashFree(ret);
+    return NULL;
+}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 56f4a74dd..9d6a24643 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -48,4 +48,7 @@ int
 qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
                          virDomainObjPtr vm);

+virHashTablePtr
+qemuBlockGetNodeData(virJSONValuePtr data);
+
 #endif /* __QEMU_BLOCK_H__ */
-- 
2.12.0

--
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