]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Define a QEMU specific API to attach to a running QEMU process
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 5 May 2011 14:05:40 +0000 (15:05 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Jul 2011 14:39:03 +0000 (15:39 +0100)
Introduce a new API in libvirt-qemu.so

 virDomainPtr virDomainQemuAttach(virConnectPtr domain,
                                  unsigned long long pid,
                                  unsigned int flags);

This allows libvirtd to attach to an existing, externally
launched QEMU process. This is useful for QEMU developers who
prefer to launch QEMU themselves for debugging/devel reasons,
but still want the benefit of libvirt based tools like
virt-top, virt-viewer, etc

* include/libvirt/libvirt-qemu.h: Define virDomainQemuAttach
* src/driver.h, src/libvirt-qemu.c, src/libvirt_qemu.syms:
  Driver glue for virDomainQemuAttach

include/libvirt/libvirt-qemu.h
src/driver.h
src/libvirt-qemu.c
src/libvirt_qemu.syms

index f172eff0fed47481b87879020bac67089970cbbd..7f12e4f587a5a5657cac97bfa9461576dac12867 100644 (file)
@@ -28,6 +28,10 @@ typedef enum {
 int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
                                 char **result, unsigned int flags);
 
+virDomainPtr virDomainQemuAttach(virConnectPtr domain,
+                                 unsigned int pid,
+                                 unsigned int flags);
+
 # ifdef __cplusplus
 }
 # endif
index 71a52c96c2ff2f38350e4a6665a9cf8f80380e76..70ea4c235fd63bfbd60a9f5489e6d44604ae381c 100644 (file)
@@ -566,6 +566,11 @@ typedef int
     (*virDrvDomainQemuMonitorCommand)(virDomainPtr domain, const char *cmd,
                                       char **result, unsigned int flags);
 
+typedef virDomainPtr
+    (*virDrvDomainQemuAttach)(virConnectPtr conn,
+                              unsigned int pid,
+                              unsigned int flags);
+
 typedef int
     (*virDrvDomainOpenConsole)(virDomainPtr dom,
                                const char *devname,
@@ -786,6 +791,7 @@ struct _virDriver {
     virDrvDomainRevertToSnapshot domainRevertToSnapshot;
     virDrvDomainSnapshotDelete domainSnapshotDelete;
     virDrvDomainQemuMonitorCommand qemuDomainMonitorCommand;
+    virDrvDomainQemuAttach qemuDomainAttach;
     virDrvDomainOpenConsole domainOpenConsole;
     virDrvDomainInjectNMI domainInjectNMI;
     virDrvDomainMigrateBegin3  domainMigrateBegin3;
index 46727c843c3db983f1db4a0c3eda9629c8772b26..b9aa2dc9fdcd00b12d5abeaddf12e5af19f75818 100644 (file)
@@ -79,3 +79,71 @@ error:
     virDispatchError(conn);
     return -1;
 }
+
+
+
+/**
+ * virDomainQemuAttach:
+ * @conn: pointer to a hypervisor connection
+ * @pid: the UNIX process ID of the external QEMU process
+ * @flags: optional flags, currently unused
+ *
+ * This API is QEMU specific, so will only work with hypervisor
+ * connections to the QEMU driver.
+ *
+ * This API will attach to an externally launched QEMU process
+ * identified by @pid. There are several requirements to succcesfully
+ * attach to an external QEMU process:
+ *
+ *   - It must have been started with a monitor socket using the UNIX
+ *     domain socket protocol.
+ *   - No device hotplug/unplug, or other configuration changes can
+ *     have been made via the monitor since it started.
+ *   - The '-name' and '-uuid' arguments should have been set (not
+ *     mandatory, but strongly recommended)
+ *
+ * If successful, then the guest will appear in the list of running
+ * domains for this connection, and other APIs should operate
+ * normally (provided the above requirements were honoured
+ *
+ * Returns a new domain object on success, NULL otherwise
+ */
+virDomainPtr
+virDomainQemuAttach(virConnectPtr conn,
+                    unsigned pid,
+                    unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, pid=%u, flags=%u", conn, pid, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return NULL;
+    }
+
+    if (pid <= 1) {
+        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->qemuDomainAttach) {
+        virDomainPtr ret;
+        ret = conn->driver->qemuDomainAttach(conn, pid, flags);
+        if (!ret)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return NULL;
+}
index 5702d367eded1574deadd1e7cb0d2dc168cff717..8447730fd0ee6f33160647dd48e217ccdfa06b1b 100644 (file)
@@ -14,3 +14,8 @@ LIBVIRT_QEMU_0.8.3 {
     global:
         virDomainQemuMonitorCommand;
 };
+
+LIBVIRT_QEMU_0.9.4 {
+    global:
+        virDomainQemuAttach;
+} LIBVIRT_QEMU_0.8.3;