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
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
$(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)
$(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
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@
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
$(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
const char *cg_controller_names[] = {
"cpu",
+ "cpuacct",
+ "memory",
+ "cpuset",
NULL,
};
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);
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+");
{
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++) {
* 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
/*
* 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
* 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);
* 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;
}
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);
}
}
- cg_destroy_group_and_mount_info();
}
/*
* 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;
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;
/*
* 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)) {
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);
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>
# 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
--------------------
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
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.