[libvirt] Add USB controller support

Hey, Here is the second version of the patch series implementing USB controller support in libvirt-gconfig. There's a bug fixed in GVirConfigDomainAddressUsb creation (type="usb" was missing) as well as a few small bug fixes/changes in the test program. I also added an additional patch implementing a gvir_config_domain_setup_default_usb_controllers to make adding usb controllers easier following Marc-André's suggestion. Christophe

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-controller.c | 50 ++++++++++++++++ .../libvirt-gconfig-domain-controller.h | 63 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 2 + 5 files changed, 118 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-controller.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-controller.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 181ec57..06b95af 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -20,6 +20,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-chardev-source-spicevmc.h \ libvirt-gconfig-domain-clock.h \ libvirt-gconfig-domain-console.h \ + libvirt-gconfig-domain-controller.h \ libvirt-gconfig-domain-device.h \ libvirt-gconfig-domain-disk.h \ libvirt-gconfig-domain-filesys.h \ @@ -73,6 +74,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-chardev-source-spicevmc.c \ libvirt-gconfig-domain-clock.c \ libvirt-gconfig-domain-console.c \ + libvirt-gconfig-domain-controller.c \ libvirt-gconfig-domain-device.c \ libvirt-gconfig-domain-disk.c \ libvirt-gconfig-domain-filesys.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.c b/libvirt-gconfig/libvirt-gconfig-domain-controller.c new file mode 100644 index 0000000..3aea5ba --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.c @@ -0,0 +1,50 @@ +/* + * libvirt-gconfig-domain-controller.c: libvirt domain controller 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_CONTROLLER_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER, GVirConfigDomainControllerPrivate)) + +struct _GVirConfigDomainControllerPrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainController, gvir_config_domain_controller, GVIR_CONFIG_TYPE_DOMAIN_DEVICE); + + +static void gvir_config_domain_controller_class_init(GVirConfigDomainControllerClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainControllerPrivate)); +} + + +static void gvir_config_domain_controller_init(GVirConfigDomainController *controller) +{ + g_debug("Init GVirConfigDomainController=%p", controller); + + controller->priv = GVIR_CONFIG_DOMAIN_CONTROLLER_GET_PRIVATE(controller); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.h b/libvirt-gconfig/libvirt-gconfig-domain-controller.h new file mode 100644 index 0000000..41847c3 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.h @@ -0,0 +1,63 @@ +/* + * libvirt-gconfig-domain-controller.h: libvirt domain controller 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#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_CONTROLLER_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CONTROLLER_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER (gvir_config_domain_controller_get_type ()) +#define GVIR_CONFIG_DOMAIN_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER, GVirConfigDomainController)) +#define GVIR_CONFIG_DOMAIN_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER, GVirConfigDomainControllerClass)) +#define GVIR_CONFIG_IS_DOMAIN_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER)) +#define GVIR_CONFIG_IS_DOMAIN_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER)) +#define GVIR_CONFIG_DOMAIN_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER, GVirConfigDomainControllerClass)) + +typedef struct _GVirConfigDomainController GVirConfigDomainController; +typedef struct _GVirConfigDomainControllerPrivate GVirConfigDomainControllerPrivate; +typedef struct _GVirConfigDomainControllerClass GVirConfigDomainControllerClass; + +struct _GVirConfigDomainController +{ + GVirConfigDomainDevice parent; + + GVirConfigDomainControllerPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainControllerClass +{ + GVirConfigDomainDeviceClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_controller_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CONTROLLER_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 2fcc4ba..c433060 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -37,6 +37,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-channel.h> #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain-console.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-controller.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h> #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 717c3c9..7b590ff 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -69,6 +69,8 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_console_set_target_type; gvir_config_domain_console_target_type_get_type; + gvir_config_domain_controller_get_type; + gvir_config_domain_device_get_type; gvir_config_domain_disk_get_type; -- 1.7.10

On Wed, Apr 11, 2012 at 03:48:09PM +0200, Christophe Fergeau wrote: [..snip..]
--- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -69,6 +69,8 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_console_set_target_type; gvir_config_domain_console_target_type_get_type;
+ gvir_config_domain_controller_get_type; + gvir_config_domain_device_get_type;
gvir_config_domain_disk_get_type; -- Wouldn't this need to go into LIBVIRT_GCONFIG_0.0.8 by either introducing a new section or bumping LIBVIRT_GCONFIG_0.0.X in general? Cheers, -- Guido

On Thu, Apr 12, 2012 at 12:06:52PM +0200, Guido Günther wrote:
On Wed, Apr 11, 2012 at 03:48:09PM +0200, Christophe Fergeau wrote: [..snip..]
--- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -69,6 +69,8 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_console_set_target_type; gvir_config_domain_console_target_type_get_type;
+ gvir_config_domain_controller_get_type; + gvir_config_domain_device_get_type;
gvir_config_domain_disk_get_type; -- Wouldn't this need to go into LIBVIRT_GCONFIG_0.0.8 by either introducing a new section or bumping LIBVIRT_GCONFIG_0.0.X in general?
Yep, we generally do this once before releasing (and forget :-/), I'll add this to the first patch adding new symbols. Christophe

--- .../libvirt-gconfig-domain-controller.c | 29 ++++++++++++++++++++ .../libvirt-gconfig-domain-controller.h | 4 +++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 35 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.c b/libvirt-gconfig/libvirt-gconfig-domain-controller.c index 3aea5ba..d8d9ffb 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.c @@ -48,3 +48,32 @@ static void gvir_config_domain_controller_init(GVirConfigDomainController *contr controller->priv = GVIR_CONFIG_DOMAIN_CONTROLLER_GET_PRIVATE(controller); } + +void gvir_config_domain_controller_set_index(GVirConfigDomainController *controller, + guint index) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER(controller)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(controller), + "index", G_TYPE_UINT, + index, NULL); +} + +guint gvir_config_domain_controller_get_index(GVirConfigDomainController *controller) +{ + const char *index_str; + char *end; + guint index; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER(controller), 0); + + index_str = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(controller), + NULL, "index"); + if (index_str == 0) + return 0; + + index = strtoul(index_str, &end, 0); + g_return_val_if_fail(*end == '\0', 0); + + return index; +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.h b/libvirt-gconfig/libvirt-gconfig-domain-controller.h index 41847c3..7cdabe2 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.h @@ -58,6 +58,10 @@ struct _GVirConfigDomainControllerClass GType gvir_config_domain_controller_get_type(void); +void gvir_config_domain_controller_set_index(GVirConfigDomainController *controller, + guint index); +guint gvir_config_domain_controller_get_index(GVirConfigDomainController *controller); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_CONTROLLER_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7b590ff..a7d2c19 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -70,6 +70,8 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_console_target_type_get_type; gvir_config_domain_controller_get_type; + gvir_config_domain_controller_get_index; + gvir_config_domain_controller_set_index; gvir_config_domain_device_get_type; -- 1.7.10

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-controller-usb.c | 72 ++++++++++++++++++++ .../libvirt-gconfig-domain-controller-usb.h | 66 ++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 3 +- libvirt-gconfig/libvirt-gconfig.sym | 4 ++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 06b95af..43582b0 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -21,6 +21,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-clock.h \ libvirt-gconfig-domain-console.h \ libvirt-gconfig-domain-controller.h \ + libvirt-gconfig-domain-controller-usb.h \ libvirt-gconfig-domain-device.h \ libvirt-gconfig-domain-disk.h \ libvirt-gconfig-domain-filesys.h \ @@ -75,6 +76,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-clock.c \ libvirt-gconfig-domain-console.c \ libvirt-gconfig-domain-controller.c \ + libvirt-gconfig-domain-controller-usb.c \ libvirt-gconfig-domain-device.c \ libvirt-gconfig-domain-disk.c \ libvirt-gconfig-domain-filesys.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c new file mode 100644 index 0000000..2b7e0b6 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-domain-controller-usb.c: libvirt domain USB controller 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_CONTROLLER_USB_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, GVirConfigDomainControllerUsbPrivate)) + +struct _GVirConfigDomainControllerUsbPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainControllerUsb, gvir_config_domain_controller_usb, GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER); + + +static void gvir_config_domain_controller_usb_class_init(GVirConfigDomainControllerUsbClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainControllerUsbPrivate)); +} + + +static void gvir_config_domain_controller_usb_init(GVirConfigDomainControllerUsb *controller_usb) +{ + g_debug("Init GVirConfigDomainControllerUsb=%p", controller_usb); + + controller_usb->priv = GVIR_CONFIG_DOMAIN_CONTROLLER_USB_GET_PRIVATE(controller_usb); +} + + +GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, + "controller", NULL); + gvir_config_object_set_attribute(object, "type", "usb", NULL); + return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object); +} + +GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, + "controller", NULL, xml, error); + gvir_config_object_set_attribute(object, "type", "usb", NULL); + return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h new file mode 100644 index 0000000..2d50340 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h @@ -0,0 +1,66 @@ +/* + * libvirt-gconfig-domain-controller-usb.h: libvirt domain USB controller 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#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_CONTROLLER_USB_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CONTROLLER_USB_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB (gvir_config_domain_controller_usb_get_type ()) +#define GVIR_CONFIG_DOMAIN_CONTROLLER_USB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, GVirConfigDomainControllerUsb)) +#define GVIR_CONFIG_DOMAIN_CONTROLLER_USB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, GVirConfigDomainControllerUsbClass)) +#define GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB)) +#define GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB)) +#define GVIR_CONFIG_DOMAIN_CONTROLLER_USB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, GVirConfigDomainControllerUsbClass)) + +typedef struct _GVirConfigDomainControllerUsb GVirConfigDomainControllerUsb; +typedef struct _GVirConfigDomainControllerUsbPrivate GVirConfigDomainControllerUsbPrivate; +typedef struct _GVirConfigDomainControllerUsbClass GVirConfigDomainControllerUsbClass; + +struct _GVirConfigDomainControllerUsb +{ + GVirConfigDomainController parent; + + GVirConfigDomainControllerUsbPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainControllerUsbClass +{ + GVirConfigDomainControllerClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_controller_usb_get_type(void); + +GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new(void); +GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(const gchar *xml, + GError **error); +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CONTROLLER_USB_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index c433060..846a1d3 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -1,7 +1,7 @@ /* * libvirt-gconfig.h: libvirt gconfig integration * - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-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 @@ -38,6 +38,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain-console.h> #include <libvirt-gconfig/libvirt-gconfig-domain-controller.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h> #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index a7d2c19..9453a97 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -73,6 +73,10 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_controller_get_index; gvir_config_domain_controller_set_index; + gvir_config_domain_controller_usb_get_type; + gvir_config_domain_controller_usb_new; + gvir_config_domain_controller_usb_new_from_xml; + gvir_config_domain_device_get_type; gvir_config_domain_disk_get_type; -- 1.7.10

--- libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c | 13 +++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h | 15 +++++++++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 30 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c index 2b7e0b6..5da1cbd 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c @@ -70,3 +70,16 @@ GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(co gvir_config_object_set_attribute(object, "type", "usb", NULL); return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object); } + +void gvir_config_domain_controller_usb_set_model(GVirConfigDomainControllerUsb *controller, + GVirConfigDomainControllerUsbModel model) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(controller)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(controller), + "model", + GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB_MODEL, + model, + NULL); + +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h index 2d50340..f8cc4bf 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h @@ -56,11 +56,26 @@ struct _GVirConfigDomainControllerUsbClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_PIIX3_UHCI, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_PIIX4_UHCI, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_EHCI, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_VT82C686B_UHCI, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_PCI_OHCI +} GVirConfigDomainControllerUsbModel; + GType gvir_config_domain_controller_usb_get_type(void); GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new(void); GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(const gchar *xml, GError **error); +void gvir_config_domain_controller_usb_set_model(GVirConfigDomainControllerUsb *controller, + GVirConfigDomainControllerUsbModel model); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_CONTROLLER_USB_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 9453a97..a0dca07 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -74,8 +74,10 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_controller_set_index; gvir_config_domain_controller_usb_get_type; + gvir_config_domain_controller_usb_model_get_type; gvir_config_domain_controller_usb_new; gvir_config_domain_controller_usb_new_from_xml; + gvir_config_domain_controller_usb_set_model; gvir_config_domain_device_get_type; -- 1.7.10

--- .../libvirt-gconfig-domain-controller-usb.c | 21 ++++++++++++++++++++ .../libvirt-gconfig-domain-controller-usb.h | 3 +++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 25 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c index 5da1cbd..8ab3e25 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.c @@ -83,3 +83,24 @@ void gvir_config_domain_controller_usb_set_model(GVirConfigDomainControllerUsb * NULL); } + +void gvir_config_domain_controller_usb_set_master(GVirConfigDomainControllerUsb *controller, + GVirConfigDomainControllerUsb *master, + guint startport) +{ + guint index; + char *startport_str; + + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(controller)); + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(master)); + + index = gvir_config_domain_controller_get_index(GVIR_CONFIG_DOMAIN_CONTROLLER(master)); + gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), index); + startport_str = g_strdup_printf("%d", startport); + gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(controller), + "master", + "startport", + startport_str); + g_free(startport_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h index f8cc4bf..b87921c 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h @@ -75,6 +75,9 @@ GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(co GError **error); void gvir_config_domain_controller_usb_set_model(GVirConfigDomainControllerUsb *controller, GVirConfigDomainControllerUsbModel model); +void gvir_config_domain_controller_usb_set_master(GVirConfigDomainControllerUsb *controller, + GVirConfigDomainControllerUsb *master, + guint startport); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index a0dca07..06d7b32 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -77,6 +77,7 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_controller_usb_model_get_type; gvir_config_domain_controller_usb_new; gvir_config_domain_controller_usb_new_from_xml; + gvir_config_domain_controller_usb_set_master; gvir_config_domain_controller_usb_set_model; gvir_config_domain_device_get_type; -- 1.7.10

--- libvirt-gconfig/tests/test-domain-create.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 4ee33aa..7be9fc2 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -199,8 +199,33 @@ int main(int argc, char **argv) devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(channel)); /* spice usb redirection */ + GVirConfigDomainControllerUsb *ehci; + GVirConfigDomainControllerUsb *uhci1; + GVirConfigDomainControllerUsb *uhci2; + GVirConfigDomainControllerUsb *uhci3; GVirConfigDomainRedirdev *redirdev; + ehci = gvir_config_domain_controller_usb_new(); + gvir_config_domain_controller_usb_set_model(ehci, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1); + gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(ehci), 7); + uhci1 = gvir_config_domain_controller_usb_new(); + gvir_config_domain_controller_usb_set_model(uhci1, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1); + gvir_config_domain_controller_usb_set_master(uhci1, ehci, 0); + uhci2 = gvir_config_domain_controller_usb_new(); + gvir_config_domain_controller_usb_set_model(uhci2, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2); + gvir_config_domain_controller_usb_set_master(uhci2, ehci, 2); + uhci3 = gvir_config_domain_controller_usb_new(); + gvir_config_domain_controller_usb_set_model(uhci3, + GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3); + gvir_config_domain_controller_usb_set_master(uhci3, ehci, 4); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(ehci)); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci1)); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci2)); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci3)); + redirdev = gvir_config_domain_redirdev_new(); gvir_config_domain_redirdev_set_bus(redirdev, GVIR_CONFIG_DOMAIN_REDIRDEV_BUS_USB); -- 1.7.10

