|
@@ -93,31 +93,29 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|
|
{
|
|
|
struct file *file = iocb->ki_filp;
|
|
|
struct inode *inode = file_inode(iocb->ki_filp);
|
|
|
- struct mutex *aio_mutex = NULL;
|
|
|
struct blk_plug plug;
|
|
|
int o_direct = iocb->ki_flags & IOCB_DIRECT;
|
|
|
+ int unaligned_aio = 0;
|
|
|
int overwrite = 0;
|
|
|
ssize_t ret;
|
|
|
|
|
|
+ inode_lock(inode);
|
|
|
+ ret = generic_write_checks(iocb, from);
|
|
|
+ if (ret <= 0)
|
|
|
+ goto out;
|
|
|
+
|
|
|
/*
|
|
|
- * Unaligned direct AIO must be serialized; see comment above
|
|
|
- * In the case of O_APPEND, assume that we must always serialize
|
|
|
+ * Unaligned direct AIO must be serialized among each other as zeroing
|
|
|
+ * of partial blocks of two competing unaligned AIOs can result in data
|
|
|
+ * corruption.
|
|
|
*/
|
|
|
- if (o_direct &&
|
|
|
- ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
|
|
|
+ if (o_direct && ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
|
|
|
!is_sync_kiocb(iocb) &&
|
|
|
- (iocb->ki_flags & IOCB_APPEND ||
|
|
|
- ext4_unaligned_aio(inode, from, iocb->ki_pos))) {
|
|
|
- aio_mutex = ext4_aio_mutex(inode);
|
|
|
- mutex_lock(aio_mutex);
|
|
|
+ ext4_unaligned_aio(inode, from, iocb->ki_pos)) {
|
|
|
+ unaligned_aio = 1;
|
|
|
ext4_unwritten_wait(inode);
|
|
|
}
|
|
|
|
|
|
- inode_lock(inode);
|
|
|
- ret = generic_write_checks(iocb, from);
|
|
|
- if (ret <= 0)
|
|
|
- goto out;
|
|
|
-
|
|
|
/*
|
|
|
* If we have encountered a bitmap-format file, the size limit
|
|
|
* is smaller than s_maxbytes, which is for extent-mapped files.
|
|
@@ -139,7 +137,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|
|
blk_start_plug(&plug);
|
|
|
|
|
|
/* check whether we do a DIO overwrite or not */
|
|
|
- if (ext4_should_dioread_nolock(inode) && !aio_mutex &&
|
|
|
+ if (ext4_should_dioread_nolock(inode) && !unaligned_aio &&
|
|
|
!file->f_mapping->nrpages && pos + length <= i_size_read(inode)) {
|
|
|
struct ext4_map_blocks map;
|
|
|
unsigned int blkbits = inode->i_blkbits;
|
|
@@ -181,14 +179,10 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|
|
if (o_direct)
|
|
|
blk_finish_plug(&plug);
|
|
|
|
|
|
- if (aio_mutex)
|
|
|
- mutex_unlock(aio_mutex);
|
|
|
return ret;
|
|
|
|
|
|
out:
|
|
|
inode_unlock(inode);
|
|
|
- if (aio_mutex)
|
|
|
- mutex_unlock(aio_mutex);
|
|
|
return ret;
|
|
|
}
|
|
|
|