]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to 6628827a8707 bcachefs: Skip deleted members in member_to_t...
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 27 Oct 2023 23:38:36 +0000 (19:38 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 27 Oct 2023 23:38:36 +0000 (19:38 -0400)
14 files changed:
.bcachefs_revision
libbcachefs/btree_iter.c
libbcachefs/btree_key_cache.c
libbcachefs/btree_locking.c
libbcachefs/btree_locking.h
libbcachefs/btree_trans_commit.c
libbcachefs/btree_types.h
libbcachefs/btree_update_interior.c
libbcachefs/buckets.c
libbcachefs/data_update.c
libbcachefs/io_misc.c
libbcachefs/io_misc.h
libbcachefs/sb-members.c
libbcachefs/trace.h

index e904af2ab99defa0a6c503306cc0d7431ccb6ba8..0476cc0ead1a5ab034a149c45e1379be5e6832bd 100644 (file)
@@ -1 +1 @@
-7250b2ee5574d7e2063c4498dde98ba11e2fd35f
+6628827a87075d3f807c974045ed293ac1e8965b
index eff7630a8e6ecf3184d1879804e5fd974c0f28f2..feba9a315c8ce0657de9cd30322aa47f3f420af4 100644 (file)
@@ -1523,6 +1523,7 @@ static inline struct btree_path *btree_path_alloc(struct btree_trans *trans,
        path->ref               = 0;
        path->intent_ref        = 0;
        path->nodes_locked      = 0;
+       path->alloc_seq++;
 
        btree_path_list_add(trans, pos, path);
        trans->paths_sorted = false;
@@ -1598,7 +1599,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
 
        locks_want = min(locks_want, BTREE_MAX_DEPTH);
        if (locks_want > path->locks_want)
-               bch2_btree_path_upgrade_noupgrade_sibs(trans, path, locks_want);
+               bch2_btree_path_upgrade_noupgrade_sibs(trans, path, locks_want, NULL);
 
        return path;
 }
index 0603e054d7fc0e3339616e22594f6c64abffc291..98aeedb7c22a2062e401803064fe7436e26b23f0 100644 (file)
@@ -510,7 +510,7 @@ fill:
                 * path->uptodate yet:
                 */
                if (!path->locks_want &&
-                   !__bch2_btree_path_upgrade(trans, path, 1)) {
+                   !__bch2_btree_path_upgrade(trans, path, 1, NULL)) {
                        trace_and_count(trans->c, trans_restart_key_cache_upgrade, trans, _THIS_IP_);
                        ret = btree_trans_restart(trans, BCH_ERR_transaction_restart_key_cache_upgrade);
                        goto err;
index 0b0f9d607798842ca9c9877a95992eaf1ca9c619..ba263302585d6ab62f71e48fe2d09eca8a910280 100644 (file)
@@ -430,7 +430,8 @@ void bch2_btree_node_lock_write_nofail(struct btree_trans *trans,
 
 static inline bool btree_path_get_locks(struct btree_trans *trans,
                                        struct btree_path *path,
-                                       bool upgrade)
+                                       bool upgrade,
+                                       struct get_locks_fail *f)
 {
        unsigned l = path->level;
        int fail_idx = -1;
@@ -441,8 +442,14 @@ static inline bool btree_path_get_locks(struct btree_trans *trans,
 
                if (!(upgrade
                      ? bch2_btree_node_upgrade(trans, path, l)
-                     : bch2_btree_node_relock(trans, path, l)))
-                       fail_idx = l;
+                     : bch2_btree_node_relock(trans, path, l))) {
+                       fail_idx        = l;
+
+                       if (f) {
+                               f->l    = l;
+                               f->b    = path->l[l].b;
+                       }
+               }
 
                l++;
        } while (l < path->locks_want);
@@ -583,7 +590,9 @@ __flatten
 bool bch2_btree_path_relock_norestart(struct btree_trans *trans,
                        struct btree_path *path, unsigned long trace_ip)
 {
-       return btree_path_get_locks(trans, path, false);
+       struct get_locks_fail f;
+
+       return btree_path_get_locks(trans, path, false, &f);
 }
 
 int __bch2_btree_path_relock(struct btree_trans *trans,
@@ -599,22 +608,24 @@ int __bch2_btree_path_relock(struct btree_trans *trans,
 
 bool bch2_btree_path_upgrade_noupgrade_sibs(struct btree_trans *trans,
                               struct btree_path *path,
-                              unsigned new_locks_want)
+                              unsigned new_locks_want,
+                              struct get_locks_fail *f)
 {
        EBUG_ON(path->locks_want >= new_locks_want);
 
        path->locks_want = new_locks_want;
 
-       return btree_path_get_locks(trans, path, true);
+       return btree_path_get_locks(trans, path, true, f);
 }
 
 bool __bch2_btree_path_upgrade(struct btree_trans *trans,
                               struct btree_path *path,
-                              unsigned new_locks_want)
+                              unsigned new_locks_want,
+                              struct get_locks_fail *f)
 {
        struct btree_path *linked;
 
-       if (bch2_btree_path_upgrade_noupgrade_sibs(trans, path, new_locks_want))
+       if (bch2_btree_path_upgrade_noupgrade_sibs(trans, path, new_locks_want, f))
                return true;
 
        /*
@@ -643,7 +654,7 @@ bool __bch2_btree_path_upgrade(struct btree_trans *trans,
                            linked->btree_id == path->btree_id &&
                            linked->locks_want < new_locks_want) {
                                linked->locks_want = new_locks_want;
-                               btree_path_get_locks(trans, linked, true);
+                               btree_path_get_locks(trans, linked, true, NULL);
                        }
 
        return false;
@@ -655,6 +666,9 @@ void __bch2_btree_path_downgrade(struct btree_trans *trans,
 {
        unsigned l;
 
+       if (trans->restarted)
+               return;
+
        EBUG_ON(path->locks_want < new_locks_want);
 
        path->locks_want = new_locks_want;
@@ -673,6 +687,9 @@ void __bch2_btree_path_downgrade(struct btree_trans *trans,
        }
 
        bch2_btree_path_verify_locks(path);
+
+       path->downgrade_seq++;
+       trace_path_downgrade(trans, _RET_IP_, path);
 }
 
 /* Btree transaction locking: */
@@ -681,6 +698,9 @@ void bch2_trans_downgrade(struct btree_trans *trans)
 {
        struct btree_path *path;
 
+       if (trans->restarted)
+               return;
+
        trans_for_each_path(trans, path)
                bch2_btree_path_downgrade(trans, path);
 }
index 6231e9ffc5d7497b693febe166e64560a6f024c9..11b0a2c8cd691b21afccdcc38486aa060351f62a 100644 (file)
@@ -355,26 +355,36 @@ static inline bool bch2_btree_node_relock_notrace(struct btree_trans *trans,
 
 /* upgrade */
 
+
+struct get_locks_fail {
+       unsigned        l;
+       struct btree    *b;
+};
+
 bool bch2_btree_path_upgrade_noupgrade_sibs(struct btree_trans *,
-                              struct btree_path *, unsigned);
+                              struct btree_path *, unsigned,
+                              struct get_locks_fail *);
+
 bool __bch2_btree_path_upgrade(struct btree_trans *,
-                              struct btree_path *, unsigned);
+                              struct btree_path *, unsigned,
+                              struct get_locks_fail *);
 
 static inline int bch2_btree_path_upgrade(struct btree_trans *trans,
                                          struct btree_path *path,
                                          unsigned new_locks_want)
 {
+       struct get_locks_fail f;
        unsigned old_locks_want = path->locks_want;
 
        new_locks_want = min(new_locks_want, BTREE_MAX_DEPTH);
 
        if (path->locks_want < new_locks_want
-           ? __bch2_btree_path_upgrade(trans, path, new_locks_want)
+           ? __bch2_btree_path_upgrade(trans, path, new_locks_want, &f)
            : path->uptodate == BTREE_ITER_UPTODATE)
                return 0;
 
        trace_and_count(trans->c, trans_restart_upgrade, trans, _THIS_IP_, path,
-                       old_locks_want, new_locks_want);
+                       old_locks_want, new_locks_want, &f);
        return btree_trans_restart(trans, BCH_ERR_transaction_restart_upgrade);
 }
 
