From: Li Zefan <lizf@cn.fujitsu.com>
To: Matt Helsley <matthltc@us.ibm.com>
Cc: "akpm >> Andrew Morton" <akpm@linux-foundation.org>,
containers@lists.linux-foundation.org,
Paul Menage <menage@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 2/7] cgroups: Allow to bind a subsystem to a cgroup hierarchy
Date: Mon, 25 Oct 2010 09:23:00 +0800 [thread overview]
Message-ID: <4CC4DBF4.1030405@cn.fujitsu.com> (raw)
In-Reply-To: <20101022213819.GK10119@count0.beaverton.ibm.com>
>> +/*
>> + * cgroup_walk_herarchy - iterate through a cgroup hierarchy
>> + * @process_cgroup: callback called on each cgroup in the hierarchy
>> + * @data: will be passed to @process_cgroup
>> + * @top_cgrp: the root cgroup of the hierarchy
>> + *
>> + * For such a hierarchy:
>> + * a1 c1
>> + * / /
>> + * Root - a2 - b1 - c2
>> + * \
>> + * a3
>> + *
>> + * The iterating order is: a1, a2, b1, c1, c2, a3. So a parent will be
>> + * processed before its children.
>> + */
>
> You could just say it's a depth-first walk except we process the parent before
> its children.
>
Will revise the comment. A diagram is intuitive. :)
>> +static int cgroup_walk_hierarchy(int (*process_cgroup)(struct cgroup *, void *),
>> + void *data, struct cgroup *top_cgrp)
>
> <snip>
>
>> +static int hierarchy_populate_dir(struct cgroup *cgrp, void *data)
>> +{
>> + mutex_lock_nested(&cgrp->dentry->d_inode->i_mutex, I_MUTEX_CHILD);
>> + cgroup_populate_dir(cgrp);
>> + mutex_unlock(&cgrp->dentry->d_inode->i_mutex);
>> + return 0;
>> +}
>> +
>> /*
>> * Call with cgroup_mutex held. Drops reference counts on modules, including
>> * any duplicate ones that parse_cgroupfs_options took. If this function
>> @@ -945,36 +1079,53 @@ static int rebind_subsystems(struct cgroupfs_root *root,
>> unsigned long added_bits, removed_bits;
>> struct cgroup *cgrp = &root->top_cgroup;
>> int i;
>> + int err;
>>
>> BUG_ON(!mutex_is_locked(&cgroup_mutex));
>>
>> removed_bits = root->actual_subsys_bits & ~final_bits;
>> added_bits = final_bits & ~root->actual_subsys_bits;
>> +
>> /* Check that any added subsystems are currently free */
>> - for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
>> - unsigned long bit = 1UL << i;
>> - struct cgroup_subsys *ss = subsys[i];
>> - if (!(bit & added_bits))
>> - continue;
>> + for_each_set_bit(i, &added_bits, CGROUP_SUBSYS_COUNT) {
>> /*
>> * Nobody should tell us to do a subsys that doesn't exist:
>> * parse_cgroupfs_options should catch that case and refcounts
>> * ensure that subsystems won't disappear once selected.
>> */
>> - BUG_ON(ss == NULL);
>> - if (ss->root != &rootnode) {
>> + BUG_ON(subsys[i] == NULL);
>> + if (subsys[i]->root != &rootnode) {
>> /* Subsystem isn't free */
>> return -EBUSY;
>> }
>> }
>>
>> - /* Currently we don't handle adding/removing subsystems when
>> - * any child cgroups exist. This is theoretically supportable
>> - * but involves complex error handling, so it's being left until
>> - * later */
>> - if (root->number_of_cgroups > 1)
>> + /* removing will be supported later */
>> + if (root->number_of_cgroups > 1 && removed_bits)
>> return -EBUSY;
>>
>> + if (root->number_of_cgroups > 1) {
>
> Is there something wrong with the indentation here? I can't
> see the closing brace for the "if (root->number_of_cgroups > 1)"
> that should precede the for_each_set_bit() loop below.
>
Oops, I must have forgot to commit the change when I fixed this.
>> + for_each_set_bit(i, &added_bits, CGROUP_SUBSYS_COUNT)
>> + if (!subsys[i]->can_bind)
>> + return -EBUSY;
>
> I think you could avoid the can_bind flag field entirely and do:
>
> if (!subsys[i]->bind)
>
Nope. For some subsystems we just set the flag and need not to
provide a bind() callback.
> Also, if we're going with my "split out unbind" suggestion I think
> the part here would be:
>
> for_each_set_bit(i, &removed_bits, CGROUP_SUBSYS_COUNT)
> if (!subsys[i]->unbind)
> return -EBUSY;
>
next prev parent reply other threads:[~2010-10-25 1:22 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-22 8:09 [PATCH 0/7] cgroups: Allow to bind/unbind subsystems to/from non-trival hierarchy Li Zefan
2010-10-22 8:09 ` [PATCH 1/7] cgroups: Shrink struct cgroup_subsys Li Zefan
2010-10-28 23:34 ` Paul Menage
2010-11-08 5:23 ` Li Zefan
2010-11-09 21:05 ` Paul Menage
2010-11-10 0:52 ` Li Zefan
2010-11-10 1:53 ` Paul Menage
2010-11-10 2:06 ` Li Zefan
2010-11-10 2:15 ` Paul Menage
2010-10-22 8:09 ` [PATCH 2/7] cgroups: Allow to bind a subsystem to a cgroup hierarchy Li Zefan
2010-10-22 12:47 ` Peter Zijlstra
2010-10-25 0:59 ` Li Zefan
2010-10-22 21:38 ` Matt Helsley
2010-10-25 1:23 ` Li Zefan [this message]
2010-10-28 23:57 ` Paul Menage
2010-10-28 23:55 ` Paul Menage
2010-11-08 5:26 ` Li Zefan
2010-10-22 8:10 ` [PATCH 3/7] cgroups: Allow to unbind subsystem from a cgroup hierarachy Li Zefan
2010-10-29 0:02 ` Paul Menage
2010-10-22 8:11 ` [PATCH 4/7] cgroups: Mark some subsystems bindable Li Zefan
2010-10-22 8:11 ` [PATCH 5/7] cgroups: Make freezer subsystem bindable Li Zefan
2010-10-22 20:57 ` Matt Helsley
2010-10-22 21:46 ` Matt Helsley
2010-10-29 0:06 ` Paul Menage
2010-10-22 21:57 ` Matt Helsley
2010-10-25 1:15 ` Li Zefan
2010-10-22 8:12 ` [PATCH 6/7] cgroups: Warn if a bindable subsystem calls css_get() Li Zefan
2010-10-29 0:05 ` Paul Menage
2010-10-22 8:12 ` [PATCH 7/7] cgroups: Update documentation for bindable subsystems Li Zefan
2010-10-25 0:36 ` KAMEZAWA Hiroyuki
2010-10-25 0:52 ` Li Zefan
2010-10-25 0:56 ` Li Zefan
2010-10-29 0:13 ` Paul Menage
2010-10-29 0:15 ` Paul Menage
2010-11-08 5:27 ` Li Zefan
2010-10-22 12:50 ` [PATCH 0/7] cgroups: Allow to bind/unbind subsystems to/from non-trival hierarchy Peter Zijlstra
2010-10-25 1:07 ` Li Zefan
2010-10-28 23:33 ` Paul Menage
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=4CC4DBF4.1030405@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.linux-foundation.org \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthltc@us.ibm.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