Skip to content

Commit d3246fb

Browse files
jdurginidryomov
authored andcommitted
rbd: use helpers to handle discard for layered images correctly
Only allocate two osd ops for discard requests, since the preallocation hint is only added for regular writes. Use rbd_img_obj_request_fill() to recreate the original write or discard osd operations, isolating that logic to one place, and change the assert in rbd_osd_req_create_copyup() to accept discard requests as well. Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
1 parent 3b434a2 commit d3246fb

1 file changed

Lines changed: 22 additions & 32 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,9 +1934,10 @@ static struct ceph_osd_request *rbd_osd_req_create(
19341934
}
19351935

19361936
/*
1937-
* Create a copyup osd request based on the information in the
1938-
* object request supplied. A copyup request has three osd ops,
1939-
* a copyup method call, a hint op, and a write op.
1937+
* Create a copyup osd request based on the information in the object
1938+
* request supplied. A copyup request has two or three osd ops, a
1939+
* copyup method call, potentially a hint op, and a write or truncate
1940+
* or zero op.
19401941
*/
19411942
static struct ceph_osd_request *
19421943
rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request)
@@ -1946,18 +1947,24 @@ rbd_osd_req_create_copyup(struct rbd_obj_request *obj_request)
19461947
struct rbd_device *rbd_dev;
19471948
struct ceph_osd_client *osdc;
19481949
struct ceph_osd_request *osd_req;
1950+
int num_osd_ops = 3;
19491951

19501952
rbd_assert(obj_request_img_data_test(obj_request));
19511953
img_request = obj_request->img_request;
19521954
rbd_assert(img_request);
1953-
rbd_assert(img_request_write_test(img_request));
1955+
rbd_assert(img_request_write_test(img_request) ||
1956+
img_request_discard_test(img_request));
19541957

1955-
/* Allocate and initialize the request, for the three ops */
1958+
if (img_request_discard_test(img_request))
1959+
num_osd_ops = 2;
1960+
1961+
/* Allocate and initialize the request, for all the ops */
19561962

19571963
snapc = img_request->snapc;
19581964
rbd_dev = img_request->rbd_dev;
19591965
osdc = &rbd_dev->rbd_client->client->osdc;
1960-
osd_req = ceph_osdc_alloc_request(osdc, snapc, 3, false, GFP_ATOMIC);
1966+
osd_req = ceph_osdc_alloc_request(osdc, snapc, num_osd_ops,
1967+
false, GFP_ATOMIC);
19611968
if (!osd_req)
19621969
return NULL; /* ENOMEM */
19631970

@@ -2337,10 +2344,9 @@ static void rbd_img_obj_request_fill(struct rbd_obj_request *obj_request,
23372344
u16 opcode;
23382345

23392346
if (op_type == OBJ_OP_DISCARD) {
2340-
if (!offset && (length == object_size)
2341-
&& (!img_request_layered_test(img_request) ||
2342-
(rbd_dev->parent_overlap <=
2343-
obj_request->img_offset))) {
2347+
if (!offset && length == object_size &&
2348+
(!img_request_layered_test(img_request) ||
2349+
!obj_request_overlaps_parent(obj_request))) {
23442350
opcode = CEPH_OSD_OP_DELETE;
23452351
} else if ((offset + length == object_size)) {
23462352
opcode = CEPH_OSD_OP_TRUNCATE;
@@ -2500,7 +2506,8 @@ rbd_img_obj_copyup_callback(struct rbd_obj_request *obj_request)
25002506
struct page **pages;
25012507
u32 page_count;
25022508

2503-
rbd_assert(obj_request->type == OBJ_REQUEST_BIO);
2509+
rbd_assert(obj_request->type == OBJ_REQUEST_BIO ||
2510+
obj_request->type == OBJ_REQUEST_NODATA);
25042511
rbd_assert(obj_request_img_data_test(obj_request));
25052512
img_request = obj_request->img_request;
25062513
rbd_assert(img_request);
@@ -2538,11 +2545,10 @@ rbd_img_obj_parent_read_full_callback(struct rbd_img_request *img_request)
25382545
struct ceph_osd_client *osdc;
25392546
struct rbd_device *rbd_dev;
25402547
struct page **pages;
2548+
enum obj_operation_type op_type;
25412549
u32 page_count;
25422550
int img_result;
25432551
u64 parent_length;
2544-
u64 offset;
2545-
u64 length;
25462552

25472553
rbd_assert(img_request_child_test(img_request));
25482554

@@ -2606,26 +2612,10 @@ rbd_img_obj_parent_read_full_callback(struct rbd_img_request *img_request)
26062612
osd_req_op_cls_request_data_pages(osd_req, 0, pages, parent_length, 0,
26072613
false, false);
26082614

2609-
/* Then the hint op */
2610-
2611-
osd_req_op_alloc_hint_init(osd_req, 1, rbd_obj_bytes(&rbd_dev->header),
2612-
rbd_obj_bytes(&rbd_dev->header));
2613-
2614-
/* And the original write request op */
2615-
2616-
offset = orig_request->offset;
2617-
length = orig_request->length;
2618-
osd_req_op_extent_init(osd_req, 2, CEPH_OSD_OP_WRITE,
2619-
offset, length, 0, 0);
2620-
if (orig_request->type == OBJ_REQUEST_BIO)
2621-
osd_req_op_extent_osd_data_bio(osd_req, 2,
2622-
orig_request->bio_list, length);
2623-
else
2624-
osd_req_op_extent_osd_data_pages(osd_req, 2,
2625-
orig_request->pages, length,
2626-
offset & ~PAGE_MASK, false, false);
2615+
/* Add the other op(s) */
26272616

2628-
rbd_osd_req_format_write(orig_request);
2617+
op_type = rbd_img_request_op_type(orig_request->img_request);
2618+
rbd_img_obj_request_fill(orig_request, osd_req, op_type, 1);
26292619

26302620
/* All set, send it off. */
26312621

0 commit comments

Comments
 (0)