Add SPICE compression and streaming options
authorAndrea Spadaccini <spadaccio@google.com>
Thu, 8 Sep 2011 10:03:06 +0000 (11:03 +0100)
committerAndrea Spadaccini <spadaccio@google.com>
Tue, 13 Sep 2011 12:35:56 +0000 (13:35 +0100)
Add the following SPICE audio/image compression and video streaming
detection hypervisor options:

* spice_image_compression
* spice_jpeg_wan_compression
* spice_zlib_glz_wan_compression
* spice_streaming_video
* spice_playback_compression

Also add the related documentation and silence pylint R0914 warning
about too many local variables in hv_kvm._GenerateKVMRuntime.

Signed-off-by: Andrea Spadaccini <spadaccio@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/constants.py
lib/hypervisor/hv_kvm.py
man/gnt-instance.rst

index 80d32fd..13a1a07 100644 (file)
@@ -674,6 +674,11 @@ HV_VNC_X509_VERIFY = "vnc_x509_verify"
 HV_KVM_SPICE_BIND = "spice_bind"
 HV_KVM_SPICE_IP_VERSION = "spice_ip_version"
 HV_KVM_SPICE_PASSWORD_FILE = "spice_password_file"
+HV_KVM_SPICE_LOSSLESS_IMG_COMPR = "spice_image_compression"
+HV_KVM_SPICE_JPEG_IMG_COMPR = "spice_jpeg_wan_compression"
+HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR = "spice_zlib_glz_wan_compression"
+HV_KVM_SPICE_STREAMING_VIDEO_DETECTION = "spice_streaming_video"
+HV_KVM_SPICE_AUDIO_COMPR = "spice_playback_compression"
 HV_ACPI = "acpi"
 HV_PAE = "pae"
 HV_USE_BOOTLOADER = "use_bootloader"
