From 2fddb1448b91145dff229c2239db8fabfa987563 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 11 Jan 2013 17:32:13 +0000
Subject: [PATCH] Allow -soundhw option to kvm

For all of us that love to listen to music on our kvm virtual machines,
the -soundhw option is paramount.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/constants.py         | 3 +++
 lib/hypervisor/hv_kvm.py | 5 +++++
 man/gnt-instance.rst     | 6 ++++++
 3 files changed, 14 insertions(+)

diff --git a/lib/constants.py b/lib/constants.py
index 3b48426ae..a5a758d4c 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -830,6 +830,7 @@ HV_CPU_WEIGHT = "cpu_weight"
 HV_CPU_CORES = "cpu_cores"
 HV_CPU_THREADS = "cpu_threads"
 HV_CPU_SOCKETS = "cpu_sockets"
+HV_SOUNDHW = "soundhw"
 
 
 HVS_PARAMETER_TYPES = {
@@ -893,6 +894,7 @@ HVS_PARAMETER_TYPES = {
   HV_CPU_CORES: VTYPE_INT,
   HV_CPU_THREADS: VTYPE_INT,
   HV_CPU_SOCKETS: VTYPE_INT,
+  HV_SOUNDHW: VTYPE_STRING,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -1960,6 +1962,7 @@ HVC_DEFAULTS = {
     HV_CPU_CORES: 0,
     HV_CPU_THREADS: 0,
     HV_CPU_SOCKETS: 0,
+    HV_SOUNDHW: "",
     },
   HT_FAKE: {},
   HT_CHROOT: {
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index 94ce5b19f..aa629b5c7 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -535,6 +535,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_CPU_CORES: hv_base.OPT_NONNEGATIVE_INT_CHECK,
     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,
     }
 
   _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)",
@@ -1334,6 +1335,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if hvp[constants.HV_CPU_TYPE]:
       kvm_cmd.extend(["-cpu", hvp[constants.HV_CPU_TYPE]])
 
+    # As requested by music lovers
+    if hvp[constants.HV_SOUNDHW]:
+      kvm_cmd.extend(["-soundhw", hvp[constants.HV_SOUNDHW]])
+
     # 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 6e40d3771..9837e5ccc 100644
--- a/man/gnt-instance.rst
+++ b/man/gnt-instance.rst
@@ -649,6 +649,12 @@ cpu\_sockets
 
     Number of emulated CPU sockets.
 
+soundhw
+    Valid for the KVM hypervisor.
+
+    Comma separated list of emulated sounds cards, or "all" to enable
+    all the available ones.
+
 
 The ``-O (--os-parameters)`` option allows customisation of the OS
 parameters. The actual parameter names and values depends on the OS
-- 
GitLab