diff options
author | Anatol Pomozov <anatol.pomozov@gmail.com> | 2012-11-08 15:07:16 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2012-11-08 15:07:16 -0500 |
commit | 8b0f165f790c897fa744e7fed6f0bfeb6eb6f494 (patch) | |
tree | 6cc2fff4f731b93103184d3ef858b8a0f48310c6 /fs/ext4/inode.c | |
parent | 8d8c1825709020c73b5e66f96c114f6a1f6461e7 (diff) |
ext4: remove code duplication in ext4_get_block_write_nolock()
729f52c6be51013 introduced function ext4_get_block_write_nolock() that
is very similar to _ext4_get_block(). Eliminate code duplication
by passing different flags to _ext4_get_block()
Tested: xfs tests
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 63 |
1 files changed, 24 insertions, 39 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b3c243b9afa5..f84bfd6d1867 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -683,7 +683,7 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, | |||
683 | map.m_lblk = iblock; | 683 | map.m_lblk = iblock; |
684 | map.m_len = bh->b_size >> inode->i_blkbits; | 684 | map.m_len = bh->b_size >> inode->i_blkbits; |
685 | 685 | ||
686 | if (flags && !handle) { | 686 | if (flags && !(flags & EXT4_GET_BLOCKS_NO_LOCK) && !handle) { |
687 | /* Direct IO write... */ | 687 | /* Direct IO write... */ |
688 | if (map.m_len > DIO_MAX_BLOCKS) | 688 | if (map.m_len > DIO_MAX_BLOCKS) |
689 | map.m_len = DIO_MAX_BLOCKS; | 689 | map.m_len = DIO_MAX_BLOCKS; |
@@ -880,6 +880,8 @@ static int do_journal_get_write_access(handle_t *handle, | |||
880 | 880 | ||
881 | static int ext4_get_block_write(struct inode *inode, sector_t iblock, | 881 | static int ext4_get_block_write(struct inode *inode, sector_t iblock, |
882 | struct buffer_head *bh_result, int create); | 882 | struct buffer_head *bh_result, int create); |
883 | static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock, | ||
884 | struct buffer_head *bh_result, int create); | ||
883 | static int ext4_write_begin(struct file *file, struct address_space *mapping, | 885 | static int ext4_write_begin(struct file *file, struct address_space *mapping, |
884 | loff_t pos, unsigned len, unsigned flags, | 886 | loff_t pos, unsigned len, unsigned flags, |
885 | struct page **pagep, void **fsdata) | 887 | struct page **pagep, void **fsdata) |
@@ -2850,29 +2852,12 @@ static int ext4_get_block_write(struct inode *inode, sector_t iblock, | |||
2850 | } | 2852 | } |
2851 | 2853 | ||
2852 | static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock, | 2854 | static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock, |
2853 | struct buffer_head *bh_result, int flags) | 2855 | struct buffer_head *bh_result, int create) |
2854 | { | 2856 | { |
2855 | handle_t *handle = ext4_journal_current_handle(); | 2857 | ext4_debug("ext4_get_block_write_nolock: inode %lu, create flag %d\n", |
2856 | struct ext4_map_blocks map; | 2858 | inode->i_ino, create); |
2857 | int ret = 0; | 2859 | return _ext4_get_block(inode, iblock, bh_result, |
2858 | 2860 | EXT4_GET_BLOCKS_NO_LOCK); | |
2859 | ext4_debug("ext4_get_block_write_nolock: inode %lu, flag %d\n", | ||
2860 | inode->i_ino, flags); | ||
2861 | |||
2862 | flags = EXT4_GET_BLOCKS_NO_LOCK; | ||
2863 | |||
2864 | map.m_lblk = iblock; | ||
2865 | map.m_len = bh_result->b_size >> inode->i_blkbits; | ||
2866 | |||
2867 | ret = ext4_map_blocks(handle, inode, &map, flags); | ||
2868 | if (ret > 0) { | ||
2869 | map_bh(bh_result, inode->i_sb, map.m_pblk); | ||
2870 | bh_result->b_state = (bh_result->b_state & ~EXT4_MAP_FLAGS) | | ||
2871 | map.m_flags; | ||
2872 | bh_result->b_size = inode->i_sb->s_blocksize * map.m_len; | ||
2873 | ret = 0; | ||
2874 | } | ||
2875 | return ret; | ||
2876 | } | 2861 | } |
2877 | 2862 | ||
2878 | static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, | 2863 | static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, |
@@ -3003,6 +2988,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3003 | loff_t final_size = offset + count; | 2988 | loff_t final_size = offset + count; |
3004 | if (rw == WRITE && final_size <= inode->i_size) { | 2989 | if (rw == WRITE && final_size <= inode->i_size) { |
3005 | int overwrite = 0; | 2990 | int overwrite = 0; |
2991 | get_block_t *get_block_func = NULL; | ||
2992 | int dio_flags = 0; | ||
3006 | 2993 | ||
3007 | BUG_ON(iocb->private == NULL); | 2994 | BUG_ON(iocb->private == NULL); |
3008 | 2995 | ||
@@ -3056,22 +3043,20 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3056 | ext4_inode_aio_set(inode, io_end); | 3043 | ext4_inode_aio_set(inode, io_end); |
3057 | } | 3044 | } |
3058 | 3045 | ||
3059 | if (overwrite) | 3046 | if (overwrite) { |
3060 | ret = __blockdev_direct_IO(rw, iocb, inode, | 3047 | get_block_func = ext4_get_block_write_nolock; |
3061 | inode->i_sb->s_bdev, iov, | 3048 | } else { |
3062 | offset, nr_segs, | 3049 | get_block_func = ext4_get_block_write; |
3063 | ext4_get_block_write_nolock, | 3050 | dio_flags = DIO_LOCKING; |
3064 | ext4_end_io_dio, | 3051 | } |
3065 | NULL, | 3052 | ret = __blockdev_direct_IO(rw, iocb, inode, |
3066 | 0); | 3053 | inode->i_sb->s_bdev, iov, |
3067 | else | 3054 | offset, nr_segs, |
3068 | ret = __blockdev_direct_IO(rw, iocb, inode, | 3055 | get_block_func, |
3069 | inode->i_sb->s_bdev, iov, | 3056 | ext4_end_io_dio, |
3070 | offset, nr_segs, | 3057 | NULL, |
3071 | ext4_get_block_write, | 3058 | dio_flags); |
3072 | ext4_end_io_dio, | 3059 | |
3073 | NULL, | ||
3074 | DIO_LOCKING); | ||
3075 | if (iocb->private) | 3060 | if (iocb->private) |
3076 | ext4_inode_aio_set(inode, NULL); | 3061 | ext4_inode_aio_set(inode, NULL); |
3077 | /* | 3062 | /* |