bcachefs: Write out alloc info more carefully
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 28 Mar 2019 07:40:39 +0000 (03:40 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:19 +0000 (17:08 -0400)
In flight btree updates could update alloc info until they're flushed -
so we have to try writing again after they've been flushed.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super.c

index dd1496af9a06ba1008f328e0daf30842ff8b3dac..369c533e677b489d900ffa5fbb2ea91dd21604a6 100644 (file)
@@ -175,7 +175,7 @@ static void __bch2_fs_read_only(struct bch_fs *c)
 {
        struct bch_dev *ca;
        bool wrote;
-       unsigned i;
+       unsigned i, clean_passes = 0;
        int ret;
 
        bch2_rebalance_stop(c);
@@ -195,15 +195,15 @@ static void __bch2_fs_read_only(struct bch_fs *c)
                goto allocator_not_running;
 
        do {
-               ret = bch2_alloc_write(c, false, &wrote);
+               ret = bch2_stripes_write(c, &wrote);
                if (ret) {
-                       bch2_fs_inconsistent(c, "error writing out alloc info %i", ret);
+                       bch2_fs_inconsistent(c, "error writing out stripes");
                        break;
                }
 
-               ret = bch2_stripes_write(c, &wrote);
+               ret = bch2_alloc_write(c, false, &wrote);
                if (ret) {
-                       bch2_fs_inconsistent(c, "error writing out stripes");
+                       bch2_fs_inconsistent(c, "error writing out alloc info %i", ret);
                        break;
                }
 
@@ -221,7 +221,9 @@ static void __bch2_fs_read_only(struct bch_fs *c)
                 */
                closure_wait_event(&c->btree_interior_update_wait,
                                   !bch2_btree_interior_updates_nr_pending(c));
-       } while (wrote);
+
+               clean_passes = wrote ? 0 : clean_passes + 1;
+       } while (clean_passes < 2);
 allocator_not_running:
        for_each_member_device(ca, c, i)
                bch2_dev_allocator_stop(ca);