aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Ma <boyu.mt@taobao.com>2011-10-31 17:30:44 -0400
committerTheodore Ts'o <tytso@mit.edu>2011-10-31 17:30:44 -0400
commit0edeb71dc9133bfb505d3bf59642e07cd936613e (patch)
treebcb68e2676d9bba1e4e4e28fb1ba8d382caf26eb
parentb82e384c7bb9a19036b4daf58fa216df7cd48aa0 (diff)
ext4: Create helper function for EXT4_IO_END_UNWRITTEN and i_aiodio_unwritten
EXT4_IO_END_UNWRITTEN flag set and the increase of i_aiodio_unwritten should be done simultaneously since ext4_end_io_nolock always clear the flag and decrease the counter in the same time. We have found some bugs that the flag is set while leaving i_aiodio_unwritten unchanged(commit 32c80b32c053d). So this patch just tries to create a helper function to wrap them to avoid any future bug. The idea is inspired by Eric. Cc: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Tao Ma <boyu.mt@taobao.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--fs/ext4/ext4.h9
-rw-r--r--fs/ext4/extents.c18
-rw-r--r--fs/ext4/inode.c5
-rw-r--r--fs/ext4/page-io.c6
4 files changed, 18 insertions, 20 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 657e82649fa5..604c200216c1 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1275,6 +1275,15 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
1275 ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); 1275 ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
1276} 1276}
1277 1277
1278static inline void ext4_set_io_unwritten_flag(struct inode *inode,
1279 struct ext4_io_end *io_end)
1280{
1281 if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
1282 io_end->flag |= EXT4_IO_END_UNWRITTEN;
1283 atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
1284 }
1285}
1286
1278/* 1287/*
1279 * Inode dynamic state flags 1288 * Inode dynamic state flags
1280 */ 1289 */
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 36a0f177ecad..a5c8caaaa099 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3472,12 +3472,9 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,
3472 * that this IO needs to conversion to written when IO is 3472 * that this IO needs to conversion to written when IO is
3473 * completed 3473 * completed
3474 */ 3474 */
3475 if (io) { 3475 if (io)
3476 if (!(io->flag & EXT4_IO_END_UNWRITTEN)) { 3476 ext4_set_io_unwritten_flag(inode, io);
3477 io->flag = EXT4_IO_END_UNWRITTEN; 3477 else
3478 atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
3479 }
3480 } else
3481 ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN); 3478 ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
3482 if (ext4_should_dioread_nolock(inode)) 3479 if (ext4_should_dioread_nolock(inode))
3483 map->m_flags |= EXT4_MAP_UNINIT; 3480 map->m_flags |= EXT4_MAP_UNINIT;
@@ -4030,12 +4027,9 @@ got_allocated_blocks:
4030 * that we need to perform conversion when IO is done. 4027 * that we need to perform conversion when IO is done.
4031 */ 4028 */
4032 if ((flags & EXT4_GET_BLOCKS_PRE_IO)) { 4029 if ((flags & EXT4_GET_BLOCKS_PRE_IO)) {
4033 if (io) { 4030 if (io)
4034 if (!(io->flag & EXT4_IO_END_UNWRITTEN)) { 4031 ext4_set_io_unwritten_flag(inode, io);
4035 io->flag = EXT4_IO_END_UNWRITTEN; 4032 else
4036 atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
4037 }
4038 } else
4039 ext4_set_inode_state(inode, 4033 ext4_set_inode_state(inode,
4040 EXT4_STATE_DIO_UNWRITTEN); 4034 EXT4_STATE_DIO_UNWRITTEN);
4041 } 4035 }
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e4b26faac5ff..60af5126eb05 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2831,10 +2831,7 @@ static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate)
2831 * but being more careful is always safe for the future change. 2831 * but being more careful is always safe for the future change.
2832 */ 2832 */
2833 inode = io_end->inode; 2833 inode = io_end->inode;
2834 if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 2834 ext4_set_io_unwritten_flag(inode, io_end);
2835 io_end->flag |= EXT4_IO_END_UNWRITTEN;
2836 atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
2837 }
2838 2835
2839 /* Add the io_end to per-inode completed io list*/ 2836 /* Add the io_end to per-inode completed io list*/
2840 spin_lock_irqsave(&EXT4_I(inode)->i_completed_io_lock, flags); 2837 spin_lock_irqsave(&EXT4_I(inode)->i_completed_io_lock, flags);
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 9eebf44646f6..7ce1d0b19c94 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -336,10 +336,8 @@ submit_and_retry:
336 if ((io_end->num_io_pages >= MAX_IO_PAGES) && 336 if ((io_end->num_io_pages >= MAX_IO_PAGES) &&
337 (io_end->pages[io_end->num_io_pages-1] != io_page)) 337 (io_end->pages[io_end->num_io_pages-1] != io_page))
338 goto submit_and_retry; 338 goto submit_and_retry;
339 if (buffer_uninit(bh) && !(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 339 if (buffer_uninit(bh))
340 io_end->flag |= EXT4_IO_END_UNWRITTEN; 340 ext4_set_io_unwritten_flag(inode, io_end);
341 atomic_inc(&EXT4_I(inode)->i_aiodio_unwritten);
342 }
343 io->io_end->size += bh->b_size; 341 io->io_end->size += bh->b_size;
344 io->io_next_block++; 342 io->io_next_block++;
345 ret = bio_add_page(io->io_bio, bh->b_page, bh->b_size, bh_offset(bh)); 343 ret = bio_add_page(io->io_bio, bh->b_page, bh->b_size, bh_offset(bh));