From 156681c17771617464402ec87dffa06aa2a36920 Mon Sep 17 00:00:00 2001 From: Guido Trotter Date: Fri, 11 Jan 2013 17:47:09 +0000 Subject: [PATCH] kvm: support usb devices All in one go, comma separated usb devices of all types. Signed-off-by: Guido Trotter Reviewed-by: Michael Hanselmann --- lib/constants.py | 3 +++ lib/hypervisor/hv_kvm.py | 6 ++++++ man/gnt-instance.rst | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/lib/constants.py b/lib/constants.py index a5a758d..1344951 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -831,6 +831,7 @@ HV_CPU_CORES = "cpu_cores" HV_CPU_THREADS = "cpu_threads" HV_CPU_SOCKETS = "cpu_sockets" HV_SOUNDHW = "soundhw" +HV_USB_DEVICES = "usb_devices" HVS_PARAMETER_TYPES = { @@ -895,6 +896,7 @@ HVS_PARAMETER_TYPES = { HV_CPU_THREADS: VTYPE_INT, HV_CPU_SOCKETS: VTYPE_INT, HV_SOUNDHW: VTYPE_STRING, + HV_USB_DEVICES: VTYPE_STRING, } HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys()) @@ -1963,6 +1965,7 @@ HVC_DEFAULTS = { HV_CPU_THREADS: 0, HV_CPU_SOCKETS: 0, HV_SOUNDHW: "", + HV_USB_DEVICES: "", }, HT_FAKE: {}, HT_CHROOT: { diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index aa629b5..47b0330 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -536,6 +536,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): constants.HV_CPU_THREADS: hv_base.OPT_NONNEGATIVE_INT_CHECK, constants.HV_CPU_SOCKETS: hv_base.OPT_NONNEGATIVE_INT_CHECK, constants.HV_SOUNDHW: hv_base.NO_CHECK, + constants.HV_USB_DEVICES: hv_base.NO_CHECK, } _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)", @@ -1339,6 +1340,11 @@ class KVMHypervisor(hv_base.BaseHypervisor): if hvp[constants.HV_SOUNDHW]: kvm_cmd.extend(["-soundhw", hvp[constants.HV_SOUNDHW]]) + # Various types of usb devices, comma separated + if hvp[constants.HV_USB_DEVICES]: + for dev in hvp[constants.HV_USB_DEVICES].split(","): + kvm_cmd.extend(["-usbdevice", dev]) + # Save the current instance nics, but defer their expansion as parameters, # as we'll need to generate executable temp files for them. kvm_nics = instance.nics diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst index 9837e5c..276c824 100644 --- a/man/gnt-instance.rst +++ b/man/gnt-instance.rst @@ -655,6 +655,14 @@ soundhw Comma separated list of emulated sounds cards, or "all" to enable all the available ones. +usb\_devices + Valid for the KVM hypervisor. + + Comma separated list of usb devices. These can be emulated devices + or passthrough ones, and each one gets passed to kvm with its own + ``-usbdevice`` option. See the **qemu**\(1) manpage for the syntax + of the possible components. + The ``-O (--os-parameters)`` option allows customisation of the OS parameters. The actual parameter names and values depends on the OS -- 1.7.10.4