This is an abstract type which will be the base class for device addresses. --- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-domain-address.c | 50 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-address.h | 63 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 2 + 5 files changed, 118 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 43582b0..0172d06 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -13,6 +13,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-domain.h \ + libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-channel.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ @@ -68,6 +69,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-domain.c \ + libvirt-gconfig-domain-address.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-address.c b/libvirt-gconfig/libvirt-gconfig-domain-address.c new file mode 100644 index 0000000..d0cf8c1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address.c @@ -0,0 +1,50 @@ +/* + * libvirt-gconfig-domain-address.c: libvirt domain address 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_ADDRESS_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS, GVirConfigDomainAddressPrivate)) + +struct _GVirConfigDomainAddressPrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainAddress, gvir_config_domain_address, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_domain_address_class_init(GVirConfigDomainAddressClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainAddressPrivate)); +} + + +static void gvir_config_domain_address_init(GVirConfigDomainAddress *address) +{ + g_debug("Init GVirConfigDomainAddress=%p", address); + + address->priv = GVIR_CONFIG_DOMAIN_ADDRESS_GET_PRIVATE(address); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address.h b/libvirt-gconfig/libvirt-gconfig-domain-address.h new file mode 100644 index 0000000..6866ee8 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address.h @@ -0,0 +1,63 @@ +/* + * libvirt-gconfig-domain-address.h: libvirt device address 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#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_ADDRESS_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_ADDRESS (gvir_config_domain_address_get_type ()) +#define GVIR_CONFIG_DOMAIN_ADDRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS, GVirConfigDomainAddress)) +#define GVIR_CONFIG_DOMAIN_ADDRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS, GVirConfigDomainAddressClass)) +#define GVIR_CONFIG_IS_DOMAIN_ADDRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS)) +#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS)) +#define GVIR_CONFIG_DOMAIN_ADDRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS, GVirConfigDomainAddressClass)) + +typedef struct _GVirConfigDomainAddress GVirConfigDomainAddress; +typedef struct _GVirConfigDomainAddressPrivate GVirConfigDomainAddressPrivate; +typedef struct _GVirConfigDomainAddressClass GVirConfigDomainAddressClass; + +struct _GVirConfigDomainAddress +{ + GVirConfigObject parent; + + GVirConfigDomainAddressPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainAddressClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_address_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 846a1d3..69fbd42 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -30,6 +30,7 @@ #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-address.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 06d7b32..21c9530 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -34,6 +34,8 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_set_virt_type; gvir_config_domain_virt_type_get_type; + gvir_config_domain_address_get_type; + gvir_config_domain_channel_get_type; gvir_config_domain_channel_new; gvir_config_domain_channel_new_from_xml; -- 1.7.10

It already has the needed setters. --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-address-pci.c | 124 ++++++++++++++++++++ .../libvirt-gconfig-domain-address-pci.h | 78 ++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 9 ++ 5 files changed, 214 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address-pci.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address-pci.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 0172d06..b69ed9d 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -14,6 +14,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ + libvirt-gconfig-domain-address-pci.h \ libvirt-gconfig-domain-channel.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ @@ -70,6 +71,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ + libvirt-gconfig-domain-address-pci.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-address-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c new file mode 100644 index 0000000..48e3872 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.c @@ -0,0 +1,124 @@ +/* + * libvirt-gconfig-domain-address-pci.c: libvirt pci device address 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPciPrivate)) + +struct _GVirConfigDomainAddressPciPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainAddressPci, gvir_config_domain_address_pci, GVIR_CONFIG_TYPE_DOMAIN_ADDRESS); + + +static void gvir_config_domain_address_pci_class_init(GVirConfigDomainAddressPciClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainAddressPciPrivate)); +} + + +static void gvir_config_domain_address_pci_init(GVirConfigDomainAddressPci *address) +{ + g_debug("Init GVirConfigDomainAddressPci=%p", address); + + address->priv = GVIR_CONFIG_DOMAIN_ADDRESS_PCI_GET_PRIVATE(address); +} + + +GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, + "address", NULL); + gvir_config_object_set_attribute(object, "type", "pci", NULL); + return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(object); +} + +GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, + "address", NULL, xml, error); + gvir_config_object_set_attribute(object, "type", "pci", NULL); + return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(object); +} + +static void set_attribute_hex(GVirConfigDomainAddressPci *address, + const char *attr_name, + guint attr_val, + guint min_val, + guint max_val, + guint size) +{ + char *hex_str; + char *format; + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address)); + g_return_if_fail((attr_val >= min_val) && (attr_val <= max_val)); + + format = g_strdup_printf("0x%%0%dx", size); + hex_str = g_strdup_printf(format, attr_val); + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address), + attr_name, hex_str, NULL); + g_free(hex_str); + g_free(format); +} + +void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, + guint16 pci_domain) +{ + set_attribute_hex(address, "domain", pci_domain, 0, G_MAXUINT16, 4); +} + +void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, + guchar bus) +{ + set_attribute_hex(address, "bus", bus, 0, G_MAXUINT8, 2); +} + +void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, + guchar slot) +{ + set_attribute_hex(address, "slot", slot, 0, 0x1f, 2); +} + +void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, + guchar function) +{ + set_attribute_hex(address, "function", function, 0, 7, 1); +} + +void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, + gboolean multifunction) +{ + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address), + "multifunction", + multifunction?"on":"off", NULL); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h new file mode 100644 index 0000000..8d722bb --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-pci.h @@ -0,0 +1,78 @@ +/* + * libvirt-gconfig-domain-address-pci.h: libvirt PCI device address 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#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_ADDRESS_PCI_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_PCI_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI (gvir_config_domain_address_pci_get_type ()) +#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPci)) +#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPciClass)) +#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI)) +#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI)) +#define GVIR_CONFIG_DOMAIN_ADDRESS_PCI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI, GVirConfigDomainAddressPciClass)) + +typedef struct _GVirConfigDomainAddressPci GVirConfigDomainAddressPci; +typedef struct _GVirConfigDomainAddressPciPrivate GVirConfigDomainAddressPciPrivate; +typedef struct _GVirConfigDomainAddressPciClass GVirConfigDomainAddressPciClass; + +struct _GVirConfigDomainAddressPci +{ + GVirConfigDomainAddress parent; + + GVirConfigDomainAddressPciPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainAddressPciClass +{ + GVirConfigDomainAddressClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_address_pci_get_type(void); + +GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void); +GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new_from_xml(const gchar *xml, + GError **error); + +void gvir_config_domain_address_pci_set_domain(GVirConfigDomainAddressPci *address, + guint16 pci_domain); +void gvir_config_domain_address_pci_set_bus(GVirConfigDomainAddressPci *address, + guchar bus); +void gvir_config_domain_address_pci_set_slot(GVirConfigDomainAddressPci *address, + guchar slot); +void gvir_config_domain_address_pci_set_function(GVirConfigDomainAddressPci *address, + guchar function); +void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address, + gboolean multifunction); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_PCI_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 69fbd42..28d9c86 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -31,6 +31,7 @@ #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.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 21c9530..39e8623 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -36,6 +36,15 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_address_get_type; + gvir_config_domain_address_pci_get_type; + gvir_config_domain_address_pci_new; + gvir_config_domain_address_pci_new_from_xml; + gvir_config_domain_address_pci_set_bus; + gvir_config_domain_address_pci_set_domain; + gvir_config_domain_address_pci_set_function; + gvir_config_domain_address_pci_set_multifunction; + gvir_config_domain_address_pci_set_slot; + gvir_config_domain_channel_get_type; gvir_config_domain_channel_new; gvir_config_domain_channel_new_from_xml; -- 1.7.10

--- libvirt-gconfig/libvirt-gconfig-domain-controller.c | 10 ++++++++++ libvirt-gconfig/libvirt-gconfig-domain-controller.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 13 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.c b/libvirt-gconfig/libvirt-gconfig-domain-controller.c index d8d9ffb..813c934 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.c @@ -77,3 +77,13 @@ guint gvir_config_domain_controller_get_index(GVirConfigDomainController *contro return index; } + +void gvir_config_domain_controller_set_address(GVirConfigDomainController *controller, + GVirConfigDomainAddress *address) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER(controller)); + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS(address)); + + gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(controller), + GVIR_CONFIG_OBJECT(address)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-controller.h b/libvirt-gconfig/libvirt-gconfig-domain-controller.h index 7cdabe2..ebd3387 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-controller.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-controller.h @@ -61,6 +61,8 @@ GType gvir_config_domain_controller_get_type(void); void gvir_config_domain_controller_set_index(GVirConfigDomainController *controller, guint index); guint gvir_config_domain_controller_get_index(GVirConfigDomainController *controller); +void gvir_config_domain_controller_set_address(GVirConfigDomainController *controller, + GVirConfigDomainAddress *address); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 39e8623..57eb04f 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -81,6 +81,7 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_console_target_type_get_type; gvir_config_domain_controller_get_type; + gvir_config_domain_controller_set_address; gvir_config_domain_controller_get_index; gvir_config_domain_controller_set_index; -- 1.7.10

--- libvirt-gconfig/tests/test-domain-create.c | 54 +++++++++++++++++++--------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 7be9fc2..cdee883 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -43,6 +43,35 @@ const char *features[] = { "foo", "bar", "baz", NULL }; g_free(alloced_str); \ } G_STMT_END + +static GVirConfigDomainControllerUsb * +create_usb_controller(GVirConfigDomainControllerUsbModel model, guint index, + GVirConfigDomainControllerUsb *master, guint start_port, + guint domain, guint bus, guint slot, guint function, + gboolean multifunction) +{ + GVirConfigDomainControllerUsb *controller; + GVirConfigDomainAddressPci *address; + + controller = gvir_config_domain_controller_usb_new(); + gvir_config_domain_controller_usb_set_model(controller, model); + gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), index); + if (master) + gvir_config_domain_controller_usb_set_master(controller, master, start_port); + address = gvir_config_domain_address_pci_new(); + gvir_config_domain_address_pci_set_domain(address, domain); + gvir_config_domain_address_pci_set_bus(address, bus); + gvir_config_domain_address_pci_set_slot(address, slot); + gvir_config_domain_address_pci_set_function(address, function); + if (multifunction) + gvir_config_domain_address_pci_set_multifunction(address, multifunction); + gvir_config_domain_controller_set_address(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), + GVIR_CONFIG_DOMAIN_ADDRESS(address)); + g_object_unref(G_OBJECT(address)); + + return controller; +} + int main(int argc, char **argv) { GVirConfigDomain *domain; @@ -205,25 +234,18 @@ int main(int argc, char **argv) GVirConfigDomainControllerUsb *uhci3; GVirConfigDomainRedirdev *redirdev; - ehci = gvir_config_domain_controller_usb_new(); - gvir_config_domain_controller_usb_set_model(ehci, - GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1); - gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(ehci), 7); - uhci1 = gvir_config_domain_controller_usb_new(); - gvir_config_domain_controller_usb_set_model(uhci1, - GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1); - gvir_config_domain_controller_usb_set_master(uhci1, ehci, 0); - uhci2 = gvir_config_domain_controller_usb_new(); - gvir_config_domain_controller_usb_set_model(uhci2, - GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2); - gvir_config_domain_controller_usb_set_master(uhci2, ehci, 2); - uhci3 = gvir_config_domain_controller_usb_new(); - gvir_config_domain_controller_usb_set_model(uhci3, - GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3); - gvir_config_domain_controller_usb_set_master(uhci3, ehci, 4); + ehci = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1, + 1, NULL, 0, 0, 0, 8, 7, FALSE); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(ehci)); + uhci1 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1, + 7, ehci, 0, 0, 0, 8, 0, TRUE); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci1)); + uhci2 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2, + 7, ehci, 2, 0, 0, 8, 1, FALSE); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci2)); + uhci3 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3, + 7, ehci, 4, 0, 0, 8, 2, FALSE); + g_assert(gvir_config_domain_controller_get_index(GVIR_CONFIG_DOMAIN_CONTROLLER(uhci1)) == 1); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci3)); redirdev = gvir_config_domain_redirdev_new(); -- 1.7.10

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-address-usb.c | 96 ++++++++++++++++++++ .../libvirt-gconfig-domain-address-usb.h | 71 +++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 6 ++ 5 files changed, 176 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address-usb.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-address-usb.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index b69ed9d..e1b67b2 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ + libvirt-gconfig-domain-address-usb.h \ libvirt-gconfig-domain-channel.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ @@ -72,6 +73,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ + libvirt-gconfig-domain-address-usb.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-address-usb.c b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c new file mode 100644 index 0000000..3da5811 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c @@ -0,0 +1,96 @@ +/* + * libvirt-gconfig-domain-address-usb.c: libvirt USB device address 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_ADDRESS_USB_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, GVirConfigDomainAddressUsbPrivate)) + +struct _GVirConfigDomainAddressUsbPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainAddressUsb, gvir_config_domain_address_usb, GVIR_CONFIG_TYPE_DOMAIN_ADDRESS); + + +static void gvir_config_domain_address_usb_class_init(GVirConfigDomainAddressUsbClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainAddressUsbPrivate)); +} + + +static void gvir_config_domain_address_usb_init(GVirConfigDomainAddressUsb *address) +{ + g_debug("Init GVirConfigDomainAddressUsb=%p", address); + + address->priv = GVIR_CONFIG_DOMAIN_ADDRESS_USB_GET_PRIVATE(address); +} + + +GVirConfigDomainAddressUsb *gvir_config_domain_address_usb_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, + "address", NULL); + gvir_config_object_set_attribute(object, "type", "usb", NULL); + return GVIR_CONFIG_DOMAIN_ADDRESS_USB(object); +} + +GVirConfigDomainAddressUsb *gvir_config_domain_address_usb_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, + "address", NULL, xml, error); + gvir_config_object_set_attribute(object, "type", "usb", NULL); + return GVIR_CONFIG_DOMAIN_ADDRESS_USB(object); +} + +void gvir_config_domain_address_usb_set_bus(GVirConfigDomainAddressUsb *address, + guint16 bus) +{ + gchar *bus_str; + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_USB(address)); + g_return_if_fail(bus <= 0xfff); + + bus_str = g_strdup_printf("0x%03x", bus); + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address), + "bus", bus_str, NULL); + g_free(bus_str); +} + +void gvir_config_domain_address_usb_set_port(GVirConfigDomainAddressUsb *address, + const char *port) +{ + /* port is a dotted notation of up to four octets, such as 1.2 or 2.1.3.1, + * that's why the argument is a char * and not an unsigned int */ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_USB(address)); + + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address), + "port", port, NULL); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-address-usb.h b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.h new file mode 100644 index 0000000..c7f2f78 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-domain-address-usb.h: libvirt USB device address 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#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_ADDRESS_USB_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_USB_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB (gvir_config_domain_address_usb_get_type ()) +#define GVIR_CONFIG_DOMAIN_ADDRESS_USB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, GVirConfigDomainAddressUsb)) +#define GVIR_CONFIG_DOMAIN_ADDRESS_USB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, GVirConfigDomainAddressUsbClass)) +#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_USB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB)) +#define GVIR_CONFIG_IS_DOMAIN_ADDRESS_USB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB)) +#define GVIR_CONFIG_DOMAIN_ADDRESS_USB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_USB, GVirConfigDomainAddressUsbClass)) + +typedef struct _GVirConfigDomainAddressUsb GVirConfigDomainAddressUsb; +typedef struct _GVirConfigDomainAddressUsbPrivate GVirConfigDomainAddressUsbPrivate; +typedef struct _GVirConfigDomainAddressUsbClass GVirConfigDomainAddressUsbClass; + +struct _GVirConfigDomainAddressUsb +{ + GVirConfigDomainAddress parent; + + GVirConfigDomainAddressUsbPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainAddressUsbClass +{ + GVirConfigDomainAddressClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_address_usb_get_type(void); + +GVirConfigDomainAddressUsb *gvir_config_domain_address_usb_new(void); +GVirConfigDomainAddressUsb *gvir_config_domain_address_usb_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_domain_address_usb_set_bus(GVirConfigDomainAddressUsb *address, + guint16 bus); +void gvir_config_domain_address_usb_set_port(GVirConfigDomainAddressUsb *address, + const char *port); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_ADDRESS_USB_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 28d9c86..fde6f03 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -32,6 +32,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain.h> #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-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 57eb04f..b2d4480 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -36,6 +36,12 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_address_get_type; + gvir_config_domain_address_usb_get_type; + gvir_config_domain_address_usb_new; + gvir_config_domain_address_usb_new_from_xml; + gvir_config_domain_address_usb_set_bus; + gvir_config_domain_address_usb_set_port; + gvir_config_domain_address_pci_get_type; gvir_config_domain_address_pci_new; gvir_config_domain_address_pci_new_from_xml; -- 1.7.10

--- libvirt-gconfig/libvirt-gconfig-domain-redirdev.c | 10 ++++++++++ libvirt-gconfig/libvirt-gconfig-domain-redirdev.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 13 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c index 30c370a..efecb5a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c @@ -80,3 +80,13 @@ void gvir_config_domain_redirdev_set_bus(GVirConfigDomainRedirdev *redirdev, bus, NULL); } + +void gvir_config_domain_redirdev_set_address(GVirConfigDomainRedirdev *redirdev, + GVirConfigDomainAddress *address) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_REDIRDEV(redirdev)); + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS(address)); + + gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(redirdev), + GVIR_CONFIG_OBJECT(address)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h index 99585bb..c5c43ed 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h @@ -67,6 +67,8 @@ GVirConfigDomainRedirdev *gvir_config_domain_redirdev_new_from_xml(const gchar * GError **error); void gvir_config_domain_redirdev_set_bus(GVirConfigDomainRedirdev *redirdev, GVirConfigDomainRedirdevBus bus); +void gvir_config_domain_redirdev_set_address(GVirConfigDomainRedirdev *redirdev, + GVirConfigDomainAddress *address); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b2d4480..6857320 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -230,6 +230,7 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_redirdev_bus_get_type; gvir_config_domain_redirdev_new; gvir_config_domain_redirdev_new_from_xml; + gvir_config_domain_redirdev_set_address; gvir_config_domain_redirdev_set_bus; gvir_config_domain_seclabel_get_type; -- 1.7.10

