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

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