To achieve this, the "for_each" macros are now somewhat more complex.
For example, rq_for_each_segment is:
#define bio_for_each_segment_offset(bv, bio, _i, offs, _size) \
for (_i.i = 0, _i.offset = (bio)->bi_offset + offs, \
_i.size = min_t(int, _size, (bio)->bi_size - offs); \
_i.i < (bio)->bi_vcnt && _i.size > 0; \
_i.i++) \
if (bv = *bio_iovec_idx((bio), _i.i), \
bv.bv_offset += _i.offset, \
bv.bv_len <= _i.offset \
? (_i.offset -= bv.bv_len, 0) \
: (bv.bv_len -= _i.offset, \
_i.offset = 0, \
bv.bv_len < _i.size \
? (_i.size -= bv.bv_len, 1) \
: (bv.bv_len = _i.size, \
_i.size = 0, \
bv.bv_len > 0)))
#define bio_for_each_segment(bv, bio, __i) \
bio_for_each_segment_offset(bv, bio, __i, 0, (bio)->bi_size)
It does some with some explanatory text in a comment, but it is still
a bit daunting. Any suggestions on making this more approachable
would be very welcome.