nilfs2: fix circular locking dependency of writer mutex
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Tue, 28 Apr 2009 12:04:59 +0000 (21:04 +0900)
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Sat, 9 May 2009 04:36:57 +0000 (13:36 +0900)
This fixes the following circular locking dependency problem:

 =======================================================
 [ INFO: possible circular locking dependency detected ]
 2.6.30-rc3 #5
 -------------------------------------------------------
 segctord/3895 is trying to acquire lock:
  (&nilfs->ns_writer_mutex){+.+...}, at: [<d0d02172>]
   nilfs_mdt_get_block+0x89/0x20f [nilfs2]

 but task is already holding lock:
  (&bmap->b_sem){++++..}, at: [<d0d02d99>]
   nilfs_bmap_propagate+0x14/0x2e [nilfs2]

 which lock already depends on the new lock.

The bugfix is done by replacing call sites of nilfs_get_writer() which
are never called from read-only context with direct dereferencing of
pointer to a writable FS-instance.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
fs/nilfs2/ioctl.c
fs/nilfs2/mdt.c

index 108d281ebca5b98bd1cdc53adb41066d2feead7f..be387c6b2d467d461f7f49000c15574ada625957 100644 (file)
@@ -516,14 +516,16 @@ static ssize_t
 nilfs_ioctl_do_free_segments(struct the_nilfs *nilfs, __u64 *posp, int flags,
                             void *buf, size_t size, size_t nmembs)
 {
-       struct nilfs_sb_info *sbi = nilfs_get_writer(nilfs);
+       struct nilfs_sb_info *sbi = nilfs->ns_writer;
        int ret;
 
-       if (unlikely(!sbi))
+       if (unlikely(!sbi)) {
+               /* never happens because called for a writable mount */
+               WARN_ON(1);
                return -EROFS;
+       }
        ret = nilfs_segctor_add_segments_to_be_freed(
                NILFS_SC(sbi), buf, nmembs);
-       nilfs_put_writer(nilfs);
 
        return (ret < 0) ? ret : nmembs;
 }
index 47dd815433fd4df6b5e484b3b52cbc6a0cc5294f..e1c6777931b714140aa50f96925769a48c499ecb 100644 (file)
@@ -77,19 +77,22 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
                                                     void *))
 {
        struct the_nilfs *nilfs = NILFS_MDT(inode)->mi_nilfs;
-       struct nilfs_sb_info *writer = NULL;
        struct super_block *sb = inode->i_sb;
        struct nilfs_transaction_info ti;
        struct buffer_head *bh;
        int err;
 
        if (!sb) {
-               writer = nilfs_get_writer(nilfs);
-               if (!writer) {
+               /*
+                * Make sure this function is not called from any
+                * read-only context.
+                */
+               if (!nilfs->ns_writer) {
+                       WARN_ON(1);
                        err = -EROFS;
                        goto out;
                }
-               sb = writer->s_super;
+               sb = nilfs->ns_writer->s_super;
        }
 
        nilfs_transaction_begin(sb, &ti, 0);
@@ -127,8 +130,6 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
                err = nilfs_transaction_commit(sb);
        else
                nilfs_transaction_abort(sb);
-       if (writer)
-               nilfs_put_writer(nilfs);
  out:
        return err;
 }