--- libvirt-gconfig/tests/test-domain-create.c | 46 +++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index cdee883..b6d8813 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -72,6 +72,34 @@ create_usb_controller(GVirConfigDomainControllerUsbModel model, guint index, return controller; } +static GVirConfigDomainRedirdev * +create_redirdev(guint bus, guint port) +{ + GVirConfigDomainRedirdev *redirdev; + GVirConfigDomainAddressUsb *address; + GVirConfigDomainChardevSourceSpiceVmc *spicevmc; + gchar *port_str; + + redirdev = gvir_config_domain_redirdev_new(); + gvir_config_domain_redirdev_set_bus(redirdev, + GVIR_CONFIG_DOMAIN_REDIRDEV_BUS_USB); + spicevmc = gvir_config_domain_chardev_source_spicevmc_new(); + gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(redirdev), + GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(spicevmc)); + g_object_unref(G_OBJECT(spicevmc)); + + address = gvir_config_domain_address_usb_new(); + gvir_config_domain_address_usb_set_bus(address, bus); + port_str = g_strdup_printf("%d", port); + gvir_config_domain_address_usb_set_port(address, port_str); + g_free(port_str); + gvir_config_domain_redirdev_set_address(redirdev, + GVIR_CONFIG_DOMAIN_ADDRESS(address)); + g_object_unref(G_OBJECT(address)); + + return redirdev; +} + int main(int argc, char **argv) { GVirConfigDomain *domain; @@ -248,15 +276,17 @@ int main(int argc, char **argv) g_assert(gvir_config_domain_controller_get_index(GVIR_CONFIG_DOMAIN_CONTROLLER(uhci1)) == 1); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(uhci3)); - redirdev = gvir_config_domain_redirdev_new(); - gvir_config_domain_redirdev_set_bus(redirdev, - GVIR_CONFIG_DOMAIN_REDIRDEV_BUS_USB); - spicevmc = gvir_config_domain_chardev_source_spicevmc_new(); - gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(redirdev), - GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(spicevmc)); - g_object_unref(G_OBJECT(spicevmc)); - devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(redirdev)); + /* three redirdev channels allows to redirect a maximum of 3 USB + * devices at a time. The address which create_redirdev assigns to the + * redirdev object is optional + */ + redirdev = create_redirdev(0, 3); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(redirdev)); + redirdev = create_redirdev(0, 4); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(redirdev)); + redirdev = create_redirdev(0, 5); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(redirdev)); gvir_config_domain_set_devices(domain, devices); g_list_foreach(devices, (GFunc)g_object_unref, NULL); -- 1.7.10

