Modify sync related functions to iterate over all writeback contexts.

Signed-off-by: Kundan Kumar <[email protected]>
Signed-off-by: Anuj Gupta <[email protected]>
---
 fs/fs-writeback.c | 66 +++++++++++++++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 22 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 432f392c8256..7bf1f6c1c0ba 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -2753,11 +2753,13 @@ static void wait_sb_inodes(struct super_block *sb)
        mutex_unlock(&sb->s_sync_lock);
 }
 
-static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,
-                                    enum wb_reason reason, bool skip_if_busy)
+static void __writeback_inodes_sb_nr_ctx(struct super_block *sb,
+                                        unsigned long nr,
+                                        enum wb_reason reason,
+                                        bool skip_if_busy,
+                                        struct bdi_writeback_ctx *bdi_wb_ctx)
 {
-       struct backing_dev_info *bdi = sb->s_bdi;
-       DEFINE_WB_COMPLETION(done, bdi->wb_ctx[0]);
+       DEFINE_WB_COMPLETION(done, bdi_wb_ctx);
        struct wb_writeback_work work = {
                .sb                     = sb,
                .sync_mode              = WB_SYNC_NONE,
@@ -2767,13 +2769,23 @@ static void __writeback_inodes_sb_nr(struct super_block 
*sb, unsigned long nr,
                .reason                 = reason,
        };
 
+       bdi_split_work_to_wbs(sb->s_bdi, bdi_wb_ctx, &work, skip_if_busy);
+       wb_wait_for_completion(&done);
+}
+
+static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,
+                                    enum wb_reason reason, bool skip_if_busy)
+{
+       struct backing_dev_info *bdi = sb->s_bdi;
+       struct bdi_writeback_ctx *bdi_wb_ctx;
+
        if (!bdi_has_dirty_io(bdi) || bdi == &noop_backing_dev_info)
                return;
        WARN_ON(!rwsem_is_locked(&sb->s_umount));
 
-       bdi_split_work_to_wbs(sb->s_bdi, bdi->wb_ctx[0], &work,
-                             skip_if_busy);
-       wb_wait_for_completion(&done);
+       for_each_bdi_wb_ctx(bdi, bdi_wb_ctx)
+               __writeback_inodes_sb_nr_ctx(sb, nr, reason, skip_if_busy,
+                                            bdi_wb_ctx);
 }
 
 /**
@@ -2826,17 +2838,11 @@ void try_to_writeback_inodes_sb(struct super_block *sb, 
enum wb_reason reason)
 }
 EXPORT_SYMBOL(try_to_writeback_inodes_sb);
 
-/**
- * sync_inodes_sb      -       sync sb inode pages
- * @sb: the superblock
- *
- * This function writes and waits on any dirty inode belonging to this
- * super_block.
- */
-void sync_inodes_sb(struct super_block *sb)
+static void sync_inodes_bdi_wb_ctx(struct super_block *sb,
+                                  struct backing_dev_info *bdi,
+                                  struct bdi_writeback_ctx *bdi_wb_ctx)
 {
-       struct backing_dev_info *bdi = sb->s_bdi;
-       DEFINE_WB_COMPLETION(done, bdi->wb_ctx[0]);
+       DEFINE_WB_COMPLETION(done, bdi_wb_ctx);
        struct wb_writeback_work work = {
                .sb             = sb,
                .sync_mode      = WB_SYNC_ALL,
@@ -2847,6 +2853,25 @@ void sync_inodes_sb(struct super_block *sb)
                .for_sync       = 1,
        };
 
+       /* protect against inode wb switch, see inode_switch_wbs_work_fn() */
+       bdi_down_write_wb_ctx_switch_rwsem(bdi_wb_ctx);
+       bdi_split_work_to_wbs(bdi, bdi_wb_ctx, &work, false);
+       wb_wait_for_completion(&done);
+       bdi_up_write_wb_ctx_switch_rwsem(bdi_wb_ctx);
+}
+
+/**
+ * sync_inodes_sb      -       sync sb inode pages
+ * @sb: the superblock
+ *
+ * This function writes and waits on any dirty inode belonging to this
+ * super_block.
+ */
+void sync_inodes_sb(struct super_block *sb)
+{
+       struct backing_dev_info *bdi = sb->s_bdi;
+       struct bdi_writeback_ctx *bdi_wb_ctx;
+
        /*
         * Can't skip on !bdi_has_dirty() because we should wait for !dirty
         * inodes under writeback and I_DIRTY_TIME inodes ignored by
@@ -2856,11 +2881,8 @@ void sync_inodes_sb(struct super_block *sb)
                return;
        WARN_ON(!rwsem_is_locked(&sb->s_umount));
 
-       /* protect against inode wb switch, see inode_switch_wbs_work_fn() */
-       bdi_down_write_wb_ctx_switch_rwsem(bdi->wb_ctx[0]);
-       bdi_split_work_to_wbs(bdi, bdi->wb_ctx[0], &work, false);
-       wb_wait_for_completion(&done);
-       bdi_up_write_wb_ctx_switch_rwsem(bdi->wb_ctx[0]);
+       for_each_bdi_wb_ctx(bdi, bdi_wb_ctx)
+               sync_inodes_bdi_wb_ctx(sb, bdi, bdi_wb_ctx);
 
        wait_sb_inodes(sb);
 }
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to