From: Erez Zadok <ezk@cs.sunysb.edu>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
viro@ftp.linux.org.uk, hch@infradead.org,
Erez Zadok <ezk@cs.sunysb.edu>
Subject: [PATCH 5/8] Unionfs: avoid a deadlock during branch-management on a pivot_root'ed union
Date: Fri, 2 Nov 2007 21:22:46 -0400 [thread overview]
Message-ID: <11940529712183-git-send-email-ezk@cs.sunysb.edu> (raw)
In-Reply-To: <11940529692937-git-send-email-ezk@cs.sunysb.edu>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Acked-by: Herton Ronaldo Krzesinski <herton@mandriva.com>
---
fs/unionfs/union.h | 39 +++++++++++++++++++++++++++++++++------
1 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/fs/unionfs/union.h b/fs/unionfs/union.h
index 6333488..0476f97 100644
--- a/fs/unionfs/union.h
+++ b/fs/unionfs/union.h
@@ -142,11 +142,18 @@ struct unionfs_sb_info {
* This rwsem is used to make sure that a branch management
* operation...
* 1) will not begin before all currently in-flight operations
- * complete
+ * complete.
* 2) any new operations do not execute until the currently
- * running branch management operation completes
+ * running branch management operation completes.
+ *
+ * The write_lock_owner records the PID of the task which grabbed
+ * the rw_sem for writing. If the same task also tries to grab the
+ * read lock, we allow it. This prevents a self-deadlock when
+ * branch-management is used on a pivot_root'ed union, because we
+ * have to ->lookup paths which belong to the same union.
*/
struct rw_semaphore rwsem;
+ pid_t write_lock_owner; /* PID of rw_sem owner (write lock) */
int high_branch_id; /* last unique branch ID given */
struct unionfs_data *data;
};
@@ -234,10 +241,30 @@ static inline off_t rdstate2offset(struct unionfs_dir_state *buf)
return tmp;
}
-#define unionfs_read_lock(sb) down_read(&UNIONFS_SB(sb)->rwsem)
-#define unionfs_read_unlock(sb) up_read(&UNIONFS_SB(sb)->rwsem)
-#define unionfs_write_lock(sb) down_write(&UNIONFS_SB(sb)->rwsem)
-#define unionfs_write_unlock(sb) up_write(&UNIONFS_SB(sb)->rwsem)
+static inline void unionfs_read_lock(struct super_block *sb)
+{
+ if (UNIONFS_SB(sb)->write_lock_owner &&
+ UNIONFS_SB(sb)->write_lock_owner == current->pid)
+ return;
+ down_read(&UNIONFS_SB(sb)->rwsem);
+}
+static inline void unionfs_read_unlock(struct super_block *sb)
+{
+ if (UNIONFS_SB(sb)->write_lock_owner &&
+ UNIONFS_SB(sb)->write_lock_owner == current->pid)
+ return;
+ up_read(&UNIONFS_SB(sb)->rwsem);
+}
+static inline void unionfs_write_lock(struct super_block *sb)
+{
+ down_write(&UNIONFS_SB(sb)->rwsem);
+ UNIONFS_SB(sb)->write_lock_owner = current->pid;
+}
+static inline void unionfs_write_unlock(struct super_block *sb)
+{
+ up_write(&UNIONFS_SB(sb)->rwsem);
+ UNIONFS_SB(sb)->write_lock_owner = 0;
+}
static inline void unionfs_double_lock_dentry(struct dentry *d1,
struct dentry *d2)
--
1.5.2.2
next prev parent reply other threads:[~2007-11-03 1:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-03 1:22 [GIT PULL -mm] 0/8 Unionfs updates/cleanups/fixes Erez Zadok
2007-11-03 1:22 ` [PATCH 1/8] Unionfs: delete whiteouts in sticky directories Erez Zadok
2007-11-03 1:22 ` [PATCH 2/8] Unionfs: cleanup permission checking code Erez Zadok
2007-11-03 1:22 ` [PATCH 3/8] Unionfs: update usage.txt documentation Erez Zadok
2007-11-03 1:22 ` [PATCH 4/8] Unionfs: mmap updates Erez Zadok
2007-11-03 1:22 ` Erez Zadok [this message]
2007-11-03 1:22 ` [PATCH 6/8] Unionfs: don't bother validating inode if it has no lower branches Erez Zadok
2007-11-03 1:22 ` [PATCH 7/8] Unionfs: don't printk an error if it's due to common copyup Erez Zadok
2007-11-03 1:22 ` [PATCH 8/8] Unionfs/VFS: no need to export 2 symbols in security/security.c Erez Zadok
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=11940529712183-git-send-email-ezk@cs.sunysb.edu \
--to=ezk@cs.sunysb.edu \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ftp.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).