Commit 5f5c7466 authored by Kent Overstreet's avatar Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 30ca6ece
...@@ -1267,6 +1267,20 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1267,6 +1267,20 @@ int bch2_fs_recovery(struct bch_fs *c)
goto err; goto err;
bch_verbose(c, "done checking need_discard and freespace btrees"); 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); set_bit(BCH_FS_MAY_GO_RW, &c->flags);
bch_info(c, "starting journal replay, %zu keys", c->journal_keys.nr); bch_info(c, "starting journal replay, %zu keys", c->journal_keys.nr);
...@@ -1293,7 +1307,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1293,7 +1307,6 @@ int bch2_fs_recovery(struct bch_fs *c)
bch_verbose(c, "done checking alloc to lru refs"); bch_verbose(c, "done checking alloc to lru refs");
set_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags); set_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags);
} else { } else {
set_bit(BCH_FS_MAY_GO_RW, &c->flags);
set_bit(BCH_FS_INITIAL_GC_DONE, &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_LRUS_DONE, &c->flags);
set_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags); set_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags);
...@@ -1302,6 +1315,22 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1302,6 +1315,22 @@ int bch2_fs_recovery(struct bch_fs *c)
if (c->opts.norecovery) if (c->opts.norecovery)
goto out; 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); bch_verbose(c, "starting journal replay, %zu keys", c->journal_keys.nr);
err = "journal replay failed"; err = "journal replay failed";
ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1); ret = bch2_journal_replay(c, last_seq, blacklist_seq - 1);
...@@ -1316,22 +1345,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1316,22 +1345,6 @@ int bch2_fs_recovery(struct bch_fs *c)
if (ret) if (ret)
goto err; 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) { if (c->sb.version < bcachefs_metadata_version_snapshot_2) {
/* set bi_subvol on root inode */ /* set bi_subvol on root inode */
err = "error upgrade root inode for subvolumes"; err = "error upgrade root inode for subvolumes";
......
...@@ -332,26 +332,12 @@ static int bch2_fs_read_write_late(struct bch_fs *c) ...@@ -332,26 +332,12 @@ static int bch2_fs_read_write_late(struct bch_fs *c)
{ {
int ret; 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); ret = bch2_rebalance_start(c);
if (ret) { if (ret) {
bch_err(c, "error starting rebalance thread"); bch_err(c, "error starting rebalance thread");
return ret; return ret;
} }
schedule_work(&c->ec_stripe_delete_work);
return 0; return 0;
} }
...@@ -398,6 +384,18 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early) ...@@ -398,6 +384,18 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
bch2_dev_allocator_add(c, ca); bch2_dev_allocator_add(c, ca);
bch2_recalc_capacity(c); 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;
}
if (!early) { if (!early) {
ret = bch2_fs_read_write_late(c); ret = bch2_fs_read_write_late(c);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment