diff mbox

[02/11] ext4: Allow unaligned unlocked DAX IO

Message ID 1478034381-19037-3-git-send-email-jack@suse.cz (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jan Kara Nov. 1, 2016, 9:06 p.m. UTC
Currently we don't allow unaligned writes without inode_lock. This is
because zeroing of partial blocks could cause data corruption for racing
unaligned writes to the same block. However DAX handles zeroing during
block allocation and thus zeroing of partial blocks cannot race. Allow
DAX unaligned IO to run without inode_lock.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Nov. 2, 2016, 2:27 p.m. UTC | #1
On Tue, Nov 01, 2016 at 10:06:12PM +0100, Jan Kara wrote:
> Currently we don't allow unaligned writes without inode_lock. This is
> because zeroing of partial blocks could cause data corruption for racing
> unaligned writes to the same block. However DAX handles zeroing during
> block allocation and thus zeroing of partial blocks cannot race. Allow
> DAX unaligned IO to run without inode_lock.

DAX writes should always take the inode lock.  Without that you break
the expectations of existing applications that did not specify O_DIRECT.
Jan Kara Nov. 3, 2016, 11:55 p.m. UTC | #2
On Wed 02-11-16 07:27:46, Christoph Hellwig wrote:
> On Tue, Nov 01, 2016 at 10:06:12PM +0100, Jan Kara wrote:
> > Currently we don't allow unaligned writes without inode_lock. This is
> > because zeroing of partial blocks could cause data corruption for racing
> > unaligned writes to the same block. However DAX handles zeroing during
> > block allocation and thus zeroing of partial blocks cannot race. Allow
> > DAX unaligned IO to run without inode_lock.
> 
> DAX writes should always take the inode lock.  Without that you break
> the expectations of existing applications that did not specify O_DIRECT.

Yeah, actually this patch has no practical effect since later iomap
conversion just effectively reverts this patch and I didn't realize it.
I'll just drop it. Thanks.

								Honza
diff mbox

Patch

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index a6a7becb9465..55f8b922b76d 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -161,7 +161,8 @@  ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 
 	iocb->private = &overwrite;
 	/* Check whether we do a DIO overwrite or not */
-	if (o_direct && ext4_should_dioread_nolock(inode) && !unaligned_aio &&
+	if (((o_direct && !unaligned_aio) || IS_DAX(inode)) &&
+	    ext4_should_dioread_nolock(inode) &&
 	    ext4_overwrite_io(inode, iocb->ki_pos, iov_iter_count(from)))
 		overwrite = 1;