[libvirt] [libvirt-glib 1/6] Set correct target node attribute for domain interface

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> gvir_config_domain_interface_set_ifname() should be setting 'dev' attribute under 'target', not 'device'. --- libvirt-gconfig/libvirt-gconfig-domain-interface.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c index 85cc194..eab4313 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c @@ -57,7 +57,7 @@ void gvir_config_domain_interface_set_ifname(GVirConfigDomainInterface *interfac g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface)); gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(interface), - "target", "device", ifname); + "target", "dev", ifname); } void gvir_config_domain_interface_set_link_state(GVirConfigDomainInterface *interface, -- 1.7.7.6

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Getter for the associated domain of a domain device. --- libvirt-gobject/libvirt-gobject-domain-device.c | 11 +++++++++++ libvirt-gobject/libvirt-gobject-domain-device.h | 3 +++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 15 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c index 528b513..750c8d9 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.c +++ b/libvirt-gobject/libvirt-gobject-domain-device.c @@ -134,3 +134,14 @@ virDomainPtr gvir_domain_device_get_domain_handle(GVirDomainDevice *self) return handle; } + +/** + * gvir_domain_device_get_domain: + * @device: the domain device + * + * Returns: (transfer full): the associated domain + */ +GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device) +{ + return g_object_ref (device->priv->domain); +} diff --git a/libvirt-gobject/libvirt-gobject-domain-device.h b/libvirt-gobject/libvirt-gobject-domain-device.h index 96c0433..98acc2d 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.h +++ b/libvirt-gobject/libvirt-gobject-domain-device.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__ #define __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__ +#include <libvirt-gobject/libvirt-gobject-domain.h> + G_BEGIN_DECLS #define GVIR_TYPE_DOMAIN_DEVICE (gvir_domain_device_get_type ()) @@ -58,6 +60,7 @@ struct _GVirDomainDeviceClass GType gvir_domain_device_get_type(void); +GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index 5081f41..0097692 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -33,6 +33,7 @@ LIBVIRT_GOBJECT_0.0.4 { gvir_connection_get_node_info; gvir_domain_device_get_type; + gvir_domain_device_get_domain; gvir_domain_disk_get_type; gvir_domain_disk_stats_get_type; -- 1.7.7.6

ACK On Thu, Mar 01, 2012 at 12:15:38AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Getter for the associated domain of a domain device. --- libvirt-gobject/libvirt-gobject-domain-device.c | 11 +++++++++++ libvirt-gobject/libvirt-gobject-domain-device.h | 3 +++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c index 528b513..750c8d9 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.c +++ b/libvirt-gobject/libvirt-gobject-domain-device.c @@ -134,3 +134,14 @@ virDomainPtr gvir_domain_device_get_domain_handle(GVirDomainDevice *self)
return handle; } + +/** + * gvir_domain_device_get_domain: + * @device: the domain device + * + * Returns: (transfer full): the associated domain + */ +GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device) +{ + return g_object_ref (device->priv->domain); +} diff --git a/libvirt-gobject/libvirt-gobject-domain-device.h b/libvirt-gobject/libvirt-gobject-domain-device.h index 96c0433..98acc2d 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.h +++ b/libvirt-gobject/libvirt-gobject-domain-device.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__ #define __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__
+#include <libvirt-gobject/libvirt-gobject-domain.h> + G_BEGIN_DECLS
#define GVIR_TYPE_DOMAIN_DEVICE (gvir_domain_device_get_type ()) @@ -58,6 +60,7 @@ struct _GVirDomainDeviceClass
GType gvir_domain_device_get_type(void); +GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device);
G_END_DECLS
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index 5081f41..0097692 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -33,6 +33,7 @@ LIBVIRT_GOBJECT_0.0.4 { gvir_connection_get_node_info;
gvir_domain_device_get_type; + gvir_domain_device_get_domain;
gvir_domain_disk_get_type; gvir_domain_disk_stats_get_type; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-gconfig/libvirt-gconfig-domain-interface.c | 35 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-interface.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 4 ++ 3 files changed, 43 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c index eab4313..5fe27a1 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c @@ -96,6 +96,41 @@ void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface "model", "type", model); } +char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface), + "target", "dev"); +} + +GVirConfigDomainInterfaceLinkState gvir_config_domain_interface_get_link_state(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), + GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(interface), + "link", "state", + GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_LINK_STATE, + GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT); +} + +char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface), + "mac", "address"); +} + +char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface), + "model", "type"); +} + G_GNUC_INTERNAL GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.h b/libvirt-gconfig/libvirt-gconfig-domain-interface.h index 6e802fb..567f95a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.h @@ -72,6 +72,10 @@ void gvir_config_domain_interface_set_mac(GVirConfigDomainInterface *interface, const char *mac_address); void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface, const char *model); +char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface); +GVirConfigDomainInterfaceLinkState gvir_config_domain_interface_get_link_state(GVirConfigDomainInterface *interface); +char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface); +char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 96ce58f..1329c17 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -142,9 +142,13 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_interface_get_type; gvir_config_domain_interface_link_state_get_type; gvir_config_domain_interface_set_ifname; + gvir_config_domain_interface_get_ifname; gvir_config_domain_interface_set_link_state; + gvir_config_domain_interface_get_link_state; gvir_config_domain_interface_set_mac; + gvir_config_domain_interface_get_mac; gvir_config_domain_interface_set_model; + gvir_config_domain_interface_get_model; gvir_config_domain_interface_bridge_get_type; gvir_config_domain_interface_bridge_new; -- 1.7.7.6

ACK, though you convinced me that we can and should propagate const char * throughout the API, but that's another patch. Christophe On Thu, Mar 01, 2012 at 12:15:39AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gconfig/libvirt-gconfig-domain-interface.c | 35 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-interface.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 4 ++ 3 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c index eab4313..5fe27a1 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c @@ -96,6 +96,41 @@ void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface "model", "type", model); }
+char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface), + "target", "dev"); +} + +GVirConfigDomainInterfaceLinkState gvir_config_domain_interface_get_link_state(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), + GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(interface), + "link", "state", + GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_LINK_STATE, + GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT); +} + +char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface), + "mac", "address"); +} + +char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface), + "model", "type"); +} + G_GNUC_INTERNAL GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.h b/libvirt-gconfig/libvirt-gconfig-domain-interface.h index 6e802fb..567f95a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.h @@ -72,6 +72,10 @@ void gvir_config_domain_interface_set_mac(GVirConfigDomainInterface *interface, const char *mac_address); void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface, const char *model); +char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface); +GVirConfigDomainInterfaceLinkState gvir_config_domain_interface_get_link_state(GVirConfigDomainInterface *interface); +char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface); +char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 96ce58f..1329c17 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -142,9 +142,13 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_interface_get_type; gvir_config_domain_interface_link_state_get_type; gvir_config_domain_interface_set_ifname; + gvir_config_domain_interface_get_ifname; gvir_config_domain_interface_set_link_state; + gvir_config_domain_interface_get_link_state; gvir_config_domain_interface_set_mac; + gvir_config_domain_interface_get_mac; gvir_config_domain_interface_set_model; + gvir_config_domain_interface_get_model;
gvir_config_domain_interface_bridge_get_type; gvir_config_domain_interface_bridge_new; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> GVirDomainDevice should have an associated GVirConfigDomainDevice. --- libvirt-gobject/libvirt-gobject-domain-device.c | 33 +++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain-device.h | 1 + libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 35 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c index 750c8d9..35d4855 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.c +++ b/libvirt-gobject/libvirt-gobject-domain-device.c @@ -37,6 +37,7 @@ struct _GVirDomainDevicePrivate { GVirDomain *domain; + GVirConfigDomainDevice *config; }; G_DEFINE_ABSTRACT_TYPE(GVirDomainDevice, gvir_domain_device, G_TYPE_OBJECT); @@ -44,6 +45,7 @@ G_DEFINE_ABSTRACT_TYPE(GVirDomainDevice, gvir_domain_device, G_TYPE_OBJECT); enum { PROP_0, PROP_DOMAIN, + PROP_CONFIG, }; static void gvir_domain_device_get_property(GObject *object, @@ -59,6 +61,10 @@ static void gvir_domain_device_get_property(GObject *object, g_value_set_object(value, priv->domain); break; + case PROP_CONFIG: + g_value_set_object(value, priv->config); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); } @@ -79,6 +85,11 @@ static void gvir_domain_device_set_property(GObject *object, priv->domain = g_value_dup_object(value); break; + case PROP_CONFIG: + g_clear_object(&priv->config); + priv->config = g_value_dup_object(value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); } @@ -93,6 +104,7 @@ static void gvir_domain_device_finalize(GObject *object) g_debug("Finalize GVirDomainDevice=%p", self); g_clear_object(&priv->domain); + g_clear_object(&priv->config); G_OBJECT_CLASS(gvir_domain_device_parent_class)->finalize(object); } @@ -115,6 +127,16 @@ static void gvir_domain_device_class_init(GVirDomainDeviceClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, + PROP_CONFIG, + g_param_spec_object("config", + "Config", + "The configuration", + GVIR_CONFIG_TYPE_DOMAIN_DEVICE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_type_class_add_private(klass, sizeof(GVirDomainDevicePrivate)); } @@ -145,3 +167,14 @@ GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device) { return g_object_ref (device->priv->domain); } + +/** + * gvir_domain_device_get_config: + * @device: the domain device + * + * Returns: (transfer full): the config + */ +GVirConfigDomainDevice *gvir_domain_device_get_config(GVirDomainDevice *device) +{ + return g_object_ref (device->priv->config); +} diff --git a/libvirt-gobject/libvirt-gobject-domain-device.h b/libvirt-gobject/libvirt-gobject-domain-device.h index 98acc2d..b308477 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.h +++ b/libvirt-gobject/libvirt-gobject-domain-device.h @@ -61,6 +61,7 @@ struct _GVirDomainDeviceClass GType gvir_domain_device_get_type(void); GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device); +GVirConfigDomainDevice *gvir_domain_device_get_config(GVirDomainDevice *device); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index 0097692..d6999dc 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -34,6 +34,7 @@ LIBVIRT_GOBJECT_0.0.4 { gvir_domain_device_get_type; gvir_domain_device_get_domain; + gvir_domain_device_get_config; gvir_domain_disk_get_type; gvir_domain_disk_stats_get_type; -- 1.7.7.6

ACK On Thu, Mar 01, 2012 at 12:15:40AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
GVirDomainDevice should have an associated GVirConfigDomainDevice. --- libvirt-gobject/libvirt-gobject-domain-device.c | 33 +++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain-device.h | 1 + libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c index 750c8d9..35d4855 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.c +++ b/libvirt-gobject/libvirt-gobject-domain-device.c @@ -37,6 +37,7 @@ struct _GVirDomainDevicePrivate { GVirDomain *domain; + GVirConfigDomainDevice *config; };
G_DEFINE_ABSTRACT_TYPE(GVirDomainDevice, gvir_domain_device, G_TYPE_OBJECT); @@ -44,6 +45,7 @@ G_DEFINE_ABSTRACT_TYPE(GVirDomainDevice, gvir_domain_device, G_TYPE_OBJECT); enum { PROP_0, PROP_DOMAIN, + PROP_CONFIG, };
static void gvir_domain_device_get_property(GObject *object, @@ -59,6 +61,10 @@ static void gvir_domain_device_get_property(GObject *object, g_value_set_object(value, priv->domain); break;
+ case PROP_CONFIG: + g_value_set_object(value, priv->config); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); } @@ -79,6 +85,11 @@ static void gvir_domain_device_set_property(GObject *object, priv->domain = g_value_dup_object(value); break;
+ case PROP_CONFIG: + g_clear_object(&priv->config); + priv->config = g_value_dup_object(value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); } @@ -93,6 +104,7 @@ static void gvir_domain_device_finalize(GObject *object) g_debug("Finalize GVirDomainDevice=%p", self);
g_clear_object(&priv->domain); + g_clear_object(&priv->config);
G_OBJECT_CLASS(gvir_domain_device_parent_class)->finalize(object); } @@ -115,6 +127,16 @@ static void gvir_domain_device_class_init(GVirDomainDeviceClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class, + PROP_CONFIG, + g_param_spec_object("config", + "Config", + "The configuration", + GVIR_CONFIG_TYPE_DOMAIN_DEVICE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_type_class_add_private(klass, sizeof(GVirDomainDevicePrivate)); }
@@ -145,3 +167,14 @@ GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device) { return g_object_ref (device->priv->domain); } + +/** + * gvir_domain_device_get_config: + * @device: the domain device + * + * Returns: (transfer full): the config + */ +GVirConfigDomainDevice *gvir_domain_device_get_config(GVirDomainDevice *device) +{ + return g_object_ref (device->priv->config); +} diff --git a/libvirt-gobject/libvirt-gobject-domain-device.h b/libvirt-gobject/libvirt-gobject-domain-device.h index 98acc2d..b308477 100644 --- a/libvirt-gobject/libvirt-gobject-domain-device.h +++ b/libvirt-gobject/libvirt-gobject-domain-device.h @@ -61,6 +61,7 @@ struct _GVirDomainDeviceClass
GType gvir_domain_device_get_type(void); GVirDomain *gvir_domain_device_get_domain(GVirDomainDevice *device); +GVirConfigDomainDevice *gvir_domain_device_get_config(GVirDomainDevice *device);
G_END_DECLS
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index 0097692..d6999dc 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -34,6 +34,7 @@ LIBVIRT_GOBJECT_0.0.4 {
gvir_domain_device_get_type; gvir_domain_device_get_domain; + gvir_domain_device_get_config;
gvir_domain_disk_get_type; gvir_domain_disk_stats_get_type; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Remove now redundant 'path' property from GVirDomainDevice subclasses. These classes now have access to their configurations, from which they can easily get the path (among other properties) internally. --- libvirt-gobject/libvirt-gobject-domain-disk.c | 84 ++++--------------- libvirt-gobject/libvirt-gobject-domain-interface.c | 81 +++---------------- 2 files changed, 32 insertions(+), 133 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain-disk.c b/libvirt-gobject/libvirt-gobject-domain-disk.c index fb7672e..0a1493a 100644 --- a/libvirt-gobject/libvirt-gobject-domain-disk.c +++ b/libvirt-gobject/libvirt-gobject-domain-disk.c @@ -36,73 +36,25 @@ struct _GVirDomainDiskPrivate { - gchar *path; + gboolean unused; }; G_DEFINE_TYPE(GVirDomainDisk, gvir_domain_disk, GVIR_TYPE_DOMAIN_DEVICE); -enum { - PROP_0, - PROP_PATH, -}; - #define GVIR_DOMAIN_DISK_ERROR gvir_domain_disk_error_quark() - static GQuark gvir_domain_disk_error_quark(void) { return g_quark_from_static_string("gvir-domain-disk"); } -static void gvir_domain_disk_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GVirDomainDisk *self = GVIR_DOMAIN_DISK(object); - GVirDomainDiskPrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_value_set_string(value, priv->path); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - -static void gvir_domain_disk_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GVirDomainDisk *self = GVIR_DOMAIN_DISK(object); - GVirDomainDiskPrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_free(priv->path); - priv->path = g_value_dup_string(value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - static void gvir_domain_disk_finalize(GObject *object) { GVirDomainDisk *self = GVIR_DOMAIN_DISK(object); - GVirDomainDiskPrivate *priv = self->priv; g_debug("Finalize GVirDomainDisk=%p", self); - g_free(priv->path); - G_OBJECT_CLASS(gvir_domain_disk_parent_class)->finalize(object); } @@ -111,19 +63,6 @@ static void gvir_domain_disk_class_init(GVirDomainDiskClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gvir_domain_disk_finalize; - object_class->get_property = gvir_domain_disk_get_property; - object_class->set_property = gvir_domain_disk_set_property; - - g_object_class_install_property(object_class, - PROP_PATH, - g_param_spec_string("path", - "Path", - "The disk path", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_type_class_add_private(klass, sizeof(GVirDomainDiskPrivate)); } @@ -151,6 +90,15 @@ gvir_domain_disk_stats_free(GVirDomainDiskStats *stats) G_DEFINE_BOXED_TYPE(GVirDomainDiskStats, gvir_domain_disk_stats, gvir_domain_disk_stats_copy, gvir_domain_disk_stats_free) +static gchar *gvir_domain_disk_get_path(GVirDomainDisk *self) +{ + GVirConfigDomainDevice *config; + + config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self)); + + return gvir_config_domain_disk_get_target_dev (GVIR_CONFIG_DOMAIN_DISK (config)); +} + /** * gvir_domain_disk_get_stats: * @self: the domain disk @@ -166,15 +114,15 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError **e { GVirDomainDiskStats *ret = NULL; virDomainBlockStatsStruct stats; - GVirDomainDiskPrivate *priv; virDomainPtr handle; + gchar *path; g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), NULL); - priv = self->priv; handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self)); + path = gvir_domain_disk_get_path (self); - if (virDomainBlockStats(handle, priv->path, &stats, sizeof (stats)) < 0) { + if (virDomainBlockStats(handle, path, &stats, sizeof (stats)) < 0) { gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR, 0, "Unable to get domain disk stats"); @@ -190,6 +138,7 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError **e end: virDomainFree(handle); + g_free(path); return ret; } @@ -211,13 +160,15 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self, { gboolean ret = FALSE; virDomainPtr handle; + gchar *path; g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), FALSE); g_return_val_if_fail(err == NULL || *err != NULL, FALSE); handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self)); + path = gvir_domain_disk_get_path (self); - if (virDomainBlockResize(handle, self->priv->path, size, flags) < 0) { + if (virDomainBlockResize(handle, path, size, flags) < 0) { gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR, 0, "Failed to resize domain disk"); @@ -228,5 +179,6 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self, end: virDomainFree(handle); + g_free(path); return ret; } diff --git a/libvirt-gobject/libvirt-gobject-domain-interface.c b/libvirt-gobject/libvirt-gobject-domain-interface.c index 0917e03..e220375 100644 --- a/libvirt-gobject/libvirt-gobject-domain-interface.c +++ b/libvirt-gobject/libvirt-gobject-domain-interface.c @@ -36,73 +36,25 @@ struct _GVirDomainInterfacePrivate { - gchar *path; + gboolean unused; }; G_DEFINE_TYPE(GVirDomainInterface, gvir_domain_interface, GVIR_TYPE_DOMAIN_DEVICE); -enum { - PROP_0, - PROP_PATH, -}; - #define GVIR_DOMAIN_INTERFACE_ERROR gvir_domain_interface_error_quark() - static GQuark gvir_domain_interface_error_quark(void) { return g_quark_from_static_string("gvir-domain-interface"); } -static void gvir_domain_interface_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object); - GVirDomainInterfacePrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_value_set_string(value, priv->path); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - -static void gvir_domain_interface_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object); - GVirDomainInterfacePrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_free(priv->path); - priv->path = g_value_dup_string(value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - static void gvir_domain_interface_finalize(GObject *object) { GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object); - GVirDomainInterfacePrivate *priv = self->priv; g_debug("Finalize GVirDomainInterface=%p", self); - g_free(priv->path); - G_OBJECT_CLASS(gvir_domain_interface_parent_class)->finalize(object); } @@ -111,19 +63,6 @@ static void gvir_domain_interface_class_init(GVirDomainInterfaceClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gvir_domain_interface_finalize; - object_class->get_property = gvir_domain_interface_get_property; - object_class->set_property = gvir_domain_interface_set_property; - - g_object_class_install_property(object_class, - PROP_PATH, - g_param_spec_string("path", - "Path", - "The interface path", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_type_class_add_private(klass, sizeof(GVirDomainInterfacePrivate)); } @@ -140,17 +79,24 @@ gvir_domain_interface_stats_copy(GVirDomainInterfaceStats *stats) return g_slice_dup(GVirDomainInterfaceStats, stats); } - static void gvir_domain_interface_stats_free(GVirDomainInterfaceStats *stats) { g_slice_free(GVirDomainInterfaceStats, stats); } - G_DEFINE_BOXED_TYPE(GVirDomainInterfaceStats, gvir_domain_interface_stats, gvir_domain_interface_stats_copy, gvir_domain_interface_stats_free) +static gchar *gvir_domain_interface_get_path(GVirDomainInterface *self) +{ + GVirConfigDomainDevice *config; + + config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self)); + + return gvir_config_domain_interface_get_ifname (GVIR_CONFIG_DOMAIN_INTERFACE (config)); +} + /** * gvir_domain_interface_get_stats: * @self: the domain interface @@ -166,15 +112,15 @@ GVirDomainInterfaceStats *gvir_domain_interface_get_stats(GVirDomainInterface *s { GVirDomainInterfaceStats *ret = NULL; virDomainInterfaceStatsStruct stats; - GVirDomainInterfacePrivate *priv; virDomainPtr handle; + gchar *path; g_return_val_if_fail(GVIR_IS_DOMAIN_INTERFACE(self), NULL); - priv = self->priv; handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self)); + path = gvir_domain_interface_get_path (self); - if (virDomainInterfaceStats(handle, priv->path, &stats, sizeof (stats)) < 0) { + if (virDomainInterfaceStats(handle, path, &stats, sizeof (stats)) < 0) { gvir_set_error_literal(err, GVIR_DOMAIN_INTERFACE_ERROR, 0, "Unable to get domain interface stats"); @@ -193,5 +139,6 @@ GVirDomainInterfaceStats *gvir_domain_interface_get_stats(GVirDomainInterface *s end: virDomainFree(handle); + g_free(path); return ret; } -- 1.7.7.6

On Thu, Mar 01, 2012 at 12:15:41AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Remove now redundant 'path' property from GVirDomainDevice subclasses. These classes now have access to their configurations, from which they can easily get the path (among other properties) internally. --- libvirt-gobject/libvirt-gobject-domain-disk.c | 84 ++++--------------- libvirt-gobject/libvirt-gobject-domain-interface.c | 81 +++---------------- 2 files changed, 32 insertions(+), 133 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain-disk.c b/libvirt-gobject/libvirt-gobject-domain-disk.c index fb7672e..0a1493a 100644 --- a/libvirt-gobject/libvirt-gobject-domain-disk.c +++ b/libvirt-gobject/libvirt-gobject-domain-disk.c @@ -36,73 +36,25 @@
struct _GVirDomainDiskPrivate { - gchar *path; + gboolean unused; };
G_DEFINE_TYPE(GVirDomainDisk, gvir_domain_disk, GVIR_TYPE_DOMAIN_DEVICE);
-enum { - PROP_0, - PROP_PATH, -}; - #define GVIR_DOMAIN_DISK_ERROR gvir_domain_disk_error_quark()
- static GQuark gvir_domain_disk_error_quark(void) { return g_quark_from_static_string("gvir-domain-disk"); }
-static void gvir_domain_disk_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GVirDomainDisk *self = GVIR_DOMAIN_DISK(object); - GVirDomainDiskPrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_value_set_string(value, priv->path); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - -static void gvir_domain_disk_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GVirDomainDisk *self = GVIR_DOMAIN_DISK(object); - GVirDomainDiskPrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_free(priv->path); - priv->path = g_value_dup_string(value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - static void gvir_domain_disk_finalize(GObject *object) { GVirDomainDisk *self = GVIR_DOMAIN_DISK(object); - GVirDomainDiskPrivate *priv = self->priv;
g_debug("Finalize GVirDomainDisk=%p", self);
- g_free(priv->path); - G_OBJECT_CLASS(gvir_domain_disk_parent_class)->finalize(object); }
@@ -111,19 +63,6 @@ static void gvir_domain_disk_class_init(GVirDomainDiskClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gvir_domain_disk_finalize; - object_class->get_property = gvir_domain_disk_get_property; - object_class->set_property = gvir_domain_disk_set_property; - - g_object_class_install_property(object_class, - PROP_PATH, - g_param_spec_string("path", - "Path", - "The disk path", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_type_class_add_private(klass, sizeof(GVirDomainDiskPrivate)); }
@@ -151,6 +90,15 @@ gvir_domain_disk_stats_free(GVirDomainDiskStats *stats) G_DEFINE_BOXED_TYPE(GVirDomainDiskStats, gvir_domain_disk_stats, gvir_domain_disk_stats_copy, gvir_domain_disk_stats_free)
+static gchar *gvir_domain_disk_get_path(GVirDomainDisk *self) +{ + GVirConfigDomainDevice *config; + + config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
missing g_object_unref(config);
+ + return gvir_config_domain_disk_get_target_dev (GVIR_CONFIG_DOMAIN_DISK (config)); +} + /** * gvir_domain_disk_get_stats: * @self: the domain disk @@ -166,15 +114,15 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError **e { GVirDomainDiskStats *ret = NULL; virDomainBlockStatsStruct stats; - GVirDomainDiskPrivate *priv; virDomainPtr handle; + gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), NULL);
- priv = self->priv; handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self)); + path = gvir_domain_disk_get_path (self);
- if (virDomainBlockStats(handle, priv->path, &stats, sizeof (stats)) < 0) { + if (virDomainBlockStats(handle, path, &stats, sizeof (stats)) < 0) { gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR, 0, "Unable to get domain disk stats"); @@ -190,6 +138,7 @@ GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError **e
end: virDomainFree(handle); + g_free(path); return ret; }
@@ -211,13 +160,15 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self, { gboolean ret = FALSE; virDomainPtr handle; + gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), FALSE); g_return_val_if_fail(err == NULL || *err != NULL, FALSE);
handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self)); + path = gvir_domain_disk_get_path (self);
- if (virDomainBlockResize(handle, self->priv->path, size, flags) < 0) { + if (virDomainBlockResize(handle, path, size, flags) < 0) { gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR, 0, "Failed to resize domain disk"); @@ -228,5 +179,6 @@ gboolean gvir_domain_disk_resize(GVirDomainDisk *self,
end: virDomainFree(handle); + g_free(path); return ret; } diff --git a/libvirt-gobject/libvirt-gobject-domain-interface.c b/libvirt-gobject/libvirt-gobject-domain-interface.c index 0917e03..e220375 100644 --- a/libvirt-gobject/libvirt-gobject-domain-interface.c +++ b/libvirt-gobject/libvirt-gobject-domain-interface.c @@ -36,73 +36,25 @@
struct _GVirDomainInterfacePrivate { - gchar *path; + gboolean unused; };
G_DEFINE_TYPE(GVirDomainInterface, gvir_domain_interface, GVIR_TYPE_DOMAIN_DEVICE);
-enum { - PROP_0, - PROP_PATH, -}; - #define GVIR_DOMAIN_INTERFACE_ERROR gvir_domain_interface_error_quark()
- static GQuark gvir_domain_interface_error_quark(void) { return g_quark_from_static_string("gvir-domain-interface"); }
-static void gvir_domain_interface_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object); - GVirDomainInterfacePrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_value_set_string(value, priv->path); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - -static void gvir_domain_interface_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object); - GVirDomainInterfacePrivate *priv = self->priv; - - switch (prop_id) { - case PROP_PATH: - g_free(priv->path); - priv->path = g_value_dup_string(value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - - static void gvir_domain_interface_finalize(GObject *object) { GVirDomainInterface *self = GVIR_DOMAIN_INTERFACE(object); - GVirDomainInterfacePrivate *priv = self->priv;
g_debug("Finalize GVirDomainInterface=%p", self);
- g_free(priv->path); - G_OBJECT_CLASS(gvir_domain_interface_parent_class)->finalize(object); }
@@ -111,19 +63,6 @@ static void gvir_domain_interface_class_init(GVirDomainInterfaceClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gvir_domain_interface_finalize; - object_class->get_property = gvir_domain_interface_get_property; - object_class->set_property = gvir_domain_interface_set_property; - - g_object_class_install_property(object_class, - PROP_PATH, - g_param_spec_string("path", - "Path", - "The interface path", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - g_type_class_add_private(klass, sizeof(GVirDomainInterfacePrivate)); }
@@ -140,17 +79,24 @@ gvir_domain_interface_stats_copy(GVirDomainInterfaceStats *stats) return g_slice_dup(GVirDomainInterfaceStats, stats); }
- static void gvir_domain_interface_stats_free(GVirDomainInterfaceStats *stats) { g_slice_free(GVirDomainInterfaceStats, stats); }
- G_DEFINE_BOXED_TYPE(GVirDomainInterfaceStats, gvir_domain_interface_stats, gvir_domain_interface_stats_copy, gvir_domain_interface_stats_free)
+static gchar *gvir_domain_interface_get_path(GVirDomainInterface *self) +{ + GVirConfigDomainDevice *config; + + config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
Missing g_object_unref here too
+ + return gvir_config_domain_interface_get_ifname (GVIR_CONFIG_DOMAIN_INTERFACE (config)); +} + /** * gvir_domain_interface_get_stats: * @self: the domain interface @@ -166,15 +112,15 @@ GVirDomainInterfaceStats *gvir_domain_interface_get_stats(GVirDomainInterface *s { GVirDomainInterfaceStats *ret = NULL; virDomainInterfaceStatsStruct stats; - GVirDomainInterfacePrivate *priv; virDomainPtr handle; + gchar *path;
g_return_val_if_fail(GVIR_IS_DOMAIN_INTERFACE(self), NULL);
- priv = self->priv; handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self)); + path = gvir_domain_interface_get_path (self);
- if (virDomainInterfaceStats(handle, priv->path, &stats, sizeof (stats)) < 0) { + if (virDomainInterfaceStats(handle, path, &stats, sizeof (stats)) < 0) { gvir_set_error_literal(err, GVIR_DOMAIN_INTERFACE_ERROR, 0, "Unable to get domain interface stats"); @@ -193,5 +139,6 @@ GVirDomainInterfaceStats *gvir_domain_interface_get_stats(GVirDomainInterface *s
end: virDomainFree(handle); + g_free(path); return ret; }
ACK with these issues fixed. Christophe
-- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Mar 1, 2012 at 12:37 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Thu, Mar 01, 2012 at 12:15:41AM +0200, Zeeshan Ali (Khattak) wrote:
+static gchar *gvir_domain_interface_get_path(GVirDomainInterface *self) +{ + GVirConfigDomainDevice *config; + + config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
Missing g_object_unref here too
Its right there where you cut it. :) You are correct about the other place, though. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> 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; + } + + 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); + + config = gvir_domain_get_config(domain, 0, err); + if (config == NULL) + return ret; + + 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

ACK, a few nits below On Thu, Mar 01, 2012 at 12:15:42AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
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@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

ACK On Thu, Mar 01, 2012 at 12:15:37AM +0200, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
gvir_config_domain_interface_set_ifname() should be setting 'dev' attribute under 'target', not 'device'. --- libvirt-gconfig/libvirt-gconfig-domain-interface.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c index 85cc194..eab4313 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c @@ -57,7 +57,7 @@ void gvir_config_domain_interface_set_ifname(GVirConfigDomainInterface *interfac g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface));
gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(interface), - "target", "device", ifname); + "target", "dev", ifname); }
void gvir_config_domain_interface_set_link_state(GVirConfigDomainInterface *interface, -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Christophe Fergeau
-
Zeeshan Ali (Khattak)