History

block: Add bio_for_each_folio_all()

Allow callers to iterate over each folio instead of each page. The bio need not have been constructed using folios originally.

Matthew Wilcox (Oracle) committed 5 years ago

Commit 640d1931 parent 85f5a742 files · +53 −1Browse files

Showing the changes to include (1 of 2 files). Show all

Unified · Split

include/linux/bio.h+52−1
@@ -166,7 +166,7 @@ static inline void bio_advance(struct bio *bio, unsigned int nbytes) · 165 unmodified lines
166 */166 */
167#define bio_for_each_bvec_all(bvl, bio, i) \167#define bio_for_each_bvec_all(bvl, bio, i) \
168 for (i = 0, bvl = bio_first_bvec_all(bio); \168 for (i = 0, bvl = bio_first_bvec_all(bio); \
169 i < (bio)->bi_vcnt; i++, bvl++) \169 i < (bio)->bi_vcnt; i++, bvl++)
170 170
171#define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)171#define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)
172 172
@@ -260,6 +260,57 @@ static inline struct bio_vec *bio_last_bvec_all(struct bio *bio) · 87 unmodified lines
260 return &bio->bi_io_vec[bio->bi_vcnt - 1];260 return &bio->bi_io_vec[bio->bi_vcnt - 1];
261}261}
262 262
263/**
264 * struct folio_iter - State for iterating all folios in a bio.
265 * @folio: The current folio we're iterating. NULL after the last folio.
266 * @offset: The byte offset within the current folio.
267 * @length: The number of bytes in this iteration (will not cross folio
268 * boundary).
269 */
270struct folio_iter {
271 struct folio *folio;
272 size_t offset;
273 size_t length;
274 /* private: for use by the iterator */
275 size_t _seg_count;
276 int _i;
277};
278
279static inline void bio_first_folio(struct folio_iter *fi, struct bio *bio,
280 int i)
281{
282 struct bio_vec *bvec = bio_first_bvec_all(bio) + i;
283
284 fi->folio = page_folio(bvec->bv_page);
285 fi->offset = bvec->bv_offset +
286 PAGE_SIZE * (bvec->bv_page - &fi->folio->page);
287 fi->_seg_count = bvec->bv_len;
288 fi->length = min(folio_size(fi->folio) - fi->offset, fi->_seg_count);
289 fi->_i = i;
290}
291
292static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio)
293{
294 fi->_seg_count -= fi->length;
295 if (fi->_seg_count) {
296 fi->folio = folio_next(fi->folio);
297 fi->offset = 0;
298 fi->length = min(folio_size(fi->folio), fi->_seg_count);
299 } else if (fi->_i + 1 < bio->bi_vcnt) {
300 bio_first_folio(fi, bio, fi->_i + 1);
301 } else {
302 fi->folio = NULL;
303 }
304}
305
306/**
307 * bio_for_each_folio_all - Iterate over each folio in a bio.
308 * @fi: struct folio_iter which is updated for each folio.
309 * @bio: struct bio to iterate over.
310 */
311#define bio_for_each_folio_all(fi, bio) \
312 for (bio_first_folio(&fi, bio, 0); fi.folio; bio_next_folio(&fi, bio))
313
263enum bip_flags {314enum bip_flags {
264 BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */315 BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */
265 BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */316 BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t