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

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