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

Christophe Fergeau cfergeau at redhat.com
Sun Feb 19 12:50:48 UTC 2012


On Sat, Feb 18, 2012 at 07:24:03PM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
> 
> Mostly just a wrapper around virNodeGetInfo() and virNodeInfo struct.

Apart from the 2 small comments below, I'm wondering if we should introduce
a GVirNode class to wrap the virNode* methods. There are currently 5 to 10
such methods (forgot the exact numbers), if more are to come, this would
"bloat" the GVirConnection class. Any thoughts on that?

Christophe

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

Why not g_strncpy here?

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

gvir_connection_get_node_info is missing here.

> -- 
> 1.7.7.6
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120219/07c90fc6/attachment-0001.sig>


More information about the libvir-list mailing list