From patchwork Tue Apr 25 09:33:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9697777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 74F85601D3 for ; Tue, 25 Apr 2017 09:34:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71F5A2843B for ; Tue, 25 Apr 2017 09:34:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66DD5284E5; Tue, 25 Apr 2017 09:34:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18A3B2843B for ; Tue, 25 Apr 2017 09:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1428725AbdDYJeo (ORCPT ); Tue, 25 Apr 2017 05:34:44 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35668 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1428700AbdDYJeR (ORCPT ); Tue, 25 Apr 2017 05:34:17 -0400 Received: by mail-qt0-f196.google.com with SMTP id o36so24161571qtb.2 for ; Tue, 25 Apr 2017 02:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=tJloJjWCgqViNQYX24dnzv8dX5sYsBz16rloOKrDz80=; b=meobkhOQ83BKgVM5KYptOGAlvMaH5UFfigeEeNOsqJzfDlHH/jMp6CWAhK3GPKNq4v wA7jgYEi8HxE35z3dLHoj08d9jFpOxrgzygdNDMcBq7YvhZZ/lox9Nm+Zcibpd3T5zbO Rx20lgtUDCBSFbyk4swSj13z2ld46ZVGv6DDEdE2fNbJYW/SQTdd/R5LrgmxMFc9gIBe 6mnMRIH7pxuLWMnfhvfUgne+rVDwj8QP0F9iHfbEWINsdKMIPwUiME8nDtYezzEjm/N+ ZJWkGWMi64IuJA0hEkwMq3OVPOACvUuLZR2L6TrAUnrBzjksD9JLqqM4+LDecBdTJOj/ DF1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=tJloJjWCgqViNQYX24dnzv8dX5sYsBz16rloOKrDz80=; b=IH1PoIA+6ic+9ecRMVRF0svK4hj5S4JWaQW63qIRwbdAi7jukZvtD6FSqGcBioehe+ OGAUruFqC7AAhZA7uE19Nb4U7V2qtlAKCq5BxfVRdb4Z1IZGVN4nz0HDYV8zAnZ64YSW bD3lFOjxRnKX6xdgSjWdeANybM9PlhFQwaXy4OltKcw6sqXuO4JcQwiuQEIgINE7wvz+ hKFzRDJeLk0ql0pffTpGr8YLQrjM1iT3gvdbtHnphg5mBdFeK3c6saKj15vqWmmt6eo1 YYLdDeUDmubWIC4lKELJTaidYKCheDmeiKZhuIoNTNshJrqpyQxuQm4zpw5vL4cbmQpT WNtw== X-Gm-Message-State: AN3rC/7gVE/0UJC/fXlZBww6gW7ZaafknudecJM7MFwrxjSJROFhCp0H hQqQHGmFTh6K5UGWzXM= X-Received: by 10.237.63.69 with SMTP id q5mr29008420qtf.236.1493112856213; Tue, 25 Apr 2017 02:34:16 -0700 (PDT) Received: from orange.brq.redhat.com. (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id w6sm7461396qta.50.2017.04.25.02.34.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 02:34:15 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 5/9] rbd: store lock cookie Date: Tue, 25 Apr 2017 11:33:41 +0200 Message-Id: <1493112825-16403-6-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1493112825-16403-1-git-send-email-idryomov@gmail.com> References: <1493112825-16403-1-git-send-email-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for supporting set_cookie method (or rather set_cookie fallback for older OSDs), store the lock cookie on lock and use it on unlock instead of recalculating from rbd_dev->watch_cookie. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 4b72286c4be6..ed8a3d0eee3b 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -387,6 +387,7 @@ struct rbd_device { struct rw_semaphore lock_rwsem; enum rbd_lock_state lock_state; + char lock_cookie[32]; struct rbd_client_id owner_cid; struct work_struct acquired_lock_work; struct work_struct released_lock_work; @@ -3079,7 +3080,8 @@ static int rbd_lock(struct rbd_device *rbd_dev) char cookie[32]; int ret; - WARN_ON(__rbd_is_lock_owner(rbd_dev)); + WARN_ON(__rbd_is_lock_owner(rbd_dev) || + rbd_dev->lock_cookie[0] != '\0'); format_lock_cookie(rbd_dev, cookie); ret = ceph_cls_lock(osdc, &rbd_dev->header_oid, &rbd_dev->header_oloc, @@ -3089,6 +3091,7 @@ static int rbd_lock(struct rbd_device *rbd_dev) return ret; rbd_dev->lock_state = RBD_LOCK_STATE_LOCKED; + strcpy(rbd_dev->lock_cookie, cookie); rbd_set_owner_cid(rbd_dev, &cid); queue_work(rbd_dev->task_wq, &rbd_dev->acquired_lock_work); return 0; @@ -3100,19 +3103,19 @@ static int rbd_lock(struct rbd_device *rbd_dev) static void rbd_unlock(struct rbd_device *rbd_dev) { struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; - char cookie[32]; int ret; - WARN_ON(!__rbd_is_lock_owner(rbd_dev)); + WARN_ON(!__rbd_is_lock_owner(rbd_dev) || + rbd_dev->lock_cookie[0] == '\0'); - format_lock_cookie(rbd_dev, cookie); ret = ceph_cls_unlock(osdc, &rbd_dev->header_oid, &rbd_dev->header_oloc, - RBD_LOCK_NAME, cookie); + RBD_LOCK_NAME, rbd_dev->lock_cookie); if (ret && ret != -ENOENT) rbd_warn(rbd_dev, "failed to unlock: %d", ret); /* treat errors as the image is unlocked */ rbd_dev->lock_state = RBD_LOCK_STATE_UNLOCKED; + rbd_dev->lock_cookie[0] = '\0'; rbd_set_owner_cid(rbd_dev, &rbd_empty_cid); queue_work(rbd_dev->task_wq, &rbd_dev->released_lock_work); }