[PATCH 1/8] Define a QEMU specific API to attach to a running QEMU process

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

 



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 |    4 +++
 src/driver.h                   |    6 +++++
 src/libvirt-qemu.c             |   41 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_qemu.syms          |    5 ++++
 4 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
index f172eff..2f0f1c6 100644
--- a/include/libvirt/libvirt-qemu.h
+++ b/include/libvirt/libvirt-qemu.h
@@ -28,6 +28,10 @@ typedef enum {
 int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
                                 char **result, unsigned int flags);
 
+virDomainPtr virDomainQemuAttach(virConnectPtr domain,
+                                 unsigned long long pid,
+                                 unsigned int flags);
+
 # ifdef __cplusplus
 }
 # endif
diff --git a/src/driver.h b/src/driver.h
index 62bbc1d..8e57a4e 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -559,6 +559,11 @@ typedef int
     (*virDrvDomainQemuMonitorCommand)(virDomainPtr domain, const char *cmd,
                                       char **result, unsigned int flags);
 
+typedef virDomainPtr
+    (*virDrvDomainQemuAttach)(virConnectPtr conn,
+                              unsigned long long pid,
+                              unsigned int flags);
+
 typedef int
     (*virDrvDomainOpenConsole)(virDomainPtr dom,
                                const char *devname,
@@ -796,6 +801,7 @@ struct _virDriver {
     virDrvDomainRevertToSnapshot domainRevertToSnapshot;
     virDrvDomainSnapshotDelete domainSnapshotDelete;
     virDrvDomainQemuMonitorCommand qemuDomainMonitorCommand;
+    virDrvDomainQemuAttach qemuDomainAttach;
     virDrvDomainOpenConsole domainOpenConsole;
     virDrvDomainInjectNMI domainInjectNMI;
     virDrvDomainMigrateBegin3	domainMigrateBegin3;
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index 46727c8..f0bcac1 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -79,3 +79,44 @@ error:
     virDispatchError(conn);
     return -1;
 }
+
+
+virDomainPtr
+virDomainQemuAttach(virConnectPtr conn,
+                    unsigned long long pid,
+                    unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, pid=%llu, 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;
+}
diff --git a/src/libvirt_qemu.syms b/src/libvirt_qemu.syms
index 5702d36..1bb8b62 100644
--- a/src/libvirt_qemu.syms
+++ b/src/libvirt_qemu.syms
@@ -14,3 +14,8 @@ LIBVIRT_QEMU_0.8.3 {
     global:
         virDomainQemuMonitorCommand;
 };
+
+LIBVIRT_QEMU_0.9.3 {
+    global:
+        virDomainQemuAttach;
+} LIBVIRT_QEMU_0.8.3;
-- 
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]