All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: [PATCH 4/6] cgroup: clean up find_css_set() and friends
Date: Fri, 21 Jun 2013 18:34:12 -0700	[thread overview]
Message-ID: <1371864854-28364-5-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1371864854-28364-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

find_css_set() passes uninitialized on-stack template[] array to
find_existing_css_set() which sets the entries for all subsystems.
Passing around an uninitialized array is a bit icky and we want to
introduce an iterator which only iterates loaded subsystems.  Let's
initialize it on definition.

While at it, also make the following cosmetic cleanups.

* Convert to proper /** comments.

* Reorder variable declarations.

* Replace comment on synchronization with lockdep_assert_held().

This patch doesn't make any functional differences.

Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 kernel/cgroup.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c3222a7..5f85f3a 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -434,7 +434,7 @@ static inline void put_css_set_taskexit(struct css_set *cset)
 	__put_css_set(cset, 1);
 }
 
-/*
+/**
  * compare_css_sets - helper function for find_existing_css_set().
  * @cset: candidate css_set being tested
  * @old_cset: existing css_set for a task
@@ -506,27 +506,20 @@ static bool compare_css_sets(struct css_set *cset,
 	return true;
 }
 
-/*
- * find_existing_css_set() is a helper for
- * find_css_set(), and checks to see whether an existing
- * css_set is suitable.
- *
- * oldcg: the cgroup group that we're using before the cgroup
- * transition
- *
- * cgrp: the cgroup that we're moving into
- *
- * template: location in which to build the desired set of subsystem
- * state objects for the new cgroup group
+/**
+ * find_existing_css_set - init css array and find the matching css_set
+ * @old_cset: the css_set that we're using before the cgroup transition
+ * @cgrp: the cgroup that we're moving into
+ * @template: out param for the new set of csses, should be clear on entry
  */
 static struct css_set *find_existing_css_set(struct css_set *old_cset,
 					struct cgroup *cgrp,
 					struct cgroup_subsys_state *template[])
 {
-	int i;
 	struct cgroupfs_root *root = cgrp->root;
 	struct css_set *cset;
 	unsigned long key;
+	int i;
 
 	/*
 	 * Build the set of subsystem state objects that we want to see in the
@@ -618,22 +611,25 @@ static void link_css_set(struct list_head *tmp_links, struct css_set *cset,
 	list_add_tail(&link->cgrp_link, &cset->cgrp_links);
 }
 
-/*
- * find_css_set() takes an existing cgroup group and a
- * cgroup object, and returns a css_set object that's
- * equivalent to the old group, but with the given cgroup
- * substituted into the appropriate hierarchy. Must be called with
- * cgroup_mutex held
+/**
+ * find_css_set - return a new css_set with one cgroup updated
+ * @old_cset: the baseline css_set
+ * @cgrp: the cgroup to be updated
+ *
+ * Return a new css_set that's equivalent to @old_cset, but with @cgrp
+ * substituted into the appropriate hierarchy.
  */
 static struct css_set *find_css_set(struct css_set *old_cset,
 				    struct cgroup *cgrp)
 {
+	struct cgroup_subsys_state *template[CGROUP_SUBSYS_COUNT] = { };
 	struct css_set *cset;
-	struct cgroup_subsys_state *template[CGROUP_SUBSYS_COUNT];
 	struct list_head tmp_links;
 	struct cgrp_cset_link *link;
 	unsigned long key;
 
+	lockdep_assert_held(&cgroup_mutex);
+
 	/* First see if we already have a cgroup group that matches
 	 * the desired set */
 	read_lock(&css_set_lock);
-- 
1.8.2.1

  parent reply	other threads:[~2013-06-22  1:34 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-22  1:34 [PATCHSET cgroup/for-3.11] cgroup: miscellaneous cleanups Tejun Heo
     [not found] ` <1371864854-28364-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-22  1:34   ` [PATCH 1/6] cgroup: convert CFTYPE_* flags to enums Tejun Heo
2013-06-22  1:34   ` Tejun Heo
     [not found]     ` <1371864854-28364-2-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-24 10:21       ` Li Zefan
2013-06-24 10:21         ` Li Zefan
2013-06-22  1:34   ` [PATCH 2/6] cgroup: prefix global variables with "cgroup_" Tejun Heo
2013-06-22  1:34   ` Tejun Heo
     [not found]     ` <1371864854-28364-3-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-24 10:22       ` Li Zefan
2013-06-22  1:34   ` [PATCH 3/6] cgroup: remove cgroup->actual_subsys_mask Tejun Heo
2013-06-22  1:34   ` Tejun Heo
     [not found]     ` <1371864854-28364-4-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-24 10:26       ` Li Zefan
2013-06-24 22:30       ` [PATCH v2 " Tejun Heo
2013-06-24 22:30       ` Tejun Heo
2013-06-22  1:34   ` [PATCH 4/6] cgroup: clean up find_css_set() and friends Tejun Heo
2013-06-22  1:34   ` Tejun Heo [this message]
     [not found]     ` <1371864854-28364-5-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-24 10:33       ` Li Zefan
     [not found]         ` <51C8206F.90404-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-24 20:03           ` Tejun Heo
2013-06-24 20:03           ` Tejun Heo
2013-06-22  1:34   ` [PATCH 5/6] cgroup: s/for_each_subsys()/for_each_root_subsys()/ Tejun Heo
     [not found]     ` <1371864854-28364-6-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-24 10:52       ` Li Zefan
2013-06-24 10:52         ` Li Zefan
2013-06-22  1:34   ` Tejun Heo
2013-06-22  1:34   ` [PATCH 6/6] cgroup: implement for_each_[builtin_]subsys() Tejun Heo
     [not found]     ` <1371864854-28364-7-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-24 10:50       ` Li Zefan
     [not found]         ` <51C82482.9020902-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-24 20:04           ` Tejun Heo
2013-06-25  0:22       ` [PATCH v2 " Tejun Heo
     [not found]         ` <20130625002236.GU1918-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-06-25  1:35           ` Li Zefan
     [not found]             ` <51C8F3EB.4090106-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-25 18:42               ` Tejun Heo
2013-06-22  1:34   ` [PATCH " Tejun Heo
2013-06-24 22:32   ` [PATCHSET cgroup/for-3.11] cgroup: miscellaneous cleanups Tejun Heo
2013-06-24 22:32   ` Tejun Heo
2013-06-25  0:34   ` [PATCH 5.5/6] cgroup: move init_css_set initialization inside cgroup_mutex Tejun Heo
     [not found]     ` <20130625003434.GV1918-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-06-25  1:36       ` 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=1371864854-28364-5-git-send-email-tj@kernel.org \
    --to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.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.