[libvirt-glib 1/2] API to get node information about the connection

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

 



From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>

Mostly just a wrapper around virNodeGetInfo() and virNodeInfo struct.
---
 libvirt-gobject/libvirt-gobject-connection.c |   49 ++++++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-connection.h |   17 +++++++++
 libvirt-gobject/libvirt-gobject.sym          |    1 +
 3 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index cb19e9d..c2691f7 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -71,6 +71,21 @@ gvir_connection_error_quark(void)
     return g_quark_from_static_string("gvir-connection");
 }
 
+static GVirNodeInfo *
+gvir_node_info_copy(GVirNodeInfo *info)
+{
+    return g_slice_dup(GVirNodeInfo, info);
+}
+
+static void
+gvir_node_info_free(GVirNodeInfo *info)
+{
+    g_slice_free(GVirNodeInfo, info);
+}
+
+G_DEFINE_BOXED_TYPE(GVirNodeInfo, gvir_node_info,
+                    gvir_node_info_copy, gvir_node_info_free)
+
 static void gvir_connection_get_property(GObject *object,
                                          guint prop_id,
                                          GValue *value,
@@ -1338,3 +1353,37 @@ GVirStoragePool *gvir_connection_create_storage_pool
 
     return g_object_ref(pool);
 }
+
+/**
+ * gvir_connection_get_node_info:
+ * @conn: the connection
+ * @err: return location for any #GError
+ *
+ * Returns: (transfer full): the info
+ */
+GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
+                                            GError **err)
+{
+    GVirConnectionPrivate *priv = conn->priv;
+    virNodeInfo info;
+    GVirNodeInfo *ret;
+
+    if (virNodeGetInfo(priv->conn, &info) < 0) {
+        gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+                               0,
+                               "Unable to get node info");
+        return NULL;
+    }
+
+    ret = g_slice_new(GVirNodeInfo);
+    g_memmove (ret->model, info.model, sizeof (ret->model));
+    ret->memory = info.memory;
+    ret->cpus = info.cpus;
+    ret->mhz = info.mhz;
+    ret->nodes = info.nodes;
+    ret->sockets = info.sockets;
+    ret->cores = info.cores;
+    ret->threads = info.threads;
+
+    return ret;
+}
diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
index 477a0c3..3cc60a2 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -38,6 +38,19 @@ G_BEGIN_DECLS
 
 #define GVIR_TYPE_CONNECTION_HANDLE      (gvir_connection_handle_get_type ())
 
+typedef struct _GVirNodeInfo GVirNodeInfo;
+struct _GVirNodeInfo
+{
+    gchar model[32]; /* string indicating the CPU model */
+    gulong memory;   /* memory size in kilobytes */
+    guint cpus;      /* the number of active CPUs */
+    guint mhz;       /* expected CPU frequency */
+    guint nodes;     /* the number of NUMA cell, 1 for unusual NUMA topologies or uniform memo */
+    guint sockets;   /* number of CPU sockets per node if nodes > 1, total number of CPU socke */
+    guint cores;     /* number of cores per socket */
+    guint threads;   /* number of threads per core */
+};
+
 typedef struct _GVirConnection GVirConnection;
 typedef struct _GVirConnectionPrivate GVirConnectionPrivate;
 typedef struct _GVirConnectionClass GVirConnectionClass;
@@ -69,6 +82,7 @@ struct _GVirConnectionClass
 
 GType gvir_connection_get_type(void);
 GType gvir_connection_handle_get_type(void);
+GType gvir_node_info_get_type(void);
 
 GVirConnection *gvir_connection_new(const char *uri);
 gboolean gvir_connection_open(GVirConnection *conn,
@@ -174,6 +188,9 @@ GVirStoragePool *gvir_connection_create_storage_pool
 GVirStream *gvir_connection_get_stream(GVirConnection *conn,
                                        guint flags);
 
+GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
+                                            GError **err);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 7a2f65d..9e63773 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -4,6 +4,7 @@ LIBVIRT_GOBJECT_0.0.4 {
         gvir_init_object_check;
 
 	gvir_connection_get_type;
+	gvir_node_info_get_type;
 	gvir_connection_new;
 	gvir_connection_open;
 	gvir_connection_open_async;
-- 
1.7.7.6

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