Re: [PATCH 1/8] cachefiles: Fix incorrect block calculations in __cachefiles_prepare_write()

From: Zizhi Wo
Date: Thu Oct 10 2024 - 07:11:52 EST




在 2024/10/10 18:34, David Howells 写道:
Zizhi Wo <wozizhi@xxxxxxxxxx> wrote:

In the __cachefiles_prepare_write function, DIO aligns blocks using
PAGE_SIZE as the unit. And currently cachefiles_add_cache() binds
cache->bsize with the requirement that it must not exceed PAGE_SIZE.
However, if cache->bsize is smaller than PAGE_SIZE, the calculated block
count will be incorrect in __cachefiles_prepare_write().

Set the block size to cache->bsize to resolve this issue.

Have you tested this with 9p, afs, cifs, ceph and/or nfs? This may cause an
issue there as it assumed that the cache file will be padded out to
PAGE_SIZE (see cachefiles_adjust_size()).

David



In my opinion, cachefiles_add_cache() will pass the corresponding size
to cache->bsize. For scenarios such as nfs/cifs, the corresponding bsize
is PAGE_SIZE aligned, which is fine. For scenarios where cache->bsize is
specified for non-PAGE_SIZE alignment (such as erofs on demand mode),
imposing PAGE_SIZE here can be problematic. So modify cache->bsize to be
more generic.

Thanks,
Zizhi Wo