mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Blum <bblum@andrew.cmu.edu>
To: linux-kernel@vger.kernel.org,
	containers@lists.linux-foundation.org, lizf@cn.fujitsu.com,
	akpm@linux-foundation.org, menage@google.com,
	bblum@andrew.cmu.edu
Subject: [RFC] [PATCH 5/5] cgroups: subsystem dependencies
Date: Fri, 4 Dec 2009 03:58:54 -0500	[thread overview]
Message-ID: <20091204085854.GE18912@andrew.cmu.edu> (raw)
In-Reply-To: <20091204085349.GA18867@andrew.cmu.edu>

[-- Attachment #1: cgroups-subsystem-dependencies.patch --]
[-- Type: text/plain, Size: 3572 bytes --]

Adds support for cgroup subsystems to specify dependencies on other subsystems

From: Ben Blum <bblum@andrew.cmu.edu>

This patch adds a mechanism with which a subsystem can specify dependencies on
other subsystems. Since subsystems can come and go, it would not be useful to
refer to a depended-upon subsystem by subsys_id, so instead a NULL-terminated
array of strings must be specified. Validation is done by scanning for each
potential subsystem its list of subsystem names with strcmp at the end of
parse_cgroupfs_options.

Signed-off-by: Ben Blum <bblum@andrew.cmu.edu>
---

 Documentation/cgroups/cgroups.txt |    4 ++++
 include/linux/cgroup.h            |    8 ++++++++
 kernel/cgroup.c                   |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)


diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt
index 110228e..a8de651 100644
--- a/Documentation/cgroups/cgroups.txt
+++ b/Documentation/cgroups/cgroups.txt
@@ -458,6 +458,10 @@ Other fields in the cgroup_subsys object include:
 - name: should be initialized to a unique subsystem name. Should be
   no longer than MAX_CGROUP_TYPE_NAMELEN.
 
+- depends: allows subsystems to specify dependencies in the form of
+  a list (NULL-terminated) of names of other subsystems. A subsystem
+  cannot be mounted unless all of its dependencies are also mounted.
+
 - early_init: indicate if the subsystem needs early initialization
   at system boot.
 
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 1cbb07f..6f77e30 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -457,6 +457,14 @@ struct cgroup_subsys {
 	bool use_id;
 #define MAX_CGROUP_TYPE_NAMELEN 32
 	const char *name;
+	/*
+	 * A subsystem can specify dependencies in the form of a list of names
+	 * of other subsystems. Such a subsystem can only be mounted on a
+	 * hierarchy if all subsystems named in this list are also to be
+	 * mounted. If this list of strings is initialized, it must be null
+	 * terminated.
+	 */
+	const char **depends;
 
 	/*
 	 * Protects sibling/children links of cgroups in this
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c2c7681..5bbc45a 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1015,6 +1015,38 @@ struct cgroup_sb_opts {
 };
 
 /*
+ * Given a mask of subsystems to be mounted, ensure all dependencies are met.
+ */
+static bool check_subsys_dependencies(unsigned long subsys_bits)
+{
+	unsigned long i, j, k;
+	bool matched;
+
+	for_each_bit(i, &subsys_bits, CGROUP_SUBSYS_COUNT) {
+		BUG_ON(!subsys[i]);
+		if (!subsys[i]->depends)
+			continue;
+		/* For each specified dependency, make sure there's a matching
+		 * subsystem among the ones intended for mounting. */
+		for (j = 0; subsys[i]->depends[j]; j++) {
+			matched = false;
+			for_each_bit(k, &subsys_bits, CGROUP_SUBSYS_COUNT) {
+				BUG_ON(!subsys[k]);
+				BUG_ON(!subsys[k]->name);
+				if (!strcmp(subsys[i]->depends[j],
+					    subsys[k]->name)) {
+					matched = true;
+					break;
+				}
+			}
+			if (!matched)
+				return false;
+		}
+	}
+	return true;
+}
+
+/*
  * Convert a hierarchy specifier into a bitmask of subsystems and flags. Call
  * with subsys_mutex held to guard subsys[] between us and rebind_subsystems.
  */
@@ -1123,6 +1155,10 @@ static int parse_cgroupfs_options(char *data,
 	if (!opts->subsys_bits && !opts->name)
 		return -EINVAL;
 
+	/* Check subsystem dependencies */
+	if (opts->subsys_bits && !check_subsys_dependencies(opts->subsys_bits))
+		return -ESRCH;
+
 	return 0;
 }
 

  parent reply	other threads:[~2009-12-04  9:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-04  8:53 [RFC] [PATCH 0/5] cgroups: support for module-loadable subsystems Ben Blum
2009-12-04  8:55 ` [RFC] [PATCH 1/5] cgroups: revamp subsys array Ben Blum
2009-12-08  7:38   ` Li Zefan
2009-12-09  5:50     ` Ben Blum
2009-12-09  6:07       ` Li Zefan
2009-12-09  6:09         ` Li Zefan
2009-12-09  8:27         ` Ben Blum
2009-12-10  3:18           ` Li Zefan
2009-12-10  5:19             ` Ben Blum
2009-12-10  6:00               ` Li Zefan
2009-12-10  6:13                 ` Ben Blum
2009-12-09  8:36     ` Ben Blum
2009-12-04  8:56 ` [RFC] [PATCH 2/5] cgroups: subsystem module loading interface Ben Blum
2009-12-04  8:57 ` [RFC] [PATCH 3/5] cgroups: net_cls as module Ben Blum
2009-12-08  6:07   ` Li Zefan
2009-12-04  8:58 ` [RFC] [PATCH 4/5] cgroups: subsystem module unloading Ben Blum
2009-12-04  8:58 ` Ben Blum [this message]
2009-12-08  6:11   ` [RFC] [PATCH 5/5] cgroups: subsystem dependencies Li Zefan
2009-12-09  1:08     ` Ben Blum
2009-12-09  1:40       ` Li Zefan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091204085854.GE18912@andrew.cmu.edu \
    --to=bblum@andrew.cmu.edu \
    --cc=akpm@linux-foundation.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®