diff options
| author | Ming Lei <ming.lei@redhat.com> | 2019-04-08 07:02:38 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2019-04-08 10:19:41 -0400 |
| commit | 1200e07f3ad4b9d976cf2fff3a0c3d9a1faecb3e (patch) | |
| tree | c46db66fbb2979d69b7fe6ad6f9065ff9312e0a5 /include/linux/bvec.h | |
| parent | 15ade5d2e7775667cf191cf2f94327a4889f8b9d (diff) | |
block: don't use for-inside-for in bio_for_each_segment_all
Commit 6dc4f100c175 ("block: allow bio_for_each_segment_all() to
iterate over multi-page bvec") changes bio_for_each_segment_all()
to use for-inside-for.
This way breaks all bio_for_each_segment_all() call with error out
branch via 'break', since now 'break' can only break from the inner
loop.
Fixes this issue by implementing bio_for_each_segment_all() via
single 'for' loop, and now the logic is very similar with normal
bvec iterator.
Cc: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: linux-btrfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Omar Sandoval <osandov@fb.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reported-and-Tested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Fixes: 6dc4f100c175 ("block: allow bio_for_each_segment_all() to iterate over multi-page bvec")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/bvec.h')
| -rw-r--r-- | include/linux/bvec.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/include/linux/bvec.h b/include/linux/bvec.h index f6275c4da13a..3bc91879e1e2 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h | |||
| @@ -145,18 +145,18 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, | |||
| 145 | 145 | ||
| 146 | static inline struct bio_vec *bvec_init_iter_all(struct bvec_iter_all *iter_all) | 146 | static inline struct bio_vec *bvec_init_iter_all(struct bvec_iter_all *iter_all) |
| 147 | { | 147 | { |
| 148 | iter_all->bv.bv_page = NULL; | ||
| 149 | iter_all->done = 0; | 148 | iter_all->done = 0; |
| 149 | iter_all->idx = 0; | ||
| 150 | 150 | ||
| 151 | return &iter_all->bv; | 151 | return &iter_all->bv; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | static inline void mp_bvec_next_segment(const struct bio_vec *bvec, | 154 | static inline void bvec_advance(const struct bio_vec *bvec, |
| 155 | struct bvec_iter_all *iter_all) | 155 | struct bvec_iter_all *iter_all) |
| 156 | { | 156 | { |
| 157 | struct bio_vec *bv = &iter_all->bv; | 157 | struct bio_vec *bv = &iter_all->bv; |
| 158 | 158 | ||
| 159 | if (bv->bv_page) { | 159 | if (iter_all->done) { |
| 160 | bv->bv_page = nth_page(bv->bv_page, 1); | 160 | bv->bv_page = nth_page(bv->bv_page, 1); |
| 161 | bv->bv_offset = 0; | 161 | bv->bv_offset = 0; |
| 162 | } else { | 162 | } else { |
| @@ -165,6 +165,12 @@ static inline void mp_bvec_next_segment(const struct bio_vec *bvec, | |||
| 165 | } | 165 | } |
| 166 | bv->bv_len = min_t(unsigned int, PAGE_SIZE - bv->bv_offset, | 166 | bv->bv_len = min_t(unsigned int, PAGE_SIZE - bv->bv_offset, |
| 167 | bvec->bv_len - iter_all->done); | 167 | bvec->bv_len - iter_all->done); |
| 168 | iter_all->done += bv->bv_len; | ||
| 169 | |||
| 170 | if (iter_all->done == bvec->bv_len) { | ||
| 171 | iter_all->idx++; | ||
| 172 | iter_all->done = 0; | ||
| 173 | } | ||
| 168 | } | 174 | } |
| 169 | 175 | ||
| 170 | /* | 176 | /* |
