]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Fix bch2_sort_repack_merge()
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 21 Aug 2019 22:35:15 +0000 (18:35 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:25 +0000 (17:08 -0400)
bch2_bkey_normalize() modifies the value, and we were modifying the
original value in the src btree node - but, we're called without a write
lock held on the src node. Oops...

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bkey_sort.c
fs/bcachefs/extents.c

index 9f5d9b4bf1c9528f0566cafc282de6cc2f37b5fa..e32fad5a91acaf7507178358b8d3915efd88e0ed 100644 (file)
@@ -415,25 +415,22 @@ bch2_sort_repack_merge(struct bch_fs *c,
                       struct bkey_format *out_f,
                       bool filter_whiteouts)
 {
-       struct bkey_packed *prev = NULL, *k_packed, *next;
-       struct bkey k_unpacked;
+       struct bkey_packed *prev = NULL, *k_packed;
        struct bkey_s k;
        struct btree_nr_keys nr;
+       BKEY_PADDED(k) tmp;
 
        memset(&nr, 0, sizeof(nr));
 
-       next = bch2_btree_node_iter_next_all(iter, src);
-       while ((k_packed = next)) {
-               /*
-                * The filter might modify the size of @k's value, so advance
-                * the iterator first:
-                */
-               next = bch2_btree_node_iter_next_all(iter, src);
-
+       while ((k_packed = bch2_btree_node_iter_next_all(iter, src))) {
                if (filter_whiteouts && bkey_whiteout(k_packed))
                        continue;
 
-               k = __bkey_disassemble(src, k_packed, &k_unpacked);
+               EBUG_ON(bkeyp_val_u64s(&src->format, k_packed) >
+                       BKEY_EXTENT_VAL_U64s_MAX);
+
+               bch2_bkey_unpack(src, &tmp.k, k_packed);
+               k = bkey_i_to_s(&tmp.k);
 
                if (filter_whiteouts &&
                    bch2_bkey_normalize(c, k))
index 81ec55526ce9716df5cb2f4c1737a49164a3aa76..779ee42350ad9e97f5df0bd0b8e55658bb919ba2 100644 (file)
@@ -1590,9 +1590,9 @@ bool bch2_extent_normalize(struct bch_fs *c, struct bkey_s k)
 
        /* will only happen if all pointers were cached: */
        if (!bkey_val_u64s(k.k))
-               k.k->type = KEY_TYPE_deleted;
+               k.k->type = KEY_TYPE_discard;
 
-       return false;
+       return bkey_whiteout(k.k);
 }
 
 void bch2_bkey_mark_replicas_cached(struct bch_fs *c, struct bkey_s k,