This function is a helper function which adds all the needed devices for working USB support in the guest. This can be done manually, but is a bit tedious, hence this helper. --- libvirt-gconfig/libvirt-gconfig-domain.c | 41 ++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 1 + libvirt-gconfig/tests/test-domain-create.c | 7 +++++ 4 files changed, 51 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index 33a69e3..05860bf 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -517,3 +517,44 @@ gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain, lookup_namespaced_node, &data); return gvir_config_xml_node_to_string(data.node); } + +static GVirConfigDomainControllerUsb * +create_usb_controller(GVirConfigDomainControllerUsbModel model, guint index, + GVirConfigDomainControllerUsb *master, guint start_port) +{ + GVirConfigDomainControllerUsb *controller; + + controller = gvir_config_domain_controller_usb_new(); + gvir_config_domain_controller_usb_set_model(controller, model); + gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), index); + if (master) + gvir_config_domain_controller_usb_set_master(controller, master, start_port); + + return controller; +} + +void gvir_config_domain_setup_default_usb_controllers(GVirConfigDomain *domain) +{ + /* spice usb redirection */ + GVirConfigDomainControllerUsb *ehci; + GVirConfigDomainControllerUsb *uhci1; + GVirConfigDomainControllerUsb *uhci2; + GVirConfigDomainControllerUsb *uhci3; + + ehci = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1, + 0, NULL, 0); + gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(ehci)); + uhci1 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1, + 0, ehci, 0); + gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci1)); + g_object_unref(G_OBJECT(uhci1)); + uhci2 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2, + 0, ehci, 2); + gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci2)); + g_object_unref(G_OBJECT(uhci2)); + uhci3 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3, + 0, ehci, 4); + gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci3)); + g_object_unref(G_OBJECT(uhci3)); + g_object_unref(G_OBJECT(ehci)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 1dbfd95..36f1fcd 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -134,6 +134,8 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain, gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain, const gchar *ns_uri); +void gvir_config_domain_setup_default_usb_controllers(GVirConfigDomain *domain); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 6857320..ada6aa2 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -32,6 +32,7 @@ LIBVIRT_GCONFIG_0.0.4 { gvir_config_domain_get_vcpus; gvir_config_domain_set_vcpus; gvir_config_domain_set_virt_type; + gvir_config_domain_setup_default_usb_controllers; gvir_config_domain_virt_type_get_type; gvir_config_domain_address_get_type; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index b6d8813..4828cd7 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -256,6 +256,7 @@ int main(int argc, char **argv) devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(channel)); /* spice usb redirection */ + GVirConfigDomainControllerUsb *ehci; GVirConfigDomainControllerUsb *uhci1; GVirConfigDomainControllerUsb *uhci2; @@ -293,6 +294,12 @@ int main(int argc, char **argv) g_list_free(devices); devices = NULL; + /* this helper function adds everything that is needed for USB support in the host, + * the manual creation of the controller below is just for testing/if + * more control over the controller devices is needed. + */ + gvir_config_domain_setup_default_usb_controllers(domain); + gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://foo", NULL); gvir_config_domain_set_custom_xml(domain, "<foo/>", "nsbar", "http://bar", NULL); gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://bar", NULL); -- 1.7.10

