Re: [PATCH] fuse: move page cache invalidation after AIO to workqueue

From: Jingbo Xu

Date: Fri Mar 06 2026 - 09:14:03 EST




On 3/6/26 6:11 PM, Cheng Ding wrote:
>
>> After reverting my previous patch, I think it would be cleaner by:
>>
>>
>> "The page cache invalidation for FOPEN_DIRECT_IO write in
>> fuse_direct_io() is moved to fuse_direct_write_iter() (with any progress
>> in write), to keep consistent with generic_file_direct_write(). This
>> covers the scenarios of both synchronous FOPEN_DIRECT_IO write
>> (regardless FUSE_ASYNC_DIO) and asynchronous FOPEN_DIRECT_IO write
>> without FUSE_ASYNC_DIO.
>
> This suggestion sounds good to me.
>
>>
>>
>>>
>>> +int sb_init_dio_done_wq(struct super_block *sb);
>>> +
>>
>> #include "../internal.h” ?
>
> We prefer to keep FUSE independent from other parts of the kernel. This way, we can create DKMS packages for the FUSE kernel module.
>
>>> + if (!inode->i_sb->s_dio_done_wq)
>>> + res = sb_init_dio_done_wq(inode->i_sb);
>>
>> Better to call sb_init_dio_done_wq() from fuse_direct_IO(), and fail the
>> IO directly if sb_init_dio_done_wq() fails.
>>
>>> + if (res >= 0) {
>>> + INIT_WORK(&io->work, fuse_aio_invalidate_worker);
>>> + queue_work(inode->i_sb->s_dio_done_wq, &io->work);
>> + return;
>> }
>>
>> Otherwise, the page cache invalidation would be missed if the previous
>> sb_init_dio_done_wq() fails.
>
> If sb_init_dio_done_wq() fails, res contains the error code, which will be passed to iocb->ki_complete(). However, I can change this if you still prefer to do that in fuse_direct_IO().
>

Yes I still prefer initializing sb->s_dio_done_wq in advance in
fuse_direct_IO(). Otherwise even you fail the direct IO on failure of
sb_init_dio_done_wq(), the data has been written to the file.


--
Thanks,
Jingbo