mirror of
https://github.com/torvalds/linux.git
synced 2025-11-03 10:10:33 +02:00
bcachefs: Simplify bch2_bkey_drop_ptrs()
bch2_bkey_drop_ptrs() had a some complicated machinery for avoiding O(n^2) when dropping multiple pointers - but when n is only going to be ~4, it's not worth it. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
ec36573dcd
commit
df88febc20
2 changed files with 14 additions and 30 deletions
|
|
@ -781,12 +781,10 @@ static union bch_extent_entry *extent_entry_prev(struct bkey_ptrs ptrs,
|
||||||
/*
|
/*
|
||||||
* Returns pointer to the next entry after the one being dropped:
|
* Returns pointer to the next entry after the one being dropped:
|
||||||
*/
|
*/
|
||||||
union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s k,
|
void bch2_bkey_drop_ptr_noerror(struct bkey_s k, struct bch_extent_ptr *ptr)
|
||||||
struct bch_extent_ptr *ptr)
|
|
||||||
{
|
{
|
||||||
struct bkey_ptrs ptrs = bch2_bkey_ptrs(k);
|
struct bkey_ptrs ptrs = bch2_bkey_ptrs(k);
|
||||||
union bch_extent_entry *entry = to_entry(ptr), *next;
|
union bch_extent_entry *entry = to_entry(ptr), *next;
|
||||||
union bch_extent_entry *ret = entry;
|
|
||||||
bool drop_crc = true;
|
bool drop_crc = true;
|
||||||
|
|
||||||
EBUG_ON(ptr < &ptrs.start->ptr ||
|
EBUG_ON(ptr < &ptrs.start->ptr ||
|
||||||
|
|
@ -811,21 +809,16 @@ union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s k,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((extent_entry_is_crc(entry) && drop_crc) ||
|
if ((extent_entry_is_crc(entry) && drop_crc) ||
|
||||||
extent_entry_is_stripe_ptr(entry)) {
|
extent_entry_is_stripe_ptr(entry))
|
||||||
ret = (void *) ret - extent_entry_bytes(entry);
|
|
||||||
extent_entry_drop(k, entry);
|
extent_entry_drop(k, entry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s k,
|
void bch2_bkey_drop_ptr(struct bkey_s k, struct bch_extent_ptr *ptr)
|
||||||
struct bch_extent_ptr *ptr)
|
|
||||||
{
|
{
|
||||||
bool have_dirty = bch2_bkey_dirty_devs(k.s_c).nr;
|
bool have_dirty = bch2_bkey_dirty_devs(k.s_c).nr;
|
||||||
union bch_extent_entry *ret =
|
|
||||||
bch2_bkey_drop_ptr_noerror(k, ptr);
|
bch2_bkey_drop_ptr_noerror(k, ptr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we deleted all the dirty pointers and there's still cached
|
* If we deleted all the dirty pointers and there's still cached
|
||||||
|
|
@ -837,14 +830,10 @@ union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s k,
|
||||||
!bch2_bkey_dirty_devs(k.s_c).nr) {
|
!bch2_bkey_dirty_devs(k.s_c).nr) {
|
||||||
k.k->type = KEY_TYPE_error;
|
k.k->type = KEY_TYPE_error;
|
||||||
set_bkey_val_u64s(k.k, 0);
|
set_bkey_val_u64s(k.k, 0);
|
||||||
ret = NULL;
|
|
||||||
} else if (!bch2_bkey_nr_ptrs(k.s_c)) {
|
} else if (!bch2_bkey_nr_ptrs(k.s_c)) {
|
||||||
k.k->type = KEY_TYPE_deleted;
|
k.k->type = KEY_TYPE_deleted;
|
||||||
set_bkey_val_u64s(k.k, 0);
|
set_bkey_val_u64s(k.k, 0);
|
||||||
ret = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bch2_bkey_drop_device(struct bkey_s k, unsigned dev)
|
void bch2_bkey_drop_device(struct bkey_s k, unsigned dev)
|
||||||
|
|
|
||||||
|
|
@ -649,26 +649,21 @@ static inline void bch2_bkey_append_ptr(struct bkey_i *k, struct bch_extent_ptr
|
||||||
|
|
||||||
void bch2_extent_ptr_decoded_append(struct bkey_i *,
|
void bch2_extent_ptr_decoded_append(struct bkey_i *,
|
||||||
struct extent_ptr_decoded *);
|
struct extent_ptr_decoded *);
|
||||||
union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s,
|
void bch2_bkey_drop_ptr_noerror(struct bkey_s, struct bch_extent_ptr *);
|
||||||
struct bch_extent_ptr *);
|
void bch2_bkey_drop_ptr(struct bkey_s, struct bch_extent_ptr *);
|
||||||
union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s,
|
|
||||||
struct bch_extent_ptr *);
|
|
||||||
|
|
||||||
#define bch2_bkey_drop_ptrs(_k, _ptr, _cond) \
|
#define bch2_bkey_drop_ptrs(_k, _ptr, _cond) \
|
||||||
do { \
|
do { \
|
||||||
struct bkey_ptrs _ptrs = bch2_bkey_ptrs(_k); \
|
__label__ _again; \
|
||||||
|
struct bkey_ptrs _ptrs; \
|
||||||
|
_again: \
|
||||||
|
_ptrs = bch2_bkey_ptrs(_k); \
|
||||||
\
|
\
|
||||||
struct bch_extent_ptr *_ptr = &_ptrs.start->ptr; \
|
bkey_for_each_ptr(_ptrs, _ptr) \
|
||||||
\
|
|
||||||
while ((_ptr = bkey_ptr_next(_ptrs, _ptr))) { \
|
|
||||||
if (_cond) { \
|
if (_cond) { \
|
||||||
_ptr = (void *) bch2_bkey_drop_ptr(_k, _ptr); \
|
bch2_bkey_drop_ptr(_k, _ptr); \
|
||||||
_ptrs = bch2_bkey_ptrs(_k); \
|
goto _again; \
|
||||||
continue; \
|
|
||||||
} \
|
} \
|
||||||
\
|
|
||||||
(_ptr)++; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
bool bch2_bkey_matches_ptr(struct bch_fs *, struct bkey_s_c,
|
bool bch2_bkey_matches_ptr(struct bch_fs *, struct bkey_s_c,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue