Skip to content

Commit 0ea7840

Browse files
bvanasschekawasaki
authored andcommitted
block: Introduce accessor functions for copy offload bios
Make it easy for block drivers to iterate over the copy offload bios by providing accessor functions for the copy offloading bios. Signed-off-by: Bart Van Assche <[email protected]>
1 parent c716f70 commit 0ea7840

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

block/blk-copy.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,53 @@
77
#include <linux/blk-copy.h>
88
#include <linux/blk-mq.h>
99

10+
static struct bio *__blk_next_copy_bio(struct request *rq, struct bio *prev_bio,
11+
enum req_op op)
12+
{
13+
struct bio *bio;
14+
15+
if (prev_bio) {
16+
bio = prev_bio->bi_next;
17+
} else {
18+
struct bio_copy_offload_ctx *copy_ctx = rq->bio->bi_copy_ctx;
19+
20+
bio = copy_ctx->bios;
21+
}
22+
23+
for (; bio && bio_op(bio) != op; bio = bio->bi_next)
24+
;
25+
return bio;
26+
}
27+
28+
struct bio *blk_first_copy_bio(struct request *rq, enum req_op op)
29+
{
30+
struct bio *bio = rq->bio;
31+
32+
if (bio_op(bio) == op)
33+
return bio;
34+
35+
return __blk_next_copy_bio(rq, NULL, op);
36+
}
37+
EXPORT_SYMBOL_GPL(blk_first_copy_bio);
38+
39+
struct bio *blk_next_copy_bio(struct bio *bio)
40+
{
41+
return __blk_next_copy_bio(NULL, bio, bio_op(bio));
42+
}
43+
EXPORT_SYMBOL_GPL(blk_next_copy_bio);
44+
45+
unsigned int blk_copy_bio_count(struct request *rq, enum req_op op)
46+
{
47+
unsigned int count = 0;
48+
49+
for (struct bio *bio = blk_first_copy_bio(rq, op); bio;
50+
bio = blk_next_copy_bio(bio))
51+
count++;
52+
53+
return count;
54+
}
55+
EXPORT_SYMBOL_GPL(blk_copy_bio_count);
56+
1057
/**
1158
* Tracks the state of a single onloaded copy operation.
1259
* @params: Data copy parameters.

include/linux/blk-copy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ struct bio_copy_offload_ctx {
4343
void (*translation_complete)(struct bio_copy_offload_ctx *ctx);
4444
};
4545

46+
struct bio *blk_first_copy_bio(struct request *rq, enum req_op op);
47+
struct bio *blk_next_copy_bio(struct bio *bio);
48+
unsigned int blk_copy_bio_count(struct request *rq, enum req_op op);
49+
4650
#endif /* __LINUX_BLK_COPY_H */

0 commit comments

Comments
 (0)