Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1340213

[PATCH 04/12] cgroup: factor out cgroup_create() out of cgroup_mkdir()

From Tejun Heo <tj@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 04/12] cgroup: factor out cgroup_create() out of cgroup_mkdir()
Date 2016-02-23 04:50 +0100
Message-ID <r5c95-7TE-19@gated-at.bofh.it> (permalink)
References <r5c94-7TE-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


We're in the process of refactoring cgroup and css management paths to
separate them out to eventually allow cgroups which aren't visible
through cgroup fs.  This patch factors out cgroup_create() out of
cgroup_mkdir().  cgroup_create() contains all internal object creation
and initialization.  cgroup_mkdir() uses cgroup_create() to create the
internal cgroup and adds interface directory and file creation.

This patch doesn't cause any behavior differences.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/cgroup.c | 72 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 29 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index dd550b3..16c04d1 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4884,33 +4884,19 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp,
 	return ERR_PTR(err);
 }
 
-static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
-			umode_t mode)
+static struct cgroup *cgroup_create(struct cgroup *parent)
 {
-	struct cgroup *parent, *cgrp, *tcgrp;
-	struct cgroup_root *root;
+	struct cgroup_root *root = parent->root;
 	struct cgroup_subsys *ss;
-	struct kernfs_node *kn;
-	int level, ssid, ret;
-
-	/* Do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable.
-	 */
-	if (strchr(name, '\n'))
-		return -EINVAL;
-
-	parent = cgroup_kn_lock_live(parent_kn);
-	if (!parent)
-		return -ENODEV;
-	root = parent->root;
-	level = parent->level + 1;
+	struct cgroup *cgrp, *tcgrp;
+	int level = parent->level + 1;
+	int ssid, ret;
 
 	/* allocate the cgroup and its ID, 0 is reserved for the root */
 	cgrp = kzalloc(sizeof(*cgrp) +
 		       sizeof(cgrp->ancestor_ids[0]) * (level + 1), GFP_KERNEL);
-	if (!cgrp) {
-		ret = -ENOMEM;
-		goto out_unlock;
-	}
+	if (!cgrp)
+		return ERR_PTR(-ENOMEM);
 
 	ret = percpu_ref_init(&cgrp->self.refcnt, css_release, 0, GFP_KERNEL);
 	if (ret)
@@ -4974,6 +4960,40 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 		cgroup_refresh_subtree_ss_mask(cgrp);
 	}
 
+	return cgrp;
+
+out_cancel_ref:
+	percpu_ref_exit(&cgrp->self.refcnt);
+out_free_cgrp:
+	kfree(cgrp);
+	return ERR_PTR(ret);
+out_destroy:
+	cgroup_destroy_locked(cgrp);
+	return ERR_PTR(ret);
+}
+
+static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
+			umode_t mode)
+{
+	struct cgroup *parent, *cgrp;
+	struct cgroup_subsys *ss;
+	struct kernfs_node *kn;
+	int ssid, ret;
+
+	/* do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable */
+	if (strchr(name, '\n'))
+		return -EINVAL;
+
+	parent = cgroup_kn_lock_live(parent_kn);
+	if (!parent)
+		return -ENODEV;
+
+	cgrp = cgroup_create(parent);
+	if (IS_ERR(cgrp)) {
+		ret = PTR_ERR(cgrp);
+		goto out_unlock;
+	}
+
 	/* create the directory */
 	kn = kernfs_create_dir(parent->kn, name, mode, cgrp);
 	if (IS_ERR(kn)) {
@@ -5008,17 +5028,11 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 	ret = 0;
 	goto out_unlock;
 
-out_cancel_ref:
-	percpu_ref_exit(&cgrp->self.refcnt);
-out_free_cgrp:
-	kfree(cgrp);
+out_destroy:
+	cgroup_destroy_locked(cgrp);
 out_unlock:
 	cgroup_kn_unlock(parent_kn);
 	return ret;
-
-out_destroy:
-	cgroup_destroy_locked(cgrp);
-	goto out_unlock;
 }
 
 /*
-- 
2.5.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHSET cgroup/for-4.6] cgroup: make control mask updates modular and recursive Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 03/12] cgroup: reorder operations in cgroup_mkdir() Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 08/12] cgroup: factor out cgroup_apply_control_enable() from cgroup_subtree_control_write() Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 05/12] cgroup: introduce cgroup_control() and cgroup_ss_mask() Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 04/12] cgroup: factor out cgroup_create() out of cgroup_mkdir() Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 06/12] cgroup: factor out cgroup_drain_offline() from cgroup_subtree_control_write() Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 02/12] cgroup: explicitly track whether a cgroup_subsys_state is visible to userland Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 10/12] cgroup: introduce cgroup_{save|propagate|restore}_control() Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 01/12] cgroup: separate out interface file creation from css creation Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100
  [PATCH 09/12] cgroup: make cgroup_drain_offline() and cgroup_apply_control_{disable|enable}() recursive Tejun Heo <tj@kernel.org> - 2016-02-23 04:50 +0100

csiph-web