Re: [PATCH 1/4] Support named cgroups hierarchies

From: Li Zefan
Date: Thu Jul 23 2009 - 02:51:56 EST


>>> static int cgroup_set_super(struct super_block *sb, void *data)
>>> {
>>> int ret;
>>> - struct cgroupfs_root *root = data;
>>> + struct cgroup_sb_opts *opts = data;
>>> +
>>> + /* If we don't have a new root, we can't set up a new sb */
>>> + if (!opts->new_root)
>>> + return -EINVAL;
>>> +
>> I think this should be BUG_ON(). If set_super() is called,
>> we are allocating a new root, so opts->new_root won't be NULL.
>
> Not true - if you try to mount a hierarchy by name, but with no
> subsystem options, then we don't construct a new root, but we still
> call sget(). If we find a superblock with the right name then we use
> it, else sget() will allocate a new superblock and call
> cgroup_set_super(), at which point we need to fail.
>

Ah, I see.

>>> + struct cgroupfs_root *new_root = cgroup_root_from_opts(&opts);
>> Why not just declare new_root in the beginning of cgroup_get_sb()?
>
> Because it's not needed for the entire scope of the function. Keeping
> its scope as small as possible makes it clearer what it's being used
> for.
>

If we had been doing this, we'll see many:

(no if, while, for)
{
...
}

in kernel code, but I don't remember I ever saw this style.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/