Re: [libvirt] [libvirt-glib v8 5/5] tests: Add test for GVirConfigDomainHostdevPci API
Hi, In my attempt to add a message to the patch series summarising the changes, I managed to add bogus emails in To and BCC fields. Please remove those when you reply. Changes in v8: gvir_config_domain_hostdev_pci_get_rom_bar() simplified as per review comment. On Mon, Jul 25, 2016 at 12:46 PM, Zeeshan Ali (Khattak) wrote: > --- > tests/test-gconfig.c| 43 > + > tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ > 2 files changed, 54 insertions(+) > create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml > > diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c > index be55ef9..a26bb5f 100644 > --- a/tests/test-gconfig.c > +++ b/tests/test-gconfig.c > @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) > g_object_unref(G_OBJECT(domain)); > } > > +static void test_domain_device_pci_hostdev(void) > +{ > +GVirConfigDomain *domain; > +GVirConfigDomainAddressPci *address; > +GVirConfigDomainHostdevPci *hostdev; > + > +domain = gvir_config_domain_new(); > + > +hostdev = gvir_config_domain_hostdev_pci_new(); > + > gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), > 1); > + > g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), > ==, 1); > +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); > +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); > +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); > +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, > "/etc/fake/boot.bin"); > +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), > ==, "/etc/fake/boot.bin"); > +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); > + > +address = gvir_config_domain_address_pci_new(); > +gvir_config_domain_address_pci_set_domain(address, 1); > +gvir_config_domain_address_pci_set_bus(address, 2); > +gvir_config_domain_address_pci_set_slot(address, 3); > +gvir_config_domain_address_pci_set_function(address, 4); > +gvir_config_domain_hostdev_pci_set_address(hostdev, address); > +g_object_unref(G_OBJECT(address)); > + > +address = gvir_config_domain_hostdev_pci_get_address(hostdev); > +g_assert(address != NULL); > +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, > 1); > +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); > +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3); > +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), > ==, 4); > +g_object_unref(G_OBJECT(address)); > + > +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE > (hostdev)); > +g_object_unref(G_OBJECT(hostdev)); > + > +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); > + > +g_object_unref(G_OBJECT(domain)); > +} > > int main(int argc, char **argv) > { > @@ -739,6 +780,8 @@ int main(int argc, char **argv) > test_domain_device_channel); > g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", > test_domain_device_usb_redir); > +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", > +test_domain_device_pci_hostdev); > > return g_test_run(); > } > diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml > b/tests/xml/gconfig-domain-device-pci-hostdev.xml > new file mode 100644 > index 000..70e32ac > --- /dev/null > +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml > @@ -0,0 +1,11 @@ > + > + > + > + > + > + > + > + > + > + > + > -- > 2.7.4 > -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v8 5/5] tests: Add test for GVirConfigDomainHostdevPci API
--- tests/test-gconfig.c| 43 + tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ 2 files changed, 54 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index be55ef9..a26bb5f 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_pci_hostdev(void) +{ +GVirConfigDomain *domain; +GVirConfigDomainAddressPci *address; +GVirConfigDomainHostdevPci *hostdev; + +domain = gvir_config_domain_new(); + +hostdev = gvir_config_domain_hostdev_pci_new(); + gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1); + g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), ==, 1); +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, "/etc/fake/boot.bin"); +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), ==, "/etc/fake/boot.bin"); +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); + +address = gvir_config_domain_address_pci_new(); +gvir_config_domain_address_pci_set_domain(address, 1); +gvir_config_domain_address_pci_set_bus(address, 2); +gvir_config_domain_address_pci_set_slot(address, 3); +gvir_config_domain_address_pci_set_function(address, 4); +gvir_config_domain_hostdev_pci_set_address(hostdev, address); +g_object_unref(G_OBJECT(address)); + +address = gvir_config_domain_hostdev_pci_get_address(hostdev); +g_assert(address != NULL); +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, 1); +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3); +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), ==, 4); +g_object_unref(G_OBJECT(address)); + +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev)); +g_object_unref(G_OBJECT(hostdev)); + +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); + +g_object_unref(G_OBJECT(domain)); +} int main(int argc, char **argv) { @@ -739,6 +780,8 @@ int main(int argc, char **argv) test_domain_device_channel); g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", test_domain_device_usb_redir); +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", +test_domain_device_pci_hostdev); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml new file mode 100644 index 000..70e32ac --- /dev/null +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v8 3/5] gconfig: Add GVirConfigDomainHostdevPci
Add API to read and write PCI hostdev nodes. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-hostdev-pci.c | 222 + .../libvirt-gconfig-domain-hostdev-pci.h | 81 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 11 + 6 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a7c6c4e..0400343 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ libvirt-gconfig-domain-hostdev.h \ + libvirt-gconfig-domain-hostdev-pci.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ libvirt-gconfig-domain-hostdev.c \ + libvirt-gconfig-domain-hostdev-pci.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c new file mode 100644 index 000..c789c9c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c @@ -0,0 +1,222 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) + +struct _GVirConfigDomainHostdevPciPrivate +{ +gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); + +static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass) +{ +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate)); +} + + +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev) +{ +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); +} + +/** + * gvir_config_domain_hostdev_pci_new: + * + * Creates a new #GVirConfigDomainHostdevPci. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void) +{ +GVirConfigObject *object; + +object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, +"hostdev", NULL); +gvir_config_object_set_attribute(object, "mode", "subsystem", NULL); +gvir_config_object_set_attribute(object, "type", "pci", NULL); + +return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object); +} + +/** + * gvir_config_domain_hostdev_pci_new_from_xml: + * @xml: xml data to create the host device from + * @error: return location for a #GError, or NULL + * + * Creates a new #GVirConfigDomainHostdevPci. The host device object will be + * created using the XML description stored in @xml. This is a fragment of + * libvirt domain XML whose root node is <hostdev>. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci,
[libvirt] [libvirt-glib v8 4/5] gconfig: Add GVirConfigDomainAddressPci getters
From: Christophe Fergeau They will be useful to do more checks in the GVirDomainDeviceHostdev unit test. --- .../libvirt-gconfig-domain-address-pci.c | 45 ++ .../libvirt-gconfig-domain-address-pci.h | 5 +++ libvirt-gconfig/libvirt-gconfig.sym| 6 +++ 3 files changed, 56 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c index 4bf94cc..0105402 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -92,30 +92,75 @@ static void set_attribute_hex(GVirConfigDomainAddressPci *address, g_free(format); } +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "domain", + -1); +} + void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain) { set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); } +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "bus", + -1); +} + void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus) { set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); } +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "slot", + -1); +} + void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot) { set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); } +int gvir_config_domain_address_pci_get_function(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "function", + -1); +} + void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, guchar function) { set_attribute_hex(address, "function", function, 0, 7, 1); } +gboolean gvir_config_domain_address_pci_get_multifunction(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), FALSE); + +return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(address), +NULL, "multifunction", +FALSE); +} + void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, gboolean multifunction) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h index 3b82624..cdef4a8 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h @@ -62,14 +62,19 @@ GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void); GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, GError **error); +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain); +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus); +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot); +int gvir_config_domain_address_pci_get_function(GVirConfigDomai
[libvirt] [libvirt-glib v8 2/5] gconfig: Add GVirConfigDomainHostdev
Add API to read and write domain/devices/hostdev nodes. This patch only adds the baseclass and hence is not useful on it's own. A more specific subclass to represent PCI devices will be added in a following patch. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-device-private.h| 3 + libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 190 + libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 10 ++ 7 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index f308539..a7c6c4e 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ + libvirt-gconfig-domain-hostdev.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ + libvirt-gconfig-domain-hostdev.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h index 062c0e2..c45e1df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h @@ -43,6 +43,9 @@ GVirConfigDomainDevice * gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c b/libvirt-gconfig/libvirt-gconfig-domain-device.c index 3d2b9b3..8a75cea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc, } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { goto unimplemented; } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { -goto unimplemented; +return gvir_config_domain_hostdev_new_from_tree(doc, tree); } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c new file mode 100644 index 000..ce5f8aa --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c @@ -0,0 +1,190 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE(
[libvirt] [libvirt-glib v8 1/5] gconfig: Add gvir_config_object_has_child
From: Christophe Fergeau --- libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++ libvirt-gconfig/libvirt-gconfig-object.c | 13 + 2 files changed, 15 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index e91c4ef..7a0d21f 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -117,6 +117,8 @@ GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject *object, const gchar *child_name, GType child_type); +gboolean gvir_config_object_has_child(GVirConfigObject *object, + const gchar *child_name); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index bf328f3..6225de2 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -970,3 +970,16 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } + +G_GNUC_INTERNAL gboolean +gvir_config_object_has_child(GVirConfigObject *object, const gchar *child_name) +{ +xmlNodePtr node; + +g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); +g_return_val_if_fail(child_name != NULL, FALSE); + +node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); + +return (node != NULL); +} -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib v7 3/5] gconfig: Add GVirConfigDomainHostdevPci
On Mon, Jul 25, 2016 at 10:08 AM, Christophe Fergeau wrote: > On Fri, Jul 22, 2016 at 01:43:35PM +0100, Zeeshan Ali (Khattak) wrote: >> +gboolean >> gvir_config_domain_hostdev_pci_get_rom_bar(GVirConfigDomainHostdevPci >> *hostdev) >> +{ >> +xmlNodePtr hostdev_node; >> +xmlNodePtr rom_node; >> +const gchar *bar_str; >> + >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev), FALSE); >> + >> +hostdev_node = >> gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(hostdev)); >> +g_return_val_if_fail(hostdev_node != NULL, FALSE); >> + >> +rom_node = gvir_config_xml_get_element(hostdev_node, "rom", NULL); >> +if (!rom_node || !(rom_node->children)) >> +/* When containing rom node is missing, default value is TRUE for >> newer Qemu */ >> +return TRUE; >> + >> +bar_str = gvir_config_xml_get_attribute_content(rom_node, "bar"); >> +return (g_strcmp0(bar_str, "on")); >> +} > > Still the same question as > https://www.redhat.com/archives/libvir-list/2016-July/msg00644.html > Can't it become: > > gboolean > gvir_config_domain_hostdev_pci_get_rom_bar(GVirConfigDomainHostdevPci > *hostdev) > { > const gchar *bar_str; > > g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev), FALSE); > > bar_str = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(hostdev), > "rom", "bar"); > return (g_strcmp0(bar_str, "on") == 0); > } Ah, I thought you were only talking of simplifying the if/return block. -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v7 4/5] gconfig: Add GVirConfigDomainAddressPci getters
From: Christophe Fergeau They will be useful to do more checks in the GVirDomainDeviceHostdev unit test. --- .../libvirt-gconfig-domain-address-pci.c | 45 ++ .../libvirt-gconfig-domain-address-pci.h | 5 +++ libvirt-gconfig/libvirt-gconfig.sym| 6 +++ 3 files changed, 56 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c index 4bf94cc..0105402 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -92,30 +92,75 @@ static void set_attribute_hex(GVirConfigDomainAddressPci *address, g_free(format); } +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "domain", + -1); +} + void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain) { set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); } +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "bus", + -1); +} + void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus) { set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); } +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "slot", + -1); +} + void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot) { set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); } +int gvir_config_domain_address_pci_get_function(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "function", + -1); +} + void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, guchar function) { set_attribute_hex(address, "function", function, 0, 7, 1); } +gboolean gvir_config_domain_address_pci_get_multifunction(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), FALSE); + +return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(address), +NULL, "multifunction", +FALSE); +} + void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, gboolean multifunction) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h index 3b82624..cdef4a8 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h @@ -62,14 +62,19 @@ GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void); GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, GError **error); +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain); +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus); +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot); +int gvir_config_domain_address_pci_get_function(GVirConfigDomai
[libvirt] [libvirt-glib v7 3/5] gconfig: Add GVirConfigDomainHostdevPci
Add API to read and write PCI hostdev nodes. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-hostdev-pci.c | 232 + .../libvirt-gconfig-domain-hostdev-pci.h | 81 +++ libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 11 + 6 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a7c6c4e..0400343 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ libvirt-gconfig-domain-hostdev.h \ + libvirt-gconfig-domain-hostdev-pci.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ libvirt-gconfig-domain-hostdev.c \ + libvirt-gconfig-domain-hostdev-pci.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c new file mode 100644 index 000..c173a8e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c @@ -0,0 +1,232 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) + +struct _GVirConfigDomainHostdevPciPrivate +{ +gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); + +static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass) +{ +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate)); +} + + +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev) +{ +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); +} + +/** + * gvir_config_domain_hostdev_pci_new: + * + * Creates a new #GVirConfigDomainHostdevPci. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void) +{ +GVirConfigObject *object; + +object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, +"hostdev", NULL); +gvir_config_object_set_attribute(object, "mode", "subsystem", NULL); +gvir_config_object_set_attribute(object, "type", "pci", NULL); + +return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object); +} + +/** + * gvir_config_domain_hostdev_pci_new_from_xml: + * @xml: xml data to create the host device from + * @error: return location for a #GError, or NULL + * + * Creates a new #GVirConfigDomainHostdevPci. The host device object will be + * created using the XML description stored in @xml. This is a fragment of + * libvirt domain XML whose root node is <hostdev>. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci,
[libvirt] [libvirt-glib v7 2/5] gconfig: Add GVirConfigDomainHostdev
Add API to read and write domain/devices/hostdev nodes. This patch only adds the baseclass and hence is not useful on it's own. A more specific subclass to represent PCI devices will be added in a following patch. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-device-private.h| 3 + libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 190 + libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 10 ++ 7 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index f308539..a7c6c4e 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ + libvirt-gconfig-domain-hostdev.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ + libvirt-gconfig-domain-hostdev.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h index 062c0e2..c45e1df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h @@ -43,6 +43,9 @@ GVirConfigDomainDevice * gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c b/libvirt-gconfig/libvirt-gconfig-domain-device.c index 3d2b9b3..8a75cea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc, } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { goto unimplemented; } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { -goto unimplemented; +return gvir_config_domain_hostdev_new_from_tree(doc, tree); } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c new file mode 100644 index 000..ce5f8aa --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c @@ -0,0 +1,190 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE(
[libvirt] [libvirt-glib v7 1/5] gconfig: Add gvir_config_object_has_child
From: Christophe Fergeau --- libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++ libvirt-gconfig/libvirt-gconfig-object.c | 13 + 2 files changed, 15 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index e91c4ef..7a0d21f 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -117,6 +117,8 @@ GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject *object, const gchar *child_name, GType child_type); +gboolean gvir_config_object_has_child(GVirConfigObject *object, + const gchar *child_name); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index bf328f3..6225de2 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -970,3 +970,16 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } + +G_GNUC_INTERNAL gboolean +gvir_config_object_has_child(GVirConfigObject *object, const gchar *child_name) +{ +xmlNodePtr node; + +g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); +g_return_val_if_fail(child_name != NULL, FALSE); + +node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); + +return (node != NULL); +} -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v7 5/5] tests: Add test for GVirConfigDomainHostdevPci API
--- tests/test-gconfig.c| 43 + tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ 2 files changed, 54 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index be55ef9..a26bb5f 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_pci_hostdev(void) +{ +GVirConfigDomain *domain; +GVirConfigDomainAddressPci *address; +GVirConfigDomainHostdevPci *hostdev; + +domain = gvir_config_domain_new(); + +hostdev = gvir_config_domain_hostdev_pci_new(); + gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1); + g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), ==, 1); +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, "/etc/fake/boot.bin"); +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), ==, "/etc/fake/boot.bin"); +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); + +address = gvir_config_domain_address_pci_new(); +gvir_config_domain_address_pci_set_domain(address, 1); +gvir_config_domain_address_pci_set_bus(address, 2); +gvir_config_domain_address_pci_set_slot(address, 3); +gvir_config_domain_address_pci_set_function(address, 4); +gvir_config_domain_hostdev_pci_set_address(hostdev, address); +g_object_unref(G_OBJECT(address)); + +address = gvir_config_domain_hostdev_pci_get_address(hostdev); +g_assert(address != NULL); +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, 1); +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3); +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), ==, 4); +g_object_unref(G_OBJECT(address)); + +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev)); +g_object_unref(G_OBJECT(hostdev)); + +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); + +g_object_unref(G_OBJECT(domain)); +} int main(int argc, char **argv) { @@ -739,6 +780,8 @@ int main(int argc, char **argv) test_domain_device_channel); g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", test_domain_device_usb_redir); +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", +test_domain_device_pci_hostdev); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml new file mode 100644 index 000..70e32ac --- /dev/null +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv5 2/5] Add GVirConfigDomainHostdev
Hi, On Fri, Jul 22, 2016 at 10:27 AM, Christophe Fergeau wrote: > On Thu, Jul 21, 2016 at 06:11:36PM +0100, Zeeshan Ali (Khattak) wrote: >> Hi, >> >> On Mon, Jul 18, 2016 at 3:54 PM, Christophe Fergeau >> wrote: >> > Please add a gconfig: prefix to the subject line. >> >> I have a custom git command to add 'libvirt-glib' prefix but I keep >> forgetting that --subject-prefix gets overriden by the second >> --subject-prefix I manually specify for adding patch series version. > > Ah, I did not pay attention to that actually ;) But I'd recommend just > doing > git config format.subjectprefix=libvirt-glib > and > git send-email -v2 > (-v2 should work with your custom git command if that fits better your > worflow). Thanks. If there is a way to also set the address to send emails to, I'll gladly drop my commands (actually they are git aliases). > But I was only asking that "Add GVirConfigDomainHostdev" becomes > "gconfig: Add GVirConfigDomainHostdev" Ah ok. I'll fix that. -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [gconfig v6 4/5] gconfig: Add GVirConfigDomainAddressPci getters
From: Christophe Fergeau They will be useful to do more checks in the GVirDomainDeviceHostdev unit test. --- .../libvirt-gconfig-domain-address-pci.c | 45 ++ .../libvirt-gconfig-domain-address-pci.h | 5 +++ libvirt-gconfig/libvirt-gconfig.sym| 6 +++ 3 files changed, 56 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c index 4bf94cc..0105402 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -92,30 +92,75 @@ static void set_attribute_hex(GVirConfigDomainAddressPci *address, g_free(format); } +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "domain", + -1); +} + void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain) { set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); } +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "bus", + -1); +} + void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus) { set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); } +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "slot", + -1); +} + void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot) { set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); } +int gvir_config_domain_address_pci_get_function(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "function", + -1); +} + void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, guchar function) { set_attribute_hex(address, "function", function, 0, 7, 1); } +gboolean gvir_config_domain_address_pci_get_multifunction(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), FALSE); + +return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(address), +NULL, "multifunction", +FALSE); +} + void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, gboolean multifunction) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h index 3b82624..cdef4a8 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h @@ -62,14 +62,19 @@ GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void); GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, GError **error); +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain); +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus); +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot); +int gvir_config_domain_address_pci_get_function(GVirConfigDomai
[libvirt] [gconfig v6 5/5] Add test for GVirConfigDomainHostdevPci API
--- tests/test-gconfig.c| 43 + tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ 2 files changed, 54 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index be55ef9..a26bb5f 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_pci_hostdev(void) +{ +GVirConfigDomain *domain; +GVirConfigDomainAddressPci *address; +GVirConfigDomainHostdevPci *hostdev; + +domain = gvir_config_domain_new(); + +hostdev = gvir_config_domain_hostdev_pci_new(); + gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1); + g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), ==, 1); +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, "/etc/fake/boot.bin"); +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), ==, "/etc/fake/boot.bin"); +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); + +address = gvir_config_domain_address_pci_new(); +gvir_config_domain_address_pci_set_domain(address, 1); +gvir_config_domain_address_pci_set_bus(address, 2); +gvir_config_domain_address_pci_set_slot(address, 3); +gvir_config_domain_address_pci_set_function(address, 4); +gvir_config_domain_hostdev_pci_set_address(hostdev, address); +g_object_unref(G_OBJECT(address)); + +address = gvir_config_domain_hostdev_pci_get_address(hostdev); +g_assert(address != NULL); +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, 1); +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3); +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), ==, 4); +g_object_unref(G_OBJECT(address)); + +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev)); +g_object_unref(G_OBJECT(hostdev)); + +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); + +g_object_unref(G_OBJECT(domain)); +} int main(int argc, char **argv) { @@ -739,6 +780,8 @@ int main(int argc, char **argv) test_domain_device_channel); g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", test_domain_device_usb_redir); +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", +test_domain_device_pci_hostdev); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml new file mode 100644 index 000..70e32ac --- /dev/null +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [gconfig v6 2/5] Add GVirConfigDomainHostdev
Add API to read and write domain/devices/hostdev nodes. This patch only adds the baseclass and hence is not useful on it's own. A more specific subclass to represent PCI devices will be added in a following patch. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-device-private.h| 3 + libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 190 + libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 10 ++ 7 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index f308539..a7c6c4e 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ + libvirt-gconfig-domain-hostdev.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ + libvirt-gconfig-domain-hostdev.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h index 062c0e2..c45e1df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h @@ -43,6 +43,9 @@ GVirConfigDomainDevice * gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c b/libvirt-gconfig/libvirt-gconfig-domain-device.c index 3d2b9b3..8a75cea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc, } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { goto unimplemented; } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { -goto unimplemented; +return gvir_config_domain_hostdev_new_from_tree(doc, tree); } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c new file mode 100644 index 000..ce5f8aa --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c @@ -0,0 +1,190 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE(
[libvirt] [gconfig v6 1/5] gconfig: Add gvir_config_object_has_child
From: Christophe Fergeau --- libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++ libvirt-gconfig/libvirt-gconfig-object.c | 13 + 2 files changed, 15 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index e91c4ef..7a0d21f 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -117,6 +117,8 @@ GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject *object, const gchar *child_name, GType child_type); +gboolean gvir_config_object_has_child(GVirConfigObject *object, + const gchar *child_name); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index bf328f3..6225de2 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -970,3 +970,16 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } + +G_GNUC_INTERNAL gboolean +gvir_config_object_has_child(GVirConfigObject *object, const gchar *child_name) +{ +xmlNodePtr node; + +g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); +g_return_val_if_fail(child_name != NULL, FALSE); + +node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); + +return (node != NULL); +} -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [gconfig v6 3/5] Add GVirConfigDomainHostdevPci
Add API to read and write PCI hostdev nodes. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-hostdev-pci.c | 232 + .../libvirt-gconfig-domain-hostdev-pci.h | 81 +++ libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 11 + 6 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a7c6c4e..0400343 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ libvirt-gconfig-domain-hostdev.h \ + libvirt-gconfig-domain-hostdev-pci.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ libvirt-gconfig-domain-hostdev.c \ + libvirt-gconfig-domain-hostdev-pci.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c new file mode 100644 index 000..c173a8e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c @@ -0,0 +1,232 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) + +struct _GVirConfigDomainHostdevPciPrivate +{ +gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); + +static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass) +{ +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate)); +} + + +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev) +{ +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); +} + +/** + * gvir_config_domain_hostdev_pci_new: + * + * Creates a new #GVirConfigDomainHostdevPci. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void) +{ +GVirConfigObject *object; + +object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, +"hostdev", NULL); +gvir_config_object_set_attribute(object, "mode", "subsystem", NULL); +gvir_config_object_set_attribute(object, "type", "pci", NULL); + +return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object); +} + +/** + * gvir_config_domain_hostdev_pci_new_from_xml: + * @xml: xml data to create the host device from + * @error: return location for a #GError, or NULL + * + * Creates a new #GVirConfigDomainHostdevPci. The host device object will be + * created using the XML description stored in @xml. This is a fragment of + * libvirt domain XML whose root node is <hostdev>. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci,
Re: [libvirt] [PATCHv5 2/5] Add GVirConfigDomainHostdev
Hi, On Mon, Jul 18, 2016 at 3:54 PM, Christophe Fergeau wrote: > Please add a gconfig: prefix to the subject line. I have a custom git command to add 'libvirt-glib' prefix but I keep forgetting that --subject-prefix gets overriden by the second --subject-prefix I manually specify for adding patch series version. > Acked-by: Christophe Fergeau > > Christophe > > On Wed, Jul 06, 2016 at 10:45:52PM +0100, Zeeshan Ali (Khattak) wrote: >> Add API to read and write domain/devices/hostdev nodes. This patch only >> adds the baseclass and hence is not useful on it's own. A more specific >> subclass to represent PCI devices will be added in a following patch. >> --- >> libvirt-gconfig/Makefile.am| 2 + >> .../libvirt-gconfig-domain-device-private.h| 3 + >> libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- >> libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 190 >> + >> libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + >> libvirt-gconfig/libvirt-gconfig.h | 1 + >> libvirt-gconfig/libvirt-gconfig.sym| 10 ++ >> 7 files changed, 283 insertions(+), 1 deletion(-) >> create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h >> >> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am >> index f308539..a7c6c4e 100644 >> --- a/libvirt-gconfig/Makefile.am >> +++ b/libvirt-gconfig/Makefile.am >> @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ >> libvirt-gconfig-domain-graphics-sdl.h \ >> libvirt-gconfig-domain-graphics-spice.h \ >> libvirt-gconfig-domain-graphics-vnc.h \ >> + libvirt-gconfig-domain-hostdev.h \ >> libvirt-gconfig-domain-input.h \ >> libvirt-gconfig-domain-interface.h \ >> libvirt-gconfig-domain-interface-bridge.h \ >> @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ >> libvirt-gconfig-domain-graphics-sdl.c \ >> libvirt-gconfig-domain-graphics-spice.c \ >> libvirt-gconfig-domain-graphics-vnc.c \ >> + libvirt-gconfig-domain-hostdev.c \ >> libvirt-gconfig-domain-input.c \ >> libvirt-gconfig-domain-interface.c \ >> libvirt-gconfig-domain-interface-bridge.c \ >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h >> b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h >> index 062c0e2..c45e1df 100644 >> --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h >> @@ -43,6 +43,9 @@ GVirConfigDomainDevice * >> gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, >>xmlNodePtr tree); >> GVirConfigDomainDevice * >> +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, >> + xmlNodePtr tree); >> +GVirConfigDomainDevice * >> gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, >> xmlNodePtr tree); >> GVirConfigDomainDevice * >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c >> b/libvirt-gconfig/libvirt-gconfig-domain-device.c >> index 3d2b9b3..8a75cea 100644 >> --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c >> @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc >> *doc, >> } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { >> goto unimplemented; >> } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { >> -goto unimplemented; >> +return gvir_config_domain_hostdev_new_from_tree(doc, tree); >> } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { >> type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; >> } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> new file mode 100644 >> index 000..ce5f8aa >> --- /dev/null >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> @@ -0,0 +1,190 @@ >> +/* >> + * libvirt-gconfi
Re: [libvirt] [PATCH] config: Add listen setter
On Thu, Jul 14, 2016 at 3:16 PM, Visarion-Mingopol Alexandru-Viorel wrote: > Actually, it seems there is some stuff to work on regarding this change. Indeed. Please keep in mind that * if we only use string types if there is no better alternatives. Static types are preferred as those make it harder to write invalid code. * for string types, gvir_config_object_set_attribute_with_type() is quite an overkill. Oh and when you provide updated patches, please make the subject prefix on emails 'gconfig' or 'libvirt-gconfig' so context is very clear. You'll want version too so --subject-prefix="gconfig v2" would be good. > On Wed, Jul 13, 2016 at 6:11 PM, Visarion Alexandru > wrote: >> >> Learn to set the listen attribute on spice. >> --- >> libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c | 10 ++ >> libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h | 3 +++ >> libvirt-gconfig/libvirt-gconfig.sym | 4 >> 3 files changed, 17 insertions(+) >> >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c >> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c >> index 079ea27..1aba9a7 100644 >> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c >> @@ -165,3 +165,13 @@ void >> gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice *gra >> gvir_config_object_replace_child_with_attribute_enum >>(GVIR_CONFIG_OBJECT(graphics), "gl", "enable", G_TYPE_BOOLEAN, gl); >> } >> + >> +void >> gvir_config_domain_graphics_spice_set_listen(GVirConfigDomainGraphicsSpice >> *graphics, >> +const char *address) >> +{ >> +g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(graphics)); >> + >> + >> gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(graphics), >> + "listen", G_TYPE_STRING, >> address, >> + NULL); >> +} >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h >> b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h >> index 25c132e..9d995b8 100644 >> --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h >> @@ -95,6 +95,9 @@ gvir_config_domain_graphics_spice_get_image_compression >> void >> gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice >> *graphics, >>gboolean gl); >> >> +void >> gvir_config_domain_graphics_spice_set_listen(GVirConfigDomainGraphicsSpice >> *graphics, >> +const char *address); >> + >> G_END_DECLS >> >> #endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ */ >> diff --git a/libvirt-gconfig/libvirt-gconfig.sym >> b/libvirt-gconfig/libvirt-gconfig.sym >> index f11f97a..4d28c86 100644 >> --- a/libvirt-gconfig/libvirt-gconfig.sym >> +++ b/libvirt-gconfig/libvirt-gconfig.sym >> @@ -738,4 +738,8 @@ LIBVIRT_GCONFIG_0.2.4 { >> gvir_config_domain_video_set_accel3d; >> } LIBVIRT_GCONFIG_0.2.2; >> >> +LIBVIRT_GCONFIG_0.2.5 { >> + gvir_config_domain_graphics_spice_set_listen; >> +} LIBVIRT_GCONFIG_0.2.4; >> + >> # define new API here using predicted next version number >> -- >> 2.5.5 >> > > > > -- > Visarion-Mingopol Alexandru-Viorel > Telefon : 0729614060 > Best Bucuresti > > -- > libvir-list mailing list > libvir-list@redhat.com > https://www.redhat.com/mailman/listinfo/libvir-list -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib] gconfig: Add gvir_config_domain_video_get_model()
Add a getter for model of domain video device. --- libvirt-gconfig/libvirt-gconfig-domain-video.c | 12 libvirt-gconfig/libvirt-gconfig-domain-video.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 1 + 3 files changed, 14 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.c b/libvirt-gconfig/libvirt-gconfig-domain-video.c index 64353bd..e38af6f 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-video.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-video.c @@ -68,6 +68,18 @@ GVirConfigDomainVideo *gvir_config_domain_video_new_from_xml(const gchar *xml, return GVIR_CONFIG_DOMAIN_VIDEO(object); } +GVirConfigDomainVideoModel gvir_config_domain_video_get_model(GVirConfigDomainVideo *video) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_VIDEO(video), GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VGA); + +return gvir_config_object_get_attribute_genum +(GVIR_CONFIG_OBJECT(video), + "model", + "type", + GVIR_CONFIG_TYPE_DOMAIN_VIDEO_MODEL, + GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VGA); +} + void gvir_config_domain_video_set_model(GVirConfigDomainVideo *video, GVirConfigDomainVideoModel model) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.h b/libvirt-gconfig/libvirt-gconfig-domain-video.h index 9fb8e4d..973ba72 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-video.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-video.h @@ -71,6 +71,7 @@ GType gvir_config_domain_video_get_type(void); GVirConfigDomainVideo *gvir_config_domain_video_new(void); GVirConfigDomainVideo *gvir_config_domain_video_new_from_xml(const gchar *xml, GError **error); +GVirConfigDomainVideoModel gvir_config_domain_video_get_model(GVirConfigDomainVideo *video); void gvir_config_domain_video_set_model(GVirConfigDomainVideo *video, GVirConfigDomainVideoModel model); void gvir_config_domain_video_set_vram(GVirConfigDomainVideo *video, diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index f11f97a..df6dd3a 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -735,6 +735,7 @@ global: LIBVIRT_GCONFIG_0.2.4 { gvir_config_domain_graphics_spice_set_gl; + gvir_config_domain_video_get_model; gvir_config_domain_video_set_accel3d; } LIBVIRT_GCONFIG_0.2.2; -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [gconfig] gconfig: VIRTIO -> VIRTIO_GPU
Hi, On Wed, Jul 13, 2016 at 4:27 PM, Daniel P. Berrange wrote: > On Wed, Jul 13, 2016 at 04:16:01PM +0100, Zeeshan Ali (Khattak) wrote: >> Rename GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO to >> GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO_GPU to get the naming the same as >> used by libosinfo. Consistency is good anyway in general but this would >> also mean that Boxes can start using virgl without any changes. >> --- >> examples/config-demo.py| 2 +- >> libvirt-gconfig/libvirt-gconfig-domain-video.h | 2 +- >> 2 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/examples/config-demo.py b/examples/config-demo.py >> index e92aa43..e52996c 100644 >> --- a/examples/config-demo.py >> +++ b/examples/config-demo.py >> @@ -62,7 +62,7 @@ graphics.set_gl(True) >> domain.add_device(graphics) >> >> video = LibvirtGConfig.DomainVideo.new() >> -video.set_model(LibvirtGConfig.DomainVideoModel.VIRTIO) >> +video.set_model(LibvirtGConfig.DomainVideoModel.VIRTIO_GPU) >> video.set_accel3d(True) >> domain.add_device(video) >> >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.h >> b/libvirt-gconfig/libvirt-gconfig-domain-video.h >> index 9fb8e4d..dda3088 100644 >> --- a/libvirt-gconfig/libvirt-gconfig-domain-video.h >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-video.h >> @@ -63,7 +63,7 @@ typedef enum { >> GVIR_CONFIG_DOMAIN_VIDEO_MODEL_XEN, >> GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VBOX, >> GVIR_CONFIG_DOMAIN_VIDEO_MODEL_QXL, >> -GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO >> +GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO_GPU >> } GVirConfigDomainVideoModel; > > Err, no you can't do this. The constants exposed in libvirt-gconfig > must match the names expected by libvirt itself in the XML parser. > Libvirt uses 'virtio' so libvirt-gconfig must do the same, unless > you want to do name re-mapping in libvirt-gconfig, which I really > would not want to see, because itmeans libvirt-gconfig diverges from > libvirt. Ah, didn't think of that. :) -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [gconfig] gconfig: VIRTIO -> VIRTIO_GPU
Rename GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO to GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO_GPU to get the naming the same as used by libosinfo. Consistency is good anyway in general but this would also mean that Boxes can start using virgl without any changes. --- examples/config-demo.py| 2 +- libvirt-gconfig/libvirt-gconfig-domain-video.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/config-demo.py b/examples/config-demo.py index e92aa43..e52996c 100644 --- a/examples/config-demo.py +++ b/examples/config-demo.py @@ -62,7 +62,7 @@ graphics.set_gl(True) domain.add_device(graphics) video = LibvirtGConfig.DomainVideo.new() -video.set_model(LibvirtGConfig.DomainVideoModel.VIRTIO) +video.set_model(LibvirtGConfig.DomainVideoModel.VIRTIO_GPU) video.set_accel3d(True) domain.add_device(video) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.h b/libvirt-gconfig/libvirt-gconfig-domain-video.h index 9fb8e4d..dda3088 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-video.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-video.h @@ -63,7 +63,7 @@ typedef enum { GVIR_CONFIG_DOMAIN_VIDEO_MODEL_XEN, GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VBOX, GVIR_CONFIG_DOMAIN_VIDEO_MODEL_QXL, -GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO +GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VIRTIO_GPU } GVirConfigDomainVideoModel; GType gvir_config_domain_video_get_type(void); -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCHv5 4/5] gconfig: Add GVirConfigDomainAddressPci getters
From: Christophe Fergeau They will be useful to do more checks in the GVirDomainDeviceHostdev unit test. --- .../libvirt-gconfig-domain-address-pci.c | 45 ++ .../libvirt-gconfig-domain-address-pci.h | 5 +++ libvirt-gconfig/libvirt-gconfig.sym| 6 +++ 3 files changed, 56 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c index 4bf94cc..0105402 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -92,30 +92,75 @@ static void set_attribute_hex(GVirConfigDomainAddressPci *address, g_free(format); } +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "domain", + -1); +} + void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain) { set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); } +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "bus", + -1); +} + void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus) { set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); } +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "slot", + -1); +} + void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot) { set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); } +int gvir_config_domain_address_pci_get_function(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "function", + -1); +} + void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, guchar function) { set_attribute_hex(address, "function", function, 0, 7, 1); } +gboolean gvir_config_domain_address_pci_get_multifunction(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), FALSE); + +return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(address), +NULL, "multifunction", +FALSE); +} + void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, gboolean multifunction) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h index 3b82624..cdef4a8 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h @@ -62,14 +62,19 @@ GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void); GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, GError **error); +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain); +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus); +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot); +int gvir_config_domain_address_pci_get_function(GVirConfigDomai
[libvirt] [PATCHv5 3/5] Add GVirConfigDomainHostdevPci
Add API to read and write PCI hostdev nodes. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-hostdev-pci.c | 235 + .../libvirt-gconfig-domain-hostdev-pci.h | 81 +++ libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 11 + 6 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a7c6c4e..0400343 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ libvirt-gconfig-domain-hostdev.h \ + libvirt-gconfig-domain-hostdev-pci.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ libvirt-gconfig-domain-hostdev.c \ + libvirt-gconfig-domain-hostdev-pci.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c new file mode 100644 index 000..5b85560 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c @@ -0,0 +1,235 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) + +struct _GVirConfigDomainHostdevPciPrivate +{ +gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); + +static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass) +{ +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate)); +} + + +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev) +{ +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); +} + +/** + * gvir_config_domain_hostdev_pci_new: + * + * Creates a new #GVirConfigDomainHostdevPci. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void) +{ +GVirConfigObject *object; + +object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, +"hostdev", NULL); +gvir_config_object_set_attribute(object, "mode", "subsystem", NULL); +gvir_config_object_set_attribute(object, "type", "pci", NULL); + +return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object); +} + +/** + * gvir_config_domain_hostdev_pci_new_from_xml: + * @xml: xml data to create the host device from + * @error: return location for a #GError, or NULL + * + * Creates a new #GVirConfigDomainHostdevPci. The host device object will be + * created using the XML description stored in @xml. This is a fragment of + * libvirt domain XML whose root node is <hostdev>. + * + * Returns: (transfer full): a new #GVirConfigDomainHostdevPci,
[libvirt] [PATCHv5 2/5] Add GVirConfigDomainHostdev
Add API to read and write domain/devices/hostdev nodes. This patch only adds the baseclass and hence is not useful on it's own. A more specific subclass to represent PCI devices will be added in a following patch. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-device-private.h| 3 + libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 190 + libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 10 ++ 7 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index f308539..a7c6c4e 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ + libvirt-gconfig-domain-hostdev.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ + libvirt-gconfig-domain-hostdev.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h index 062c0e2..c45e1df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h @@ -43,6 +43,9 @@ GVirConfigDomainDevice * gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c b/libvirt-gconfig/libvirt-gconfig-domain-device.c index 3d2b9b3..8a75cea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc, } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { goto unimplemented; } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { -goto unimplemented; +return gvir_config_domain_hostdev_new_from_tree(doc, tree); } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c new file mode 100644 index 000..ce5f8aa --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c @@ -0,0 +1,190 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE(
[libvirt] gconfig: Add hostdev support v5
It's back! :) Really intend to actually get it finished and merged this time around. Basically I mostly fixed all the minor issues in patch 3/5 (Add GVirConfigDomainHostdevPci) pointed out in last review, including treatment of on/off attributes (which is why the patch "libvirt-gconfig: Accept on/off as boolean attributes" has been dropped in this version). -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCHv5 1/5] gconfig: Add gvir_config_object_has_child
From: Christophe Fergeau --- libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++ libvirt-gconfig/libvirt-gconfig-object.c | 13 + 2 files changed, 15 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index e91c4ef..7a0d21f 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -117,6 +117,8 @@ GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject *object, const gchar *child_name, GType child_type); +gboolean gvir_config_object_has_child(GVirConfigObject *object, + const gchar *child_name); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index bf328f3..6225de2 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -970,3 +970,16 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } + +G_GNUC_INTERNAL gboolean +gvir_config_object_has_child(GVirConfigObject *object, const gchar *child_name) +{ +xmlNodePtr node; + +g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); +g_return_val_if_fail(child_name != NULL, FALSE); + +node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); + +return (node != NULL); +} -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCHv5 5/5] Add test for GVirConfigDomainHostdevPci API
--- tests/test-gconfig.c| 43 + tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ 2 files changed, 54 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index be55ef9..a26bb5f 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_pci_hostdev(void) +{ +GVirConfigDomain *domain; +GVirConfigDomainAddressPci *address; +GVirConfigDomainHostdevPci *hostdev; + +domain = gvir_config_domain_new(); + +hostdev = gvir_config_domain_hostdev_pci_new(); + gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1); + g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), ==, 1); +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, "/etc/fake/boot.bin"); +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), ==, "/etc/fake/boot.bin"); +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); + +address = gvir_config_domain_address_pci_new(); +gvir_config_domain_address_pci_set_domain(address, 1); +gvir_config_domain_address_pci_set_bus(address, 2); +gvir_config_domain_address_pci_set_slot(address, 3); +gvir_config_domain_address_pci_set_function(address, 4); +gvir_config_domain_hostdev_pci_set_address(hostdev, address); +g_object_unref(G_OBJECT(address)); + +address = gvir_config_domain_hostdev_pci_get_address(hostdev); +g_assert(address != NULL); +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, 1); +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3); +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), ==, 4); +g_object_unref(G_OBJECT(address)); + +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev)); +g_object_unref(G_OBJECT(hostdev)); + +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); + +g_object_unref(G_OBJECT(domain)); +} int main(int argc, char **argv) { @@ -739,6 +780,8 @@ int main(int argc, char **argv) test_domain_device_channel); g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", test_domain_device_usb_redir); +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", +test_domain_device_pci_hostdev); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml new file mode 100644 index 000..70e32ac --- /dev/null +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 4/6] Add GVirConfigDomainHostdevPci
On Thu, May 12, 2016 at 1:28 PM, Christophe Fergeau wrote: > Looks I never answered this one. > > On Tue, Apr 26, 2016 at 05:04:30PM +0100, Zeeshan Ali (Khattak) wrote: >> >> +const gchar >> >> *gvir_config_domain_hostdev_pci_get_rom_file(GVirConfigDomainHostdevPci >> >> *hostdev) >> >> +{ >> >> +return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(hostdev), >> >> "rom", "file"); >> > >> >> +} >> >> + >> >> +gboolean >> >> gvir_config_domain_hostdev_pci_get_rom_bar(GVirConfigDomainHostdevPci >> >> *hostdev) >> >> +{ >> >> +return >> >> gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(hostdev), >> >> +"rom", "bar", FALSE); >> > >> > I'd prefer to handle on/off parsing here rather than moving it to >> > get_attribute_boolean(). >> >> Why? Quick look through libvirt XML docs, shows that on/off is used in >> other places too. > > libvirt treats "on"/"off" and "yes"/"no" as different types, > virTristateSwitch and virTristateBool. Giving them different names don't really make them different. on/off and yes/no, both have two states and are essentially booleans. > This patch would treat the 2 as "boolean", and only in the parsing case > as it obviously cannot guess what is the right behaviour when converting > to string. > So I'd rather we don't start to treat both as booleans. So you're suggesting that I inline the implementation and not make this generic? -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 4/6] Add GVirConfigDomainHostdevPci
On Thu, Apr 21, 2016 at 3:12 PM, Christophe Fergeau wrote: > On Fri, Apr 15, 2016 at 02:38:22PM +0100, Zeeshan Ali (Khattak) wrote: >> Add API to read and write PCI hostdev nodes. >> --- >> libvirt-gconfig/Makefile.am| 2 + >> .../libvirt-gconfig-domain-hostdev-pci.c | 210 >> + >> .../libvirt-gconfig-domain-hostdev-pci.h | 81 >> libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- >> libvirt-gconfig/libvirt-gconfig.h | 1 + >> libvirt-gconfig/libvirt-gconfig.sym| 11 ++ >> 6 files changed, 306 insertions(+), 1 deletion(-) >> create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c >> create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h >> >> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am >> index a7c6c4e..0400343 100644 >> --- a/libvirt-gconfig/Makefile.am >> +++ b/libvirt-gconfig/Makefile.am >> @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ >> libvirt-gconfig-domain-graphics-spice.h \ >> libvirt-gconfig-domain-graphics-vnc.h \ >> libvirt-gconfig-domain-hostdev.h \ >> + libvirt-gconfig-domain-hostdev-pci.h \ >> libvirt-gconfig-domain-input.h \ >> libvirt-gconfig-domain-interface.h \ >> libvirt-gconfig-domain-interface-bridge.h \ >> @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ >> libvirt-gconfig-domain-graphics-spice.c \ >> libvirt-gconfig-domain-graphics-vnc.c \ >> libvirt-gconfig-domain-hostdev.c \ >> + libvirt-gconfig-domain-hostdev-pci.c \ >> libvirt-gconfig-domain-input.c \ >> libvirt-gconfig-domain-interface.c \ >> libvirt-gconfig-domain-interface-bridge.c \ >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c >> b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c >> new file mode 100644 >> index 000..04e3da9 >> --- /dev/null >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c >> @@ -0,0 +1,210 @@ >> +/* >> + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration >> + * >> + * Copyright (C) 2016 Red Hat, Inc. >> + * >> + * This library is free software; you can redistribute it and/or >> + * modify it under the terms of the GNU Lesser General Public >> + * License as published by the Free Software Foundation; either >> + * version 2.1 of the License, or (at your option) any later version. >> + * >> + * This library is distributed in the hope that it will be useful, >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + * Lesser General Public License for more details. >> + * >> + * You should have received a copy of the GNU Lesser General Public >> + * License along with this library. If not, see >> + * <http://www.gnu.org/licenses/>. >> + * >> + * Authors: Zeeshan Ali (Khattak) >> + * Christophe Fergeau >> + */ >> + >> +#include >> + >> +#include "libvirt-gconfig/libvirt-gconfig.h" >> +#include "libvirt-gconfig/libvirt-gconfig-private.h" >> + >> +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) >> \ >> +(G_TYPE_INSTANCE_GET_PRIVATE((obj), >> GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) >> + >> +struct _GVirConfigDomainHostdevPciPrivate >> +{ >> +gboolean unused; >> +}; >> + >> +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, >> GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); >> + >> +static void >> gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass >> *klass) >> +{ >> +g_type_class_add_private(klass, >> sizeof(GVirConfigDomainHostdevPciPrivate)); >> +} >> + >> + >> +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci >> *hostdev) >> +{ >> +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); >> +} >> + >> +/** >> + * gvir_config_domain_hostdev_pci_new: >> + * >> + * Creates a new #GVirConfigDomainHostdevPci. >> + * >> + * Returns:(transfer full): a new #GVirConfigDomainHostdevPci
Re: [libvirt] [PATCH v4 1/6] gconfig: Add gvir_config_object_has_child
On Thu, Apr 21, 2016 at 2:55 PM, Christophe Fergeau wrote: > On Fri, Apr 15, 2016 at 02:38:19PM +0100, Zeeshan Ali (Khattak) wrote: >> From: Christophe Fergeau > > This patch is mine, hopefully someone else will review it ;) Sure, ACK. :) > Christophe -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 6/6] Add test for GVirConfigDomainHostdevPci API
On Thu, Apr 21, 2016 at 3:14 PM, Christophe Fergeau wrote: > And one more. Yours? AFAIK it's mine. > On Fri, Apr 15, 2016 at 02:38:24PM +0100, Zeeshan Ali (Khattak) wrote: >> --- >> tests/test-gconfig.c| 43 >> + >> tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ >> 2 files changed, 54 insertions(+) >> create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml >> >> diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c >> index be55ef9..a26bb5f 100644 >> --- a/tests/test-gconfig.c >> +++ b/tests/test-gconfig.c >> @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) >> g_object_unref(G_OBJECT(domain)); >> } >> >> +static void test_domain_device_pci_hostdev(void) >> +{ >> +GVirConfigDomain *domain; >> +GVirConfigDomainAddressPci *address; >> +GVirConfigDomainHostdevPci *hostdev; >> + >> +domain = gvir_config_domain_new(); >> + >> +hostdev = gvir_config_domain_hostdev_pci_new(); >> + >> gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), >> 1); >> + >> g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), >> ==, 1); >> +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); >> +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); >> +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); >> +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, >> "/etc/fake/boot.bin"); >> +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), >> ==, "/etc/fake/boot.bin"); >> +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); >> + >> +address = gvir_config_domain_address_pci_new(); >> +gvir_config_domain_address_pci_set_domain(address, 1); >> +gvir_config_domain_address_pci_set_bus(address, 2); >> +gvir_config_domain_address_pci_set_slot(address, 3); >> +gvir_config_domain_address_pci_set_function(address, 4); >> +gvir_config_domain_hostdev_pci_set_address(hostdev, address); >> +g_object_unref(G_OBJECT(address)); >> + >> +address = gvir_config_domain_hostdev_pci_get_address(hostdev); >> +g_assert(address != NULL); >> +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, >> 1); >> +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); >> +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, >> 3); >> +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), >> ==, 4); >> +g_object_unref(G_OBJECT(address)); >> + >> +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE >> (hostdev)); >> +g_object_unref(G_OBJECT(hostdev)); >> + >> +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); >> + >> +g_object_unref(G_OBJECT(domain)); >> +} >> >> int main(int argc, char **argv) >> { >> @@ -739,6 +780,8 @@ int main(int argc, char **argv) >> test_domain_device_channel); >> g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", >> test_domain_device_usb_redir); >> +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", >> +test_domain_device_pci_hostdev); >> >> return g_test_run(); >> } >> diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml >> b/tests/xml/gconfig-domain-device-pci-hostdev.xml >> new file mode 100644 >> index 000..70e32ac >> --- /dev/null >> +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml >> @@ -0,0 +1,11 @@ >> + >> + >> + >> + >> + >> + >> + >> + >> + >> + >> + >> -- >> 2.5.5 >> >> -- >> libvir-list mailing list >> libvir-list@redhat.com >> https://www.redhat.com/mailman/listinfo/libvir-list -- Regards, Zeeshan Ali (Khattak) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 5/6] gconfig: Add GVirConfigDomainAddressPci getters
On Thu, Apr 21, 2016 at 3:14 PM, Christophe Fergeau wrote: > Another patch that I wrote... ACK. > Christophe > > On Fri, Apr 15, 2016 at 02:38:23PM +0100, Zeeshan Ali (Khattak) wrote: >> From: Christophe Fergeau >> >> They will be useful to do more checks in the GVirDomainDeviceHostdev >> unit test. >> --- >> .../libvirt-gconfig-domain-address-pci.c | 45 >> ++ >> .../libvirt-gconfig-domain-address-pci.h | 5 +++ >> libvirt-gconfig/libvirt-gconfig.sym| 6 +++ >> 3 files changed, 56 insertions(+) >> >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c >> b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c >> index 4bf94cc..0105402 100644 >> --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c >> @@ -92,30 +92,75 @@ static void set_attribute_hex(GVirConfigDomainAddressPci >> *address, >> g_free(format); >> } >> >> +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci >> *address) >> +{ >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); >> + >> +return >> gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), >> + NULL, "domain", >> + -1); >> +} >> + >> void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci >> *address, >> guint16 pci_domain) >> { >> set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); >> } >> >> +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci >> *address) >> +{ >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); >> + >> +return >> gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), >> + NULL, "bus", >> + -1); >> +} >> + >> void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci >> *address, >> guchar bus) >> { >> set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); >> } >> >> +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci >> *address) >> +{ >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); >> + >> +return >> gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), >> + NULL, "slot", >> + -1); >> +} >> + >> void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci >> *address, >> guchar slot) >> { >> set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); >> } >> >> +int gvir_config_domain_address_pci_get_function(GVirConfigDomainAddressPci >> *address) >> +{ >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); >> + >> +return >> gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), >> + NULL, "function", >> + -1); >> +} >> + >> void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci >> *address, >> guchar function) >> { >> set_attribute_hex(address, "function", function, 0, 7, 1); >> } >> >> +gboolean >> gvir_config_domain_address_pci_get_multifunction(GVirConfigDomainAddressPci >> *address) >> +{ >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), FALSE); >> + >> +return >> gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(address), >> +NULL, "multifunction", >> +FALSE); >> +} >> + >> void >> gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci >> *address, >>gboolean >> multifunction) >&g
[libvirt] [PATCH v4 6/6] Add test for GVirConfigDomainHostdevPci API
--- tests/test-gconfig.c| 43 + tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++ 2 files changed, 54 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index be55ef9..a26bb5f 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_pci_hostdev(void) +{ +GVirConfigDomain *domain; +GVirConfigDomainAddressPci *address; +GVirConfigDomainHostdevPci *hostdev; + +domain = gvir_config_domain_new(); + +hostdev = gvir_config_domain_hostdev_pci_new(); + gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1); + g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), ==, 1); +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); +g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE); +gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE); +gvir_config_domain_hostdev_pci_set_rom_file(hostdev, "/etc/fake/boot.bin"); +g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), ==, "/etc/fake/boot.bin"); +g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev)); + +address = gvir_config_domain_address_pci_new(); +gvir_config_domain_address_pci_set_domain(address, 1); +gvir_config_domain_address_pci_set_bus(address, 2); +gvir_config_domain_address_pci_set_slot(address, 3); +gvir_config_domain_address_pci_set_function(address, 4); +gvir_config_domain_hostdev_pci_set_address(hostdev, address); +g_object_unref(G_OBJECT(address)); + +address = gvir_config_domain_hostdev_pci_get_address(hostdev); +g_assert(address != NULL); +g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, 1); +g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2); +g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3); +g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), ==, 4); +g_object_unref(G_OBJECT(address)); + +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev)); +g_object_unref(G_OBJECT(hostdev)); + +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); + +g_object_unref(G_OBJECT(domain)); +} int main(int argc, char **argv) { @@ -739,6 +780,8 @@ int main(int argc, char **argv) test_domain_device_channel); g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", test_domain_device_usb_redir); +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", +test_domain_device_pci_hostdev); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml new file mode 100644 index 000..70e32ac --- /dev/null +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- 2.5.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v4 2/6] Add GVirConfigDomainHostdev
Add API to read and write domain/devices/hostdev nodes. This patch only adds the baseclass and hence is not useful on it's own. A more specific subclass to represent PCI devices will be added in a following patch. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-device-private.h| 3 + libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 190 + libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 10 ++ 7 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index f308539..a7c6c4e 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ + libvirt-gconfig-domain-hostdev.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ + libvirt-gconfig-domain-hostdev.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h index 062c0e2..c45e1df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h @@ -43,6 +43,9 @@ GVirConfigDomainDevice * gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c b/libvirt-gconfig/libvirt-gconfig-domain-device.c index 3d2b9b3..8a75cea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc, } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { goto unimplemented; } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { -goto unimplemented; +return gvir_config_domain_hostdev_new_from_tree(doc, tree); } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c new file mode 100644 index 000..205878e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c @@ -0,0 +1,190 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE(
[libvirt] [PATCH v4 4/6] Add GVirConfigDomainHostdevPci
Add API to read and write PCI hostdev nodes. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-hostdev-pci.c | 210 + .../libvirt-gconfig-domain-hostdev-pci.h | 81 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 11 ++ 6 files changed, 306 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a7c6c4e..0400343 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ libvirt-gconfig-domain-hostdev.h \ + libvirt-gconfig-domain-hostdev-pci.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ libvirt-gconfig-domain-hostdev.c \ + libvirt-gconfig-domain-hostdev-pci.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c new file mode 100644 index 000..04e3da9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c @@ -0,0 +1,210 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) + +struct _GVirConfigDomainHostdevPciPrivate +{ +gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); + +static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass) +{ +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate)); +} + + +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev) +{ +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); +} + +/** + * gvir_config_domain_hostdev_pci_new: + * + * Creates a new #GVirConfigDomainHostdevPci. + * + * Returns:(transfer full): a new #GVirConfigDomainHostdevPci. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void) +{ +GVirConfigObject *object; + +object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, +"hostdev", NULL); +gvir_config_object_set_attribute(object, "mode", "subsystem", NULL); +gvir_config_object_set_attribute(object, "type", "pci", NULL); + +return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object); +} + +/** + * gvir_config_domain_hostdev_pci_new_from_xml: + * @xml: xml data to create the host device from + * @error: return location for a #GError, or NULL + * + * Creates a new #GVirConfigDomainHostdevPci with a reference count of 1. + * The host device object will be created using the XML description stored + * in @xml. This is a fragment of libvirt domain XML whose root node is + * <hostdev>. + * + * Returns: a new #GVirConfigDomain
[libvirt] [PATCH v4 3/6] libvirt-gconfig: Accept on/off as boolean attributes
gvir_config_object_get_attribute_boolean() currently only accepts yes/no as boolean attribute values. Let's also accept on/off as valid values too. This will come handy in a following patch that adds 'hostdev' handling API. --- libvirt-gconfig/libvirt-gconfig-object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 6225de2..f44cc4c 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -690,9 +690,9 @@ gvir_config_object_get_attribute_boolean(GVirConfigObject *object, const char *str; str = gvir_config_object_get_attribute(object, node_name, attr_name); -if (g_strcmp0(str, "yes") == 0) { +if (g_strcmp0(str, "yes") == 0 || g_strcmp0(str, "on") == 0) { return TRUE; -} else if (g_strcmp0(str, "no") == 0) { +} else if (g_strcmp0(str, "no") == 0 || g_strcmp0(str, "off") == 0) { return FALSE; } else { return default_value; -- 2.5.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] gconfig: Add hostdev support v4
Finally I got the time to clean-up and fix the patches. It's been a while last i looked into them already and I got a bit confused at some point so I appologize if I didn't address some of the review comments. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v4 1/6] gconfig: Add gvir_config_object_has_child
From: Christophe Fergeau --- libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++ libvirt-gconfig/libvirt-gconfig-object.c | 13 + 2 files changed, 15 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index e91c4ef..7a0d21f 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -117,6 +117,8 @@ GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject *object, const gchar *child_name, GType child_type); +gboolean gvir_config_object_has_child(GVirConfigObject *object, + const gchar *child_name); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index bf328f3..6225de2 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -970,3 +970,16 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } + +G_GNUC_INTERNAL gboolean +gvir_config_object_has_child(GVirConfigObject *object, const gchar *child_name) +{ +xmlNodePtr node; + +g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); +g_return_val_if_fail(child_name != NULL, FALSE); + +node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); + +return (node != NULL); +} -- 2.5.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v4 5/6] gconfig: Add GVirConfigDomainAddressPci getters
From: Christophe Fergeau They will be useful to do more checks in the GVirDomainDeviceHostdev unit test. --- .../libvirt-gconfig-domain-address-pci.c | 45 ++ .../libvirt-gconfig-domain-address-pci.h | 5 +++ libvirt-gconfig/libvirt-gconfig.sym| 6 +++ 3 files changed, 56 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c index 4bf94cc..0105402 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -92,30 +92,75 @@ static void set_attribute_hex(GVirConfigDomainAddressPci *address, g_free(format); } +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "domain", + -1); +} + void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain) { set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); } +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "bus", + -1); +} + void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus) { set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); } +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "slot", + -1); +} + void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot) { set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); } +int gvir_config_domain_address_pci_get_function(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), -1); + +return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(address), + NULL, "function", + -1); +} + void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, guchar function) { set_attribute_hex(address, "function", function, 0, 7, 1); } +gboolean gvir_config_domain_address_pci_get_multifunction(GVirConfigDomainAddressPci *address) +{ +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address), FALSE); + +return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(address), +NULL, "multifunction", +FALSE); +} + void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, gboolean multifunction) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h index 3b82624..cdef4a8 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h @@ -62,14 +62,19 @@ GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void); GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, GError **error); +int gvir_config_domain_address_pci_get_domain(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, guint16 pci_domain); +int gvir_config_domain_address_pci_get_bus(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, guchar bus); +int gvir_config_domain_address_pci_get_slot(GVirConfigDomainAddressPci *address); void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, guchar slot); +int gvir_config_domain_address_pci_get_function(GVirConfigDomai
Re: [libvirt] [libvirt-glib v2 8/9] Add test for GVirConfigDomainHostdevPci API
On Fri, Mar 11, 2016 at 3:15 PM, Christophe Fergeau wrote: > On Fri, Mar 11, 2016 at 03:03:03PM +0000, Zeeshan Ali (Khattak) wrote: >> On Fri, Mar 11, 2016 at 9:21 AM, Christophe Fergeau >> wrote: >> > On Thu, Mar 10, 2016 at 05:08:33PM +0000, Zeeshan Ali (Khattak) wrote: >> >> Hi, >> >> >> >> I'm a bit confused, this patch doesn't seem to add anything to mine. >> >> Did you forget to commit? >> > >> > As indicated in the cover letter >> > >> > « This series contains this new code. The changes I made to Zeeshan's >> > initial patches are in separate fixup! commits to make reviewing them >> > easier (for you Zeeshan ;). >> > I expect these to be squashed in the main commits before being pushed. >> > Zeeshan's commits are unchanged from v1. » >> > >> > If that's more convenient for you I can send a v3 with the fixup! >> > commits squashed into the fixup ones. >> >> Yes please, cause I'm really confused. :) > > https://www.redhat.com/archives/libvir-list/2016-March/msg00504.html > (did not retest before sending, hopefully it's fine :) Thanks. Somehow my mail filter was acting up. Hence the confusion.. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib v2 8/9] Add test for GVirConfigDomainHostdevPci API
On Fri, Mar 11, 2016 at 9:21 AM, Christophe Fergeau wrote: > On Thu, Mar 10, 2016 at 05:08:33PM +0000, Zeeshan Ali (Khattak) wrote: >> Hi, >> >> I'm a bit confused, this patch doesn't seem to add anything to mine. >> Did you forget to commit? > > As indicated in the cover letter > > « This series contains this new code. The changes I made to Zeeshan's > initial patches are in separate fixup! commits to make reviewing them > easier (for you Zeeshan ;). > I expect these to be squashed in the main commits before being pushed. > Zeeshan's commits are unchanged from v1. » > > If that's more convenient for you I can send a v3 with the fixup! > commits squashed into the fixup ones. Yes please, cause I'm really confused. :) -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib v2 8/9] Add test for GVirConfigDomainHostdevPci API
Hi, I'm a bit confused, this patch doesn't seem to add anything to mine. Did you forget to commit? On Fri, Jan 29, 2016 at 6:21 PM, Christophe Fergeau wrote: > From: "Zeeshan Ali (Khattak)" > > --- > tests/test-gconfig.c| 30 > + > tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 + > 2 files changed, 41 insertions(+) > create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml > > diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c > index be55ef9..c3711f1 100644 > --- a/tests/test-gconfig.c > +++ b/tests/test-gconfig.c > @@ -709,6 +709,34 @@ static void test_domain_device_usb_redir(void) > g_object_unref(G_OBJECT(domain)); > } > > +static void test_domain_device_pci_hostdev(void) > +{ > +GVirConfigDomain *domain; > +GVirConfigDomainAddressPci *address; > +GVirConfigDomainHostdevPci *hostdev; > + > +domain = gvir_config_domain_new(); > + > +hostdev = gvir_config_domain_hostdev_pci_new(); > + > gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), > 1); > +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); > +gvir_config_domain_hostdev_pci_set_rom(hostdev, "/etc/fake/boot.bin", > TRUE); > + > +address = gvir_config_domain_address_pci_new(); > +gvir_config_domain_address_pci_set_domain(address, 1); > +gvir_config_domain_address_pci_set_bus(address, 2); > +gvir_config_domain_address_pci_set_slot(address, 3); > +gvir_config_domain_address_pci_set_function(address, 4); > +gvir_config_domain_hostdev_pci_set_address(hostdev, address); > +g_object_unref(G_OBJECT(address)); > + > +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE > (hostdev)); > +g_object_unref(G_OBJECT(hostdev)); > + > +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); > + > +g_object_unref(G_OBJECT(domain)); > +} > > int main(int argc, char **argv) > { > @@ -739,6 +767,8 @@ int main(int argc, char **argv) > test_domain_device_channel); > g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", > test_domain_device_usb_redir); > +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", > +test_domain_device_pci_hostdev); > > return g_test_run(); > } > diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml > b/tests/xml/gconfig-domain-device-pci-hostdev.xml > new file mode 100644 > index 000..70e32ac > --- /dev/null > +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml > @@ -0,0 +1,11 @@ > + > + > + > + > + > + > + > + > + > + > + > -- > 2.5.0 > -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib 2/3] Add GVirConfigDomainHostdevPci
xmlNodePtr hostdev_node; >> +xmlNodePtr rom_node; >> +const gchar *bar_str; >> + >> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev), NULL); >> + >> +hostdev_node = >> gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(hostdev)); >> +g_return_val_if_fail(hostdev_node != NULL, NULL); >> + >> +rom_node = gvir_config_xml_get_element(hostdev_node, "rom", NULL); >> +if (!rom_node || !(rom_node->children)) >> +return NULL; >> + >> +bar_str = gvir_config_xml_get_attribute_content(rom_node, "bar"); >> +if (g_strcmp0(bar_str, "on")) >> +*bar = TRUE; >> +else >> +*bar = FALSE; >> + >> +return (const char *) rom_node->children->content; > > The filename is in the file attribute, it's not in the node content > (addressed in a patch I'm going to send by switching to using > GVirConfigObject helpers). > > Regarding the API, I don't think there are other places in > libvirt-gconfig where we set (or get) 2 things with a single > setter/getter. Are these 2 parameters tightly coupled together? > It seems to me we could do something similar to the > attributes ('arch' and 'machine'). These 2 attributes are set by 2 > separate helpers, but these helpers are in the GVirConfigOs class: > gvir_config_domain_os_set_arch > gvir_config_domain_os_set_machine Both 'arch' and 'machine' are separate attributes on the 'type' node but "bar" is an attribute of "rom" node, that I think is unlikely to be used in isolation. If we keep this API, I think I should change 'rom' to be nullable. I see your point though and I don't have hard feeling either way. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib 1/3] Add GVirConfigDomainHostdev
Hi, On Fri, Jan 29, 2016 at 5:18 PM, Christophe Fergeau wrote: > Hey, > > A gconfig: prefix in the commit shortlog would be nice Hmm.. maybe for consistency, yes but I'll remove "GVirConfig" then from class name. > On Thu, Jan 28, 2016 at 04:32:12PM +0100, Zeeshan Ali (Khattak) wrote: >> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> new file mode 100644 >> index 000..42eb184 >> --- /dev/null >> +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c >> @@ -0,0 +1,180 @@ >> +/* >> + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration >> + * >> + * Copyright (C) 2012 Red Hat, Inc. > > You can set this to 2012-2016 > >> + * >> + * This library is free software; you can redistribute it and/or >> + * modify it under the terms of the GNU Lesser General Public >> + * License as published by the Free Software Foundation; either >> + * version 2.1 of the License, or (at your option) any later version. >> + * >> + * This library is distributed in the hope that it will be useful, >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + * Lesser General Public License for more details. >> + * >> + * You should have received a copy of the GNU Lesser General Public >> + * License along with this library. If not, see >> + * <http://www.gnu.org/licenses/>. >> + * >> + * Authors: Zeeshan Ali (Khattak) >> + * Christophe Fergeau >> + */ >> + >> +#include >> + >> +#include "libvirt-gconfig/libvirt-gconfig.h" >> +#include "libvirt-gconfig/libvirt-gconfig-private.h" >> + >> +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) >> \ >> +(G_TYPE_INSTANCE_GET_PRIVATE((obj), >> GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV, GVirConfigDomainHostdevPrivate)) >> + >> +struct _GVirConfigDomainHostdevPrivate >> +{ >> +gboolean unused; >> +}; >> + >> +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainHostdev, gvir_config_domain_hostdev, >> GVIR_CONFIG_TYPE_DOMAIN_DEVICE); >> + >> + >> +static void >> gvir_config_domain_hostdev_class_init(GVirConfigDomainHostdevClass *klass) >> +{ >> +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPrivate)); >> +} >> + >> + >> +static void gvir_config_domain_hostdev_init(GVirConfigDomainHostdev >> *hostdev) >> +{ >> +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(hostdev); >> +} >> + >> +G_GNUC_INTERNAL GVirConfigDomainDevice * >> +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, >> + xmlNodePtr tree) >> +{ >> +const char *type; >> +GType gtype; >> + >> +type = gvir_config_xml_get_attribute_content(tree, "type"); >> +if (type == NULL) >> +return NULL; >> + >> +if (g_str_equal(type, "usb")) { >> +goto unimplemented; >> +} else if (g_str_equal(type, "pci")) { >> +goto unimplemented; >> +} else if (g_str_equal(type, "scsi")) { >> +goto unimplemented; >> +} else { >> +g_debug("Unknown domain hostdev node: %s", type); >> +return NULL; >> +} >> + >> +return >> GVIR_CONFIG_DOMAIN_DEVICE(gvir_config_object_new_from_tree(gtype, doc, NULL, >> tree)); >> + >> +unimplemented: >> +g_debug("Parsing of '%s' domain hostdev nodes is unimplemented", type); >> +return NULL; >> +} >> + >> +void gvir_config_domain_hostdev_set_boot_order(GVirConfigDomainHostdev >> *hostdev, >> + gint order) >> +{ >> +g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV(hostdev)); >> + >> +if (order >= 0) { >> +char *order_str = g_strdup_printf("%u", order); >> + >> + >> gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(hostdev), >> +"boot", >> +"order", >> +order_str); >> +g_free(order_str); >> +} else { >> +gvir_config_object_delete_child
[libvirt] [libvirt-glib 1/3] Add GVirConfigDomainHostdev
Add API to read and write domain/devices/hostdev nodes. This patch only adds the baseclass and hence is not useful on it's own. A more specific subclass to represent PCI devices will be added in a following patch. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-device-private.h| 3 + libvirt-gconfig/libvirt-gconfig-domain-device.c| 2 +- libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 180 + libvirt-gconfig/libvirt-gconfig-domain-hostdev.h | 76 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 11 ++ 7 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 77b2032..4294bab 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ + libvirt-gconfig-domain-hostdev.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ + libvirt-gconfig-domain-hostdev.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h index 062c0e2..c45e1df 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device-private.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-device-private.h @@ -43,6 +43,9 @@ GVirConfigDomainDevice * gvir_config_domain_graphics_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * +gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +GVirConfigDomainDevice * gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc, xmlNodePtr tree); GVirConfigDomainDevice * diff --git a/libvirt-gconfig/libvirt-gconfig-domain-device.c b/libvirt-gconfig/libvirt-gconfig-domain-device.c index 3d2b9b3..8a75cea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-device.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-device.c @@ -66,7 +66,7 @@ gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc, } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) { goto unimplemented; } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) { -goto unimplemented; +return gvir_config_domain_hostdev_new_from_tree(doc, tree); } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) { type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV; } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c new file mode 100644 index 000..42eb184 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c @@ -0,0 +1,180 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE(
[libvirt] [libvirt-glib 2/3] Add GVirConfigDomainHostdevPci
Add API to read and write PCI hostdev nodes. --- libvirt-gconfig/Makefile.am| 2 + .../libvirt-gconfig-domain-hostdev-pci.c | 211 + .../libvirt-gconfig-domain-hostdev-pci.h | 80 libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym| 9 + 6 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 4294bab..245313d 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-graphics-vnc.h \ libvirt-gconfig-domain-hostdev.h \ + libvirt-gconfig-domain-hostdev-pci.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-bridge.h \ @@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-graphics-vnc.c \ libvirt-gconfig-domain-hostdev.c \ + libvirt-gconfig-domain-hostdev-pci.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-bridge.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c new file mode 100644 index 000..ed1d146 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c @@ -0,0 +1,211 @@ +/* + * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration + * + * Copyright (C) 2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Christophe Fergeau + */ + +#include + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate)) + +struct _GVirConfigDomainHostdevPciPrivate +{ +gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV); + +static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass) +{ +g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate)); +} + + +static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev) +{ +hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev); +} + +/** + * gvir_config_domain_hostdev_pci_new: + * + * Creates a new #GVirConfigDomainHostdevPci with a reference count of 1. + * + * Returns: a new #GVirConfigDomainHostdevPci + */ +GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void) +{ +GVirConfigObject *object; + +object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, +"hostdev", NULL); +gvir_config_object_set_attribute(object, "mode", "subsystem", NULL); +gvir_config_object_set_attribute(object, "type", "pci", NULL); + +return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object); +} + +/** + * gvir_config_domain_hostdev_pci_new_from_xml: + * @xml: xml data to create the host device from + * @error: return location for a #GError, or NULL + * + * Creates a new #GVirConfigDomainHostdevPci with a reference count of 1. + * The host device object will be created using the XML description stored + * in @xml. This is a fragment of libvirt domain XML whose root node is + * <hostdev>. + * + * Returns: a new #GVirConfigDomainHostdevPci, or NULL if @xml failed to + * be parsed. + */ +GVir
[libvirt] [libvirt-glib 3/3] Add test for GVirConfigDomainHostdevPci API
--- tests/test-gconfig.c| 30 + tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 + 2 files changed, 41 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index be55ef9..c3711f1 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -709,6 +709,34 @@ static void test_domain_device_usb_redir(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_pci_hostdev(void) +{ +GVirConfigDomain *domain; +GVirConfigDomainAddressPci *address; +GVirConfigDomainHostdevPci *hostdev; + +domain = gvir_config_domain_new(); + +hostdev = gvir_config_domain_hostdev_pci_new(); + gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1); +gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE); +gvir_config_domain_hostdev_pci_set_rom(hostdev, "/etc/fake/boot.bin", TRUE); + +address = gvir_config_domain_address_pci_new(); +gvir_config_domain_address_pci_set_domain(address, 1); +gvir_config_domain_address_pci_set_bus(address, 2); +gvir_config_domain_address_pci_set_slot(address, 3); +gvir_config_domain_address_pci_set_function(address, 4); +gvir_config_domain_hostdev_pci_set_address(hostdev, address); +g_object_unref(G_OBJECT(address)); + +gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev)); +g_object_unref(G_OBJECT(hostdev)); + +check_xml(domain, "gconfig-domain-device-pci-hostdev.xml"); + +g_object_unref(G_OBJECT(domain)); +} int main(int argc, char **argv) { @@ -739,6 +767,8 @@ int main(int argc, char **argv) test_domain_device_channel); g_test_add_func("/libvirt-gconfig/domain-device-usb-redir", test_domain_device_usb_redir); +g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", +test_domain_device_pci_hostdev); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml new file mode 100644 index 000..70e32ac --- /dev/null +++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib] gobject, gconfig: Drop redundant debug logging
Justification from IRC chat: danpb: i'm not sure it's good to have a g_debug() for every libvirt-gobject/gconfig object creation/destruction danpb: the debug output becomes so big that at least I never think about enabling it at runtime and sometimes end up missing important debug info yeah we could easily kill that gobject has systemtap probes builtin these days which let you debug object create/finalize problems danpb: oh cool danpb: i'll write a patch --- libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c| 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-cpu-model.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-cpu-topology.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c| 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-guest.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-host-secmodel.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities-host.c | 2 -- libvirt-gconfig/libvirt-gconfig-capabilities.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-address-pci.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-address-usb.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-address.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-channel.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spiceport.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-chardev.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-clock.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-console.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-controller.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-cpu-feature.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-cpu-model.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-cpu.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-device.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-disk-driver.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-disk.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-filesys.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-graphics.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-input.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.c | 2 -- .../libvirt-gconfig-domain-interface-filterref-parameter.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-interface-filterref.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-interface-network.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-interface-user.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-interface.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-memballoon.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-os.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-parallel.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-power-management.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-redirdev.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-seclabel.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-serial.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-smartcard-host-certificates.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-smartcard-host.c | 2 -- libvirt-gconfig/libvirt-gconfig-domain-smartcard-passthrough.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-smartcard.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c| 2 -- libvirt-gconfig/libvirt-gconfig-domain-snaps
Re: [libvirt] [libvirt-glib v5] gobject: Port to GTask API
On Thu, Nov 26, 2015 at 10:20 AM, Christophe Fergeau wrote: > Hey, > > Still a couple of comments :( Fixed and pushed. Thanks for reviews. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v5] gobject: Port to GTask API
Drop usage of deprecated GSimpleAsyncResult API. --- v5: * Plug some GError leaks. * Drop StoragePoolBuildData in favour of GUINT_TO_POINTER/GPOINTER_TO_UINT. * Don't unref GTask before using it later in idle callback. libvirt-gobject/libvirt-gobject-domain.c| 290 +-- libvirt-gobject/libvirt-gobject-input-stream.c | 78 +++ libvirt-gobject/libvirt-gobject-output-stream.c | 76 +++--- libvirt-gobject/libvirt-gobject-storage-pool.c | 296 +--- libvirt-gobject/libvirt-gobject-stream.c| 54 +++-- 5 files changed, 320 insertions(+), 474 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 5509ce3..c768cd3 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -370,28 +370,20 @@ gboolean gvir_domain_start(GVirDomain *dom, return TRUE; } -typedef struct { -guint flags; -} DomainStartData; - -static void domain_start_data_free(DomainStartData *data) -{ -g_slice_free(DomainStartData, data); -} - static void -gvir_domain_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); -DomainStartData *data; +GVirDomain *dom = GVIR_DOMAIN(source_object); +guint flags = GPOINTER_TO_UINT(task_data); GError *err = NULL; -data = g_simple_async_result_get_op_res_gpointer(res); - -if (!gvir_domain_start(dom, data->flags, &err)) -g_simple_async_result_take_error(res, err); +if (!gvir_domain_start(dom, flags, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -410,25 +402,18 @@ void gvir_domain_start_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; -DomainStartData *data; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -data = g_slice_new0(DomainStartData); -data->flags = flags; - -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_start_async); -g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free); -g_simple_async_result_run_in_thread(res, -gvir_domain_start_helper, -G_PRIORITY_DEFAULT, -cancellable); -g_object_unref(res); +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL); +g_task_run_in_thread(task, gvir_domain_start_helper); +g_object_unref(task); } gboolean gvir_domain_start_finish(GVirDomain *dom, @@ -436,13 +421,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); -g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE); +g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) -return FALSE; - -return TRUE; +return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -472,15 +454,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, } static void -gvir_domain_resume_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_resume_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); +GVirDomain *dom = GVIR_DOMAIN(source_object); GError *err = NULL; if (!gvir_domain_resume(dom, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -497,20 +482,17 @@ void gvir_domain_resume_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable
Re: [libvirt] [libvirt-glib v4] gobject: Port to GTask API
On Tue, Nov 24, 2015 at 4:23 PM, Zeeshan Ali (Khattak) wrote: > Drop usage of deprecated GSimpleAsyncResult API. > --- This version ensures that async result is returned from the main thread in gvir_stream_close_async(). > libvirt-gobject/libvirt-gobject-domain.c| 290 > +--- > libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++ > libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++--- > libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++- > libvirt-gobject/libvirt-gobject-stream.c| 53 +++-- > 5 files changed, 322 insertions(+), 454 deletions(-) > > diff --git a/libvirt-gobject/libvirt-gobject-domain.c > b/libvirt-gobject/libvirt-gobject-domain.c > index 5509ce3..c768cd3 100644 > --- a/libvirt-gobject/libvirt-gobject-domain.c > +++ b/libvirt-gobject/libvirt-gobject-domain.c > @@ -370,28 +370,20 @@ gboolean gvir_domain_start(GVirDomain *dom, > return TRUE; > } > > -typedef struct { > -guint flags; > -} DomainStartData; > - > -static void domain_start_data_free(DomainStartData *data) > -{ > -g_slice_free(DomainStartData, data); > -} > - > static void > -gvir_domain_start_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_domain_start_helper(GTask *task, > + gpointer source_object, > + gpointer task_data, > GCancellable *cancellable G_GNUC_UNUSED) > { > -GVirDomain *dom = GVIR_DOMAIN(object); > -DomainStartData *data; > +GVirDomain *dom = GVIR_DOMAIN(source_object); > +guint flags = GPOINTER_TO_UINT(task_data); > GError *err = NULL; > > -data = g_simple_async_result_get_op_res_gpointer(res); > - > -if (!gvir_domain_start(dom, data->flags, &err)) > -g_simple_async_result_take_error(res, err); > +if (!gvir_domain_start(dom, flags, &err)) > +g_task_return_error(task, err); > +else > +g_task_return_boolean(task, TRUE); > } > > /** > @@ -410,25 +402,18 @@ void gvir_domain_start_async(GVirDomain *dom, > GAsyncReadyCallback callback, > gpointer user_data) > { > -GSimpleAsyncResult *res; > -DomainStartData *data; > +GTask *task; > > g_return_if_fail(GVIR_IS_DOMAIN(dom)); > g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); > > -data = g_slice_new0(DomainStartData); > -data->flags = flags; > - > -res = g_simple_async_result_new(G_OBJECT(dom), > -callback, > -user_data, > -gvir_domain_start_async); > -g_simple_async_result_set_op_res_gpointer (res, data, > (GDestroyNotify)domain_start_data_free); > -g_simple_async_result_run_in_thread(res, > -gvir_domain_start_helper, > -G_PRIORITY_DEFAULT, > -cancellable); > -g_object_unref(res); > +task = g_task_new(G_OBJECT(dom), > + cancellable, > + callback, > + user_data); > +g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL); > +g_task_run_in_thread(task, gvir_domain_start_helper); > +g_object_unref(task); > } > > gboolean gvir_domain_start_finish(GVirDomain *dom, > @@ -436,13 +421,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, >GError **err) > { > g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); > -g_return_val_if_fail(g_simple_async_result_is_valid(result, > G_OBJECT(dom), gvir_domain_start_async), FALSE); > +g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); > g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), > err)) > -return FALSE; > - > -return TRUE; > +return g_task_propagate_boolean(G_TASK(result), err); > } > > /** > @@ -472,15 +454,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, > } > > static void > -gvir_domain_resume_helper(GSimpleAsyncResult *res, > - GObject *object, > +gvir_domain_resume_helper(GTask *task, > + gpointer source_object, > + gpointer task_data G_GNUC_UNUSED, >GCancellable *cancellable G_GNUC_UNUSED) > { > -GVirDomain *dom = GVIR_DOMAIN(objec
[libvirt] [libvirt-glib v4] gobject: Port to GTask API
Drop usage of deprecated GSimpleAsyncResult API. --- libvirt-gobject/libvirt-gobject-domain.c| 290 +--- libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++ libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++--- libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++- libvirt-gobject/libvirt-gobject-stream.c| 53 +++-- 5 files changed, 322 insertions(+), 454 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 5509ce3..c768cd3 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -370,28 +370,20 @@ gboolean gvir_domain_start(GVirDomain *dom, return TRUE; } -typedef struct { -guint flags; -} DomainStartData; - -static void domain_start_data_free(DomainStartData *data) -{ -g_slice_free(DomainStartData, data); -} - static void -gvir_domain_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); -DomainStartData *data; +GVirDomain *dom = GVIR_DOMAIN(source_object); +guint flags = GPOINTER_TO_UINT(task_data); GError *err = NULL; -data = g_simple_async_result_get_op_res_gpointer(res); - -if (!gvir_domain_start(dom, data->flags, &err)) -g_simple_async_result_take_error(res, err); +if (!gvir_domain_start(dom, flags, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -410,25 +402,18 @@ void gvir_domain_start_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; -DomainStartData *data; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -data = g_slice_new0(DomainStartData); -data->flags = flags; - -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_start_async); -g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free); -g_simple_async_result_run_in_thread(res, -gvir_domain_start_helper, -G_PRIORITY_DEFAULT, -cancellable); -g_object_unref(res); +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL); +g_task_run_in_thread(task, gvir_domain_start_helper); +g_object_unref(task); } gboolean gvir_domain_start_finish(GVirDomain *dom, @@ -436,13 +421,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); -g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE); +g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) -return FALSE; - -return TRUE; +return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -472,15 +454,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, } static void -gvir_domain_resume_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_resume_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); +GVirDomain *dom = GVIR_DOMAIN(source_object); GError *err = NULL; if (!gvir_domain_resume(dom, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -497,20 +482,17 @@ void gvir_domain_resume_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -
Re: [libvirt] [libvirt-glib v3] gobject: Port to GTask API
On Mon, Nov 23, 2015 at 10:45 PM, Zeeshan Ali (Khattak) wrote: > Drop usage of deprecated GSimpleAsyncResult API. > --- Sorry, forgot to pass --annotate option to git-send-email. v3 just drops some of the private context structures in favour of GPOINTER_TO_UINT/GUINT_TO_POINTER usage. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v3] gobject: Port to GTask API
Drop usage of deprecated GSimpleAsyncResult API. --- libvirt-gobject/libvirt-gobject-domain.c| 290 +--- libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++ libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++--- libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++- libvirt-gobject/libvirt-gobject-stream.c| 52 +++-- 5 files changed, 322 insertions(+), 453 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 5509ce3..c768cd3 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -370,28 +370,20 @@ gboolean gvir_domain_start(GVirDomain *dom, return TRUE; } -typedef struct { -guint flags; -} DomainStartData; - -static void domain_start_data_free(DomainStartData *data) -{ -g_slice_free(DomainStartData, data); -} - static void -gvir_domain_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); -DomainStartData *data; +GVirDomain *dom = GVIR_DOMAIN(source_object); +guint flags = GPOINTER_TO_UINT(task_data); GError *err = NULL; -data = g_simple_async_result_get_op_res_gpointer(res); - -if (!gvir_domain_start(dom, data->flags, &err)) -g_simple_async_result_take_error(res, err); +if (!gvir_domain_start(dom, flags, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -410,25 +402,18 @@ void gvir_domain_start_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; -DomainStartData *data; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -data = g_slice_new0(DomainStartData); -data->flags = flags; - -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_start_async); -g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free); -g_simple_async_result_run_in_thread(res, -gvir_domain_start_helper, -G_PRIORITY_DEFAULT, -cancellable); -g_object_unref(res); +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL); +g_task_run_in_thread(task, gvir_domain_start_helper); +g_object_unref(task); } gboolean gvir_domain_start_finish(GVirDomain *dom, @@ -436,13 +421,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); -g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE); +g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) -return FALSE; - -return TRUE; +return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -472,15 +454,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, } static void -gvir_domain_resume_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_resume_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); +GVirDomain *dom = GVIR_DOMAIN(source_object); GError *err = NULL; if (!gvir_domain_resume(dom, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -497,20 +482,17 @@ void gvir_domain_resume_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -
Re: [libvirt] [libvirt-glib v2 3/3] gobject: Port to GTask API
On Mon, Nov 23, 2015 at 4:08 PM, Christophe Fergeau wrote: > On Fri, Nov 20, 2015 at 09:06:30PM +0000, Zeeshan Ali (Khattak) wrote: >> Drop usage of deprecated GSimpleAsyncResult API. >> --- > > A Changes since v1 section would be nice as this patch is a bit big. > >> >> +typedef struct { >> +guint flags; >> +} DomainWakeupData; >> + >> +static void domain_wakeup_data_free(DomainWakeupData *data) >> +{ >> +g_slice_free(DomainWakeupData, data); >> +} >> + > > Any reason for not using GINT_TO_POINTER? My feeling from the previous > thread was that you were going to do that. Oh, forgot. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib v2 3/3] gobject: Port to GTask API
Drop usage of deprecated GSimpleAsyncResult API. --- libvirt-gobject/libvirt-gobject-domain.c| 273 +++ libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++ libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++ libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++-- libvirt-gobject/libvirt-gobject-stream.c| 52 +++-- 5 files changed, 333 insertions(+), 425 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 34eb7ca..6d57a73 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -380,18 +380,19 @@ static void domain_start_data_free(DomainStartData *data) } static void -gvir_domain_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); -DomainStartData *data; +GVirDomain *dom = GVIR_DOMAIN(source_object); +DomainStartData *data = (DomainStartData *) task_data; GError *err = NULL; -data = g_simple_async_result_get_op_res_gpointer(res); - if (!gvir_domain_start(dom, data->flags, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -410,7 +411,7 @@ void gvir_domain_start_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; DomainStartData *data; g_return_if_fail(GVIR_IS_DOMAIN(dom)); @@ -419,16 +420,13 @@ void gvir_domain_start_async(GVirDomain *dom, data = g_slice_new0(DomainStartData); data->flags = flags; -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_start_async); -g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free); -g_simple_async_result_run_in_thread(res, -gvir_domain_start_helper, -G_PRIORITY_DEFAULT, -cancellable); -g_object_unref(res); +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +g_task_set_task_data(task, data, (GDestroyNotify)domain_start_data_free); +g_task_run_in_thread(task, gvir_domain_start_helper); +g_object_unref(task); } gboolean gvir_domain_start_finish(GVirDomain *dom, @@ -436,13 +434,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); -g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE); +g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) -return FALSE; - -return TRUE; +return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -472,15 +467,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, } static void -gvir_domain_resume_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_resume_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); +GVirDomain *dom = GVIR_DOMAIN(source_object); GError *err = NULL; if (!gvir_domain_resume(dom, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -497,20 +495,17 @@ void gvir_domain_resume_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_resume_async); -g_simple_async_result_run_in_thread(res, -gvir_domain_resume_helper, -G_
[libvirt] [libvirt-glib v2 1/3] gobject: Drop redundant glib compatibility code
We already require and use glib >= 2.36 so there is no reason to keep around code to ensure compatibility with glib older than that. --- libvirt-gobject/libvirt-gobject-compat.c | 87 libvirt-gobject/libvirt-gobject-compat.h | 73 --- 2 files changed, 160 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-compat.c b/libvirt-gobject/libvirt-gobject-compat.c index 14b5eb3..e91b018 100644 --- a/libvirt-gobject/libvirt-gobject-compat.c +++ b/libvirt-gobject/libvirt-gobject-compat.c @@ -17,93 +17,6 @@ #include "libvirt-gobject-compat.h" -#if !GLIB_CHECK_VERSION(2,28,0) -/** - * g_simple_async_result_take_error: (skip) - * @simple: a #GSimpleAsyncResult - * @error: a #GError - * - * Sets the result from @error, and takes over the caller's ownership - * of @error, so the caller does not need to free it any more. - * - * Since: 2.28 - **/ -G_GNUC_INTERNAL void -g_simple_async_result_take_error (GSimpleAsyncResult *simple, - GError *error) -{ -/* this code is different from upstream */ -/* we can't avoid extra copy/free, since the simple struct is - opaque */ -g_simple_async_result_set_from_error (simple, error); -g_error_free (error); -} - -/** - * g_simple_async_result_new_take_error: (skip) - * @source_object: (allow-none): a #GObject, or %NULL - * @callback: (scope async): a #GAsyncReadyCallback - * @user_data: (closure): user data passed to @callback - * @error: a #GError - * - * Creates a #GSimpleAsyncResult from an error condition, and takes over the - * caller's ownership of @error, so the caller does not need to free it anymore. - * - * Returns: a #GSimpleAsyncResult - * - * Since: 2.28 - **/ -GSimpleAsyncResult * -g_simple_async_result_new_take_error(GObject *source_object, - GAsyncReadyCallback callback, - gpointer user_data, - GError *error) -{ -GSimpleAsyncResult *simple; - -g_return_val_if_fail(!source_object || G_IS_OBJECT(source_object), NULL); - -simple = g_simple_async_result_new(source_object, - callback, - user_data, NULL); -g_simple_async_result_take_error(simple, error); - -return simple; -} - -/** - * g_simple_async_report_take_gerror_in_idle: (skip) - * @object: (allow-none): a #GObject, or %NULL - * @callback: a #GAsyncReadyCallback. - * @user_data: user data passed to @callback. - * @error: the #GError to report - * - * Reports an error in an idle function. Similar to - * g_simple_async_report_gerror_in_idle(), but takes over the caller's - * ownership of @error, so the caller does not have to free it any more. - * - * Since: 2.28 - **/ -void -g_simple_async_report_take_gerror_in_idle(GObject *object, - GAsyncReadyCallback callback, - gpointer user_data, - GError *error) -{ -GSimpleAsyncResult *simple; - -g_return_if_fail(!object || G_IS_OBJECT(object)); -g_return_if_fail(error != NULL); - -simple = g_simple_async_result_new_take_error(object, - callback, - user_data, - error); -g_simple_async_result_complete_in_idle(simple); -g_object_unref(simple); -} -#endif - GMutex *gvir_mutex_new(void) { GMutex *mutex; diff --git a/libvirt-gobject/libvirt-gobject-compat.h b/libvirt-gobject/libvirt-gobject-compat.h index 2e87966..27fa305 100644 --- a/libvirt-gobject/libvirt-gobject-compat.h +++ b/libvirt-gobject/libvirt-gobject-compat.h @@ -35,77 +35,4 @@ GMutex *gvir_mutex_new(void); #endif -#if !GLIB_CHECK_VERSION(2,26,0) -#define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {}) -#define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) _G_DEFINE_BOXED_TYPE_BEGIN (TypeName, type_name, copy_func, free_func) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ -GType \ -type_name##_get_type (void) \ -{ \ - static volatile gsize g_define_type_id__volatile = 0; \ - if (g_once_init_enter (&g_define_type_id__volatile)) \ -{ \ - GType (* _g_register_boxed) \ -(const gchar *, \ - union \ - { \ - TypeName * (*do_copy_type) (TypeName *); \ - TypeName * (*do_const_copy_type) (const TypeName *); \ - GBoxedCopyFunc do_copy_boxed; \ - } __attribute__((__transparent_union__)), \ - union \ - { \ - void (* do_free_type) (T
[libvirt] [libvirt-glib v2 2/3] gconfig: Drop redundant glib compatibility code
We already require and use glib >= 2.36 so there is no reason to keep around code to ensure compatibility with glib older than that. --- libvirt-gconfig/libvirt-gconfig-compat.h | 20 1 file changed, 20 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-compat.h b/libvirt-gconfig/libvirt-gconfig-compat.h index fbf552c..c9ac645 100644 --- a/libvirt-gconfig/libvirt-gconfig-compat.h +++ b/libvirt-gconfig/libvirt-gconfig-compat.h @@ -25,26 +25,6 @@ #include -#if !GLIB_CHECK_VERSION(2,32,0) - -#if__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) -#define G_DEPRECATED __attribute__((__deprecated__)) -#elif defined(_MSC_VER) && (_MSC_VER >= 1300) -#define G_DEPRECATED __declspec(deprecated) -#else -#define G_DEPRECATED -#endif - -#if__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) -#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) -#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) -#else -#define G_DEPRECATED_FOR(f) G_DEPRECATED -#endif - -#endif - #if GLIB_CHECK_VERSION(2, 35, 0) #define g_type_init() #endif -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib 2/3] gconfig: Drop redundant glib compatibility code
We already require and use glib >= 2.36 so there is no reason to keep around code to ensure compatibility with glib older than that. --- libvirt-gconfig/libvirt-gconfig-compat.h | 20 1 file changed, 20 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-compat.h b/libvirt-gconfig/libvirt-gconfig-compat.h index fbf552c..c9ac645 100644 --- a/libvirt-gconfig/libvirt-gconfig-compat.h +++ b/libvirt-gconfig/libvirt-gconfig-compat.h @@ -25,26 +25,6 @@ #include -#if !GLIB_CHECK_VERSION(2,32,0) - -#if__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) -#define G_DEPRECATED __attribute__((__deprecated__)) -#elif defined(_MSC_VER) && (_MSC_VER >= 1300) -#define G_DEPRECATED __declspec(deprecated) -#else -#define G_DEPRECATED -#endif - -#if__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) -#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) -#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) -#else -#define G_DEPRECATED_FOR(f) G_DEPRECATED -#endif - -#endif - #if GLIB_CHECK_VERSION(2, 35, 0) #define g_type_init() #endif -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib 3/3] gobject: Port to GTask API
> if (class->close_fn && >> !class->close_fn(stream, cancellable, &error)) { >> -g_simple_async_report_take_gerror_in_idle(G_OBJECT (stream), >> - callback, user_data, >> - error); >> +g_task_return_error(task, error); >> return; >> } >> >> -res = g_simple_async_result_new(G_OBJECT (stream), >> -callback, >> -user_data, >> -gvir_stream_close_async); >> -g_simple_async_result_complete_in_idle(res); >> -g_object_unref (res); >> +g_task_return_boolean(task, TRUE); >> +} >> + >> +static void gvir_stream_close_async(GIOStream *stream, >> +int io_priority G_GNUC_UNUSED, >> +GCancellable *cancellable, >> +GAsyncReadyCallback callback, >> +gpointer user_data) >> +{ >> +GTask *task; >> + >> +task = g_task_new(G_OBJECT(stream), >> + cancellable, >> + callback, >> + user_data); >> +g_task_run_in_thread(task, gvir_stream_close_helper); >> +g_object_unref(task); >> } > > Was this one creating a GSimpleAsyncResult and returning immediately > without doing anything? I doubt so. AFAICT, it was scheduling the result to be returned in the idle using 'g_simple_async_result_complete_in_idle'. > The helper does not seem to be doing anything more, in which case I'd > suggest not creating an intermediate helper thread, and to do something > similar to what was done before. If this is a bug and more work should > be done, I'd prefer if this was done in a separate patch. I just failed to find a straight GTask replacement API for 'g_simple_async_result_complete_in_idle'. The docs for 'g_task_return_pointer' say: ""Completes the task" means that for an ordinary asynchronous task it will either invoke the task's callback, or else queue that callback to be invoked in the proper GMainContext, or in the next iteration of the current GMainContext." So I'm not sure if simply calling g_task_return_*() wouldn't change the behaviour and call the callback immediately. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [v3] gobject: Add wrapper virDomainSetTime()
--- libvirt-gobject/libvirt-gobject-domain.c | 134 +++ libvirt-gobject/libvirt-gobject-domain.h | 15 +++- libvirt-gobject/libvirt-gobject.sym | 9 +++ 3 files changed, 157 insertions(+), 1 deletion(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 34eb7ca..cb8096b 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -1886,3 +1886,137 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom, return TRUE; } + +/** + * gvir_domain_set_time: + * @dom: the domain + * @date_time: (allow-none)(transfer none): the time to set as #GDateTime. + * @flags: Unused, pass 0. + * @error: (allow-none): Place-holder for error or %NULL + * + * This function tries to set guest time to the given value. The passed + * time must in UTC. + * + * If @date_time is %NULL, the time is reset using the domain's RTC. + * + * Please note that some hypervisors may require guest agent to be configured + * and running in order for this function to work. + * + * Returns: %TRUE on success, %FALSE otherwise. + */ +gboolean gvir_domain_set_time(GVirDomain *dom, + GDateTime *date_time, + guint flags G_GNUC_UNUSED, + GError **err) +{ +int ret; +GTimeVal tv; +glong seconds; +glong nseconds; +guint settime_flags; + +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); +g_return_val_if_fail(flags == 0, FALSE); + +if (date_time != NULL) { +if (!g_date_time_to_timeval(date_time, &tv)) { +g_set_error_literal(err, GVIR_DOMAIN_ERROR, +0, +"Failed to parse given time argument"); +return FALSE; +} + +seconds = tv.tv_sec; +nseconds = tv.tv_usec * 1000; +settime_flags = 0; +} else { +seconds = 0; +nseconds = 0; +settime_flags = VIR_DOMAIN_TIME_SYNC; +} + +ret = virDomainSetTime(dom->priv->handle, seconds, nseconds, settime_flags); +if (ret < 0) { +gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to set domain time"); +return FALSE; +} + +return TRUE; +} + +static void +gvir_domain_set_time_helper(GTask *task, +gpointer object, +gpointer task_data, +GCancellable *cancellable G_GNUC_UNUSED) +{ +GVirDomain *dom = GVIR_DOMAIN(object); +GDateTime *date_time = (GDateTime *) task_data; +GError *err = NULL; + +if (!gvir_domain_set_time(dom, date_time, 0, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); +} + +/** + * gvir_domain_set_time_async: + * @dom: the domain + * @date_time: (allow-none)(transfer none): the time to set as #GDateTime. + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + * + * Asynchronous variant of #gvir_domain_set_time. + */ +void gvir_domain_set_time_async(GVirDomain *dom, +GDateTime *date_time, +guint flags G_GNUC_UNUSED, +GCancellable *cancellable, +GAsyncReadyCallback callback, +gpointer user_data) +{ +GTask *task; + +g_return_if_fail(GVIR_IS_DOMAIN(dom)); +g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); +g_return_if_fail(flags == 0); + +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +if (date_time != NULL) +g_task_set_task_data(task, + g_date_time_ref(date_time), + (GDestroyNotify)g_date_time_unref); +g_task_run_in_thread(task, gvir_domain_set_time_helper); + +g_object_unref(task); +} + +/** + * gvir_domain_set_time_finish: + * @dom: the domain + * @result: (transfer none): async method result + * @err: Place-holder for possible errors + * + * Finishes the operation started by #gvir_domain_set_time_async. + * + * Returns: %TRUE on success, %FALSE otherwise. + */ +gboolean gvir_domain_set_time_finish(GVirDomain *dom, + GAsyncResult *result, + GError **err) +{ +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); +g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(dom)), FALSE); +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); + +return g_task_propagate_boolean(G_TA
Re: [libvirt] [PATCH v2] gobject: Add wrapper virDomainSetTime()
Hi, >> +guint settime_flags; >> + >> +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); >> +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > > I'd keep a g_return_val_if_fail(flags == 0, FALSE); But doesn't that make G_GNUC_UNUSED declaration wrong then? I think it's more important to optimize it out rather than ensuring programmer doesn't pass wrong value by mistake, here. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2] gobject: Add wrapper virDomainSetTime()
--- This version: * Replaces the seconds and nseconds arguments by a GDateTime. * Drops the use of flags argument, since caller can specify the only flag currently possible (VIR_DOMAIN_TIME_SYNC) by simply passing a NULL as the GDateTime argument. * Add some needed articles to doc comment. libvirt-gobject/libvirt-gobject-domain.c | 121 +++ libvirt-gobject/libvirt-gobject-domain.h | 15 +++- libvirt-gobject/libvirt-gobject.sym | 9 +++ 3 files changed, 144 insertions(+), 1 deletion(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 34eb7ca..debae2d 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -1886,3 +1886,124 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom, return TRUE; } + +/** + * gvir_domain_set_time: + * @dom: the domain + * @date_time: (allow-none)(transfer none): the time to set as #GDateTime. + * @flags: Unused, Pass 0. + * + * This function tries to set guest time to the given value. The passed + * time must in UTC. + * + * If @date_time is %NULL, the time is reset using the domain's RTC. + * + * Please note that some hypervisors may require guest agent to be configured + * and running in order for this function to work. + */ +gboolean gvir_domain_set_time(GVirDomain *dom, + GDateTime *date_time, + guint flags G_GNUC_UNUSED, + GError **err) +{ +GVirDomainPrivate *priv; +int ret; +GTimeVal tv; +gint64 seconds; +guint nseconds; +guint settime_flags; + +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); + +if (date_time != NULL) { +if (!g_date_time_to_timeval(date_time, &tv)) { +gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Failed to parse given time argument"); +return FALSE; +} + +seconds = tv.tv_sec; +nseconds = tv.tv_usec * 1000; +settime_flags = 0; +} else { +seconds = 0; +nseconds = 0; +settime_flags = VIR_DOMAIN_TIME_SYNC; +} + +priv = dom->priv; +ret = virDomainSetTime(priv->handle, seconds, nseconds, settime_flags); +if (ret < 0) { +gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to set domain time"); +return FALSE; +} + +return TRUE; +} + +static void +gvir_domain_set_time_helper(GTask *task, +gpointer object, +gpointer task_data, +GCancellable *cancellable G_GNUC_UNUSED) +{ +GVirDomain *dom = GVIR_DOMAIN(object); +GDateTime *date_time = (GDateTime *) task_data; +GError *err = NULL; + +if (!gvir_domain_set_time(dom, date_time, 0, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); +} + +/** + * gvir_domain_set_time_async: + * @dom: the domain + * @date_time: (allow-none)(transfer none): the time to set as #GDateTime. + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + * + * Asynchronous variant of #gvir_domain_set_time. + */ +void gvir_domain_set_time_async(GVirDomain *dom, +GDateTime *date_time, +guint flags G_GNUC_UNUSED, +GCancellable *cancellable, +GAsyncReadyCallback callback, +gpointer user_data) +{ +GTask *task; + +g_return_if_fail(GVIR_IS_DOMAIN(dom)); +g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); + +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +if (date_time != NULL) +g_task_set_task_data(task, + g_date_time_ref(date_time), + (GDestroyNotify)g_date_time_unref); +g_task_run_in_thread(task, gvir_domain_set_time_helper); + +g_object_unref(task); +} + +gboolean gvir_domain_set_time_finish(GVirDomain *dom, + GAsyncResult *result, + GError **err) +{ +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); +g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(dom)), FALSE); +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); + +return g_task_propagate_boolean(G_TASK(result), err); +} diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index
[libvirt] [libvirt-glib 3/3] gobject: Port to GTask API
Drop usage of deprecated GSimpleAsyncResult API. --- libvirt-gobject/libvirt-gobject-domain.c| 270 ++- libvirt-gobject/libvirt-gobject-input-stream.c | 76 +++ libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++ libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++-- libvirt-gobject/libvirt-gobject-stream.c| 46 ++-- 5 files changed, 326 insertions(+), 422 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 34eb7ca..dda9268 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -380,18 +380,19 @@ static void domain_start_data_free(DomainStartData *data) } static void -gvir_domain_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); -DomainStartData *data; +GVirDomain *dom = GVIR_DOMAIN(source_object); +DomainStartData *data = (DomainStartData *) task_data; GError *err = NULL; -data = g_simple_async_result_get_op_res_gpointer(res); - if (!gvir_domain_start(dom, data->flags, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -410,7 +411,7 @@ void gvir_domain_start_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; DomainStartData *data; g_return_if_fail(GVIR_IS_DOMAIN(dom)); @@ -419,16 +420,13 @@ void gvir_domain_start_async(GVirDomain *dom, data = g_slice_new0(DomainStartData); data->flags = flags; -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_start_async); -g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free); -g_simple_async_result_run_in_thread(res, -gvir_domain_start_helper, -G_PRIORITY_DEFAULT, -cancellable); -g_object_unref(res); +task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); +g_task_set_task_data(task, data, (GDestroyNotify)domain_start_data_free); +g_task_run_in_thread(task, gvir_domain_start_helper); +g_object_unref(task); } gboolean gvir_domain_start_finish(GVirDomain *dom, @@ -436,13 +434,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); -g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE); +g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) -return FALSE; - -return TRUE; +return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -472,15 +467,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, } static void -gvir_domain_resume_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_resume_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { -GVirDomain *dom = GVIR_DOMAIN(object); +GVirDomain *dom = GVIR_DOMAIN(source_object); GError *err = NULL; if (!gvir_domain_resume(dom, &err)) -g_simple_async_result_take_error(res, err); +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } /** @@ -497,20 +495,17 @@ void gvir_domain_resume_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -res = g_simple_async_result_new(G_OBJECT(dom), -callback, -user_data, -gvir_domain_resume_async); -g_simple_async_result_run_in_thread(res, -gvir_domain_resume_helper, -G_P
[libvirt] [libvirt-glib 1/3] gobject: Drop redundant glib compatibility code
We already require and use glib >= 2.36 so there is no reason to keep around code to ensure compatibility with glib oler than that. --- libvirt-gobject/libvirt-gobject-compat.c | 87 libvirt-gobject/libvirt-gobject-compat.h | 73 --- 2 files changed, 160 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-compat.c b/libvirt-gobject/libvirt-gobject-compat.c index 14b5eb3..e91b018 100644 --- a/libvirt-gobject/libvirt-gobject-compat.c +++ b/libvirt-gobject/libvirt-gobject-compat.c @@ -17,93 +17,6 @@ #include "libvirt-gobject-compat.h" -#if !GLIB_CHECK_VERSION(2,28,0) -/** - * g_simple_async_result_take_error: (skip) - * @simple: a #GSimpleAsyncResult - * @error: a #GError - * - * Sets the result from @error, and takes over the caller's ownership - * of @error, so the caller does not need to free it any more. - * - * Since: 2.28 - **/ -G_GNUC_INTERNAL void -g_simple_async_result_take_error (GSimpleAsyncResult *simple, - GError *error) -{ -/* this code is different from upstream */ -/* we can't avoid extra copy/free, since the simple struct is - opaque */ -g_simple_async_result_set_from_error (simple, error); -g_error_free (error); -} - -/** - * g_simple_async_result_new_take_error: (skip) - * @source_object: (allow-none): a #GObject, or %NULL - * @callback: (scope async): a #GAsyncReadyCallback - * @user_data: (closure): user data passed to @callback - * @error: a #GError - * - * Creates a #GSimpleAsyncResult from an error condition, and takes over the - * caller's ownership of @error, so the caller does not need to free it anymore. - * - * Returns: a #GSimpleAsyncResult - * - * Since: 2.28 - **/ -GSimpleAsyncResult * -g_simple_async_result_new_take_error(GObject *source_object, - GAsyncReadyCallback callback, - gpointer user_data, - GError *error) -{ -GSimpleAsyncResult *simple; - -g_return_val_if_fail(!source_object || G_IS_OBJECT(source_object), NULL); - -simple = g_simple_async_result_new(source_object, - callback, - user_data, NULL); -g_simple_async_result_take_error(simple, error); - -return simple; -} - -/** - * g_simple_async_report_take_gerror_in_idle: (skip) - * @object: (allow-none): a #GObject, or %NULL - * @callback: a #GAsyncReadyCallback. - * @user_data: user data passed to @callback. - * @error: the #GError to report - * - * Reports an error in an idle function. Similar to - * g_simple_async_report_gerror_in_idle(), but takes over the caller's - * ownership of @error, so the caller does not have to free it any more. - * - * Since: 2.28 - **/ -void -g_simple_async_report_take_gerror_in_idle(GObject *object, - GAsyncReadyCallback callback, - gpointer user_data, - GError *error) -{ -GSimpleAsyncResult *simple; - -g_return_if_fail(!object || G_IS_OBJECT(object)); -g_return_if_fail(error != NULL); - -simple = g_simple_async_result_new_take_error(object, - callback, - user_data, - error); -g_simple_async_result_complete_in_idle(simple); -g_object_unref(simple); -} -#endif - GMutex *gvir_mutex_new(void) { GMutex *mutex; diff --git a/libvirt-gobject/libvirt-gobject-compat.h b/libvirt-gobject/libvirt-gobject-compat.h index 2e87966..27fa305 100644 --- a/libvirt-gobject/libvirt-gobject-compat.h +++ b/libvirt-gobject/libvirt-gobject-compat.h @@ -35,77 +35,4 @@ GMutex *gvir_mutex_new(void); #endif -#if !GLIB_CHECK_VERSION(2,26,0) -#define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {}) -#define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) _G_DEFINE_BOXED_TYPE_BEGIN (TypeName, type_name, copy_func, free_func) {_C_;} _G_DEFINE_TYPE_EXTENDED_END() -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \ -GType \ -type_name##_get_type (void) \ -{ \ - static volatile gsize g_define_type_id__volatile = 0; \ - if (g_once_init_enter (&g_define_type_id__volatile)) \ -{ \ - GType (* _g_register_boxed) \ -(const gchar *, \ - union \ - { \ - TypeName * (*do_copy_type) (TypeName *); \ - TypeName * (*do_const_copy_type) (const TypeName *); \ - GBoxedCopyFunc do_copy_boxed; \ - } __attribute__((__transparent_union__)), \ - union \ - { \ - void (* do_free_type) (Ty
[libvirt] [libvirt-glib 2/3] gconfig: Drop redundant glib compatibility code
We already require and use glib >= 2.36 so there is no reason to keep around code to ensure compatibility with glib oler than that. --- libvirt-gconfig/libvirt-gconfig-compat.h | 20 1 file changed, 20 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-compat.h b/libvirt-gconfig/libvirt-gconfig-compat.h index fbf552c..c9ac645 100644 --- a/libvirt-gconfig/libvirt-gconfig-compat.h +++ b/libvirt-gconfig/libvirt-gconfig-compat.h @@ -25,26 +25,6 @@ #include -#if !GLIB_CHECK_VERSION(2,32,0) - -#if__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) -#define G_DEPRECATED __attribute__((__deprecated__)) -#elif defined(_MSC_VER) && (_MSC_VER >= 1300) -#define G_DEPRECATED __declspec(deprecated) -#else -#define G_DEPRECATED -#endif - -#if__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) -#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) -#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) -#else -#define G_DEPRECATED_FOR(f) G_DEPRECATED -#endif - -#endif - #if GLIB_CHECK_VERSION(2, 35, 0) #define g_type_init() #endif -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Drop deprecated API use + redundant compat. code
Couldn't come up with a better summary here, sorry but these patches simply * Drop usage of deprecated GSimpleAsyncResult API. * Drop redundant compatibility API. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib] gobject: Add wrapper virDomainSetTime()
Hi Christophe, On Wed, Oct 28, 2015 at 10:15 AM, Christophe Fergeau wrote: > Hey, > > On Tue, Oct 27, 2015 at 06:17:58PM +, Zeeshan Ali (Khattak) wrote: >> --- >> libvirt-gobject/libvirt-gobject-domain.c | 126 >> +++ >> libvirt-gobject/libvirt-gobject-domain.h | 25 ++ >> libvirt-gobject/libvirt-gobject.sym | 9 +++ >> 3 files changed, 160 insertions(+) >> >> diff --git a/libvirt-gobject/libvirt-gobject-domain.c >> b/libvirt-gobject/libvirt-gobject-domain.c >> index 34eb7ca..26d0cba 100644 >> --- a/libvirt-gobject/libvirt-gobject-domain.c >> +++ b/libvirt-gobject/libvirt-gobject-domain.c >> @@ -1886,3 +1886,129 @@ gboolean >> gvir_domain_get_has_current_snapshot(GVirDomain *dom, >> >> return TRUE; >> } >> + >> +/** >> + * gvir_domain_set_time: >> + * @dom: the domain >> + * @seconds: The seconds since Epoch in UTC. >> + * @nseconds: The microseconds. >> + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. >> + * >> + * This function tries to set guest time to the given value. The time to set >> + * (@seconds and @nseconds) should be in seconds relative to the Epoch of >> + * 1970-01-01 00:00:00 in UTC. >> + * >> + * If you pass #GVIR_DOMAIN_TIME_SYNC as @flags, the time is reset using >> + * domain's RTC and @seconds and @nseconds arguments are ignored. > > I'd add some more articles, but not sure it's needed/better: « using > the domain's RTC and the @seconds and @nseconds arguments are ignored. » > >> + * >> + * Please note that some hypervisors may require guest agent to be >> configured >> + * and running in order for this function to work. > > and here « a guest agent ». Just ignore these comments if you are > confident your version reads better to native speakers :) I'm no native speaker so I wouldn't know. :) However, "a guest agent" would sound to me that it could be any guest agent but then again, specifying "Qemu guest agent" would be wrong, keeping in mind that libvirt wants to remain hypervisor-agnostic. I had just copy&pasted that part from underlying libvirt docs. >> + */ >> +gboolean gvir_domain_set_time(GVirDomain *dom, >> + gint64 seconds, >> + guint nseconds, > > A GDateTime would be more convenient than these seconds/nseconds fields. Ah, indeed. >> + guint flags, >> + GError **err) >> +{ >> +GVirDomainPrivate *priv; >> +int ret; >> + >> +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); >> +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); >> +g_return_val_if_fail(flags == 0 || flags & GVIR_DOMAIN_TIME_SYNC, >> FALSE); > > (flags & GVIR_DOMAIN_TIME_SYNC) != 0 to be consistent with the 'flags == > 0' before. However, shouldn't it be flags & GVIR_DOMAIN_TIME_SYNC == > GVIR_DOMAIN_TIME_SYNC to be sure we were not passed unknown flags? Yeah, that sounds better. > Looks good otherwise. Out of curiosity have you observed > virDomainSetTime blocking, or is the async version there because it will > be doing expensive stuff if it has to talk to a guest agent? The latter. Most libvirt calls do I/O so it's best to have async variants for them but in this case I thought it's especially needed since there not only communication with libvirtd involved but also guest agent. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib] gobject: Add wrapper virDomainSetTime()
--- libvirt-gobject/libvirt-gobject-domain.c | 126 +++ libvirt-gobject/libvirt-gobject-domain.h | 25 ++ libvirt-gobject/libvirt-gobject.sym | 9 +++ 3 files changed, 160 insertions(+) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 34eb7ca..26d0cba 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -1886,3 +1886,129 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom, return TRUE; } + +/** + * gvir_domain_set_time: + * @dom: the domain + * @seconds: The seconds since Epoch in UTC. + * @nseconds: The microseconds. + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. + * + * This function tries to set guest time to the given value. The time to set + * (@seconds and @nseconds) should be in seconds relative to the Epoch of + * 1970-01-01 00:00:00 in UTC. + * + * If you pass #GVIR_DOMAIN_TIME_SYNC as @flags, the time is reset using + * domain's RTC and @seconds and @nseconds arguments are ignored. + * + * Please note that some hypervisors may require guest agent to be configured + * and running in order for this function to work. + */ +gboolean gvir_domain_set_time(GVirDomain *dom, + gint64 seconds, + guint nseconds, + guint flags, + GError **err) +{ +GVirDomainPrivate *priv; +int ret; + +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); +g_return_val_if_fail(flags == 0 || flags & GVIR_DOMAIN_TIME_SYNC, FALSE); + +priv = dom->priv; +ret = virDomainSetTime(priv->handle, seconds, nseconds, flags); +if (ret < 0) { +gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to set domain time"); +return FALSE; +} + +return TRUE; +} + +typedef struct { +gint64 seconds; +guint nseconds; +guint flags; +} DomainSetTimeData; + +static void domain_set_time_data_free(DomainSetTimeData *data) +{ +g_slice_free(DomainSetTimeData, data); +} + +static void +gvir_domain_set_time_helper(GTask *task, +gpointer object, +gpointer task_data, +GCancellable *cancellable G_GNUC_UNUSED) +{ +GVirDomain *dom = GVIR_DOMAIN(object); +DomainSetTimeData *data = (DomainSetTimeData *) task_data; +GError *err = NULL; + +if (!gvir_domain_set_time(dom, + data->seconds, + data->nseconds, + data->flags, + &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); +} + +/** + * gvir_domain_set_time_async: + * @dom: the domain + * @dom: the domain + * @seconds: The seconds since Epoch in UTC. + * @nseconds: The microseconds. + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + * + * Asynchronous variant of #gvir_domain_set_time. + */ +void gvir_domain_set_time_async(GVirDomain *dom, +gint64 seconds, +guint nseconds, +guint flags, +GCancellable *cancellable, +GAsyncReadyCallback callback, +gpointer user_data) +{ +GTask *task; +DomainSetTimeData *data; + +g_return_if_fail(GVIR_IS_DOMAIN(dom)); +g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); + +data = g_slice_new0(DomainSetTimeData); +data->seconds = seconds; +data->nseconds = nseconds; +data->flags = flags; + +task = g_task_new (G_OBJECT(dom), + cancellable, + callback, + user_data); +g_task_set_task_data (task, data, (GDestroyNotify)domain_set_time_data_free); +g_task_run_in_thread(task, gvir_domain_set_time_helper); + +g_object_unref(task); +} + +gboolean gvir_domain_set_time_finish(GVirDomain *dom, + GAsyncResult *result, + GError **err) +{ +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); +g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(dom)), FALSE); +g_return_val_if_fail(err == NULL || *err == NULL, FALSE); + +return g_task_propagate_boolean(G_TASK(result), err); +} diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 4fe381e..fbf7173 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h
Re: [libvirt] [libvirt-glib] gobject: Correct docs for gvir_storage_pool_get_info()
On Wed, Sep 23, 2015 at 3:00 PM, Daniel P. Berrange wrote: > On Wed, Sep 23, 2015 at 02:54:51PM +0100, Zeeshan Ali (Khattak) wrote: >> On Wed, Sep 23, 2015 at 2:18 PM, Daniel P. Berrange >> wrote: >> > On Wed, Sep 23, 2015 at 01:44:28PM +0100, Zeeshan Ali (Khattak) wrote: >> >> The returned GVirStoragePoolInfo pointer is not a GObject so it must not >> >> be unrefed using g_object_unref(). Since gvir_storage_pool_info_free() >> >> is private function, callers must either use g_slice_free() or >> >> g_boxed_free(). >> >> --- >> >> >> >> Perhaps we should just make gvir_storage_pool_info_free() public instead? >> >> >> >> libvirt-gobject/libvirt-gobject-storage-pool.c | 4 ++-- >> >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> >> >> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c >> >> b/libvirt-gobject/libvirt-gobject-storage-pool.c >> >> index 7f26b1b..f015efa 100644 >> >> --- a/libvirt-gobject/libvirt-gobject-storage-pool.c >> >> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c >> >> @@ -277,8 +277,8 @@ GVirConfigStoragePool >> >> *gvir_storage_pool_get_config(GVirStoragePool *pool, >> >> * @pool: the storage_pool >> >> * @err: Place-holder for possible errors >> >> * >> >> - * Returns: (transfer full): the info. The returned object should be >> >> - * unreffed with g_object_unref() when no longer needed. >> >> + * Returns: (transfer full): the info. The returned pointer should be >> >> + * freed using either #g_slice_free() or #g_boxed_free() when no longer >> >> needed. >> >> */ >> >> GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool, >> >> GError **err) >> > >> > ACK >> >> Thanks but just to be sure, I hope you didn't miss the details and >> this comment below it: >> >> > Perhaps we should just make gvir_storage_pool_info_free() public instead? > > Since we've defined it as a boxed type, I think recommending g_boxed_free > is the right solution. It's just that it's slightly awkward to use that, since you need to pass it the gtype, not just the pointer. > We should make sure our docs actually tell people > this is a boxed type if they don't already :-) > > We should *not* in fact recommend g_slice_free(), as the use of the slice > allocator is an internal implementation detail. We should be free to change > to use a different allocator without breaking clients. Sure, I pushed with g_slice_free() mention removed. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib] gobject: Correct docs for gvir_storage_pool_get_info()
On Wed, Sep 23, 2015 at 2:18 PM, Daniel P. Berrange wrote: > On Wed, Sep 23, 2015 at 01:44:28PM +0100, Zeeshan Ali (Khattak) wrote: >> The returned GVirStoragePoolInfo pointer is not a GObject so it must not >> be unrefed using g_object_unref(). Since gvir_storage_pool_info_free() >> is private function, callers must either use g_slice_free() or >> g_boxed_free(). >> --- >> >> Perhaps we should just make gvir_storage_pool_info_free() public instead? >> >> libvirt-gobject/libvirt-gobject-storage-pool.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c >> b/libvirt-gobject/libvirt-gobject-storage-pool.c >> index 7f26b1b..f015efa 100644 >> --- a/libvirt-gobject/libvirt-gobject-storage-pool.c >> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c >> @@ -277,8 +277,8 @@ GVirConfigStoragePool >> *gvir_storage_pool_get_config(GVirStoragePool *pool, >> * @pool: the storage_pool >> * @err: Place-holder for possible errors >> * >> - * Returns: (transfer full): the info. The returned object should be >> - * unreffed with g_object_unref() when no longer needed. >> + * Returns: (transfer full): the info. The returned pointer should be >> + * freed using either #g_slice_free() or #g_boxed_free() when no longer >> needed. >> */ >> GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool, >> GError **err) > > ACK Thanks but just to be sure, I hope you didn't miss the details and this comment below it: > Perhaps we should just make gvir_storage_pool_info_free() public instead? -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib] gobject: Correct docs for gvir_storage_pool_get_info()
The returned GVirStoragePoolInfo pointer is not a GObject so it must not be unrefed using g_object_unref(). Since gvir_storage_pool_info_free() is private function, callers must either use g_slice_free() or g_boxed_free(). --- Perhaps we should just make gvir_storage_pool_info_free() public instead? libvirt-gobject/libvirt-gobject-storage-pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index 7f26b1b..f015efa 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -277,8 +277,8 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, * @pool: the storage_pool * @err: Place-holder for possible errors * - * Returns: (transfer full): the info. The returned object should be - * unreffed with g_object_unref() when no longer needed. + * Returns: (transfer full): the info. The returned pointer should be + * freed using either #g_slice_free() or #g_boxed_free() when no longer needed. */ GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool, GError **err) -- 2.4.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH glib] README: formally document intended platform support targets
On Wed, Jul 22, 2015 at 2:02 PM, Daniel P. Berrange wrote: > Give users an indication of what distro platforms the project > intends to be buildable on. This policy will be used to decide > when it is appropriate to increase the minimum required versions > of external dependancies. While this sounds like a good idea at first, being so specific about versions makes it a very bad one IMO. i-e this list will get outdated all the time and none of us will remember to update it often enough for it to be useful. Also IMO selecting a few downstreams isn't a good idea in upstream project. We really should be distro-agnostic and libosinfo should be buildable on any GNU/Linux distro. The idea here is to convey the message "We do care a lot about individual distros" but unless this list is a long one, we are actually saying "We only care of these distros". As I said before, I think we only need to define a time frame in upstream (i-e we guarantee we won't bump any dep to anything newer than X amount of time) and be done with it. No need to focus on any particular distros, just provide enough time for distros. In worse case, they'd have to cherry-pick fixes from newer version of software, which is what long-term support downstream typically imply anyway. > Signed-off-by: Daniel P. Berrange > --- > README | 65 + > 1 file changed, 53 insertions(+), 12 deletions(-) > > diff --git a/README b/README > index 3108e3c..3547089 100644 > --- a/README > +++ b/README > @@ -26,18 +26,59 @@ The latest official releases can be found at: > NB: at this time, libvirt-glib is *NOT* considered API/ABI stable. Future > releases may still include API/ABI incompatible changes. > > -Dependencies > - > - > -- Required: > - - glib-2.0 > - - gobject-2.0 > - - libxml-2.0 > - - libvirt > - > -- Optional: > - - gobject-introspection > - - Vala (build-time only) > +Dependencies / supported platforms > +== > + > +The libvirt-glib projects attempts to be moderately conservative > +about updating the minimum required versions of external package > +dependencies, to strike a balance between enabling use of new > +features while minimizing inconvenience for downstream developers > +on distro platforms with specific shipped version. > + > +There are commonly two classes of Linux distro - short lifetime > +(Fedora, Ubuntu non-LTS, etc) and extended lifetime (RHEL, CentOS, > +Debian, Ubuntu LTS). Based on this classification, the libvirt-glib > +project will generally aim to ensure build support for > + > + - Most recent 2 releases of short lifetime distros > + - Most recent major release of extended lifetime distros, > + with most recent 2 minor updates > + > +The project will consider RHEL, Fedora, Ubuntu LTS, Ubuntu, OpenSUSE > +and SUSE (SLES/SLED) distros to be a representative subset of distros > +when determining min required versions of external deps, as other distros > +of similar release vintage will typically have similar versions. In the > +case of Debian, the project may at times choose to require use of an > +update from the backports repository. > + > +As an example, as of July 1st 2015 this policy would imply that the > +following distros are officially targetted as buildable platforms: > + > + - RHEL: 7.1, 7.2 > + - Fedora: 21, 22 > + - Ubuntu LTS: 14.04 (Trusty) > + - Ubuntu: 14.10 (Utopic), 15.04 (Vivid) > + - Suse: 12.0 > + - OpenSUSE: 13.1, 13.2 > + - Debian: 8.0 (Jessie) > + > +At any time, it may be possible to build on versions of distros > +that are older than those implied by this policy, but the project > +will not guarantee this remains the case in future releases. The > +min required package versions of external dependancies may be > +raised in future releases based on this distro build target policy. > + > +The packages required to build libvirt-glib are > + > + - glib-2.0 > + - gobject-2.0 > + - libxml-2.0 > + - libvirt > + > +Functionality is optionally enhanced by the following packages: > + > + - gobject-introspection > + - Vala (build-time only) > > Patches sumissions > == > -- > 2.4.3 > > -- > libvir-list mailing list > libvir-list@redhat.com > https://www.redhat.com/mailman/listinfo/libvir-list -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib 0/4] gconfig: Leak fixes and small cleanup
On Wed, Jul 22, 2015 at 11:41 AM, Christophe Fergeau wrote: > Hey, > > On Fri, Jul 17, 2015 at 09:01:46AM +0200, Christophe Fergeau wrote: >> On Thu, Jul 09, 2015 at 10:13:16AM +0200, Christophe Fergeau wrote: >> > Hey, >> > >> > This patch series makes tests/test-gconfig valgrind-clean, and refactors >> > two >> > setters in GVirConfigDomainVideo to make them use the helpers provided by >> > GVirConfigObject. >> >> Ping? > > These missed the libvirt-glib release, it would be nice to get them > in... :) Sorry I had missed them somehow. ACK series. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH glib] Make use of DHCP API conditionally compiled
On Tue, Jul 21, 2015 at 4:09 PM, Daniel P. Berrange wrote: > On Tue, Jul 21, 2015 at 03:56:54PM +0100, Zeeshan Ali (Khattak) wrote: >> On Tue, Jul 21, 2015 at 3:20 PM, Daniel P. Berrange >> wrote: >> > Previously the use of virDomainOpenGraphicsFD API from libvirt >> > 1.2.8 was made to be conditionally compiled. Given this past >> > practice, make use of the virNetworkGetDHCPLeases API >> > conditional too, rather than requiring newer libvirt. >> > --- >> > configure.ac | 6 ++- >> > .../libvirt-gobject-network-dhcp-lease.c | 50 >> > ++ >> > libvirt-gobject/libvirt-gobject-network.c | 12 ++ >> > 3 files changed, 67 insertions(+), 1 deletion(-) >> > >> > diff --git a/configure.ac b/configure.ac >> > index 26beada..228788e 100644 >> > --- a/configure.ac >> > +++ b/configure.ac >> > @@ -9,7 +9,7 @@ AC_CANONICAL_HOST >> > >> > AM_SILENT_RULES([yes]) >> > >> > -LIBVIRT_REQUIRED=1.2.6 >> > +LIBVIRT_REQUIRED=0.10.2 >> > AC_SUBST([LIBVIRT_REQUIRED]) dnl used in the .spec file >> > GLIB2_REQUIRED=2.36.0 >> > AC_SUBST([GLIB2_REQUIRED]) dnl used in the .spec file >> > @@ -97,6 +97,10 @@ PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED) >> > AC_CHECK_LIB([virt], >> > [virDomainOpenGraphicsFD], >> > [AC_DEFINE([HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD], 1, [Have >> > virDomainOpenGraphicsFD?])]) >> > +# virNetworkGetDHCPLeases was introduced in libvirt 1.2.6 >> > +AC_CHECK_LIB([virt], >> > + [virNetworkGetDHCPLeases], >> > + [AC_DEFINE([HAVE_VIR_NETWORK_GET_DHCP_LEASES], 1, [Have >> > virNetworkGetDHCPLeases?])]) >> > enable_tests=no >> > PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_TEST_REQUIRED, >> >[enable_tests=yes], >> > diff --git a/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c >> > b/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c >> > index 6ac3c14..90a402b 100644 >> > --- a/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c >> > +++ b/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c >> > @@ -30,14 +30,20 @@ >> > #include "libvirt-glib/libvirt-glib.h" >> > #include "libvirt-gobject/libvirt-gobject.h" >> > #include "libvirt-gobject-compat.h" >> > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES >> > #include "libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h" >> > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ >> > >> > #define GVIR_NETWORK_DHCP_LEASE_GET_PRIVATE(obj) \ >> > (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK_DHCP_LEASE, >> > GVirNetworkDHCPLeasePrivate)) >> > >> > struct _GVirNetworkDHCPLeasePrivate >> > { >> > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES >> > virNetworkDHCPLeasePtr handle; >> > +#else >> > +void *handle; >> > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ >> > }; >> > >> > G_DEFINE_TYPE(GVirNetworkDHCPLease, gvir_network_dhcp_lease, >> > G_TYPE_OBJECT); >> > @@ -75,8 +81,10 @@ static void >> > gvir_network_dhcp_lease_set_property(GObject *object, >> > >> > switch (prop_id) { >> > case PROP_HANDLE: >> > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES >> > if (priv->handle) >> > virNetworkDHCPLeaseFree(priv->handle); >> > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ >> > priv->handle = g_value_get_pointer(value); >> > break; >> > >> > @@ -89,11 +97,15 @@ static void >> > gvir_network_dhcp_lease_set_property(GObject *object, >> > static void gvir_network_dhcp_lease_finalize(GObject *object) >> > { >> > GVirNetworkDHCPLease *lease = GVIR_NETWORK_DHCP_LEASE(object); >> > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES >> > GVirNetworkDHCPLeasePrivate *priv = lease->priv; >> > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ >> > >> > g_debug("Finalize GVirNetworkDHCPLease=%p", lease); >> >> Why not just move this debug below to avoid adding two #ifdef here? > > I want the debug message to be the first thing, so you see the > debug message in the case that the libvirt API call crashes the > program. > >> &
Re: [libvirt] [PATCH glib] Make use of DHCP API conditionally compiled
lease->priv->handle->iface; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return NULL; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -157,7 +175,11 @@ gint64 > gvir_network_dhcp_lease_get_expiry_time(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), -1); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->expirytime; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return -1; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -170,7 +192,11 @@ gint > gvir_network_dhcp_lease_get_ip_type(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), -1); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->type; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return -1; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -183,7 +209,11 @@ const gchar > *gvir_network_dhcp_lease_get_mac(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->mac; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return NULL; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -196,7 +226,11 @@ const gchar > *gvir_network_dhcp_lease_get_iaid(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->iaid; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return NULL; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -209,7 +243,11 @@ const gchar > *gvir_network_dhcp_lease_get_ip(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->ipaddr; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return NULL; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -222,7 +260,11 @@ guint > gvir_network_dhcp_lease_get_prefix(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), 0); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->prefix; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return 0; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -235,7 +277,11 @@ const gchar > *gvir_network_dhcp_lease_get_hostname(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->hostname; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return NULL; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > > /** > @@ -248,5 +294,9 @@ const gchar > *gvir_network_dhcp_lease_get_client_id(GVirNetworkDHCPLease *lease) > { > g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL); > > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > return lease->priv->handle->clientid; > +#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > +return NULL; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > } > diff --git a/libvirt-gobject/libvirt-gobject-network.c > b/libvirt-gobject/libvirt-gobject-network.c > index 45dbb71..a278105 100644 > --- a/libvirt-gobject/libvirt-gobject-network.c > +++ b/libvirt-gobject/libvirt-gobject-network.c > @@ -29,7 +29,9 @@ > #include "libvirt-glib/libvirt-glib.h" > #include "libvirt-gobject/libvirt-gobject.h" > #include "libvirt-gobject-compat.h" > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > #include "libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h" > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > > #define GVIR_NETWORK_GET_PRIVATE(obj) \ > (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, > GVirNetworkPrivate)) > @@ -249,14 +251,17 @@ GList *gvir_network_get_dhcp_leases(GVirNetwork > *network, > guint flags, > GError **err) > { > +#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES > virNetworkDHCPLeasePtr *leases; > GList *ret = NULL; > int num_leases, i; > +#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */ > > g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL); > g_return_val_if_fail(err == NULL ||
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Mon, Jul 20, 2015 at 6:32 PM, Christophe Fergeau wrote: > On Mon, Jul 20, 2015 at 05:24:30PM +0100, Zeeshan Ali (Khattak) wrote: >> And all that data is completely irrelevant for the reason I mentioned >> again and again. > > Now that we have the data, and that it goes your way, yes you can say > it's irrelevant ;) Not at all, I didn't even care to see if it goes "my way" or not. It's completely irrelevant and I'm getting tired of pointing out the very obvious reason why that is the case. > What if instead, it turned out only f22 was shipping a > new enough libvirt? I would have reverted your patch and added some > #ifdef. That would have been fine by me, as already explained. What it did boil down in the end to was you being way too caring about downstream than me and hence ugly solutions are acceptable to you. I really don't see us able to change each other's mind on that and hence the reason I wanted a vote rather in the first place to avoid this discussion. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Thu, Jul 16, 2015 at 10:11 AM, Christophe Fergeau wrote: > On Mon, Jul 13, 2015 at 02:45:21PM +0100, Zeeshan Ali (Khattak) wrote: >> On Fri, Jul 10, 2015 at 5:04 PM, Christophe Fergeau >> wrote: >> > Patches of yours broke the build, you have a strong opinion on the right >> > way >> > to fix it, in such situations I usually go the extra mile to >> > convince others that it's the best way :) That's why I'm a bit surprised >> > this drags for so long with no real attempt at finding some common >> > ground. >> >> I gave you an easy way out of this dragging discussion and even >> promised to implement either of the solutions you want me to. You're >> still not happy so I'll just bump the dependencies now. Feel free to >> implement ugly hack solution. I'm out here.. > > Thanks a lot for pushing an unreviewed patch after not wanting to go > through proper patch discussion (ie do a bit of research in order to > address the concerns which were raised rather than making up excuses for > not doing it), that's appreciated! I did address all your arguments and you still insist I did not. I have no idea how I can possibly fix that. FWIW, the patch I pushed only fixes a bug: libvirt-glib was requiring a version of libvirt that it wasn't checking for in configure stage. > After 10 minutes looking around, Ubuntu 14.04 LTS has libvirt 1.2.2 and > SLES 12 has 1.2.5, both have long support cycles and a too old libvirt. > Apart from these, supported Fedoras, latest Debian stable, opensuse 13.2 > and EL7.1 all have new enough libvirt. > With this data in mind, and unless people from the impacted distros > speak up, raising the requirement is probably reasonable enough. And all that data is completely irrelevant for the reason I mentioned again and again. Please point to at least one actual example of any distro wanting to upgrade libvirt-glib to latest while wanting to keep an year old release of libvirt and you'll have a point. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Fri, Jul 10, 2015 at 5:04 PM, Christophe Fergeau wrote: > On Fri, Jul 10, 2015 at 04:43:15PM +0100, Zeeshan Ali (Khattak) wrote: >> >> I really don't see the point of evaluating possible but unlinkely[1] >> impact on any distro. As I said, we give distros enough time and that >> should be more than enough upstream could do. i-e these exact details >> are irrelevant to me. Since they are very relevant to you, I'd suggest >> you do the research and then let me know which solution you want and I >> will implement that. > > Patches of yours broke the build, you have a strong opinion on the right way > to fix it, in such situations I usually go the extra mile to > convince others that it's the best way :) That's why I'm a bit surprised > this drags for so long with no real attempt at finding some common > ground. I gave you an easy way out of this dragging discussion and even promised to implement either of the solutions you want me to. You're still not happy so I'll just bump the dependencies now. Feel free to implement ugly hack solution. I'm out here.. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Thu, Jul 9, 2015 at 3:01 PM, Christophe Fergeau wrote: > On Thu, Jul 09, 2015 at 02:41:45PM +0100, Zeeshan Ali (Khattak) wrote: >> The answer was that magnitude of ugliness is irrelevant. Surely you >> know that this is not anything objective. To me a single #ifdef is >> ugly enough but seems it's not for you so how do you expect either of >> us to convince each other with arguments? If you really need something >> more concrete, I see at least 12 #ifdefs needed. Pretty ugly for my >> taste at least. > > I'm just trying to have a discussion about something concrete. If just > one #ifdef was needed, I guess you'll bear with me if I try to convince > you to go this way, with 12 #ifdef, you've got a more understandable > standing in opposing this. > >> >> > Quite >> > hard to make a decision with so few details ;) >> >> All needed "details" are avaiable and it's only a matter of taste and >> amount of care we want to give to distros. Both are subjective >> matters. > > Same deal as with the amount of #ifdef needed, if only EL6 has a too old > libvirt, then you are in a much better position to convince me than if > Debian stable and latest Ubuntu (making things up) have a too old > libvirt. > Ie let's know the exact tradeoffs we are discussing here from a > technical point of view, maybe we won't have to agree to disagree and > look for a tie breaker ;) I really don't see the point of evaluating possible but unlinkely[1] impact on any distro. As I said, we give distros enough time and that should be more than enough upstream could do. i-e these exact details are irrelevant to me. Since they are very relevant to you, I'd suggest you do the research and then let me know which solution you want and I will implement that. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ [1] As I already mentioned already, it's very unlikely that any distro would want to upgrade Boxes and libvirt-glib to latest version but not want to update to even an year older libvirt. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Thu, Jul 9, 2015 at 12:56 PM, Christophe Fergeau wrote: > On Thu, Jul 09, 2015 at 12:42:23PM +0100, Zeeshan Ali (Khattak) wrote: >> > Honestly, this is a very weird attitude, rather than trying to >> > come with hard facts, you prefer having some kind of poll and make an >> > arbitary uninformed decision. >> >> I regret having to resort to some sort of poll as well but this is not >> a purely objective discussion. I did present arguments but you >> maintain that I did not. So let's leave at that, shall we? > > Unless I missed important things, your arguments boiled down to "one > year is old enough, we should not care about distros". It's very hard to discuss if you over-exagerate my opinions to make them sound bad. I'm did not say we should not care about distros but rather that 1 year is plenty of care. > I've asked what > the impact would be on distros, no answer so far. The answer was that 1 year of grace time is enough and we shouldn't need to be bound by release cycles and packaging of individual distros. Also I pointed out the fact that it does not (in practical terms) make any sense to only upgrade to latest libvirt-glib but wanting to stay with an year old libvirt. > I've asked what the > impact would be in terms of #ifdef ugliness, no answer so far. The answer was that magnitude of ugliness is irrelevant. Surely you know that this is not anything objective. To me a single #ifdef is ugly enough but seems it's not for you so how do you expect either of us to convince each other with arguments? If you really need something more concrete, I see at least 12 #ifdefs needed. Pretty ugly for my taste at least. > Quite > hard to make a decision with so few details ;) All needed "details" are avaiable and it's only a matter of taste and amount of care we want to give to distros. Both are subjective matters. >> I'll just proceed as Dan tell me to. It's his project in the end. > > danpb is away for a while as I understand it, and my feeling is that we > could resolve this on our own if you were at least trying to give more > details about the various alternatives. I don't know many alternatives. It's either bumping the dep or adding ugly #ifdef based solution. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Thu, Jul 9, 2015 at 8:05 AM, Christophe Fergeau wrote: > On Wed, Jul 08, 2015 at 07:00:36PM +0100, Zeeshan Ali (Khattak) wrote: >> On Wed, Jul 8, 2015 at 3:42 PM, Christophe Fergeau >> wrote: >> > but you haven't brought >> > anything forward to support that "ugly hack" statement in this specific >> > case, >> >> #ifdef based solution is going to be ugly, surely you know that. I >> never made any claims about the magnitude of ugliness, I always want >> to avoid ugly hacks whenever possible. > > If it just requires 2 or 3 #ifdef, adding them and forgetting they > existed would have been faster than this thread ;) I agree but I want to clarify how we intend to proceed about this in future. I'm fine with 2 or 3 but with this kind of extremely strict definition of "too new libvirt dep", we'd need to keep on doing this and before you know it, we'll have lots of these ugly hacks. >> > nor any hard data regarding which distros could be impacted by a >> > req bump. I'll stop this discussion until you bring some concrete >> > datapoints to the table. >> >> Fair enough! The main point of this discussion was not to convince you >> but rather to get a third opinion. > > Honestly, this is a very weird attitude, rather than trying to > come with hard facts, you prefer having some kind of poll and make an > arbitary uninformed decision. I regret having to resort to some sort of poll as well but this is not a purely objective discussion. I did present arguments but you maintain that I did not. So let's leave at that, shall we? I'll just proceed as Dan tell me to. It's his project in the end. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Wed, Jul 8, 2015 at 3:42 PM, Christophe Fergeau wrote: > On Wed, Jul 08, 2015 at 03:37:43PM +0100, Zeeshan Ali (Khattak) wrote: >> >> Also keeping in mind that it makes very little >> >> sense to upgrade libvirt-glib and not libvirt since libvirt doesn't >> >> break any ABI/API. >> > >> > Generally speaking, there could be security issues, critical bugs in >> > Boxes which require a libvirt-glib update to be fixed, >> >> That is why we roll out bug fix releases to stable releases and try >> our best not to bump any deps while doing so. > > So far, we haven't done that for libvirt-glib, just incremental releases > with bugfixes and new features... Only because we never really needed to. >> > ... where >> > upgrading just libvirt-glib would be much more convenient than upgrading >> > the whole stack. So all in all, this is just a tradeoff to make between >> > making our life easier, and (potentially) making distributions life easier. >> >> Surely we need to meet somewhere in between. If Ubuntu or Debian would >> for example not upgrade their libvirt for many years to come, would we >> keep wasting our time on adding ugly hacks upstream for them? > > So far, you keep saying "let's bump the req!", I'm sorry if that is all you read in my emails, cause I've been trying my best to have a rational discussion here. > but you haven't brought > anything forward to support that "ugly hack" statement in this specific > case, #ifdef based solution is going to be ugly, surely you know that. I never made any claims about the magnitude of ugliness, I always want to avoid ugly hacks whenever possible. > nor any hard data regarding which distros could be impacted by a > req bump. I'll stop this discussion until you bring some concrete > datapoints to the table. Fair enough! The main point of this discussion was not to convince you but rather to get a third opinion. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Wed, Jul 8, 2015 at 2:27 PM, Christophe Fergeau wrote: > On Wed, Jul 08, 2015 at 01:13:09PM +0100, Zeeshan Ali (Khattak) wrote: >> On Wed, Jul 8, 2015 at 11:11 AM, Christophe Fergeau >> wrote: >> > On Tue, Jul 07, 2015 at 05:27:39PM +0100, Zeeshan Ali (Khattak) wrote: >> >> Hi all, >> >> >> >> Christophe pointed out that this and the previous patch binds API that >> >> was added an year ago: >> >> >> >> commit: 03e0e79e07622496522609741734c2fdcacb5bf2 >> >> Author: Nehal J Wani >> >> Date: Tue Jun 24 02:31:49 2014 +0530 >> >> >> >> net-dhcp-leases: Implement the public APIs >> >> >> >> Introduce 3 new APIs, virNetworkGetDHCPLeases, >> >> virNetworkGetDHCPLeasesForMAC >> >> and virNetworkDHCPLeaseFree. >> >> --- >> >> >> >> While I think 1 year old is pretty old enough to justify bumping the >> >> dep to that version, Christophe thinks its still too soon. I'd hate to >> >> go through the trouble of adding ugly #ifdef around these new API but >> >> if others (I guess mainly Dan?) agree with Christophe, I can do that. >> > >> > 1 year being old/not old is not a very useful/convincing argument. What >> > is more interesting is what (supported) distros are shipping (f21, el7, >> > oldest ubuntu LTS shipping libvirt-glib, debian, ...). >> >> For the record, I don't think upstream development should depend on >> when distros decided to upgrade packages and their release cycles. > > Ok, I'll call you next time I need to get something newish to work with > the RHEL6 glib ;) glib is much lower level and libvirt-glib isn't about binding it so its very different case. >> Also keeping in mind that it makes very little >> sense to upgrade libvirt-glib and not libvirt since libvirt doesn't >> break any ABI/API. > > Generally speaking, there could be security issues, critical bugs in > Boxes which require a libvirt-glib update to be fixed, That is why we roll out bug fix releases to stable releases and try our best not to bump any deps while doing so. If there is a bug fix in a newer release thats not made available for an older release, distros are extremely unlikely to simply upgrade to latest release but rather back port those fixes since new release would also bring along new features (and therefore bugs). > ... where > upgrading just libvirt-glib would be much more convenient than upgrading > the whole stack. So all in all, this is just a tradeoff to make between > making our life easier, and (potentially) making distributions life easier. Surely we need to meet somewhere in between. If Ubuntu or Debian would for example not upgrade their libvirt for many years to come, would we keep wasting our time on adding ugly hacks upstream for them? -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Wed, Jul 8, 2015 at 11:11 AM, Christophe Fergeau wrote: > On Tue, Jul 07, 2015 at 05:27:39PM +0100, Zeeshan Ali (Khattak) wrote: >> Hi all, >> >> Christophe pointed out that this and the previous patch binds API that >> was added an year ago: >> >> commit: 03e0e79e07622496522609741734c2fdcacb5bf2 >> Author: Nehal J Wani >> Date: Tue Jun 24 02:31:49 2014 +0530 >> >> net-dhcp-leases: Implement the public APIs >> >> Introduce 3 new APIs, virNetworkGetDHCPLeases, >> virNetworkGetDHCPLeasesForMAC >> and virNetworkDHCPLeaseFree. >> --- >> >> While I think 1 year old is pretty old enough to justify bumping the >> dep to that version, Christophe thinks its still too soon. I'd hate to >> go through the trouble of adding ugly #ifdef around these new API but >> if others (I guess mainly Dan?) agree with Christophe, I can do that. > > 1 year being old/not old is not a very useful/convincing argument. What > is more interesting is what (supported) distros are shipping (f21, el7, > oldest ubuntu LTS shipping libvirt-glib, debian, ...). For the record, I don't think upstream development should depend on when distros decided to upgrade packages and their release cycles. The important thing is for us to give them enough time and IMO 1 year is plenty of time. Also keeping in mind that it makes very little sense to upgrade libvirt-glib and not libvirt since libvirt doesn't break any ABI/API. > I'd tend to favour #ifdefs though unless this gets very invasive/ugly ;) Well we don't agree and that's why I brought it up here. :) -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
Hi all, Christophe pointed out that this and the previous patch binds API that was added an year ago: commit: 03e0e79e07622496522609741734c2fdcacb5bf2 Author: Nehal J Wani Date: Tue Jun 24 02:31:49 2014 +0530 net-dhcp-leases: Implement the public APIs Introduce 3 new APIs, virNetworkGetDHCPLeases, virNetworkGetDHCPLeasesForMAC and virNetworkDHCPLeaseFree. --- While I think 1 year old is pretty old enough to justify bumping the dep to that version, Christophe thinks its still too soon. I'd hate to go through the trouble of adding ugly #ifdef around these new API but if others (I guess mainly Dan?) agree with Christophe, I can do that. On Tue, Jul 7, 2015 at 4:26 PM, Zeeshan Ali (Khattak) wrote: > On Tue, Jul 7, 2015 at 3:17 PM, Zeeshan Ali (Khattak) > wrote: >> --- >> libvirt-gobject/libvirt-gobject-network.c | 55 >> +++ >> libvirt-gobject/libvirt-gobject-network.h | 4 +++ >> libvirt-gobject/libvirt-gobject.sym | 2 ++ >> 3 files changed, 61 insertions(+) >> >> diff --git a/libvirt-gobject/libvirt-gobject-network.c >> b/libvirt-gobject/libvirt-gobject-network.c >> index b1b38a0..2a7bed6 100644 >> --- a/libvirt-gobject/libvirt-gobject-network.c >> +++ b/libvirt-gobject/libvirt-gobject-network.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-network-dhcp-lease-private.h" >> >> #define GVIR_NETWORK_GET_PRIVATE(obj) \ >> (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, >> GVirNetworkPrivate)) >> @@ -224,3 +225,57 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork >> *network, >> free(xml); >> return conf; >> } >> + >> +/** >> + * gvir_network_get_dhcp_leases: >> + * @network: the network >> + * @mac: (allow-none): The optional ASCII formatted MAC address of an >> interface >> + * @flags: placeholder for flags, must be 0 >> + * >> + * @err: Place-holder for possible errors >> + * >> + * This function fetches leases info of guests in the specified network. If >> the >> + * optional parameter @mac is specified, the returned list will contain only >> + * lease info about a specific guest interface with @mac. There can be >> multiple >> + * leases for a single @mac because this API supports DHCPv6 too. >> + * >> + * Returns: (element-type LibvirtGObject.NetworkDHCPLease) (transfer >> full): the >> + * list of network leases. Each object in the returned list should be >> unreffed >> + * with g_object_unref() and the list itself using g_list_free, when no >> longer >> + * needed. >> + */ >> +GList *gvir_network_get_dhcp_leases(GVirNetwork *network, >> +const char* mac, >> +guint flags, >> + GError **err) >> +{ >> +virNetworkDHCPLeasePtr *leases; >> +GList *ret = NULL; >> +int num_leases, i; >> + >> +g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL); >> +g_return_val_if_fail(err == NULL || *err == NULL, NULL); >> +g_return_val_if_fail(flags != 0, NULL); > > Oh, this should be flags == 0. I'll fix before pushing. > > -- > Regards, > > Zeeshan Ali (Khattak) > > Befriend GNOME: http://www.gnome.org/friends/ -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Tue, Jul 7, 2015 at 3:17 PM, Zeeshan Ali (Khattak) wrote: > --- > libvirt-gobject/libvirt-gobject-network.c | 55 > +++ > libvirt-gobject/libvirt-gobject-network.h | 4 +++ > libvirt-gobject/libvirt-gobject.sym | 2 ++ > 3 files changed, 61 insertions(+) > > diff --git a/libvirt-gobject/libvirt-gobject-network.c > b/libvirt-gobject/libvirt-gobject-network.c > index b1b38a0..2a7bed6 100644 > --- a/libvirt-gobject/libvirt-gobject-network.c > +++ b/libvirt-gobject/libvirt-gobject-network.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-network-dhcp-lease-private.h" > > #define GVIR_NETWORK_GET_PRIVATE(obj) \ > (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, > GVirNetworkPrivate)) > @@ -224,3 +225,57 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork > *network, > free(xml); > return conf; > } > + > +/** > + * gvir_network_get_dhcp_leases: > + * @network: the network > + * @mac: (allow-none): The optional ASCII formatted MAC address of an > interface > + * @flags: placeholder for flags, must be 0 > + * > + * @err: Place-holder for possible errors > + * > + * This function fetches leases info of guests in the specified network. If > the > + * optional parameter @mac is specified, the returned list will contain only > + * lease info about a specific guest interface with @mac. There can be > multiple > + * leases for a single @mac because this API supports DHCPv6 too. > + * > + * Returns: (element-type LibvirtGObject.NetworkDHCPLease) (transfer full): > the > + * list of network leases. Each object in the returned list should be > unreffed > + * with g_object_unref() and the list itself using g_list_free, when no > longer > + * needed. > + */ > +GList *gvir_network_get_dhcp_leases(GVirNetwork *network, > +const char* mac, > +guint flags, > +GError **err) > +{ > +virNetworkDHCPLeasePtr *leases; > +GList *ret = NULL; > +int num_leases, i; > + > +g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL); > +g_return_val_if_fail(err == NULL || *err == NULL, NULL); > +g_return_val_if_fail(flags != 0, NULL); Oh, this should be flags == 0. I'll fix before pushing. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib PATCHv5 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
--- libvirt-gobject/libvirt-gobject-network.c | 55 +++ libvirt-gobject/libvirt-gobject-network.h | 4 +++ libvirt-gobject/libvirt-gobject.sym | 2 ++ 3 files changed, 61 insertions(+) diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c index b1b38a0..2a7bed6 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.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-network-dhcp-lease-private.h" #define GVIR_NETWORK_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, GVirNetworkPrivate)) @@ -224,3 +225,57 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, free(xml); return conf; } + +/** + * gvir_network_get_dhcp_leases: + * @network: the network + * @mac: (allow-none): The optional ASCII formatted MAC address of an interface + * @flags: placeholder for flags, must be 0 + * + * @err: Place-holder for possible errors + * + * This function fetches leases info of guests in the specified network. If the + * optional parameter @mac is specified, the returned list will contain only + * lease info about a specific guest interface with @mac. There can be multiple + * leases for a single @mac because this API supports DHCPv6 too. + * + * Returns: (element-type LibvirtGObject.NetworkDHCPLease) (transfer full): the + * list of network leases. Each object in the returned list should be unreffed + * with g_object_unref() and the list itself using g_list_free, when no longer + * needed. + */ +GList *gvir_network_get_dhcp_leases(GVirNetwork *network, +const char* mac, +guint flags, +GError **err) +{ +virNetworkDHCPLeasePtr *leases; +GList *ret = NULL; +int num_leases, i; + +g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL); +g_return_val_if_fail(err == NULL || *err == NULL, NULL); +g_return_val_if_fail(flags != 0, NULL); + +num_leases = virNetworkGetDHCPLeases(network->priv->handle, mac, &leases, flags); +if (num_leases < 0) { +gvir_set_error_literal(err, GVIR_NETWORK_ERROR, + 0, + "Unable to get network DHCP leases"); +return NULL; +} + +if (num_leases == 0) +return NULL; + +for (i = 0; i < num_leases; i++) { +GVirNetworkDHCPLease *lease; + +lease = gvir_network_dhcp_lease_new(leases[i]); +ret = g_list_prepend(ret, lease); +} +ret = g_list_reverse(ret); +free(leases); + +return ret; +} diff --git a/libvirt-gobject/libvirt-gobject-network.h b/libvirt-gobject/libvirt-gobject-network.h index 9f746c0..5617ed6 100644 --- a/libvirt-gobject/libvirt-gobject-network.h +++ b/libvirt-gobject/libvirt-gobject-network.h @@ -71,6 +71,10 @@ const gchar *gvir_network_get_uuid(GVirNetwork *network); GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, guint flags, GError **err); +GList *gvir_network_get_dhcp_leases(GVirNetwork *network, +const char* mac, +guint flags, +GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index dfd858a..ca89a45 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -300,6 +300,8 @@ LIBVIRT_GOBJECT_0.2.2 { gvir_network_dhcp_lease_get_mac; gvir_network_dhcp_lease_get_prefix; gvir_network_dhcp_lease_get_type; + + gvir_network_get_dhcp_leases; } LIBVIRT_GOBJECT_0.2.1; # define new API here using predicted next version number -- 2.4.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib PATCHv5 6/7] gobject: Add wrapper for virNetworkDHCPLease
--- libvirt-gobject/Makefile.am| 5 +- .../libvirt-gobject-network-dhcp-lease-private.h | 34 +++ .../libvirt-gobject-network-dhcp-lease.c | 252 + .../libvirt-gobject-network-dhcp-lease.h | 85 +++ libvirt-gobject/libvirt-gobject.h | 1 + libvirt-gobject/libvirt-gobject.sym| 13 ++ 6 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h create mode 100644 libvirt-gobject/libvirt-gobject-network-dhcp-lease.c create mode 100644 libvirt-gobject/libvirt-gobject-network-dhcp-lease.h diff --git a/libvirt-gobject/Makefile.am b/libvirt-gobject/Makefile.am index 7163c7d..8464f04 100644 --- a/libvirt-gobject/Makefile.am +++ b/libvirt-gobject/Makefile.am @@ -13,6 +13,7 @@ GOBJECT_HEADER_FILES = \ libvirt-gobject-domain.h \ libvirt-gobject-interface.h \ libvirt-gobject-network.h \ + libvirt-gobject-network-dhcp-lease.h \ libvirt-gobject-network-filter.h \ libvirt-gobject-node-device.h \ libvirt-gobject-secret.h \ @@ -22,7 +23,8 @@ GOBJECT_HEADER_FILES = \ libvirt-gobject-connection.h \ libvirt-gobject-manager.h noinst_HEADERS = \ - libvirt-gobject-storage-pool-private.h + libvirt-gobject-storage-pool-private.h \ + libvirt-gobject-network-dhcp-lease-private.h GOBJECT_SOURCE_FILES = \ libvirt-gobject-main.c \ libvirt-gobject-domain-snapshot.c \ @@ -32,6 +34,7 @@ GOBJECT_SOURCE_FILES = \ libvirt-gobject-domain.c \ libvirt-gobject-interface.c \ libvirt-gobject-network.c \ + libvirt-gobject-network-dhcp-lease.c \ libvirt-gobject-network-filter.c \ libvirt-gobject-node-device.c \ libvirt-gobject-secret.c \ diff --git a/libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h b/libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h new file mode 100644 index 000..eaf6c2f --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h @@ -0,0 +1,34 @@ +/* + * libvirt-gobject-network-dhcp-lease-private.h: libvirt gobject integration + * + * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2015 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Daniel P. Berrange + */ + +#ifndef __LIBVIRT_GOBJECT_NETWORK_DHCP_LEASE_PRIVATE_H__ +#define __LIBVIRT_GOBJECT_NETWORK_DHCP_LEASE_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirNetworkDHCPLease *gvir_network_dhcp_lease_new(virNetworkDHCPLeasePtr handle); + +G_END_DECLS + +#endif /* __LIBVIRT_GOBJECT_NETWORK_DHCP_LEASE_PRIVATE_H__ */ diff --git a/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c b/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c new file mode 100644 index 000..6ac3c14 --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c @@ -0,0 +1,252 @@ +/* + * libvirt-gobject-network-dhcp-lease.c: libvirt glib integration + * + * Copyright (C) 2008 Daniel P. Berrange + * Copyright (C) 2015 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: Zeeshan Ali (Khattak) + * Daniel P. Berrange + */ + +#include + +#include +#include + +#include "libvirt-glib/libvirt-glib.h" +#in
[libvirt] [libvirt-glib PATCHv5 1/7] gobject: Simplify gvir_connection_list*() implementations
Make use of virConnectListAll* functions to avoid making 4 calls and hence avoid race conditions and complicated code. --- libvirt-gobject/libvirt-gobject-connection.c | 203 --- 1 file changed, 28 insertions(+), 175 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index cf073a5..e088427 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -680,48 +680,6 @@ void gvir_connection_close(GVirConnection *conn) g_signal_emit(conn, signals[VIR_CONNECTION_CLOSED], 0); } -typedef gint (* CountFunction) (virConnectPtr vconn); -typedef gint (* ListFunction) (virConnectPtr vconn, gchar **lst, gint max); - -static gchar ** fetch_list(virConnectPtr vconn, - const char *name, - CountFunction count_func, - ListFunction list_func, - GCancellable *cancellable, - gint *length, - GError **err) -{ -gchar **lst = NULL; -gint n = 0; - -if ((n = count_func(vconn)) < 0) { -gvir_set_error(err, GVIR_CONNECTION_ERROR, - 0, - _("Unable to count %s"), name); -goto error; -} - -if (n) { -if (g_cancellable_set_error_if_cancelled(cancellable, err)) -goto error; - -lst = g_new0(gchar *, n); -if ((n = list_func(vconn, lst, n)) < 0) { -gvir_set_error(err, GVIR_CONNECTION_ERROR, - 0, - _("Unable to list %s %d"), name, n); -goto error; -} -} - -*length = n; -return lst; - -error: -g_free(lst); -return NULL; -} - /** * gvir_connection_fetch_domains: * @conn: a #GVirConnection @@ -733,14 +691,11 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn, { GVirConnectionPrivate *priv; GHashTable *doms; -gchar **inactive = NULL; -gint ninactive = 0; -gint *active = NULL; -gint nactive = 0; +virDomainPtr *domains = NULL; +gint ndomains = 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), @@ -761,81 +716,28 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn, virConnectRef(vconn); g_mutex_unlock(priv->lock); -if (g_cancellable_set_error_if_cancelled(cancellable, err)) -goto cleanup; - -if ((nactive = virConnectNumOfDomains(vconn)) < 0) { -gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, - 0, - _("Unable to count domains")); +ndomains = virConnectListAllDomains(vconn, &domains, 0); +if (ndomains < 0) { +gvir_set_error(err, GVIR_CONNECTION_ERROR, + 0, + _("Failed to fetch list of domains")); goto cleanup; } -if (nactive) { -if (g_cancellable_set_error_if_cancelled(cancellable, err)) -goto cleanup; - -active = g_new(gint, nactive); -if ((nactive = virConnectListDomains(vconn, active, nactive)) < 0) { -gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, - 0, - _("Unable to list domains")); -goto cleanup; -} -} if (g_cancellable_set_error_if_cancelled(cancellable, err)) goto cleanup; -inactive = fetch_list(vconn, - "Domains", - virConnectNumOfDefinedDomains, - virConnectListDefinedDomains, - cancellable, - &ninactive, - &lerr); -if (lerr) { -g_propagate_error(err, lerr); -lerr = NULL; -goto cleanup; -} - doms = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref); -for (i = 0 ; i < nactive ; i++) { -if (g_cancellable_set_error_if_cancelled(cancellable, err)) -goto cleanup; - -virDomainPtr vdom = virDomainLookupByID(vconn, active[i]); +for (i = 0 ; i < ndomains; i++) { GVirDomain *dom; -if (!vdom) -continue; dom = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN, - "handle", vdom, + "handle", domains[i], NULL)); -virDomainFree(vdom); - -g_hash_table_insert(doms, -(gpointer)gvir_domain_get_uuid(dom), -
[libvirt] [libvirt-glib PATCHv5 3/7] gobject: Port GVirConnection to GTask
GSimpleAsyncResult has been deprecated in favour of GTask and with latest glib headers, we get tons of warnings about use of deprecated API. This patch ports the GVirConnection class to GTask. --- libvirt-gobject/libvirt-gobject-connection.c | 280 +-- 1 file changed, 136 insertions(+), 144 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 02eef7b..5b3a7bc 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -497,17 +497,18 @@ gboolean gvir_connection_open_read_only(GVirConnection *conn, } static void -gvir_connection_open_helper(GSimpleAsyncResult *res, -GObject *object, +gvir_connection_open_helper(GTask *task, +gpointer object, +gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable) { GVirConnection *conn = GVIR_CONNECTION(object); GError *err = NULL; -if (!gvir_connection_open(conn, cancellable, &err)) { -g_simple_async_result_set_from_error(res, err); -g_error_free(err); -} +if (!gvir_connection_open(conn, cancellable, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } @@ -523,20 +524,20 @@ void gvir_connection_open_async(GVirConnection *conn, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_CONNECTION(conn)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -res = g_simple_async_result_new(G_OBJECT(conn), -callback, -user_data, -gvir_connection_open_async); -g_simple_async_result_run_in_thread(res, -gvir_connection_open_helper, -G_PRIORITY_DEFAULT, -cancellable); -g_object_unref(res); +task = g_task_new(G_OBJECT(conn), + cancellable, + callback, + user_data); +g_task_set_source_tag(task, + gvir_connection_open_async); +g_task_run_in_thread(task, + gvir_connection_open_helper); +g_object_unref(task); } @@ -550,28 +551,28 @@ gboolean gvir_connection_open_finish(GVirConnection *conn, GError **err) { g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE); -g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn), - gvir_connection_open_async), +g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(conn)), + FALSE); +g_return_val_if_fail(g_task_get_source_tag(G_TASK(result)) == + gvir_connection_open_async, FALSE); -if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) -return FALSE; - -return TRUE; +return g_task_propagate_boolean(G_TASK(result), err); } static void -gvir_connection_open_read_only_helper(GSimpleAsyncResult *res, -GObject *object, -GCancellable *cancellable) +gvir_connection_open_read_only_helper(GTask *task, + gpointer object, + gpointer task_data G_GNUC_UNUSED, + GCancellable *cancellable) { GVirConnection *conn = GVIR_CONNECTION(object); GError *err = NULL; -if (!gvir_connection_open_read_only(conn, cancellable, &err)) { -g_simple_async_result_set_from_error(res, err); -g_error_free(err); -} +if (!gvir_connection_open_read_only(conn, cancellable, &err)) +g_task_return_error(task, err); +else +g_task_return_boolean(task, TRUE); } @@ -587,20 +588,20 @@ void gvir_connection_open_read_only_async(GVirConnection *conn, GAsyncReadyCallback callback, gpointer user_data) { -GSimpleAsyncResult *res; +GTask *task; g_return_if_fail(GVIR_IS_CONNECTION(conn)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); -res = g_simple_async_result_new(G_OBJECT(conn), -callback, -user_data, -gvir_connection_open_read_only_async); -g_simple_async_result_run_in_thread(res, -gvir_connection_open_read_only_helper, -
[libvirt] [libvirt-glib PATCHv5 4/7] gobject: Add API to query connection interfaces
Add API to query network interfaces from a connection. --- libvirt-gobject/libvirt-gobject-connection.c | 270 +++ libvirt-gobject/libvirt-gobject-connection.h | 13 +- libvirt-gobject/libvirt-gobject.sym | 7 + 3 files changed, 288 insertions(+), 2 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 5b3a7bc..7d28178 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -44,6 +44,7 @@ struct _GVirConnectionPrivate GHashTable *domains; GHashTable *pools; +GHashTable *interfaces; }; G_DEFINE_TYPE(GVirConnection, gvir_connection, G_TYPE_OBJECT); @@ -252,6 +253,10 @@ static void gvir_connection_init(GVirConnection *conn) g_str_equal, NULL, g_object_unref); +priv->interfaces = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); } @@ -668,6 +673,11 @@ void gvir_connection_close(GVirConnection *conn) priv->pools = NULL; } +if (priv->interfaces) { +g_hash_table_unref(priv->interfaces); +priv->interfaces = NULL; +} + if (priv->conn) { virConnectDomainEventDeregister(priv->conn, domain_event_cb); virConnectClose(priv->conn); @@ -1443,6 +1453,266 @@ GVirDomain *gvir_connection_start_domain(GVirConnection *conn, } /** + * gvir_connection_fetch_interfaces: + * @conn: a #GVirConnection + * @cancellable: (allow-none)(transfer none): cancellation object + * @err: return location for any errors + * + * Use this method to fetch information on all network interfaces + * managed by connection @conn on host machine. Use + * #gvir_connection_get_interfaces or #gvir_connection_get_interface afterwards + * to query the fetched interfaces. + * + * Return value: %TRUE on success, %FALSE otherwise and @err is set. + */ +gboolean gvir_connection_fetch_interfaces(GVirConnection *conn, + GCancellable *cancellable, + GError **err) +{ +GVirConnectionPrivate *priv; +GHashTable *interfaces; +virInterfacePtr *ifaces = NULL; +gint ninterfaces = 0; +gboolean ret = FALSE; +gint i; +virConnectPtr vconn = 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; + +ninterfaces = virConnectListAllInterfaces(vconn, &ifaces, 0); +if (ninterfaces < 0) { +gvir_set_error(err, GVIR_CONNECTION_ERROR, + 0, + _("Failed to fetch list of interfaces")); +goto cleanup; +} + +if (g_cancellable_set_error_if_cancelled(cancellable, err)) +goto cleanup; + +interfaces = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); + +for (i = 0 ; i < ninterfaces; i++) { +GVirInterface *iface; + +if (g_cancellable_set_error_if_cancelled(cancellable, err)) +goto cleanup; + +iface = GVIR_INTERFACE(g_object_new(GVIR_TYPE_INTERFACE, +"handle", ifaces[i], +NULL)); + +g_hash_table_insert(interfaces, +(gpointer)gvir_interface_get_name(iface), +iface); +} + +g_mutex_lock(priv->lock); +if (priv->interfaces) +g_hash_table_unref(priv->interfaces); +priv->interfaces = interfaces; +g_mutex_unlock(priv->lock); + +ret = TRUE; + +cleanup: +if (ninterfaces > 0) { +for (i = 0 ; i < ninterfaces; i++) +virInterfaceFree(ifaces[i]); +free(ifaces); +} +if (vconn != NULL) +virConnectClose(vconn); +return ret; +} + +static void +gvir_connection_fetch_interfaces_helper(GTask *task, +gpointer object, +
[libvirt] [libvirt-glib PATCHv5 2/7] gobject: Plug 2 virConnect leaks
A virConnect reference is leaked in error cases. This patch moves the unref after the label we jump to on errors, to avoid this leak. --- libvirt-gobject/libvirt-gobject-connection.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index e088427..02eef7b 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -748,7 +748,6 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn, if (priv->domains) g_hash_table_unref(priv->domains); priv->domains = doms; -virConnectClose(vconn); g_mutex_unlock(priv->lock); ret = TRUE; @@ -759,6 +758,8 @@ cleanup: virDomainFree(domains[i]); free(domains); } +if (vconn != NULL) +virConnectClose(vconn); return ret; } @@ -835,7 +836,6 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn, if (priv->pools) g_hash_table_unref(priv->pools); priv->pools = pools; -virConnectClose(vconn); g_mutex_unlock(priv->lock); ret = TRUE; @@ -846,6 +846,8 @@ cleanup: virStoragePoolFree(vpools[i]); free(vpools); } +if (vconn != NULL) +virConnectClose(vconn); return ret; } -- 2.4.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib PATCHv5 5/7] gobject: Add API to query connection networks
Add API to query networks from a connection. --- libvirt-gobject/libvirt-gobject-connection.c | 262 +++ libvirt-gobject/libvirt-gobject-connection.h | 13 +- libvirt-gobject/libvirt-gobject.sym | 6 + 3 files changed, 279 insertions(+), 2 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 7d28178..9e7bb68 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -45,6 +45,7 @@ struct _GVirConnectionPrivate GHashTable *domains; GHashTable *pools; GHashTable *interfaces; +GHashTable *networks; }; G_DEFINE_TYPE(GVirConnection, gvir_connection, G_TYPE_OBJECT); @@ -257,6 +258,10 @@ static void gvir_connection_init(GVirConnection *conn) g_str_equal, NULL, g_object_unref); +priv->networks = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); } @@ -678,6 +683,11 @@ void gvir_connection_close(GVirConnection *conn) priv->interfaces = NULL; } +if (priv->networks) { +g_hash_table_unref(priv->networks); +priv->networks = NULL; +} + if (priv->conn) { virConnectDomainEventDeregister(priv->conn, domain_event_cb); virConnectClose(priv->conn); @@ -1713,6 +1723,258 @@ GVirInterface *gvir_connection_find_interface_by_mac(GVirConnection *conn, } /** + * gvir_connection_fetch_networks: + * @conn: a #GVirConnection + * @cancellable: (allow-none)(transfer none): cancellation object + */ +gboolean gvir_connection_fetch_networks(GVirConnection *conn, +GCancellable *cancellable, +GError **err) +{ +GVirConnectionPrivate *priv; +GHashTable *networks; +virNetworkPtr *vnetworks = NULL; +gint nnetworks = 0; +gboolean ret = FALSE; +gint i; +virConnectPtr vconn = 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; + +nnetworks = virConnectListAllNetworks(vconn, &vnetworks, 0); +if (nnetworks < 0) { +gvir_set_error(err, GVIR_CONNECTION_ERROR, + 0, + _("Failed to fetch list of networks")); +goto cleanup; +} + +if (g_cancellable_set_error_if_cancelled(cancellable, err)) +goto cleanup; + +networks = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); + +for (i = 0 ; i < nnetworks; i++) { +GVirNetwork *network; + +if (g_cancellable_set_error_if_cancelled(cancellable, err)) +goto cleanup; + +network = GVIR_NETWORK(g_object_new(GVIR_TYPE_NETWORK, +"handle", vnetworks[i], +NULL)); +g_hash_table_insert(networks, +(gpointer)gvir_network_get_uuid(network), +network); +} + +g_mutex_lock(priv->lock); +if (priv->networks) +g_hash_table_unref(priv->networks); +priv->networks = networks; +g_mutex_unlock(priv->lock); + +ret = TRUE; + +cleanup: +if (nnetworks > 0) { +for (i = 0 ; i < nnetworks; i++) +virNetworkFree(vnetworks[i]); +free(vnetworks); +} +if (vconn != NULL) +virConnectClose(vconn); +return ret; +} + +static void +gvir_connection_fetch_networks_helper(GTask *task, + gpointer object, + gpointer task_data G_GNUC_UNUSED, + GCancellable *cancellable) +{ +GVirConnection *conn = GVIR_CONNECTION(object); +GError *err = NULL; + +if (!gvir_connection_fetch_networks(conn, cancellable, &err)) +g_task_return_error(task, err); +else +g_task_return_bool
Re: [libvirt] [libvirt-glib PATCHv4 7/7] gobject: Add wrapper for virNetworkGetDHCPLeases
On Mon, Jul 6, 2015 at 6:05 PM, Christophe Fergeau wrote: > On Wed, Jul 01, 2015 at 09:40:51PM +0100, Zeeshan Ali (Khattak) wrote: >> --- >> libvirt-gobject/libvirt-gobject-network.c | 54 >> +++ >> libvirt-gobject/libvirt-gobject-network.h | 4 +++ >> libvirt-gobject/libvirt-gobject.sym | 2 ++ >> 3 files changed, 60 insertions(+) >> >> diff --git a/libvirt-gobject/libvirt-gobject-network.c >> b/libvirt-gobject/libvirt-gobject-network.c >> index b1b38a0..b29be36 100644 >> --- a/libvirt-gobject/libvirt-gobject-network.c >> +++ b/libvirt-gobject/libvirt-gobject-network.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-network-dhcp-lease-private.h" >> >> #define GVIR_NETWORK_GET_PRIVATE(obj) \ >> (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, >> GVirNetworkPrivate)) >> @@ -224,3 +225,56 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork >> *network, >> free(xml); >> return conf; >> } >> + >> +/** >> + * gvir_network_get_dhcp_leases: >> + * @network: the network >> + * @mac: (allow-none): The optional ASCII formatted MAC address of an >> interface >> + * @flags: placeholder for flags, pass 0 > > "must be 0" rather than "pass 0" ? I just copy&pasted from another place in code. :) -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-glib] gobject: Remove redundant virtual functions
On Fri, Jul 3, 2015 at 3:35 PM, Daniel P. Berrange wrote: > On Fri, Jul 03, 2015 at 03:17:42PM +0100, Zeeshan Ali (Khattak) wrote: >> These virtual functions were most likely a result of copy&paste error. >> --- >> libvirt-gobject/libvirt-gobject-network.h | 5 + >> 1 file changed, 1 insertion(+), 4 deletions(-) >> >> diff --git a/libvirt-gobject/libvirt-gobject-network.h >> b/libvirt-gobject/libvirt-gobject-network.h >> index 5617ed6..8c31af4 100644 >> --- a/libvirt-gobject/libvirt-gobject-network.h >> +++ b/libvirt-gobject/libvirt-gobject-network.h >> @@ -55,10 +55,7 @@ struct _GVirNetworkClass >> { >> GObjectClass parent_class; >> >> -void (*started)(GVirNetwork *net); >> -void (*stopped)(GVirNetwork *net); >> - >> -gpointer padding[20]; >> +gpointer padding[22]; >> }; > > Although you maintained the struct size ABI, this is still technically > an API incompatible change / break. > > FWIW this is equivalent the the same named slots in the domain class, > where they are used for signals. It seems we never wired up the signals > in the network class though, hence why they may appear uneccessary. So > I think we shouldn't remove them, but instead add the use by signals > as we have for other classes Ah they do apply to network as well. Didn't realize that. BTW, virtual functions are no longer needed/recommended for signals. -- Regards, Zeeshan Ali (Khattak) Befriend GNOME: http://www.gnome.org/friends/ -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib] gobject: Remove redundant virtual functions
These virtual functions were most likely a result of copy&paste error. --- libvirt-gobject/libvirt-gobject-network.h | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-network.h b/libvirt-gobject/libvirt-gobject-network.h index 5617ed6..8c31af4 100644 --- a/libvirt-gobject/libvirt-gobject-network.h +++ b/libvirt-gobject/libvirt-gobject-network.h @@ -55,10 +55,7 @@ struct _GVirNetworkClass { GObjectClass parent_class; -void (*started)(GVirNetwork *net); -void (*stopped)(GVirNetwork *net); - -gpointer padding[20]; +gpointer padding[22]; }; -- 2.4.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-glib PATCHv4 5/7] gobject: Add API to query connection networks
Add API to query networks from a connection. --- libvirt-gobject/libvirt-gobject-connection.c | 257 +++ libvirt-gobject/libvirt-gobject-connection.h | 13 +- libvirt-gobject/libvirt-gobject.sym | 6 + 3 files changed, 274 insertions(+), 2 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 47b6861..a055a86 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -45,6 +45,7 @@ struct _GVirConnectionPrivate GHashTable *domains; GHashTable *pools; GHashTable *interfaces; +GHashTable *networks; }; G_DEFINE_TYPE(GVirConnection, gvir_connection, G_TYPE_OBJECT); @@ -257,6 +258,10 @@ static void gvir_connection_init(GVirConnection *conn) g_str_equal, NULL, g_object_unref); +priv->networks = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); } @@ -672,6 +677,11 @@ void gvir_connection_close(GVirConnection *conn) priv->interfaces = NULL; } +if (priv->networks) { +g_hash_table_unref(priv->networks); +priv->networks = NULL; +} + if (priv->conn) { virConnectDomainEventDeregister(priv->conn, domain_event_cb); virConnectClose(priv->conn); @@ -1696,6 +1706,253 @@ GVirInterface *gvir_connection_find_interface_by_mac(GVirConnection *conn, } /** + * gvir_connection_fetch_networks: + * @conn: a #GVirConnection + * @cancellable: (allow-none)(transfer none): cancellation object + */ +gboolean gvir_connection_fetch_networks(GVirConnection *conn, +GCancellable *cancellable, +GError **err) +{ +GVirConnectionPrivate *priv; +GHashTable *networks; +virNetworkPtr *vnetworks = NULL; +gint nnetworks = 0; +gboolean ret = FALSE; +gint i; +virConnectPtr vconn = 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; + +nnetworks = virConnectListAllNetworks(vconn, &vnetworks, 0); +if (nnetworks < 0) { +gvir_set_error(err, GVIR_CONNECTION_ERROR, + 0, + _("Failed to fetch list of networks")); +goto cleanup; +} + +if (g_cancellable_set_error_if_cancelled(cancellable, err)) +goto cleanup; + +networks = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); + +for (i = 0 ; i < nnetworks; i++) { +if (g_cancellable_set_error_if_cancelled(cancellable, err)) +goto cleanup; + +GVirNetwork *network; + +network = GVIR_NETWORK(g_object_new(GVIR_TYPE_NETWORK, +"handle", vnetworks[i], +NULL)); +g_hash_table_insert(networks, +(gpointer)gvir_network_get_uuid(network), +network); +} + +g_mutex_lock(priv->lock); +if (priv->networks) +g_hash_table_unref(priv->networks); +priv->networks = networks; +g_mutex_unlock(priv->lock); + +ret = TRUE; + +cleanup: +if (nnetworks > 0) { +for (i = 0 ; i < nnetworks; i++) +virNetworkFree(vnetworks[i]); +free(vnetworks); +} +if (vconn != NULL) +virConnectClose(vconn); +return ret; +} + +static void +gvir_connection_fetch_networks_helper(GTask *res, + gpointer object, + gpointer task_data G_GNUC_UNUSED, + GCancellable *cancellable) +{ +GVirConnection *conn = GVIR_CONNECTION(object); +GError *err = NULL; + +if (!gvir_connection_fetch_networks(conn, cancellable, &err)) +g_task_return_error(res, err); +else +g_task_return_boolea