Re: [PATCH v2 2/3] cgroup: revise how we re-populate root directory

From: Hillf Danton
Date: Thu Mar 01 2012 - 07:48:21 EST


On Thu, Mar 1, 2012 at 2:17 PM, Li Zefan <lizf@xxxxxxxxxxxxxx> wrote:
>
> -static void cgroup_clear_directory(struct dentry *dentry)
> +static void cgroup_clear_directory(struct dentry *dentry, bool remove_all,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âunsigned long removed_bits)
> Â{
> - Â Â Â struct list_head *node;
> + Â Â Â LIST_HEAD(head);
> + Â Â Â struct dentry *d, *node;
>
> Â Â Â ÂBUG_ON(!mutex_is_locked(&dentry->d_inode->i_mutex));
> +
> Â Â Â Âspin_lock(&dentry->d_lock);
> - Â Â Â node = dentry->d_subdirs.next;
> - Â Â Â while (node != &dentry->d_subdirs) {
> - Â Â Â Â Â Â Â struct dentry *d = list_entry(node, struct dentry, d_u.d_child);
> + Â Â Â list_for_each_entry_safe(d, node, &dentry->d_subdirs, d_u.d_child) {
> + Â Â Â Â Â Â Â struct cftype *cft = d->d_fsdata;
> +
> + Â Â Â Â Â Â Â if (!remove_all && cft->subsys &&
> + Â Â Â Â Â Â Â Â Â !test_bit(cft->subsys->subsys_id, &removed_bits))
> + Â Â Â Â Â Â Â Â Â Â Â continue;
>
> Â Â Â Â Â Â Â Âspin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
> - Â Â Â Â Â Â Â list_del_init(node);
> + Â Â Â Â Â Â Â list_move(&d->d_u.d_child, &head);
> Â Â Â Â Â Â Â Âif (d->d_inode) {
> Â Â Â Â Â Â Â Â Â Â Â Â/* This should never be called on a cgroup
> Â Â Â Â Â Â Â Â Â Â Â Â * directory with child cgroups */
> Â Â Â Â Â Â Â Â Â Â Â ÂBUG_ON(d->d_inode->i_mode & S_IFDIR);
> Â Â Â Â Â Â Â Â Â Â Â Âdget_dlock(d);
> - Â Â Â Â Â Â Â Â Â Â Â spin_unlock(&d->d_lock);
> - Â Â Â Â Â Â Â Â Â Â Â spin_unlock(&dentry->d_lock);
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â spin_unlock(&d->d_lock);
> + Â Â Â }
> + Â Â Â spin_unlock(&dentry->d_lock);
> +

Safe to process isolated entries without dentry->d_lock held?

-hd

> + Â Â Â list_for_each_entry_safe(d, node, &head, d_u.d_child) {
> + Â Â Â Â Â Â Â spin_lock(&d->d_lock);
> + Â Â Â Â Â Â Â list_del_init(&d->d_u.d_child);
> + Â Â Â Â Â Â Â spin_unlock(&d->d_lock);
> + Â Â Â Â Â Â Â if (d->d_inode) {
> Â Â Â Â Â Â Â Â Â Â Â Âd_delete(d);
> Â Â Â Â Â Â Â Â Â Â Â Âsimple_unlink(dentry->d_inode, d);
> Â Â Â Â Â Â Â Â Â Â Â Âdput(d);
> - Â Â Â Â Â Â Â Â Â Â Â spin_lock(&dentry->d_lock);
> - Â Â Â Â Â Â Â } else
> - Â Â Â Â Â Â Â Â Â Â Â spin_unlock(&d->d_lock);
> - Â Â Â Â Â Â Â node = dentry->d_subdirs.next;
> + Â Â Â Â Â Â Â }
> Â Â Â Â}
> - Â Â Â spin_unlock(&dentry->d_lock);
> Â}
>
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—