kill-the-BKL/reiserfs: provide a tool to lock only once the write lock
authorFrederic Weisbecker <fweisbec@gmail.com>
Tue, 14 Apr 2009 03:34:23 +0000 (05:34 +0200)
committerFrederic Weisbecker <fweisbec@gmail.com>
Mon, 14 Sep 2009 05:18:02 +0000 (07:18 +0200)
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>
fs/reiserfs/lock.c
include/linux/reiserfs_fs.h

index cdd8d9ef048e162dacc9dfe057e31c2a8294d14c..cb1bba3802dd01e09f75b3a9791ca698e8d78133 100644 (file)
@@ -49,6 +49,32 @@ void reiserfs_write_unlock(struct super_block *s)
        }
 }
 
+/*
+ * If we already own the lock, just exit and don't increase the depth.
+ * Useful when we don't want to lock more than once.
+ *
+ * We always return the lock_depth we had before calling
+ * this function.
+ */
+int reiserfs_write_lock_once(struct super_block *s)
+{
+       struct reiserfs_sb_info *sb_i = REISERFS_SB(s);
+
+       if (sb_i->lock_owner != current) {
+               mutex_lock(&sb_i->lock);
+               sb_i->lock_owner = current;
+               return sb_i->lock_depth++;
+       }
+
+       return sb_i->lock_depth;
+}
+
+void reiserfs_write_unlock_once(struct super_block *s, int lock_depth)
+{
+       if (lock_depth == -1)
+               reiserfs_write_unlock(s);
+}
+
 /*
  * Utility function to force a BUG if it is called without the superblock
  * write lock held.  caller is the string printed just before calling BUG()
index e47328f51801e74913e8314eb8f1648476391b57..4a2df57c8b1d590ba2f9226e358d2e413a3917ca 100644 (file)
@@ -59,6 +59,8 @@
  */
 void reiserfs_write_lock(struct super_block *s);
 void reiserfs_write_unlock(struct super_block *s);
+int reiserfs_write_lock_once(struct super_block *s);
+void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);
 
 struct fid;