Re: [libvirt-glib][PATCH v3 1/2] gobject: Introduce gvir_connection_get_hypervisor_name

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

 



On 12.09.2012 17:54, Christophe Fergeau wrote:
> On Wed, Sep 12, 2012 at 05:32:00PM +0200, Michal Privoznik wrote:
>> which is basically a wrapper for virConnectGetType().
>> ---
>>
>> The list is sad as it hasn't delivered previous version.
>>
>>  examples/conn-test.c                         |   12 +++++++
>>  libvirt-gobject/libvirt-gobject-connection.c |   45 ++++++++++++++++++++++++++
>>  libvirt-gobject/libvirt-gobject-connection.h |    3 ++
>>  libvirt-gobject/libvirt-gobject.sym          |    5 +++
>>  4 files changed, 65 insertions(+), 0 deletions(-)
>>
>> diff --git a/examples/conn-test.c b/examples/conn-test.c
>> index 8c70997..b90d2b0 100644
>> --- a/examples/conn-test.c
>> +++ b/examples/conn-test.c
>> @@ -31,11 +31,23 @@ do_connection_open(GObject *source,
>>  {
>>      GVirConnection *conn = GVIR_CONNECTION(source);
>>      GError *err = NULL;
>> +    gchar *hv_name = NULL;
>>  
>>      if (!gvir_connection_open_finish(conn, res, &err)) {
>>          g_error("%s", err->message);
>> +        goto cleanup;
> 
> g_error() calls abort(), so this goto cleanup; is not really useful
> 
>>      }
>>      g_print("Connected to libvirt\n");
>> +
>> +    if (!(hv_name = gvir_connection_get_hypervisor_name(conn, &err))) {
>> +        g_error("%s", err->message);
>> +        goto cleanup;
>> +    }
>> +
>> +    g_print("Hypervisor name: %s\n", hv_name);
>> +
>> +cleanup:
>> +    g_free(hv_name);
>>      g_object_unref(conn);
>>  }
>>  
>> diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
>> index d826905..75bf041 100644
>> --- a/libvirt-gobject/libvirt-gobject-connection.c
>> +++ b/libvirt-gobject/libvirt-gobject-connection.c
>> @@ -1025,6 +1025,51 @@ const gchar *gvir_connection_get_uri(GVirConnection *conn)
>>      return conn->priv->uri;
>>  }
>>  
>> +/**
>> + * gvir_connection_get_hypervisor_name:
>> + * @conn: a #GVirConnection
>> + * @err: return location for any #GError
>> + *
>> + * Get name of current hypervisor used.
>> + *
>> + * Return value: new string that should be freed when no longer needed,
>> + * or NULL upon error.
>> + */
>> +gchar *
>> +gvir_connection_get_hypervisor_name(GVirConnection *conn,
>> +                                    GError **err)
>> +{
>> +    GVirConnectionPrivate *priv;
>> +    gchar *ret = NULL;
>> +    const char *type;
>> +
>> +    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
>> +    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
>> +
>> +    priv = conn->priv;
>> +    /* Stop another thread closing the connection just at the minute */
>> +    virConnectRef(priv->conn);
> 
> I'm not sure what this achieves? Another thread could close priv->conn
> right before this call, so why ref it just now? Do calls to
> virConnectGetType need to be protected with a ref?

I though it would be nice to have a reference counter increased through
this API so other thread don't close it right in the middle.
But now as I am rethinking this again - it is already done on libvirt level.
IOW in a racy situation it just make this API more probable to fetch
result. It depends if the last virConnectClose() is scheduled before of
after virConnectRef().

So yeah, I should have dropped it. Fixed on my local branch now.

Michal

> 
> 
>> +    if (!priv->conn) {
>> +        g_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
>> +                            "Connection is not open");
> 
> opened
> 
> Christophe
> 

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