Skip to content

Commit df88feb

Browse files
author
Kent Overstreet
committed
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 <[email protected]>
1 parent ec36573 commit df88feb

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

fs/bcachefs/extents.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,10 @@ static union bch_extent_entry *extent_entry_prev(struct bkey_ptrs ptrs,
781781
/*
782782
* Returns pointer to the next entry after the one being dropped:
783783
*/
784-
union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s k,
785-
struct bch_extent_ptr *ptr)
784+
void bch2_bkey_drop_ptr_noerror(struct bkey_s k, struct bch_extent_ptr *ptr)
786785
{
787786
struct bkey_ptrs ptrs = bch2_bkey_ptrs(k);
788787
union bch_extent_entry *entry = to_entry(ptr), *next;
789-
union bch_extent_entry *ret = entry;
790788
bool drop_crc = true;
791789

792790
EBUG_ON(ptr < &ptrs.start->ptr ||
@@ -811,21 +809,16 @@ union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s k,
811809
break;
812810

813811
if ((extent_entry_is_crc(entry) && drop_crc) ||
814-
extent_entry_is_stripe_ptr(entry)) {
815-
ret = (void *) ret - extent_entry_bytes(entry);
812+
extent_entry_is_stripe_ptr(entry))
816813
extent_entry_drop(k, entry);
817-
}
818814
}
819-
820-
return ret;
821815
}
822816

823-
union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s k,
824-
struct bch_extent_ptr *ptr)
817+
void bch2_bkey_drop_ptr(struct bkey_s k, struct bch_extent_ptr *ptr)
825818
{
826819
bool have_dirty = bch2_bkey_dirty_devs(k.s_c).nr;
827-
union bch_extent_entry *ret =
828-
bch2_bkey_drop_ptr_noerror(k, ptr);
820+
821+
bch2_bkey_drop_ptr_noerror(k, ptr);
829822

830823
/*
831824
* 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,
837830
!bch2_bkey_dirty_devs(k.s_c).nr) {
838831
k.k->type = KEY_TYPE_error;
839832
set_bkey_val_u64s(k.k, 0);
840-
ret = NULL;
841833
} else if (!bch2_bkey_nr_ptrs(k.s_c)) {
842834
k.k->type = KEY_TYPE_deleted;
843835
set_bkey_val_u64s(k.k, 0);
844-
ret = NULL;
845836
}
846-
847-
return ret;
848837
}
849838

850839
void bch2_bkey_drop_device(struct bkey_s k, unsigned dev)

fs/bcachefs/extents.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -649,26 +649,21 @@ static inline void bch2_bkey_append_ptr(struct bkey_i *k, struct bch_extent_ptr
649649

650650
void bch2_extent_ptr_decoded_append(struct bkey_i *,
651651
struct extent_ptr_decoded *);
652-
union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s,
653-
struct bch_extent_ptr *);
654-
union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s,
655-
struct bch_extent_ptr *);
652+
void bch2_bkey_drop_ptr_noerror(struct bkey_s, struct bch_extent_ptr *);
653+
void bch2_bkey_drop_ptr(struct bkey_s, struct bch_extent_ptr *);
656654

657655
#define bch2_bkey_drop_ptrs(_k, _ptr, _cond) \
658656
do { \
659-
struct bkey_ptrs _ptrs = bch2_bkey_ptrs(_k); \
657+
__label__ _again; \
658+
struct bkey_ptrs _ptrs; \
659+
_again: \
660+
_ptrs = bch2_bkey_ptrs(_k); \
660661
\
661-
struct bch_extent_ptr *_ptr = &_ptrs.start->ptr; \
662-
\
663-
while ((_ptr = bkey_ptr_next(_ptrs, _ptr))) { \
662+
bkey_for_each_ptr(_ptrs, _ptr) \
664663
if (_cond) { \
665-
_ptr = (void *) bch2_bkey_drop_ptr(_k, _ptr); \
666-
_ptrs = bch2_bkey_ptrs(_k); \
667-
continue; \
664+
bch2_bkey_drop_ptr(_k, _ptr); \
665+
goto _again; \
668666
} \
669-
\
670-
(_ptr)++; \
671-
} \
672667
} while (0)
673668

674669
bool bch2_bkey_matches_ptr(struct bch_fs *, struct bkey_s_c,

0 commit comments

Comments
 (0)