/** * virDomainQemuAgentCommand: * @domain: a domain object * @cmd: the guest agent command string * @timeout: timeout seconds * @flags: execution flags * * Execute an arbitrary Guest Agent command. * * Issue @cmd to the guest agent running in @domain. * @timeout must be -2, -1, 0 or positive. * VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK(-2): meaning to block forever waiting for * a result. * VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT(-1): use default timeout value. * VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT(0): does not wait. * positive value: wait for @timeout seconds * * Returns strings if success, NULL in failure. */ char * virDomainQemuAgentCommand(virDomainPtr domain, const char *cmd, int timeout, unsigned int flags) { virConnectPtr conn; VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x", domain, cmd, timeout, flags); if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); return NULL; } if (domain->conn->flags & VIR_CONNECT_RO) { virLibDomainError(NULL, VIR_ERR_OPERATION_DENIED, __FUNCTION__); return NULL; } conn = domain->conn; if (conn->driver->qemuDomainArbitraryAgentCommand) { return conn->driver->qemuDomainArbitraryAgentCommand(domain, cmd, timeout, flags); } virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); /* Copy to connection error object for back compatibility */ virDispatchError(conn); return NULL; }
/** * virDomainLxcOpenNamespace: * @domain: a domain object * @fdlist: pointer to an array to be filled with FDs * @flags: currently unused, pass 0 * * This API is LXC specific, so it will only work with hypervisor * connections to the LXC driver. * * Open the namespaces associated with the container @domain. * The @fdlist array will be allocated to a suitable size, * and filled with file descriptors for the namespaces. It * is the caller's responsibility to close the file descriptors * * The returned file descriptors are intended to be used with * the setns() system call. * * Returns the number of opened file descriptors, or -1 on error */ int virDomainLxcOpenNamespace(virDomainPtr domain, int **fdlist, unsigned int flags) { virConnectPtr conn; VIR_DEBUG("domain=%p, fdlist=%p flags=%x", domain, fdlist, flags); virResetLastError(); if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); return -1; } conn = domain->conn; virCheckNonNullArgGoto(fdlist, error); if (conn->flags & VIR_CONNECT_RO) { virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__); goto error; } if (conn->driver->domainLxcOpenNamespace) { int ret; ret = conn->driver->domainLxcOpenNamespace(domain, fdlist, flags); if (ret < 0) goto error; return ret; } virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); error: virDispatchError(conn); return -1; }
int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, char **result, unsigned int flags) { virConnectPtr conn; VIR_DEBUG("domain=%p, cmd=%s, result=%p, flags=%u", domain, cmd, result, flags); virResetLastError(); if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); return -1; } conn = domain->conn; if (result == NULL) { 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->qemuDomainMonitorCommand) { int ret; ret = conn->driver->qemuDomainMonitorCommand(domain, cmd, result, flags); if (ret < 0) goto error; return ret; } virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); error: virDispatchError(conn); return -1; }
/** * virDomainQemuAttach: * @conn: pointer to a hypervisor connection * @pid_value: the UNIX process ID of the external QEMU process * @flags: optional flags, currently unused * * This API is QEMU specific, so it 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 successfully * 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) * * To date, the only platforms we know of where pid_t is larger than * unsigned int (64-bit Windows) also lack UNIX sockets, so the choice * of @pid_value as an unsigned int should not present any difficulties. * * 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 honored). * * Returns a new domain object on success, NULL otherwise */ virDomainPtr virDomainQemuAttach(virConnectPtr conn, unsigned int pid_value, unsigned int flags) { pid_t pid = pid_value; VIR_DEBUG("conn=%p, pid=%u, flags=%x", conn, pid_value, flags); virResetLastError(); if (!VIR_IS_CONNECT(conn)) { virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); virDispatchError(NULL); return NULL; } virCheckPositiveArgGoto(pid_value, error); if (pid != pid_value) { virReportInvalidArg(pid_value, _("pid_value in %s is too large"), __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_value, flags); if (!ret) goto error; return ret; } virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); error: virDispatchError(conn); return NULL; }