From: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Cgroups <cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 2/3] cgroup: add cgroup_name() API
Date: Tue, 26 Feb 2013 18:25:08 +0800 [thread overview]
Message-ID: <512C8D84.7090707@huawei.com> (raw)
In-Reply-To: <20130226022703.GA13837-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
On 2013/2/26 10:27, Tejun Heo wrote:
> On Mon, Feb 25, 2013 at 02:17:49PM +0800, Li Zefan wrote:
>> cgroup_name() returns the name of a cgroup and it must be called with
>> rcu_read_lock() held.
>>
>> This will be used by cpuset.
>>
>> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> ...
>> /**
>> + * cgroup_name - get the name of a cgroup
>> + * @cgrp: the cgroup in question
>> + *
>> + * Must be called with rcu_read_lock() held.
>> + */
>> +char *cgroup_name(const struct cgroup *cgrp)
>> +{
>> + if (!cgrp->parent)
>> + return "/";
>> + else
>> + return rcu_dereference(cgrp->name)->name;
>> +}
>
> Can't we initialize ->name of root cgroup to "/" and lose the
> conditional?
Sure we can. We'll have to allocate cgrp->name in cgroup_remount() and
cgroup_init(), and free cgrp->name in cgroup_kill_sb(). It looks to me
the current version is a bit simpler.
That said, I don't have strong preference. I'll revise the patchset if
you still prefer to init root_cgrp->name.
> We can lose the wrapper altogether but if you're worried
> that sparse check isn't enough, we can have trivial inline wrapper,
> but in that case it probably would help to rename cgrp->name to, say,
> cgrp->__name and put a comment directing people to the accessing
> wrapper which should probably return const char *.
>
I do expect people always use cgroup_name(). Should anyone access
cgrp->name directly and doesn't notice cgrp->name can be NULL, he'll
get NULL ptr crash and turn to cgroup_name(), and a comment to guide
people to cgroup_name() is helpful too.
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizefan@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>,
LKML <linux-kernel@vger.kernel.org>,
Cgroups <cgroups@vger.kernel.org>
Subject: Re: [PATCH 2/3] cgroup: add cgroup_name() API
Date: Tue, 26 Feb 2013 18:25:08 +0800 [thread overview]
Message-ID: <512C8D84.7090707@huawei.com> (raw)
In-Reply-To: <20130226022703.GA13837@htj.dyndns.org>
On 2013/2/26 10:27, Tejun Heo wrote:
> On Mon, Feb 25, 2013 at 02:17:49PM +0800, Li Zefan wrote:
>> cgroup_name() returns the name of a cgroup and it must be called with
>> rcu_read_lock() held.
>>
>> This will be used by cpuset.
>>
>> Signed-off-by: Li Zefan <lizefan@huawei.com>
> ...
>> /**
>> + * cgroup_name - get the name of a cgroup
>> + * @cgrp: the cgroup in question
>> + *
>> + * Must be called with rcu_read_lock() held.
>> + */
>> +char *cgroup_name(const struct cgroup *cgrp)
>> +{
>> + if (!cgrp->parent)
>> + return "/";
>> + else
>> + return rcu_dereference(cgrp->name)->name;
>> +}
>
> Can't we initialize ->name of root cgroup to "/" and lose the
> conditional?
Sure we can. We'll have to allocate cgrp->name in cgroup_remount() and
cgroup_init(), and free cgrp->name in cgroup_kill_sb(). It looks to me
the current version is a bit simpler.
That said, I don't have strong preference. I'll revise the patchset if
you still prefer to init root_cgrp->name.
> We can lose the wrapper altogether but if you're worried
> that sparse check isn't enough, we can have trivial inline wrapper,
> but in that case it probably would help to rename cgrp->name to, say,
> cgrp->__name and put a comment directing people to the accessing
> wrapper which should probably return const char *.
>
I do expect people always use cgroup_name(). Should anyone access
cgrp->name directly and doesn't notice cgrp->name can be NULL, he'll
get NULL ptr crash and turn to cgroup_name(), and a comment to guide
people to cgroup_name() is helpful too.
next prev parent reply other threads:[~2013-02-26 10:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 6:17 [PATCH v3 1/3] cgroup: fix cgroup_path() vs rename() race Li Zefan
2013-02-25 6:17 ` Li Zefan
2013-02-25 6:17 ` [PATCH 2/3] cgroup: add cgroup_name() API Li Zefan
[not found] ` <512B020D.9040504-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-02-26 2:27 ` Tejun Heo
2013-02-26 2:27 ` Tejun Heo
[not found] ` <20130226022703.GA13837-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-02-26 10:25 ` Li Zefan [this message]
2013-02-26 10:25 ` Li Zefan
2013-02-26 13:26 ` Tejun Heo
[not found] ` <CAOS58YMb7HRQ3X+Z92vi3+jKr4DuNmAgxtc5e3Jkhy-s-7Os-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-02-27 10:49 ` Li Zefan
2013-02-27 10:49 ` Li Zefan
[not found] ` <512DE4A8.5050303-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-02-27 13:23 ` Tejun Heo
2013-02-27 13:23 ` Tejun Heo
[not found] ` <CAOS58YMhm6Uia0bx6oUHwheXUhu8i31LPhh8VVggvg0vg-UmUQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-02-28 6:53 ` Li Zefan
2013-02-28 6:53 ` Li Zefan
2013-02-28 14:49 ` Tejun Heo
2013-03-01 6:36 ` Li Zefan
[not found] ` <51304C6D.8050207-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-03-01 20:39 ` Al Viro
2013-03-01 20:39 ` Al Viro
[not found] ` <20130301203917.GT4503-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2013-03-01 20:45 ` Tejun Heo
2013-03-01 20:45 ` Tejun Heo
[not found] ` <CAOS58YPNAPhWUwNq9G39Airo+TvV2ecXBiNU5s9PFqkL3RbRFg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-03-04 3:02 ` Li Zefan
2013-03-04 3:02 ` Li Zefan
[not found] ` <51340ECD.1030905-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-03-04 17:38 ` Tejun Heo
2013-03-04 17:38 ` Tejun Heo
[not found] ` <512B01FA.5020506-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-02-25 6:18 ` [PATCH 3/3] cpuset: use cgroup_name() in cpuset_print_task_mems_allowed() Li Zefan
2013-02-25 6:18 ` 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=512C8D84.7090707@huawei.com \
--to=lizefan-hv44wf8li93qt0dzr+alfa@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@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.