From patchwork Mon Dec 3 12:50:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10709501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C70D16B1 for ; Mon, 3 Dec 2018 12:56:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E1ED2B54C for ; Mon, 3 Dec 2018 12:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 019D02B569; Mon, 3 Dec 2018 12:56:18 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 9CE9B2B415 for ; Mon, 3 Dec 2018 12:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbeLCM5M (ORCPT ); Mon, 3 Dec 2018 07:57:12 -0500 Received: from m50211.mail.qiye.163.com ([123.125.50.211]:22061 "EHLO m50211.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbeLCM5L (ORCPT ); Mon, 3 Dec 2018 07:57:11 -0500 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp3 (Coremail) with SMTP id PdOowEDpa0CfJgVcOwAAAA--.14S12; Mon, 03 Dec 2018 20:50:43 +0800 (CST) From: Dongsheng Yang To: idryomov@gmail.com, sage@redhat.com, elder@kernel.org, jdillama@redhat.com Cc: dongsheng.yang@easystack.cn, ceph-devel@vger.kernel.org Subject: [PATCH 10/11] rbd: introduce a lock_flag in rbd_dev to make some process exclusive-lock protected Date: Mon, 3 Dec 2018 07:50:34 -0500 Message-Id: <1543841435-13652-11-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1543841435-13652-1-git-send-email-dongsheng.yang@easystack.cn> References: <1543841435-13652-1-git-send-email-dongsheng.yang@easystack.cn> X-CM-TRANSID: PdOowEDpa0CfJgVcOwAAAA--.14S12 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjfUl0eHDUUUU X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbiiAMSeltVe+V9mQAAsX 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 When we are going to open journal, we don't want to release exclusive-lock in the whole process. But we can release it after opening. So introduce a lock_flag in rbd_dev to say, wait, we don't want to release exclusive-lock currently, please wait for this flag cleared. Signed-off-by: Dongsheng Yang --- drivers/block/rbd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index cc9ee8d..8db4c36 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -316,6 +316,10 @@ enum rbd_lock_state { RBD_LOCK_STATE_RELEASING, }; +enum rbd_lock_flags { + RBD_LOCK_FLAG_RELEASE_WAIT, // wait until this flag cleared in lock releasing +}; + /* WatchNotify::ClientId */ struct rbd_client_id { u64 gid; @@ -363,6 +367,8 @@ struct rbd_device { struct rw_semaphore lock_rwsem; enum rbd_lock_state lock_state; + unsigned long lock_flags; + struct completion lock_wait; char lock_cookie[32]; struct rbd_client_id owner_cid; struct work_struct acquired_lock_work; @@ -3080,6 +3086,19 @@ static void rbd_acquire_lock(struct work_struct *work) } } +static int rbd_lock_wait(struct rbd_device *rbd_dev) +{ + int ret = 0; + + while (test_bit(RBD_LOCK_FLAG_RELEASE_WAIT, &rbd_dev->lock_flags)) { + ret = wait_for_completion_interruptible(&rbd_dev->lock_wait); + if (ret) + break; + } + + return ret; +} + static int rbd_inflight_wait(struct rbd_device *rbd_dev) { int ret = 0; @@ -3108,6 +3127,12 @@ static bool rbd_release_lock(struct rbd_device *rbd_dev) rbd_dev->lock_state = RBD_LOCK_STATE_RELEASING; up_write(&rbd_dev->lock_rwsem); + ret = rbd_lock_wait(rbd_dev); + if (ret) { + down_write(&rbd_dev->lock_rwsem); + return false; + } + ret = rbd_inflight_wait(rbd_dev); if (ret) { down_write(&rbd_dev->lock_rwsem); @@ -4428,6 +4453,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_client *rbdc, init_rwsem(&rbd_dev->lock_rwsem); rbd_dev->lock_state = RBD_LOCK_STATE_UNLOCKED; + init_completion(&rbd_dev->lock_wait); INIT_WORK(&rbd_dev->acquired_lock_work, rbd_notify_acquired_lock); INIT_WORK(&rbd_dev->released_lock_work, rbd_notify_released_lock); INIT_DELAYED_WORK(&rbd_dev->lock_dwork, rbd_acquire_lock);