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

Don't try to activate cgroups if not present for LXC

* src/lxc_controller.c: Don't throw error in LXC startup if
  the cgroups driver mount isn't available. Improve error
  logging for resource setup
上级 87f3d69d
...@@ -84,25 +84,38 @@ static int lxcSetContainerResources(virDomainDefPtr def) ...@@ -84,25 +84,38 @@ static int lxcSetContainerResources(virDomainDefPtr def)
rc = virCgroupForDriver("lxc", &driver, 1, 0); rc = virCgroupForDriver("lxc", &driver, 1, 0);
if (rc != 0) { if (rc != 0) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", /* Skip all if no driver cgroup is configured */
_("Unable to get cgroup for driver")); if (rc == -ENXIO || rc == -ENOENT)
return 0;
virReportSystemError(NULL, -rc, "%s",
_("Unable to get cgroup for driver"));
return rc; return rc;
} }
rc = virCgroupForDomain(driver, def->name, &cgroup, 1); rc = virCgroupForDomain(driver, def->name, &cgroup, 1);
if (rc != 0) { if (rc != 0) {
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR, virReportSystemError(NULL, -rc,
_("Unable to create cgroup for domain %s"), def->name); _("Unable to create cgroup for domain %s"),
def->name);
goto cleanup; goto cleanup;
} }
rc = virCgroupSetMemory(cgroup, def->maxmem); rc = virCgroupSetMemory(cgroup, def->maxmem);
if (rc != 0) if (rc != 0) {
goto out; virReportSystemError(NULL, -rc,
_("Unable to set memory limit for domain %s"),
def->name);
goto cleanup;
}
rc = virCgroupDenyAllDevices(cgroup); rc = virCgroupDenyAllDevices(cgroup);
if (rc != 0) if (rc != 0) {
goto out; virReportSystemError(NULL, -rc,
_("Unable to deny devices for domain %s"),
def->name);
goto cleanup;
}
for (i = 0; devices[i].type != 0; i++) { for (i = 0; devices[i].type != 0; i++) {
struct cgroup_device_policy *dev = &devices[i]; struct cgroup_device_policy *dev = &devices[i];
...@@ -110,19 +123,27 @@ static int lxcSetContainerResources(virDomainDefPtr def) ...@@ -110,19 +123,27 @@ static int lxcSetContainerResources(virDomainDefPtr def)
dev->type, dev->type,
dev->major, dev->major,
dev->minor); dev->minor);
if (rc != 0) if (rc != 0) {
goto out; virReportSystemError(NULL, -rc,
_("Unable to allow device %c:%d:%d for domain %s"),
dev->type, dev->major, dev->minor, def->name);
goto cleanup;
}
} }
rc = virCgroupAllowDeviceMajor(cgroup, 'c', LXC_DEV_MAJ_PTY); rc = virCgroupAllowDeviceMajor(cgroup, 'c', LXC_DEV_MAJ_PTY);
if (rc != 0) if (rc != 0) {
goto out; virReportSystemError(NULL, -rc,
_("Unable to allow PYT devices for domain %s"),
def->name);
goto cleanup;
}
rc = virCgroupAddTask(cgroup, getpid()); rc = virCgroupAddTask(cgroup, getpid());
out:
if (rc != 0) { if (rc != 0) {
virReportSystemError(NULL, -rc, "%s", virReportSystemError(NULL, -rc,
_("Failed to set lxc resources")); _("Unable to add task %d to cgroup for domain %s"),
getpid(), def->name);
} }
cleanup: cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册