Commit 8b0f165f authored by Anatol Pomozov's avatar Anatol Pomozov Committed by Theodore Ts'o

ext4: remove code duplication in ext4_get_block_write_nolock()

729f52c6 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: default avatarZheng Liu <wenqing.lz@taobao.com>
Signed-off-by: default avatarAnatol Pomozov <anatol.pomozov@gmail.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 8d8c1825
...@@ -683,7 +683,7 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, ...@@ -683,7 +683,7 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock,
map.m_lblk = iblock; map.m_lblk = iblock;
map.m_len = bh->b_size >> inode->i_blkbits; map.m_len = bh->b_size >> inode->i_blkbits;
if (flags && !handle) { if (flags && !(flags & EXT4_GET_BLOCKS_NO_LOCK) && !handle) {
/* Direct IO write... */ /* Direct IO write... */
if (map.m_len > DIO_MAX_BLOCKS) if (map.m_len > DIO_MAX_BLOCKS)
map.m_len = DIO_MAX_BLOCKS; map.m_len = DIO_MAX_BLOCKS;
...@@ -880,6 +880,8 @@ static int do_journal_get_write_access(handle_t *handle, ...@@ -880,6 +880,8 @@ static int do_journal_get_write_access(handle_t *handle,
static int ext4_get_block_write(struct inode *inode, sector_t iblock, static int ext4_get_block_write(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create); struct buffer_head *bh_result, int create);
static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create);
static int ext4_write_begin(struct file *file, struct address_space *mapping, static int ext4_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags, loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata) struct page **pagep, void **fsdata)
...@@ -2850,29 +2852,12 @@ static int ext4_get_block_write(struct inode *inode, sector_t iblock, ...@@ -2850,29 +2852,12 @@ static int ext4_get_block_write(struct inode *inode, sector_t iblock,
} }
static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock, static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int flags) struct buffer_head *bh_result, int create)
{ {
handle_t *handle = ext4_journal_current_handle(); ext4_debug("ext4_get_block_write_nolock: inode %lu, create flag %d\n",
struct ext4_map_blocks map; inode->i_ino, create);
int ret = 0; return _ext4_get_block(inode, iblock, bh_result,
EXT4_GET_BLOCKS_NO_LOCK);
ext4_debug("ext4_get_block_write_nolock: inode %lu, flag %d\n",
inode->i_ino, flags);
flags = EXT4_GET_BLOCKS_NO_LOCK;
map.m_lblk = iblock;
map.m_len = bh_result->b_size >> inode->i_blkbits;
ret = ext4_map_blocks(handle, inode, &map, flags);
if (ret > 0) {
map_bh(bh_result, inode->i_sb, map.m_pblk);
bh_result->b_state = (bh_result->b_state & ~EXT4_MAP_FLAGS) |
map.m_flags;
bh_result->b_size = inode->i_sb->s_blocksize * map.m_len;
ret = 0;
}
return ret;
} }
static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, 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,6 +2988,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
loff_t final_size = offset + count; loff_t final_size = offset + count;
if (rw == WRITE && final_size <= inode->i_size) { if (rw == WRITE && final_size <= inode->i_size) {
int overwrite = 0; int overwrite = 0;
get_block_t *get_block_func = NULL;
int dio_flags = 0;
BUG_ON(iocb->private == NULL); BUG_ON(iocb->private == NULL);
...@@ -3056,22 +3043,20 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, ...@@ -3056,22 +3043,20 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
ext4_inode_aio_set(inode, io_end); ext4_inode_aio_set(inode, io_end);
} }
if (overwrite) if (overwrite) {
ret = __blockdev_direct_IO(rw, iocb, inode, get_block_func = ext4_get_block_write_nolock;
inode->i_sb->s_bdev, iov, } else {
offset, nr_segs, get_block_func = ext4_get_block_write;
ext4_get_block_write_nolock, dio_flags = DIO_LOCKING;
ext4_end_io_dio, }
NULL,
0);
else
ret = __blockdev_direct_IO(rw, iocb, inode, ret = __blockdev_direct_IO(rw, iocb, inode,
inode->i_sb->s_bdev, iov, inode->i_sb->s_bdev, iov,
offset, nr_segs, offset, nr_segs,
ext4_get_block_write, get_block_func,
ext4_end_io_dio, ext4_end_io_dio,
NULL, NULL,
DIO_LOCKING); dio_flags);
if (iocb->private) if (iocb->private)
ext4_inode_aio_set(inode, NULL); ext4_inode_aio_set(inode, NULL);
/* /*
......
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