Skip to content

Commit 6039257

Browse files
Christoph Hellwigdchinner
authored andcommitted
direct-io: add flag to allow aio writes beyond i_size
Some filesystems can handle direct I/O writes beyond i_size safely, so allow them to opt into receiving them. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Dave Chinner <[email protected]>
1 parent 38dbfb5 commit 6039257

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

fs/direct-io.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,13 +1194,19 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
11941194
}
11951195

11961196
/*
1197-
* For file extending writes updating i_size before data
1198-
* writeouts complete can expose uninitialized blocks. So
1199-
* even for AIO, we need to wait for i/o to complete before
1200-
* returning in this case.
1197+
* For file extending writes updating i_size before data writeouts
1198+
* complete can expose uninitialized blocks in dumb filesystems.
1199+
* In that case we need to wait for I/O completion even if asked
1200+
* for an asynchronous write.
12011201
*/
1202-
dio->is_async = !is_sync_kiocb(iocb) && !((rw & WRITE) &&
1203-
(end > i_size_read(inode)));
1202+
if (is_sync_kiocb(iocb))
1203+
dio->is_async = false;
1204+
else if (!(dio->flags & DIO_ASYNC_EXTEND) &&
1205+
(rw & WRITE) && end > i_size_read(inode))
1206+
dio->is_async = false;
1207+
else
1208+
dio->is_async = true;
1209+
12041210
dio->inode = inode;
12051211
dio->rw = rw;
12061212

include/linux/fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,9 @@ enum {
25272527

25282528
/* filesystem does not support filling holes */
25292529
DIO_SKIP_HOLES = 0x02,
2530+
2531+
/* filesystem can handle aio writes beyond i_size */
2532+
DIO_ASYNC_EXTEND = 0x04,
25302533
};
25312534

25322535
void dio_end_io(struct bio *bio, int error);

0 commit comments

Comments
 (0)