Google
  Web www.spinics.net

Re: [libvirt-glib 6/6] Add gvir_domain_get_devices()

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


ACK, a few nits below

On Thu, Mar 01, 2012 at 12:15:42AM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>
> 
> Currently we only support existing DomainDevice implementations:
> DomainDisk and DomainInterface.
> ---
>  .../libvirt-gobject-domain-device-private.h        |    2 +
>  libvirt-gobject/libvirt-gobject-domain-device.c    |   22 ++++++++++
>  libvirt-gobject/libvirt-gobject-domain.c           |   42 ++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h           |    3 +
>  libvirt-gobject/libvirt-gobject.sym                |    1 +
>  5 files changed, 70 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain-device-private.h b/libvirt-gobject/libvirt-gobject-domain-device-private.h
> index 72c660e..a505ecd 100644
> --- a/libvirt-gobject/libvirt-gobject-domain-device-private.h
> +++ b/libvirt-gobject/libvirt-gobject-domain-device-private.h
> @@ -24,6 +24,8 @@
>  
>  G_BEGIN_DECLS
>  
> +G_GNUC_INTERNAL GVirDomainDevice *gvir_domain_device_new(GVirDomain *domain,
> +                                                         GVirConfigDomainDevice *config);
>  virDomainPtr gvir_domain_device_get_domain_handle(GVirDomainDevice *self);
>  
>  G_END_DECLS
> diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c
> index 35d4855..f2195af 100644
> --- a/libvirt-gobject/libvirt-gobject-domain-device.c
> +++ b/libvirt-gobject/libvirt-gobject-domain-device.c
> @@ -178,3 +178,25 @@ GVirConfigDomainDevice *gvir_domain_device_get_config(GVirDomainDevice *device)
>  {
>      return g_object_ref (device->priv->config);
>  }
> +
> +G_GNUC_INTERNAL GVirDomainDevice *gvir_domain_device_new(GVirDomain *domain,
> +                                                         GVirConfigDomainDevice *config)
> +{
> +    GType type;
> +
> +    g_return_val_if_fail(GVIR_IS_DOMAIN(domain), NULL);
> +    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DEVICE(config), NULL);
> +
> +    if (GVIR_CONFIG_IS_DOMAIN_DISK(config))
> +        type = GVIR_TYPE_DOMAIN_DISK;
> +    else if (GVIR_CONFIG_IS_DOMAIN_INTERFACE(config))
> +        type = GVIR_TYPE_DOMAIN_INTERFACE;
> +    else {
> +        g_debug("Unknown device type: %s", G_OBJECT_TYPE_NAME(config));
> +        return NULL;
> +    }

Coding style nit:
(from HACKING)
 - If a brace needs to be used for one clause in an if/else statement,
   it should be used for both clauses, even if the other clauses are
   only single statements. eg

      if (foo) {
         bar;
         wizz;
      } else {
         eek;
      }

   Not

      if (foo) {
         bar;
         wizz;
      } else
         eek;

> +
> +    return GVIR_DOMAIN_DEVICE(g_object_new(type,
> +                                           "config", config,
> +                                           "domain", domain, NULL));
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index 23ad882..ae86f0e 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -29,6 +29,7 @@
>  #include "libvirt-glib/libvirt-glib.h"
>  #include "libvirt-gobject/libvirt-gobject.h"
>  #include "libvirt-gobject-compat.h"
> +#include "libvirt-gobject/libvirt-gobject-domain-device-private.h"
>  
>  #define GVIR_DOMAIN_GET_PRIVATE(obj)                         \
>          (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN, GVirDomainPrivate))
> @@ -868,3 +869,44 @@ gboolean gvir_domain_get_saved(GVirDomain *dom)
>  
>      return virDomainHasManagedSaveImage(dom->priv->handle, 0) == 1;
>  }
> +
> +/**
> + * gvir_domain_get_devices:
> + * @domain: the domain
> + * @err: place-holder for possible errors, or NULL
> + *
> + * Gets the list of devices attached to @domain
> + *
> + * Returns: (element-type LibvirtGObject.DomainDevice) (transfer full): a newly
> + * allocated #GList of #GVirDomainDevice.
> + */
> +GList *gvir_domain_get_devices(GVirDomain *domain,
> +                               GError **err)
> +{
> +    GVirConfigDomain *config;
> +    GList *config_devices;
> +    GList *node;
> +    GList *ret = NULL;
> +
> +    g_return_val_if_fail(GVIR_IS_DOMAIN(domain), NULL);

In other patches, you're testing 'err' for sanity too

> +
> +    config = gvir_domain_get_config(domain, 0, err);
> +    if (config == NULL)
> +        return ret;

return NULL would be more readable.

> +
> +    config_devices = gvir_config_domain_get_devices(config);
> +    for (node = config_devices; node != NULL; node = node->next) {
> +        GVirConfigDomainDevice *device_config;
> +        GVirDomainDevice *device;
> +
> +        device_config = GVIR_CONFIG_DOMAIN_DEVICE(node->data);
> +        device = gvir_domain_device_new(domain, device_config);
> +        if (device != NULL)
> +             ret = g_list_prepend(ret, device);
> +
> +        g_object_unref (device_config);
> +    }
> +    g_list_free (config_devices);
> +
> +    return ret;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
> index 56500a8..8a4836e 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.h
> +++ b/libvirt-gobject/libvirt-gobject-domain.h
> @@ -183,6 +183,9 @@ gboolean gvir_domain_save_finish (GVirDomain *dom,
>  gboolean gvir_domain_get_persistent(GVirDomain *dom);
>  gboolean gvir_domain_get_saved(GVirDomain *dom);
>  
> +GList *gvir_domain_get_devices(GVirDomain *domain,
> +                               GError **err);
> +
>  G_END_DECLS
>  
>  #endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index d6999dc..460280b 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -68,6 +68,7 @@ LIBVIRT_GOBJECT_0.0.4 {
>  	gvir_domain_reboot;
>  	gvir_domain_get_config;
>  	gvir_domain_set_config;
> +	gvir_domain_get_devices;
>  	gvir_domain_get_info;
>  	gvir_domain_get_persistent;
>  	gvir_domain_get_saved;
> -- 
> 1.7.7.6
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpprV7EOWZwh.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]

Powered by Linux

Google
  Web www.spinics.net