On Wed, Apr 11, 2012 at 3:48 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+void gvir_config_domain_setup_default_usb_controllers(GVirConfigDomain *domain)
I suggest it takes an enum, such as CONFIG_DOMAIN_SETUP_USB_CONTROLLERS_ICH9 or USB2 regards -- Marc-André Lureau

On Wed, Apr 11, 2012 at 04:29:28PM +0200, Marc-André Lureau wrote:
On Wed, Apr 11, 2012 at 3:48 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+void gvir_config_domain_setup_default_usb_controllers(GVirConfigDomain *domain)
I suggest it takes an enum, such as CONFIG_DOMAIN_SETUP_USB_CONTROLLERS_ICH9 or USB2
What would _USB2 do? Add an _EHCI controller, plus either _PIIX3_UHCI or _PIIX4_UHCI? Christophe

On Wed, Apr 11, 2012 at 5:29 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What would _USB2 do? Add an _EHCI controller, plus either _PIIX3_UHCI or _PIIX4_UHCI?
From what I remember Hans told me, all the 4 ehci + uhci companions controllers are needed for a proper USB2 setup.
I suggest an enum value such as CONFIG_DOMAIN_SETUP_USB_CONTROLLERS_USB2 for default USB2 setup (using the ICH9 controllers, but could be changed someday perhaps) -- Marc-André Lureau

