- if (c->opts.noreplay)
- goto recovery_done;
-
- bch_verbose(c, "mark and sweep done");
-
- /*
- * bch2_journal_start() can't happen sooner, or btree_gc_finish()
- * will give spurious errors about oldest_gen > bucket_gen -
- * this is a hack but oh well.
- */
- bch2_journal_start(c);
-
- err = "error starting allocator thread";
- for_each_rw_member(ca, c, i)
- if (bch2_dev_allocator_start(ca)) {
- percpu_ref_put(&ca->io_ref);
- goto err;
- }
-
- bch_verbose(c, "starting journal replay:");
-
- err = "journal replay failed";
- ret = bch2_journal_replay(c, &journal);
- if (ret)
- goto err;
-
- bch_verbose(c, "journal replay done");
-
- if (c->opts.norecovery)
- goto recovery_done;
-
- bch_verbose(c, "starting fsck:");
- err = "error in fsck";
- ret = bch2_fsck(c, !c->opts.nofsck);
- if (ret)
- goto err;
-
- for_each_rw_member(ca, c, i)
- if (ca->need_prio_write) {
- ret = bch2_prio_write(ca);
- if (ret) {
- percpu_ref_put(&ca->io_ref);
- goto err;
- }
- }
-
- bch_verbose(c, "fsck done");
- } else {
- struct bch_inode_unpacked inode;
- struct bkey_inode_buf packed_inode;
- struct closure cl;
-
- closure_init_stack(&cl);
-
- bch_notice(c, "initializing new filesystem");
-
- ret = bch2_initial_gc(c, &journal);
- if (ret)
- goto err;
-
- err = "unable to allocate journal buckets";
- for_each_rw_member(ca, c, i)
- if (bch2_dev_journal_alloc(ca)) {
- percpu_ref_put(&ca->io_ref);
- goto err;
- }
-
- /*
- * journal_res_get() will crash if called before this has
- * set up the journal.pin FIFO and journal.cur pointer:
- */
- bch2_journal_start(c);
- bch2_journal_set_replay_done(&c->journal);
-
- err = "error starting allocator thread";
- for_each_rw_member(ca, c, i)
- if (bch2_dev_allocator_start(ca)) {
- percpu_ref_put(&ca->io_ref);
- goto err;
- }
-
- err = "cannot allocate new btree root";
- for (id = 0; id < BTREE_ID_NR; id++)
- if (bch2_btree_root_alloc(c, id, &cl)) {
- closure_sync(&cl);
- goto err;
- }