diff options
| author | Kent Overstreet <kmo@daterainc.com> | 2013-09-24 19:26:05 -0400 |
|---|---|---|
| committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-24 01:33:51 -0500 |
| commit | 458b76ed2f9517becb74dcc8eedd70d3068ea6e4 (patch) | |
| tree | b01b2150b197e0759b3ba59c0f9367d4477ebb8c /include/linux | |
| parent | d57a5f7c6605f15f3b5134837e68b448a7cea88e (diff) | |
block: Kill bio_segments()/bi_vcnt usage
When we start sharing biovecs, keeping bi_vcnt accurate for splits is
going to be error prone - and unnecessary, if we refactor some code.
So bio_segments() has to go - but most of the existing users just needed
to know if the bio had multiple segments, which is easier - add a
bio_multiple_segments() for them.
(Two of the current uses of bio_segments() are going to go away in a
couple patches, but the current implementation of bio_segments() is
unsafe as soon as we start doing driver conversions for immutable
biovecs - so implement a dumb version for bisectability, it'll go away
in a couple patches)
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Neil Brown <neilb@suse.de>
Cc: Nagalakshmi Nandigama <Nagalakshmi.Nandigama@lsi.com>
Cc: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/bio.h | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h index 930cb73c894b..aea9896a6289 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h | |||
| @@ -97,13 +97,46 @@ | |||
| 97 | #define bio_offset(bio) bio_iter_offset((bio), (bio)->bi_iter) | 97 | #define bio_offset(bio) bio_iter_offset((bio), (bio)->bi_iter) |
| 98 | #define bio_iovec(bio) bio_iter_iovec((bio), (bio)->bi_iter) | 98 | #define bio_iovec(bio) bio_iter_iovec((bio), (bio)->bi_iter) |
| 99 | 99 | ||
| 100 | #define bio_segments(bio) ((bio)->bi_vcnt - (bio)->bi_iter.bi_idx) | 100 | #define bio_multiple_segments(bio) \ |
| 101 | ((bio)->bi_iter.bi_size != bio_iovec(bio).bv_len) | ||
| 101 | #define bio_sectors(bio) ((bio)->bi_iter.bi_size >> 9) | 102 | #define bio_sectors(bio) ((bio)->bi_iter.bi_size >> 9) |
| 102 | #define bio_end_sector(bio) ((bio)->bi_iter.bi_sector + bio_sectors((bio))) | 103 | #define bio_end_sector(bio) ((bio)->bi_iter.bi_sector + bio_sectors((bio))) |
| 103 | 104 | ||
| 105 | /* | ||
| 106 | * Check whether this bio carries any data or not. A NULL bio is allowed. | ||
| 107 | */ | ||
| 108 | static inline bool bio_has_data(struct bio *bio) | ||
| 109 | { | ||
| 110 | if (bio && | ||
| 111 | bio->bi_iter.bi_size && | ||
| 112 | !(bio->bi_rw & REQ_DISCARD)) | ||
| 113 | return true; | ||
| 114 | |||
| 115 | return false; | ||
| 116 | } | ||
| 117 | |||
| 118 | static inline bool bio_is_rw(struct bio *bio) | ||
| 119 | { | ||
| 120 | if (!bio_has_data(bio)) | ||
| 121 | return false; | ||
| 122 | |||
| 123 | if (bio->bi_rw & BIO_NO_ADVANCE_ITER_MASK) | ||
| 124 | return false; | ||
| 125 | |||
| 126 | return true; | ||
| 127 | } | ||
| 128 | |||
| 129 | static inline bool bio_mergeable(struct bio *bio) | ||
| 130 | { | ||
| 131 | if (bio->bi_rw & REQ_NOMERGE_FLAGS) | ||
| 132 | return false; | ||
| 133 | |||
| 134 | return true; | ||
| 135 | } | ||
| 136 | |||
| 104 | static inline unsigned int bio_cur_bytes(struct bio *bio) | 137 | static inline unsigned int bio_cur_bytes(struct bio *bio) |
| 105 | { | 138 | { |
| 106 | if (bio->bi_vcnt) | 139 | if (bio_has_data(bio)) |
| 107 | return bio_iovec(bio).bv_len; | 140 | return bio_iovec(bio).bv_len; |
| 108 | else /* dataless requests such as discard */ | 141 | else /* dataless requests such as discard */ |
| 109 | return bio->bi_iter.bi_size; | 142 | return bio->bi_iter.bi_size; |
| @@ -111,7 +144,7 @@ static inline unsigned int bio_cur_bytes(struct bio *bio) | |||
| 111 | 144 | ||
| 112 | static inline void *bio_data(struct bio *bio) | 145 | static inline void *bio_data(struct bio *bio) |
| 113 | { | 146 | { |
| 114 | if (bio->bi_vcnt) | 147 | if (bio_has_data(bio)) |
| 115 | return page_address(bio_page(bio)) + bio_offset(bio); | 148 | return page_address(bio_page(bio)) + bio_offset(bio); |
| 116 | 149 | ||
| 117 | return NULL; | 150 | return NULL; |
| @@ -221,6 +254,18 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, | |||
| 221 | 254 | ||
| 222 | #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) | 255 | #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) |
| 223 | 256 | ||
| 257 | static inline unsigned bio_segments(struct bio *bio) | ||
| 258 | { | ||
| 259 | unsigned segs = 0; | ||
| 260 | struct bio_vec bv; | ||
| 261 | struct bvec_iter iter; | ||
| 262 | |||
| 263 | bio_for_each_segment(bv, bio, iter) | ||
| 264 | segs++; | ||
| 265 | |||
| 266 | return segs; | ||
| 267 | } | ||
| 268 | |||
| 224 | /* | 269 | /* |
| 225 | * get a reference to a bio, so it won't disappear. the intended use is | 270 | * get a reference to a bio, so it won't disappear. the intended use is |
| 226 | * something like: | 271 | * something like: |
| @@ -435,36 +480,6 @@ static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx, | |||
| 435 | #define bio_kunmap_irq(buf,flags) __bio_kunmap_irq(buf, flags) | 480 | #define bio_kunmap_irq(buf,flags) __bio_kunmap_irq(buf, flags) |
| 436 | 481 | ||
| 437 | /* | 482 | /* |
| 438 | * Check whether this bio carries any data or not. A NULL bio is allowed. | ||
| 439 | */ | ||
| 440 | static inline bool bio_has_data(struct bio *bio) | ||
| 441 | { | ||
| 442 | if (bio && bio->bi_vcnt) | ||
| 443 | return true; | ||
| 444 | |||
| 445 | return false; | ||
| 446 | } | ||
| 447 | |||
| 448 | static inline bool bio_is_rw(struct bio *bio) | ||
| 449 | { | ||
| 450 | if (!bio_has_data(bio)) | ||
| 451 | return false; | ||
| 452 | |||
| 453 | if (bio->bi_rw & REQ_WRITE_SAME) | ||
| 454 | return false; | ||
| 455 | |||
| 456 | return true; | ||
| 457 | } | ||
| 458 | |||
| 459 | static inline bool bio_mergeable(struct bio *bio) | ||
| 460 | { | ||
| 461 | if (bio->bi_rw & REQ_NOMERGE_FLAGS) | ||
| 462 | return false; | ||
| 463 | |||
| 464 | return true; | ||
| 465 | } | ||
| 466 | |||
| 467 | /* | ||
| 468 | * BIO list management for use by remapping drivers (e.g. DM or MD) and loop. | 483 | * BIO list management for use by remapping drivers (e.g. DM or MD) and loop. |
| 469 | * | 484 | * |
| 470 | * A bio_list anchors a singly-linked list of bios chained through the bi_next | 485 | * A bio_list anchors a singly-linked list of bios chained through the bi_next |
