From: Daniel Lezcano Date: Fri, 9 Oct 2009 09:38:39 +0000 (+0200) Subject: use the configuration structure for the cgroup X-Git-Tag: lxc_0_6_4~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=102a53038a6d3485d7dc62e10cb964bb9e43a645;p=thirdparty%2Flxc.git use the configuration structure for the cgroup Do not use the directory configuration Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 1e80d245f..347757110 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -373,34 +373,6 @@ out: return err; } -static int configure_cgroup(const char *name, struct lxc_list *cgroup) -{ - char path[MAXPATHLEN]; - struct lxc_list *iterator; - struct lxc_cgroup *cg; - FILE *file; - - if (lxc_list_empty(cgroup)) - return 0; - - snprintf(path, MAXPATHLEN, LXCPATH "/%s/cgroup", name); - - file = fopen(path, "w+"); - if (!file) { - SYSERROR("failed to open '%s'", path); - return -1; - } - - lxc_list_for_each(iterator, cgroup) { - cg = iterator->elem; - fprintf(file, "%s=%s\n", cg->subsystem, cg->value); - } - - fclose(file); - - return 0; -} - static int configure_find_fstype_cb(void* buffer, void *data) { struct cbarg { @@ -876,107 +848,24 @@ static int setup_console(const char *rootfs, const char *tty) return 0; } -static int setup_cgroup_cb(void* buffer, void *data) +static int setup_cgroup(const char *name, struct lxc_list *cgroups) { - char *key = buffer, *value; - char *name = data; - int ret; - - value = strchr(key, '='); - if (!value) - return -1; - - *value = '\0'; - value += 1; - - /* remove spurious '\n'*/ - if (value[strlen(value) - 1] == '\n') - value[strlen(value) - 1] = '\0'; - - ret = lxc_cgroup_set(name, key, value); - if (ret) - ERROR("failed to set cgroup '%s' = '%s' for '%s'", - key, value, name); - else - DEBUG("cgroup '%s' set to '%s'", key, value); - - return ret; -} - -static int setup_convert_cgroup_cb(const char *name, const char *directory, - const char *file, void *data) -{ - FILE *f = data; - char line[MAXPATHLEN]; - - if (read_info(directory, file, line, MAXPATHLEN)) { - ERROR("failed to read %s", file); - return -1; - } - - fprintf(f, "%s=%s\n", file, line); - - return 0; -} - -static int setup_convert_cgroup(const char *name, char *directory) -{ - char filename[MAXPATHLEN]; - FILE *file; - int ret; - - snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup.new", name); - - file = fopen(filename, "w+"); - if (!file) - return -1; - - ret = lxc_dir_for_each(name, directory, setup_convert_cgroup_cb, file); - if (ret) - goto out_error; - - ret = unconfigure_cgroup(name); - if (ret) - goto out_error; - - ret = rename(filename, directory); - if (ret) - goto out_error; -out: - fclose(file); - return ret; + struct lxc_list *iterator; + struct lxc_cgroup *cg; -out_error: - unlink(filename); - goto out; -} + if (lxc_list_empty(cgroups)) + return 0; -static int setup_cgroup(const char *name) -{ - char filename[MAXPATHLEN]; - char line[MAXPATHLEN]; - struct stat s; - int ret; + lxc_list_for_each(iterator, cgroups) { - snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name); + cg = iterator->elem; - if (stat(filename, &s)) { - SYSERROR("failed to stat '%s'", filename); - return -1; - } + if (lxc_cgroup_set(name, cg->subsystem, cg->value)) + break; - if (S_ISDIR(s.st_mode)) { - if (setup_convert_cgroup(name, filename)) { - ERROR("failed to convert old cgroup configuration"); - return -1; - } + DEBUG("cgroup '%s' set to '%s'", cg->subsystem, cg->value); } - ret = lxc_file_for_each_line(filename, setup_cgroup_cb, - line, MAXPATHLEN, (void *)name); - if (ret) - return ret; - INFO("cgroup has been setup"); return 0; @@ -1363,11 +1252,6 @@ int lxc_configure(const char *name, struct lxc_conf *conf) if (!conf) return 0; - if (configure_cgroup(name, &conf->cgroup)) { - ERROR("failed to configure the control group"); - return -1; - } - if (configure_network(name, &conf->networks)) { ERROR("failed to configure the network"); return -1; @@ -1769,7 +1653,7 @@ int lxc_setup(const char *name, const char *cons, return -1; } - if (!lxc_list_empty(&lxc_conf.cgroup) && setup_cgroup(name)) { + if (setup_cgroup(name, &lxc_conf.cgroup)) { ERROR("failed to setup the cgroups for '%s'", name); return -1; }