[Devel] [PATCH VZ10 2/2] fs/fuse: redirty folio on -ENOMEM in fuse_writepages_fill()

Alexey Kuznetsov kuznet at virtuozzo.com
Fri Apr 24 13:16:37 MSK 2026


Ack

On Mon, Apr 20, 2026 at 3:26 PM Liu Kui <kui.liu at virtuozzo.com> wrote:
>
> When fuse_writepages_fill() fails with -ENOMEM, the folio is incorrectly
> left in a clean state even though it is still being tagged dirty in the
> xarray. Since -ENOMEM is non-fatal, the VFS layer may retry writeback
> later, but this inconsistency can cause the folio to never be written back,
> leading to silent data loss from the application's perspective.
>
> Signed-off-by: Liu Kui <kui.liu at virtuozzo.com>
> ---
>  fs/fuse/file.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index b84aac13bfc9..edea59ee4839 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -2724,13 +2724,11 @@ static int fuse_writepages_fill(struct folio *folio,
>         int err;
>         int check_for_blocked = 0;
>
> -       if (!wpa && test_bit(FUSE_I_INVAL_FILES, &fi->state)) {
> -               unlock_page(&folio->page);
> -               return -EIO;
> -       }
> +       err = -EIO;
> +       if (unlikely(!wpa && test_bit(FUSE_I_INVAL_FILES, &fi->state)))
> +               goto out_unlock;
>
>         if (!data->ff) {
> -               err = -EIO;
>                 data->ff = fuse_write_file_get(fi);
>                 if (!data->ff)
>                         goto out_unlock;
> @@ -2743,8 +2741,10 @@ static int fuse_writepages_fill(struct folio *folio,
>
>         err = -ENOMEM;
>         tmp_folio = folio_alloc(GFP_NOFS | __GFP_HIGHMEM, 0);
> -       if (!tmp_folio)
> +       if (!tmp_folio) {
> +               folio_redirty_for_writepage(wbc, folio);
>                 goto out_unlock;
> +       }
>
>         /*
>          * The page must not be redirtied until the writeout is completed
> @@ -2764,6 +2764,7 @@ static int fuse_writepages_fill(struct folio *folio,
>                 wpa = fuse_writepage_args_setup(folio, data->ff);
>                 if (!wpa) {
>                         folio_put(tmp_folio);
> +                       folio_redirty_for_writepage(wbc, folio);
>                         goto out_unlock;
>                 }
>                 fuse_file_get(wpa->ia.ff);
> --
> 2.39.5 (Apple Git-154)



More information about the Devel mailing list