]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/btree_gc.c
Update bcachefs sources to c3e4d892b77b mean and variance: Promote to lib/math
[bcachefs-tools-debian] / libbcachefs / btree_gc.c
index 475f8e8d9185da5f718c69a42ddddb7d9fd701c6..d1615607480d33d49ad74e46e126f74fe203119f 100644 (file)
@@ -95,20 +95,20 @@ static int bch2_gc_check_topology(struct bch_fs *c,
                        bch2_bkey_val_to_text(&buf2, c, bkey_i_to_s_c(cur.k));
 
                        if (__fsck_err(c,
-                                 FSCK_CAN_FIX|
-                                 FSCK_CAN_IGNORE|
-                                 FSCK_NO_RATELIMIT,
-                                 "btree node with incorrect min_key at btree %s level %u:\n"
-                                 "  prev %s\n"
-                                 "  cur %s",
-                                 bch2_btree_id_str(b->c.btree_id), b->c.level,
-                                 buf1.buf, buf2.buf) &&
-                           should_restart_for_topology_repair(c)) {
+                                      FSCK_CAN_FIX|
+                                      FSCK_CAN_IGNORE|
+                                      FSCK_NO_RATELIMIT,
+                                      btree_node_topology_bad_min_key,
+                                      "btree node with incorrect min_key at btree %s level %u:\n"
+                                      "  prev %s\n"
+                                      "  cur %s",
+                                      bch2_btree_id_str(b->c.btree_id), b->c.level,
+                                      buf1.buf, buf2.buf) && should_restart_for_topology_repair(c)) {
                                bch_info(c, "Halting mark and sweep to start topology repair pass");
                                ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_check_topology);
                                goto err;
                        } else {
-                               set_bit(BCH_FS_INITIAL_GC_UNFIXED, &c->flags);
+                               set_bit(BCH_FS_initial_gc_unfixed, &c->flags);
                        }
                }
        }
@@ -122,10 +122,8 @@ static int bch2_gc_check_topology(struct bch_fs *c,
                bch2_bkey_val_to_text(&buf1, c, bkey_i_to_s_c(cur.k));
                bch2_bpos_to_text(&buf2, node_end);
 
-               if (__fsck_err(c,
-                         FSCK_CAN_FIX|
-                         FSCK_CAN_IGNORE|
-                         FSCK_NO_RATELIMIT,
+               if (__fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE|FSCK_NO_RATELIMIT,
+                         btree_node_topology_bad_max_key,
                          "btree node with incorrect max_key at btree %s level %u:\n"
                          "  %s\n"
                          "  expected %s",
@@ -136,7 +134,7 @@ static int bch2_gc_check_topology(struct bch_fs *c,
                        ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_check_topology);
                        goto err;
                } else {
-                       set_bit(BCH_FS_INITIAL_GC_UNFIXED, &c->flags);
+                       set_bit(BCH_FS_initial_gc_unfixed, &c->flags);
                }
        }
 
@@ -287,6 +285,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
 
                if (mustfix_fsck_err_on(bpos_ge(prev->data->min_key,
                                                cur->data->min_key), c,
+                               btree_node_topology_overwritten_by_next_node,
                                "btree node overwritten by next node at btree %s level %u:\n"
                                "  node %s\n"
                                "  next %s",
@@ -298,6 +297,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
 
                if (mustfix_fsck_err_on(!bpos_eq(prev->key.k.p,
                                                 bpos_predecessor(cur->data->min_key)), c,
+                               btree_node_topology_bad_max_key,
                                "btree node with incorrect max_key at btree %s level %u:\n"
                                "  node %s\n"
                                "  next %s",
@@ -310,6 +310,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
 
                if (mustfix_fsck_err_on(bpos_ge(expected_start,
                                                cur->data->max_key), c,
+                               btree_node_topology_overwritten_by_prev_node,
                                "btree node overwritten by prev node at btree %s level %u:\n"
                                "  prev %s\n"
                                "  node %s",
@@ -320,6 +321,7 @@ static int btree_repair_node_boundaries(struct bch_fs *c, struct btree *b,
                }
 
                if (mustfix_fsck_err_on(!bpos_eq(expected_start, cur->data->min_key), c,
+                               btree_node_topology_bad_min_key,
                                "btree node with incorrect min_key at btree %s level %u:\n"
                                "  prev %s\n"
                                "  node %s",
@@ -344,6 +346,7 @@ static int btree_repair_node_end(struct bch_fs *c, struct btree *b,
        bch2_bpos_to_text(&buf2, b->key.k.p);
 
        if (mustfix_fsck_err_on(!bpos_eq(child->key.k.p, b->key.k.p), c,
+                               btree_node_topology_bad_max_key,
                        "btree node with incorrect max_key at btree %s level %u:\n"
                        "  %s\n"
                        "  expected %s",
@@ -396,6 +399,7 @@ again:
                bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(cur_k.k));
 
                if (mustfix_fsck_err_on(ret == -EIO, c,
+                               btree_node_unreadable,
                                "Topology repair: unreadable btree node at btree %s level %u:\n"
                                "  %s",
                                bch2_btree_id_str(b->c.btree_id),
@@ -504,6 +508,7 @@ again:
        bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
 
        if (mustfix_fsck_err_on(!have_child, c,
+                       btree_node_topology_interior_node_empty,
                        "empty interior btree node at btree %s level %u\n"
                        "  %s",
                        bch2_btree_id_str(b->c.btree_id),
@@ -582,7 +587,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
 
                if (!g->gen_valid &&
                    (c->opts.reconstruct_alloc ||
-                    fsck_err(c, "bucket %u:%zu data type %s ptr gen %u missing in alloc btree\n"
+                    fsck_err(c, ptr_to_missing_alloc_key,
+                             "bucket %u:%zu data type %s ptr gen %u missing in alloc btree\n"
                              "while marking %s",
                              p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
                              bch2_data_types[ptr_data_type(k->k, &p.ptr)],
@@ -599,7 +605,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
 
                if (gen_cmp(p.ptr.gen, g->gen) > 0 &&
                    (c->opts.reconstruct_alloc ||
-                    fsck_err(c, "bucket %u:%zu data type %s ptr gen in the future: %u > %u\n"
+                    fsck_err(c, ptr_gen_newer_than_bucket_gen,
+                             "bucket %u:%zu data type %s ptr gen in the future: %u > %u\n"
                              "while marking %s",
                              p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
                              bch2_data_types[ptr_data_type(k->k, &p.ptr)],
@@ -612,7 +619,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
                                g->data_type            = 0;
                                g->dirty_sectors        = 0;
                                g->cached_sectors       = 0;
-                               set_bit(BCH_FS_NEED_ANOTHER_GC, &c->flags);
+                               set_bit(BCH_FS_need_another_gc, &c->flags);
                        } else {
                                do_update = true;
                        }
@@ -620,7 +627,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
 
                if (gen_cmp(g->gen, p.ptr.gen) > BUCKET_GC_GEN_MAX &&
                    (c->opts.reconstruct_alloc ||
-                    fsck_err(c, "bucket %u:%zu gen %u data type %s: ptr gen %u too stale\n"
+                    fsck_err(c, ptr_gen_newer_than_bucket_gen,
+                             "bucket %u:%zu gen %u data type %s: ptr gen %u too stale\n"
                              "while marking %s",
                              p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr), g->gen,
                              bch2_data_types[ptr_data_type(k->k, &p.ptr)],
@@ -631,7 +639,8 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
 
                if (!p.ptr.cached && gen_cmp(p.ptr.gen, g->gen) < 0 &&
                    (c->opts.reconstruct_alloc ||
-                    fsck_err(c, "bucket %u:%zu data type %s stale dirty ptr: %u < %u\n"
+                    fsck_err(c, stale_dirty_ptr,
+                             "bucket %u:%zu data type %s stale dirty ptr: %u < %u\n"
                              "while marking %s",
                              p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
                              bch2_data_types[ptr_data_type(k->k, &p.ptr)],
@@ -645,6 +654,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
 
                if (fsck_err_on(bucket_data_type(g->data_type) &&
                                bucket_data_type(g->data_type) != data_type, c,
+                               ptr_bucket_data_type_mismatch,
                                "bucket %u:%zu different types of data in same bucket: %s, %s\n"
                                "while marking %s",
                                p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr),
@@ -654,7 +664,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
                                 bch2_bkey_val_to_text(&buf, c, *k), buf.buf))) {
                        if (data_type == BCH_DATA_btree) {
                                g->data_type    = data_type;
-                               set_bit(BCH_FS_NEED_ANOTHER_GC, &c->flags);
+                               set_bit(BCH_FS_need_another_gc, &c->flags);
                        } else {
                                do_update = true;
                        }
@@ -664,6 +674,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
                        struct gc_stripe *m = genradix_ptr(&c->gc_stripes, p.ec.idx);
 
                        if (fsck_err_on(!m || !m->alive, c,
+                                       ptr_to_missing_stripe,
                                        "pointer to nonexistent stripe %llu\n"
                                        "while marking %s",
                                        (u64) p.ec.idx,
@@ -672,6 +683,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
                                do_update = true;
 
                        if (fsck_err_on(m && m->alive && !bch2_ptr_matches_stripe_m(m, p), c,
+                                       ptr_to_incorrect_stripe,
                                        "pointer does not match stripe %llu\n"
                                        "while marking %s",
                                        (u64) p.ec.idx,
@@ -811,6 +823,7 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
                        goto err;
 
                if (fsck_err_on(k->k->version.lo > atomic64_read(&c->key_version), c,
+                               bkey_version_in_future,
                                "key version number higher than recorded: %llu > %llu",
                                k->k->version.lo,
                                atomic64_read(&c->key_version)))
@@ -968,6 +981,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b
                                          FSCK_CAN_FIX|
                                          FSCK_CAN_IGNORE|
                                          FSCK_NO_RATELIMIT,
+                                         btree_node_read_error,
                                          "Unreadable btree node at btree %s level %u:\n"
                                          "  %s",
                                          bch2_btree_id_str(b->c.btree_id),
@@ -982,7 +996,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b
                                        /* Continue marking when opted to not
                                         * fix the error: */
                                        ret = 0;
-                                       set_bit(BCH_FS_INITIAL_GC_UNFIXED, &c->flags);
+                                       set_bit(BCH_FS_initial_gc_unfixed, &c->flags);
                                        continue;
                                }
                        } else if (ret) {
@@ -1025,6 +1039,7 @@ static int bch2_gc_btree_init(struct btree_trans *trans,
        printbuf_reset(&buf);
        bch2_bpos_to_text(&buf, b->data->min_key);
        if (mustfix_fsck_err_on(!bpos_eq(b->data->min_key, POS_MIN), c,
+                               btree_root_bad_min_key,
                        "btree root with incorrect min_key: %s", buf.buf)) {
                bch_err(c, "repair unimplemented");
                ret = -BCH_ERR_fsck_repair_unimplemented;
@@ -1034,6 +1049,7 @@ static int bch2_gc_btree_init(struct btree_trans *trans,
        printbuf_reset(&buf);
        bch2_bpos_to_text(&buf, b->data->max_key);
        if (mustfix_fsck_err_on(!bpos_eq(b->data->max_key, SPOS_MAX), c,
+                               btree_root_bad_max_key,
                        "btree root with incorrect max_key: %s", buf.buf)) {
                bch_err(c, "repair unimplemented");
                ret = -BCH_ERR_fsck_repair_unimplemented;
@@ -1210,16 +1226,16 @@ static int bch2_gc_done(struct bch_fs *c,
 
        percpu_down_write(&c->mark_lock);
 
-#define copy_field(_f, _msg, ...)                                      \
+#define copy_field(_err, _f, _msg, ...)                                        \
        if (dst->_f != src->_f &&                                       \
            (!verify ||                                                 \
-            fsck_err(c, _msg ": got %llu, should be %llu"              \
+            fsck_err(c, _err, _msg ": got %llu, should be %llu"        \
                      , ##__VA_ARGS__, dst->_f, src->_f)))              \
                dst->_f = src->_f
-#define copy_dev_field(_f, _msg, ...)                                  \
-       copy_field(_f, "dev %u has wrong " _msg, dev, ##__VA_ARGS__)
-#define copy_fs_field(_f, _msg, ...)                                   \
-       copy_field(_f, "fs has wrong " _msg, ##__VA_ARGS__)
+#define copy_dev_field(_err, _f, _msg, ...)                            \
+       copy_field(_err, _f, "dev %u has wrong " _msg, dev, ##__VA_ARGS__)
+#define copy_fs_field(_err, _f, _msg, ...)                             \
+       copy_field(_err, _f, "fs has wrong " _msg, ##__VA_ARGS__)
 
        for (i = 0; i < ARRAY_SIZE(c->usage); i++)
                bch2_fs_usage_acc_to_base(c, i);
@@ -1230,12 +1246,13 @@ static int bch2_gc_done(struct bch_fs *c,
                        bch2_acc_percpu_u64s((u64 __percpu *) ca->usage_gc,
                                             dev_usage_u64s());
 
-               copy_dev_field(buckets_ec,              "buckets_ec");
-
                for (i = 0; i < BCH_DATA_NR; i++) {
-                       copy_dev_field(d[i].buckets,    "%s buckets", bch2_data_types[i]);
-                       copy_dev_field(d[i].sectors,    "%s sectors", bch2_data_types[i]);
-                       copy_dev_field(d[i].fragmented, "%s fragmented", bch2_data_types[i]);
+                       copy_dev_field(dev_usage_buckets_wrong,
+                                      d[i].buckets,    "%s buckets", bch2_data_types[i]);
+                       copy_dev_field(dev_usage_sectors_wrong,
+                                      d[i].sectors,    "%s sectors", bch2_data_types[i]);
+                       copy_dev_field(dev_usage_fragmented_wrong,
+                                      d[i].fragmented, "%s fragmented", bch2_data_types[i]);
                }
        }
 
@@ -1245,22 +1262,29 @@ static int bch2_gc_done(struct bch_fs *c,
                struct bch_fs_usage *src = (void *)
                        bch2_acc_percpu_u64s((u64 __percpu *) c->usage_gc, nr);
 
-               copy_fs_field(hidden,           "hidden");
-               copy_fs_field(btree,            "btree");
+               copy_fs_field(fs_usage_hidden_wrong,
+                             hidden,           "hidden");
+               copy_fs_field(fs_usage_btree_wrong,
+                             btree,            "btree");
 
                if (!metadata_only) {
-                       copy_fs_field(data,     "data");
-                       copy_fs_field(cached,   "cached");
-                       copy_fs_field(reserved, "reserved");
-                       copy_fs_field(nr_inodes,"nr_inodes");
+                       copy_fs_field(fs_usage_data_wrong,
+                                     data,     "data");
+                       copy_fs_field(fs_usage_cached_wrong,
+                                     cached,   "cached");
+                       copy_fs_field(fs_usage_reserved_wrong,
+                                     reserved, "reserved");
+                       copy_fs_field(fs_usage_nr_inodes_wrong,
+                                     nr_inodes,"nr_inodes");
 
                        for (i = 0; i < BCH_REPLICAS_MAX; i++)
-                               copy_fs_field(persistent_reserved[i],
+                               copy_fs_field(fs_usage_persistent_reserved_wrong,
+                                             persistent_reserved[i],
                                              "persistent_reserved[%i]", i);
                }
 
                for (i = 0; i < c->replicas.nr; i++) {
-                       struct bch_replicas_entry *e =
+                       struct bch_replicas_entry_v1 *e =
                                cpu_replicas_entry(&c->replicas, i);
 
                        if (metadata_only &&
@@ -1271,7 +1295,8 @@ static int bch2_gc_done(struct bch_fs *c,
                        printbuf_reset(&buf);
                        bch2_replicas_entry_to_text(&buf, e);
 
-                       copy_fs_field(replicas[i], "%s", buf.buf);
+                       copy_fs_field(fs_usage_replicas_wrong,
+                                     replicas[i], "%s", buf.buf);
                }
        }
 
@@ -1407,6 +1432,7 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
 
        if (c->opts.reconstruct_alloc ||
            fsck_err_on(new.data_type != gc.data_type, c,
+                       alloc_key_data_type_wrong,
                        "bucket %llu:%llu gen %u has wrong data_type"
                        ": got %s, should be %s",
                        iter->pos.inode, iter->pos.offset,
@@ -1415,9 +1441,9 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
                        bch2_data_types[gc.data_type]))
                new.data_type = gc.data_type;
 
-#define copy_bucket_field(_f)                                          \
+#define copy_bucket_field(_errtype, _f)                                        \
        if (c->opts.reconstruct_alloc ||                                \
-           fsck_err_on(new._f != gc._f, c,                             \
+           fsck_err_on(new._f != gc._f, c, _errtype,                   \
                        "bucket %llu:%llu gen %u data type %s has wrong " #_f   \
                        ": got %u, should be %u",                       \
                        iter->pos.inode, iter->pos.offset,              \
@@ -1426,11 +1452,16 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
                        new._f, gc._f))                                 \
                new._f = gc._f;                                         \
 
-       copy_bucket_field(gen);
-       copy_bucket_field(dirty_sectors);
-       copy_bucket_field(cached_sectors);
-       copy_bucket_field(stripe_redundancy);
-       copy_bucket_field(stripe);
+       copy_bucket_field(alloc_key_gen_wrong,
+                         gen);
+       copy_bucket_field(alloc_key_dirty_sectors_wrong,
+                         dirty_sectors);
+       copy_bucket_field(alloc_key_cached_sectors_wrong,
+                         cached_sectors);
+       copy_bucket_field(alloc_key_stripe_wrong,
+                         stripe);
+       copy_bucket_field(alloc_key_stripe_redundancy_wrong,
+                         stripe_redundancy);
 #undef copy_bucket_field
 
        if (!bch2_alloc_v4_cmp(*old, new))
@@ -1468,7 +1499,7 @@ static int bch2_gc_alloc_done(struct bch_fs *c, bool metadata_only)
                ret = for_each_btree_key_commit(trans, iter, BTREE_ID_alloc,
                                POS(ca->dev_idx, ca->mi.first_bucket),
                                BTREE_ITER_SLOTS|BTREE_ITER_PREFETCH, k,
-                               NULL, NULL, BTREE_INSERT_LAZY_RW,
+                               NULL, NULL, BCH_TRANS_COMMIT_lazy_rw,
                        bch2_alloc_write_key(trans, &iter, k, metadata_only));
 
                if (ret < 0) {
@@ -1510,8 +1541,8 @@ static int bch2_gc_alloc_start(struct bch_fs *c, bool metadata_only)
                rcu_assign_pointer(ca->buckets_gc, buckets);
        }
 
-       for_each_btree_key(trans, iter, BTREE_ID_alloc, POS_MIN,
-                          BTREE_ITER_PREFETCH, k, ret) {
+       ret = for_each_btree_key2(trans, iter, BTREE_ID_alloc, POS_MIN,
+                                 BTREE_ITER_PREFETCH, k, ({
                ca = bch_dev_bkey_exists(c, k.k->p.inode);
                g = gc_bucket(ca, k.k->p.offset);
 
@@ -1530,8 +1561,9 @@ static int bch2_gc_alloc_start(struct bch_fs *c, bool metadata_only)
                        g->stripe               = a->stripe;
                        g->stripe_redundancy    = a->stripe_redundancy;
                }
-       }
-       bch2_trans_iter_exit(trans, &iter);
+
+               0;
+       }));
 err:
        bch2_trans_put(trans);
        if (ret)
@@ -1587,6 +1619,7 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
        }
 
        if (fsck_err_on(r->refcount != le64_to_cpu(*refcount), c,
+                       reflink_v_refcount_wrong,
                        "reflink key has wrong refcount:\n"
                        "  %s\n"
                        "  should be %u",
@@ -1624,7 +1657,7 @@ static int bch2_gc_reflink_done(struct bch_fs *c, bool metadata_only)
        ret = for_each_btree_key_commit(trans, iter,
                        BTREE_ID_reflink, POS_MIN,
                        BTREE_ITER_PREFETCH, k,
-                       NULL, NULL, BTREE_INSERT_NOFAIL,
+                       NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
                bch2_gc_write_reflink_key(trans, &iter, k, &idx));
 
        c->reflink_gc_nr = 0;
@@ -1712,7 +1745,8 @@ static int bch2_gc_write_stripes_key(struct btree_trans *trans,
        if (bad)
                bch2_bkey_val_to_text(&buf, c, k);
 
-       if (fsck_err_on(bad, c, "%s", buf.buf)) {
+       if (fsck_err_on(bad, c, stripe_sector_count_wrong,
+                       "%s", buf.buf)) {
                struct bkey_i_stripe *new;
 
                new = bch2_trans_kmalloc(trans, bkey_bytes(k.k));
@@ -1747,7 +1781,7 @@ static int bch2_gc_stripes_done(struct bch_fs *c, bool metadata_only)
        ret = for_each_btree_key_commit(trans, iter,
                        BTREE_ID_stripes, POS_MIN,
                        BTREE_ITER_PREFETCH, k,
-                       NULL, NULL, BTREE_INSERT_NOFAIL,
+                       NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
                bch2_gc_write_stripes_key(trans, &iter, k));
 
        bch2_trans_put(trans);
@@ -1814,7 +1848,7 @@ again:
 #endif
        c->gc_count++;
 
-       if (test_bit(BCH_FS_NEED_ANOTHER_GC, &c->flags) ||
+       if (test_bit(BCH_FS_need_another_gc, &c->flags) ||
            (!iter && bch2_test_restart_gc)) {
                if (iter++ > 2) {
                        bch_info(c, "Unable to fix bucket gens, looping");
@@ -1826,7 +1860,7 @@ again:
                 * XXX: make sure gens we fixed got saved
                 */
                bch_info(c, "Second GC pass needed, restarting:");
-               clear_bit(BCH_FS_NEED_ANOTHER_GC, &c->flags);
+               clear_bit(BCH_FS_need_another_gc, &c->flags);
                __gc_pos_set(c, gc_phase(GC_PHASE_NOT_RUNNING));
 
                bch2_gc_stripes_reset(c, metadata_only);
@@ -1983,7 +2017,7 @@ int bch2_gc_gens(struct bch_fs *c)
                                        BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS,
                                        k,
                                        NULL, NULL,
-                                       BTREE_INSERT_NOFAIL,
+                                       BCH_TRANS_COMMIT_no_enospc,
                                gc_btree_gens_key(trans, &iter, k));
                        if (ret && !bch2_err_matches(ret, EROFS))
                                bch_err_fn(c, ret);
@@ -1996,7 +2030,7 @@ int bch2_gc_gens(struct bch_fs *c)
                        BTREE_ITER_PREFETCH,
                        k,
                        NULL, NULL,
-                       BTREE_INSERT_NOFAIL,
+                       BCH_TRANS_COMMIT_no_enospc,
                bch2_alloc_write_oldest_gen(trans, &iter, k));
        if (ret && !bch2_err_matches(ret, EROFS))
                bch_err_fn(c, ret);