Skip to content

Commit 5359a17

Browse files
committed
libceph, rbd: new bio handling code (aka don't clone bios)
The reason we clone bios is to be able to give each object request (and consequently each ceph_osd_data/ceph_msg_data item) its own pointer to a (list of) bio(s). The messenger then initializes its cursor with cloned bio's ->bi_iter, so it knows where to start reading from/writing to. That's all the cloned bios are used for: to determine each object request's starting position in the provided data buffer. Introduce ceph_bio_iter to do exactly that -- store position within bio list (i.e. pointer to bio) + position within that bio (i.e. bvec_iter). Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent a1fbb5e commit 5359a17

5 files changed

Lines changed: 139 additions & 112 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ typedef void (*rbd_obj_callback_t)(struct rbd_obj_request *);
218218

219219
enum obj_request_type {
220220
OBJ_REQUEST_NODATA = 1,
221-
OBJ_REQUEST_BIO,
221+
OBJ_REQUEST_BIO, /* pointer into provided bio (list) */
222222
OBJ_REQUEST_PAGES,
223223
};
224224

@@ -270,7 +270,7 @@ struct rbd_obj_request {
270270

271271
enum obj_request_type type;
272272
union {
273-
struct bio *bio_list;
273+
struct ceph_bio_iter bio_pos;
274274
struct {
275275
struct page **pages;
276276
u32 page_count;
@@ -1255,6 +1255,27 @@ static u64 rbd_segment_length(struct rbd_device *rbd_dev,
12551255
return length;
12561256
}
12571257

1258+
static void zero_bvec(struct bio_vec *bv)
1259+
{
1260+
void *buf;
1261+
unsigned long flags;
1262+
1263+
buf = bvec_kmap_irq(bv, &flags);
1264+
memset(buf, 0, bv->bv_len);
1265+
flush_dcache_page(bv->bv_page);
1266+
bvec_kunmap_irq(buf, &flags);
1267+
}
1268+
1269+
static void zero_bios(struct ceph_bio_iter *bio_pos, u32 off, u32 bytes)
1270+
{
1271+
struct ceph_bio_iter it = *bio_pos;
1272+
1273+
ceph_bio_iter_advance(&it, off);
1274+
ceph_bio_iter_advance_step(&it, bytes, ({
1275+
zero_bvec(&bv);
1276+
}));
1277+
}
1278+
12581279
/*
12591280
* bio helpers
12601281
*/
@@ -1719,13 +1740,14 @@ rbd_img_obj_request_read_callback(struct rbd_obj_request *obj_request)
17191740
rbd_assert(obj_request->type != OBJ_REQUEST_NODATA);
17201741
if (obj_request->result == -ENOENT) {
17211742
if (obj_request->type == OBJ_REQUEST_BIO)
1722-
zero_bio_chain(obj_request->bio_list, 0);
1743+
zero_bios(&obj_request->bio_pos, 0, length);
17231744
else
17241745
zero_pages(obj_request->pages, 0, length);
17251746
obj_request->result = 0;
17261747
} else if (xferred < length && !obj_request->result) {
17271748
if (obj_request->type == OBJ_REQUEST_BIO)
1728-
zero_bio_chain(obj_request->bio_list, xferred);
1749+
zero_bios(&obj_request->bio_pos, xferred,
1750+
length - xferred);
17291751
else
17301752
zero_pages(obj_request->pages, xferred, length);
17311753
}
@@ -2036,11 +2058,8 @@ static void rbd_obj_request_destroy(struct kref *kref)
20362058
rbd_assert(obj_request_type_valid(obj_request->type));
20372059
switch (obj_request->type) {
20382060
case OBJ_REQUEST_NODATA:
2039-
break; /* Nothing to do */
20402061
case OBJ_REQUEST_BIO:
2041-
if (obj_request->bio_list)
2042-
bio_chain_put(obj_request->bio_list);
2043-
break;
2062+
break; /* Nothing to do */
20442063
case OBJ_REQUEST_PAGES:
20452064
/* img_data requests don't own their page array */
20462065
if (obj_request->pages &&
@@ -2368,7 +2387,7 @@ static void rbd_img_obj_request_fill(struct rbd_obj_request *obj_request,
23682387

23692388
if (obj_request->type == OBJ_REQUEST_BIO)
23702389
osd_req_op_extent_osd_data_bio(osd_request, num_ops,
2371-
obj_request->bio_list, length);
2390+
&obj_request->bio_pos, length);
23722391
else if (obj_request->type == OBJ_REQUEST_PAGES)
23732392
osd_req_op_extent_osd_data_pages(osd_request, num_ops,
23742393
obj_request->pages, length,
@@ -2396,8 +2415,7 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request,
23962415
struct rbd_device *rbd_dev = img_request->rbd_dev;
23972416
struct rbd_obj_request *obj_request = NULL;
23982417
struct rbd_obj_request *next_obj_request;
2399-
struct bio *bio_list = NULL;
2400-
unsigned int bio_offset = 0;
2418+
struct ceph_bio_iter bio_it;
24012419
struct page **pages = NULL;
24022420
enum obj_operation_type op_type;
24032421
u64 img_offset;
@@ -2412,9 +2430,9 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request,
24122430
op_type = rbd_img_request_op_type(img_request);
24132431

24142432
if (type == OBJ_REQUEST_BIO) {
2415-
bio_list = data_desc;
2433+
bio_it = *(struct ceph_bio_iter *)data_desc;
24162434
rbd_assert(img_offset ==
2417-
bio_list->bi_iter.bi_sector << SECTOR_SHIFT);
2435+
bio_it.iter.bi_sector << SECTOR_SHIFT);
24182436
} else if (type == OBJ_REQUEST_PAGES) {
24192437
pages = data_desc;
24202438
}
@@ -2440,17 +2458,8 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request,
24402458
rbd_img_obj_request_add(img_request, obj_request);
24412459

24422460
if (type == OBJ_REQUEST_BIO) {
2443-
unsigned int clone_size;
2444-
2445-
rbd_assert(length <= (u64)UINT_MAX);
2446-
clone_size = (unsigned int)length;
2447-
obj_request->bio_list =
2448-
bio_chain_clone_range(&bio_list,
2449-
&bio_offset,
2450-
clone_size,
2451-
GFP_NOIO);
2452-
if (!obj_request->bio_list)
2453-
goto out_unwind;
2461+
obj_request->bio_pos = bio_it;
2462+
ceph_bio_iter_advance(&bio_it, length);
24542463
} else if (type == OBJ_REQUEST_PAGES) {
24552464
unsigned int page_count;
24562465

@@ -2980,7 +2989,7 @@ static void rbd_img_parent_read(struct rbd_obj_request *obj_request)
29802989

29812990
if (obj_request->type == OBJ_REQUEST_BIO)
29822991
result = rbd_img_request_fill(img_request, OBJ_REQUEST_BIO,
2983-
obj_request->bio_list);
2992+
&obj_request->bio_pos);
29842993
else
29852994
result = rbd_img_request_fill(img_request, OBJ_REQUEST_PAGES,
29862995
obj_request->pages);
@@ -4093,9 +4102,13 @@ static void rbd_queue_workfn(struct work_struct *work)
40934102
if (op_type == OBJ_OP_DISCARD)
40944103
result = rbd_img_request_fill(img_request, OBJ_REQUEST_NODATA,
40954104
NULL);
4096-
else
4105+
else {
4106+
struct ceph_bio_iter bio_it = { .bio = rq->bio,
4107+
.iter = rq->bio->bi_iter };
4108+
40974109
result = rbd_img_request_fill(img_request, OBJ_REQUEST_BIO,
4098-
rq->bio);
4110+
&bio_it);
4111+
}
40994112
if (result)
41004113
goto err_img_request;
41014114

‎include/linux/ceph/messenger.h‎

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,60 @@ static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type)
9393
}
9494
}
9595

96+
#ifdef CONFIG_BLOCK
97+
98+
struct ceph_bio_iter {
99+
struct bio *bio;
100+
struct bvec_iter iter;
101+
};
102+
103+
#define __ceph_bio_iter_advance_step(it, n, STEP) do { \
104+
unsigned int __n = (n), __cur_n; \
105+
\
106+
while (__n) { \
107+
BUG_ON(!(it)->iter.bi_size); \
108+
__cur_n = min((it)->iter.bi_size, __n); \
109+
(void)(STEP); \
110+
bio_advance_iter((it)->bio, &(it)->iter, __cur_n); \
111+
if (!(it)->iter.bi_size && (it)->bio->bi_next) { \
112+
dout("__ceph_bio_iter_advance_step next bio\n"); \
113+
(it)->bio = (it)->bio->bi_next; \
114+
(it)->iter = (it)->bio->bi_iter; \
115+
} \
116+
__n -= __cur_n; \
117+
} \
118+
} while (0)
119+
120+
/*
121+
* Advance @it by @n bytes.
122+
*/
123+
#define ceph_bio_iter_advance(it, n) \
124+
__ceph_bio_iter_advance_step(it, n, 0)
125+
126+
/*
127+
* Advance @it by @n bytes, executing BVEC_STEP for each bio_vec.
128+
*/
129+
#define ceph_bio_iter_advance_step(it, n, BVEC_STEP) \
130+
__ceph_bio_iter_advance_step(it, n, ({ \
131+
struct bio_vec bv; \
132+
struct bvec_iter __cur_iter; \
133+
\
134+
__cur_iter = (it)->iter; \
135+
__cur_iter.bi_size = __cur_n; \
136+
__bio_for_each_segment(bv, (it)->bio, __cur_iter, __cur_iter) \
137+
(void)(BVEC_STEP); \
138+
}))
139+
140+
#endif /* CONFIG_BLOCK */
141+
96142
struct ceph_msg_data {
97143
struct list_head links; /* ceph_msg->data */
98144
enum ceph_msg_data_type type;
99145
union {
100146
#ifdef CONFIG_BLOCK
101147
struct {
102-
struct bio *bio;
103-
size_t bio_length;
148+
struct ceph_bio_iter bio_pos;
149+
u32 bio_length;
104150
};
105151
#endif /* CONFIG_BLOCK */
106152
struct {
@@ -122,10 +168,7 @@ struct ceph_msg_data_cursor {
122168
bool need_crc; /* crc update needed */
123169
union {
124170
#ifdef CONFIG_BLOCK
125-
struct { /* bio */
126-
struct bio *bio; /* bio from list */
127-
struct bvec_iter bvec_iter;
128-
};
171+
struct ceph_bio_iter bio_iter;
129172
#endif /* CONFIG_BLOCK */
130173
struct { /* pages */
131174
unsigned int page_offset; /* offset in page */
@@ -290,8 +333,8 @@ extern void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages,
290333
extern void ceph_msg_data_add_pagelist(struct ceph_msg *msg,
291334
struct ceph_pagelist *pagelist);
292335
#ifdef CONFIG_BLOCK
293-
extern void ceph_msg_data_add_bio(struct ceph_msg *msg, struct bio *bio,
294-
size_t length);
336+
void ceph_msg_data_add_bio(struct ceph_msg *msg, struct ceph_bio_iter *bio_pos,
337+
u32 length);
295338
#endif /* CONFIG_BLOCK */
296339

297340
extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,

‎include/linux/ceph/osd_client.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ struct ceph_osd_data {
7272
struct ceph_pagelist *pagelist;
7373
#ifdef CONFIG_BLOCK
7474
struct {
75-
struct bio *bio; /* list of bios */
76-
size_t bio_length; /* total in list */
75+
struct ceph_bio_iter bio_pos;
76+
u32 bio_length;
7777
};
7878
#endif /* CONFIG_BLOCK */
7979
};
@@ -405,9 +405,10 @@ extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
405405
unsigned int which,
406406
struct ceph_pagelist *pagelist);
407407
#ifdef CONFIG_BLOCK
408-
extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
409-
unsigned int which,
410-
struct bio *bio, size_t bio_length);
408+
void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
409+
unsigned int which,
410+
struct ceph_bio_iter *bio_pos,
411+
u32 bio_length);
411412
#endif /* CONFIG_BLOCK */
412413

413414
extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,

0 commit comments

Comments
 (0)