Commit d19de7ed authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

writeback: fix writeback_inodes_wb from writeback_inodes_sb

When we call writeback_inodes_wb from writeback_inodes_sb we always have
s_umount held, which currently makes the whole operation a no-op.

But if we are called to write out inodes for a specific superblock we always
have s_umount held, so replace the incorrect logic checking for WB_SYNC_ALL
which only worked by coincidence with the proper check for an explicit
superblock argument.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <jaxboe@fusionio.com>
parent cf37e972
...@@ -518,39 +518,19 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc) ...@@ -518,39 +518,19 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
return ret; return ret;
} }
static void unpin_sb_for_writeback(struct super_block *sb)
{
up_read(&sb->s_umount);
put_super(sb);
}
enum sb_pin_state {
SB_PINNED,
SB_NOT_PINNED,
SB_PIN_FAILED
};
/* /*
* For WB_SYNC_NONE writeback, the caller does not have the sb pinned * For background writeback the caller does not have the sb pinned
* before calling writeback. So make sure that we do pin it, so it doesn't * before calling writeback. So make sure that we do pin it, so it doesn't
* go away while we are writing inodes from it. * go away while we are writing inodes from it.
*/ */
static enum sb_pin_state pin_sb_for_writeback(struct writeback_control *wbc, static bool pin_sb_for_writeback(struct super_block *sb)
struct super_block *sb)
{ {
/*
* Caller must already hold the ref for this
*/
if (wbc->sync_mode == WB_SYNC_ALL) {
WARN_ON(!rwsem_is_locked(&sb->s_umount));
return SB_NOT_PINNED;
}
spin_lock(&sb_lock); spin_lock(&sb_lock);
sb->s_count++; sb->s_count++;
if (down_read_trylock(&sb->s_umount)) { if (down_read_trylock(&sb->s_umount)) {
if (sb->s_root) { if (sb->s_root) {
spin_unlock(&sb_lock); spin_unlock(&sb_lock);
return SB_PINNED; return true;
} }
/* /*
* umounted, drop rwsem again and fall through to failure * umounted, drop rwsem again and fall through to failure
...@@ -559,7 +539,7 @@ static enum sb_pin_state pin_sb_for_writeback(struct writeback_control *wbc, ...@@ -559,7 +539,7 @@ static enum sb_pin_state pin_sb_for_writeback(struct writeback_control *wbc,
} }
sb->s_count--; sb->s_count--;
spin_unlock(&sb_lock); spin_unlock(&sb_lock);
return SB_PIN_FAILED; return false;
} }
/* /*
...@@ -638,24 +618,29 @@ static void writeback_inodes_wb(struct bdi_writeback *wb, ...@@ -638,24 +618,29 @@ static void writeback_inodes_wb(struct bdi_writeback *wb,
struct inode *inode = list_entry(wb->b_io.prev, struct inode *inode = list_entry(wb->b_io.prev,
struct inode, i_list); struct inode, i_list);
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
enum sb_pin_state state;
if (wbc->sb && sb != wbc->sb) { if (wbc->sb) {
/* super block given and doesn't /*
match, skip this inode */ * We are requested to write out inodes for a specific
* superblock. This means we already have s_umount
* taken by the caller which also waits for us to
* complete the writeout.
*/
if (sb != wbc->sb) {
redirty_tail(inode); redirty_tail(inode);
continue; continue;
} }
state = pin_sb_for_writeback(wbc, sb);
if (state == SB_PIN_FAILED) { WARN_ON(!rwsem_is_locked(&sb->s_umount));
requeue_io(inode);
ret = writeback_sb_inodes(sb, wb, wbc);
} else {
if (!pin_sb_for_writeback(sb))
continue; continue;
}
ret = writeback_sb_inodes(sb, wb, wbc); ret = writeback_sb_inodes(sb, wb, wbc);
drop_super(sb);
}
if (state == SB_PINNED)
unpin_sb_for_writeback(sb);
if (ret) if (ret)
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment