From: <bal...@us...> - 2008-09-29 04:40:43
|
Revision: 196 http://libcg.svn.sourceforge.net/libcg/?rev=196&view=rev Author: balbir_singh Date: 2008-09-29 04:40:38 +0000 (Mon, 29 Sep 2008) Log Message: ----------- Fix several bugs, including a chown BUG in api.c. Fix passing of ownership in config.c. Remove file-ops.c and update parse.y to allow passing of NULL name value conf's for controllers, so that groups can be created without setting any configuration values Signed-off-by: Balbir Singh <ba...@li...> Modified Paths: -------------- branches/balbir-config-cleanup/api.c branches/balbir-config-cleanup/config.c branches/balbir-config-cleanup/libcgroup.h branches/balbir-config-cleanup/parse.y branches/balbir-config-cleanup/samples/wlm.conf.3 Removed Paths: ------------- branches/balbir-config-cleanup/file-ops.c Modified: branches/balbir-config-cleanup/api.c =================================================================== --- branches/balbir-config-cleanup/api.c 2008-09-28 17:42:19 UTC (rev 195) +++ branches/balbir-config-cleanup/api.c 2008-09-29 04:40:38 UTC (rev 196) @@ -830,6 +830,7 @@ if (ret) { switch (errno) { case EEXIST: + ret = 0; /* Not fatal really */ break; case EPERM: ret = ECGROUPNOTOWNER; @@ -1120,7 +1121,7 @@ strcat(path, "/tasks"); error = chown(path, cgroup->tasks_uid, cgroup->tasks_gid); - if (!error) { + if (error) { error = ECGFAIL; goto err; } Modified: branches/balbir-config-cleanup/config.c =================================================================== --- branches/balbir-config-cleanup/config.c 2008-09-28 17:42:19 UTC (rev 195) +++ branches/balbir-config-cleanup/config.c 2008-09-29 04:40:38 UTC (rev 196) @@ -113,6 +113,13 @@ if (!cgc) goto parse_error; + /* + * Did we just specify the controller to create the correct + * set of directories, without setting any values? + */ + if (!name_value) + goto done; + name = strtok_r(name_value, " ", &buffer); if (!name) @@ -129,6 +136,7 @@ if (error) goto parse_error; +done: free(controller); free(name_value); return 1; @@ -136,7 +144,8 @@ parse_error: free(controller); free(name_value); - cgroup_free(&config_cgroup); + cgroup_delete_cgroup(config_cgroup, 1); + cgroup_table_index--; return 0; } @@ -162,7 +171,7 @@ error = getpwnam_r(value, pw, buffer, CGROUP_BUFFER_LEN, &pw_buffer); - if (error) { + if (pw_buffer == NULL) { free(pw); goto group_task_error; } @@ -183,7 +192,7 @@ error = getgrnam_r(value, group, buffer, CGROUP_BUFFER_LEN, &group_buffer); - if (error) { + if (group_buffer == NULL) { free(group); goto group_task_error; } @@ -199,7 +208,8 @@ group_task_error: free(perm_type); free(value); - cgroup_free(&config_cgroup); + cgroup_delete_cgroup(config_cgroup, 1); + cgroup_table_index--; return 0; } @@ -262,7 +272,8 @@ admin_error: free(perm_type); free(value); - cgroup_free(&config_cgroup); + cgroup_delete_cgroup(config_cgroup, 1); + cgroup_table_index--; return 0; } @@ -290,7 +301,7 @@ void cgconfig_cleanup_mount_table(void) { memset(&config_mount_table, 0, - sizeof(config_mount_table) * CG_CONTROLLER_MAX); + sizeof(struct cg_mount_table_s) * CG_CONTROLLER_MAX); } /* @@ -324,7 +335,7 @@ 0, curr->name); if (ret < 0) - return ECGOTHER; + return ECGMOUNTFAIL; } return 0; } @@ -340,6 +351,7 @@ for (i = 0; i < cgroup_table_index; i++) { struct cgroup *cgroup = &cgconfig_cgroup_table[i]; error = cgroup_create_cgroup(cgroup, 0); + printf("creating group %s, error %d\n", cgroup->name, error); if (error) return error; } @@ -407,16 +419,15 @@ } error = cgconfig_mount_fs(); - if (error) goto err_mnt; error = cgroup_init(); - if (error) goto err_mnt; error = cgconfig_create_groups(); + printf("creating all cgroups now, error=%d\n", error); if (error) goto err_grp; Deleted: branches/balbir-config-cleanup/file-ops.c =================================================================== --- branches/balbir-config-cleanup/file-ops.c 2008-09-28 17:42:19 UTC (rev 195) +++ branches/balbir-config-cleanup/file-ops.c 2008-09-29 04:40:38 UTC (rev 196) @@ -1,176 +0,0 @@ -/* - * Copyright IBM Corporation. 2007 - * - * Authors: Balbir Singh <ba...@li...> - * Dhaval Giani <dh...@li...> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2.1 of the GNU Lesser General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -#include <dirent.h> -#include <errno.h> -#include <fts.h> -#include <grp.h> -#include <libcgroup.h> -#include <limits.h> -#include <pwd.h> -#include <search.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/types.h> - -extern const char cg_filesystem[]; -extern struct mount_table *mount_table; - -int cg_chown_file(FTS *fts, FTSENT *ent, uid_t owner, gid_t group) -{ - int ret = 1; - const char *filename = fts->fts_path; - dbg("seeing file %s\n", filename); - switch (ent->fts_info) { - case FTS_ERR: - errno = ent->fts_errno; - break; - case FTS_D: - case FTS_DC: - case FTS_NSOK: - case FTS_NS: - case FTS_DNR: - case FTS_DP: - case FTS_F: - case FTS_DEFAULT: - ret = chown(filename, owner, group); - break; - } - return ret; -} - -/* - * TODO: Need to decide a better place to put this function. - */ -int cg_chown_recursive(char *path[], uid_t owner, gid_t group) -{ - int ret = 1; - FTS *fts = fts_open((char **)path, FTS_PHYSICAL | FTS_NOCHDIR | - FTS_NOSTAT, NULL); - while (1) { - FTSENT *ent; - ent = fts_read(fts); - if (!ent) { - dbg("fts_read failed\n"); - break; - } - cg_chown_file(fts, ent, owner, group); - } - fts_close(fts); - return ret; -} - -char *cg_build_group_path(struct cg_group *cg_group, - struct mount_table *mount_info) -{ - char *group_path; - - group_path = malloc(strlen(mount_info->mount_point) + - strlen(cg_group->name) + 2); - if (!group_path) - return NULL; - strncpy(group_path, mount_info->mount_point, - strlen(mount_info->mount_point) + 1); - dbg("group path is %s\n", group_path); - strncat(group_path, "/", strlen("/")); - strncat(group_path, cg_group->name, strlen(cg_group->name)); - dbg("group path is %s\n", group_path); - return group_path; -} - -int cg_make_directory(struct cg_group *cg_group, char *group_path[]) -{ - int ret; - ret = mkdir(group_path[0], S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (ret < 0) - return 0; - /* - * Recursively change all files under the directory - */ - ret = cg_chown_recursive(group_path, cg_group->admin_uid, - cg_group->admin_gid); - return ret; -} - -/* - * After having parsed the configuration file, walk through the mount_table - * and mount the specified controllers. This routine might create directories - * specified as mount_point. - */ -int cg_mount_controllers(void) -{ - int ret; - struct mount_table *curr = mount_table; - struct stat buf; - - while (curr) { - ret = stat(curr->mount_point, &buf); - if (ret < 0 && errno != ENOENT) - return 0; - - /* - * Check if path needs to be created before mounting - */ - if (errno == ENOENT) { - ret = mkdir(curr->mount_point, S_IRWXU | S_IRWXG | - S_IRWXO | S_ISVTX); - if (ret < 0) - return 0; - } else if (!S_ISDIR(buf.st_mode)) { - errno = ENOTDIR; - return 0; - } - - ret = mount(cg_filesystem, curr->mount_point, - cg_filesystem, 0, curr->options); - - if (ret < 0) - return 0; - curr = curr->next; - } - return 1; -} - -/* - * Called during end of WLM configuration to unmount all controllers or - * on failure, to cleanup mounted controllers - */ -int cg_unmount_controllers(void) -{ - struct mount_table *curr = mount_table; - int ret; - - while (curr) { - /* - * We ignore failures and ensure that all mounted - * containers are unmounted - */ - ret = umount(curr->mount_point); - if (ret < 0) - printf("Unmount failed\n"); - ret = rmdir(curr->mount_point); - if (ret < 0) - printf("rmdir failed\n"); - curr = curr->next; - } - return 1; -} - Modified: branches/balbir-config-cleanup/libcgroup.h =================================================================== --- branches/balbir-config-cleanup/libcgroup.h 2008-09-28 17:42:19 UTC (rev 195) +++ branches/balbir-config-cleanup/libcgroup.h 2008-09-29 04:40:38 UTC (rev 196) @@ -93,6 +93,7 @@ ECGCONTROLLERNOTEQUAL, ECGROUPPARSEFAIL, /* Failed to parse rules configuration file. */ ECGROUPNORULES, /* Rules list does not exist. */ + ECGMOUNTFAIL, }; #define CG_NV_MAX 100 Modified: branches/balbir-config-cleanup/parse.y =================================================================== --- branches/balbir-config-cleanup/parse.y 2008-09-28 17:42:19 UTC (rev 195) +++ branches/balbir-config-cleanup/parse.y 2008-09-29 04:40:38 UTC (rev 196) @@ -126,6 +126,10 @@ $$ = strncat($2, $4, strlen($4)); free($4); } + | + { + $$ = NULL; + } ; task_namevalue_conf Modified: branches/balbir-config-cleanup/samples/wlm.conf.3 =================================================================== --- branches/balbir-config-cleanup/samples/wlm.conf.3 2008-09-28 17:42:19 UTC (rev 195) +++ branches/balbir-config-cleanup/samples/wlm.conf.3 2008-09-29 04:40:38 UTC (rev 196) @@ -32,6 +32,7 @@ memory { memory.limit_in_bytes = 200M; } + } group default { @@ -53,6 +54,9 @@ memory { memory.limit_in_bytes = 200M; } + + cpuacct { + } } mount { @@ -61,5 +65,5 @@ } mount { - cpu_acct = /acct; + cpuacct = /acct; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |