Blame SOURCES/0013-output-create_libvirt_xml-wire-up-the-QEMU-guest-age.patch

c1a9fa
From 0699afed37343d73c6803cabec466e1c3ca229b0 Mon Sep 17 00:00:00 2001
c1a9fa
From: Laszlo Ersek <lersek@redhat.com>
c1a9fa
Date: Mon, 13 Jun 2022 19:01:32 +0200
c1a9fa
Subject: [PATCH] output/create_libvirt_xml: wire up the QEMU guest agent
c1a9fa
c1a9fa
The intent (even before RHBZ#2028764) has been to install the QEMU guest
c1a9fa
agent in the converted domain unconditionally. Therefore, in order for the
c1a9fa
GA to be actually accessible from the host side, augment the libvirt
c1a9fa
output module with a "guest agent connection" also unconditionally.
c1a9fa
c1a9fa
For starters, the domain needs a virtio-serial device. Then there must be
c1a9fa
a port on the device that (in the guest) the GA identifies by name, and
c1a9fa
that (on the host) is exposed as a listening socket (usually in the unix
c1a9fa
address family). The adress of that port (usually a pathname, i.e., for a
c1a9fa
unix domain socket) is then passed to whatever host-side application wants
c1a9fa
to talk to the GA.
c1a9fa
c1a9fa
The minimal domain XML fragment for that ("minimal" for our purposes) is
c1a9fa
c1a9fa
  <controller type='virtio-serial' model='virtio'>
c1a9fa
  <channel type='unix'>
c1a9fa
    <target type='virtio' name='org.qemu.guest_agent.0'/>
c1a9fa
  </channel>
c1a9fa
c1a9fa
The "controller" element is needed because "controller/@model" is where we
c1a9fa
regulate "virtio" vs. "virtio-transitional".
c1a9fa
c1a9fa
Everything else is filled in by libvirt. Notably, libvirt (a) creates and
c1a9fa
binds the unix domain socket itself (usually
c1a9fa
"/var/lib/libvirt/qemu/channel/target/DOMAIN/org.qemu.guest_agent.0"), (b)
c1a9fa
passes the file descriptor to QEMU, and (c) figures out the socket
c1a9fa
pathname for commands such as
c1a9fa
c1a9fa
  virsh domfsinfo DOMAIN
c1a9fa
  virsh domhostname DOMAIN --source agent
c1a9fa
  virsh domifaddr DOMAIN --source agent
c1a9fa
  virsh guestinfo DOMAIN
c1a9fa
c1a9fa
For QEMU, the corresponding options would be
c1a9fa
c1a9fa
  -chardev socket,id=agent,server=on,wait=off,path=/tmp/DOMAIN-agent \
c1a9fa
  -device virtio-serial-pci,id=vioserial \
c1a9fa
  -device virtserialport,bus=vioserial.0,nr=1,chardev=agent,name=org.qemu.guest_agent.0 \
c1a9fa
c1a9fa
Note the "path=/tmp/DOMAIN-agent" property of "-chardev"; virt-v2v would
c1a9fa
have to generate that (in place of the "fd=nnnn" property that libvirt
c1a9fa
passes to QEMU).
c1a9fa
c1a9fa
Omit extending the QEMU output module for now, as the QGA protocol is
c1a9fa
based on JSON, and one needs "virsh" or "virt-manager" (or another
c1a9fa
management application interface) anyway, for efficiently exchanging
c1a9fa
messages with QGA. I don't know of end-user tools that directly connect to
c1a9fa
"/tmp/DOMAIN-agent".
c1a9fa
c1a9fa
Don't modify the RHV and OpenStack outputs either; both of these
c1a9fa
management products likely configure the virtio-serial device
c1a9fa
automatically, for the agent access.
c1a9fa
c1a9fa
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2028764
c1a9fa
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
c1a9fa
Message-Id: <20220613170135.12557-2-lersek@redhat.com>
c1a9fa
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
c1a9fa
Tested-by: Richard W.M. Jones <rjones@redhat.com>
c1a9fa
(cherry picked from commit 48c6ea27c5a7053e418622f7450e3f9ef05c923f)
c1a9fa
---
c1a9fa
 output/create_libvirt_xml.ml | 11 +++++++++++
c1a9fa
 tests/test-v2v-i-ova.xml     |  4 ++++
c1a9fa
 2 files changed, 15 insertions(+)
c1a9fa
c1a9fa
diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
c1a9fa
index 68d0a909..531a4f75 100644
c1a9fa
--- a/output/create_libvirt_xml.ml
c1a9fa
+++ b/output/create_libvirt_xml.ml
c1a9fa
@@ -524,6 +524,17 @@ let create_libvirt_xml ?pool source inspect
c1a9fa
     e "console" ["type", "pty"] [];
c1a9fa
   ];
c1a9fa
 
c1a9fa
+  (* Given that we install the QEMU Guest Agent for both Linux and Windows
c1a9fa
+   * guests unconditionally, create the virtio-serial device that's needed for
c1a9fa
+   * communication between the host and the agent.
c1a9fa
+   *)
c1a9fa
+  List.push_back_list devices [
c1a9fa
+    e "controller" ["type", "virtio-serial"; "model", virtio_model] [];
c1a9fa
+    e "channel" ["type", "unix"] [
c1a9fa
+      e "target" ["type", "virtio"; "name", "org.qemu.guest_agent.0"] []
c1a9fa
+    ]
c1a9fa
+  ];
c1a9fa
+
c1a9fa
   List.push_back_list body [
c1a9fa
     e "devices" [] !devices;
c1a9fa
   ];
c1a9fa
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
c1a9fa
index 6b8cda62..da1db473 100644
c1a9fa
--- a/tests/test-v2v-i-ova.xml
c1a9fa
+++ b/tests/test-v2v-i-ova.xml
c1a9fa
@@ -49,5 +49,9 @@
c1a9fa
     <input type='tablet' bus='usb'/>
c1a9fa
     <input type='mouse' bus='ps2'/>
c1a9fa
     <console type='pty'/>
c1a9fa
+    <controller type='virtio-serial' model='virtio'/>
c1a9fa
+    <channel type='unix'>
c1a9fa
+      <target type='virtio' name='org.qemu.guest_agent.0'/>
c1a9fa
+    </channel>
c1a9fa
   </devices>
c1a9fa
 </domain>