[PATCH 3/8] Add a new 'virsh qemu-attach' command.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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   |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |   26 +++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 9a189fd..f7a1274 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -11611,6 +11611,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 long long pid;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        goto cleanup;
+
+    if (vshCommandOptULongLong(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 %llu\n"),
+                 virDomainGetName(dom), pid);
+        virDomainFree(dom);
+        ret = true;
+    } else {
+        vshError(ctl, _("Failed to attach to pid %llu"), pid);
+    }
+
+cleanup:
+    return ret;
+}
+
 static const vshCmdDef domManagementCmds[] = {
     {"attach-device", cmdAttachDevice, opts_attach_device,
      info_attach_device, 0},
@@ -11874,6 +11920,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},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 736b919..56251aa 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -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
 
@@ -1517,6 +1518,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
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]