Skip to content

Commit 7759eb2

Browse files
Ming Leiaxboe
authored andcommitted
block: remove bio_rewind_iter()
It is pointed that bio_rewind_iter() is one very bad API[1]: 1) bio size may not be restored after rewinding 2) it causes some bogus change, such as 5151842 (block: reset bi_iter.bi_done after splitting bio) 3) rewinding really makes things complicated wrt. bio splitting 4) unnecessary updating of .bi_done in fast path [1] https://marc.info/?t=153549924200005&r=1&w=2 So this patch takes Kent's suggestion to restore one bio into its original state via saving bio iterator(struct bvec_iter) in bio_integrity_prep(), given now bio_rewind_iter() is only used by bio integrity code. Cc: Dmitry Monakhov <[email protected]> Cc: Hannes Reinecke <[email protected]> Suggested-by: Kent Overstreet <[email protected]> Acked-by: Kent Overstreet <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 3d0e637 commit 7759eb2

File tree

4 files changed

+8
-30
lines changed

4 files changed

+8
-30
lines changed

block/bio-integrity.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ bool bio_integrity_prep(struct bio *bio)
306306
if (bio_data_dir(bio) == WRITE) {
307307
bio_integrity_process(bio, &bio->bi_iter,
308308
bi->profile->generate_fn);
309+
} else {
310+
bip->bio_iter = bio->bi_iter;
309311
}
310312
return true;
311313

@@ -331,20 +333,14 @@ static void bio_integrity_verify_fn(struct work_struct *work)
331333
container_of(work, struct bio_integrity_payload, bip_work);
332334
struct bio *bio = bip->bip_bio;
333335
struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
334-
struct bvec_iter iter = bio->bi_iter;
335336

336337
/*
337338
* At the moment verify is called bio's iterator was advanced
338339
* during split and completion, we need to rewind iterator to
339340
* it's original position.
340341
*/
341-
if (bio_rewind_iter(bio, &iter, iter.bi_done)) {
342-
bio->bi_status = bio_integrity_process(bio, &iter,
343-
bi->profile->verify_fn);
344-
} else {
345-
bio->bi_status = BLK_STS_IOERR;
346-
}
347-
342+
bio->bi_status = bio_integrity_process(bio, &bip->bio_iter,
343+
bi->profile->verify_fn);
348344
bio_integrity_free(bio);
349345
bio_endio(bio);
350346
}

block/bio.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,6 @@ struct bio *bio_split(struct bio *bio, int sectors,
18071807
bio_integrity_trim(split);
18081808

18091809
bio_advance(bio, split->bi_iter.bi_size);
1810-
bio->bi_iter.bi_done = 0;
18111810

18121811
if (bio_flagged(bio, BIO_TRACE_COMPLETION))
18131812
bio_set_flag(split, BIO_TRACE_COMPLETION);

include/linux/bio.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,11 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
170170
{
171171
iter->bi_sector += bytes >> 9;
172172

173-
if (bio_no_advance_iter(bio)) {
173+
if (bio_no_advance_iter(bio))
174174
iter->bi_size -= bytes;
175-
iter->bi_done += bytes;
176-
} else {
175+
else
177176
bvec_iter_advance(bio->bi_io_vec, iter, bytes);
178177
/* TODO: It is reasonable to complete bio with error here. */
179-
}
180-
}
181-
182-
static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter,
183-
unsigned int bytes)
184-
{
185-
iter->bi_sector -= bytes >> 9;
186-
187-
if (bio_no_advance_iter(bio)) {
188-
iter->bi_size += bytes;
189-
iter->bi_done -= bytes;
190-
return true;
191-
}
192-
193-
return bvec_iter_rewind(bio->bi_io_vec, iter, bytes);
194178
}
195179

196180
#define __bio_for_each_segment(bvl, bio, iter, start) \
@@ -353,6 +337,8 @@ struct bio_integrity_payload {
353337
unsigned short bip_max_vcnt; /* integrity bio_vec slots */
354338
unsigned short bip_flags; /* control flags */
355339

340+
struct bvec_iter bio_iter; /* for rewinding parent bio */
341+
356342
struct work_struct bip_work; /* I/O completion */
357343

358344
struct bio_vec *bip_vec;

include/linux/bvec.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ struct bvec_iter {
4040

4141
unsigned int bi_idx; /* current index into bvl_vec */
4242

43-
unsigned int bi_done; /* number of bytes completed */
44-
4543
unsigned int bi_bvec_done; /* number of bytes completed in
4644
current bvec */
4745
};
@@ -85,7 +83,6 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv,
8583
bytes -= len;
8684
iter->bi_size -= len;
8785
iter->bi_bvec_done += len;
88-
iter->bi_done += len;
8986

9087
if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) {
9188
iter->bi_bvec_done = 0;

0 commit comments

Comments
 (0)