How can I expose qemu-guest-agent QMP capabilities to the qmp tcp server in qemu?

Viewed 362

I'm using qemu-system-x86_64 to run a vm exposing QMP commands via TCP connection in this way:

qemu-system-x86_64 \
-smp 4 -m 4096 \
-vga std \
-display vnc=:0 \
-netdev user,id=n0 \
-device e1000,netdev=n0 \
-usb -device usb-tablet \
-qmp tcp:localhost:8124,server,nowait \
-k en-us \
-boot d \
-hda /filesystem/filesystem.img

Everything is ok, because I can send QMP commands to qemu locally via TCP socket connection on port 8124.

Then I installed qemu-guest-agent on the vm (Ubuntu 21.04 desktop) and I created the virtio ports required by the quemu-guest-agent service in this way:

qemu-system-x86_64 \
-smp 4 -m 4096 \
-vga std \
-display vnc=:0 \
-netdev user,id=n0 \
-device e1000,netdev=n0 \
-chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-usb -device usb-tablet \
-qmp tcp:localhost:8124,server,nowait \
-k en-us \
-boot d \
-hda /filesystem/filesystem.img

quemu-guest-agent systemd service is up and running as expected (obviously on a local socket, not via TCP).

Now I want to see qemu-guest-agent QMP capabilities via TCP socket connection. How can I achieve this?

Based on the official guide I have to change chardev in this way -chardev qga_proxy,id=qga0 \ but it's not working. It seems an obsolete info in that guide, because this command is not supported today. It throws error: qemu-system-x86_64: -chardev qga_proxy,id=qga0: 'qga_proxy' is not a valid char driver name

Which is the correct way to expose guest-agent QMP commands through TCP socket?

Thank you.

1 Answers

You simply need to associate the virtio serial device with a TCP chardev.

Iow, replace: -chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 (unix socket) with -chardev socket,id=qga0,host=localhost,port=9876,server=on (tcp socket).

Fwiw, qga_proxy never happened, it was just some sketchy ideas on the wiki.

Related