From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Alessio Igor Bogani <abogani@texware.it>,
Jeff Mahoney <jeffm@suse.com>,
ReiserFS Development List <reiserfs-devel@vger.kernel.org>,
Alexander Beregalov <a.beregalov@gmail.com>,
Chris Mason <chris.mason@oracle.com>
Subject: [PATCH 1/3] kill-the-BKL/reiserfs: provide a tool to lock only once the write lock
Date: Tue, 14 Apr 2009 05:34:23 +0200 [thread overview]
Message-ID: <1239680065-25013-2-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1239680065-25013-1-git-send-email-fweisbec@gmail.com>
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>
---
fs/reiserfs/lock.c | 26 ++++++++++++++++++++++++++
include/linux/reiserfs_fs.h | 2 ++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/fs/reiserfs/lock.c b/fs/reiserfs/lock.c
index cdd8d9e..cb1bba3 100644
--- a/fs/reiserfs/lock.c
+++ b/fs/reiserfs/lock.c
@@ -50,6 +50,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()
*/
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index f6b7b7b..6587b4e 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -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;
--
1.6.1
next prev parent reply other threads:[~2009-04-14 3:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-14 3:34 [PATCH 0/3] kill-the-BKL/reiserfs: reiserfs fixes Frederic Weisbecker
2009-04-14 3:34 ` Frederic Weisbecker [this message]
2009-04-14 3:34 ` [PATCH 2/3] kill-the-BKL/reiserfs: lock only once in reiserfs_truncate_file Frederic Weisbecker
2009-04-14 3:34 ` [PATCH 3/3] kill-the-BKL/reiserfs: only acquire the write lock once in reiserfs_dirty_inode Frederic Weisbecker
2009-04-14 4:51 ` [PATCH 0/3] kill-the-BKL/reiserfs: reiserfs fixes Alexander Beregalov
2009-04-14 9:01 ` [tree] latest kill-the-BKL tree, v12 Ingo Molnar
2009-04-14 10:02 ` Edward Shishkin
2009-04-14 21:32 ` Frederic Weisbecker
2009-04-14 21:27 ` Frederic Weisbecker
2009-04-15 22:58 ` Alexander Beregalov
2009-04-15 23:07 ` Ingo Molnar
2009-04-15 23:13 ` Trond Myklebust
2009-04-15 23:35 ` Frederic Weisbecker
2009-04-16 8:51 ` Ingo Molnar
2009-04-16 14:35 ` Alessio Igor Bogani
2009-04-16 16:40 ` Frederic Weisbecker
2009-04-14 10:00 ` [PATCH 0/3] kill-the-BKL/reiserfs: reiserfs fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1239680065-25013-2-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=a.beregalov@gmail.com \
--cc=abogani@texware.it \
--cc=chris.mason@oracle.com \
--cc=jeffm@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=reiserfs-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome