From patchwork Wed Jun 25 17:16:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 4422431 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 89A909F1D6 for ; Wed, 25 Jun 2014 17:17:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ADC9920394 for ; Wed, 25 Jun 2014 17:17:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D67352038D for ; Wed, 25 Jun 2014 17:17:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757710AbaFYRRW (ORCPT ); Wed, 25 Jun 2014 13:17:22 -0400 Received: from mail-la0-f51.google.com ([209.85.215.51]:44583 "EHLO mail-la0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757671AbaFYRRT (ORCPT ); Wed, 25 Jun 2014 13:17:19 -0400 Received: by mail-la0-f51.google.com with SMTP id mc6so999630lab.10 for ; Wed, 25 Jun 2014 10:17:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=KtWoPkNnX61JFC5O99ydGvvpGpcRF51pto8yxOHy8KU=; b=HeYs9p6/KNZmEJSkCzmAvvVKK2VVa2aIXrrTNoUut4sdYYqVfURF7zZ0aVWIS6nNPZ hhfAtJc2OiGpRTcdYCpvzgkGSSd/pCPUOcpX4lq3lc4WWFoEzYzMyg4ej8EJhBNLI0k9 NyJr1wie/AHWOC5zZJPG9jI1oNom4WRbJGx5wMwQ3PxR3EAwYXL1nko95/Nw9dkljttL CP1KX+gnvY5eIg3+F48bsrlK/tGKqUz0V7apTU7voB+ln+DlioTng0rTvo6Dtd3d4WY+ AJxbUKMfLHVJM9ZcLsyNwUCQQxD4iJEQeTJ0mWArRy2tUMtAY39iXpFVMBpkM7N28dc6 RWJQ== X-Gm-Message-State: ALoCoQmG4+xs6V5GfcHuIIdoKHnnWpYy1asUbm8XHjOfqtQ+2A5aFKW7T06qlt6g5x7QQgjD5NcL X-Received: by 10.112.85.202 with SMTP id j10mr1755201lbz.95.1403716638450; Wed, 25 Jun 2014 10:17:18 -0700 (PDT) Received: from localhost ([109.110.67.53]) by mx.google.com with ESMTPSA id kh4sm4217245lbc.29.2014.06.25.10.17.17 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 25 Jun 2014 10:17:17 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 11/14] rbd: add rbd_obj_watch_request_helper() helper Date: Wed, 25 Jun 2014 21:16:44 +0400 Message-Id: <1403716607-13535-12-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1403716607-13535-1-git-send-email-ilya.dryomov@inktank.com> References: <1403716607-13535-1-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the past, rbd_dev_header_watch_sync() used to handle both watch and unwatch requests and was entangled and leaky. Commit b30a01f2a307 ("rbd: fix osd_request memory leak in __rbd_dev_header_watch_sync()") split it into two separate functions. This commit cleanly abstracts the common bits, relying on the fixed rbd_obj_request_wait(). Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder --- drivers/block/rbd.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 20147aec86f3..02cf7aba7679 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2971,6 +2971,59 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data) } /* + * Send a (un)watch request and wait for the ack. Return a request + * with a ref held on success or error. + */ +static struct rbd_obj_request *rbd_obj_watch_request_helper( + struct rbd_device *rbd_dev, + bool watch) +{ + struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; + struct rbd_obj_request *obj_request; + int ret; + + obj_request = rbd_obj_request_create(rbd_dev->header_name, 0, 0, + OBJ_REQUEST_NODATA); + if (!obj_request) + return ERR_PTR(-ENOMEM); + + obj_request->osd_req = rbd_osd_req_create(rbd_dev, true, 1, + obj_request); + if (!obj_request->osd_req) { + ret = -ENOMEM; + goto out; + } + + osd_req_op_watch_init(obj_request->osd_req, 0, CEPH_OSD_OP_WATCH, + rbd_dev->watch_event->cookie, 0, watch); + rbd_osd_req_format_write(obj_request); + + if (watch) + ceph_osdc_set_request_linger(osdc, obj_request->osd_req); + + ret = rbd_obj_request_submit(osdc, obj_request); + if (ret) + goto out; + + ret = rbd_obj_request_wait(obj_request); + if (ret) + goto out; + + ret = obj_request->result; + if (ret) { + if (watch) + rbd_obj_request_end(obj_request); + goto out; + } + + return obj_request; + +out: + rbd_obj_request_put(obj_request); + return ERR_PTR(ret); +} + +/* * Initiate a watch request, synchronously. */ static int rbd_dev_header_watch_sync(struct rbd_device *rbd_dev)