summaryrefslogtreecommitdiffstats
path: root/fs/ext4/page-io.c
diff options
context:
space:
mode:
authorTao Ma2011-10-30 23:26:08 +0100
committerTheodore Ts'o2011-10-30 23:26:08 +0100
commitd73d5046a72467d4510825b99e2269e09ad80e15 (patch)
tree4ac8b5729e1aeffe8348557a7f77da1791c268cc /fs/ext4/page-io.c
parentext4: fix race in xattr block allocation path (diff)
downloadkernel-qcow2-linux-d73d5046a72467d4510825b99e2269e09ad80e15.tar.gz
kernel-qcow2-linux-d73d5046a72467d4510825b99e2269e09ad80e15.tar.xz
kernel-qcow2-linux-d73d5046a72467d4510825b99e2269e09ad80e15.zip
ext4: Use correct locking for ext4_end_io_nolock()
We must hold i_completed_io_lock when manipulating anything on the i_completed_io_list linked list. This includes io->lock, which we were checking in ext4_end_io_nolock(). So move this check to ext4_end_io_work(). This also has the bonus of avoiding extra work if it is already done without needing to take the mutex. Signed-off-by: Tao Ma <boyu.mt@taobao.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/page-io.c')
-rw-r--r--fs/ext4/page-io.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 92f38ee13f8a..aed40966f342 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -87,6 +87,9 @@ void ext4_free_io_end(ext4_io_end_t *io)
/*
* check a range of space and convert unwritten extents to written.
+ *
+ * Called with inode->i_mutex; we depend on this when we manipulate
+ * io->flag, since we could otherwise race with ext4_flush_completed_IO()
*/
int ext4_end_io_nolock(ext4_io_end_t *io)
{
@@ -100,9 +103,6 @@ int ext4_end_io_nolock(ext4_io_end_t *io)
"list->prev 0x%p\n",
io, inode->i_ino, io->list.next, io->list.prev);
- if (list_empty(&io->list))
- return ret;
-
if (!(io->flag & EXT4_IO_END_UNWRITTEN))
return ret;
@@ -142,6 +142,13 @@ static void ext4_end_io_work(struct work_struct *work)
unsigned long flags;
int ret;
+ spin_lock_irqsave(&ei->i_completed_io_lock, flags);
+ if (list_empty(&io->list)) {
+ spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
+ goto free;
+ }
+ spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
+
if (!mutex_trylock(&inode->i_mutex)) {
/*
* Requeue the work instead of waiting so that the work
@@ -170,6 +177,7 @@ static void ext4_end_io_work(struct work_struct *work)
list_del_init(&io->list);
spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
mutex_unlock(&inode->i_mutex);
+free:
ext4_free_io_end(io);
}