Skip to content

Commit d148d75

Browse files
keithbuschaxboe
authored andcommitted
blk-integrity: properly account for segments
Both types of merging when integrity data is used are miscounting the segments: Merging two requests wasn't accounting for the new segment count, so add the "next" segment count to the first on a successful merge to ensure this value is accurate. Merging a bio into an existing request was double counting the bio's segments, even if the merge failed later on. Move the segment accounting to the end when the merge is successful. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Keith Busch <kbusch@kernel.org> Link: https://lore.kernel.org/r/20240913182854.2445457-4-kbusch@meta.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 9c297ec commit d148d75

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

block/blk-integrity.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ bool blk_integrity_merge_bio(struct request_queue *q, struct request *req,
153153
q->limits.max_integrity_segments)
154154
return false;
155155

156-
req->nr_integrity_segments += nr_integrity_segs;
157-
158156
return true;
159157
}
160158

block/blk-merge.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
639639
* counters.
640640
*/
641641
req->nr_phys_segments += nr_phys_segs;
642+
if (bio_integrity(bio))
643+
req->nr_integrity_segments += blk_rq_count_integrity_sg(req->q,
644+
bio);
642645
return 1;
643646

644647
no_merge:
@@ -731,6 +734,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
731734

732735
/* Merge is OK... */
733736
req->nr_phys_segments = total_phys_segments;
737+
req->nr_integrity_segments += next->nr_integrity_segments;
734738
return 1;
735739
}
736740

0 commit comments

Comments
 (0)