fuse: fix fuseblk i_blkbits for iomap partial writes
authorJoanne Koong <joannelkoong@gmail.com>
Fri, 15 Aug 2025 18:25:39 +0000 (11:25 -0700)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 26 Aug 2025 10:43:31 +0000 (12:43 +0200)
commitbd24d2108e9c8459d2c9f3d6d910b0053887df57
tree5288ff465350a41bf1e300f713f0898849a5bee1
parent79569946502258ef53984f3000bffa77e469d8dc
fuse: fix fuseblk i_blkbits for iomap partial writes

On regular fuse filesystems, i_blkbits is set to PAGE_SHIFT which means
any iomap partial writes will mark the entire folio as uptodate. However
fuseblk filesystems work differently and allow the blocksize to be less
than the page size. As such, this may lead to data corruption if fuseblk
sets its blocksize to less than the page size, uses the writeback cache,
and does a partial write, then a read and the read happens before the
write has undergone writeback, since the folio will not be marked
uptodate from the partial write so the read will read in the entire
folio from disk, which will overwrite the partial write.

The long-term solution for this, which will also be needed for fuse to
enable large folios with the writeback cache on, is to have fuse also
use iomap for folio reads, but until that is done, the cleanest
workaround is to use the page size for fuseblk's internal kernel inode
blksize/blkbits values while maintaining current behavior for stat().

This was verified using ntfs-3g:
$ sudo mkfs.ntfs -f -c 512 /dev/vdd1
$ sudo ntfs-3g /dev/vdd1 ~/fuseblk
$ stat ~/fuseblk/hi.txt
IO Block: 512

Fixes: a4c9ab1d4975 ("fuse: use iomap for buffered writes")
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dir.c
fs/fuse/fuse_i.h
fs/fuse/inode.c