fuse: move fuse file initialization to wpa allocation time
authorJoanne Koong <joannelkoong@gmail.com>
Mon, 26 Aug 2024 21:19:07 +0000 (14:19 -0700)
committerMiklos Szeredi <mszeredi@redhat.com>
Thu, 29 Aug 2024 09:43:12 +0000 (11:43 +0200)
Before this change, wpa->ia.ff is initialized with an acquired reference
on the fuse file right before it submits the writeback request. If there
are auxiliary writebacks, then the initialization and reference
acquisition needs to also be set before we submit the auxiliary writeback
request.

To make the logic simpler and to pave the way for a subsequent
refactoring of fuse_writepages_fill() and fuse_writepage_locked(), this
change initializes and acquires wpa->ia.ff when the wpa is allocated.

No functional changes added.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/file.c

index 0653fac40782bdd27a844496935868f563987e84..be0d7fdf04d0d6daff2e043da2f3eee6a2892d6b 100644 (file)
@@ -1762,8 +1762,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)
        for (i = 0; i < ap->num_pages; i++)
                __free_page(ap->pages[i]);
 
-       if (wpa->ia.ff)
-               fuse_file_put(wpa->ia.ff, false);
+       fuse_file_put(wpa->ia.ff, false);
 
        kfree(ap->pages);
        kfree(wpa);
@@ -1936,7 +1935,6 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
 
                wpa->next = next->next;
                next->next = NULL;
-               next->ia.ff = fuse_file_get(wpa->ia.ff);
                tree_insert(&fi->writepages, next);
 
                /*
@@ -2155,7 +2153,6 @@ static void fuse_writepages_send(struct fuse_fill_wb_data *data)
        int num_pages = wpa->ia.ap.num_pages;
        int i;
 
-       wpa->ia.ff = fuse_file_get(data->ff);
        spin_lock(&fi->lock);
        list_add_tail(&wpa->queue_entry, &fi->queued_writes);
        fuse_flush_writepages(inode);
@@ -2300,6 +2297,7 @@ static int fuse_writepages_fill(struct folio *folio,
                ap = &wpa->ia.ap;
                fuse_write_args_fill(&wpa->ia, data->ff, folio_pos(folio), 0);
                wpa->ia.write.in.write_flags |= FUSE_WRITE_CACHE;
+               wpa->ia.ff = fuse_file_get(data->ff);
                wpa->next = NULL;
                ap->args.in_pages = true;
                ap->args.end = fuse_writepage_end;