On Wed, Apr 11, 2012 at 06:01:42PM +0200, Marc-André Lureau wrote:
On Wed, Apr 11, 2012 at 5:29 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What would _USB2 do? Add an _EHCI controller, plus either _PIIX3_UHCI or _PIIX4_UHCI?
From what I remember Hans told me, all the 4 ehci + uhci companions controllers are needed for a proper USB2 setup.
I suggest an enum value such as CONFIG_DOMAIN_SETUP_USB_CONTROLLERS_USB2 for default USB2 setup (using the ICH9 controllers, but could be changed someday perhaps)
Ah ok, you want an enum for future-safety, not because you have a specific usecase in mind? I thought you already wanted to support various cases with this enum. My initial reaction is that one default usb setup (which can be vary depending on what properties were set on the domain) should be enough and that the enum is not needed, especially since more sophisticated setups can be achieved using the "raw" API. But I think years of libvirt development disagree with my initial reaction ;) Christophe

On Wed, Apr 11, 2012 at 06:01:42PM +0200, Marc-André Lureau wrote:
On Wed, Apr 11, 2012 at 5:29 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What would _USB2 do? Add an _EHCI controller, plus either _PIIX3_UHCI or _PIIX4_UHCI?
From what I remember Hans told me, all the 4 ehci + uhci companions controllers are needed for a proper USB2 setup.
I suggest an enum value such as CONFIG_DOMAIN_SETUP_USB_CONTROLLERS_USB2 for default USB2 setup (using the ICH9 controllers, but could be changed someday perhaps)
When we get into such discussions, I question whether the API is appropriate for libvirt-gconfig. This API should be focusing on the mechanism for creating guest configs & trying to avoid policy based questions, which can be left upto higher level apps/APIs. The concept of 'default usb controllers' seems very policy based to me & different hypervisors will have different views of this. So IMHO we should not add this API Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Apr 11, 2012 at 05:19:33PM +0100, Daniel P. Berrange wrote:
The concept of 'default usb controllers' seems very policy based to me & different hypervisors will have different views of this.
So IMHO we should not add this API
I'm fine with dropping the patch. My feeling was that this API had a bit too much policy in it, but that it can be quite helpful. I guess now I have to replace it with actual API documentation for GVirConfigDomainControllerUsb so that people know they should not copy&paste all of what is done in the test program. Christophe

