提交 c39554bf 编写于 作者: D Daniel P. Berrange

Remove virConnectPtr from LXC driver

上级 caa805ea
...@@ -63,8 +63,8 @@ struct __lxc_driver { ...@@ -63,8 +63,8 @@ struct __lxc_driver {
int lxcLoadDriverConfig(lxc_driver_t *driver); int lxcLoadDriverConfig(lxc_driver_t *driver);
virCapsPtr lxcCapsInit(void); virCapsPtr lxcCapsInit(void);
#define lxcError(conn, dom, code, fmt...) \ #define lxcError(code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_LXC, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_LXC, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)
#endif /* LXC_CONF_H */ #endif /* LXC_CONF_H */
...@@ -684,13 +684,13 @@ static int lxcContainerDropCapabilities(void) ...@@ -684,13 +684,13 @@ static int lxcContainerDropCapabilities(void)
CAP_AUDIT_CONTROL, /* No messing with auditing status */ CAP_AUDIT_CONTROL, /* No messing with auditing status */
CAP_MAC_ADMIN, /* No messing with LSM config */ CAP_MAC_ADMIN, /* No messing with LSM config */
-1 /* sentinal */)) < 0) { -1 /* sentinal */)) < 0) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Failed to remove capabilities: %d"), ret); _("Failed to remove capabilities: %d"), ret);
return -1; return -1;
} }
if ((ret = capng_apply(CAPNG_SELECT_BOTH)) < 0) { if ((ret = capng_apply(CAPNG_SELECT_BOTH)) < 0) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Failed to apply capabilities: %d"), ret); _("Failed to apply capabilities: %d"), ret);
return -1; return -1;
} }
...@@ -729,7 +729,7 @@ static int lxcContainerChild( void *data ) ...@@ -729,7 +729,7 @@ static int lxcContainerChild( void *data )
virDomainFSDefPtr root; virDomainFSDefPtr root;
if (NULL == vmDef) { if (NULL == vmDef) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
"%s", _("lxcChild() passed invalid vm definition")); "%s", _("lxcChild() passed invalid vm definition"));
return -1; return -1;
} }
......
...@@ -179,7 +179,7 @@ static int lxcMonitorServer(const char *sockpath) ...@@ -179,7 +179,7 @@ static int lxcMonitorServer(const char *sockpath)
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
if (virStrcpyStatic(addr.sun_path, sockpath) == NULL) { if (virStrcpyStatic(addr.sun_path, sockpath) == NULL) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Socket path %s too long for destination"), sockpath); _("Socket path %s too long for destination"), sockpath);
goto error; goto error;
} }
...@@ -253,7 +253,7 @@ static int lxcControllerClearCapabilities(void) ...@@ -253,7 +253,7 @@ static int lxcControllerClearCapabilities(void)
capng_clear(CAPNG_SELECT_BOTH); capng_clear(CAPNG_SELECT_BOTH);
if ((ret = capng_apply(CAPNG_SELECT_BOTH)) < 0) { if ((ret = capng_apply(CAPNG_SELECT_BOTH)) < 0) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("failed to apply capabilities: %d"), ret); _("failed to apply capabilities: %d"), ret);
return -1; return -1;
} }
...@@ -380,7 +380,7 @@ static int lxcControllerMain(int monitor, ...@@ -380,7 +380,7 @@ static int lxcControllerMain(int monitor,
DEBUG("EPOLLHUP from fd %d", epollEvent.data.fd); DEBUG("EPOLLHUP from fd %d", epollEvent.data.fd);
continue; continue;
} else { } else {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("error event %d"), epollEvent.events); _("error event %d"), epollEvent.events);
goto cleanup; goto cleanup;
} }
...@@ -451,7 +451,7 @@ static int lxcControllerMoveInterfaces(unsigned int nveths, ...@@ -451,7 +451,7 @@ static int lxcControllerMoveInterfaces(unsigned int nveths,
unsigned int i; unsigned int i;
for (i = 0 ; i < nveths ; i++) for (i = 0 ; i < nveths ; i++)
if (moveInterfaceToNetNs(veths[i], container) < 0) { if (moveInterfaceToNetNs(veths[i], container) < 0) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Failed to move interface %s to ns %d"), _("Failed to move interface %s to ns %d"),
veths[i], container); veths[i], container);
return -1; return -1;
...@@ -476,7 +476,7 @@ static int lxcControllerCleanupInterfaces(unsigned int nveths, ...@@ -476,7 +476,7 @@ static int lxcControllerCleanupInterfaces(unsigned int nveths,
unsigned int i; unsigned int i;
for (i = 0 ; i < nveths ; i++) for (i = 0 ; i < nveths ; i++)
if (vethDelete(veths[i]) < 0) if (vethDelete(veths[i]) < 0)
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Failed to delete veth: %s"), veths[i]); _("Failed to delete veth: %s"), veths[i]);
/* will continue to try to cleanup any other interfaces */ /* will continue to try to cleanup any other interfaces */
......
...@@ -127,7 +127,7 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn, ...@@ -127,7 +127,7 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn,
/* If path isn't '/' then they typoed, tell them correct path */ /* If path isn't '/' then they typoed, tell them correct path */
if (STRNEQ(conn->uri->path, "/")) { if (STRNEQ(conn->uri->path, "/")) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected LXC URI path '%s', try lxc:///"), _("Unexpected LXC URI path '%s', try lxc:///"),
conn->uri->path); conn->uri->path);
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
...@@ -135,7 +135,7 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn, ...@@ -135,7 +135,7 @@ static virDrvOpenStatus lxcOpen(virConnectPtr conn,
/* URI was good, but driver isn't active */ /* URI was good, but driver isn't active */
if (lxc_driver == NULL) { if (lxc_driver == NULL) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
"%s", _("lxc state driver is not active")); "%s", _("lxc state driver is not active"));
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
} }
...@@ -198,7 +198,7 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn, ...@@ -198,7 +198,7 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(conn, NULL, VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup; goto cleanup;
} }
...@@ -224,7 +224,7 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn, ...@@ -224,7 +224,7 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn,
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(conn, NULL, VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup; goto cleanup;
} }
...@@ -249,7 +249,7 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn, ...@@ -249,7 +249,7 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
vm = virDomainFindByName(&driver->domains, name); vm = virDomainFindByName(&driver->domains, name);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(conn, NULL, VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup; goto cleanup;
} }
...@@ -274,7 +274,7 @@ static int lxcDomainIsActive(virDomainPtr dom) ...@@ -274,7 +274,7 @@ static int lxcDomainIsActive(virDomainPtr dom)
obj = virDomainFindByUUID(&driver->domains, dom->uuid); obj = virDomainFindByUUID(&driver->domains, dom->uuid);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!obj) { if (!obj) {
lxcError(dom->conn, NULL, VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup; goto cleanup;
} }
ret = virDomainObjIsActive(obj); ret = virDomainObjIsActive(obj);
...@@ -296,7 +296,7 @@ static int lxcDomainIsPersistent(virDomainPtr dom) ...@@ -296,7 +296,7 @@ static int lxcDomainIsPersistent(virDomainPtr dom)
obj = virDomainFindByUUID(&driver->domains, dom->uuid); obj = virDomainFindByUUID(&driver->domains, dom->uuid);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!obj) { if (!obj) {
lxcError(dom->conn, NULL, VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup; goto cleanup;
} }
ret = obj->persistent; ret = obj->persistent;
...@@ -374,7 +374,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml) ...@@ -374,7 +374,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
goto cleanup; goto cleanup;
if ((def->nets != NULL) && !(driver->have_netns)) { if ((def->nets != NULL) && !(driver->have_netns)) {
lxcError(conn, NULL, VIR_ERR_NO_SUPPORT, lxcError(VIR_ERR_NO_SUPPORT,
"%s", _("System lacks NETNS support")); "%s", _("System lacks NETNS support"));
goto cleanup; goto cleanup;
} }
...@@ -423,19 +423,19 @@ static int lxcDomainUndefine(virDomainPtr dom) ...@@ -423,19 +423,19 @@ static int lxcDomainUndefine(virDomainPtr dom)
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
"%s", _("No domain with matching uuid")); "%s", _("No domain with matching uuid"));
goto cleanup; goto cleanup;
} }
if (virDomainObjIsActive(vm)) { if (virDomainObjIsActive(vm)) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, lxcError(VIR_ERR_OPERATION_INVALID,
"%s", _("Cannot delete active domain")); "%s", _("Cannot delete active domain"));
goto cleanup; goto cleanup;
} }
if (!vm->persistent) { if (!vm->persistent) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, lxcError(VIR_ERR_OPERATION_INVALID,
"%s", _("Cannot undefine transient domain")); "%s", _("Cannot undefine transient domain"));
goto cleanup; goto cleanup;
} }
...@@ -475,7 +475,7 @@ static int lxcDomainGetInfo(virDomainPtr dom, ...@@ -475,7 +475,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
"%s", _("No domain with matching uuid")); "%s", _("No domain with matching uuid"));
goto cleanup; goto cleanup;
} }
...@@ -487,18 +487,18 @@ static int lxcDomainGetInfo(virDomainPtr dom, ...@@ -487,18 +487,18 @@ static int lxcDomainGetInfo(virDomainPtr dom,
info->memory = vm->def->memory; info->memory = vm->def->memory;
} else { } else {
if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Unable to get cgroup for %s"), vm->def->name); _("Unable to get cgroup for %s"), vm->def->name);
goto cleanup; goto cleanup;
} }
if (virCgroupGetCpuacctUsage(cgroup, &(info->cpuTime)) < 0) { if (virCgroupGetCpuacctUsage(cgroup, &(info->cpuTime)) < 0) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, lxcError(VIR_ERR_OPERATION_FAILED,
"%s", _("Cannot read cputime for domain")); "%s", _("Cannot read cputime for domain"));
goto cleanup; goto cleanup;
} }
if (virCgroupGetMemoryUsage(cgroup, &(info->memory)) < 0) { if (virCgroupGetMemoryUsage(cgroup, &(info->memory)) < 0) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, lxcError(VIR_ERR_OPERATION_FAILED,
"%s", _("Cannot read memory usage for domain")); "%s", _("Cannot read memory usage for domain"));
goto cleanup; goto cleanup;
} }
...@@ -528,7 +528,7 @@ static char *lxcGetOSType(virDomainPtr dom) ...@@ -528,7 +528,7 @@ static char *lxcGetOSType(virDomainPtr dom)
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
"%s", _("No domain with matching uuid")); "%s", _("No domain with matching uuid"));
goto cleanup; goto cleanup;
} }
...@@ -557,7 +557,7 @@ static unsigned long lxcDomainGetMaxMemory(virDomainPtr dom) { ...@@ -557,7 +557,7 @@ static unsigned long lxcDomainGetMaxMemory(virDomainPtr dom) {
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
...@@ -582,13 +582,13 @@ static int lxcDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) { ...@@ -582,13 +582,13 @@ static int lxcDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) {
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (newmax < vm->def->memory) { if (newmax < vm->def->memory) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_ARG, lxcError(VIR_ERR_INVALID_ARG,
"%s", _("Cannot set max memory lower than current memory")); "%s", _("Cannot set max memory lower than current memory"));
goto cleanup; goto cleanup;
} }
...@@ -614,26 +614,26 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) { ...@@ -614,26 +614,26 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (newmem > vm->def->maxmem) { if (newmem > vm->def->maxmem) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_ARG, lxcError(VIR_ERR_INVALID_ARG,
"%s", _("Cannot set memory higher than max memory")); "%s", _("Cannot set memory higher than max memory"));
goto cleanup; goto cleanup;
} }
if (virDomainObjIsActive(vm)) { if (virDomainObjIsActive(vm)) {
if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) {
lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Unable to get cgroup for %s\n"), vm->def->name); _("Unable to get cgroup for %s\n"), vm->def->name);
goto cleanup; goto cleanup;
} }
if (virCgroupSetMemory(cgroup, newmem) < 0) { if (virCgroupSetMemory(cgroup, newmem) < 0) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, lxcError(VIR_ERR_OPERATION_FAILED,
"%s", _("Failed to set memory for domain")); "%s", _("Failed to set memory for domain"));
goto cleanup; goto cleanup;
} }
...@@ -662,7 +662,7 @@ static char *lxcDomainDumpXML(virDomainPtr dom, ...@@ -662,7 +662,7 @@ static char *lxcDomainDumpXML(virDomainPtr dom,
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
"%s", _("No domain with matching uuid")); "%s", _("No domain with matching uuid"));
goto cleanup; goto cleanup;
} }
...@@ -691,8 +691,7 @@ cleanup: ...@@ -691,8 +691,7 @@ cleanup:
* *
* Returns 0 on success or -1 in case of error * Returns 0 on success or -1 in case of error
*/ */
static int lxcVmCleanup(virConnectPtr conn, static int lxcVmCleanup(lxc_driver_t *driver,
lxc_driver_t *driver,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
int rc = -1; int rc = -1;
...@@ -723,7 +722,7 @@ static int lxcVmCleanup(virConnectPtr conn, ...@@ -723,7 +722,7 @@ static int lxcVmCleanup(virConnectPtr conn,
close(priv->monitor); close(priv->monitor);
virFileDeletePid(driver->stateDir, vm->def->name); virFileDeletePid(driver->stateDir, vm->def->name);
virDomainDeleteConfig(conn, driver->stateDir, NULL, vm); virDomainDeleteConfig(NULL, driver->stateDir, NULL, vm);
vm->state = VIR_DOMAIN_SHUTOFF; vm->state = VIR_DOMAIN_SHUTOFF;
vm->pid = -1; vm->pid = -1;
...@@ -801,7 +800,7 @@ static int lxcSetupInterfaces(virConnectPtr conn, ...@@ -801,7 +800,7 @@ static int lxcSetupInterfaces(virConnectPtr conn,
DEBUG("bridge: %s", bridge); DEBUG("bridge: %s", bridge);
if (NULL == bridge) { if (NULL == bridge) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to get bridge for interface")); "%s", _("Failed to get bridge for interface"));
goto error_exit; goto error_exit;
} }
...@@ -812,7 +811,7 @@ static int lxcSetupInterfaces(virConnectPtr conn, ...@@ -812,7 +811,7 @@ static int lxcSetupInterfaces(virConnectPtr conn,
} }
DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth); DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
if (0 != (rc = vethCreate(parentVeth, PATH_MAX, containerVeth, PATH_MAX))) { if (0 != (rc = vethCreate(parentVeth, PATH_MAX, containerVeth, PATH_MAX))) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Failed to create veth device pair: %d"), rc); _("Failed to create veth device pair: %d"), rc);
goto error_exit; goto error_exit;
} }
...@@ -869,8 +868,7 @@ error_exit: ...@@ -869,8 +868,7 @@ error_exit:
} }
static int lxcMonitorClient(virConnectPtr conn, static int lxcMonitorClient(lxc_driver_t * driver,
lxc_driver_t * driver,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
char *sockpath = NULL; char *sockpath = NULL;
...@@ -892,7 +890,7 @@ static int lxcMonitorClient(virConnectPtr conn, ...@@ -892,7 +890,7 @@ static int lxcMonitorClient(virConnectPtr conn,
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
if (virStrcpyStatic(addr.sun_path, sockpath) == NULL) { if (virStrcpyStatic(addr.sun_path, sockpath) == NULL) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Socket path %s too big for destination"), sockpath); _("Socket path %s too big for destination"), sockpath);
goto error; goto error;
} }
...@@ -914,8 +912,7 @@ error: ...@@ -914,8 +912,7 @@ error:
} }
static int lxcVmTerminate(virConnectPtr conn, static int lxcVmTerminate(lxc_driver_t *driver,
lxc_driver_t *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
int signum) int signum)
{ {
...@@ -923,7 +920,7 @@ static int lxcVmTerminate(virConnectPtr conn, ...@@ -923,7 +920,7 @@ static int lxcVmTerminate(virConnectPtr conn,
signum = SIGINT; signum = SIGINT;
if (vm->pid <= 0) { if (vm->pid <= 0) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Invalid PID %d for container"), vm->pid); _("Invalid PID %d for container"), vm->pid);
return -1; return -1;
} }
...@@ -939,7 +936,7 @@ static int lxcVmTerminate(virConnectPtr conn, ...@@ -939,7 +936,7 @@ static int lxcVmTerminate(virConnectPtr conn,
vm->state = VIR_DOMAIN_SHUTDOWN; vm->state = VIR_DOMAIN_SHUTDOWN;
return lxcVmCleanup(conn, driver, vm); return lxcVmCleanup(driver, vm);
} }
static void lxcMonitorEvent(int watch, static void lxcMonitorEvent(int watch,
...@@ -963,7 +960,7 @@ static void lxcMonitorEvent(int watch, ...@@ -963,7 +960,7 @@ static void lxcMonitorEvent(int watch,
goto cleanup; goto cleanup;
} }
if (lxcVmTerminate(NULL, driver, vm, SIGINT) < 0) { if (lxcVmTerminate(driver, vm, SIGINT) < 0) {
virEventRemoveHandle(watch); virEventRemoveHandle(watch);
} else { } else {
event = virDomainEventNewFromObj(vm, event = virDomainEventNewFromObj(vm,
...@@ -986,7 +983,7 @@ cleanup: ...@@ -986,7 +983,7 @@ cleanup:
} }
static int lxcControllerStart(virConnectPtr conn, static int lxcControllerStart(lxc_driver_t *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
int nveths, int nveths,
char **veths, char **veths,
...@@ -1008,7 +1005,6 @@ static int lxcControllerStart(virConnectPtr conn, ...@@ -1008,7 +1005,6 @@ static int lxcControllerStart(virConnectPtr conn,
fd_set keepfd; fd_set keepfd;
char appPtyStr[30]; char appPtyStr[30];
const char *emulator; const char *emulator;
lxc_driver_t *driver = conn->privateData;
FD_ZERO(&keepfd); FD_ZERO(&keepfd);
...@@ -1138,7 +1134,7 @@ static int lxcControllerStart(virConnectPtr conn, ...@@ -1138,7 +1134,7 @@ static int lxcControllerStart(virConnectPtr conn,
} }
if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) { if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Container '%s' unexpectedly shutdown during startup"), _("Container '%s' unexpectedly shutdown during startup"),
largv[0]); largv[0]);
goto cleanup; goto cleanup;
...@@ -1235,7 +1231,7 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1235,7 +1231,7 @@ static int lxcVmStart(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (lxcControllerStart(conn, if (lxcControllerStart(driver,
vm, vm,
nveths, veths, nveths, veths,
parentTty, logfd) < 0) parentTty, logfd) < 0)
...@@ -1244,7 +1240,7 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1244,7 +1240,7 @@ static int lxcVmStart(virConnectPtr conn,
/* Connect to the controller as a client *first* because /* Connect to the controller as a client *first* because
* this will block until the child has written their * this will block until the child has written their
* pid file out to disk */ * pid file out to disk */
if ((priv->monitor = lxcMonitorClient(conn, driver, vm)) < 0) if ((priv->monitor = lxcMonitorClient(driver, vm)) < 0)
goto cleanup; goto cleanup;
/* And get its pid */ /* And get its pid */
...@@ -1263,7 +1259,7 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1263,7 +1259,7 @@ static int lxcVmStart(virConnectPtr conn,
VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP, VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
lxcMonitorEvent, lxcMonitorEvent,
vm, NULL)) < 0) { vm, NULL)) < 0) {
lxcVmTerminate(conn, driver, vm, 0); lxcVmTerminate(driver, vm, 0);
goto cleanup; goto cleanup;
} }
...@@ -1305,13 +1301,13 @@ static int lxcDomainStart(virDomainPtr dom) ...@@ -1305,13 +1301,13 @@ static int lxcDomainStart(virDomainPtr dom)
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByName(&driver->domains, dom->name); vm = virDomainFindByName(&driver->domains, dom->name);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
_("No domain named %s"), dom->name); _("No domain named %s"), dom->name);
goto cleanup; goto cleanup;
} }
if ((vm->def->nets != NULL) && !(driver->have_netns)) { if ((vm->def->nets != NULL) && !(driver->have_netns)) {
lxcError(dom->conn, NULL, VIR_ERR_NO_SUPPORT, lxcError(VIR_ERR_NO_SUPPORT,
"%s", _("System lacks NETNS support")); "%s", _("System lacks NETNS support"));
goto cleanup; goto cleanup;
} }
...@@ -1361,7 +1357,7 @@ lxcDomainCreateAndStart(virConnectPtr conn, ...@@ -1361,7 +1357,7 @@ lxcDomainCreateAndStart(virConnectPtr conn,
goto cleanup; goto cleanup;
if ((def->nets != NULL) && !(driver->have_netns)) { if ((def->nets != NULL) && !(driver->have_netns)) {
lxcError(conn, NULL, VIR_ERR_NO_SUPPORT, lxcError(VIR_ERR_NO_SUPPORT,
"%s", _("System lacks NETNS support")); "%s", _("System lacks NETNS support"));
goto cleanup; goto cleanup;
} }
...@@ -1414,12 +1410,12 @@ static int lxcDomainShutdown(virDomainPtr dom) ...@@ -1414,12 +1410,12 @@ static int lxcDomainShutdown(virDomainPtr dom)
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByID(&driver->domains, dom->id); vm = virDomainFindByID(&driver->domains, dom->id);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
_("No domain with id %d"), dom->id); _("No domain with id %d"), dom->id);
goto cleanup; goto cleanup;
} }
ret = lxcVmTerminate(dom->conn, driver, vm, 0); ret = lxcVmTerminate(driver, vm, 0);
event = virDomainEventNewFromObj(vm, event = virDomainEventNewFromObj(vm,
VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN); VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
...@@ -1547,12 +1543,12 @@ static int lxcDomainDestroy(virDomainPtr dom) ...@@ -1547,12 +1543,12 @@ static int lxcDomainDestroy(virDomainPtr dom)
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByID(&driver->domains, dom->id); vm = virDomainFindByID(&driver->domains, dom->id);
if (!vm) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(VIR_ERR_INVALID_DOMAIN,
_("No domain with id %d"), dom->id); _("No domain with id %d"), dom->id);
goto cleanup; goto cleanup;
} }
ret = lxcVmTerminate(dom->conn, driver, vm, SIGKILL); ret = lxcVmTerminate(driver, vm, SIGKILL);
event = virDomainEventNewFromObj(vm, event = virDomainEventNewFromObj(vm,
VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED); VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
...@@ -1650,7 +1646,7 @@ lxcReconnectVM(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaque) ...@@ -1650,7 +1646,7 @@ lxcReconnectVM(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaque)
virDomainObjLock(vm); virDomainObjLock(vm);
priv = vm->privateData; priv = vm->privateData;
if ((priv->monitor = lxcMonitorClient(NULL, driver, vm)) < 0) { if ((priv->monitor = lxcMonitorClient(driver, vm)) < 0) {
goto cleanup; goto cleanup;
} }
...@@ -1683,7 +1679,7 @@ lxcReconnectVM(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaque) ...@@ -1683,7 +1679,7 @@ lxcReconnectVM(void *payload, const char *name ATTRIBUTE_UNUSED, void *opaque)
VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP, VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
lxcMonitorEvent, lxcMonitorEvent,
vm, NULL)) < 0) { vm, NULL)) < 0) {
lxcVmTerminate(NULL, driver, vm, 0); lxcVmTerminate(driver, vm, 0);
goto cleanup; goto cleanup;
} }
} else { } else {
...@@ -1870,7 +1866,7 @@ lxcActive(void) { ...@@ -1870,7 +1866,7 @@ lxcActive(void) {
return active; return active;
} }
static int lxcVersion(virConnectPtr conn, unsigned long *version) static int lxcVersion(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned long *version)
{ {
struct utsname ver; struct utsname ver;
int maj; int maj;
...@@ -1880,7 +1876,7 @@ static int lxcVersion(virConnectPtr conn, unsigned long *version) ...@@ -1880,7 +1876,7 @@ static int lxcVersion(virConnectPtr conn, unsigned long *version)
uname(&ver); uname(&ver);
if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) { if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("Unknown release: %s"), ver.release); _("Unknown release: %s"), ver.release);
return -1; return -1;
} }
...@@ -1923,7 +1919,7 @@ static int lxcSetSchedulerParameters(virDomainPtr domain, ...@@ -1923,7 +1919,7 @@ static int lxcSetSchedulerParameters(virDomainPtr domain,
vm = virDomainFindByUUID(&driver->domains, domain->uuid); vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (vm == NULL) { if (vm == NULL) {
lxcError(NULL, domain, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("No such domain %s"), domain->uuid); _("No such domain %s"), domain->uuid);
goto cleanup; goto cleanup;
} }
...@@ -1934,7 +1930,7 @@ static int lxcSetSchedulerParameters(virDomainPtr domain, ...@@ -1934,7 +1930,7 @@ static int lxcSetSchedulerParameters(virDomainPtr domain,
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
virSchedParameterPtr param = &params[i]; virSchedParameterPtr param = &params[i];
if (param->type != VIR_DOMAIN_SCHED_FIELD_ULLONG) { if (param->type != VIR_DOMAIN_SCHED_FIELD_ULLONG) {
lxcError(NULL, domain, VIR_ERR_INVALID_ARG, "%s", lxcError(VIR_ERR_INVALID_ARG, "%s",
_("Invalid type for cpu_shares tunable, expected a 'ullong'")); _("Invalid type for cpu_shares tunable, expected a 'ullong'"));
goto cleanup; goto cleanup;
} }
...@@ -1943,7 +1939,7 @@ static int lxcSetSchedulerParameters(virDomainPtr domain, ...@@ -1943,7 +1939,7 @@ static int lxcSetSchedulerParameters(virDomainPtr domain,
if (virCgroupSetCpuShares(group, params[i].value.ul) != 0) if (virCgroupSetCpuShares(group, params[i].value.ul) != 0)
goto cleanup; goto cleanup;
} else { } else {
lxcError(NULL, domain, VIR_ERR_INVALID_ARG, lxcError(VIR_ERR_INVALID_ARG,
_("Invalid parameter `%s'"), param->field); _("Invalid parameter `%s'"), param->field);
goto cleanup; goto cleanup;
} }
...@@ -1972,7 +1968,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain, ...@@ -1972,7 +1968,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain,
return -1; return -1;
if ((*nparams) != 1) { if ((*nparams) != 1) {
lxcError(NULL, domain, VIR_ERR_INVALID_ARG, lxcError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count")); "%s", _("Invalid parameter count"));
return -1; return -1;
} }
...@@ -1981,7 +1977,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain, ...@@ -1981,7 +1977,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain,
vm = virDomainFindByUUID(&driver->domains, domain->uuid); vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (vm == NULL) { if (vm == NULL) {
lxcError(NULL, domain, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("No such domain %s"), domain->uuid); _("No such domain %s"), domain->uuid);
goto cleanup; goto cleanup;
} }
...@@ -1993,7 +1989,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain, ...@@ -1993,7 +1989,7 @@ static int lxcGetSchedulerParameters(virDomainPtr domain,
goto cleanup; goto cleanup;
params[0].value.ul = val; params[0].value.ul = val;
if (virStrcpyStatic(params[0].field, "cpu_shares") == NULL) { if (virStrcpyStatic(params[0].field, "cpu_shares") == NULL) {
lxcError(NULL, domain, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field cpu_shares too big for destination")); "%s", _("Field cpu_shares too big for destination"));
goto cleanup; goto cleanup;
} }
...@@ -2027,13 +2023,13 @@ lxcDomainInterfaceStats(virDomainPtr dom, ...@@ -2027,13 +2023,13 @@ lxcDomainInterfaceStats(virDomainPtr dom,
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, lxcError(VIR_ERR_OPERATION_INVALID,
"%s", _("Domain is not running")); "%s", _("Domain is not running"));
goto cleanup; goto cleanup;
} }
...@@ -2050,7 +2046,7 @@ lxcDomainInterfaceStats(virDomainPtr dom, ...@@ -2050,7 +2046,7 @@ lxcDomainInterfaceStats(virDomainPtr dom,
if (ret == 0) if (ret == 0)
ret = linuxDomainInterfaceStats(path, stats); ret = linuxDomainInterfaceStats(path, stats);
else else
lxcError(dom->conn, dom, VIR_ERR_INVALID_ARG, lxcError(VIR_ERR_INVALID_ARG,
_("Invalid path, '%s' is not a known interface"), path); _("Invalid path, '%s' is not a known interface"), path);
cleanup: cleanup:
...@@ -2063,7 +2059,7 @@ static int ...@@ -2063,7 +2059,7 @@ static int
lxcDomainInterfaceStats(virDomainPtr dom, lxcDomainInterfaceStats(virDomainPtr dom,
const char *path ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED,
struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED) struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED)
lxcError(dom->conn, dom, VIR_ERR_NO_SUPPORT, "%s", __FUNCTION__); lxcError(VIR_ERR_NO_SUPPORT, "%s", __FUNCTION__);
return -1; return -1;
} }
#endif #endif
...@@ -2081,7 +2077,7 @@ static int lxcDomainGetAutostart(virDomainPtr dom, ...@@ -2081,7 +2077,7 @@ static int lxcDomainGetAutostart(virDomainPtr dom,
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
...@@ -2108,13 +2104,13 @@ static int lxcDomainSetAutostart(virDomainPtr dom, ...@@ -2108,13 +2104,13 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (!vm->persistent) { if (!vm->persistent) {
lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Cannot set autostart for transient domain")); "%s", _("Cannot set autostart for transient domain"));
goto cleanup; goto cleanup;
} }
...@@ -2277,20 +2273,20 @@ static int lxcDomainSuspend(virDomainPtr dom) ...@@ -2277,20 +2273,20 @@ static int lxcDomainSuspend(virDomainPtr dom)
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, lxcError(VIR_ERR_OPERATION_INVALID,
"%s", _("Domain is not running")); "%s", _("Domain is not running"));
goto cleanup; goto cleanup;
} }
if (vm->state != VIR_DOMAIN_PAUSED) { if (vm->state != VIR_DOMAIN_PAUSED) {
if (lxcFreezeContainer(driver, vm) < 0) { if (lxcFreezeContainer(driver, vm) < 0) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, lxcError(VIR_ERR_OPERATION_FAILED,
"%s", _("Suspend operation failed")); "%s", _("Suspend operation failed"));
goto cleanup; goto cleanup;
} }
...@@ -2342,20 +2338,20 @@ static int lxcDomainResume(virDomainPtr dom) ...@@ -2342,20 +2338,20 @@ static int lxcDomainResume(virDomainPtr dom)
if (!vm) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
lxcError(dom->conn, dom, VIR_ERR_NO_DOMAIN, lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr); _("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, lxcError(VIR_ERR_OPERATION_INVALID,
"%s", _("Domain is not running")); "%s", _("Domain is not running"));
goto cleanup; goto cleanup;
} }
if (vm->state == VIR_DOMAIN_PAUSED) { if (vm->state == VIR_DOMAIN_PAUSED) {
if (lxcUnfreezeContainer(driver, vm) < 0) { if (lxcUnfreezeContainer(driver, vm) < 0) {
lxcError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, lxcError(VIR_ERR_OPERATION_FAILED,
"%s", _("Resume operation failed")); "%s", _("Resume operation failed"));
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册