[PATCH 01/14] fsnotify: change locking order in fsnotify_add_mark()

From: Lino Sanfilippo
Date: Wed Jan 19 2011 - 11:47:42 EST


Instead of taking
1. mark->lock
2. group->mark_lock
3. inode->lock

we now use another order in fsnotify_add_mark():
1. inode->lock
2. mark->lock

and assume that the callers took the group->mark_lock already.
By taking the mark_lock first, we can protect modification of the groups mark
list without the need of an extra lock like the group->mutex.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@xxxxxx>
---
fs/notify/mark.c | 38 +++++---------------------------------
1 files changed, 5 insertions(+), 33 deletions(-)

diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 28b64eb..a677af0 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -213,20 +213,9 @@ int fsnotify_add_mark(struct fsnotify_mark *mark,

/*
* LOCKING ORDER!!!!
- * mark->lock
- * group->mark_lock
* inode->i_lock
+ * mark->lock
*/
- spin_lock(&mark->lock);
- spin_lock(&group->mark_lock);
-
- mark->flags |= FSNOTIFY_MARK_FLAG_ALIVE;
- mark->group = group;
- list_add(&mark->g_list, &group->marks_list);
- fsnotify_get_mark(mark); /* for i_list and g_list */
- atomic_inc(&group->num_marks);
-
- ret = 0;
if (inode)
ret = fsnotify_add_inode_mark(mark, group, inode, allow_dups);
else if (mnt)
@@ -234,34 +223,17 @@ int fsnotify_add_mark(struct fsnotify_mark *mark,
else
BUG();
if (ret)
- goto err;
-
- spin_unlock(&group->mark_lock);
+ return ret;

- /* this will pin the object if appropriate */
- fsnotify_set_mark_mask_locked(mark, mark->mask);
+ fsnotify_get_mark(mark); /* for i_list and g_list */

- spin_unlock(&mark->lock);
+ list_add(&mark->g_list, &group->marks_list);
+ atomic_inc(&group->num_marks);

if (inode)
__fsnotify_update_child_dentry_flags(inode);

return 0;
-err:
- mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE;
- list_del_init(&mark->g_list);
- mark->group = NULL;
- atomic_dec(&group->num_marks);
-
- spin_unlock(&group->mark_lock);
- spin_unlock(&mark->lock);
-
- spin_lock(&destroy_lock);
- list_add(&mark->destroy_list, &destroy_list);
- spin_unlock(&destroy_lock);
- wake_up(&destroy_waitq);
-
- return ret;
}

/*
--
1.5.6.5

--
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/