Skip to content

Commit daf88c8

Browse files
committed
kill-the-BKL/reiserfs: provide a tool to lock only once the write lock
Sometimes we don't want to recursively hold the per superblock write lock because we want to be sure it is actually released when we come to sleep. This patch introduces the necessary tools for that. reiserfs_write_lock_once() does the same job than reiserfs_write_lock() except that it won't try to acquire recursively the lock if the current task already owns it. Also the lock_depth before the call of this function is returned. reiserfs_write_unlock_once() unlock only if reiserfs_write_lock_once() returned a depth equal to -1, ie: only if it actually locked. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Alessio Igor Bogani <abogani@texware.it> Cc: Jeff Mahoney <jeffm@suse.com> Cc: Alexander Beregalov <a.beregalov@gmail.com> Cc: Chris Mason <chris.mason@oracle.com> LKML-Reference: <1239680065-25013-2-git-send-email-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent a412f9e commit daf88c8

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎fs/reiserfs/lock.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,32 @@ void reiserfs_write_unlock(struct super_block *s)
4949
}
5050
}
5151

52+
/*
53+
* If we already own the lock, just exit and don't increase the depth.
54+
* Useful when we don't want to lock more than once.
55+
*
56+
* We always return the lock_depth we had before calling
57+
* this function.
58+
*/
59+
int reiserfs_write_lock_once(struct super_block *s)
60+
{
61+
struct reiserfs_sb_info *sb_i = REISERFS_SB(s);
62+
63+
if (sb_i->lock_owner != current) {
64+
mutex_lock(&sb_i->lock);
65+
sb_i->lock_owner = current;
66+
return sb_i->lock_depth++;
67+
}
68+
69+
return sb_i->lock_depth;
70+
}
71+
72+
void reiserfs_write_unlock_once(struct super_block *s, int lock_depth)
73+
{
74+
if (lock_depth == -1)
75+
reiserfs_write_unlock(s);
76+
}
77+
5278
/*
5379
* Utility function to force a BUG if it is called without the superblock
5480
* write lock held. caller is the string printed just before calling BUG()

‎include/linux/reiserfs_fs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
*/
6060
void reiserfs_write_lock(struct super_block *s);
6161
void reiserfs_write_unlock(struct super_block *s);
62+
int reiserfs_write_lock_once(struct super_block *s);
63+
void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
6264

6365
struct fid;
6466

0 commit comments

Comments
 (0)