168 lines
5.5 KiB
Diff
168 lines
5.5 KiB
Diff
From 88c26043ea0b7fb1d68b5e7ca2befc1e3077020b Mon Sep 17 00:00:00 2001
|
|
From: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Date: Sun, 20 Oct 2024 01:32:55 -0400
|
|
Subject: [PATCH 039/233] bcachefs: small cleanup for extent ptr bitmasks
|
|
Content-Type: text/plain; charset="utf-8"
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
|
|
---
|
|
fs/bcachefs/data_update.c | 30 +++++++++++++++---------------
|
|
fs/bcachefs/extents.c | 12 ++++++------
|
|
fs/bcachefs/io_read.c | 6 +++---
|
|
3 files changed, 24 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/fs/bcachefs/data_update.c b/fs/bcachefs/data_update.c
|
|
index a176e5439cbf..90da57a26962 100644
|
|
--- a/fs/bcachefs/data_update.c
|
|
+++ b/fs/bcachefs/data_update.c
|
|
@@ -189,7 +189,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
|
|
struct bpos next_pos;
|
|
bool should_check_enospc;
|
|
s64 i_sectors_delta = 0, disk_sectors_delta = 0;
|
|
- unsigned rewrites_found = 0, durability, i;
|
|
+ unsigned rewrites_found = 0, durability, ptr_bit;
|
|
|
|
bch2_trans_begin(trans);
|
|
|
|
@@ -226,16 +226,16 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
|
|
*
|
|
* Fist, drop rewrite_ptrs from @new:
|
|
*/
|
|
- i = 0;
|
|
+ ptr_bit = 1;
|
|
bkey_for_each_ptr_decode(old.k, bch2_bkey_ptrs_c(old), p, entry_c) {
|
|
- if (((1U << i) & m->data_opts.rewrite_ptrs) &&
|
|
+ if ((ptr_bit & m->data_opts.rewrite_ptrs) &&
|
|
(ptr = bch2_extent_has_ptr(old, p, bkey_i_to_s(insert))) &&
|
|
!ptr->cached) {
|
|
bch2_extent_ptr_set_cached(c, &m->op.opts,
|
|
bkey_i_to_s(insert), ptr);
|
|
- rewrites_found |= 1U << i;
|
|
+ rewrites_found |= ptr_bit;
|
|
}
|
|
- i++;
|
|
+ ptr_bit <<= 1;
|
|
}
|
|
|
|
if (m->data_opts.rewrite_ptrs &&
|
|
@@ -609,7 +609,7 @@ int bch2_data_update_init(struct btree_trans *trans,
|
|
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
|
|
const union bch_extent_entry *entry;
|
|
struct extent_ptr_decoded p;
|
|
- unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas;
|
|
+ unsigned reserve_sectors = k.k->size * data_opts.extra_replicas;
|
|
int ret = 0;
|
|
|
|
/*
|
|
@@ -652,17 +652,17 @@ int bch2_data_update_init(struct btree_trans *trans,
|
|
|
|
unsigned durability_have = 0, durability_removing = 0;
|
|
|
|
- i = 0;
|
|
+ unsigned ptr_bit = 1;
|
|
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
|
|
if (!p.ptr.cached) {
|
|
rcu_read_lock();
|
|
- if (BIT(i) & m->data_opts.rewrite_ptrs) {
|
|
+ if (ptr_bit & m->data_opts.rewrite_ptrs) {
|
|
if (crc_is_compressed(p.crc))
|
|
reserve_sectors += k.k->size;
|
|
|
|
m->op.nr_replicas += bch2_extent_ptr_desired_durability(c, &p);
|
|
durability_removing += bch2_extent_ptr_desired_durability(c, &p);
|
|
- } else if (!(BIT(i) & m->data_opts.kill_ptrs)) {
|
|
+ } else if (!(ptr_bit & m->data_opts.kill_ptrs)) {
|
|
bch2_dev_list_add_dev(&m->op.devs_have, p.ptr.dev);
|
|
durability_have += bch2_extent_ptr_durability(c, &p);
|
|
}
|
|
@@ -682,7 +682,7 @@ int bch2_data_update_init(struct btree_trans *trans,
|
|
if (p.crc.compression_type == BCH_COMPRESSION_TYPE_incompressible)
|
|
m->op.incompressible = true;
|
|
|
|
- i++;
|
|
+ ptr_bit <<= 1;
|
|
}
|
|
|
|
unsigned durability_required = max(0, (int) (io_opts.data_replicas - durability_have));
|
|
@@ -745,14 +745,14 @@ int bch2_data_update_init(struct btree_trans *trans,
|
|
void bch2_data_update_opts_normalize(struct bkey_s_c k, struct data_update_opts *opts)
|
|
{
|
|
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
|
|
- unsigned i = 0;
|
|
+ unsigned ptr_bit = 1;
|
|
|
|
bkey_for_each_ptr(ptrs, ptr) {
|
|
- if ((opts->rewrite_ptrs & (1U << i)) && ptr->cached) {
|
|
- opts->kill_ptrs |= 1U << i;
|
|
- opts->rewrite_ptrs ^= 1U << i;
|
|
+ if ((opts->rewrite_ptrs & ptr_bit) && ptr->cached) {
|
|
+ opts->kill_ptrs |= ptr_bit;
|
|
+ opts->rewrite_ptrs ^= ptr_bit;
|
|
}
|
|
|
|
- i++;
|
|
+ ptr_bit <<= 1;
|
|
}
|
|
}
|
|
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
|
|
index 45a67daf0d64..243cb15b74b3 100644
|
|
--- a/fs/bcachefs/extents.c
|
|
+++ b/fs/bcachefs/extents.c
|
|
@@ -1414,7 +1414,7 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
|
|
unsigned compression_type = bch2_compression_opt_to_type(compression);
|
|
const union bch_extent_entry *entry;
|
|
struct extent_ptr_decoded p;
|
|
- unsigned i = 0;
|
|
+ unsigned ptr_bit = 1;
|
|
|
|
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
|
|
if (p.crc.compression_type == BCH_COMPRESSION_TYPE_incompressible ||
|
|
@@ -1424,18 +1424,18 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
|
|
}
|
|
|
|
if (!p.ptr.cached && p.crc.compression_type != compression_type)
|
|
- rewrite_ptrs |= 1U << i;
|
|
- i++;
|
|
+ rewrite_ptrs |= ptr_bit;
|
|
+ ptr_bit <<= 1;
|
|
}
|
|
}
|
|
incompressible:
|
|
if (target && bch2_target_accepts_data(c, BCH_DATA_user, target)) {
|
|
- unsigned i = 0;
|
|
+ unsigned ptr_bit = 1;
|
|
|
|
bkey_for_each_ptr(ptrs, ptr) {
|
|
if (!ptr->cached && !bch2_dev_in_target(c, ptr->dev, target))
|
|
- rewrite_ptrs |= 1U << i;
|
|
- i++;
|
|
+ rewrite_ptrs |= ptr_bit;
|
|
+ ptr_bit <<= 1;
|
|
}
|
|
}
|
|
|
|
diff --git a/fs/bcachefs/io_read.c b/fs/bcachefs/io_read.c
|
|
index b3b934a87c6d..cbc3cc1f6d03 100644
|
|
--- a/fs/bcachefs/io_read.c
|
|
+++ b/fs/bcachefs/io_read.c
|
|
@@ -231,11 +231,11 @@ static struct promote_op *__promote_alloc(struct btree_trans *trans,
|
|
update_opts.target = opts.foreground_target;
|
|
|
|
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
|
|
- unsigned i = 0;
|
|
+ unsigned ptr_bit = 1;
|
|
bkey_for_each_ptr(ptrs, ptr) {
|
|
if (bch2_dev_io_failures(failed, ptr->dev))
|
|
- update_opts.rewrite_ptrs |= BIT(i);
|
|
- i++;
|
|
+ update_opts.rewrite_ptrs |= ptr_bit;
|
|
+ ptr_bit <<= 1;
|
|
}
|
|
}
|
|
|
|
--
|
|
2.45.2
|
|
|