diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-10-17 04:51:58 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-02-05 18:15:37 -0500 |
commit | d541281b4eb68094e3a7dabf79b1718be9416a77 (patch) | |
tree | e9f0bda3341b611b7344ad243afb86017449861d | |
parent | cb12531b8af9c3ba5087b6e2d4f959d25b507a29 (diff) |
bcachefs: Start copygc when first going read-write
In the distant past, it wasn't possible to start copygc until after
journal replay had finished. Now, the btree iterator code overlays keys
from the journal, so there's no reason not to start it earlier - and it
solves a rare deadlock.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/recovery.c | 47 | ||||
-rw-r--r-- | fs/bcachefs/super.c | 28 |
2 files changed, 44 insertions, 31 deletions
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index 622c34065bda..e699544e9cb3 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -1266,6 +1266,20 @@ use_clean: goto err; bch_verbose(c, "done checking need_discard and freespace btrees"); + if (c->sb.version < bcachefs_metadata_version_snapshot_2) { + err = "error creating root snapshot node"; + ret = bch2_fs_initialize_subvolumes(c); + if (ret) + goto err; + } + + bch_verbose(c, "reading snapshots table"); + err = "error reading snapshots table"; + ret = bch2_fs_snapshots_start(c); + if (ret) + goto err; + bch_verbose(c, "reading snapshots done"); + set_bit(BCH_FS_MAY_GO_RW, &c->flags); bch_info(c, "starting journal replay, %zu keys", c->journal_keys.nr); @@ -1314,7 +1328,6 @@ use_clean: bch_verbose(c, "done checking alloc to lru refs"); set_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags); } else { - set_bit(BCH_FS_MAY_GO_RW, &c->flags); set_bit(BCH_FS_INITIAL_GC_DONE, &c->flags); set_bit(BCH_FS_CHECK_LRUS_DONE, &c->flags); set_bit(BCH_FS_CHECK_BACKPOINTERS_DONE, &c->flags); @@ -1324,6 +1337,22 @@ use_clean: if (c->opts.norecovery) goto out; + if (c->sb.version < bcachefs_metadata_version_snapshot_2) { + err = "error creating root snapshot node"; + ret = bch2_fs_initialize_subvolumes(c); + if (ret) + goto err; + } + + bch_verbose(c, "reading snapshots table"); + err = "error reading snapshots table"; + ret = bch2_fs_snapshots_start(c); + if (ret) + goto err; + bch_verbose(c, "reading snapshots done"); + + set_bit(BCH_FS_MAY_GO_RW, &c->flags); + bch_verbose(c, "starting journal replay, %zu keys", c->journal_keys.nr); err = "journal replay failed"; ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1); @@ -1339,22 +1368,6 @@ use_clean: goto err; if (c->sb.version < bcachefs_metadata_version_snapshot_2) { - bch2_fs_lazy_rw(c); - - err = "error creating root snapshot node"; - ret = bch2_fs_initialize_subvolumes(c); - if (ret) - goto err; - } - - bch_verbose(c, "reading snapshots table"); - err = "error reading snapshots table"; - ret = bch2_fs_snapshots_start(c); - if (ret) - goto err; - bch_verbose(c, "reading snapshots done"); - - if (c->sb.version < bcachefs_metadata_version_snapshot_2) { /* set bi_subvol on root inode */ err = "error upgrade root inode for subvolumes"; ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_LAZY_RW, diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index cf4e70c77694..f5819709b9a2 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -327,26 +327,12 @@ static int bch2_fs_read_write_late(struct bch_fs *c) { int ret; - ret = bch2_gc_thread_start(c); - if (ret) { - bch_err(c, "error starting gc thread"); - return ret; - } - - ret = bch2_copygc_start(c); - if (ret) { - bch_err(c, "error starting copygc thread"); - return ret; - } - ret = bch2_rebalance_start(c); if (ret) { bch_err(c, "error starting rebalance thread"); return ret; } - schedule_work(&c->ec_stripe_delete_work); - return 0; } @@ -393,6 +379,20 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early) bch2_dev_allocator_add(c, ca); bch2_recalc_capacity(c); + ret = bch2_gc_thread_start(c); + if (ret) { + bch_err(c, "error starting gc thread"); + return ret; + } + + ret = bch2_copygc_start(c); + if (ret) { + bch_err(c, "error starting copygc thread"); + return ret; + } + + schedule_work(&c->ec_stripe_delete_work); + bch2_do_discards(c); bch2_do_invalidates(c); |