]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/super.c
Update bcachefs sources to fd381c355c bcachefs: Fix a null ptr deref in fsck check_ex...
[bcachefs-tools-debian] / libbcachefs / super.c
index 359ca164e0889764d03cd930449debc89327b59a..613d09f5b8e6c90774ce95db6aa02442f6cfb42c 100644 (file)
@@ -206,11 +206,15 @@ static void __bch2_fs_read_only(struct bch_fs *c)
        unsigned i, clean_passes = 0;
        u64 seq = 0;
 
+       bch2_fs_ec_stop(c);
+       bch2_open_buckets_stop(c, NULL, true);
        bch2_rebalance_stop(c);
        bch2_copygc_stop(c);
        bch2_gc_thread_stop(c);
+       bch2_fs_ec_flush(c);
 
-       bch_verbose(c, "flushing journal and stopping allocators");
+       bch_verbose(c, "flushing journal and stopping allocators, journal seq %llu",
+                   journal_cur_seq(&c->journal));
 
        do {
                clean_passes++;
@@ -224,7 +228,8 @@ static void __bch2_fs_read_only(struct bch_fs *c)
                }
        } while (clean_passes < 2);
 
-       bch_verbose(c, "flushing journal and stopping allocators complete");
+       bch_verbose(c, "flushing journal and stopping allocators complete, journal seq %llu",
+                   journal_cur_seq(&c->journal));
 
        if (test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags) &&
            !test_bit(BCH_FS_EMERGENCY_RO, &c->flags))
@@ -489,6 +494,8 @@ static void __bch2_fs_free(struct bch_fs *c)
        kfree(c->journal_seq_blacklist_table);
        kfree(c->unused_inode_hints);
 
+       if (c->write_ref_wq)
+               destroy_workqueue(c->write_ref_wq);
        if (c->io_complete_wq)
                destroy_workqueue(c->io_complete_wq);
        if (c->copygc_wq)
@@ -642,7 +649,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
 
        c = kvpmalloc(sizeof(struct bch_fs), GFP_KERNEL|__GFP_ZERO);
        if (!c) {
-               c = ERR_PTR(-ENOMEM);
+               c = ERR_PTR(-BCH_ERR_ENOMEM_fs_alloc);
                goto out;
        }
 
@@ -679,6 +686,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
        bch2_fs_rebalance_init(c);
        bch2_fs_quota_init(c);
        bch2_fs_ec_init_early(c);
+       bch2_fs_move_init(c);
 
        INIT_LIST_HEAD(&c->list);
 
@@ -697,23 +705,15 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
        INIT_LIST_HEAD(&c->fsck_errors);
        mutex_init(&c->fsck_error_lock);
 
-       INIT_LIST_HEAD(&c->ec_stripe_head_list);
-       mutex_init(&c->ec_stripe_head_lock);
-
-       INIT_LIST_HEAD(&c->ec_stripe_new_list);
-       mutex_init(&c->ec_stripe_new_lock);
-
-       INIT_LIST_HEAD(&c->data_progress_list);
-       mutex_init(&c->data_progress_lock);
-
-       mutex_init(&c->ec_stripes_heap_lock);
-
        seqcount_init(&c->gc_pos_lock);
 
        seqcount_init(&c->usage_lock);
 
        sema_init(&c->io_in_flight, 128);
 
+       INIT_LIST_HEAD(&c->vfs_inodes_list);
+       mutex_init(&c->vfs_inodes_lock);
+
        c->copy_gc_enabled              = 1;
        c->rebalance.enabled            = 1;
        c->promote_whole_extents        = true;
@@ -742,7 +742,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
        strscpy(c->name, name.buf, sizeof(c->name));
        printbuf_exit(&name);
 
-       ret = name.allocation_failure ? -ENOMEM : 0;
+       ret = name.allocation_failure ? -BCH_ERR_ENOMEM_fs_name_alloc : 0;
        if (ret)
                goto err;
 
@@ -789,6 +789,8 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
                                WQ_FREEZABLE|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE, 1)) ||
            !(c->io_complete_wq = alloc_workqueue("bcachefs_io",
                                WQ_FREEZABLE|WQ_HIGHPRI|WQ_MEM_RECLAIM, 1)) ||
+           !(c->write_ref_wq = alloc_workqueue("bcachefs_write_ref",
+                               WQ_FREEZABLE, 0)) ||
 #ifndef BCH_WRITE_REF_DEBUG
            percpu_ref_init(&c->writes, bch2_writes_disabled,
                            PERCPU_REF_INIT_DEAD, GFP_KERNEL) ||
@@ -806,7 +808,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
            mempool_init_kmalloc_pool(&c->large_bkey_pool, 1, 2048) ||
            !(c->unused_inode_hints = kcalloc(1U << c->inode_shard_bits,
                                              sizeof(u64), GFP_KERNEL))) {
-               ret = -ENOMEM;
+               ret = -BCH_ERR_ENOMEM_fs_other_alloc;
                goto err;
        }
 
@@ -1187,7 +1189,7 @@ out:
 err:
        if (ca)
                bch2_dev_free(ca);
-       ret = -ENOMEM;
+       ret = -BCH_ERR_ENOMEM_dev_alloc;
        goto out;
 }
 
@@ -1743,6 +1745,10 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
        bch2_write_super(c);
        mutex_unlock(&c->sb_lock);
 
+       ret = bch2_fs_freespace_init(c);
+       if (ret)
+               bch_err(c, "device add error: error initializing free space: %s", bch2_err_str(ret));
+
        up_write(&c->state_lock);
        return 0;
 err: