aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/ext4.h4
-rw-r--r--fs/ext4/file.c33
-rw-r--r--fs/ext4/indirect.c25
-rw-r--r--fs/ext4/inode.c28
4 files changed, 46 insertions, 44 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 8a3981ea35d8..c8eb32eefc3c 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2152,8 +2152,8 @@ extern void ext4_da_update_reserve_space(struct inode *inode,
2152/* indirect.c */ 2152/* indirect.c */
2153extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode, 2153extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
2154 struct ext4_map_blocks *map, int flags); 2154 struct ext4_map_blocks *map, int flags);
2155extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, 2155extern ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
2156 struct iov_iter *iter, loff_t offset); 2156 loff_t offset);
2157extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock); 2157extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
2158extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks); 2158extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
2159extern void ext4_ind_truncate(handle_t *, struct inode *inode); 2159extern void ext4_ind_truncate(handle_t *, struct inode *inode);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 7a6defcf3352..e576d682b353 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -95,11 +95,9 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
95 struct inode *inode = file_inode(iocb->ki_filp); 95 struct inode *inode = file_inode(iocb->ki_filp);
96 struct mutex *aio_mutex = NULL; 96 struct mutex *aio_mutex = NULL;
97 struct blk_plug plug; 97 struct blk_plug plug;
98 int o_direct = io_is_direct(file); 98 int o_direct = iocb->ki_flags & IOCB_DIRECT;
99 int overwrite = 0; 99 int overwrite = 0;
100 size_t length = iov_iter_count(from);
101 ssize_t ret; 100 ssize_t ret;
102 loff_t pos = iocb->ki_pos;
103 101
104 /* 102 /*
105 * Unaligned direct AIO must be serialized; see comment above 103 * Unaligned direct AIO must be serialized; see comment above
@@ -108,16 +106,17 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
108 if (o_direct && 106 if (o_direct &&
109 ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) && 107 ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
110 !is_sync_kiocb(iocb) && 108 !is_sync_kiocb(iocb) &&
111 (file->f_flags & O_APPEND || 109 (iocb->ki_flags & IOCB_APPEND ||
112 ext4_unaligned_aio(inode, from, pos))) { 110 ext4_unaligned_aio(inode, from, iocb->ki_pos))) {
113 aio_mutex = ext4_aio_mutex(inode); 111 aio_mutex = ext4_aio_mutex(inode);
114 mutex_lock(aio_mutex); 112 mutex_lock(aio_mutex);
115 ext4_unwritten_wait(inode); 113 ext4_unwritten_wait(inode);
116 } 114 }
117 115
118 mutex_lock(&inode->i_mutex); 116 mutex_lock(&inode->i_mutex);
119 if (file->f_flags & O_APPEND) 117 ret = generic_write_checks(iocb, from);
120 iocb->ki_pos = pos = i_size_read(inode); 118 if (ret <= 0)
119 goto out;
121 120
122 /* 121 /*
123 * If we have encountered a bitmap-format file, the size limit 122 * If we have encountered a bitmap-format file, the size limit
@@ -126,22 +125,19 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
126 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { 125 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
127 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 126 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
128 127
129 if ((pos > sbi->s_bitmap_maxbytes) || 128 if (iocb->ki_pos >= sbi->s_bitmap_maxbytes) {
130 (pos == sbi->s_bitmap_maxbytes && length > 0)) {
131 mutex_unlock(&inode->i_mutex);
132 ret = -EFBIG; 129 ret = -EFBIG;
133 goto errout; 130 goto out;
134 } 131 }
135 132 iov_iter_truncate(from, sbi->s_bitmap_maxbytes - iocb->ki_pos);
136 if (pos + length > sbi->s_bitmap_maxbytes)
137 iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos);
138 } 133 }
139 134
140 iocb->private = &overwrite; 135 iocb->private = &overwrite;
141 if (o_direct) { 136 if (o_direct) {
137 size_t length = iov_iter_count(from);
138 loff_t pos = iocb->ki_pos;
142 blk_start_plug(&plug); 139 blk_start_plug(&plug);
143 140
144
145 /* check whether we do a DIO overwrite or not */ 141 /* check whether we do a DIO overwrite or not */
146 if (ext4_should_dioread_nolock(inode) && !aio_mutex && 142 if (ext4_should_dioread_nolock(inode) && !aio_mutex &&
147 !file->f_mapping->nrpages && pos + length <= i_size_read(inode)) { 143 !file->f_mapping->nrpages && pos + length <= i_size_read(inode)) {
@@ -185,7 +181,12 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
185 if (o_direct) 181 if (o_direct)
186 blk_finish_plug(&plug); 182 blk_finish_plug(&plug);
187 183
188errout: 184 if (aio_mutex)
185 mutex_unlock(aio_mutex);
186 return ret;
187
188out:
189 mutex_unlock(&inode->i_mutex);
189 if (aio_mutex) 190 if (aio_mutex)
190 mutex_unlock(aio_mutex); 191 mutex_unlock(aio_mutex);
191 return ret; 192 return ret;
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index 740c7871c117..3580629e42d3 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -642,8 +642,8 @@ out:
642 * crashes then stale disk data _may_ be exposed inside the file. But current 642 * crashes then stale disk data _may_ be exposed inside the file. But current
643 * VFS code falls back into buffered path in that case so we are safe. 643 * VFS code falls back into buffered path in that case so we are safe.
644 */ 644 */
645ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, 645ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
646 struct iov_iter *iter, loff_t offset) 646 loff_t offset)
647{ 647{
648 struct file *file = iocb->ki_filp; 648 struct file *file = iocb->ki_filp;
649 struct inode *inode = file->f_mapping->host; 649 struct inode *inode = file->f_mapping->host;
@@ -654,7 +654,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
654 size_t count = iov_iter_count(iter); 654 size_t count = iov_iter_count(iter);
655 int retries = 0; 655 int retries = 0;
656 656
657 if (rw == WRITE) { 657 if (iov_iter_rw(iter) == WRITE) {
658 loff_t final_size = offset + count; 658 loff_t final_size = offset + count;
659 659
660 if (final_size > inode->i_size) { 660 if (final_size > inode->i_size) {
@@ -676,7 +676,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
676 } 676 }
677 677
678retry: 678retry:
679 if (rw == READ && ext4_should_dioread_nolock(inode)) { 679 if (iov_iter_rw(iter) == READ && ext4_should_dioread_nolock(inode)) {
680 /* 680 /*
681 * Nolock dioread optimization may be dynamically disabled 681 * Nolock dioread optimization may be dynamically disabled
682 * via ext4_inode_block_unlocked_dio(). Check inode's state 682 * via ext4_inode_block_unlocked_dio(). Check inode's state
@@ -690,23 +690,24 @@ retry:
690 goto locked; 690 goto locked;
691 } 691 }
692 if (IS_DAX(inode)) 692 if (IS_DAX(inode))
693 ret = dax_do_io(rw, iocb, inode, iter, offset, 693 ret = dax_do_io(iocb, inode, iter, offset,
694 ext4_get_block, NULL, 0); 694 ext4_get_block, NULL, 0);
695 else 695 else
696 ret = __blockdev_direct_IO(rw, iocb, inode, 696 ret = __blockdev_direct_IO(iocb, inode,
697 inode->i_sb->s_bdev, iter, offset, 697 inode->i_sb->s_bdev, iter,
698 ext4_get_block, NULL, NULL, 0); 698 offset, ext4_get_block, NULL,
699 NULL, 0);
699 inode_dio_done(inode); 700 inode_dio_done(inode);
700 } else { 701 } else {
701locked: 702locked:
702 if (IS_DAX(inode)) 703 if (IS_DAX(inode))
703 ret = dax_do_io(rw, iocb, inode, iter, offset, 704 ret = dax_do_io(iocb, inode, iter, offset,
704 ext4_get_block, NULL, DIO_LOCKING); 705 ext4_get_block, NULL, DIO_LOCKING);
705 else 706 else
706 ret = blockdev_direct_IO(rw, iocb, inode, iter, 707 ret = blockdev_direct_IO(iocb, inode, iter, offset,
707 offset, ext4_get_block); 708 ext4_get_block);
708 709
709 if (unlikely((rw & WRITE) && ret < 0)) { 710 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
710 loff_t isize = i_size_read(inode); 711 loff_t isize = i_size_read(inode);
711 loff_t end = offset + count; 712 loff_t end = offset + count;
712 713
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 035b7a06f1c3..b49cf6e59953 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2952,8 +2952,8 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
2952 * if the machine crashes during the write. 2952 * if the machine crashes during the write.
2953 * 2953 *
2954 */ 2954 */
2955static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, 2955static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
2956 struct iov_iter *iter, loff_t offset) 2956 loff_t offset)
2957{ 2957{
2958 struct file *file = iocb->ki_filp; 2958 struct file *file = iocb->ki_filp;
2959 struct inode *inode = file->f_mapping->host; 2959 struct inode *inode = file->f_mapping->host;
@@ -2966,8 +2966,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
2966 ext4_io_end_t *io_end = NULL; 2966 ext4_io_end_t *io_end = NULL;
2967 2967
2968 /* Use the old path for reads and writes beyond i_size. */ 2968 /* Use the old path for reads and writes beyond i_size. */
2969 if (rw != WRITE || final_size > inode->i_size) 2969 if (iov_iter_rw(iter) != WRITE || final_size > inode->i_size)
2970 return ext4_ind_direct_IO(rw, iocb, iter, offset); 2970 return ext4_ind_direct_IO(iocb, iter, offset);
2971 2971
2972 BUG_ON(iocb->private == NULL); 2972 BUG_ON(iocb->private == NULL);
2973 2973
@@ -2976,7 +2976,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
2976 * conversion. This also disallows race between truncate() and 2976 * conversion. This also disallows race between truncate() and
2977 * overwrite DIO as i_dio_count needs to be incremented under i_mutex. 2977 * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
2978 */ 2978 */
2979 if (rw == WRITE) 2979 if (iov_iter_rw(iter) == WRITE)
2980 atomic_inc(&inode->i_dio_count); 2980 atomic_inc(&inode->i_dio_count);
2981 2981
2982 /* If we do a overwrite dio, i_mutex locking can be released */ 2982 /* If we do a overwrite dio, i_mutex locking can be released */
@@ -3034,10 +3034,10 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
3034 dio_flags = DIO_LOCKING; 3034 dio_flags = DIO_LOCKING;
3035 } 3035 }
3036 if (IS_DAX(inode)) 3036 if (IS_DAX(inode))
3037 ret = dax_do_io(rw, iocb, inode, iter, offset, get_block_func, 3037 ret = dax_do_io(iocb, inode, iter, offset, get_block_func,
3038 ext4_end_io_dio, dio_flags); 3038 ext4_end_io_dio, dio_flags);
3039 else 3039 else
3040 ret = __blockdev_direct_IO(rw, iocb, inode, 3040 ret = __blockdev_direct_IO(iocb, inode,
3041 inode->i_sb->s_bdev, iter, offset, 3041 inode->i_sb->s_bdev, iter, offset,
3042 get_block_func, 3042 get_block_func,
3043 ext4_end_io_dio, NULL, dio_flags); 3043 ext4_end_io_dio, NULL, dio_flags);
@@ -3078,7 +3078,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
3078 } 3078 }
3079 3079
3080retake_lock: 3080retake_lock:
3081 if (rw == WRITE) 3081 if (iov_iter_rw(iter) == WRITE)
3082 inode_dio_done(inode); 3082 inode_dio_done(inode);
3083 /* take i_mutex locking again if we do a ovewrite dio */ 3083 /* take i_mutex locking again if we do a ovewrite dio */
3084 if (overwrite) { 3084 if (overwrite) {
@@ -3089,8 +3089,8 @@ retake_lock:
3089 return ret; 3089 return ret;
3090} 3090}
3091 3091
3092static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, 3092static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
3093 struct iov_iter *iter, loff_t offset) 3093 loff_t offset)
3094{ 3094{
3095 struct file *file = iocb->ki_filp; 3095 struct file *file = iocb->ki_filp;
3096 struct inode *inode = file->f_mapping->host; 3096 struct inode *inode = file->f_mapping->host;
@@ -3107,12 +3107,12 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
3107 if (ext4_has_inline_data(inode)) 3107 if (ext4_has_inline_data(inode))
3108 return 0; 3108 return 0;
3109 3109
3110 trace_ext4_direct_IO_enter(inode, offset, count, rw); 3110 trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
3111 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) 3111 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
3112 ret = ext4_ext_direct_IO(rw, iocb, iter, offset); 3112 ret = ext4_ext_direct_IO(iocb, iter, offset);
3113 else 3113 else
3114 ret = ext4_ind_direct_IO(rw, iocb, iter, offset); 3114 ret = ext4_ind_direct_IO(iocb, iter, offset);
3115 trace_ext4_direct_IO_exit(inode, offset, count, rw, ret); 3115 trace_ext4_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
3116 return ret; 3116 return ret;
3117} 3117}
3118 3118