direct-io: add flag to allow aio writes beyond i_size
authorChristoph Hellwig <hch@infradead.org>
Sun, 9 Feb 2014 23:27:11 +0000 (10:27 +1100)
committerDave Chinner <david@fromorbit.com>
Sun, 9 Feb 2014 23:27:11 +0000 (10:27 +1100)
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 <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/direct-io.c
include/linux/fs.h

index 160a5489a93936372c85683ee8cfd6da5185007b..a701752dd7505a139b1a52282ba788d7b1271857 100644 (file)
@@ -1194,13 +1194,19 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
        }
 
        /*
-        * For file extending writes updating i_size before data
-        * writeouts complete can expose uninitialized blocks. So
-        * even for AIO, we need to wait for i/o to complete before
-        * returning in this case.
+        * For file extending writes updating i_size before data writeouts
+        * complete can expose uninitialized blocks in dumb filesystems.
+        * In that case we need to wait for I/O completion even if asked
+        * for an asynchronous write.
         */
-       dio->is_async = !is_sync_kiocb(iocb) && !((rw & WRITE) &&
-               (end > i_size_read(inode)));
+       if (is_sync_kiocb(iocb))
+               dio->is_async = false;
+       else if (!(dio->flags & DIO_ASYNC_EXTEND) &&
+            (rw & WRITE) && end > i_size_read(inode))
+               dio->is_async = false;
+       else
+               dio->is_async = true;
+
        dio->inode = inode;
        dio->rw = rw;
 
index 09f553c59813a2b2f88991ab0ab854880e07e574..f7faefcf4843576aa535ac44241b79cca56b7164 100644 (file)
@@ -2527,6 +2527,9 @@ enum {
 
        /* filesystem does not support filling holes */
        DIO_SKIP_HOLES  = 0x02,
+
+       /* filesystem can handle aio writes beyond i_size */
+       DIO_ASYNC_EXTEND = 0x04,
 };
 
 void dio_end_io(struct bio *bio, int error);