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

Daniel P. Berrange berrange at redhat.com
Wed Dec 21 10:29:04 UTC 2016

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.

|: 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/ :|

More information about the libvir-list mailing list