summaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-08-13 19:35:01 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-08-13 19:35:01 +0000
commit5d3c683a3f4160cb4d081a3ddcf367311ddf0c8b (patch)
treefcb3bc308190d622eb1559714b82d8372e38a5e5 /config.c
parent5c16f4a02dfee006b7fb8a04162ed511e3abc481 (diff)
downloadlibcg-5d3c683a3f4160cb4d081a3ddcf367311ddf0c8b.tar.gz
libcg-5d3c683a3f4160cb4d081a3ddcf367311ddf0c8b.tar.xz
libcg-5d3c683a3f4160cb4d081a3ddcf367311ddf0c8b.zip
libcgroup: Configuration and parsing updates (v2)
Dhaval, wanted a patch with -p1 generated so that he can apply it and use it with quilt. Here goes Testing Tested with samples/cgconfig.conf (NOTE: expects user balbir to be present on the system, feel free to change and test). TODO 1. Add hooks for other controllers, namely memory, cpuacct and cpuset Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@134 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'config.c')
-rw-r--r--config.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/config.c b/config.c
index bed45ce..9ad26ad 100644
--- a/config.c
+++ b/config.c
@@ -56,6 +56,9 @@ struct cg_group *current_group;
const char *cg_controller_names[] = {
"cpu",
+ "cpuacct",
+ "memory",
+ "cpuset",
NULL,
};
@@ -138,13 +141,16 @@ struct mount_table *cg_find_mount_info(const char *controller_name)
char *str;
while (curr) {
+ dbg("options %s mntpt %s next %p\n", curr->options,
+ curr->mount_point, curr->next);
+ dbg("passed controller name %s\n", controller_name);
str = curr->options;
if (!str)
return NULL;
str = strtok(curr->options, ",");
do {
- if (!strncmp(str, controller_name, strlen(str)))
+ if (!strcmp(str, controller_name))
return curr;
str = strtok(NULL, ",");
} while(str);
@@ -163,9 +169,8 @@ int cg_cpu_controller_settings(struct cg_group *cg_group,
if (!shares_file)
return 0;
- strncpy(shares_file, group_path, strlen(group_path));
- shares_file = strncat(shares_file, "/cpu.shares",
- strlen("/cpu.shares"));
+ strcpy(shares_file, group_path);
+ shares_file = strcat(shares_file, "/cpu.shares");
dbg("shares file is %s\n", shares_file);
if (cg_group->cpu_config.shares) {
FILE *fd = fopen(shares_file, "rw+");
@@ -199,9 +204,10 @@ int cg_create_group(struct cg_group *cg_group)
{
int i, ret;
struct mount_table *mount_info;
- char *group_path, *tasks_file, *shares_file;
+ char *group_path[2], *tasks_file, *shares_file;
dbg("found group %s\n", cg_group->name);
+ group_path[1] = NULL;
for (i = 0; cg_controller_names[i]; i++) {
@@ -209,11 +215,11 @@ int cg_create_group(struct cg_group *cg_group)
* Find the mount point related information
*/
mount_info = cg_find_mount_info(cg_controller_names[i]);
- dbg("mount_info for controller %s:%s\n",
- mount_info->mount_point, cg_controller_names[i]);
if (!mount_info)
- return 0;
+ continue;
+ dbg("mount_info for controller %s:%s\n",
+ mount_info->mount_point, cg_controller_names[i]);
/*
* TODO: Namespace support is most likely going to be
* plugged in here
@@ -222,10 +228,9 @@ int cg_create_group(struct cg_group *cg_group)
/*
* Find the path to the group directory
*/
- group_path = cg_build_group_path(cg_group, mount_info);
- if (!group_path)
+ group_path[0] = cg_build_group_path(cg_group, mount_info);
+ if (!group_path[0])
goto cleanup_group;
-
/*
* Create the specified directory. Errors are ignored.
* If the directory already exists, we are most likely
@@ -239,10 +244,10 @@ int cg_create_group(struct cg_group *cg_group)
* Find the tasks file, should probably be encapsulated
* like we encapsulate cg_build_group_path
*/
- tasks_file = malloc(strlen(group_path) + strlen("/tasks") + 1);
+ tasks_file = malloc(strlen(group_path[0]) + strlen("/tasks") + 1);
if (!tasks_file)
goto cleanup_dir;
- strncpy(tasks_file, group_path, strlen(group_path));
+ strcpy(tasks_file, group_path[0]);
tasks_file = strncat(tasks_file, "/tasks", strlen("/tasks"));
dbg("tasks file is %s\n", tasks_file);
@@ -258,15 +263,15 @@ int cg_create_group(struct cg_group *cg_group)
* Controller specific work, errors are not fatal.
*/
cg_controller_handle_option(cg_group, cg_controller_names[i],
- group_path);
+ group_path[0]);
free(tasks_file);
- free(group_path);
+ free(group_path[0]);
}
return 1;
cleanup_perm:
- rmdir(group_path);
+ rmdir(group_path[0]);
cleanup_dir:
- free(group_path);
+ free(group_path[0]);
cleanup_group:
return 0;
}
@@ -650,9 +655,11 @@ int cg_load_config(const char *pathname)
fclose(yyin);
return 1;
err_grp:
+ dbg("Creating groups failed\n");
cg_destroy_groups();
cg_cleanup_group_list();
err_mnt:
+ dbg("Mounting controllers failed\n");
cg_unmount_controllers();
cg_cleanup_mount_table();
fclose(yyin);
@@ -700,5 +707,4 @@ int main(int argc, char *argv[])
}
}
- cg_destroy_group_and_mount_info();
}