diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h index f172eff0fe..7f12e4f587 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 int pid, + unsigned int flags); + # ifdef __cplusplus } # endif diff --git a/src/driver.h b/src/driver.h index 71a52c96c2..70ea4c235f 100644 --- a/src/driver.h +++ b/src/driver.h @@ -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; diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c index 46727c843c..b9aa2dc9fd 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -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; +} diff --git a/src/libvirt_qemu.syms b/src/libvirt_qemu.syms index 5702d367ed..8447730fd0 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.4 { + global: + virDomainQemuAttach; +} LIBVIRT_QEMU_0.8.3;