summaryrefslogtreecommitdiff
path: root/fs/bcachefs/buckets.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-12-06 11:52:58 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:13 -0400
commit641ab736437a3f9881467c0005b0d677194fff63 (patch)
tree1b20da644db6b5cf9c3341c28f63124e2971a0d1 /fs/bcachefs/buckets.c
parent57cb2142ed1aadf2bf737f732bc74e5649dbcb15 (diff)
downloadlwn-641ab736437a3f9881467c0005b0d677194fff63.tar.gz
lwn-641ab736437a3f9881467c0005b0d677194fff63.zip
bcachefs: improve/clarify ptr_disk_sectors()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/buckets.c')
-rw-r--r--fs/bcachefs/buckets.c47
1 files changed, 19 insertions, 28 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index c4fe703d1681..ab68c5138ade 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -558,36 +558,25 @@ void bch2_mark_metadata_bucket(struct bch_fs *c, struct bch_dev *ca,
preempt_enable();
}
-static int __disk_sectors(struct bch_extent_crc_unpacked crc, unsigned sectors)
+static s64 ptr_disk_sectors_delta(struct extent_ptr_decoded p,
+ s64 delta)
{
- if (!sectors)
- return 0;
-
- return max(1U, DIV_ROUND_UP(sectors * crc.compressed_size,
- crc.uncompressed_size));
-}
-
-static s64 ptr_disk_sectors(const struct bkey *k,
- struct extent_ptr_decoded p,
- s64 sectors)
-{
-
- if (p.crc.compression_type) {
- unsigned old_sectors, new_sectors;
-
- if (sectors > 0) {
- old_sectors = 0;
- new_sectors = sectors;
- } else {
- old_sectors = k->size;
- new_sectors = k->size + sectors;
- }
+ if (delta > 0) {
+ /*
+ * marking a new extent, which _will have size_ @delta
+ *
+ * in the bch2_mark_update -> BCH_EXTENT_OVERLAP_MIDDLE
+ * case, we haven't actually created the key we'll be inserting
+ * yet (for the split) - so we don't want to be using
+ * k->size/crc.live_size here:
+ */
+ return __ptr_disk_sectors(p, delta);
+ } else {
+ BUG_ON(-delta > p.crc.live_size);
- sectors = -__disk_sectors(p.crc, old_sectors)
- +__disk_sectors(p.crc, new_sectors);
+ return (s64) __ptr_disk_sectors(p, p.crc.live_size + delta) -
+ (s64) ptr_disk_sectors(p);
}
-
- return sectors;
}
/*
@@ -722,7 +711,9 @@ static int bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k,
BUG_ON(!sectors);
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
- s64 disk_sectors = ptr_disk_sectors(k.k, p, sectors);
+ s64 disk_sectors = data_type == BCH_DATA_BTREE
+ ? sectors
+ : ptr_disk_sectors_delta(p, sectors);
s64 adjusted_disk_sectors = disk_sectors;
bch2_mark_pointer(c, p, disk_sectors, data_type,