fuse: fix alignment in short read optimization for async_dio
authorMaxim Patlasov <mpatlasov@parallels.com>
Thu, 30 May 2013 12:41:34 +0000 (16:41 +0400)
committerMiklos Szeredi <mszeredi@suse.cz>
Mon, 3 Jun 2013 13:15:42 +0000 (15:15 +0200)
commite5c5f05dca0cf90f0f3bb1aea85dcf658baff185
treed6290697847d61da2c4a183d9ea521989a814a43
parentc9ecf989cc7626e9edf8abef79f64b909542129b
fuse: fix alignment in short read optimization for async_dio

The bug was introduced with async_dio feature: trying to optimize short reads,
we cut number-of-bytes-to-read to i_size boundary. Hence the following example:

truncate --size=300 /mnt/file
dd if=/mnt/file of=/dev/null iflag=direct

led to FUSE_READ request of 300 bytes size. This turned out to be problem
for userspace fuse implementations who rely on assumption that kernel fuse
does not change alignment of request from client FS.

The patch turns off the optimization if async_dio is disabled. And, if it's
enabled, the patch fixes adjustment of number-of-bytes-to-read to preserve
alignment.

Note, that we cannot throw out short read optimization entirely because
otherwise a direct read of a huge size issued on a tiny file would generate
a huge amount of fuse requests and most of them would be ACKed by userspace
with zero bytes read.

Signed-off-by: Maxim Patlasov <MPatlasov@parallels.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
fs/fuse/file.c