Skip to content

Commit

Permalink
rbd: move bumping img_request refcount into rbd_obj_request_submit()
Browse files Browse the repository at this point in the history
Commit 0f2d5be ("rbd: use reference counts for image requests")
added rbd_img_request_get(), which rbd_img_request_fill() calls for
each obj_request added to img_request.  It was an urgent band-aid for
the uglyness that is rbd_img_obj_callback() and none of the error paths
were updated.

Given that this img_request reference is meant to represent an
obj_request that hasn't passed through rbd_img_obj_callback() yet,
proper cleanup in appropriate destructors is a challenge.  However,
noting that if we don't get a chance to call rbd_obj_request_complete(),
there is not going to be a call to rbd_img_obj_callback(), we can move
rbd_img_request_get() into rbd_obj_request_submit() and fixup the two
places that call rbd_obj_request_complete() directly and not through
rbd_obj_request_submit() to temporarily bump img_request, so that
rbd_img_obj_callback() can put as usual.

This takes care of img_request leaks on errors on the submit side.

Signed-off-by: Ilya Dryomov <[email protected]>
Reviewed-by: Alex Elder <[email protected]>
  • Loading branch information
idryomov committed Oct 3, 2016
1 parent c2e8241 commit 4a17dad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,17 @@ static bool obj_request_type_valid(enum obj_request_type type)
}
}

static void rbd_img_obj_callback(struct rbd_obj_request *obj_request);

static void rbd_obj_request_submit(struct rbd_obj_request *obj_request)
{
struct ceph_osd_request *osd_req = obj_request->osd_req;

dout("%s %p osd_req %p\n", __func__, obj_request, osd_req);
if (obj_request_img_data_test(obj_request)) {
WARN_ON(obj_request->callback != rbd_img_obj_callback);
rbd_img_request_get(obj_request->img_request);
}
ceph_osdc_start_request(osd_req->r_osdc, osd_req, false);
}

Expand Down Expand Up @@ -2588,8 +2594,6 @@ static int rbd_img_request_fill(struct rbd_img_request *img_request,

rbd_img_obj_request_fill(obj_request, osd_req, op_type, 0);

rbd_img_request_get(img_request);

img_offset += length;
resid -= length;
}
Expand Down Expand Up @@ -2723,10 +2727,9 @@ rbd_img_obj_parent_read_full_callback(struct rbd_img_request *img_request)
return;

out_err:
/* Record the error code and complete the request */

orig_request->result = img_result;
orig_request->xferred = 0;
rbd_img_request_get(orig_request->img_request);
obj_request_done_set(orig_request);
rbd_obj_request_complete(orig_request);
}
Expand Down Expand Up @@ -2881,6 +2884,7 @@ static void rbd_img_obj_exists_callback(struct rbd_obj_request *obj_request)
fail_orig_request:
orig_request->result = result;
orig_request->xferred = 0;
rbd_img_request_get(orig_request->img_request);
obj_request_done_set(orig_request);
rbd_obj_request_complete(orig_request);
}
Expand Down

0 comments on commit 4a17dad

Please sign in to comment.