[libvirt] connecting to qemu domain monitor socket outside of libvirt/virsh

Hi, So I see that when i have a qemu vm running, that i created via libvirt, there is a socket here: /var/lib/libvirt/qemu/domain-<name>/monitor.sock I am trying to connect to this socket via cli or a completely separate C/C++ application to be able to control the VM, but I can't seem to get it to work. Does anyone know if/how this is possible? I've tried 'nc', 'socat', and based on the qemu libvirt code, 'socket'/'connect', but nothing seems to work. Also, is it possible through libvirt, when creating a qemu VM, one can specify to enable the QMP socket? Thanks in advance, Jason

On 12/20/2016 12:48 PM, Jason Miesionczek wrote:
Hi,
So I see that when i have a qemu vm running, that i created via libvirt, there is a socket here: /var/lib/libvirt/qemu/domain-<name>/monitor.sock
I am trying to connect to this socket via cli or a completely separate C/C++ application to be able to control the VM, but I can't seem to get it to work.
Does anyone know if/how this is possible?
Not by connecting directly to the socket, but you CAN use libvirt-qemu.so, which provides the virDomainQemuMonitorCommand() API (also conveniently exposed to shell programming via 'virsh qemu-monitor-command') to do what you want.
I've tried 'nc', 'socat', and based on the qemu libvirt code, 'socket'/'connect', but nothing seems to work.
Going behind libvirt's back and trying to use the same socket that libvirt is using will never work. But going through libvirt's API should work (we document that use of libvirt-qemu.so is explicitly unsupported, not because it doesn't work, but because it is powerful enough to let you change state of the VM behind libvirt's back in ways that libvirt can't cope with - but as long as you use it for safe actions only, such as QMP commands starting with query-, you should be fine). Ideally, however, if there's something you can currently only accomplish by using libvirt-qemu.so, we should really enhance libvirt to natively provide that through supported APIs that belong to libvirt.so.
Also, is it possible through libvirt, when creating a qemu VM, one can specify to enable the QMP socket?
Libvirt creates a QMP socket already. If you're asking if it is possible to create a second QMP socket for use in parallel with libvirt's socket, it might be possible using <qemu:commandline> XML in your domain description; but in general, it's usually sufficient to rely on virDomainQemuMonitorCommand() instead of needing a second QMP monitor. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 12/20/2016 12:56 PM, Eric Blake wrote:
On 12/20/2016 12:48 PM, Jason Miesionczek wrote:
Hi,
So I see that when i have a qemu vm running, that i created via libvirt, there is a socket here: /var/lib/libvirt/qemu/domain-<name>/monitor.sock
Libvirt creates a QMP socket already.
More to the point, looking at the command line of any libvirt-created guest, and you will see these four arguments (alongside all the others): -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-XXX/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control which is the monitor.sock you are asking about, and the mode=control is what tells you it is a QMP monitor socket. (The qemu command line argument '-qmp' is syntactic sugar for the longer paired -chardev/-mon spelling used by libvirt.) -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Tue, Dec 20, 2016 at 01:48:44PM -0500, Jason Miesionczek wrote:
Hi,
So I see that when i have a qemu vm running, that i created via libvirt, there is a socket here: /var/lib/libvirt/qemu/domain-<name>/monitor.sock
I am trying to connect to this socket via cli or a completely separate C/C++ application to be able to control the VM, but I can't seem to get it to work.
Does anyone know if/how this is possible?
I've tried 'nc', 'socat', and based on the qemu libvirt code, 'socket'/'connect', but nothing seems to work.
QEMU only allows a single client to be connected, and that is libvirt. So it'll ignore your connection attempts.
Also, is it possible through libvirt, when creating a qemu VM, one can specify to enable the QMP socket?
Libvirt always enables QMP when it detects it is available. If you need to send QMP commands for some feature libvirt does not yet support, then you need to use the libvirt QMP passthrough API exposed in /usr/include/libvirt/libvirt-qemu.h / libvirt-qemu.so NB, use of QMP at all is strongly discouraged as your app may break on future libvirt updates. The QMP backdoor is only there to enable short term hacks to access features libvirt does not yet expose. For any feature you need long term support for, we should expose it formally in the libvirt API, so plesae let us know what features are missing that you need QMP for. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Jason Miesionczek