summaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2019-05-08 07:35:57 -0400
committerIlya Dryomov <idryomov@gmail.com>2019-07-08 08:01:44 -0400
commita9b67e69949d20dcb38ea6aaed5500318c7c91f6 (patch)
treedd132e809acfee75de2ba3dabb5b4cb46c188594 /drivers/block/rbd.c
parent54ab3b24c536bc9b45ab444830974c6bea57778e (diff)
rbd: replace obj_req->tried_parent with obj_req->read_state
Make rbd_obj_handle_read() look like a state machine and get rid of the necessity to patch result in rbd_obj_handle_request(), completing the removal of obj_req->xferred and img_req->xferred. Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c82
1 files changed, 46 insertions, 36 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index a9b0b23148f9..7925b2fdde79 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -219,6 +219,11 @@ enum obj_operation_type {
219 OBJ_OP_ZEROOUT, 219 OBJ_OP_ZEROOUT,
220}; 220};
221 221
222enum rbd_obj_read_state {
223 RBD_OBJ_READ_OBJECT = 1,
224 RBD_OBJ_READ_PARENT,
225};
226
222/* 227/*
223 * Writes go through the following state machine to deal with 228 * Writes go through the following state machine to deal with
224 * layering: 229 * layering:
@@ -255,7 +260,7 @@ enum rbd_obj_write_state {
255struct rbd_obj_request { 260struct rbd_obj_request {
256 struct ceph_object_extent ex; 261 struct ceph_object_extent ex;
257 union { 262 union {
258 bool tried_parent; /* for reads */ 263 enum rbd_obj_read_state read_state; /* for reads */
259 enum rbd_obj_write_state write_state; /* for writes */ 264 enum rbd_obj_write_state write_state; /* for writes */
260 }; 265 };
261 266
@@ -1794,6 +1799,7 @@ static int rbd_obj_setup_read(struct rbd_obj_request *obj_req)
1794 rbd_osd_req_setup_data(obj_req, 0); 1799 rbd_osd_req_setup_data(obj_req, 0);
1795 1800
1796 rbd_osd_req_format_read(obj_req); 1801 rbd_osd_req_format_read(obj_req);
1802 obj_req->read_state = RBD_OBJ_READ_OBJECT;
1797 return 0; 1803 return 0;
1798} 1804}
1799 1805
@@ -2402,44 +2408,48 @@ static bool rbd_obj_handle_read(struct rbd_obj_request *obj_req, int *result)
2402 struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev; 2408 struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev;
2403 int ret; 2409 int ret;
2404 2410
2405 if (*result == -ENOENT && 2411 switch (obj_req->read_state) {
2406 rbd_dev->parent_overlap && !obj_req->tried_parent) { 2412 case RBD_OBJ_READ_OBJECT:
2407 /* reverse map this object extent onto the parent */ 2413 if (*result == -ENOENT && rbd_dev->parent_overlap) {
2408 ret = rbd_obj_calc_img_extents(obj_req, false); 2414 /* reverse map this object extent onto the parent */
2409 if (ret) { 2415 ret = rbd_obj_calc_img_extents(obj_req, false);
2410 *result = ret;
2411 return true;
2412 }
2413
2414 if (obj_req->num_img_extents) {
2415 obj_req->tried_parent = true;
2416 ret = rbd_obj_read_from_parent(obj_req);
2417 if (ret) { 2416 if (ret) {
2418 *result = ret; 2417 *result = ret;
2419 return true; 2418 return true;
2420 } 2419 }
2421 return false; 2420 if (obj_req->num_img_extents) {
2421 ret = rbd_obj_read_from_parent(obj_req);
2422 if (ret) {
2423 *result = ret;
2424 return true;
2425 }
2426 obj_req->read_state = RBD_OBJ_READ_PARENT;
2427 return false;
2428 }
2422 } 2429 }
2423 }
2424 2430
2425 /* 2431 /*
2426 * -ENOENT means a hole in the image -- zero-fill the entire 2432 * -ENOENT means a hole in the image -- zero-fill the entire
2427 * length of the request. A short read also implies zero-fill 2433 * length of the request. A short read also implies zero-fill
2428 * to the end of the request. 2434 * to the end of the request.
2429 */ 2435 */
2430 if (*result == -ENOENT) { 2436 if (*result == -ENOENT) {
2431 rbd_obj_zero_range(obj_req, 0, obj_req->ex.oe_len); 2437 rbd_obj_zero_range(obj_req, 0, obj_req->ex.oe_len);
2432 *result = 0; 2438 *result = 0;
2433 } else if (*result >= 0) { 2439 } else if (*result >= 0) {
2434 if (*result < obj_req->ex.oe_len) 2440 if (*result < obj_req->ex.oe_len)
2435 rbd_obj_zero_range(obj_req, *result, 2441 rbd_obj_zero_range(obj_req, *result,
2436 obj_req->ex.oe_len - *result); 2442 obj_req->ex.oe_len - *result);
2437 else 2443 else
2438 rbd_assert(*result == obj_req->ex.oe_len); 2444 rbd_assert(*result == obj_req->ex.oe_len);
2439 *result = 0; 2445 *result = 0;
2446 }
2447 return true;
2448 case RBD_OBJ_READ_PARENT:
2449 return true;
2450 default:
2451 BUG();
2440 } 2452 }
2441
2442 return true;
2443} 2453}
2444 2454
2445/* 2455/*
@@ -2658,11 +2668,11 @@ static bool rbd_obj_handle_write(struct rbd_obj_request *obj_req, int *result)
2658 case RBD_OBJ_WRITE_COPYUP_OPS: 2668 case RBD_OBJ_WRITE_COPYUP_OPS:
2659 return true; 2669 return true;
2660 case RBD_OBJ_WRITE_READ_FROM_PARENT: 2670 case RBD_OBJ_WRITE_READ_FROM_PARENT:
2661 if (*result < 0) 2671 if (*result)
2662 return true; 2672 return true;
2663 2673
2664 rbd_assert(*result); 2674 ret = rbd_obj_issue_copyup(obj_req,
2665 ret = rbd_obj_issue_copyup(obj_req, *result); 2675 rbd_obj_img_extents_bytes(obj_req));
2666 if (ret) { 2676 if (ret) {
2667 *result = ret; 2677 *result = ret;
2668 return true; 2678 return true;
@@ -2757,7 +2767,7 @@ again:
2757 rbd_assert(img_req->result <= 0); 2767 rbd_assert(img_req->result <= 0);
2758 if (test_bit(IMG_REQ_CHILD, &img_req->flags)) { 2768 if (test_bit(IMG_REQ_CHILD, &img_req->flags)) {
2759 obj_req = img_req->obj_request; 2769 obj_req = img_req->obj_request;
2760 result = img_req->result ?: rbd_obj_img_extents_bytes(obj_req); 2770 result = img_req->result;
2761 rbd_img_request_put(img_req); 2771 rbd_img_request_put(img_req);
2762 goto again; 2772 goto again;
2763 } 2773 }