提交 4eaf99be 编写于 作者: M Martin K. Petersen 提交者: Jens Axboe

block: Don't merge requests if integrity flags differ

We'd occasionally merge requests with conflicting integrity flags.
Introduce a merge helper which checks that the requests have compatible
integrity payloads.
Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NSagi Grimberg <sagig@mellanox.com>
Signed-off-by: NJens Axboe <axboe@fb.com>
上级 aae7df50
...@@ -186,37 +186,53 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2) ...@@ -186,37 +186,53 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
} }
EXPORT_SYMBOL(blk_integrity_compare); EXPORT_SYMBOL(blk_integrity_compare);
int blk_integrity_merge_rq(struct request_queue *q, struct request *req, bool blk_integrity_merge_rq(struct request_queue *q, struct request *req,
struct request *next) struct request *next)
{ {
if (blk_integrity_rq(req) != blk_integrity_rq(next)) if (blk_integrity_rq(req) == 0 && blk_integrity_rq(next) == 0)
return -1; return true;
if (blk_integrity_rq(req) == 0 || blk_integrity_rq(next) == 0)
return false;
if (bio_integrity(req->bio)->bip_flags !=
bio_integrity(next->bio)->bip_flags)
return false;
if (req->nr_integrity_segments + next->nr_integrity_segments > if (req->nr_integrity_segments + next->nr_integrity_segments >
q->limits.max_integrity_segments) q->limits.max_integrity_segments)
return -1; return false;
return 0; return true;
} }
EXPORT_SYMBOL(blk_integrity_merge_rq); EXPORT_SYMBOL(blk_integrity_merge_rq);
int blk_integrity_merge_bio(struct request_queue *q, struct request *req, bool blk_integrity_merge_bio(struct request_queue *q, struct request *req,
struct bio *bio) struct bio *bio)
{ {
int nr_integrity_segs; int nr_integrity_segs;
struct bio *next = bio->bi_next; struct bio *next = bio->bi_next;
if (blk_integrity_rq(req) == 0 && bio_integrity(bio) == NULL)
return true;
if (blk_integrity_rq(req) == 0 || bio_integrity(bio) == NULL)
return false;
if (bio_integrity(req->bio)->bip_flags != bio_integrity(bio)->bip_flags)
return false;
bio->bi_next = NULL; bio->bi_next = NULL;
nr_integrity_segs = blk_rq_count_integrity_sg(q, bio); nr_integrity_segs = blk_rq_count_integrity_sg(q, bio);
bio->bi_next = next; bio->bi_next = next;
if (req->nr_integrity_segments + nr_integrity_segs > if (req->nr_integrity_segments + nr_integrity_segs >
q->limits.max_integrity_segments) q->limits.max_integrity_segments)
return -1; return false;
req->nr_integrity_segments += nr_integrity_segs; req->nr_integrity_segments += nr_integrity_segs;
return 0; return true;
} }
EXPORT_SYMBOL(blk_integrity_merge_bio); EXPORT_SYMBOL(blk_integrity_merge_bio);
......
...@@ -313,7 +313,7 @@ static inline int ll_new_hw_segment(struct request_queue *q, ...@@ -313,7 +313,7 @@ static inline int ll_new_hw_segment(struct request_queue *q,
if (req->nr_phys_segments + nr_phys_segs > queue_max_segments(q)) if (req->nr_phys_segments + nr_phys_segs > queue_max_segments(q))
goto no_merge; goto no_merge;
if (bio_integrity(bio) && blk_integrity_merge_bio(q, req, bio)) if (blk_integrity_merge_bio(q, req, bio) == false)
goto no_merge; goto no_merge;
/* /*
...@@ -410,7 +410,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req, ...@@ -410,7 +410,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
if (total_phys_segments > queue_max_segments(q)) if (total_phys_segments > queue_max_segments(q))
return 0; return 0;
if (blk_integrity_rq(req) && blk_integrity_merge_rq(q, req, next)) if (blk_integrity_merge_rq(q, req, next) == false)
return 0; return 0;
/* Merge is OK... */ /* Merge is OK... */
...@@ -590,7 +590,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) ...@@ -590,7 +590,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
return false; return false;
/* only merge integrity protected bio into ditto rq */ /* only merge integrity protected bio into ditto rq */
if (bio_integrity(bio) != blk_integrity_rq(rq)) if (blk_integrity_merge_bio(rq->q, rq, bio) == false)
return false; return false;
/* must be using the same buffer */ /* must be using the same buffer */
......
...@@ -1497,10 +1497,10 @@ extern int blk_integrity_compare(struct gendisk *, struct gendisk *); ...@@ -1497,10 +1497,10 @@ extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *,
struct scatterlist *); struct scatterlist *);
extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *);
extern int blk_integrity_merge_rq(struct request_queue *, struct request *, extern bool blk_integrity_merge_rq(struct request_queue *, struct request *,
struct request *); struct request *);
extern int blk_integrity_merge_bio(struct request_queue *, struct request *, extern bool blk_integrity_merge_bio(struct request_queue *, struct request *,
struct bio *); struct bio *);
static inline static inline
struct blk_integrity *bdev_get_integrity(struct block_device *bdev) struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
...@@ -1580,15 +1580,15 @@ static inline unsigned short queue_max_integrity_segments(struct request_queue * ...@@ -1580,15 +1580,15 @@ static inline unsigned short queue_max_integrity_segments(struct request_queue *
{ {
return 0; return 0;
} }
static inline int blk_integrity_merge_rq(struct request_queue *rq, static inline bool blk_integrity_merge_rq(struct request_queue *rq,
struct request *r1, struct request *r1,
struct request *r2) struct request *r2)
{ {
return 0; return 0;
} }
static inline int blk_integrity_merge_bio(struct request_queue *rq, static inline bool blk_integrity_merge_bio(struct request_queue *rq,
struct request *r, struct request *r,
struct bio *b) struct bio *b)
{ {
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册