From patchwork Tue Apr 25 09:33:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9697781 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 61452601D3 for ; Tue, 25 Apr 2017 09:35:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C061283FB for ; Tue, 25 Apr 2017 09:35:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E5EF2843B; Tue, 25 Apr 2017 09:35:03 +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 DFF54283FB for ; Tue, 25 Apr 2017 09:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1428726AbdDYJfA (ORCPT ); Tue, 25 Apr 2017 05:35:00 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:35716 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1428703AbdDYJeT (ORCPT ); Tue, 25 Apr 2017 05:34:19 -0400 Received: by mail-qk0-f196.google.com with SMTP id a19so6834488qkg.2 for ; Tue, 25 Apr 2017 02:34:19 -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=Znm3hmqureHWyZbQggP+MZFe6tbONAuUaK2Obs8WejI=; b=JwYKWnqpmzN2RpuOmOsBr+16qcxBq/eHLW6h6PSmoLEQ7LriQrFugocbdP5becDRAx 0BKDd40Tu+n1nFh7BXzkfGHs/fX2jksG+kfJZLeQF7zSWTKrakY22cX211cTRRVc6PpP dyhQQGDRxaz/wudqbIcquO6ObNwKtmm1GirZ/MyekHNaScWXikqGvbmA3NDAzFaTQ5EB EdjEmw1p7VbZQhhGrmUeZc2J43O+yinzjJvvKWKVM8Gq/TJsIgYJH9vuCe9zd/CyewVQ WjcrpDECQu7kPGc6SR+8ffTe1OOnDOhP2J9f60ZHd91SwokgU1JDUnCmhWf0Aut4YsUD sPjA== 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=Znm3hmqureHWyZbQggP+MZFe6tbONAuUaK2Obs8WejI=; b=oPHy06jNIW1XIMqDtLsjaCs8YG82HcgPF1qIC8dxx4cgGGGKnFUylPrH8FTw6DKCtq qrLt17Z7eU4XmpZH39fTq6/FP/LwTwyXoARAQvLsLk75tHImIAwwSSG4ELgpbYiryycQ tD0+OZ8L7iMZCXsfNRyoECjo3VNv0NQtDghpYRNeiXuf9FSwAxN/jpnX3uxH+hDCaPfF 8mrbkR8Z4HIlmO3dl6jrpvjtyVLFFJ/0xfIpDdGFUZnaAJECk7Yh/eNk1+Y9Fih70pL4 +JLCUXfDOAgjr/E0BxY/0udqQGJL7kG1lEW9YcKAJaUah3YdHew53QdaDQInvugIEr1d OEWA== X-Gm-Message-State: AN3rC/7ww16mk4glZVfU/5MbVMcMCuUNn42hTnZCE1UXw/2jFw6mAxQi jOQqY/nDZmUQVznDWRc= X-Received: by 10.55.198.197 with SMTP id s66mr30982624qkl.179.1493112858859; Tue, 25 Apr 2017 02:34:18 -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.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 02:34:18 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 8/9] rbd: return ResponseMessage result from rbd_handle_request_lock() Date: Tue, 25 Apr 2017 11:33:44 +0200 Message-Id: <1493112825-16403-9-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 Right now it's just 0, but "no automatic exclusive lock transfers" mode code will need -EROFS. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index bcc43fb8a9b3..9bb4293e05e0 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -3572,12 +3572,16 @@ static void rbd_handle_released_lock(struct rbd_device *rbd_dev, u8 struct_v, up_read(&rbd_dev->lock_rwsem); } -static bool rbd_handle_request_lock(struct rbd_device *rbd_dev, u8 struct_v, - void **p) +/* + * Returns result for ResponseMessage to be encoded (<= 0), or 1 if no + * ResponseMessage is needed. + */ +static int rbd_handle_request_lock(struct rbd_device *rbd_dev, u8 struct_v, + void **p) { struct rbd_client_id my_cid = rbd_get_cid(rbd_dev); struct rbd_client_id cid = { 0 }; - bool need_to_send; + int result = 1; if (struct_v >= 2) { cid.gid = ceph_decode_64(p); @@ -3587,19 +3591,30 @@ static bool rbd_handle_request_lock(struct rbd_device *rbd_dev, u8 struct_v, dout("%s rbd_dev %p cid %llu-%llu\n", __func__, rbd_dev, cid.gid, cid.handle); if (rbd_cid_equal(&cid, &my_cid)) - return false; + return result; down_read(&rbd_dev->lock_rwsem); - need_to_send = __rbd_is_lock_owner(rbd_dev); - if (rbd_dev->lock_state == RBD_LOCK_STATE_LOCKED) { - if (!rbd_cid_equal(&rbd_dev->owner_cid, &rbd_empty_cid)) { + if (__rbd_is_lock_owner(rbd_dev)) { + if (rbd_dev->lock_state == RBD_LOCK_STATE_LOCKED && + rbd_cid_equal(&rbd_dev->owner_cid, &rbd_empty_cid)) + goto out_unlock; + + /* + * encode ResponseMessage(0) so the peer can detect + * a missing owner + */ + result = 0; + + if (rbd_dev->lock_state == RBD_LOCK_STATE_LOCKED) { dout("%s rbd_dev %p queueing unlock_work\n", __func__, rbd_dev); queue_work(rbd_dev->task_wq, &rbd_dev->unlock_work); } } + +out_unlock: up_read(&rbd_dev->lock_rwsem); - return need_to_send; + return result; } static void __rbd_acknowledge_notify(struct rbd_device *rbd_dev, @@ -3682,13 +3697,10 @@ static void rbd_watch_cb(void *arg, u64 notify_id, u64 cookie, rbd_acknowledge_notify(rbd_dev, notify_id, cookie); break; case RBD_NOTIFY_OP_REQUEST_LOCK: - if (rbd_handle_request_lock(rbd_dev, struct_v, &p)) - /* - * send ResponseMessage(0) back so the client - * can detect a missing owner - */ + ret = rbd_handle_request_lock(rbd_dev, struct_v, &p); + if (ret <= 0) rbd_acknowledge_notify_result(rbd_dev, notify_id, - cookie, 0); + cookie, ret); else rbd_acknowledge_notify(rbd_dev, notify_id, cookie); break;