fs/affs/file.c: fix direct IO writes beyond EOF
authorFabian Frederick <fabf@skynet.be>
Tue, 17 Feb 2015 21:46:15 +0000 (13:46 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 17 Feb 2015 22:34:52 +0000 (14:34 -0800)
Use the same fallback to normal IO in case of write
operations beyond EOF as fat direct IO. This patch fixes

fsx file -d -Z -r 4096 -w 4096

Report:
  129(129 mod 256): TRUNCATE DOWN from 0x3ff01 to 0xb3f6
  130(130 mod 256): WRITE    0x22000 thru 0x2dfff (0xc000 bytes) HOLE

Thanks to Jan for helping me on this problem.

The ideal solution suggested by Jan Kara would be to use
cont_write_begin() but affs direct_IO shouldn't be used a lot anyway...

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/affs/file.c

index 7e83ba22bed47ddc390cf17f1da100cc2ca9e3b7..d2468bf95669850520a2a0dc852b1185c5234c7b 100644 (file)
@@ -398,6 +398,13 @@ affs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
        size_t count = iov_iter_count(iter);
        ssize_t ret;
 
+       if (rw == WRITE) {
+               loff_t size = offset + count;
+
+               if (AFFS_I(inode)->mmu_private < size)
+                       return 0;
+       }
+
        ret = blockdev_direct_IO(rw, iocb, inode, iter, offset, affs_get_block);
        if (ret < 0 && (rw & WRITE))
                affs_write_failed(mapping, offset + count);