Blob Blame History Raw
From 6ec78c1b8a935bd5fe0896dc323bfdf51cc67585 Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Wed, 18 May 2022 17:03:29 -0500
Subject: [PATCH] virt-install: add support for qemu-vdagent channel

This allows support for host/guest clipboard sharing when using vnc
guests (and possibly other graphics types in the future). This channel
is similar to the spicevmc channel, but it contains a couple additional
options to enable/disable clipboard sharing and specify the mouse mode.
In the case of spice, these settings are specified on the 'graphics'
element, but for qemu-vdagent, they are specified on the channel. For
example:

   --channel=qemu-vdagent,source.clipboard.copypaste=on,source.mouse.mode=client

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
(cherry picked from commit 44355e5ed0d0791675e8113732dde37664d5aa91)

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=2060724

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
 man/virt-install.rst                                 | 9 +++++++++
 tests/data/cli/compare/virt-install-many-devices.xml | 7 +++++++
 tests/test_cli.py                                    | 5 +++--
 virtinst/cli.py                                      | 2 ++
 virtinst/devices/char.py                             | 8 +++++++-
 5 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/man/virt-install.rst b/man/virt-install.rst
index c1d1c1aa1..3a6e8dcd2 100644
--- a/man/virt-install.rst
+++ b/man/virt-install.rst
@@ -1761,6 +1761,15 @@ Some of the types of character device redirection are:
     and can be any string, such as the default com.redhat.spice.0 that
     specifies how the guest will see the channel.
 
+``--channel qemu-vdagent,target.type=virtio[,target.name=NAME]``
+    Communication channel for QEMU vd agent, using virtio serial (requires
+    2.6.34 or later host and guest). This allows copy/paste functionality with
+    VNC guests. Note that the guest clipboard integration is implemented via
+    spice-vdagent, which must be running even when the guest does not use spice
+    graphics. NAME is optional metadata that specifies how the guest will see
+    the channel, and should be left as the default com.redhat.spice.0 unless you
+    know what you are doing.
+
 
 Use --channel=? to see a list of all available sub options.
 Complete details at https://libvirt.org/formatdomain.html#elementsCharChannel
diff --git a/tests/data/cli/compare/virt-install-many-devices.xml b/tests/data/cli/compare/virt-install-many-devices.xml
index 4c0024225..be82032fe 100644
--- a/tests/data/cli/compare/virt-install-many-devices.xml
+++ b/tests/data/cli/compare/virt-install-many-devices.xml
@@ -647,6 +647,13 @@
     <channel type="spicevmc">
       <target type="virtio" name="com.redhat.spice.0"/>
     </channel>
+    <channel type="qemu-vdagent">
+      <source>
+        <clipboard copypaste="yes"/>
+        <mouse mode="client"/>
+      </source>
+      <target type="virtio" name="com.redhat.spice.0"/>
+    </channel>
     <input type="keyboard" bus="usb"/>
     <input type="tablet" bus="usb"/>
     <input type="mouse" bus="ps2"/>
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 8b78a1a78..22749d43a 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -669,6 +669,7 @@ source.reservations.managed=no,source.reservations.source.type=unix,source.reser
 --channel pty,target_type=virtio,name=org.linux-kvm.port1
 --channel pty,target.type=virtio,target.name=org.linux-kvm.port2
 --channel spicevmc
+--channel qemu-vdagent,source.clipboard.copypaste=on,source.mouse.mode=client
 
 
 --console pty,target_type=virtio
@@ -734,7 +735,7 @@ source.reservations.managed=no,source.reservations.source.type=unix,source.reser
 
 
 --rng /dev/random
---rng device=/dev/urandom,backend.protocol.type=,backend.log.file=,backend.log.append=
+--rng device=/dev/urandom,backend.protocol.type=,backend.log.file=,backend.log.append=,backend.source.clipboard.copypaste=,backend.source.mouse.mode=
 --rng type=egd,backend.type=nmdm,backend.source.master=/dev/foo1,backend.source.slave=/dev/foo2
 --rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=udp,backend_mode=bind,backend_connect_host=foo,backend_connect_service=708,rate.bytes=1234,rate.period=1000,model=virtio
 
@@ -786,7 +787,7 @@ source.reservations.managed=no,source.reservations.source.type=unix,source.reser
 --xml xpath.delete=./deleteme/deleteme2
 
 
-""", "many-devices", predefine_check="7.4.0")
+""", "many-devices", predefine_check="8.4.0")
 
 
 # Specific XML test cases #1
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 52be9f298..c869c323a 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -3396,6 +3396,8 @@ def _add_char_source_args(cls, prefix=""):
     _add_arg("protocol.type", "source.protocol")
     _add_arg("log.file", "source.log_file")
     _add_arg("log.append", "source.log_append", is_onoff=True)
+    _add_arg("source.clipboard.copypaste", "source.clipboard_copypaste", is_onoff=True)
+    _add_arg("source.mouse.mode", "source.mouse_mode")
 
 
 ##################
diff --git a/virtinst/devices/char.py b/virtinst/devices/char.py
index 9547c649e..01fc634b1 100644
--- a/virtinst/devices/char.py
+++ b/virtinst/devices/char.py
@@ -45,6 +45,10 @@ class CharSource(XMLBuilder):
     slave = XMLProperty("./@slave")
     mode = XMLProperty("./@mode")
 
+    # for qemu-vdagent channel
+    clipboard_copypaste = XMLProperty("./clipboard/@copypaste", is_yesno=True)
+    mouse_mode = XMLProperty("./mouse/@mode")
+
     # It's weird to track these properties here, since the XML is set on
     # the parent, but this is how libvirt does it internally, which means
     # everything that shares a charsource has these values too.
@@ -80,6 +84,7 @@ class _DeviceChar(Device):
     TYPE_SPICEVMC = "spicevmc"
     TYPE_SPICEPORT = "spiceport"
     TYPE_NMDM = "nmdm"
+    TYPE_QEMUVDAGENT = "qemu-vdagent"
 
     CHANNEL_NAME_SPICE = "com.redhat.spice.0"
     CHANNEL_NAME_QEMUGA = "org.qemu.guest_agent.0"
@@ -117,7 +122,8 @@ class _DeviceChar(Device):
             self.source.mode = "bind"
         if not self.target_type and self.DEVICE_TYPE == "channel":
             self.target_type = "virtio"
-        if not self.target_name and self.type == self.TYPE_SPICEVMC:
+        if not self.target_name and (self.type == self.TYPE_SPICEVMC or
+                self.type == self.TYPE_QEMUVDAGENT):
             self.target_name = self.CHANNEL_NAME_SPICE
 
 
-- 
2.35.3