ext4: move ext4_file_dio_write() into ext4_file_write()
This commit doesn't actually change anything; it just moves code around in preparation for some code simplification work. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reviewed-by: Jan Kara <jack@suse.cz>
This commit is contained in:
@@ -92,20 +92,42 @@ ext4_unaligned_aio(struct inode *inode, const struct iovec *iov,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,
|
ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
|
||||||
unsigned long nr_segs, loff_t pos)
|
unsigned long nr_segs, loff_t pos)
|
||||||
{
|
{
|
||||||
struct file *file = iocb->ki_filp;
|
struct file *file = iocb->ki_filp;
|
||||||
struct inode *inode = file->f_mapping->host;
|
struct inode *inode = file_inode(iocb->ki_filp);
|
||||||
struct blk_plug plug;
|
struct blk_plug plug;
|
||||||
int unaligned_aio = 0;
|
int unaligned_aio = 0;
|
||||||
ssize_t ret;
|
|
||||||
int overwrite = 0;
|
int overwrite = 0;
|
||||||
size_t length = iov_length(iov, nr_segs);
|
size_t length = iov_length(iov, nr_segs);
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
BUG_ON(iocb->ki_pos != pos);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we have encountered a bitmap-format file, the size limit
|
||||||
|
* is smaller than s_maxbytes, which is for extent-mapped files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
|
||||||
|
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
|
||||||
|
|
||||||
|
if ((pos > sbi->s_bitmap_maxbytes ||
|
||||||
|
(pos == sbi->s_bitmap_maxbytes && length > 0)))
|
||||||
|
return -EFBIG;
|
||||||
|
|
||||||
|
if (pos + length > sbi->s_bitmap_maxbytes) {
|
||||||
|
nr_segs = iov_shorten((struct iovec *)iov, nr_segs,
|
||||||
|
sbi->s_bitmap_maxbytes - pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlikely(iocb->ki_filp->f_flags & O_DIRECT)) {
|
||||||
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
|
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
|
||||||
!is_sync_kiocb(iocb))
|
!is_sync_kiocb(iocb))
|
||||||
unaligned_aio = ext4_unaligned_aio(inode, iov, nr_segs, pos);
|
unaligned_aio = ext4_unaligned_aio(inode, iov,
|
||||||
|
nr_segs, pos);
|
||||||
|
|
||||||
/* Unaligned direct AIO must be serialized; see comment above */
|
/* Unaligned direct AIO must be serialized; see comment above */
|
||||||
if (unaligned_aio) {
|
if (unaligned_aio) {
|
||||||
@@ -132,13 +154,16 @@ ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,
|
|||||||
|
|
||||||
err = ext4_map_blocks(NULL, inode, &map, 0);
|
err = ext4_map_blocks(NULL, inode, &map, 0);
|
||||||
/*
|
/*
|
||||||
* 'err==len' means that all of blocks has been preallocated no
|
* 'err==len' means that all of blocks has
|
||||||
* matter they are initialized or not. For excluding
|
* been preallocated no matter they are
|
||||||
* unwritten extents, we need to check m_flags. There are
|
* initialized or not. For excluding
|
||||||
* two conditions that indicate for initialized extents.
|
* unwritten extents, we need to check
|
||||||
* 1) If we hit extent cache, EXT4_MAP_MAPPED flag is returned;
|
* m_flags. There are two conditions that
|
||||||
* 2) If we do a real lookup, non-flags are returned.
|
* indicate for initialized extents. 1) If we
|
||||||
* So we should check these two conditions.
|
* hit extent cache, EXT4_MAP_MAPPED flag is
|
||||||
|
* returned; 2) If we do a real lookup,
|
||||||
|
* non-flags are returned. So we should check
|
||||||
|
* these two conditions.
|
||||||
*/
|
*/
|
||||||
if (err == len && (map.m_flags & EXT4_MAP_MAPPED))
|
if (err == len && (map.m_flags & EXT4_MAP_MAPPED))
|
||||||
overwrite = 1;
|
overwrite = 1;
|
||||||
@@ -158,42 +183,7 @@ ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,
|
|||||||
|
|
||||||
if (unaligned_aio)
|
if (unaligned_aio)
|
||||||
mutex_unlock(ext4_aio_mutex(inode));
|
mutex_unlock(ext4_aio_mutex(inode));
|
||||||
|
} else {
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t
|
|
||||||
ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
|
|
||||||
unsigned long nr_segs, loff_t pos)
|
|
||||||
{
|
|
||||||
struct file *file = iocb->ki_filp;
|
|
||||||
struct inode *inode = file_inode(iocb->ki_filp);
|
|
||||||
ssize_t ret;
|
|
||||||
|
|
||||||
BUG_ON(iocb->ki_pos != pos);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If we have encountered a bitmap-format file, the size limit
|
|
||||||
* is smaller than s_maxbytes, which is for extent-mapped files.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
|
|
||||||
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
|
|
||||||
size_t length = iov_length(iov, nr_segs);
|
|
||||||
|
|
||||||
if ((pos > sbi->s_bitmap_maxbytes ||
|
|
||||||
(pos == sbi->s_bitmap_maxbytes && length > 0)))
|
|
||||||
return -EFBIG;
|
|
||||||
|
|
||||||
if (pos + length > sbi->s_bitmap_maxbytes) {
|
|
||||||
nr_segs = iov_shorten((struct iovec *)iov, nr_segs,
|
|
||||||
sbi->s_bitmap_maxbytes - pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unlikely(iocb->ki_filp->f_flags & O_DIRECT))
|
|
||||||
ret = ext4_file_dio_write(iocb, iov, nr_segs, pos);
|
|
||||||
else {
|
|
||||||
mutex_lock(&inode->i_mutex);
|
mutex_lock(&inode->i_mutex);
|
||||||
ret = __generic_file_aio_write(iocb, iov, nr_segs);
|
ret = __generic_file_aio_write(iocb, iov, nr_segs);
|
||||||
mutex_unlock(&inode->i_mutex);
|
mutex_unlock(&inode->i_mutex);
|
||||||
|
Reference in New Issue
Block a user