/** * 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; }
/** * virUnrefDomain: * @domain: the domain to unreference * * Unreference the domain. If the use count drops to zero, the structure is * actually freed. * * Returns the reference count or -1 in case of failure. */ int virUnrefDomain(virDomainPtr domain) { int refs; if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibConnError(VIR_ERR_INVALID_DOMAIN, _("bad domain or no connection")); return -1; } virMutexLock(&domain->conn->lock); VIR_DEBUG("unref domain %p %s %d", domain, domain->name, domain->refs); domain->refs--; refs = domain->refs; if (refs == 0) { virReleaseDomain(domain); /* Already unlocked mutex */ return 0; } virMutexUnlock(&domain->conn->lock); return refs; }