]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add a new 'virsh qemu-attach' command.
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 5 May 2011 16:32:07 +0000 (17:32 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Jul 2011 14:39:03 +0000 (15:39 +0100)
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

tools/virsh.c
tools/virsh.pod

index 3cdf043946b7c1df3e6397e74c645eb2d3d73de7..cd17f4249f8ff1dc8daba386b5a06b90047758a4 100644 (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},
index d1c285f1671cb1cc1aee43e59ce9dd21da16a9d0..52f15492217526c5258c66c88476c1c51897e531 100644 (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