]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Configuration and parsing updates (v2)
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Wed, 13 Aug 2008 19:35:01 +0000 (19:35 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Wed, 13 Aug 2008 19:35:01 +0000 (19:35 +0000)
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

Makefile
Makefile.in
config.c
file-ops.c
libcgroup.h
scripts/doc/howto.txt

index 4c70322b52a42e58c44081cde9fdb7beddec6a80..8371d35dc7b933123d32064fdcca541aa425679b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,13 +14,14 @@ YACC_DEBUG=-t
 DEBUG=-DDEBUG
 INC=-I.
 LIBS= -lcgroup -lpthread
-LDFLAGS=
+LDFLAGS= -L .
 YACC=byacc
 LEX=flex
 bindir=${exec_prefix}/bin
+sbindir=${exec_prefix}/sbin
 libdir=${exec_prefix}/lib
 includedir=${prefix}/include
-prefix=/usr/local
+prefix=/usr
 exec_prefix=${prefix}
 INSTALL=install
 INSTALL_DATA=install -m 644
@@ -28,10 +29,11 @@ PACKAGE_VERSION=0.2
 CFLAGS=-g -O2 $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION)
 VERSION=1
 
-all: libcgroup.so
+all: libcgroup.so cgconfigparser
 
-cgconfig: libcgroup.so config.c y.tab.c lex.yy.c libcgroup.h file-ops.c
-       $(CC) $(CFLAGS) -o $@ y.tab.c lex.yy.c config.c file-ops.c $(LDFLAGS) $(LIBS)
+cgconfigparser: libcgroup.so config.c y.tab.c lex.yy.c libcgroup.h file-ops.c
+       $(CC) $(CFLAGS) -o $@ y.tab.c lex.yy.c config.c file-ops.c \
+       $(LDFLAGS) $(LIBS)
 
 y.tab.c: parse.y lex.yy.c
        $(YACC) -v -d parse.y
@@ -40,7 +42,7 @@ lex.yy.c: lex.l
        $(LEX) lex.l
 
 libcgroup.so: api.c libcgroup.h wrapper.c
-       $(CC) $(CFLAGS) -shared -fPIC -Wl,--soname,$@.$(VERSION) -o $@ api.c \
+       $(CXX) $(CFLAGS) -shared -fPIC -Wl,--soname,$@.$(VERSION) -o $@ api.c \
        wrapper.c
        ln -sf $@ $@.$(VERSION)
 
@@ -52,14 +54,16 @@ install: libcgroup.so
        $(INSTALL) -D libcgroup.so $(DESTDIR)$(libdir)/libcgroup-$(PACKAGE_VERSION).so
        ln -sf libcgroup-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libcgroup.so.$(VERSION)
        ln -sf libcgroup.so.$(VERSION) $(DESTDIR)$(libdir)/libcgroup.so
+       $(INSTALL) -D cgconfigparser $(DESTDIR)$(sbindir)
 
 uninstall: libcgroup.so
        rm -f $(DESTDIR)$(includedir)/libcgroup.h
        rm -f $(DESTDIR)$(libdir)/libcgroup.so
        rm -f $(DESTDIR)$(libdir)/libcgroup.so.$(VERSION)
        rm -f $(DESTDIR)$(libdir)/libcgroup-$(PACKAGE_VERSION).so
+       rm -f $(DESTDIR)$(sbindir)/cgconfigparser
 
 clean:
        \rm -f y.tab.c y.tab.h lex.yy.c y.output cgconfig libcgroup.so \
-       libcgroup.so.$(VERSION)
+       libcgroup.so.$(VERSION) cgconfigparser config.log config.status
        $(MAKE) -C tests clean
index f0269baa2c8b2d018afd27546920609c0c27f190..aeab421dc2e660395edf1ef3302ad845390f9dca 100644 (file)
@@ -14,10 +14,11 @@ YACC_DEBUG=-t
 DEBUG=-DDEBUG
 INC=-I.
 LIBS= -lcgroup -lpthread
-LDFLAGS=@LDFLAGS@
+LDFLAGS=@LDFLAGS@ -L .
 YACC=@YACC@
 LEX=@LEX@
 bindir=@bindir@
+sbindir=@sbindir@
 libdir=@libdir@
 includedir=@includedir@
 prefix=@prefix@
@@ -28,10 +29,11 @@ PACKAGE_VERSION=@PACKAGE_VERSION@
 CFLAGS=@CFLAGS@ $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION)
 VERSION=1
 
-all: libcgroup.so
+all: libcgroup.so cgconfigparser
 
-cgconfig: libcgroup.so config.c y.tab.c lex.yy.c libcgroup.h file-ops.c
-       $(CC) $(CFLAGS) -o $@ y.tab.c lex.yy.c config.c file-ops.c $(LDFLAGS) $(LIBS)
+cgconfigparser: libcgroup.so config.c y.tab.c lex.yy.c libcgroup.h file-ops.c
+       $(CC) $(CFLAGS) -o $@ y.tab.c lex.yy.c config.c file-ops.c \
+       $(LDFLAGS) $(LIBS)
 
 y.tab.c: parse.y lex.yy.c
        $(YACC) -v -d parse.y
@@ -40,26 +42,24 @@ lex.yy.c: lex.l
        $(LEX) lex.l
 
 libcgroup.so: api.c libcgroup.h wrapper.c
-       $(CC) $(CFLAGS) -shared -fPIC -Wl,--soname,$@.$(VERSION) -o $@ api.c \
+       $(CXX) $(CFLAGS) -shared -fPIC -Wl,--soname,$@.$(VERSION) -o $@ api.c \
        wrapper.c
        ln -sf $@ $@.$(VERSION)
 
-test:
-       $(MAKE) -C tests
-
 install: libcgroup.so
        $(INSTALL_DATA) -D libcgroup.h $(DESTDIR)$(includedir)/libcgroup.h
        $(INSTALL) -D libcgroup.so $(DESTDIR)$(libdir)/libcgroup-$(PACKAGE_VERSION).so
        ln -sf libcgroup-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libcgroup.so.$(VERSION)
        ln -sf libcgroup.so.$(VERSION) $(DESTDIR)$(libdir)/libcgroup.so
+       $(INSTALL) -D cgconfigparser $(DESTDIR)$(sbindir)
 
 uninstall: libcgroup.so
        rm -f $(DESTDIR)$(includedir)/libcgroup.h
        rm -f $(DESTDIR)$(libdir)/libcgroup.so
        rm -f $(DESTDIR)$(libdir)/libcgroup.so.$(VERSION)
        rm -f $(DESTDIR)$(libdir)/libcgroup-$(PACKAGE_VERSION).so
+       rm -f $(DESTDIR)$(sbindir)/cgconfigparser
 
 clean:
-       \rm -f y.tab.c y.tab.h lex.yy.c y.output cgconfig libcgroup.so \
-       libcgroup.so.$(VERSION)
-       $(MAKE) -C tests clean
+       \rm -f y.tab.c y.tab.h lex.yy.c y.output libcgroup.so \
+       libcgroup.so.$(VERSION) cgconfigparser config.log config.status
index bed45ce788bfa2bb85264424dff485e819534a07..9ad26ad015df26603840034bbed96aaec05bb4f9 100644 (file)
--- 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();
 }
index da3dee7602f2e8529409c0c077fe9220990935e1..ffba8e80bc95e1c1cdad66810720b12d1136948b 100644 (file)
@@ -60,10 +60,10 @@ int cg_chown_file(FTS *fts, FTSENT *ent, uid_t owner, gid_t group)
 /*
  * TODO: Need to decide a better place to put this function.
  */
-int cg_chown_recursive(const char *path, uid_t owner, gid_t group)
+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 *fts = fts_open((char **)path, FTS_PHYSICAL | FTS_NOCHDIR |
                                FTS_NOSTAT, NULL);
        while (1) {
                FTSENT *ent;
@@ -96,10 +96,10 @@ char *cg_build_group_path(struct cg_group *cg_group,
        return group_path;
 }
 
-int cg_make_directory(struct cg_group *cg_group, const char *group_path)
+int cg_make_directory(struct cg_group *cg_group, char *group_path[])
 {
        int ret;
-       ret = mkdir(group_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+       ret = mkdir(group_path[0], S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
        if (ret < 0)
                return 0;
        /*
@@ -130,8 +130,8 @@ int cg_mount_controllers(void)
                 * Check if path needs to be created before mounting
                 */
                if (errno == ENOENT) {
-                       ret = mkdir(curr->mount_point, S_IRWXU |
-                                               S_IRWXG | S_IROTH | S_IXOTH);
+                       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)) {
index 5252c7f920fb15199bd4c510f7aed801d871e86b..fe1375871ac7ed1817eb0c003b2b4636304f0419 100644 (file)
@@ -145,7 +145,7 @@ int cg_group_task_perm(char *perm_type, char *value);
 int cg_parse_controller_options(char *controller, char *name_value);
 int cg_insert_group(const char *group_name);
 int chown_recursive(const char* path, uid_t owner, gid_t group);
-int cg_make_directory(struct cg_group *cg_group, const char *group_path);
+int cg_make_directory(struct cg_group *cg_group, char *group_path[]);
 char *cg_build_group_path(struct cg_group *cg_group,
                                        struct mount_table *mount_info);
 int cg_mount_controllers(void);
index c6796d683e6424775e8bbdc38e184b47c0d096e9..d72994a4ea664f7c02e4b2eb21b0949d162ae084 100644 (file)
@@ -4,7 +4,7 @@ management system. The script consists of two major components
 Configuration files
 -------------------
 
-The main configuraiton file /etc/wlm.conf. This file has a format
+The main configuraiton file /etc/cgconfig.conf. This file has a format
 
 mount <mountpoint>     <list of controllers>
 <controller>           <controller configuration file>
@@ -15,11 +15,11 @@ A sample configuration file is included below
 # controller    file
 #
 mount   /container      cpu
-cpu     /etc/wlm/cpu.conf
+cpu     /etc/cgconfig/cpu.conf
 
 NOTE: Any line beginning with '#' is ignored as comments. The sample
 configuration above, mounts the cpu controller at mount point /container.
-It then parses /etc/wlm/cpu.conf as the configuration file for the
+It then parses /etc/cgconfig/cpu.conf as the configuration file for the
 cpu controller.
 
 The controller configuration file is of the format
@@ -53,7 +53,7 @@ Intialization script
 --------------------
 
 The initialization script is installed in /etc/init.d, it is called
-"wlm". Depending on the run-level, it is installed in the appropriate
+"cgconfig". Depending on the run-level, it is installed in the appropriate
 /etc/rc.d/rc<N>.d. The script comes with two options
 
 a. start
@@ -73,4 +73,4 @@ Assumptions
 
 1. The kernel is compiled in with the correct options to support
     cgroups and the CPU controller.
-2. This version has been tested with 2.6.24-rc1 only.
+2. This version has been tested with 2.6.25 only.