diff options
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | Makefile.in | 9 | ||||
-rw-r--r-- | api.c | 57 | ||||
-rw-r--r-- | cgconfig.c | 5 | ||||
-rw-r--r-- | config.c | 4 | ||||
-rw-r--r-- | libcgroup.spec.in | 36 | ||||
-rw-r--r-- | samples/wlm.conf.3 | 6 | ||||
-rw-r--r-- | scripts/init.d/cgconfig | 36 | ||||
-rw-r--r-- | scripts/init.d/cgred | 2 |
9 files changed, 121 insertions, 47 deletions
@@ -21,7 +21,7 @@ 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 @@ -29,7 +29,9 @@ PACKAGE_VERSION=0.32 CFLAGS=-g -O2 $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION) VERSION=1 -all: libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd +TARGETS = libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd + +all: $(TARGETS) cgconfigparser: libcgroup.so cgconfig.c libcgroup.h $(CC) $(CFLAGS) $(INC) -Wall -o $@ cgconfig.c $(LDFLAGS) $(LIBS) @@ -63,12 +65,12 @@ pam_cgroup.so: pam_cgroup.c $(CC) $(CFLAGS) -shared -fPIC -Wall -o $@ pam_cgroup.c $(LDFLAGS) \ $(LIBS) -lpam -install: libcgroup.so cgexec cgclassify cgconfigparser +install: $(TARGETS) $(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) + $(INSTALL) -D cgconfigparser $(DESTDIR)$(sbindir)/cgconfigparser $(INSTALL) -D cgexec $(DESTDIR)$(bindir)/cgexec $(INSTALL) -D cgclassify $(DESTDIR)$(bindir)/cgclassify $(INSTALL) -D cgrulesengd $(DESTDIR)$(bindir)/cgrulesengd @@ -85,5 +87,4 @@ uninstall: libcgroup.so clean: \rm -f y.tab.c y.tab.h lex.yy.c y.output libcgroup.so cgclassify \ - libcgroup.so.$(VERSION) cgconfigparser config.log config.status cgexec \ - pam_cgroup.so cgrulesengd + libcgroup.so.$(VERSION) $(TARGETS) diff --git a/Makefile.in b/Makefile.in index f98552a..feb750e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,7 +29,9 @@ PACKAGE_VERSION=@PACKAGE_VERSION@ CFLAGS=@CFLAGS@ $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION) VERSION=1 -all: libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd +TARGETS = libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd + +all: $(TARGETS) cgconfigparser: libcgroup.so cgconfig.c libcgroup.h $(CC) $(CFLAGS) $(INC) -Wall -o $@ cgconfig.c $(LDFLAGS) $(LIBS) @@ -63,7 +65,7 @@ pam_cgroup.so: pam_cgroup.c $(CC) $(CFLAGS) -shared -fPIC -Wall -o $@ pam_cgroup.c $(LDFLAGS) \ $(LIBS) -lpam -install: libcgroup.so cgexec cgclassify cgconfigparser +install: $(TARGETS) $(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) @@ -85,5 +87,4 @@ uninstall: libcgroup.so clean: \rm -f y.tab.c y.tab.h lex.yy.c y.output libcgroup.so cgclassify \ - libcgroup.so.$(VERSION) cgconfigparser config.log config.status cgexec \ - pam_cgroup.so cgrulesengd + libcgroup.so.$(VERSION) $(TARGETS) @@ -536,7 +536,7 @@ int cgroup_init() &hierarchy, &num_cgroups, &enabled); if (err < 0) break; - controllers[i] = (char *)malloc(strlen(subsys_name)); + controllers[i] = (char *)malloc(strlen(subsys_name) + 1); strcpy(controllers[i], subsys_name); i++; } @@ -584,6 +584,8 @@ int cgroup_init() } } + free(temp_ent); + if (!found_mnt) { cg_mount_table[0].name[0] = '\0'; ret = ECGROUPNOTMOUNTED; @@ -606,6 +608,7 @@ static int cg_test_mounted_fs() FILE *proc_mount; struct mntent *ent, *temp_ent; char mntent_buff[4 * FILENAME_MAX]; + int ret = 1; proc_mount = fopen("/proc/mounts", "r"); if (proc_mount == NULL) { @@ -627,11 +630,15 @@ static int cg_test_mounted_fs() while (strcmp(ent->mnt_type, "cgroup") !=0) { ent = getmntent_r(proc_mount, temp_ent, mntent_buff, sizeof(mntent_buff)); - if (ent == NULL) - return 0; + if (ent == NULL) { + ret = 0; + goto done; + } } +done: fclose(proc_mount); - return 1; + free(temp_ent); + return ret; } static inline pid_t cg_gettid() @@ -1058,6 +1065,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership) char *fts_path[2], base[FILENAME_MAX], *path; int i, j, k; int error = 0; + int retval = 0; if (!cgroup_initialized) return ECGROUPNOTINITIALIZED; @@ -1108,12 +1116,17 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership) cgroup->controller[k]->values[j]->value); /* * Should we undo, what we've done in the loops above? - * An error should not be treated as fatal, since we have - * several read-only files and several files that + * An error should not be treated as fatal, since we + * have several read-only files and several files that * are only conditionally created in the child. + * + * A middle ground would be to track that there + * was an error and return that value. */ - if (error) + if (error) { + retval = error; continue; + } } if (!ignore_ownership) { @@ -1130,6 +1143,8 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership) err: free(path); + if (retval && !error) + error = retval; return error; } @@ -1266,38 +1281,38 @@ int cgroup_delete_cgroup(struct cgroup *cgroup, int ignore_migration) base_tasks = fopen(path, "w"); if (!base_tasks) - goto base_open_err; + goto open_err; if (!cg_build_path(cgroup->name, path, - cgroup->controller[i]->name)) + cgroup->controller[i]->name)) { + fclose(base_tasks); continue; + } strcat(path, "tasks"); delete_tasks = fopen(path, "r"); - if (!delete_tasks) - goto del_open_err; + if (!delete_tasks) { + fclose(base_tasks); + goto open_err; + } while (!feof(delete_tasks)) { ret = fscanf(delete_tasks, "%d", &tids); - /* - * Don't know how to handle EOF yet, so - * ignore it - */ + if (ret == EOF || ret < 1) + break; fprintf(base_tasks, "%d", tids); } + fclose(delete_tasks); + fclose(base_tasks); + if (!cg_build_path(cgroup->name, path, cgroup->controller[i]->name)) continue; error = rmdir(path); - - fclose(delete_tasks); } -del_open_err: - if (base_tasks) - fclose(base_tasks); -base_open_err: +open_err: if (ignore_migration) { for (i = 0; i < cgroup->index; i++) { if (!cg_build_path(cgroup->name, path, @@ -22,6 +22,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> int main(int argc, char *argv[]) { @@ -42,7 +43,9 @@ int main(int argc, char *argv[]) ret = cgroup_config_load_config(filename); if (ret) { printf("Loading configuration file %s " - "failed, ret = %d\n", filename, ret); + "failed, error: %s\n", filename, + strerror(errno)); + printf("return code = %d\n", ret); exit(3); } break; @@ -203,6 +203,8 @@ int cgroup_config_group_task_perm(char *perm_type, char *value) config_cgroup->tasks_gid = val; } + free(perm_type); + free(value); return 1; group_task_error: @@ -267,6 +269,8 @@ int cgroup_config_group_admin_perm(char *perm_type, char *value) config_cgroup->control_gid = val; } + free(perm_type); + free(value); return 1; admin_error: diff --git a/libcgroup.spec.in b/libcgroup.spec.in index 93ad868..177c7c0 100644 --- a/libcgroup.spec.in +++ b/libcgroup.spec.in @@ -10,6 +10,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: byacc BuildRequires: flex BuildRequires: coreutils +Requires(post): chkconfig, /sbin/service %description Control groups infrastructure. The tools and library help manipulate, control, @@ -36,11 +37,27 @@ make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install +mkdir -p $RPM_BUILD_ROOT/%{_initrddir} +cp scripts/init.d/cgconfig $RPM_BUILD_ROOT/%{_initrddir}/cgconfig +cp scripts/init.d/cgred $RPM_BUILD_ROOT/%{_initrddir}/cgred + %clean rm -rf $RPM_BUILD_ROOT -%post -p /sbin/ldconfig +%post +/sbin/ldconfig +# +# Do this later if required +# +#/sbin/chkconfig --add cgred +#/sbin/chkconfig --add cgconfig + +%preun +/sbin/service cgred stop > /dev/null 2>&1 || : +/sbin/service cgconfig stop > /dev/null 2>&1 || : +/sbin/chkconfig --del cgconfig +/sbin/chkconfig --del cgred %postun -p /sbin/ldconfig @@ -48,16 +65,29 @@ rm -rf $RPM_BUILD_ROOT %defattr(-,root,root,-) %{_libdir}/libcgroup-%{version}.so %{_libdir}/libcgroup.so.* -%doc COPYING INSTALL +%{_bindir}/cgexec +%{_bindir}/cgclassify +%{_sbindir}/cgconfigparser +%{_bindir}/cgrulesengd +%attr(0755,root,root) %{_initrddir}/cgconfig +%attr(0755,root,root) %{_initrddir}/cgred + +%doc COPYING INSTALL README_daemon %files devel %defattr(-,root,root,-) %{_includedir}/libcgroup.h %{_libdir}/libcgroup.so -%doc COPYING INSTALL +%doc COPYING INSTALL %changelog +* Fri Oct 10 2008 Dhaval Giani <dhaval@linux.vnet.ibm.com> 0.32-1 +- Update to latest upstream +* Thu Sep 11 2008 Dhaval Giani <dhaval@linux-vnet.ibm.com> 0.31-1 +- Update to latest upstream +* Sat Aug 2 2008 Dhaval Giani <dhaval@linux.vnet.ibm.com> 0.1c-3 +- Change release to fix broken upgrade path * Wed Jun 11 2008 Dhaval Giani <dhaval@linux.vnet.ibm.com> 0.1c-1 - Update to latest upstream version * Tue Jun 3 2008 Balbir Singh <balbir@linux.vnet.ibm.com> 0.1b-3 diff --git a/samples/wlm.conf.3 b/samples/wlm.conf.3 index a0e9a1b..8700854 100644 --- a/samples/wlm.conf.3 +++ b/samples/wlm.conf.3 @@ -17,11 +17,11 @@ group ca1 { perm { task { uid = root; - gid = kvm; + gid = root; } admin { - uid = root; - gid = root; + uid = balbir; + gid = balbir; } } diff --git a/scripts/init.d/cgconfig b/scripts/init.d/cgconfig index 1a8ca42..4e04fb9 100644 --- a/scripts/init.d/cgconfig +++ b/scripts/init.d/cgconfig @@ -1,3 +1,4 @@ +#!/bin/bash # # Start/Stop the workload manager # @@ -12,8 +13,13 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # +# cgconfig Control Groups Configuration Startup +# chkconfig: 2345 80 20 +# description: This script runs the cgconfigparser utility to parse and setup +# the control group filesystem. It uses /etc/cgconfig.conf +# and parses the configuration specified in there. -#### BEGIN INIT INFO +### BEGIN INIT INFO # Provides: cgconfig # Required-Start: $local_fs $syslog $time # Required-Stop: $local_fs $syslog @@ -23,7 +29,7 @@ # Default-Stop: 0 1 6 # Short-Description: start and stop the WLM configuration # Description: This script allows us to create a default configuration -#### END INIT INFO +### END INIT INFO PATH=/bin:/usr/bin:/sbin:/usr/sbin:. MOUNTS_FILE=/proc/mounts @@ -35,6 +41,7 @@ CONFIG_FILE=/etc/cgconfig.conf declare -a MOUNTPOINT declare -a MOUNTOPTS maxindex=0 +servicename=cgconfig # # Source LSB routines @@ -64,7 +71,7 @@ umount_fs() { } start() { - if [ -f /var/lock/cgconfig ] + if [ -f /var/lock/subsys/$servicename ] then log_warning_msg "lock file already exists" return @@ -72,10 +79,10 @@ start() { if [ $? -eq 0 ] then - log_progress_msg "Starting cgconfig service: " + #log_progress_msg "Starting cgconfig service: " cgconfigparser -l $CONFIG_FILE fi - [ $? == 0 ] && touch /var/lock/cgconfig + [ $? == 0 ] && touch /var/lock/subsys/$servicename return $? } @@ -97,7 +104,7 @@ move_all_to_init_class() { ;; *) class=${i#./*} - log_progress_msg "Removing class $class" + #log_progress_msg "Removing class $class" sed -nu p < ./$i/tasks > tasks rmdir $i ;; @@ -111,7 +118,7 @@ move_all_to_init_class() { stop() { move_all_to_init_class umount_fs - rm -f /var/lock/cgconfig + rm -f /var/lock/subsys/$servicename } trapped() { @@ -122,7 +129,7 @@ trapped() { } usage() { - echo "$0 <start|stop>" + echo "$0 <start|stop|restart|condrestart|status>" exit 1 } @@ -157,6 +164,19 @@ case $1 in stop start ;; + 'condrestart') + if [ -f /var/lock/subsys/$servicename ] ; then + stop + start + fi + ;; + 'status') + if [ -f /var/lock/subsys/$servicename ] ; then + echo "Running" + else + echo "Stopped" + fi + ;; *) usage ;; diff --git a/scripts/init.d/cgred b/scripts/init.d/cgred index b99e769..3d9fe2a 100644 --- a/scripts/init.d/cgred +++ b/scripts/init.d/cgred @@ -23,7 +23,7 @@ # ### BEGIN INIT INFO # Provides: cgrulesengd -# Required-Start: $local_fs $syslog $wlm +# Required-Start: $local_fs $syslog $cgconfig # Required-Stop: $local_fs $syslog # Should-Start: # Should-Stop: |