[libvirt] Question, how to use virDomainQemuMonitorCommand()
Chris Lalancette
clalance at redhat.com
Tue Sep 7 13:22:30 UTC 2010
On 09/07/10 - 04:08:13PM, Lai Jiangshan wrote:
> Hi, Chris,
>
> I saw virDomainQemuMonitorCommand() in libvirt-qemu.c,
> I think it will help me to send arbitrary qemu-monitor command to
> qemu via libvirtd.
>
> But how can I use virDomainQemuMonitorCommand()?
> Can I use it by just using current tools(virsh or other) without writing any code?
Unfortunately, no. There is a bug in the current virsh command that prevents
it from properly parsing the command-lines necessary to send monitor commands
to the qemu monitor. Until we fix that bug, we won't push the support into
virsh.
For that reason you will need to write a custom program to call
virDomainQemuMonitorCommand as appropriate. The absolute easiest program you
can write looks something like (untested):
#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>
int main()
{
virConnectPtr conn;
virDomainPtr dom;
char *reply;
conn = virConnectOpen(NULL);
dom = virDomainLookupByName(conn, "mydomain");
virDomainQemuMonitorCommand(dom, "info cpus", &reply, 0);
fprintf(stderr, "Reply: %s\n", reply);
free(reply);
virConnectClose(conn);
return 0;
}
--
Chris Lalancette
More information about the libvir-list
mailing list