Introduce a new API in libvirt-qemu.so virDomainPtr virDomainQemuAttach(virConnectPtr domain, int 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 * src/esx/esx_driver.c, src/libxl/libxl_driver.c, src/lxc/lxc_driver.c, src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/qemu/qemu_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c, src/vmware/vmware_driver.c, src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Driver entry stub --- include/libvirt/libvirt-qemu.h | 4 ++++ src/driver.h | 5 +++++ src/esx/esx_driver.c | 1 + src/libvirt-qemu.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/libvirt_qemu.syms | 5 +++++ src/libxl/libxl_driver.c | 1 + src/lxc/lxc_driver.c | 1 + src/openvz/openvz_driver.c | 1 + src/phyp/phyp_driver.c | 1 + src/qemu/qemu_driver.c | 1 + src/remote/remote_driver.c | 1 + src/test/test_driver.c | 1 + src/uml/uml_driver.c | 1 + src/vbox/vbox_tmpl.c | 1 + src/vmware/vmware_driver.c | 1 + src/xen/xen_driver.c | 1 + src/xenapi/xenapi_driver.c | 1 + 17 files changed, 67 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h index f172eff..a182739 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, + int pid, + unsigned int flags); + # ifdef __cplusplus } # endif diff --git a/src/driver.h b/src/driver.h index a8b79e6..4cf6cbd 100644 --- a/src/driver.h +++ b/src/driver.h @@ -509,6 +509,10 @@ typedef int (*virDrvQemuDomainMonitorCommand)(virDomainPtr domain, const char *cmd, char **result, unsigned int flags); +typedef virDomainPtr + (*virDrvQemuDomainAttach)(virConnectPtr conn, int pid, + unsigned int flags); + typedef int (*virDrvDomainOpenConsole)(virDomainPtr dom, const char *devname, @@ -638,6 +642,7 @@ struct _virDriver { virDrvDomainRevertToSnapshot domainRevertToSnapshot; virDrvDomainSnapshotDelete domainSnapshotDelete; virDrvQemuDomainMonitorCommand qemuDomainMonitorCommand; + virDrvQemuDomainAttach qemuDomainAttach; virDrvDomainOpenConsole domainOpenConsole; }; diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index c958197..061c857 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -4698,6 +4698,7 @@ static virDriver esxDriver = { esxDomainRevertToSnapshot, /* domainRevertToSnapshot */ esxDomainSnapshotDelete, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c index 46727c8..4c4d2e7 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -79,3 +79,43 @@ error: virDispatchError(conn); return -1; } + + +virDomainPtr +virDomainQemuAttach(virConnectPtr conn, int pid, + unsigned int flags) +{ + VIR_DEBUG("conn=%p, pid=%d, 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..90e6b9e 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.2 { + global: + virDomainQemuAttach; +} LIBVIRT_QEMU_0.8.3; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index dec4f43..31c9881 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2745,6 +2745,7 @@ static virDriver libxlDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index b94941d..56857ee 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2904,6 +2904,7 @@ static virDriver lxcDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ lxcDomainOpenConsole, /* domainOpenConsole */ }; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 4af28e9..7fd8f15 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1666,6 +1666,7 @@ static virDriver openvzDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index ebd4a8a..3b9c187 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3827,6 +3827,7 @@ static virDriver phypDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index dd89786..24447b9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7193,6 +7193,7 @@ static virDriver qemuDriver = { qemuDomainRevertToSnapshot, /* domainRevertToSnapshot */ qemuDomainSnapshotDelete, /* domainSnapshotDelete */ qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ qemuDomainOpenConsole, /* domainOpenConsole */ }; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index e30780c..8137faa 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -11297,6 +11297,7 @@ static virDriver remote_driver = { remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */ remoteDomainSnapshotDelete, /* domainSnapshotDelete */ remoteQemuDomainMonitorCommand, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ remoteDomainOpenConsole, /* domainOpenConsole */ }; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0978214..7181753 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5446,6 +5446,7 @@ static virDriver testDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 33849a0..2784542 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2252,6 +2252,7 @@ static virDriver umlDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ umlDomainOpenConsole, /* domainOpenConsole */ }; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 8241d34..d24b883 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -8651,6 +8651,7 @@ virDriver NAME(Driver) = { vboxDomainRevertToSnapshot, /* domainRevertToSnapshot */ vboxDomainSnapshotDelete, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index bbfb1a4..c902fc0 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -1006,6 +1006,7 @@ static virDriver vmwareDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index dd94fbc..2bb345b 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2207,6 +2207,7 @@ static virDriver xenUnifiedDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ xenUnifiedDomainOpenConsole, /* domainOpenConsole */ }; diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 3fbdcc6..1273797 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1888,6 +1888,7 @@ static virDriver xenapiDriver = { NULL, /* domainRevertToSnapshot */ NULL, /* domainSnapshotDelete */ NULL, /* qemuDomainMonitorCommand */ + NULL, /* qemuDomainAttach */ NULL, /* domainOpenConsole */ }; -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list