index 53ddcaf042a20b255f6e73bb5a72d42d77c03e7a..8140b6e6e9a65245615397dd60489feb57240da1 100644 (file)
@@ -861,12 +861,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
         */
        bch2_journal_res_put(&c->journal, &trans->journal_res);
 
-       if (unlikely(ret))
-               return ret;
-
-       bch2_trans_downgrade(trans);
-
-       return 0;
+       return ret;
 }
 
 static int journal_reclaim_wait_done(struct bch_fs *c)
@@ -1135,6 +1130,8 @@ out:
        if (likely(!(flags & BTREE_INSERT_NOCHECK_RW)))
                bch2_write_ref_put(c, BCH_WRITE_REF_trans);
 out_reset:
+       if (!ret)
+               bch2_trans_downgrade(trans);
        bch2_trans_reset_updates(trans);
 
        return ret;
index 9a4d97f9c3a9be5c2c7fd41f4bc951f6d5246bfe..cbcb04a45e8eed4ba27a51022e323e511436c704 100644 (file)
@@ -238,6 +238,8 @@ struct btree_path {
        u8                      sorted_idx;
        u8                      ref;
        u8                      intent_ref;
+       u32                     alloc_seq;
+       u32                     downgrade_seq;
 
        /* btree_iter_copy starts here: */
        struct bpos             pos;
index 818a83f35d276149ebbcdd2d1e1430f4c281cae1..d029e0348c918a292d596af7ce520588235ccabd 100644 (file)
@@ -1987,7 +1987,7 @@ int bch2_btree_node_rewrite(struct btree_trans *trans,
 out:
        if (new_path)
                bch2_path_put(trans, new_path, true);
-       bch2_btree_path_downgrade(trans, iter->path);
+       bch2_trans_downgrade(trans);
        return ret;
 err:
        bch2_btree_node_free_never_used(as, trans, n);
index 2acd727d3f9b142b329fa2cdb35a9f0fb8623f17..58d8c6ffd955429d9f13207ddf04c1f687a68b2e 100644 (file)
@@ -1322,7 +1322,7 @@ int bch2_trans_fs_usage_apply(struct btree_trans *trans,
        struct bch_fs *c = trans->c;
        static int warned_disk_usage = 0;
        bool warn = false;
-       unsigned disk_res_sectors = trans->disk_res ? trans->disk_res->sectors : 0;
+       u64 disk_res_sectors = trans->disk_res ? trans->disk_res->sectors : 0;
        struct replicas_delta *d, *d2;
        struct replicas_delta *top = (void *) deltas->d + deltas->used;
        struct bch_fs_usage *dst;
@@ -1381,7 +1381,7 @@ int bch2_trans_fs_usage_apply(struct btree_trans *trans,
 
        if (unlikely(warn) && !xchg(&warned_disk_usage, 1))
                bch2_trans_inconsistent(trans,
-                                       "disk usage increased %lli more than %u sectors reserved)",
+                                       "disk usage increased %lli more than %llu sectors reserved)",
                                        should_not_have_added, disk_res_sectors);
        return 0;
 need_mark:
index d116f2f03db24a8949ac9bc728cfea2b80e9ce30..0771a6d880bf5e2e4efcbcc21d91d34b64160dd4 100644 (file)
@@ -162,11 +162,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
                        if (((1U << i) & m->data_opts.rewrite_ptrs) &&
                            (ptr = bch2_extent_has_ptr(old, p, bkey_i_to_s(insert))) &&
                            !ptr->cached) {
-                               bch2_bkey_drop_ptr_noerror(bkey_i_to_s(insert), ptr);
-                               /*
-                                * See comment below:
                                bch2_extent_ptr_set_cached(bkey_i_to_s(insert), ptr);
-                               */
                                rewrites_found |= 1U << i;
                        }
                        i++;
@@ -212,14 +208,8 @@ restart_drop_extra_replicas:
                        if (!p.ptr.cached &&
                            durability - ptr_durability >= m->op.opts.data_replicas) {
                                durability -= ptr_durability;
-                               bch2_bkey_drop_ptr_noerror(bkey_i_to_s(insert), &entry->ptr);
-                               /*
-                                * Currently, we're dropping unneeded replicas
-                                * instead of marking them as cached, since
-                                * cached data in stripe buckets prevents them
-                                * from being reused:
+
                                bch2_extent_ptr_set_cached(bkey_i_to_s(insert), &entry->ptr);
-                               */
                                goto restart_drop_extra_replicas;
                        }
                }
index 0979d5e05713e4769af3b8ff299d7b0a737a7ce7..bebc11444ef5ec598ef83c475716ea789b33bf69 100644 (file)
@@ -23,7 +23,7 @@
 int bch2_extent_fallocate(struct btree_trans *trans,
                          subvol_inum inum,
                          struct btree_iter *iter,
-                         unsigned sectors,
+                         u64 sectors,
                          struct bch_io_opts opts,
                          s64 *i_sectors_delta,
                          struct write_point_specifier write_point)
@@ -105,7 +105,7 @@ int bch2_extent_fallocate(struct btree_trans *trans,
                if (ret)
                        goto err;
 
-               sectors = min(sectors, wp->sectors_free);
+               sectors = min_t(u64, sectors, wp->sectors_free);
                sectors_allocated = sectors;
 
                bch2_key_resize(&e->k, sectors);
index c9e6ed40e1b80c6582d40d0db40b9c1e3eef807d..9cb44a7c43c1714678ef27d4ead33b29ac567849 100644 (file)
@@ -3,7 +3,7 @@
 #define _BCACHEFS_IO_MISC_H
 
 int bch2_extent_fallocate(struct btree_trans *, subvol_inum, struct btree_iter *,
-                         unsigned, struct bch_io_opts, s64 *,
+                         u64, struct bch_io_opts, s64 *,
                          struct write_point_specifier);
 int bch2_fpunch_at(struct btree_trans *, struct btree_iter *,
                   subvol_inum, u64, s64 *);
index 032fe45481d3d088ecd2e13dee5f1c9e91fbef1c..ab5de12eca4acdf230a4e26fee884cff059c6ef8 100644 (file)
@@ -168,6 +168,9 @@ static void member_to_text(struct printbuf *out,
        u64 bucket_size = le16_to_cpu(m.bucket_size);
        u64 device_size = le64_to_cpu(m.nbuckets) * bucket_size;
 
+       if (!bch2_member_exists(&m))
+               return;
+
        prt_printf(out, "Device:");
        prt_tab(out);
        prt_printf(out, "%u", i);
@@ -304,10 +307,8 @@ static void bch2_sb_members_v1_to_text(struct printbuf *out, struct bch_sb *sb,
        struct bch_sb_field_disk_groups *gi = bch2_sb_field_get(sb, disk_groups);
        unsigned i;
 
-       for (i = 0; i < sb->nr_devices; i++) {
-               struct bch_member m = members_v1_get(mi, i);
-               member_to_text(out, m, gi, sb, i);
-       }
+       for (i = 0; i < sb->nr_devices; i++)
+               member_to_text(out, members_v1_get(mi, i), gi, sb, i);
 }
 
 const struct bch_sb_field_ops bch_sb_field_ops_members_v1 = {
@@ -322,10 +323,8 @@ static void bch2_sb_members_v2_to_text(struct printbuf *out, struct bch_sb *sb,
        struct bch_sb_field_disk_groups *gi = bch2_sb_field_get(sb, disk_groups);
        unsigned i;
 
-       for (i = 0; i < sb->nr_devices; i++) {
-               struct bch_member m = members_v2_get(mi, i);
-               member_to_text(out, m, gi, sb, i);
-       }
+       for (i = 0; i < sb->nr_devices; i++)
+               member_to_text(out, members_v2_get(mi, i), gi, sb, i);
 }
 
 static int bch2_sb_members_v2_validate(struct bch_sb *sb,
index 81f72b2add09a5dc250cfe8646d2b9a37cbaa45b..893304a1f06e6ea03df55020cf7be26f349d8cfe 100644 (file)
@@ -1043,13 +1043,16 @@ DEFINE_EVENT(transaction_restart_iter,  trans_restart_btree_node_split,
        TP_ARGS(trans, caller_ip, path)
 );
 
+struct get_locks_fail;
+
 TRACE_EVENT(trans_restart_upgrade,
        TP_PROTO(struct btree_trans *trans,
                 unsigned long caller_ip,
                 struct btree_path *path,
                 unsigned old_locks_want,
-                unsigned new_locks_want),
-       TP_ARGS(trans, caller_ip, path, old_locks_want, new_locks_want),
+                unsigned new_locks_want,
+                struct get_locks_fail *f),
+       TP_ARGS(trans, caller_ip, path, old_locks_want, new_locks_want, f),
 
        TP_STRUCT__entry(
                __array(char,                   trans_fn, 32    )
@@ -1057,6 +1060,11 @@ TRACE_EVENT(trans_restart_upgrade,
                __field(u8,                     btree_id        )
                __field(u8,                     old_locks_want  )
                __field(u8,                     new_locks_want  )
+               __field(u8,                     level           )
+               __field(u32,                    path_seq        )
+               __field(u32,                    node_seq        )
+               __field(u32,                    path_alloc_seq  )
+               __field(u32,                    downgrade_seq)
                TRACE_BPOS_entries(pos)
        ),
 
@@ -1066,10 +1074,15 @@ TRACE_EVENT(trans_restart_upgrade,
                __entry->btree_id               = path->btree_id;
                __entry->old_locks_want         = old_locks_want;
                __entry->new_locks_want         = new_locks_want;
+               __entry->level                  = f->l;
+               __entry->path_seq               = path->l[f->l].lock_seq;
+               __entry->node_seq               = IS_ERR_OR_NULL(f->b) ? 0 : f->b->c.lock.seq;
+               __entry->path_alloc_seq         = path->alloc_seq;
+               __entry->downgrade_seq          = path->downgrade_seq;
                TRACE_BPOS_assign(pos, path->pos)
        ),
 
-       TP_printk("%s %pS btree %s pos %llu:%llu:%u locks_want %u -> %u",
+       TP_printk("%s %pS btree %s pos %llu:%llu:%u locks_want %u -> %u level %u path seq %u node seq %u alloc_seq %u downgrade_seq %u",
                  __entry->trans_fn,
                  (void *) __entry->caller_ip,
                  bch2_btree_id_str(__entry->btree_id),
@@ -1077,7 +1090,12 @@ TRACE_EVENT(trans_restart_upgrade,
                  __entry->pos_offset,
                  __entry->pos_snapshot,
                  __entry->old_locks_want,
-                 __entry->new_locks_want)
+                 __entry->new_locks_want,
+                 __entry->level,
+                 __entry->path_seq,
+                 __entry->node_seq,
+                 __entry->path_alloc_seq,
+                 __entry->downgrade_seq)
 );
 
 DEFINE_EVENT(transaction_restart_iter, trans_restart_relock,
@@ -1238,6 +1256,27 @@ TRACE_EVENT(trans_restart_key_cache_key_realloced,
                  __entry->new_u64s)
 );
 
+TRACE_EVENT(path_downgrade,
+       TP_PROTO(struct btree_trans *trans,
+                unsigned long caller_ip,
+                struct btree_path *path),
+       TP_ARGS(trans, caller_ip, path),
+
+       TP_STRUCT__entry(
+               __array(char,                   trans_fn, 32    )
+               __field(unsigned long,          caller_ip       )
+       ),
+
+       TP_fast_assign(
+               strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
+               __entry->caller_ip              = caller_ip;
+       ),
+
+       TP_printk("%s %pS",
+                 __entry->trans_fn,
+                 (void *) __entry->caller_ip)
+);
+
 DEFINE_EVENT(transaction_event,        trans_restart_write_buffer_flush,
        TP_PROTO(struct btree_trans *trans,
                 unsigned long caller_ip),