Discussion:
[libvirt-users] Is there a way to disable libvirt qemu monitor while creating kvm vm using virsh?
Min Du
2014-11-07 22:28:57 UTC
Permalink
Hi,

Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when creating a KVM VM using libvirt. This command meaning in “qemu-kvm --help” is: -qmp dev like -monitor but opens in 'control' mode.
I added command-line equivalent options into the xml file, like below format:

<qemu:commandline>
<qemu:arg value="-s"/>
<qemu:arg value="-qmp"/>
<qemu:arg value="tcp:127.0.0.1:1235"/>
</qemu:commandline>

However when I create VM using this xml file, I got the error:

# virsh create instance-libvirt.xml
error: Failed to create domain from instance-libvirt.xml
error: internal error process exited while connecting to monitor: qemu-kvm: -qmp tcp:127.0.0.1:1235: Duplicate ID 'monitor' for mon
duplicate chardev: monitor

The VM I created, without “—qmp” option, has below options showing in “ps aux | grep qemu-kvm”:

-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/vmifs_test.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control

Looks like libvirt automatically adds the monitor options upon VM creation.

Is there a way to disable this and use “—qmp” instead when creating VM?

Thanks for your help.


Best Regards,
Min
Kashyap Chamarthy
2014-11-09 18:34:08 UTC
Permalink
Post by Min Du
Hi,
Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when
creating a KVM VM using libvirt.
You might need to elaborate how exactly you're doing this.
Post by Min Du
This command meaning in “qemu-kvm --help” is: -qmp dev like
-monitor but opens in 'control' mode.
The above is used if you want to explicitly control a running QEMU
instance via QMP, e.g. manually issue them QMP commands via telnet(1)
for development/testing/debugging.
Post by Min Du
<qemu:commandline> <qemu:arg value="-s"/> <qemu:arg value="-qmp"/>
<qemu:arg value="tcp:127.0.0.1:1235"/> </qemu:commandline>
In guests created in a regular fashion (e.g. virt-install,
virt-manager), this is all handled by libvirt for you via its APIs.
Post by Min Du
# virsh create instance-libvirt.xml error: Failed to create domain
from instance-libvirt.xml error: internal error process exited while
connecting to monitor: qemu-kvm: -qmp tcp:127.0.0.1:1235: Duplicate ID
'monitor' for mon duplicate chardev: monitor
The VM I created, without “—qmp” option, has below options showing in
-chardev
socket,id=charmonitor,path=/var/lib/libvirt/qemu/vmifs_test.monitor,server,nowait
-mon chardev=charmonitor,id=monitor,mode=control
Looks like libvirt automatically adds the monitor options upon VM creation.
As I understand it, libvirt uses its own APIs to handle interactions
with QEMU monitor console, e.g. qemuMonitorOpen(), etc.

If you're fine delving into code, you might want to libvirt
sources, specificially this directory: libvirt/src/qemu.
Post by Min Du
Is there a way to disable this and use “—qmp” instead when creating VM?
I doubt libvirt developers will agree with this proposal. But if you're
intending to try QEMU monitor console for testing, here's some old notes
on different ways to access QEMU monitor via QMP:

http://kashyapc.com/2013/03/31/multiple-ways-to-access-qemu-monitor-protocol-qmp/
--
/kashyap
Min Du
2014-11-11 01:54:58 UTC
Permalink
Hi Kashyap,

