From patchwork Thu Jan 24 16:33:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2033801 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id DB913DF264 for ; Thu, 24 Jan 2013 16:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752830Ab3AXQd7 (ORCPT ); Thu, 24 Jan 2013 11:33:59 -0500 Received: from mail-oa0-f46.google.com ([209.85.219.46]:34103 "EHLO mail-oa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752573Ab3AXQd7 (ORCPT ); Thu, 24 Jan 2013 11:33:59 -0500 Received: by mail-oa0-f46.google.com with SMTP id h16so10192024oag.33 for ; Thu, 24 Jan 2013 08:33:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=M4Qe8MGYSiLJxuWKTMvow3MUfHYwFSXo3iv4sr11JgY=; b=SwjoOlW6Y6ONOMwnuOFXTfz3yhgX3/atOK/Ggz63V5KrgwlUDxD4oykStw2jgXN9MX EJAYRw64i5GJo8dDzVeGMBWDHgMK4B4aiSR5msXKI2Hy+wt2BBh90Sst/AQLiZuAhBMJ GwuELeSrgYOHmkUFWPg5SoN89bBD3U0IX14OfnKXSvYzIhU577p+9LK2goPbBPYttyGN HeMVunhAD3Lff8UG8+4I9HdpjNKjwDyS6pwns8ElbU73X1ajxo88CqS7EMNuRDlyLoas 1BmGhmw236otnWYs981J4qloZMgROoRgrCWiJkxQ0sptTWIWsWFzaHLjYzmI1iwkkpEr 2Xuw== X-Received: by 10.50.36.133 with SMTP id q5mr1718067igj.109.1359045238683; Thu, 24 Jan 2013 08:33:58 -0800 (PST) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id fv6sm1396053igc.17.2013.01.24.08.33.56 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Jan 2013 08:33:57 -0800 (PST) Message-ID: <51016274.2070408@inktank.com> Date: Thu, 24 Jan 2013 10:33:56 -0600 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: "ceph-devel@vger.kernel.org" Subject: [PATCH 06/12, v2] rbd: implement watch/unwatch with new code References: <50FF11EA.3000808@inktank.com> <50FF128B.1030405@inktank.com> <5101406E.4060602@inktank.com> In-Reply-To: <5101406E.4060602@inktank.com> X-Gm-Message-State: ALoCoQmkdUB5tCmRA5TtFB2+2lC/58LPnFBKt39ZHMGbQaoKaxnHuDffPUc9cGqCoyNj+P7QPNv4 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Implement a new function to set up or tear down a watch event for an mapped rbd image header using the new request code. Create a new object request type "nodata" to handle this. And define rbd_osd_trivial_callback() which simply marks a request done. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) const char *object_name; @@ -1083,6 +1083,7 @@ static inline void rbd_img_obj_request_del(struct rbd_img_request *img_request, static bool obj_req_type_valid(enum obj_req_type type) { switch (type) { + case obj_req_nodata: case obj_req_bio: case obj_req_pages: return true; @@ -1306,6 +1307,12 @@ static int rbd_obj_request_wait(struct rbd_obj_request *obj_request) return wait_for_completion_interruptible(&obj_request->completion); } +static void rbd_osd_trivial_callback(struct rbd_obj_request *obj_request, + struct ceph_osd_op *op) +{ + atomic_set(&obj_request->done, 1); +} + static void rbd_obj_request_complete(struct rbd_obj_request *obj_request) { if (obj_request->callback) @@ -1500,6 +1507,9 @@ static void rbd_osd_req_callback(struct ceph_osd_request *osd_req, case CEPH_OSD_OP_WRITE: rbd_osd_write_callback(obj_request, op); break; + case CEPH_OSD_OP_WATCH: + rbd_osd_trivial_callback(obj_request, op); + break; default: rbd_warn(NULL, "%s: unsupported op %hu\n", obj_request->object_name, (unsigned short) opcode); @@ -1543,6 +1553,8 @@ static struct ceph_osd_request *rbd_osd_req_create( rbd_assert(obj_req_type_valid(obj_request->type)); switch (obj_request->type) { + case obj_req_nodata: + break; /* Nothing to do */ case obj_req_bio: rbd_assert(obj_request->bio_list != NULL); osd_req->r_bio = obj_request->bio_list; @@ -1637,6 +1649,8 @@ static void rbd_obj_request_destroy(struct kref *kref) rbd_assert(obj_req_type_valid(obj_request->type)); switch (obj_request->type) { + case obj_req_nodata: + break; /* Nothing to do */ case obj_req_bio: if (obj_request->bio_list) bio_chain_put(obj_request->bio_list); @@ -1863,6 +1877,72 @@ static int rbd_img_request_submit(struct rbd_img_request *img_request) return 0; } +/* + * Request sync osd watch/unwatch. The value of "start" determines + * whether a watch request is being initiated or torn down. + */ +static int rbd_dev_header_watch_sync(struct rbd_device *rbd_dev, int start) +{ + struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; + struct rbd_obj_request *obj_request; + struct ceph_osd_req_op *op; + int ret; + + rbd_assert(start ^ !!rbd_dev->watch_event); + rbd_assert(start ^ !!rbd_dev->watch_request); + + if (start) { + ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, rbd_dev, + &rbd_dev->watch_event); + if (ret < 0) + return ret; + } + + ret = -ENOMEM; + obj_request = rbd_obj_request_create(rbd_dev->header_name, + 0, 0, obj_req_nodata); + if (!obj_request) + goto out_cancel; + + op = rbd_osd_req_op_create(CEPH_OSD_OP_WATCH, + rbd_dev->watch_event->cookie, + rbd_dev->header.obj_version, start); + if (!op) + goto out_cancel; + obj_request->osd_req = rbd_osd_req_create(rbd_dev, true, + obj_request, op); + rbd_osd_req_op_destroy(op); + if (!obj_request->osd_req) + goto out_cancel; + + if (start) { + rbd_dev->watch_request = obj_request->osd_req; + ceph_osdc_set_request_linger(osdc, rbd_dev->watch_request); + } + ret = rbd_obj_request_submit(osdc, obj_request); + if (ret) + goto out_cancel; + ret = rbd_obj_request_wait(obj_request); + if (ret) + goto out_cancel; + + ret = obj_request->result; + if (ret) + goto out_cancel; + + if (start) + goto done; /* Done if setting up the watch request */ +out_cancel: + /* Cancel the event if we're tearing down, or on error */ + ceph_osdc_cancel_event(rbd_dev->watch_event); + rbd_dev->watch_event = NULL; +done: + if (obj_request) + rbd_obj_request_put(obj_request); + + return ret; +} + static void rbd_request_fn(struct request_queue *q) { struct rbd_device *rbd_dev = q->queuedata; @@ -3880,7 +3960,8 @@ static int rbd_dev_probe_finish(struct rbd_device *rbd_dev) if (ret) goto err_out_bus; - ret = rbd_req_sync_watch(rbd_dev, 1); + (void) rbd_req_sync_watch; /* avoid a warning */ + ret = rbd_dev_header_watch_sync(rbd_dev, 1); if (ret) goto err_out_bus; @@ -4043,7 +4124,7 @@ static void rbd_dev_release(struct device *dev) rbd_dev->watch_request); } if (rbd_dev->watch_event) - rbd_req_sync_watch(rbd_dev, 0); + rbd_dev_header_watch_sync(rbd_dev, 0); /* clean up and free blkdev */ rbd_free_disk(rbd_dev); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 750fc73..7b1eddc 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -170,7 +170,7 @@ typedef void (*rbd_img_callback_t)(struct rbd_img_request *); struct rbd_obj_request; typedef void (*rbd_obj_callback_t)(struct rbd_obj_request *); -enum obj_req_type { obj_req_bio, obj_req_pages }; +enum obj_req_type { obj_req_nodata, obj_req_bio, obj_req_pages }; struct rbd_obj_request {