@@ -720,6 +725,11 @@ HVS_PARAMETER_TYPES = {
   HV_KVM_SPICE_BIND: VTYPE_STRING,
   HV_KVM_SPICE_IP_VERSION: VTYPE_INT,
   HV_KVM_SPICE_PASSWORD_FILE: VTYPE_STRING,
+  HV_KVM_SPICE_LOSSLESS_IMG_COMPR: VTYPE_STRING,
+  HV_KVM_SPICE_JPEG_IMG_COMPR: VTYPE_STRING,
+  HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR: VTYPE_STRING,
+  HV_KVM_SPICE_STREAMING_VIDEO_DETECTION: VTYPE_STRING,
+  HV_KVM_SPICE_AUDIO_COMPR: VTYPE_BOOL,
   HV_ACPI: VTYPE_BOOL,
   HV_PAE: VTYPE_BOOL,
   HV_USE_BOOTLOADER: VTYPE_BOOL,
@@ -953,6 +963,45 @@ HT_KVM_VALID_BO_TYPES = frozenset([
   HT_BO_NETWORK
   ])
 
+# SPICE lossless image compression options
+HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ = "auto_glz"
+HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ = "auto_lz"
+HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC = "quic"
+HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ = "glz"
+HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ = "lz"
+HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF = "off"
+
+HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS = frozenset([
+  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_GLZ,
+  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_AUTO_LZ,
+  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_QUIC,
+  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_GLZ,
+  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_LZ,
+  HT_KVM_SPICE_LOSSLESS_IMG_COMPR_OFF,
+  ])
+
+# SPICE lossy image compression options (valid for both jpeg and zlib-glz)
+HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO = "auto"
+HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER = "never"
+HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS = "always"
+
+HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS = frozenset([
+  HT_KVM_SPICE_LOSSY_IMG_COMPR_AUTO,
+  HT_KVM_SPICE_LOSSY_IMG_COMPR_NEVER,
+  HT_KVM_SPICE_LOSSY_IMG_COMPR_ALWAYS,
+  ])
+
+# SPICE video stream detection
+HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF = "off"
+HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL = "all"
+HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER = "filter"
+
+HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS = frozenset([
+  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_OFF,
+  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_ALL,
+  HT_KVM_SPICE_VIDEO_STREAM_DETECTION_FILTER,
+  ])
+
 # Security models
 HT_SM_NONE = "none"
 HT_SM_USER = "user"
@@ -1301,6 +1350,11 @@ HVC_DEFAULTS = {
     HV_KVM_SPICE_BIND: "",
     HV_KVM_SPICE_IP_VERSION: IFACE_NO_IP_VERSION_SPECIFIED,
     HV_KVM_SPICE_PASSWORD_FILE: "",
+    HV_KVM_SPICE_LOSSLESS_IMG_COMPR: "",
+    HV_KVM_SPICE_JPEG_IMG_COMPR: "",
+    HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR: "",
+    HV_KVM_SPICE_STREAMING_VIDEO_DETECTION: "",
+    HV_KVM_SPICE_AUDIO_COMPR: True,
     HV_KVM_FLOPPY_IMAGE_PATH: "",
     HV_CDROM_IMAGE_PATH: "",
     HV_KVM_CDROM2_IMAGE_PATH: "",
index 8334ded..15358a6 100644 (file)
@@ -419,6 +419,19 @@ class KVMHypervisor(hv_base.BaseHypervisor):
        "the SPICE IP version should be 4 or 6",
        None, None),
     constants.HV_KVM_SPICE_PASSWORD_FILE: hv_base.OPT_FILE_CHECK,
+    constants.HV_KVM_SPICE_LOSSLESS_IMG_COMPR:
+      hv_base.ParamInSet(False,
+        constants.HT_KVM_SPICE_VALID_LOSSLESS_IMG_COMPR_OPTIONS),
+    constants.HV_KVM_SPICE_JPEG_IMG_COMPR:
+      hv_base.ParamInSet(False,
+        constants.HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS),
+    constants.HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR:
+      hv_base.ParamInSet(False,
+        constants.HT_KVM_SPICE_VALID_LOSSY_IMG_COMPR_OPTIONS),
+    constants.HV_KVM_SPICE_STREAMING_VIDEO_DETECTION:
+      hv_base.ParamInSet(False,
+        constants.HT_KVM_SPICE_VALID_VIDEO_STREAM_DETECTION_OPTIONS),
+    constants.HV_KVM_SPICE_AUDIO_COMPR: hv_base.NO_CHECK,
     constants.HV_KVM_FLOPPY_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
     constants.HV_CDROM_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
     constants.HV_KVM_CDROM2_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
@@ -780,6 +793,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     """Generate KVM information to start an instance.
 
     """
+    # pylint: disable=R0914
     _, v_major, v_min, _ = self._GetKVMVersion()
 
     pidfile = self._InstancePidFile(instance.name)
@@ -1023,6 +1037,26 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       if spice_ip_version:
         spice_arg = "%s,ipv%s" % (spice_arg, spice_ip_version)
 
+      # Image compression options
+      img_lossless = hvp[constants.HV_KVM_SPICE_LOSSLESS_IMG_COMPR]
+      img_jpeg = hvp[constants.HV_KVM_SPICE_JPEG_IMG_COMPR]
+      img_zlib_glz = hvp[constants.HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR]
+      if img_lossless:
+        spice_arg = "%s,image-compression=%s" % (spice_arg, img_lossless)
+      if img_jpeg:
+        spice_arg = "%s,jpeg-wan-compression=%s" % (spice_arg, img_jpeg)
+      if img_zlib_glz:
+        spice_arg = "%s,zlib-glz-wan-compression=%s" % (spice_arg, img_zlib_glz)
+
+      # Video stream detection
+      video_streaming = hvp[constants.HV_KVM_SPICE_STREAMING_VIDEO_DETECTION]
+      if video_streaming:
+        spice_arg = "%s,streaming-video=%s" % (spice_arg, video_streaming)
+
+      # Audio compression, by default in qemu-kvm it is on
+      if not hvp[constants.HV_KVM_SPICE_AUDIO_COMPR]:
+        spice_arg = "%s,playback-compression=off" % spice_arg
+
       logging.info("KVM: SPICE will listen on port %s", instance.network_port)
       kvm_cmd.extend(["-spice", spice_arg])
 
@@ -1613,6 +1647,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       spice_additional_params = frozenset([
         constants.HV_KVM_SPICE_IP_VERSION,
         constants.HV_KVM_SPICE_PASSWORD_FILE,
+        constants.HV_KVM_SPICE_LOSSLESS_IMG_COMPR,
+        constants.HV_KVM_SPICE_JPEG_IMG_COMPR,
+        constants.HV_KVM_SPICE_ZLIB_GLZ_IMG_COMPR,
+        constants.HV_KVM_SPICE_STREAMING_VIDEO_DETECTION,
         ])
       for param in spice_additional_params:
         if hvparams[param]:
index c3a0c92..9ae83c2 100644 (file)
@@ -307,6 +307,52 @@ spice\_password\_file
     connecting via the SPICE protocol. If the option is not specified,
     passwordless connections are allowed.
 
+spice\_image\_compression
+    Valid for the KVM hypervisor.
+
+    Configures the SPICE lossless image compression. Valid values are:
+
+    - auto_glz
+    - auto_lz
+    - quic
+    - glz
+    - lz
+    - off
+
+spice\_jpeg\_wan\_compression
+    Valid for the KVM hypervisor.
+
+    Configures how SPICE should use the jpeg algorithm for lossy image
+    compression on slow links. Valid values are:
+
+    - auto
+    - never
+    - always
+
+spice\_zlib\_glz\_wan\_compression
+    Valid for the KVM hypervisor.
+
+    Configures how SPICE should use the zlib-glz algorithm for lossy image
+    compression on slow links. Valid values are:
+
+    - auto
+    - never
+    - always
+
+spice\_streaming\_video
+    Valid for the KVM hypervisor.
+
+    Configures how SPICE should detect video streams. Valid values are:
+
+    - off
+    - all
+    - filter
+
+spice\_playback\_compression
+    Valid for the KVM hypervisor.
+
+    Configures whether SPICE should compress audio streams or not.
+
 acpi
     Valid for the Xen HVM and KVM hypervisors.