[libvirt] [glib PATCH 0/8] Add machinery forsetting firmware attribute to <os/>

This series consists in two different things that, together, are needed to set <os firmware="efi|bios"/> as part of libvirt domain's XML. The first patch simply changes the XML adding the bit mentioned above. All the other patches, on the other hand, add enough (and nothing more than that) infra for consumers to check which are the supported firmwares (the ones listed by virConnectGetDomainCapabilities()). Fabiano Fidêncio (8): gconfig: Add _domain_os_set_firmware() gobject: Use the proper return type in _connection_get_capabilities_finish() gconfig: Add GVirConfigDomainCapabilities gconfig: Add GVirConfigDomainCapabilitiesOs gconfig: Add _domain_capabilities_get_os() gconfig: Add _domain_capabilities_os_get_firmwares() tests: Add basic test for domain capabilities gobject: Wrap virConnectGetDomainCapabilities() libvirt-gconfig/Makefile.am | 4 + .../libvirt-gconfig-domain-capabilities-os.c | 115 ++++++++++++ .../libvirt-gconfig-domain-capabilities-os.h | 66 +++++++ .../libvirt-gconfig-domain-capabilities.c | 94 ++++++++++ .../libvirt-gconfig-domain-capabilities.h | 68 +++++++ libvirt-gconfig/libvirt-gconfig-domain-os.c | 17 ++ libvirt-gconfig/libvirt-gconfig-domain-os.h | 7 + libvirt-gconfig/libvirt-gconfig.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 8 + libvirt-gobject/libvirt-gobject-connection.c | 170 +++++++++++++++++- libvirt-gobject/libvirt-gobject-connection.h | 22 +++ libvirt-gobject/libvirt-gobject.sym | 8 + tests/test-gconfig.c | 34 ++++ tests/xml/gconfig-domain-capabilities-os.xml | 23 +++ tests/xml/gconfig-domain-os.xml | 2 +- 15 files changed, 638 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.h create mode 100644 tests/xml/gconfig-domain-capabilities-os.xml -- 2.21.0

Add a way to set <os firmware="bios|efi"/> to the domain XML. Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gconfig/libvirt-gconfig-domain-os.c | 17 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-os.h | 7 +++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ tests/test-gconfig.c | 1 + tests/xml/gconfig-domain-os.xml | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-os.c b/libvirt-gconfig/libvirt-gconfig-domain-os.c index ecbf5b3..62c3441 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-os.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-os.c @@ -328,3 +328,20 @@ void gvir_config_domain_os_set_machine(GVirConfigDomainOs *os, const char *machi xmlNewProp(os_type_node, (xmlChar*)"machine", (xmlChar*)machine); } + +void gvir_config_domain_os_set_firmware(GVirConfigDomainOs *os, GVirConfigDomainOsFirmware firmware) +{ + xmlNodePtr node; + const gchar *firmware_str; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_OS(os)); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); + g_return_if_fail(node != NULL); + + firmware_str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_OS_FIRMWARE, + firmware); + g_warn_if_fail(firmware_str != NULL); + + xmlNewProp(node, (xmlChar*)"firmware", (xmlChar*)firmware_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-os.h b/libvirt-gconfig/libvirt-gconfig-domain-os.h index fe17dd4..2a8fc13 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-os.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-os.h @@ -77,6 +77,11 @@ typedef enum { GVIR_CONFIG_DOMAIN_OS_BOOT_DEVICE_NETWORK } GVirConfigDomainOsBootDevice; +typedef enum { + GVIR_CONFIG_DOMAIN_OS_FIRMWARE_BIOS, + GVIR_CONFIG_DOMAIN_OS_FIRMWARE_EFI +} GVirConfigDomainOsFirmware; + GType gvir_config_domain_os_get_type(void); GVirConfigDomainOs *gvir_config_domain_os_new(void); @@ -99,6 +104,8 @@ void gvir_config_domain_os_set_smbios_mode(GVirConfigDomainOs *os, GVirConfigDomainOsSmBiosMode mode); void gvir_config_domain_os_enable_boot_menu(GVirConfigDomainOs *os, gboolean enable); void gvir_config_domain_os_bios_enable_serial(GVirConfigDomainOs *os, gboolean enable); +void gvir_config_domain_os_set_firmware(GVirConfigDomainOs *os, + GVirConfigDomainOsFirmware firmware); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 885e708..746fd1a 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -774,6 +774,8 @@ global: LIBVIRT_GCONFIG_2.0.1 { global: + gvir_config_domain_os_firmware_get_type; + gvir_config_domain_os_set_firmware; gvir_config_storage_vol_target_features_get_type; gvir_config_storage_vol_target_set_features; } LIBVIRT_GCONFIG_2.0.0; diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index 3328297..fda4fcb 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -215,6 +215,7 @@ static void test_domain_os(void) gvir_config_domain_os_set_os_type(os, GVIR_CONFIG_DOMAIN_OS_TYPE_HVM); gvir_config_domain_os_set_arch(os, "x86_64"); gvir_config_domain_os_set_machine(os, "q35"); + gvir_config_domain_os_set_firmware(os, GVIR_CONFIG_DOMAIN_OS_FIRMWARE_EFI); g_assert_cmpint(gvir_config_domain_os_get_os_type(os), ==, GVIR_CONFIG_DOMAIN_OS_TYPE_HVM); g_assert_cmpstr(gvir_config_domain_os_get_arch(os), ==, "x86_64"); g_assert_cmpstr(gvir_config_domain_os_get_machine(os), ==, "q35"); diff --git a/tests/xml/gconfig-domain-os.xml b/tests/xml/gconfig-domain-os.xml index 56af776..690024d 100644 --- a/tests/xml/gconfig-domain-os.xml +++ b/tests/xml/gconfig-domain-os.xml @@ -1,5 +1,5 @@ <domain> - <os> + <os firmware="efi"> <type arch="x86_64" machine="q35">hvm</type> <boot dev="cdrom"/> <boot dev="network"/> -- 2.21.0

On 5/10/19 9:12 PM, Fabiano Fidêncio wrote:
Add a way to set <os firmware="bios|efi"/> to the domain XML.
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gconfig/libvirt-gconfig-domain-os.c | 17 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-os.h | 7 +++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ tests/test-gconfig.c | 1 + tests/xml/gconfig-domain-os.xml | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-os.c b/libvirt-gconfig/libvirt-gconfig-domain-os.c index ecbf5b3..62c3441 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-os.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-os.c @@ -328,3 +328,20 @@ void gvir_config_domain_os_set_machine(GVirConfigDomainOs *os, const char *machi
xmlNewProp(os_type_node, (xmlChar*)"machine", (xmlChar*)machine); } + +void gvir_config_domain_os_set_firmware(GVirConfigDomainOs *os, GVirConfigDomainOsFirmware firmware) +{ + xmlNodePtr node; + const gchar *firmware_str; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_OS(os)); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); + g_return_if_fail(node != NULL); + + firmware_str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_OS_FIRMWARE, + firmware); + g_warn_if_fail(firmware_str != NULL);
I'd rather return an error here. If enum -> str conversion went wrong, then we shouldn't proceed, even though looking at the current implementation of xmlNewProp it's a NO-OP if attribute's value is NULL.
+ + xmlNewProp(node, (xmlChar*)"firmware", (xmlChar*)firmware_str); +}
Michal

