Commit 88005d5d authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: extent_entry_next_safe()

We need to be able to iterate over extent ptrs that may be corrupted in
order to print them - this fixes a bug where we'd pop an assert in
bch2_bkey_durability_safe().
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6fa30fe7
...@@ -43,6 +43,11 @@ enum bkey_invalid_flags; ...@@ -43,6 +43,11 @@ enum bkey_invalid_flags;
#define extent_entry_next(_entry) \ #define extent_entry_next(_entry) \
((typeof(_entry)) ((void *) (_entry) + extent_entry_bytes(_entry))) ((typeof(_entry)) ((void *) (_entry) + extent_entry_bytes(_entry)))
#define extent_entry_next_safe(_entry, _end) \
(likely(__extent_entry_type(_entry) < BCH_EXTENT_ENTRY_MAX) \
? extent_entry_next(_entry) \
: _end)
static inline unsigned static inline unsigned
__extent_entry_type(const union bch_extent_entry *e) __extent_entry_type(const union bch_extent_entry *e)
{ {
...@@ -280,7 +285,7 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k) ...@@ -280,7 +285,7 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k)
#define __bkey_extent_entry_for_each_from(_start, _end, _entry) \ #define __bkey_extent_entry_for_each_from(_start, _end, _entry) \
for ((_entry) = (_start); \ for ((_entry) = (_start); \
(_entry) < (_end); \ (_entry) < (_end); \
(_entry) = extent_entry_next(_entry)) (_entry) = extent_entry_next_safe(_entry, _end))
#define __bkey_ptr_next(_ptr, _end) \ #define __bkey_ptr_next(_ptr, _end) \
({ \ ({ \
...@@ -318,7 +323,7 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k) ...@@ -318,7 +323,7 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k)
(_ptr).has_ec = false; \ (_ptr).has_ec = false; \
\ \
__bkey_extent_entry_for_each_from(_entry, _end, _entry) \ __bkey_extent_entry_for_each_from(_entry, _end, _entry) \
switch (extent_entry_type(_entry)) { \ switch (__extent_entry_type(_entry)) { \
case BCH_EXTENT_ENTRY_ptr: \ case BCH_EXTENT_ENTRY_ptr: \
(_ptr).ptr = _entry->ptr; \ (_ptr).ptr = _entry->ptr; \
goto out; \ goto out; \
...@@ -344,7 +349,7 @@ out: \ ...@@ -344,7 +349,7 @@ out: \
for ((_ptr).crc = bch2_extent_crc_unpack(_k, NULL), \ for ((_ptr).crc = bch2_extent_crc_unpack(_k, NULL), \
(_entry) = _start; \ (_entry) = _start; \
__bkey_ptr_next_decode(_k, _end, _ptr, _entry); \ __bkey_ptr_next_decode(_k, _end, _ptr, _entry); \
(_entry) = extent_entry_next(_entry)) (_entry) = extent_entry_next_safe(_entry, _end))
#define bkey_for_each_ptr_decode(_k, _p, _ptr, _entry) \ #define bkey_for_each_ptr_decode(_k, _p, _ptr, _entry) \
__bkey_for_each_ptr_decode(_k, (_p).start, (_p).end, \ __bkey_for_each_ptr_decode(_k, (_p).start, (_p).end, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment