Add a new 'virsh qemu-attach' command.

This command allows libvirt to attach to an existing QEMU
instance.

 $ qemu-kvm -cdrom ~/demo.iso \
     -monitor unix:/tmp/demo,server,nowait \
     -name foo \
     -uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea  &
 $ QEMUPID=$!
 $ virsh qemu-attach $QEMUPID
This commit is contained in:
Daniel P. Berrange 2011-05-05 17:32:07 +01:00
parent 4403646001
commit eb7be6a606
2 changed files with 74 additions and 3 deletions

View File

@ -11552,8 +11552,8 @@ cleanup:
* "qemu-monitor-command" command
*/
static const vshCmdInfo info_qemu_monitor_command[] = {
{"help", N_("Qemu Monitor Command")},
{"desc", N_("Qemu Monitor Command")},
{"help", N_("QEMU Monitor Command")},
{"desc", N_("QEMU Monitor Command")},
{NULL, NULL}
};
@ -11603,6 +11603,52 @@ cleanup:
return ret;
}
/*
* "qemu-attach" command
*/
static const vshCmdInfo info_qemu_attach[] = {
{"help", N_("QEMU Attach")},
{"desc", N_("QEMU Attach")},
{NULL, NULL}
};
static const vshCmdOptDef opts_qemu_attach[] = {
{"pid", VSH_OT_DATA, VSH_OFLAG_REQ, N_("pid")},
{NULL, 0, 0, NULL}
};
static bool
cmdQemuAttach(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
bool ret = false;
unsigned int flags = 0;
unsigned int pid;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
if (vshCommandOptUInt(cmd, "pid", &pid) <= 0) {
vshError(ctl, "%s", _("missing pid value"));
goto cleanup;
}
if (!(dom = virDomainQemuAttach(ctl->conn, pid, flags)))
goto cleanup;
if (dom != NULL) {
vshPrint(ctl, _("Domain %s attached to pid %u\n"),
virDomainGetName(dom), pid);
virDomainFree(dom);
ret = true;
} else {
vshError(ctl, _("Failed to attach to pid %u"), pid);
}
cleanup:
return ret;
}
static const vshCmdDef domManagementCmds[] = {
{"attach-device", cmdAttachDevice, opts_attach_device,
info_attach_device, 0},
@ -11866,6 +11912,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = {
{"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0},
{"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
{"nodememstats", cmdNodeMemStats, opts_node_memstats, info_nodememstats, 0},
{"qemu-attach", cmdQemuAttach, opts_qemu_attach, info_qemu_attach},
{"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command,
info_qemu_monitor_command, 0},
{"sysinfo", cmdSysinfo, NULL, info_sysinfo, 0},

View File

@ -131,7 +131,8 @@ group as an option. For example:
connect (re)connect to hypervisor
freecell NUMA free memory
hostname print the hypervisor hostname
qemu-monitor-command Qemu Monitor Command
qemu-attach Attach to existing QEMU process
qemu-monitor-command QEMU Monitor Command
sysinfo print the hypervisor sysinfo
uri print the hypervisor canonical URI
@ -1519,6 +1520,29 @@ problems to the libvirt developers; the reports will be ignored.
=over 4
=item B<qemu-attach> I<pid>
Attach an externally launched QEMU process to the libvirt QEMU driver.
The QEMU process must have been created with a monitor connection
using the UNIX driver. Ideally the process will also have had the
'-name' argument specified.
=over 4
$ qemu-kvm -cdrom ~/demo.iso \
-monitor unix:/tmp/demo,server,nowait \
-name foo \
-uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea &
$ QEMUPID=$!
$ virsh qemu-attach $QEMUPID
=back
Not all functions of libvirt are expected to work reliably after
attaching to an externally launched QEMU process. There may be
issues with the guest ABI changing upon migration, and hotunplug
may not work.
=item B<qemu-monitor-command> I<domain> I<command> optional I<--hmp>
Send an arbitrary monitor command I<command> to domain I<domain> through the