Blame SOURCES/libcgroup-0.41-use-character-as-a-meta-character-for-all-mounted-co.patch

308897
From 2102de58417416a3051fee17e012964b56971fb3 Mon Sep 17 00:00:00 2001
308897
From: Jan Chaloupka <jchaloup@redhat.com>
308897
Date: Sat, 20 Sep 2014 19:13:01 +0200
308897
Subject: [PATCH] use * character as a meta character for all mounted
308897
 controllers
308897
308897
---
308897
 doc/man/cgcreate.1         |  3 ++-
308897
 include/libcgroup/groups.h | 10 ++++++++++
308897
 src/libcgroup.map          |  7 +++++++
308897
 src/tools/cgcreate.c       | 32 +++++++++++++++++++----------
308897
 src/wrapper.c              | 50 ++++++++++++++++++++++++++++++++++++++++++++++
308897
 5 files changed, 91 insertions(+), 11 deletions(-)
308897
308897
diff --git a/doc/man/cgcreate.1 b/doc/man/cgcreate.1
308897
index 7068073..557b5ae 100644
308897
--- a/doc/man/cgcreate.1
308897
+++ b/doc/man/cgcreate.1
308897
@@ -38,7 +38,8 @@ others permissions to the owners permissions).
308897
 .TP
308897
 .B -g <controllers>:<path>
308897
 defines control groups to be added.
308897
-\fBcontrollers\fR is a list of controllers and
308897
+\fBcontrollers\fR is a list of controllers. Character "*" can be used
308897
+as a shortcut for "all mounted controllers".
308897
 \fBpath\fR is the relative path to control groups
308897
 in the given controllers list. This option can be specified
308897
 multiple times.
308897
diff --git a/include/libcgroup/groups.h b/include/libcgroup/groups.h
308897
index d5c87aa..201558f 100644
308897
--- a/include/libcgroup/groups.h
308897
+++ b/include/libcgroup/groups.h
308897
@@ -150,6 +150,16 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup,
308897
 						const char *name);
308897
 
308897
 /**
308897
+ * Attach all mounted controllers to given cgroup. This function just modifies
308897
+ * internal libcgroup structure, not the kernel control group.
308897
+ *
308897
+ * @param cgroup
308897
+ * @return zero or error number
308897
+ */
308897
+int cgroup_add_all_controllers(struct cgroup *cgroup);
308897
+
308897
+
308897
+/**
308897
  * Return appropriate controller from given group.
308897
  * The controller must be added before using cgroup_add_controller() or loaded
308897
  * from kernel using cgroup_get_cgroup().
308897
diff --git a/src/libcgroup.map b/src/libcgroup.map
308897
index f8b0fb9..8fe1990 100644
308897
--- a/src/libcgroup.map
308897
+++ b/src/libcgroup.map
308897
@@ -122,3 +122,10 @@ CGROUP_0.40 {
308897
 	cgroup_templates_cache_set_source_files;
308897
 	cgroup_load_templates_cache_from_files;
308897
 } CGROUP_0.39;
308897
+
308897
+CGROUP_0.41 {
308897
+} CGROUP_0.40;
308897
+
308897
+CGROUP_0.42 {
308897
+	cgroup_add_all_controllers;
308897
+} CGROUP_0.41;
308897
diff --git a/src/tools/cgcreate.c b/src/tools/cgcreate.c
308897
index 73abd91..65b188a 100644
308897
--- a/src/tools/cgcreate.c
308897
+++ b/src/tools/cgcreate.c
308897
@@ -54,7 +54,6 @@ static void usage(int status, const char *program_name)
308897
 	printf("  -t <tuid>:<tgid>		Owner of the tasks file\n");
308897
 }
308897
 
308897
-
308897
 int main(int argc, char *argv[])
308897
 {
308897
 	int ret = 0;
308897
@@ -195,16 +194,29 @@ int main(int argc, char *argv[])
308897
 		/* add controllers to the new cgroup */
