[libvirt] USB redirection support

Hey, This patch series adds the needed classes for apps to be able to use USB redirection. I've followed http://hansdegoede.livejournal.com/11084.html and added all the API needed to be able to get the same XML. However, I'm not 100% sure all these attributes are required, in particular the various addresses. Given that for now libvirt-gconfig users tend to reuse what test-domain-create does, it would be useful to know which parts are required and which are not to get working USB redirection. Thanks, 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.9.3

--- .../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.9.3

--- 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.9.3

--- .../libvirt-gconfig-domain-controller-usb.c | 13 +++++++++++++ .../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.9.3

--- .../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.9.3

--- 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.9.3

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.9.3

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.9.3

--- .../libvirt-gconfig-domain-controller.c | 10 ++++++++++ .../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.9.3

--- libvirt-gconfig/tests/test-domain-create.c | 53 +++++++++++++++++++--------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 7be9fc2..0c1aad5 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), 7); + 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,22 +234,14 @@ 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, + 7, NULL, 0, 0, 0, 8, 7, FALSE); + uhci1 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1, + 0, ehci, 0, 0, 0, 8, 0, TRUE); + uhci2 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2, + 0, ehci, 2, 0, 0, 8, 1, FALSE); + uhci3 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3, + 0, ehci, 4, 0, 0, 8, 2, FALSE); 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)); -- 1.7.9.3

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-address-usb.c | 94 ++++++++++++++++++++ .../libvirt-gconfig-domain-address-usb.h | 71 +++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 6 ++ 5 files changed, 174 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..8bac902 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-address-usb.c @@ -0,0 +1,94 @@ +/* + * 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); + 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); + 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.9.3

--- 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.9.3

--- libvirt-gconfig/tests/test-domain-create.c | 43 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 0c1aad5..2b2f734 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; @@ -247,15 +275,14 @@ int main(int argc, char **argv) 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); - 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)); + 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)); + redirdev = create_redirdev(0, 6); 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.9.3

On Fri, Apr 6, 2012 at 2:51 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
This patch series adds the needed classes for apps to be able to use USB redirection. I've followed http://hansdegoede.livejournal.com/11084.html and added all the API needed to be able to get the same XML. However, I'm not 100% sure all these attributes are required, in particular the various addresses.
You only need to specify the startport. (ie, look at how it's implemented in python-virtinst) This is the expected XML <controller type='usb' index='0' model='ich9-ehci1'/> <controller type='usb' index='0' model='ich9-uhci1'> <master startport='0'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> </controller> I would add a convenience function to add these controllers (in python-virtinst: add_usb_ich9_controllers) regards -- Marc-André Lureau

On Fri, Apr 06, 2012 at 02:51:35PM +0200, Christophe Fergeau wrote:
Hey,
This patch series adds the needed classes for apps to be able to use USB redirection. I've followed http://hansdegoede.livejournal.com/11084.html and added all the API needed to be able to get the same XML. However, I'm not 100% sure all these attributes are required, in particular the various addresses. Given that for now libvirt-gconfig users tend to reuse what test-domain-create does, it would be useful to know which parts are required and which are not to get working USB redirection.
Just noticed I had uncommitted changes in my tree which fix a bug in GVirConfigDomainAddressUsb and small issues in the testing code, will send a v2 Christophe
participants (2)
-
Christophe Fergeau
-
Marc-André Lureau