]> www.infradead.org Git - users/hch/misc.git/commitdiff
btrfs: push struct writeback_control into start_delalloc_inodes
authorChristoph Hellwig <hch@lst.de>
Mon, 6 Oct 2025 08:36:11 +0000 (10:36 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 23 Oct 2025 06:47:24 +0000 (08:47 +0200)
In preparation for changing the filemap_fdatawrite_wbc API to not expose
the writeback_control to the callers, push the wbc declaration next to
the filemap_fdatawrite_wbc call and just pass the nr_to_write value to
start_delalloc_inodes.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
fs/btrfs/inode.c

index 9edb78fc57fccc699dde6947616122958d18b6ea..b97d6c1f77727281b818cb46e4128c7be97b5ca1 100644 (file)
@@ -8709,15 +8709,13 @@ static struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode
  * some fairly slow code that needs optimization. This walks the list
  * of all the inodes with pending delalloc and forces them to disk.
  */
-static int start_delalloc_inodes(struct btrfs_root *root,
-                                struct writeback_control *wbc, bool snapshot,
-                                bool in_reclaim_context)
+static int start_delalloc_inodes(struct btrfs_root *root, long *nr_to_write,
+                                bool snapshot, bool in_reclaim_context)
 {
        struct btrfs_delalloc_work *work, *next;
        LIST_HEAD(works);
        LIST_HEAD(splice);
        int ret = 0;
-       bool full_flush = wbc->nr_to_write == LONG_MAX;
 
        mutex_lock(&root->delalloc_mutex);
        spin_lock(&root->delalloc_lock);
@@ -8743,7 +8741,7 @@ static int start_delalloc_inodes(struct btrfs_root *root,
 
                if (snapshot)
                        set_bit(BTRFS_INODE_SNAPSHOT_FLUSH, &inode->runtime_flags);
-               if (full_flush) {
+               if (nr_to_write == NULL) {
                        work = btrfs_alloc_delalloc_work(tmp_inode);
                        if (!work) {
                                iput(tmp_inode);
@@ -8754,9 +8752,20 @@ static int start_delalloc_inodes(struct btrfs_root *root,
                        btrfs_queue_work(root->fs_info->flush_workers,
                                         &work->work);
                } else {
-                       ret = filemap_fdatawrite_wbc(tmp_inode->i_mapping, wbc);
+                       struct writeback_control wbc = {
+                               .nr_to_write = *nr_to_write,
+                               .sync_mode = WB_SYNC_NONE,
+                               .range_start = 0,
+                               .range_end = LLONG_MAX,
+                       };
+
+                       ret = filemap_fdatawrite_wbc(tmp_inode->i_mapping,
+                                       &wbc);
                        btrfs_add_delayed_iput(inode);
-                       if (ret || wbc->nr_to_write <= 0)
+
+                       if (*nr_to_write != LONG_MAX)
+                               *nr_to_write = wbc.nr_to_write;
+                       if (ret || *nr_to_write <= 0)
                                goto out;
                }
                cond_resched();
@@ -8782,29 +8791,17 @@ out:
 
 int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context)
 {
-       struct writeback_control wbc = {
-               .nr_to_write = LONG_MAX,
-               .sync_mode = WB_SYNC_NONE,
-               .range_start = 0,
-               .range_end = LLONG_MAX,
-       };
        struct btrfs_fs_info *fs_info = root->fs_info;
 
        if (BTRFS_FS_ERROR(fs_info))
                return -EROFS;
-
-       return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
+       return start_delalloc_inodes(root, NULL, true, in_reclaim_context);
 }
 
 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
                               bool in_reclaim_context)
 {
-       struct writeback_control wbc = {
-               .nr_to_write = nr,
-               .sync_mode = WB_SYNC_NONE,
-               .range_start = 0,
-               .range_end = LLONG_MAX,
-       };
+       long *nr_to_write = nr == LONG_MAX ? NULL : &nr;
        struct btrfs_root *root;
        LIST_HEAD(splice);
        int ret;
@@ -8816,13 +8813,6 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
        spin_lock(&fs_info->delalloc_root_lock);
        list_splice_init(&fs_info->delalloc_roots, &splice);
        while (!list_empty(&splice)) {
-               /*
-                * Reset nr_to_write here so we know that we're doing a full
-                * flush.
-                */
-               if (nr == LONG_MAX)
-                       wbc.nr_to_write = LONG_MAX;
-
                root = list_first_entry(&splice, struct btrfs_root,
                                        delalloc_root);
                root = btrfs_grab_root(root);
@@ -8831,9 +8821,10 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
                               &fs_info->delalloc_roots);
                spin_unlock(&fs_info->delalloc_root_lock);
 
-               ret = start_delalloc_inodes(root, &wbc, false, in_reclaim_context);
+               ret = start_delalloc_inodes(root, nr_to_write, false,
+                               in_reclaim_context);
                btrfs_put_root(root);
-               if (ret < 0 || wbc.nr_to_write <= 0)
+               if (ret < 0 || nr <= 0)
                        goto out;
                spin_lock(&fs_info->delalloc_root_lock);
        }