提交 bbe97ae9 编写于 作者: J Jim Fehlig

Fix starting domains when kernel has no cgroups support

Found that I was unable to start existing domains after updating
to a kernel with no cgroups support

  # zgrep CGROUP /proc/config.gz
  # CONFIG_CGROUPS is not set
  # virsh start test
  error: Failed to start domain test
  error: Unable to initialize /machine cgroup: Cannot allocate memory

virCgroupPartitionNeedsEscaping() correctly returns errno (ENOENT) when
attempting to open /proc/cgroups on such a system, but it was being
dropped in virCgroupSetPartitionSuffix().

Change virCgroupSetPartitionSuffix() to propagate errors returned by
its callees.  Also check for ENOENT in qemuInitCgroup() when determining
if cgroups support is available.
上级 a011479d
...@@ -456,7 +456,8 @@ int qemuInitCgroup(virQEMUDriverPtr driver, ...@@ -456,7 +456,8 @@ int qemuInitCgroup(virQEMUDriverPtr driver,
if (rc != 0) { if (rc != 0) {
if (rc == -ENXIO || if (rc == -ENXIO ||
rc == -EPERM || rc == -EPERM ||
rc == -EACCES) { /* No cgroups mounts == success */ rc == -EACCES ||
rc == -ENOENT) { /* No cgroups mounts == success */
VIR_DEBUG("No cgroups present/configured/accessible, ignoring error"); VIR_DEBUG("No cgroups present/configured/accessible, ignoring error");
goto done; goto done;
} }
......
...@@ -1168,14 +1168,14 @@ static int virCgroupPartitionEscape(char **path) ...@@ -1168,14 +1168,14 @@ static int virCgroupPartitionEscape(char **path)
return 0; return 0;
} }
static char *virCgroupSetPartitionSuffix(const char *path) static int virCgroupSetPartitionSuffix(const char *path, char **res)
{ {
char **tokens = virStringSplit(path, "/", 0); char **tokens = virStringSplit(path, "/", 0);
size_t i; size_t i;
char *ret = NULL; int ret = -1;
if (!tokens) if (!tokens)
return NULL; return ret;
for (i = 0 ; tokens[i] != NULL ; i++) { for (i = 0 ; tokens[i] != NULL ; i++) {
/* Whitelist the 3 top level fixed dirs /* Whitelist the 3 top level fixed dirs
...@@ -1194,20 +1194,27 @@ static char *virCgroupSetPartitionSuffix(const char *path) ...@@ -1194,20 +1194,27 @@ static char *virCgroupSetPartitionSuffix(const char *path)
!strchr(tokens[i], '.')) { !strchr(tokens[i], '.')) {
if (VIR_REALLOC_N(tokens[i], if (VIR_REALLOC_N(tokens[i],
strlen(tokens[i]) + strlen(".partition") + 1) < 0) { strlen(tokens[i]) + strlen(".partition") + 1) < 0) {
ret = -ENOMEM;
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
strcat(tokens[i], ".partition"); strcat(tokens[i], ".partition");
} }
if (virCgroupPartitionEscape(&(tokens[i])) < 0) { ret = virCgroupPartitionEscape(&(tokens[i]));
virReportOOMError(); if (ret < 0) {
if (ret == -ENOMEM)
virReportOOMError();
goto cleanup; goto cleanup;
} }
} }
if (!(ret = virStringJoin((const char **)tokens, "/"))) if (!(*res = virStringJoin((const char **)tokens, "/"))) {
ret = -ENOMEM;
goto cleanup; goto cleanup;
}
ret = 0;
cleanup: cleanup:
virStringFreeList(tokens); virStringFreeList(tokens);
...@@ -1242,9 +1249,9 @@ int virCgroupNewPartition(const char *path, ...@@ -1242,9 +1249,9 @@ int virCgroupNewPartition(const char *path,
/* XXX convert all cgroups APIs to use error report /* XXX convert all cgroups APIs to use error report
* APIs instead of returning errno */ * APIs instead of returning errno */
if (!(newpath = virCgroupSetPartitionSuffix(path))) { rc = virCgroupSetPartitionSuffix(path, &newpath);
if (rc < 0) {
virResetLastError(); virResetLastError();
rc = -ENOMEM;
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册