Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ad2850f authored by Theodore Ts'o's avatar Theodore Ts'o
Browse files

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: default avatar"Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
parent 7608e610
Loading
Loading
Loading
Loading
+64 −74
Original line number Diff line number Diff line
@@ -92,20 +92,42 @@ ext4_unaligned_aio(struct inode *inode, const struct iovec *iov,
}

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)
{
	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;
	int unaligned_aio = 0;
	ssize_t ret;
	int overwrite = 0;
	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) &&
		    !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 */
		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==len' means that all of blocks has been preallocated no
		 * matter they are initialized or not.  For excluding
		 * unwritten extents, we need to check m_flags.  There are
		 * two conditions that indicate for initialized extents.
		 * 1) If we 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.
			 * 'err==len' means that all of blocks has
			 * been preallocated no matter they are
			 * initialized or not.  For excluding
			 * unwritten extents, we need to check
			 * m_flags.  There are two conditions that
			 * indicate for initialized extents.  1) If we
			 * 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))
				overwrite = 1;
@@ -158,42 +183,7 @@ ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,

		if (unaligned_aio)
			mutex_unlock(ext4_aio_mutex(inode));

	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 {
	} else {
		mutex_lock(&inode->i_mutex);
		ret = __generic_file_aio_write(iocb, iov, nr_segs);
		mutex_unlock(&inode->i_mutex);