On Wed, Apr 11, 2012 at 6:19 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
The concept of 'default usb controllers' seems very policy based to me & different hypervisors will have different views of this.
This is a helper, it is not imposing any policy, but giving you sane default setup for ICH9 USB2 controllers if you want to. -- Marc-André Lureau

On Wed, Apr 11, 2012 at 06:51:48PM +0200, Marc-André Lureau wrote:
On Wed, Apr 11, 2012 at 6:19 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
The concept of 'default usb controllers' seems very policy based to me & different hypervisors will have different views of this.
This is a helper, it is not imposing any policy, but giving you sane default setup for ICH9 USB2 controllers if you want to.
Deciding on what the default setup is is some kind of policy ) But yeah it's not imposed since there are still the lower level function. That said, this function doing something magical is quite odd compared to the rest of libvirt-gconfig API which directly manipulate xml nodes. A "simpler" API will probably needed at some point, but maybe it belongs just above libvirt-gconfig instead of inside it. Christophe

On Wed, Apr 11, 2012 at 05:19:33PM +0100, Daniel P. Berrange wrote:
The concept of 'default usb controllers' seems very policy based to me & different hypervisors will have different views of this.
With respect to hypervisors, since the function has a GVirConfigDomain parameter, we could use it to have different defaults depending on the hypervisor/arch/... Christophe

Hi On Wed, Apr 11, 2012 at 3:48 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Here is the second version of the patch series implementing USB controller support in libvirt-gconfig. There's a bug fixed in GVirConfigDomainAddressUsb creation (type="usb" was missing) as well as a few small bug fixes/changes in the test program. I also added an additional patch implementing a gvir_config_domain_setup_default_usb_controllers to make adding usb controllers easier following Marc-André's suggestion.
Series look good. I would still keep the helper in 14/14. I don't think it hurts, and it saves the people from making mistakes when using USB2 controller... I don't personally think libvirt-glib should only be a dumb binding, it could also provide higher level common helpers or functionality such as this, and later manipulating the XML in certain way could be useful, like switching from VNC <-> Spice in a smart way etc... imho, this is not a policy as long as that logic/knowledge is not imposed, but left as a choice. ack for the 1-13 patches, let see if 14/14 still holds a chance :-) -- Marc-André Lureau
participants (4)
-
Christophe Fergeau
-
Daniel P. Berrange
-
Guido Günther
-
Marc-André Lureau