Instead of returning FALSE, return NULL. Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gobject/libvirt-gobject-connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 15b4709..e84ca6d 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -2177,7 +2177,7 @@ gvir_connection_get_capabilities_finish(GVirConnection *conn, NULL); g_return_val_if_fail(g_task_get_source_tag(G_TASK(result)) == gvir_connection_get_capabilities_async, - FALSE); + NULL); return g_task_propagate_pointer(G_TASK(result), err); } -- 2.21.0

GVirConfigDomainCapabilities object has been introduced in order to represent the output of virConnectGetDomainCapabilities(). For now it's not used anywhere, but its addition allows us to start building the needed machinery for: - Creating a wrapper around virConnectGetDomainCapabilities(); - Creating new objects that will be used to return each of the elements present in the output of virConnectGetDomainCapabilities(), accordingly to the consumers of this library's need; Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-capabilities.c | 71 +++++++++++++++++++ .../libvirt-gconfig-domain-capabilities.h | 67 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 3 + 5 files changed, 144 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index b976e4d..db2fa79 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -26,6 +26,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ libvirt-gconfig-domain-address-usb.h \ + libvirt-gconfig-domain-capabilities.h \ libvirt-gconfig-domain-channel.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ @@ -119,6 +120,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ libvirt-gconfig-domain-address-usb.c \ + libvirt-gconfig-domain-capabilities.c \ libvirt-gconfig-domain-channel.c \ libvirt-gconfig-domain-chardev.c \ libvirt-gconfig-domain-chardev-source.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c new file mode 100644 index 0000000..3377889 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-domain-capabilities.c: libvirt domain capabilities configuration + * + * Copyright (C) 2019 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/>. + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, GVirConfigDomainCapabilitiesPrivate)) + +struct _GVirConfigDomainCapabilitiesPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilities, gvir_config_domain_capabilities, GVIR_CONFIG_TYPE_OBJECT); + +static void +gvir_config_domain_capabilities_class_init(GVirConfigDomainCapabilitiesClass *klass G_GNUC_UNUSED) +{ +} + + +static void +gvir_config_domain_capabilities_init(GVirConfigDomainCapabilities *domain_caps) +{ + domain_caps->priv = GVIR_CONFIG_DOMAIN_CAPABILITIES_GET_PRIVATE(domain_caps); +} + + +GVirConfigDomainCapabilities * +gvir_config_domain_capabilities_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, + "domainCapabilities", + DATADIR "/libvirt/schemas/domaincaps.rng"); + return GVIR_CONFIG_DOMAIN_CAPABILITIES(object); +} + +GVirConfigDomainCapabilities * +gvir_config_domain_capabilities_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, + "domainCapabilities", + DATADIR "/libvirt/schemas/domaincaps.rng", + xml, error); + return GVIR_CONFIG_DOMAIN_CAPABILITIES(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h new file mode 100644 index 0000000..965d2a4 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-domain-capabilities.c: libvirt domain capabilities configuration + * + * Copyright (C) 2019 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/>. + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_H__ + +#include "libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES (gvir_config_domain_capabilities_get_type ()) +#define GVIR_CONFIG_DOMAIN_CAPABILITIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, GVirConfigDomainCapabilities)) +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, GVirConfigDomainCapabilitiesClass)) +#define GVIR_CONFIG_IS_DOMAIN_CAPABILITIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES)) +#define GVIR_CONFIG_IS_DOMAIN_CAPABILITIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES)) +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, GVirConfigDomainCapabilitiesClass)) + +typedef struct _GVirConfigDomainCapabilities GVirConfigDomainCapabilities; +typedef struct _GVirConfigDomainCapabilitiesPrivate GVirConfigDomainCapabilitiesPrivate; +typedef struct _GVirConfigDomainCapabilitiesClass GVirConfigDomainCapabilitiesClass; + +struct _GVirConfigDomainCapabilities +{ + GVirConfigObject parent; + + GVirConfigDomainCapabilitiesPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainCapabilitiesClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_capabilities_get_type(void); + +GVirConfigDomainCapabilities *gvir_config_domain_capabilities_new(void); +GVirConfigDomainCapabilities *gvir_config_domain_capabilities_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 6462154..9fde05a 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -43,6 +43,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-usb.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 746fd1a..4a13635 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -774,6 +774,9 @@ global: LIBVIRT_GCONFIG_2.0.1 { global: + gvir_config_domain_capabilities_get_type; + gvir_config_domain_capabilities_new; + gvir_config_domain_capabilities_new_from_xml; gvir_config_domain_os_firmware_get_type; gvir_config_domain_os_set_firmware; gvir_config_storage_vol_target_features_get_type; -- 2.21.0

On 5/10/19 9:12 PM, Fabiano Fidêncio wrote:
GVirConfigDomainCapabilities object has been introduced in order to represent the output of virConnectGetDomainCapabilities().
For now it's not used anywhere, but its addition allows us to start building the needed machinery for: - Creating a wrapper around virConnectGetDomainCapabilities(); - Creating new objects that will be used to return each of the elements present in the output of virConnectGetDomainCapabilities(), accordingly to the consumers of this library's need;
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-capabilities.c | 71 +++++++++++++++++++ .../libvirt-gconfig-domain-capabilities.h | 67 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 3 + 5 files changed, 144 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index b976e4d..db2fa79 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -26,6 +26,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ libvirt-gconfig-domain-address-usb.h \ + libvirt-gconfig-domain-capabilities.h \ libvirt-gconfig-domain-channel.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ @@ -119,6 +120,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ libvirt-gconfig-domain-address-usb.c \ + libvirt-gconfig-domain-capabilities.c \ libvirt-gconfig-domain-channel.c \ libvirt-gconfig-domain-chardev.c \ libvirt-gconfig-domain-chardev-source.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c new file mode 100644 index 0000000..3377889 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-domain-capabilities.c: libvirt domain capabilities configuration + * + * Copyright (C) 2019 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/>. + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, GVirConfigDomainCapabilitiesPrivate)) + +struct _GVirConfigDomainCapabilitiesPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilities, gvir_config_domain_capabilities, GVIR_CONFIG_TYPE_OBJECT); + +static void +gvir_config_domain_capabilities_class_init(GVirConfigDomainCapabilitiesClass *klass G_GNUC_UNUSED) +{ +} + + +static void +gvir_config_domain_capabilities_init(GVirConfigDomainCapabilities *domain_caps) +{ + domain_caps->priv = GVIR_CONFIG_DOMAIN_CAPABILITIES_GET_PRIVATE(domain_caps); +} + + +GVirConfigDomainCapabilities * +gvir_config_domain_capabilities_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, + "domainCapabilities", + DATADIR "/libvirt/schemas/domaincaps.rng"); + return GVIR_CONFIG_DOMAIN_CAPABILITIES(object); +} + +GVirConfigDomainCapabilities * +gvir_config_domain_capabilities_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES, + "domainCapabilities", + DATADIR "/libvirt/schemas/domaincaps.rng", + xml, error); + return GVIR_CONFIG_DOMAIN_CAPABILITIES(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h new file mode 100644 index 0000000..965d2a4 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-domain-capabilities.c: libvirt domain capabilities configuration + * + * Copyright (C) 2019 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/>. + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_H__ + +#include "libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h"
Oops, there's no such file, yet. Save this for the next patch where the file is introduced. Or even better - save it for the one after (6/8) where it's actually needed. Michal

GVirConfigDomainCapabilitiesOs object has been introduced in order to represent the <os/> element under <domainCapabilities/>. For now it's not used anywhere, but it's addition allows us to start building the needed machinery for: - Returning a representation os <os/> element; - Having the most basic machinery to start adding functions to return any child element we may need to query from <os/> element; Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-capabilities-os.c | 43 +++++++++++++ .../libvirt-gconfig-domain-capabilities-os.h | 61 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 1 + 5 files changed, 108 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index db2fa79..089b42a 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -27,6 +27,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-address-pci.h \ libvirt-gconfig-domain-address-usb.h \ libvirt-gconfig-domain-capabilities.h \ + libvirt-gconfig-domain-capabilities-os.h \ libvirt-gconfig-domain-channel.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ @@ -121,6 +122,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-address-pci.c \ libvirt-gconfig-domain-address-usb.c \ libvirt-gconfig-domain-capabilities.c \ + libvirt-gconfig-domain-capabilities-os.c \ libvirt-gconfig-domain-channel.c \ libvirt-gconfig-domain-chardev.c \ libvirt-gconfig-domain-chardev-source.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c new file mode 100644 index 0000000..d3b6e3c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c @@ -0,0 +1,43 @@ +/* + * libvirt-gconfig-domain-capabilities-os.c: libvirt OS domain capabilities + * + * Copyright (C) 2019 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/>. + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS, GVirConfigDomainCapabilitiesOsPrivate)) + +struct _GVirConfigDomainCapabilitiesOsPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilitiesOs, gvir_config_domain_capabilities_os, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass G_GNUC_UNUSED) +{ +} + +static void gvir_config_domain_capabilities_os_init(GVirConfigDomainCapabilitiesOs *os) +{ + os->priv = GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_PRIVATE(os); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h new file mode 100644 index 0000000..dba8572 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h @@ -0,0 +1,61 @@ +/* + * libvirt-gconfig-domain-capabilities-os.h: libvirt domain capabilities OS + * + * Copyright (C) 2019 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/>. + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_OS_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_OS_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS (gvir_config_domain_capabilities_os_get_type ()) +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_OS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS, GVirConfigDomainCapabilitiesOs)) +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS, GVirConfigDomainCapabilitiesOsClass)) +#define GVIR_CONFIG_IS_DOMAIN_CAPABILITIES_OS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS)) +#define GVIR_CONFIG_IS_DOMAIN_CAPABILITIES_OS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS)) +#define GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS, GVirConfigDomainCapabilitiesOsClass)) + +typedef struct _GVirConfigDomainCapabilitiesOs GVirConfigDomainCapabilitiesOs; +typedef struct _GVirConfigDomainCapabilitiesOsPrivate GVirConfigDomainCapabilitiesOsPrivate; +typedef struct _GVirConfigDomainCapabilitiesOsClass GVirConfigDomainCapabilitiesOsClass; + +struct _GVirConfigDomainCapabilitiesOs +{ + GVirConfigObject parent; + + GVirConfigDomainCapabilitiesOsPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainCapabilitiesOsClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_capabilities_os_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_OS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 9fde05a..896b4f1 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -44,6 +44,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-usb.h> #include <libvirt-gconfig/libvirt-gconfig-domain-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 4a13635..0e5c06b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -777,6 +777,7 @@ global: gvir_config_domain_capabilities_get_type; gvir_config_domain_capabilities_new; gvir_config_domain_capabilities_new_from_xml; + gvir_config_domain_capabilities_os_get_type; gvir_config_domain_os_firmware_get_type; gvir_config_domain_os_set_firmware; gvir_config_storage_vol_target_features_get_type; -- 2.21.0

Add a way to access the object which represents the <os/> element from the <domainCapabilities/>. Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- .../libvirt-gconfig-domain-capabilities.c | 23 +++++++++++++++++++ .../libvirt-gconfig-domain-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 25 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c index 3377889..906e7f0 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.c @@ -69,3 +69,26 @@ gvir_config_domain_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_DOMAIN_CAPABILITIES(object); } + +/** + * gvir_config_domain_capabilities_get_os: + * @domain_caps: a #GVirConfigDomainCapabilities + * + * Gets the @os associated with the @domain_caps. + * + * Returns: (transfer full): a new #GVirConfigDomainCapabilitiesOs. + */ +GVirConfigDomainCapabilitiesOs * +gvir_config_domain_capabilities_get_os(GVirConfigDomainCapabilities *domain_caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CAPABILITIES(domain_caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(domain_caps), + "os", + GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS); + + return GVIR_CONFIG_DOMAIN_CAPABILITIES_OS(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h index 965d2a4..cbe7540 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities.h @@ -61,6 +61,7 @@ GType gvir_config_domain_capabilities_get_type(void); GVirConfigDomainCapabilities *gvir_config_domain_capabilities_new(void); GVirConfigDomainCapabilities *gvir_config_domain_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigDomainCapabilitiesOs *gvir_config_domain_capabilities_get_os(GVirConfigDomainCapabilities *domain_caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 0e5c06b..783b0d7 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -774,6 +774,7 @@ global: LIBVIRT_GCONFIG_2.0.1 { global: + gvir_config_domain_capabilities_get_os; gvir_config_domain_capabilities_get_type; gvir_config_domain_capabilities_new; gvir_config_domain_capabilities_new_from_xml; -- 2.21.0

Add a way to access the <enum name="firmware"/> element's conent from <os/>. Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- .../libvirt-gconfig-domain-capabilities-os.c | 74 ++++++++++++++++++- .../libvirt-gconfig-domain-capabilities-os.h | 7 +- libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c index d3b6e3c..98a1bff 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c @@ -33,11 +33,83 @@ struct _GVirConfigDomainCapabilitiesOsPrivate G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilitiesOs, gvir_config_domain_capabilities_os, GVIR_CONFIG_TYPE_OBJECT); -static void gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass G_GNUC_UNUSED) +static GList * +_gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os); + +static void gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass) { + klass->get_firmwares = _gvir_config_domain_capabilities_os_get_firmwares; } static void gvir_config_domain_capabilities_os_init(GVirConfigDomainCapabilitiesOs *os) { os->priv = GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_PRIVATE(os); } + +static gboolean add_firmwares(xmlNodePtr node, gpointer opaque) +{ + GList **firmwares = opaque; + GVirConfigDomainOsFirmware firmware; + + if (node == NULL || node->children == NULL) + return TRUE; + + firmware = gvir_config_genum_get_value + (GVIR_CONFIG_TYPE_DOMAIN_OS_FIRMWARE, + (const gchar *)node->children->content, + GVIR_CONFIG_DOMAIN_OS_FIRMWARE_BIOS); + *firmwares = g_list_append(*firmwares, GINT_TO_POINTER(firmware)); + + return TRUE; +} + +static gboolean search_firmwares(xmlNodePtr node, gpointer opaque) +{ + const gchar *content; + + if (!g_str_equal(node->name, "enum")) + return TRUE; + + content = gvir_config_xml_get_attribute_content(node, "name"); + if (content == NULL) + return TRUE; + + if (!g_str_equal(content, "firmware")) + return TRUE; + + gvir_config_xml_foreach_child(node, + add_firmwares, + opaque); + + return TRUE; +} + +static GList * +_gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os) +{ + GList *firmwares = NULL; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CAPABILITIES_OS(os), NULL); + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(os), + NULL, + search_firmwares, + &firmwares); + + return firmwares; +} + +/** + * gvir_config_domain_capabilities_os_get_firmwares: + * + * Gets the firmwares supported by @os. The returned list should be freed with + * g_list_free(). + * + * Returns: (element-type LibvirtGConfig.DomainOsFirmware) (transfer container): + * a newly allocated #GList of #GVirConfigDomainOsFirmware. + */ +GList * +gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os) +{ + return GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_CLASS(os)->get_firmwares(os); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h index dba8572..ce36be2 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h @@ -51,11 +51,16 @@ struct _GVirConfigDomainCapabilitiesOsClass { GVirConfigObjectClass parent_class; - gpointer padding[20]; + GList *(*get_firmwares)(GVirConfigDomainCapabilitiesOs *os); + + gpointer padding[19]; }; GType gvir_config_domain_capabilities_os_get_type(void); +GList * +gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_OS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 783b0d7..d40bb7b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -778,6 +778,7 @@ global: gvir_config_domain_capabilities_get_type; gvir_config_domain_capabilities_new; gvir_config_domain_capabilities_new_from_xml; + gvir_config_domain_capabilities_os_get_firmwares; gvir_config_domain_capabilities_os_get_type; gvir_config_domain_os_firmware_get_type; gvir_config_domain_os_set_firmware; -- 2.21.0

On 5/10/19 9:12 PM, Fabiano Fidêncio wrote:
Add a way to access the <enum name="firmware"/> element's conent from <os/>.
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- .../libvirt-gconfig-domain-capabilities-os.c | 74 ++++++++++++++++++- .../libvirt-gconfig-domain-capabilities-os.h | 7 +- libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 80 insertions(+), 2 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c index d3b6e3c..98a1bff 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c @@ -33,11 +33,83 @@ struct _GVirConfigDomainCapabilitiesOsPrivate
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilitiesOs, gvir_config_domain_capabilities_os, GVIR_CONFIG_TYPE_OBJECT);
-static void gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass G_GNUC_UNUSED) +static GList * +_gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os); + +static void gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass) { + klass->get_firmwares = _gvir_config_domain_capabilities_os_get_firmwares; }
static void gvir_config_domain_capabilities_os_init(GVirConfigDomainCapabilitiesOs *os) { os->priv = GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_PRIVATE(os); } + +static gboolean add_firmwares(xmlNodePtr node, gpointer opaque) +{ + GList **firmwares = opaque; + GVirConfigDomainOsFirmware firmware; + + if (node == NULL || node->children == NULL) + return TRUE; + + firmware = gvir_config_genum_get_value + (GVIR_CONFIG_TYPE_DOMAIN_OS_FIRMWARE, + (const gchar *)node->children->content, + GVIR_CONFIG_DOMAIN_OS_FIRMWARE_BIOS); + *firmwares = g_list_append(*firmwares, GINT_TO_POINTER(firmware)); + + return TRUE; +} + +static gboolean search_firmwares(xmlNodePtr node, gpointer opaque) +{ + const gchar *content; + + if (!g_str_equal(node->name, "enum")) + return TRUE; + + content = gvir_config_xml_get_attribute_content(node, "name"); + if (content == NULL) + return TRUE; + + if (!g_str_equal(content, "firmware")) + return TRUE; + + gvir_config_xml_foreach_child(node, + add_firmwares, + opaque); + + return TRUE; +} + +static GList * +_gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os) +{ + GList *firmwares = NULL; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CAPABILITIES_OS(os), NULL); + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(os), + NULL, + search_firmwares, + &firmwares); + + return firmwares; +} + +/** + * gvir_config_domain_capabilities_os_get_firmwares: + * + * Gets the firmwares supported by @os. The returned list should be freed with + * g_list_free(). + * + * Returns: (element-type LibvirtGConfig.DomainOsFirmware) (transfer container): + * a newly allocated #GList of #GVirConfigDomainOsFirmware. + */ +GList * +gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os) +{ + return GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_CLASS(os)->get_firmwares(os); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h index dba8572..ce36be2 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h @@ -51,11 +51,16 @@ struct _GVirConfigDomainCapabilitiesOsClass { GVirConfigObjectClass parent_class;
- gpointer padding[20]; + GList *(*get_firmwares)(GVirConfigDomainCapabilitiesOs *os); + + gpointer padding[19];
Strictly speaking, this shouldn't be needed as this wasn't released yet, so we can change the siz of this class. But it's a good practise, so your call whether we'll do that or not. Michal

This basic test only ensures that we can properly parse: <domainCapabilities> <os> <enum name="firmeware"> <value>bios</value> <value>efi</value> </enum> </os> </domainCapabilities> Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- tests/test-gconfig.c | 33 ++++++++++++++++++++ tests/xml/gconfig-domain-capabilities-os.xml | 23 ++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/xml/gconfig-domain-capabilities-os.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index fda4fcb..6979578 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -791,6 +791,37 @@ static void test_domain_device_unknown(void) g_free(xml); } +static void test_domain_capabilities_os(void) +{ + GVirConfigDomainCapabilities *domain_caps; + GVirConfigDomainCapabilitiesOs *os; + GList *firmwares, *l; + gsize i; + GVirConfigDomainOsFirmware expected_firmwares[] = {GVIR_CONFIG_DOMAIN_OS_FIRMWARE_BIOS, + GVIR_CONFIG_DOMAIN_OS_FIRMWARE_EFI}; + GError *error = NULL; + gchar *xml; + + xml = load_xml("gconfig-domain-capabilities-os.xml"); + + domain_caps = gvir_config_domain_capabilities_new_from_xml(xml, &error); + g_assert_no_error(error); + + os = gvir_config_domain_capabilities_get_os(domain_caps); + g_assert_nonnull(os); + + firmwares = gvir_config_domain_capabilities_os_get_firmwares(os); + g_assert_nonnull(firmwares); + + for (l = firmwares, i = 0; l != NULL; l = l->next, i++) + g_assert_cmpint(GPOINTER_TO_INT(l->data), ==, expected_firmwares[i]); + + + g_list_free(firmwares); + g_object_unref(os); + g_object_unref(domain_caps); + g_free(xml); +} int main(int argc, char **argv) { @@ -825,6 +856,8 @@ int main(int argc, char **argv) test_domain_device_pci_hostdev); g_test_add_func("/libvirt-gconfig/domain-device-unknown", test_domain_device_unknown); + g_test_add_func("/libvirt-gconfig/domain-capabilities-os", + test_domain_capabilities_os); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-capabilities-os.xml b/tests/xml/gconfig-domain-capabilities-os.xml new file mode 100644 index 0000000..7e813c6 --- /dev/null +++ b/tests/xml/gconfig-domain-capabilities-os.xml @@ -0,0 +1,23 @@ +<domainCapabilities> + <os supported='yes'> + <enum name='firmware'> + <value>bios</value> + <value>efi</value> + </enum> + <loader supported='yes'> + <value>/usr/share/edk2/ovmf/OVMF_CODE.fd</value> + <value>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw</value> + <enum name='type'> + <value>rom</value> + <value>pflash</value> + </enum> + <enum name='readonly'> + <value>yes</value> + <value>no</value> + </enum> + <enum name='secure'> + <value>no</value> + </enum> + </loader> + </os> +</domainCapabilities> -- 2.21.0

In order to do so, 3 new APIs have been added: - gvir_connection_get_domain_capabilities(); - gvir_connection_get_domain_capabilities_async(); - gvir_connection_get_domain_capabilities_finish(); The returned object is a GVirConfigDomainCapabilities, from which consumers will be able to access a few other objects representing the XML returned by virConnectGetDomainCapabilities(). Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com> --- libvirt-gobject/libvirt-gobject-connection.c | 168 +++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 22 +++ libvirt-gobject/libvirt-gobject.sym | 8 + 3 files changed, 198 insertions(+) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index e84ca6d..8e7bf5e 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -2077,6 +2077,174 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, return ret; } +/** + * gvir_connection_get_domain_capabilities: + * @conn: a #GVirConnection + * @emulatorbin: (allow-none): path to emulator + * @arch: (allow-none): domain architecture + * @machine: (allow-none): machine type + * @virttype: (allow-none): virtualization type + * @flags: extra flags; not used yet, so callers should always pass 0 + * @err: return location for any #GError + * + * Return value: (transfer full): a #GVirConfigDomainCapabilities or NULL. + * The return object should be unreffed with g_object_unref() when no longer + * needed. + */ +GVirConfigDomainCapabilities * +gvir_connection_get_domain_capabilities(GVirConnection *conn, + const gchar *emulatorbin, + const gchar *arch, + const gchar *machine, + const gchar *virttype, + guint flags, + GError **err) +{ + GVirConfigDomainCapabilities *domain_caps; + gchar *domain_caps_xml; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + g_return_val_if_fail(conn->priv->conn, NULL); + + domain_caps_xml = virConnectGetDomainCapabilities(conn->priv->conn, + emulatorbin, + arch, + machine, + virttype, + flags); + if (domain_caps_xml == NULL) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, + 0, + _("Unable to get domain capabilities")); + return NULL; + } + + domain_caps = gvir_config_domain_capabilities_new_from_xml(domain_caps_xml, err); + free(domain_caps_xml); + + return domain_caps; +} + +typedef struct { + gchar *emulatorbin; + gchar *arch; + gchar *machine; + gchar *virttype; + guint flags; +} GetDomainCapabilitiesData; + +static void get_domain_capabilities_data_free(GetDomainCapabilitiesData *data) +{ + g_free(data->emulatorbin); + g_free(data->arch); + g_free(data->machine); + g_free(data->virttype); + g_slice_free(GetDomainCapabilitiesData, data); +} + +static void +gvir_connection_get_domain_capabilities_helper(GTask *task, + gpointer object, + gpointer task_data G_GNUC_UNUSED, + GCancellable *cancellable G_GNUC_UNUSED) +{ + GVirConnection *conn = GVIR_CONNECTION(object); + GetDomainCapabilitiesData *data; + GError *err = NULL; + GVirConfigDomainCapabilities *domain_caps; + + data = (GetDomainCapabilitiesData *)task_data; + + domain_caps = gvir_connection_get_domain_capabilities(conn, + data->emulatorbin, + data->arch, + data->machine, + data->virttype, + data->flags, + &err); + if (domain_caps == NULL) { + g_task_return_error(task, err); + + return; + } + + g_task_return_pointer(task, domain_caps, g_object_unref); +} + +/** + * gvir_connection_get_domain_capabilities_async: + * @conn: a #GVirConnection + * @emulatorbin: (allow-none): path to emulator + * @arch: (allow-none): domain architecture + * @machine: (allow-none): machine type + * @virttype: (allow-none): virtualization type + * @flags: extra flags; not used yet, so callers should always pass 0 + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + */ +void gvir_connection_get_domain_capabilities_async(GVirConnection *conn, + const gchar *emulatorbin, + const gchar *arch, + const gchar *machine, + const gchar *virttype, + guint flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + GetDomainCapabilitiesData *data; + + g_return_if_fail(GVIR_IS_CONNECTION(conn)); + g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); + + data = g_slice_new0(GetDomainCapabilitiesData); + data->emulatorbin = g_strdup(emulatorbin); + data->arch = g_strdup(arch); + data->machine = g_strdup(machine); + data->virttype = g_strdup(virttype); + data->flags = flags; + + task = g_task_new(G_OBJECT(conn), + cancellable, + callback, + user_data); + g_task_set_source_tag(task, + gvir_connection_get_domain_capabilities_async); + g_task_set_task_data(task, + data, + (GDestroyNotify)get_domain_capabilities_data_free); + g_task_run_in_thread(task, + gvir_connection_get_domain_capabilities_helper); + g_object_unref(task); +} + +/** + * gvir_connection_get_domain_capabilities_finish: + * @conn: a #GVirConnection + * @result: (transfer none): async method result + * + * Return value: (transfer full): a #GVirConfigDomainCapabilities or NULL. + * The returned object should be unreffed with g_object_unref() when no + * longer needed. + */ +GVirConfigDomainCapabilities * +gvir_connection_get_domain_capabilities_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err) +{ + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(conn)), + NULL); + g_return_val_if_fail(g_task_get_source_tag(G_TASK(result)) == + gvir_connection_get_domain_capabilities_async, + NULL); + + return g_task_propagate_pointer(G_TASK(result), err); +} + /** * gvir_connection_get_capabilities: * @conn: a #GVirConnection diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index f3d2cb8..9557fde 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -255,6 +255,28 @@ gboolean gvir_connection_restore_domain_from_file_finish(GVirConnection *conn, GAsyncResult *result, GError **err); + +GVirConfigDomainCapabilities *gvir_connection_get_domain_capabilities(GVirConnection *conn, + const gchar *emulatorbin, + const gchar *arch, + const gchar *machine, + const gchar *virttype, + guint flags, + GError **err); +void gvir_connection_get_domain_capabilities_async(GVirConnection *conn, + const gchar *emulatorbin, + const gchar *arch, + const gchar *machine, + const gchar *virttype, + guint flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GVirConfigDomainCapabilities * +gvir_connection_get_domain_capabilities_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index fe5bffe..b663906 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -311,4 +311,12 @@ LIBVIRT_GOBJECT_0.2.3 { gvir_domain_set_time_finish; } LIBVIRT_GOBJECT_0.2.2; + +LIBVIRT_GOBJECT_2.0.1 { + global: + gvir_connection_get_domain_capabilities; + gvir_connection_get_domain_capabilities_async; + gvir_connection_get_domain_capabilities_finish; +} LIBVIRT_GOBJECT_0.2.3; + # .... define new API here using predicted next version number .... -- 2.21.0

On 5/10/19 9:12 PM, Fabiano Fidêncio wrote:
This series consists in two different things that, together, are needed to set <os firmware="efi|bios"/> as part of libvirt domain's XML.
The first patch simply changes the XML adding the bit mentioned above. All the other patches, on the other hand, add enough (and nothing more than that) infra for consumers to check which are the supported firmwares (the ones listed by virConnectGetDomainCapabilities()).
Fabiano Fidêncio (8): gconfig: Add _domain_os_set_firmware() gobject: Use the proper return type in _connection_get_capabilities_finish() gconfig: Add GVirConfigDomainCapabilities gconfig: Add GVirConfigDomainCapabilitiesOs gconfig: Add _domain_capabilities_get_os() gconfig: Add _domain_capabilities_os_get_firmwares() tests: Add basic test for domain capabilities gobject: Wrap virConnectGetDomainCapabilities()
libvirt-gconfig/Makefile.am | 4 + .../libvirt-gconfig-domain-capabilities-os.c | 115 ++++++++++++ .../libvirt-gconfig-domain-capabilities-os.h | 66 +++++++ .../libvirt-gconfig-domain-capabilities.c | 94 ++++++++++ .../libvirt-gconfig-domain-capabilities.h | 68 +++++++ libvirt-gconfig/libvirt-gconfig-domain-os.c | 17 ++ libvirt-gconfig/libvirt-gconfig-domain-os.h | 7 + libvirt-gconfig/libvirt-gconfig.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 8 + libvirt-gobject/libvirt-gobject-connection.c | 170 +++++++++++++++++- libvirt-gobject/libvirt-gobject-connection.h | 22 +++ libvirt-gobject/libvirt-gobject.sym | 8 + tests/test-gconfig.c | 34 ++++ tests/xml/gconfig-domain-capabilities-os.xml | 23 +++ tests/xml/gconfig-domain-os.xml | 2 +- 15 files changed, 638 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-capabilities.h create mode 100644 tests/xml/gconfig-domain-capabilities-os.xml
ACK, but see my comments before pushing, please. Michal
participants (2)
-
Fabiano Fidêncio
-
Michal Privoznik