[libvirt] [libvirt-glib PATCHv2 2/5] gobject: Add API to query connection interfaces

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Jun 30 12:22:18 UTC 2015


Hi Christophe,

Thanks for reviewing.

>> +gboolean gvir_connection_fetch_interfaces(GVirConnection *conn,
>> +                                          GCancellable *cancellable,
>> +                                          GError **err)
>> +{
>> +    GVirConnectionPrivate *priv;
>> +    GHashTable *interfaces;
>> +    gchar **inactive = NULL;
>> +    gint ninactive = 0;
>> +    gchar **active = NULL;
>> +    gint nactive = 0;
>> +    gboolean ret = FALSE;
>> +    gint i;
>> +    virConnectPtr vconn = NULL;
>> +    GError *lerr = NULL;
>> +
>> +    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
>> +    g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable),
>> +                         FALSE);
>> +    g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
>> +
>> +    priv = conn->priv;
>> +    g_mutex_lock(priv->lock);
>> +    if (!priv->conn) {
>> +        g_set_error_literal(err, GVIR_CONNECTION_ERROR,
>> +                            0,
>> +                            _("Connection is not open"));
>> +        g_mutex_unlock(priv->lock);
>> +        goto cleanup;
>> +    }
>> +    vconn = priv->conn;
>> +    /* Stop another thread closing the connection just at the minute */
>> +    virConnectRef(vconn);
>> +    g_mutex_unlock(priv->lock);
>> +
>> +    if (g_cancellable_set_error_if_cancelled(cancellable, err))
>> +        goto cleanup;
>> +
>> +    active = fetch_list(vconn,
>> +                        "Interfaces",
>> +                        virConnectNumOfInterfaces,
>> +                        virConnectListInterfaces,
>> +                        cancellable,
>> +                        &nactive,
>> +                        &lerr);
>
> Would it be possible to use virConnectListAllInterfaces() rather than
> this awkward split between active/inactive interfaces? (which is also
> likely to be racy if one interface becomes active between the 2
> fetch_list calls).

Yeah I was just using existing code as bases for this. I'll change
other code too..

>> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
>> index 29c4349..b7ce1d5 100644
>> --- a/libvirt-gobject/libvirt-gobject.sym
>> +++ b/libvirt-gobject/libvirt-gobject.sym
>> @@ -273,6 +273,11 @@ LIBVIRT_GOBJECT_0.2.1 {
>>
>>  LIBVIRT_GOBJECT_0.2.2 {
>>    global:
>> +     gvir_connection_fetch_interfaces;
>
> No async variant ?
>
> Christophe
>
>> +     gvir_connection_find_interface_by_mac;
>> +     gvir_connection_get_interface;
>> +     gvir_connection_get_interfaces;
>> +
>>       gvir_interface_get_mac;
>>  } LIBVIRT_GOBJECT_0.2.1;

The existing _fetch() methods don't have async variants so I didn't
add here either. I'll look into adding those..

-- 
Regards,

Zeeshan Ali (Khattak)
________________________________________
Befriend GNOME: http://www.gnome.org/friends/




More information about the libvir-list mailing list