All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aristeu Rozanski <aris@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Li Zefan <lizefan@huawei.com>,
	aris@redhat.com, Tejun Heo <tj@kernel.org>,
	Hugh Dickins <hughd@google.com>, Hillf Danton <dhillf@gmail.com>
Subject: [PATCH v3 2/3] cgroup: revise how we re-populate root directory
Date: Mon, 02 Jul 2012 10:29:27 -0400	[thread overview]
Message-ID: <20120702142926.405632285@napanee.usersys.redhat.com> (raw)
In-Reply-To: 20120702142925.795007114@napanee.usersys.redhat.com

[-- Attachment #1: cgroup2.patch --]
[-- Type: text/plain, Size: 5610 bytes --]

From: Li Zefan <lizefan@huawei.com>

When remounting cgroupfs with some subsystems added to it and some
removed, cgroup will remove all the files in root directory and then
re-popluate it.

What I'm doing here is, only remove files which belong to subsystems that
are to be unbinded, and only create files for newly-added subsystems.
The purpose is to have all other files untouched.

This is a preparation for cgroup xattr support.

v3:
- refresh patches after recent refactoring

Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Aristeu Rozanski <aris@redhat.com>

---
 include/linux/cgroup.h |    3 +++
 kernel/cgroup.c        |   49 +++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 44 insertions(+), 8 deletions(-)

--- linus-2.6.orig/include/linux/cgroup.h	2012-07-02 10:21:39.505647330 -0400
+++ linus-2.6/include/linux/cgroup.h	2012-07-02 10:21:58.055646941 -0400
@@ -306,6 +306,9 @@ 	 * If not 0, file mode is set to this v
 	 */
 	size_t max_write_len;
 
+	/* The subsystem this cgroup file belongs to */
+	struct cgroup_subsys *subsys;
+
 	/* CFTYPE_* flags */
 	unsigned int flags;
 
--- linus-2.6.orig/kernel/cgroup.c	2012-07-02 10:21:39.505647330 -0400
+++ linus-2.6/kernel/cgroup.c	2012-07-02 10:21:58.059646980 -0400
@@ -825,6 +825,7 @@ static int cgroup_mkdir(struct inode *di
 static struct dentry *cgroup_lookup(struct inode *, struct dentry *, struct nameidata *);
 static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
 static int cgroup_populate_dir(struct cgroup *cgrp);
+static int cgroup_repopulate_dir(struct cgroup *cgrp, unsigned long added_bits);
 static const struct inode_operations cgroup_dir_inode_operations;
 static const struct file_operations proc_cgroupstats_operations;
 
@@ -949,7 +950,8 @@ static void remove_dir(struct dentry *d)
 	dput(parent);
 }
 
-static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
+static int __cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft,
+			  bool remove_all, unsigned long removed_bits)
 {
 	struct cfent *cfe;
 
@@ -958,8 +960,13 @@ static int cgroup_rm_file(struct cgroup 
 
 	list_for_each_entry(cfe, &cgrp->files, node) {
 		struct dentry *d = cfe->dentry;
+		struct cftype *cft2 = cfe->type;
+
+		if (cft && cft2 != cft)
+			continue;
 
-		if (cft && cfe->type != cft)
+		if (!remove_all && cft2->subsys &&
+		    !test_bit(cft2->subsys->subsys_id, &removed_bits))
 			continue;
 
 		dget(d);
@@ -973,12 +980,19 @@ 		return 0;
 	return -ENOENT;
 }
 
-static void cgroup_clear_directory(struct dentry *dir)
+static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
+{
+	return __cgroup_rm_file(cgrp, cft, false, 0);
+}
+
+static void cgroup_clear_directory(struct dentry *dir, bool remove_all,
+				   unsigned long removed_bits)
 {
 	struct cgroup *cgrp = __d_cgrp(dir);
 
 	while (!list_empty(&cgrp->files))
-		cgroup_rm_file(cgrp, NULL);
+		if (__cgroup_rm_file(cgrp, NULL, remove_all, removed_bits))
+			break;
 }
 
 /*
@@ -988,7 +1002,7 @@ static void cgroup_d_remove_dir(struct d
 {
 	struct dentry *parent;
 
-	cgroup_clear_directory(dentry);
+	cgroup_clear_directory(dentry, true, 0);
 
 	parent = dentry->d_parent;
 	spin_lock(&parent->d_lock);
@@ -1353,6 +1367,7 @@ 	int ret = 0;
 	struct cgroupfs_root *root = sb->s_fs_info;
 	struct cgroup *cgrp = &root->top_cgroup;
 	struct cgroup_sb_opts opts;
+	unsigned long added_bits, removed_bits;
 
 	mutex_lock(&cgrp->dentry->d_inode->i_mutex);
 	mutex_lock(&cgroup_mutex);
@@ -1368,6 +1383,9 @@ 	int ret = 0;
 		pr_warning("cgroup: option changes via remount are deprecated (pid=%d comm=%s)\n",
 			   task_tgid_nr(current), current->comm);
 
+	added_bits = opts.subsys_bits & ~root->subsys_bits;
+	removed_bits = root->subsys_bits & ~opts.subsys_bits;
+
 	/* Don't allow flags or name to change at remount */
 	if (opts.flags != root->flags ||
 	    (opts.name && strcmp(opts.name, root->name))) {
@@ -1383,8 +1401,9 @@ 	int ret = 0;
 	}
 
 	/* clear out any existing files and repopulate subsystem files */
-	cgroup_clear_directory(cgrp->dentry);
-	cgroup_populate_dir(cgrp);
+	cgroup_clear_directory(cgrp->dentry, false, removed_bits);
+	/* re-populate subsystem files */
+	cgroup_repopulate_dir(cgrp, added_bits);
 
 	if (opts.release_agent)
 		strcpy(root->release_agent_path, opts.release_agent);
@@ -2696,6 +2715,8 @@ static int cgroup_add_file(struct cgroup
 	umode_t mode;
 	char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 };
 
+	cft->subsys = subsys;
+
 	/* does @cft->flags tell us to skip creation on @cgrp? */
 	if ((cft->flags & CFTYPE_NOT_ON_ROOT) && !cgrp->parent)
 		return 0;
@@ -3858,7 +3879,7 @@ static struct cftype files[] = {
 	{ }	/* terminate */
 };
 
-static int cgroup_populate_dir(struct cgroup *cgrp)
+static int __cgroup_populate_dir(struct cgroup *cgrp, unsigned long added_bits)
 {
 	int err;
 	struct cgroup_subsys *ss;
@@ -3870,6 +3891,8 @@ 	if (err < 0)
 	/* process cftsets of each subsystem */
 	for_each_subsys(cgrp->root, ss) {
 		struct cftype_set *set;
+		if (!test_bit(ss->subsys_id, &added_bits))
+			continue;
 
 		list_for_each_entry(set, &ss->cftsets, node)
 			cgroup_addrm_files(cgrp, ss, set->cfts, true);
@@ -3890,6 +3913,16 @@ 	if (err < 0)
 	return 0;
 }
 
+static int cgroup_populate_dir(struct cgroup *cgrp)
+{
+	return __cgroup_populate_dir(cgrp, cgrp->root->subsys_bits);
+}
+
+static int cgroup_repopulate_dir(struct cgroup *cgrp, unsigned long added_bits)
+{
+	return __cgroup_populate_dir(cgrp, added_bits);
+}
+
 static void css_dput_fn(struct work_struct *work)
 {
 	struct cgroup_subsys_state *css =


  parent reply	other threads:[~2012-07-02 14:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-02 14:29 [PATCH v3 0/3] cgroup: add xattr support Aristeu Rozanski
2012-07-02 14:29 ` [PATCH v3 1/3] xattr: extract simple_xattr code from tmpfs Aristeu Rozanski
2012-07-03 16:53   ` [PATCH v4 " Aristeu Rozanski
2012-07-02 14:29 ` Aristeu Rozanski [this message]
2012-07-09 17:17   ` [PATCH v3 2/3] cgroup: revise how we re-populate root directory Tejun Heo
2012-07-09 17:22     ` Tejun Heo
2012-07-09 17:28       ` Tejun Heo
2012-07-10 19:27         ` Aristeu Rozanski
2012-07-17 13:56           ` Aristeu Rozanski
2012-07-17 18:38           ` Tejun Heo
2012-07-17 21:29             ` Aristeu Rozanski
2012-07-17 21:40               ` Tejun Heo
2012-07-18 14:16                 ` Aristeu Rozanski
2012-07-18 16:32                   ` Tejun Heo
2012-07-02 14:29 ` [PATCH v3 3/3] cgroup: add xattr support Aristeu Rozanski
2012-07-17 20:41 ` [PATCH v3 0/3] " Tejun Heo
2012-07-18 20:02   ` Hugh Dickins
2012-07-18 22:10     ` Tejun Heo
2012-07-19  1:11       ` Hugh Dickins
2012-07-20 17:59         ` Aristeu Rozanski
2012-07-20 18:04           ` Tejun Heo
2012-08-07 15:22             ` Aristeu Rozanski
2012-07-22 19:12           ` Hugh Dickins
2012-07-23 18:12             ` Aristeu Rozanski
2012-07-24 18:28               ` Tejun Heo
2012-07-24 21:44                 ` Aristeu Rozanski
2012-07-20 18:10         ` Tejun Heo

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=20120702142926.405632285@napanee.usersys.redhat.com \
    --to=aris@redhat.com \
    --cc=dhillf@gmail.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.