308897
 		j = 0;
308897
 		while (cgroup_list[i]->controllers[j]) {
308897
-			cgc = cgroup_add_controller(cgroup,
308897
-				cgroup_list[i]->controllers[j]);
308897
-			if (!cgc) {
308897
-				ret = ECGINVAL;
308897
-				fprintf(stderr, "%s: "
308897
-					"controller %s can't be add\n",
308897
-					argv[0],
308897
+			if (strcmp(cgroup_list[i]->controllers[j], "*") == 0) {
308897
+				/* it is meta character, add all controllers */
308897
+				ret = cgroup_add_all_controllers(cgroup);
308897
+				if (ret != 0) {
308897
+					ret = ECGINVAL;
308897
+					fprintf(stderr, "%s: can't add ",
308897
+						argv[0]);
308897
+					fprintf(stderr, "all controllers\n");
308897
+					cgroup_free(&cgroup);
308897
+					goto err;
308897
+				}
308897
+			} else {
308897
+				cgc = cgroup_add_controller(cgroup,
308897
 					cgroup_list[i]->controllers[j]);
308897
-				cgroup_free(&cgroup);
308897
-				goto err;
308897
+				if (!cgc) {
308897
+					ret = ECGINVAL;
308897
+					fprintf(stderr, "%s: ", argv[0]);
308897
+					fprintf(stderr, "controller %s",
308897
+						cgroup_list[i]->controllers[j]);
308897
+					fprintf(stderr, "can't be add\n");
308897
+					cgroup_free(&cgroup);
308897
+					goto err;
308897
+				}
308897
 			}
308897
 			j++;
308897
 		}
308897
diff --git a/src/wrapper.c b/src/wrapper.c
308897
index c03472a..3a9331f 100644
308897
--- a/src/wrapper.c
308897
+++ b/src/wrapper.c
308897
@@ -92,6 +92,56 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup,
308897
 	return controller;
308897
 }
308897
 
308897
+int cgroup_add_all_controllers(struct cgroup *cgroup)
308897
+{
308897
+	int ret;
308897
+	void *handle;
308897
+	struct controller_data info;
308897
+	struct cgroup_controller *cgc;
308897
+
308897
+	/* go through the controller list */
308897
+	ret = cgroup_get_all_controller_begin(&handle, &info;;
308897
+	if ((ret != 0) && (ret != ECGEOF)) {
308897
+		fprintf(stderr, "cannot read controller data: %s\n",
308897
+			cgroup_strerror(ret));
308897
+		return ret;
308897
+	}
308897
+
308897
+	while (ret == 0) {
308897
+		if (info.hierarchy == 0) {
308897
+			/* the controller is not attached to any hierarchy
308897
+			   skip it */
308897
+			goto next;
308897
+		}
308897
+
308897
+		/* add mounted controller to cgroup structure */
308897
+		cgc = cgroup_add_controller(cgroup, info.name);
308897
+		if (!cgc) {
308897
+			ret = ECGINVAL;
308897
+			fprintf(stderr, "controller %s can't be add\n",
308897
+				info.name);
308897
+		}
308897
+
308897
+next:
308897
+		ret = cgroup_get_all_controller_next(&handle, &info;;
308897
+		if (ret && ret != ECGEOF)
308897
+			goto end;
308897
+	}
308897
+
308897
+end:
308897
+	cgroup_get_all_controller_end(&handle);
308897
+
308897
+	if (ret == ECGEOF)
308897
+		ret = 0;
308897
+
308897
+	if (ret)
308897
+		fprintf(stderr,
308897
+			"cgroup_get_controller_begin/next failed (%s)\n",
308897
+			cgroup_strerror(ret));
308897
+
308897
+	return ret;
308897
+}
308897
+
308897
 void cgroup_free_controllers(struct cgroup *cgroup)
308897
 {
308897
 	int i, j;
308897
-- 
308897
1.9.3
308897