diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-04-28 23:49:30 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:06 -0400 |
commit | 59ba21d99fc7a19d32fc4c2cb21509b8876d8e01 (patch) | |
tree | 850853ae1082de0d8a6c00698a795bd9945dca41 /fs/bcachefs/extents.c | |
parent | cd8319fdd91a600594b2edb6c6eed65dc74354c8 (diff) | |
download | lwn-59ba21d99fc7a19d32fc4c2cb21509b8876d8e01.tar.gz lwn-59ba21d99fc7a19d32fc4c2cb21509b8876d8e01.zip |
bcachefs: Clean up key merging
This patch simplifies the key merging code by getting rid of partial
merges - it's simpler and saner if we just don't merge extents when
they'd overflow k->size.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/extents.c')
-rw-r--r-- | fs/bcachefs/extents.c | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c index 1f28dea26ca2..2ced3557e13b 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -229,17 +229,16 @@ void bch2_extent_to_text(struct printbuf *out, struct bch_fs *c, bch2_bkey_ptrs_to_text(out, c, k); } -enum merge_result bch2_extent_merge(struct bch_fs *c, - struct bkey_s _l, struct bkey_s _r) +bool bch2_extent_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r) { struct bkey_s_extent l = bkey_s_to_extent(_l); - struct bkey_s_extent r = bkey_s_to_extent(_r); + struct bkey_s_c_extent r = bkey_s_c_to_extent(_r); union bch_extent_entry *en_l = l.v->start; - union bch_extent_entry *en_r = r.v->start; + const union bch_extent_entry *en_r = r.v->start; struct bch_extent_crc_unpacked crc_l, crc_r; if (bkey_val_u64s(l.k) != bkey_val_u64s(r.k)) - return BCH_MERGE_NOMERGE; + return false; crc_l = bch2_extent_crc_unpack(l.k, NULL); @@ -247,7 +246,7 @@ enum merge_result bch2_extent_merge(struct bch_fs *c, en_r = vstruct_idx(r.v, (u64 *) en_l - l.v->_data); if (extent_entry_type(en_l) != extent_entry_type(en_r)) - return BCH_MERGE_NOMERGE; + return false; switch (extent_entry_type(en_l)) { case BCH_EXTENT_ENTRY_ptr: { @@ -258,20 +257,20 @@ enum merge_result bch2_extent_merge(struct bch_fs *c, if (lp->offset + crc_l.compressed_size != rp->offset || lp->dev != rp->dev || lp->gen != rp->gen) - return BCH_MERGE_NOMERGE; + return false; /* We don't allow extents to straddle buckets: */ ca = bch_dev_bkey_exists(c, lp->dev); if (PTR_BUCKET_NR(ca, lp) != PTR_BUCKET_NR(ca, rp)) - return BCH_MERGE_NOMERGE; + return false; break; } case BCH_EXTENT_ENTRY_stripe_ptr: if (en_l->stripe_ptr.block != en_r->stripe_ptr.block || en_l->stripe_ptr.idx != en_r->stripe_ptr.idx) - return BCH_MERGE_NOMERGE; + return false; break; case BCH_EXTENT_ENTRY_crc32: case BCH_EXTENT_ENTRY_crc64: @@ -282,30 +281,30 @@ enum merge_result bch2_extent_merge(struct bch_fs *c, if (crc_l.csum_type != crc_r.csum_type || crc_l.compression_type != crc_r.compression_type || crc_l.nonce != crc_r.nonce) - return BCH_MERGE_NOMERGE; + return false; if (crc_l.offset + crc_l.live_size != crc_l.compressed_size || crc_r.offset) - return BCH_MERGE_NOMERGE; + return false; if (!bch2_checksum_mergeable(crc_l.csum_type)) - return BCH_MERGE_NOMERGE; + return false; if (crc_is_compressed(crc_l)) - return BCH_MERGE_NOMERGE; + return false; if (crc_l.csum_type && crc_l.uncompressed_size + crc_r.uncompressed_size > c->sb.encoded_extent_max) - return BCH_MERGE_NOMERGE; + return false; if (crc_l.uncompressed_size + crc_r.uncompressed_size > bch2_crc_field_size_max[extent_entry_type(en_l)]) - return BCH_MERGE_NOMERGE; + return false; break; default: - return BCH_MERGE_NOMERGE; + return false; } } @@ -333,8 +332,7 @@ enum merge_result bch2_extent_merge(struct bch_fs *c, } bch2_key_resize(l.k, l.k->size + r.k->size); - - return BCH_MERGE_MERGE; + return true; } /* KEY_TYPE_reservation: */ @@ -362,25 +360,17 @@ void bch2_reservation_to_text(struct printbuf *out, struct bch_fs *c, r.v->nr_replicas); } -enum merge_result bch2_reservation_merge(struct bch_fs *c, - struct bkey_s _l, struct bkey_s _r) +bool bch2_reservation_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r) { struct bkey_s_reservation l = bkey_s_to_reservation(_l); - struct bkey_s_reservation r = bkey_s_to_reservation(_r); + struct bkey_s_c_reservation r = bkey_s_c_to_reservation(_r); if (l.v->generation != r.v->generation || l.v->nr_replicas != r.v->nr_replicas) - return BCH_MERGE_NOMERGE; - - if ((u64) l.k->size + r.k->size > KEY_SIZE_MAX) { - bch2_key_resize(l.k, KEY_SIZE_MAX); - bch2_cut_front_s(l.k->p, r.s); - return BCH_MERGE_PARTIAL; - } + return false; bch2_key_resize(l.k, l.k->size + r.k->size); - - return BCH_MERGE_MERGE; + return true; } /* Extent checksum entries: */ |