Skip to content

Commit badf7f6

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move a few merge helpers out of <linux/blkdev.h>
These are block-layer internal helpers, so move them to block/blk.h and block/blk-merge.c. Also update a comment a bit to use better grammar. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20210920123328.1399408-16-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b81e0c2 commit badf7f6

3 files changed

Lines changed: 62 additions & 64 deletions

File tree

‎block/blk-merge.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,23 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq)
558558
return queue_max_segments(rq->q);
559559
}
560560

561+
static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
562+
sector_t offset)
563+
{
564+
struct request_queue *q = rq->q;
565+
566+
if (blk_rq_is_passthrough(rq))
567+
return q->limits.max_hw_sectors;
568+
569+
if (!q->limits.chunk_sectors ||
570+
req_op(rq) == REQ_OP_DISCARD ||
571+
req_op(rq) == REQ_OP_SECURE_ERASE)
572+
return blk_queue_get_max_sectors(q, req_op(rq));
573+
574+
return min(blk_max_size_offset(q, offset, 0),
575+
blk_queue_get_max_sectors(q, req_op(rq)));
576+
}
577+
561578
static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
562579
unsigned int nr_phys_segs)
563580
{
@@ -718,6 +735,13 @@ static enum elv_merge blk_try_req_merge(struct request *req,
718735
return ELEVATOR_NO_MERGE;
719736
}
720737

738+
static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
739+
{
740+
if (bio_page(a) == bio_page(b) && bio_offset(a) == bio_offset(b))
741+
return true;
742+
return false;
743+
}
744+
721745
/*
722746
* For non-mq, this has to be called with the request spinlock acquired.
723747
* For mq with scheduling, the appropriate queue wide lock should be held.

‎block/blk.h‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,44 @@ static inline bool bvec_gap_to_prev(struct request_queue *q,
9696
return __bvec_gap_to_prev(q, bprv, offset);
9797
}
9898

99+
static inline bool rq_mergeable(struct request *rq)
100+
{
101+
if (blk_rq_is_passthrough(rq))
102+
return false;
103+
104+
if (req_op(rq) == REQ_OP_FLUSH)
105+
return false;
106+
107+
if (req_op(rq) == REQ_OP_WRITE_ZEROES)
108+
return false;
109+
110+
if (req_op(rq) == REQ_OP_ZONE_APPEND)
111+
return false;
112+
113+
if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
114+
return false;
115+
if (rq->rq_flags & RQF_NOMERGE_FLAGS)
116+
return false;
117+
118+
return true;
119+
}
120+
121+
/*
122+
* There are two different ways to handle DISCARD merges:
123+
* 1) If max_discard_segments > 1, the driver treats every bio as a range and
124+
* send the bios to controller together. The ranges don't need to be
125+
* contiguous.
126+
* 2) Otherwise, the request will be normal read/write requests. The ranges
127+
* need to be contiguous.
128+
*/
129+
static inline bool blk_discard_mergable(struct request *req)
130+
{
131+
if (req_op(req) == REQ_OP_DISCARD &&
132+
queue_max_discard_segments(req->q) > 1)
133+
return true;
134+
return false;
135+
}
136+
99137
#ifdef CONFIG_BLK_DEV_INTEGRITY
100138
void blk_flush_integrity(void);
101139
bool __bio_integrity_endio(struct bio *);

‎include/linux/blkdev.h‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -745,37 +745,6 @@ static inline bool rq_is_sync(struct request *rq)
745745
return op_is_sync(rq->cmd_flags);
746746
}
747747

748-
static inline bool rq_mergeable(struct request *rq)
749-
{
750-
if (blk_rq_is_passthrough(rq))
751-
return false;
752-
753-
if (req_op(rq) == REQ_OP_FLUSH)
754-
return false;
755-
756-
if (req_op(rq) == REQ_OP_WRITE_ZEROES)
757-
return false;
758-
759-
if (req_op(rq) == REQ_OP_ZONE_APPEND)
760-
return false;
761-
762-
if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
763-
return false;
764-
if (rq->rq_flags & RQF_NOMERGE_FLAGS)
765-
return false;
766-
767-
return true;
768-
}
769-
770-
static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
771-
{
772-
if (bio_page(a) == bio_page(b) &&
773-
bio_offset(a) == bio_offset(b))
774-
return true;
775-
776-
return false;
777-
}
778-
779748
static inline unsigned int blk_queue_depth(struct request_queue *q)
780749
{
781750
if (q->queue_depth)
@@ -1030,23 +999,6 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
1030999
return min(q->limits.max_sectors, chunk_sectors);
10311000
}
10321001

1033-
static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
1034-
sector_t offset)
1035-
{
1036-
struct request_queue *q = rq->q;
1037-
1038-
if (blk_rq_is_passthrough(rq))
1039-
return q->limits.max_hw_sectors;
1040-
1041-
if (!q->limits.chunk_sectors ||
1042-
req_op(rq) == REQ_OP_DISCARD ||
1043-
req_op(rq) == REQ_OP_SECURE_ERASE)
1044-
return blk_queue_get_max_sectors(q, req_op(rq));
1045-
1046-
return min(blk_max_size_offset(q, offset, 0),
1047-
blk_queue_get_max_sectors(q, req_op(rq)));
1048-
}
1049-
10501002
static inline unsigned int blk_rq_count_bios(struct request *rq)
10511003
{
10521004
unsigned int nr_bios = 0;
@@ -1490,22 +1442,6 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
14901442
return offset << SECTOR_SHIFT;
14911443
}
14921444

1493-
/*
1494-
* Two cases of handling DISCARD merge:
1495-
* If max_discard_segments > 1, the driver takes every bio
1496-
* as a range and send them to controller together. The ranges
1497-
* needn't to be contiguous.
1498-
* Otherwise, the bios/requests will be handled as same as
1499-
* others which should be contiguous.
1500-
*/
1501-
static inline bool blk_discard_mergable(struct request *req)
1502-
{
1503-
if (req_op(req) == REQ_OP_DISCARD &&
1504-
queue_max_discard_segments(req->q) > 1)
1505-
return true;
1506-
return false;
1507-
}
1508-
15091445
static inline int bdev_discard_alignment(struct block_device *bdev)
15101446
{
15111447
struct request_queue *q = bdev_get_queue(bdev);

0 commit comments

Comments
 (0)