|
Packit |
a07778 |
/*
|
|
Packit |
a07778 |
* libvirt-gconfig-domain-controller-usb.c: libvirt domain USB controller configuration
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Copyright (C) 2012 Red Hat, Inc.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a07778 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License as published by the Free Software Foundation; either
|
|
Packit |
a07778 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a07778 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a07778 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a07778 |
* Lesser General Public License for more details.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License along with this library. If not, see
|
|
Packit |
a07778 |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Author: Christophe Fergeau <cfergeau@redhat.com>
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include <config.h>
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include "libvirt-gconfig/libvirt-gconfig.h"
|
|
Packit |
a07778 |
#include "libvirt-gconfig/libvirt-gconfig-private.h"
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* SECTION:libvirt-gconfig-domain-controller-usb
|
|
Packit |
a07778 |
* @title: USB Controller Configuration
|
|
Packit |
a07778 |
* @short_description: configuration of USB controllers
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* A #GVirConfigDomainControllerUsb represents an USB controller device.
|
|
Packit |
a07778 |
* A #GVirConfigDomain with #GVirConfigDomainControllerUsb devices will
|
|
Packit |
a07778 |
* be able to use USB devices.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Several USB controllers can be added to the same domain, for example
|
|
Packit |
a07778 |
* to have an USB1 and an USB2 controller.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* When using SPICE (see #GVirConfigGraphicsSpice), USB devices plugged
|
|
Packit |
a07778 |
* on the client can be forwarded to the guest through the use of
|
|
Packit |
a07778 |
* #GVirConfigDomainRedirDev.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* <example>
|
|
Packit |
a07778 |
* <title>Adding USB controllers to a standard x86 domain</title>
|
|
Packit |
a07778 |
* <para>
|
|
Packit |
a07778 |
* This example shows the recommended USB setup to get a virtual machine
|
|
Packit |
a07778 |
* looking like your usual x86 desktop or laptop.
|
|
Packit |
a07778 |
* </para>
|
|
Packit |
a07778 |
* <programlisting>
|
|
Packit |
a07778 |
* static GVirConfigDomainControllerUsb *
|
|
Packit |
a07778 |
* create_usb_controller(GVirConfigDomainControllerUsbModel model, guint index,
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb *master, guint start_port)
|
|
Packit |
a07778 |
* {
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb *controller;
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* controller = gvir_config_domain_controller_usb_new();
|
|
Packit |
a07778 |
* gvir_config_domain_controller_usb_set_model(controller, model);
|
|
Packit |
a07778 |
* gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), index);
|
|
Packit |
a07778 |
* if (master)
|
|
Packit |
a07778 |
* gvir_config_domain_controller_usb_set_master(controller, master, start_port);
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* return controller;
|
|
Packit |
a07778 |
* }
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* void setup_default_usb_controllers(GVirConfigDomain *domain)
|
|
Packit |
a07778 |
* {
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb *ehci;
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb *uhci1;
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb *uhci2;
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb *uhci3;
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* ehci = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1,
|
|
Packit |
a07778 |
* 0, NULL, 0);
|
|
Packit |
a07778 |
* gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(ehci));
|
|
Packit |
a07778 |
* uhci1 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1,
|
|
Packit |
a07778 |
* 0, ehci, 0);
|
|
Packit |
a07778 |
* gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci1));
|
|
Packit |
a07778 |
* g_object_unref(G_OBJECT(uhci1));
|
|
Packit |
a07778 |
* uhci2 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2,
|
|
Packit |
a07778 |
* 0, ehci, 2);
|
|
Packit |
a07778 |
* gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci2));
|
|
Packit |
a07778 |
* g_object_unref(G_OBJECT(uhci2));
|
|
Packit |
a07778 |
* uhci3 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3,
|
|
Packit |
a07778 |
* 0, ehci, 4);
|
|
Packit |
a07778 |
* gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci3));
|
|
Packit |
a07778 |
* g_object_unref(G_OBJECT(uhci3));
|
|
Packit |
a07778 |
* g_object_unref(G_OBJECT(ehci));
|
|
Packit |
a07778 |
*}
|
|
Packit |
a07778 |
* </programlisting>
|
|
Packit |
a07778 |
* </example>
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This class models libvirt XML nodes located at
|
|
Packit |
a07778 |
* <ulink url="http://libvirt.org/formatdomain.html#elementsControllers">
|
|
Packit |
a07778 |
* /domain/devices/controller[@type="usb"]</ulink>
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* GVirConfigDomainControllerUsb:
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* The #GVirConfigDomainControllerUsb struct is an opaque data structure
|
|
Packit |
a07778 |
* which is used to configure USB controllers on a domain. It should only
|
|
Packit |
a07778 |
* be accessed via the following functions.
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#define GVIR_CONFIG_DOMAIN_CONTROLLER_USB_GET_PRIVATE(obj) \
|
|
Packit |
a07778 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB, GVirConfigDomainControllerUsbPrivate))
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
struct _GVirConfigDomainControllerUsbPrivate
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
gboolean unused;
|
|
Packit |
a07778 |
};
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainControllerUsb, gvir_config_domain_controller_usb, GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_config_domain_controller_usb_class_init(GVirConfigDomainControllerUsbClass *klass G_GNUC_UNUSED)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_config_domain_controller_usb_init(GVirConfigDomainControllerUsb *controller_usb)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
controller_usb->priv = GVIR_CONFIG_DOMAIN_CONTROLLER_USB_GET_PRIVATE(controller_usb);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_config_domain_controller_usb_new:
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Creates a new #GVirConfigDomainControllerUsb with a reference count of 1.
|
|
Packit |
a07778 |
* gvir_config_domain_controller_set_index() must be called before
|
|
Packit |
a07778 |
* this controller is usable.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Returns: a new #GVirConfigDomainControllerUsb
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new(void)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirConfigObject *object;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB,
|
|
Packit |
a07778 |
"controller", NULL);
|
|
Packit |
a07778 |
gvir_config_object_set_attribute(object, "type", "usb", NULL);
|
|
Packit |
a07778 |
return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_config_domain_controller_usb_new_from_xml:
|
|
Packit |
a07778 |
* @xml: xml data to create the controller from
|
|
Packit |
a07778 |
* @error: return location for a #GError, or NULL
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Creates a new #GVirConfigDomainControllerUsb with a reference count of 1.
|
|
Packit |
a07778 |
* The controller object will be created using the XML description stored
|
|
Packit |
a07778 |
* in @xml. This is a fragment of libvirt domain XML whose root node is
|
|
Packit |
a07778 |
* <controller>.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Returns: a new #GVirConfigDomainControllerUsb, or NULL if @xml failed to
|
|
Packit |
a07778 |
* be parsed.
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new_from_xml(const gchar *xml,
|
|
Packit |
a07778 |
GError **error)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirConfigObject *object;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB,
|
|
Packit |
a07778 |
"controller", NULL, xml, error);
|
|
Packit |
a07778 |
if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "usb") != 0) {
|
|
Packit |
a07778 |
g_object_unref(G_OBJECT(object));
|
|
Packit |
a07778 |
g_return_val_if_reached(NULL);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_config_domain_controller_usb_set_model:
|
|
Packit |
a07778 |
* @controller: a #GVirConfigDomainControllerUsb
|
|
Packit |
a07778 |
* @model: the USB controller model
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Sets the model of @controller to @model.
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
void gvir_config_domain_controller_usb_set_model(GVirConfigDomainControllerUsb *controller,
|
|
Packit |
a07778 |
GVirConfigDomainControllerUsbModel model)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(controller));
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(controller),
|
|
Packit |
a07778 |
"model",
|
|
Packit |
a07778 |
GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB_MODEL,
|
|
Packit |
a07778 |
model,
|
|
Packit |
a07778 |
NULL);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_config_domain_controller_usb_set_master:
|
|
Packit |
a07778 |
* @controller: a #GVirConfigDomainControllerUsb
|
|
Packit |
a07778 |
* @master: the master #GVirConfigDomainControllerUsb
|
|
Packit |
a07778 |
* @startport: the start port number
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Sets @controller to be a companion controller of @master. @controller
|
|
Packit |
a07778 |
* will be exposed from port @startport on @master in the guest.
|
|
Packit |
a07778 |
* After this call, @controller's index will be set to @master's index.
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
void gvir_config_domain_controller_usb_set_master(GVirConfigDomainControllerUsb *controller,
|
|
Packit |
a07778 |
GVirConfigDomainControllerUsb *master,
|
|
Packit |
a07778 |
guint startport)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
guint index;
|
|
Packit |
a07778 |
char *startport_str;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(controller));
|
|
Packit |
a07778 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONTROLLER_USB(master));
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
index = gvir_config_domain_controller_get_index(GVIR_CONFIG_DOMAIN_CONTROLLER(master));
|
|
Packit |
a07778 |
gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), index);
|
|
Packit |
a07778 |
startport_str = g_strdup_printf("%d", startport);
|
|
Packit |
a07778 |
gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(controller),
|
|
Packit |
a07778 |
"master",
|
|
Packit |
a07778 |
"startport",
|
|
Packit |
a07778 |
startport_str);
|
|
Packit |
a07778 |
g_free(startport_str);
|
|
Packit |
a07778 |
}
|