Thanks for the reply.
Post by Kashyap Chamarthy
Post by Min Du
Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when
creating a KVM VM using libvirt.
You might need to elaborate how exactly you're doing this.
I wanted to add “-qmp tcp:127.0.0.1:1235” when creating VM because I was using a multi-level debugger which needs this option to get more information of the VM kernel debuginfo and the processes running inside the VM besides gdb attach.
Post by Kashyap Chamarthy
Post by Min Du
This command meaning in “qemu-kvm --help” is: -qmp dev like
-monitor but opens in 'control' mode.
The above is used if you want to explicitly control a running QEMU
instance via QMP, e.g. manually issue them QMP commands via telnet(1)
for development/testing/debugging.
This is exactly what I need - for debugging. Is there a way to achieve this while still using the default monitor libvirt provides?
Post by Kashyap Chamarthy
Post by Min Du
<qemu:commandline> <qemu:arg value="-s"/> <qemu:arg value="-qmp"/>
<qemu:arg value="tcp:127.0.0.1:1235"/> </qemu:commandline>
In guests created in a regular fashion (e.g. virt-install,
virt-manager), this is all handled by libvirt for you via its APIs.
Post by Min Du
# virsh create instance-libvirt.xml error: Failed to create domain
from instance-libvirt.xml error: internal error process exited while
connecting to monitor: qemu-kvm: -qmp tcp:127.0.0.1:1235: Duplicate ID
'monitor' for mon duplicate chardev: monitor
The VM I created, without “—qmp” option, has below options showing in
-chardev
socket,id=charmonitor,path=/var/lib/libvirt/qemu/vmifs_test.monitor,server,nowait
-mon chardev=charmonitor,id=monitor,mode=control
Looks like libvirt automatically adds the monitor options upon VM creation.
As I understand it, libvirt uses its own APIs to handle interactions
with QEMU monitor console, e.g. qemuMonitorOpen(), etc.
If you're fine delving into code, you might want to libvirt
sources, specificially this directory: libvirt/src/qemu.
Messing up the source code is the last thing I want to do. I am using the default libvirt coming with CentOs6.5, last time I modified and installed the libvirt source code, I got seriously version-not-match problem.
Post by Kashyap Chamarthy
Post by Min Du
Is there a way to disable this and use “—qmp” instead when creating VM?
I doubt libvirt developers will agree with this proposal. But if you're
intending to try QEMU monitor console for testing, here's some old notes
http://kashyapc.com/2013/03/31/multiple-ways-to-access-qemu-monitor-protocol-qmp/
I’ve read this and looks like you’re also using command line to create a KVM machine while enabling “—qmp” option. Is there a way to do this but still creating VM through libvirt?

Thank you very much for your time!


Best Regards,
Min
Post by Kashyap Chamarthy
Post by Min Du
Hi,
Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when
creating a KVM VM using libvirt.
You might need to elaborate how exactly you're doing this.
Post by Min Du
This command meaning in “qemu-kvm --help” is: -qmp dev like
-monitor but opens in 'control' mode.
The above is used if you want to explicitly control a running QEMU
instance via QMP, e.g. manually issue them QMP commands via telnet(1)
for development/testing/debugging.
Post by Min Du
<qemu:commandline> <qemu:arg value="-s"/> <qemu:arg value="-qmp"/>
<qemu:arg value="tcp:127.0.0.1:1235"/> </qemu:commandline>
In guests created in a regular fashion (e.g. virt-install,
virt-manager), this is all handled by libvirt for you via its APIs.
Post by Min Du
# virsh create instance-libvirt.xml error: Failed to create domain
from instance-libvirt.xml error: internal error process exited while
connecting to monitor: qemu-kvm: -qmp tcp:127.0.0.1:1235: Duplicate ID
'monitor' for mon duplicate chardev: monitor
The VM I created, without “—qmp” option, has below options showing in
-chardev
socket,id=charmonitor,path=/var/lib/libvirt/qemu/vmifs_test.monitor,server,nowait
-mon chardev=charmonitor,id=monitor,mode=control
Looks like libvirt automatically adds the monitor options upon VM creation.
As I understand it, libvirt uses its own APIs to handle interactions
with QEMU monitor console, e.g. qemuMonitorOpen(), etc.
If you're fine delving into code, you might want to libvirt
sources, specificially this directory: libvirt/src/qemu.
Post by Min Du
Is there a way to disable this and use “—qmp” instead when creating VM?
I doubt libvirt developers will agree with this proposal. But if you're
intending to try QEMU monitor console for testing, here's some old notes
http://kashyapc.com/2013/03/31/multiple-ways-to-access-qemu-monitor-protocol-qmp/
--
/kashyap
Daniel P. Berrange
2014-11-11 09:32:48 UTC
Permalink
Post by Min Du
Hi Kashyap,
Thanks for the reply.
Post by Kashyap Chamarthy
Post by Min Du
Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when
creating a KVM VM using libvirt.
You might need to elaborate how exactly you're doing this.
I wanted to add “-qmp tcp:127.0.0.1:1235” when creating VM because I
was using a multi-level debugger which needs this option to get more
information of the VM kernel debuginfo and the processes running inside
the VM besides gdb attach.
That's impossible, because libvirt owns the QMP monitor and cannot delegate
use to another process. A core part of the VM startup process requires that
libvirt talk to the QMP monitor to accomplish work, as well as to receive
ongoing notifications of changes in state.

What is the debugger program you are using ? It really needs to be updated
to use the libvirt APIs instead of QEMU monitor directly. Libvirt provides
an API for issuing monitor commands which it should be able to use. It is
just a question of re-writing the debugger to know about this.

Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Min Du
2014-11-11 21:42:48 UTC
Permalink
Hi Daniel,

Thanks. The debugger program I used is a multi-level debugging tool called StackDB developed in our department. It was developed for Xen initially, and KVM support was only added recently.

I've forwarded your email to the developer and hopefully it should be pretty straightforward to do so.



Best Regards,
Min
Post by Daniel P. Berrange
Post by Min Du
Hi Kashyap,
Thanks for the reply.
Post by Kashyap Chamarthy
Post by Min Du
Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when
creating a KVM VM using libvirt.
You might need to elaborate how exactly you're doing this.
I wanted to add “-qmp tcp:127.0.0.1:1235” when creating VM because I
was using a multi-level debugger which needs this option to get more
information of the VM kernel debuginfo and the processes running inside
the VM besides gdb attach.
That's impossible, because libvirt owns the QMP monitor and cannot delegate
use to another process. A core part of the VM startup process requires that
libvirt talk to the QMP monitor to accomplish work, as well as to receive
ongoing notifications of changes in state.
What is the debugger program you are using ? It really needs to be updated
to use the libvirt APIs instead of QEMU monitor directly. Libvirt provides
an API for issuing monitor commands which it should be able to use. It is
just a question of re-writing the debugger to know about this.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Daniel P. Berrange
2014-11-12 10:03:31 UTC
Permalink
Post by Min Du
Hi Daniel,
Thanks. The debugger program I used is a multi-level debugging tool called
StackDB developed in our department. It was developed for Xen initially,
and KVM support was only added recently.
I've forwarded your email to the developer and hopefully it should be pretty
straightforward to do so.
Ok, specifically they'll want to look at the virDomainQemuMonitorCommand API
call that is part of the libvirt/libvirt-qemu.h header file.

This will normally expect to be given JSON encoded commands (QMP style)
but if you set VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP, then it also accepts
old style human monitor commands.

Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Michal Privoznik
2014-11-10 08:50:20 UTC
Permalink
Post by Min Du
Hi,
Now for some reason, I need to add “ -qmp tcp:127.0.0.1:1235” when creating a KVM VM using libvirt. This command meaning in “qemu-kvm --help” is: -qmp dev like -monitor but opens in 'control' mode.
<qemu:commandline>
<qemu:arg value="-s"/>
<qemu:arg value="-qmp"/>
<qemu:arg value="tcp:127.0.0.1:1235"/>
</qemu:commandline>
# virsh create instance-libvirt.xml
error: Failed to create domain from instance-libvirt.xml
error: internal error process exited while connecting to monitor: qemu-kvm: -qmp tcp:127.0.0.1:1235: Duplicate ID 'monitor' for mon
duplicate chardev: monitor
-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/vmifs_test.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control
Looks like libvirt automatically adds the monitor options upon VM creation.
Is there a way to disable this and use “—qmp” instead when creating VM?
No. Libvirt always creates a VM with monitor as it is used to control
the machine. Without the monitor there's not much left for our APIs.

Why do you need to have monitor anyway? Is there something you can't
achieve with libvirt APIs? Even if it was so, there's this APIs which
allows you to pass arbitrary monitor commands to qemu:
virDomainQemuMonitorCommand.

Michal
Loading...