From patchwork Thu Jan 17 06:15:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Xiaoxu X-Patchwork-Id: 10767539 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 C9A1514E5 for ; Thu, 17 Jan 2019 06:12:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B24572F6CA for ; Thu, 17 Jan 2019 06:12:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A35262F6C4; Thu, 17 Jan 2019 06:12:23 +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 2EF472F6C4 for ; Thu, 17 Jan 2019 06:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729564AbfAQGMW (ORCPT ); Thu, 17 Jan 2019 01:12:22 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:48536 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725320AbfAQGMW (ORCPT ); Thu, 17 Jan 2019 01:12:22 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 14F3EB15315E2FC27DBB; Thu, 17 Jan 2019 14:12:19 +0800 (CST) Received: from RH5885H-V3.huawei.com (10.90.53.225) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Thu, 17 Jan 2019 14:12:08 +0800 From: ZhangXiaoxu To: , , , , , Subject: [PATCH] lockd: NSMPROC_MON should be send only once even if in multithread Date: Thu, 17 Jan 2019 14:15:46 +0800 Message-ID: <1547705746-69554-1-git-send-email-zhangxiaoxu5@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If multiple processes are locking the same file, the NSMPROC_MON message would be send more than one times when the host is not monitored by the peer. Add a mutex to ensure that we just send once. If some one has send the msg, Just waiting for the result or try again if failed. Signed-off-by: ZhangXiaoxu --- fs/lockd/mon.c | 10 ++++++++++ include/linux/lockd/lockd.h | 1 + 2 files changed, 11 insertions(+) diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c index 654594e..4ba2658 100644 --- a/fs/lockd/mon.c +++ b/fs/lockd/mon.c @@ -155,6 +155,12 @@ int nsm_monitor(const struct nlm_host *host) if (nsm->sm_monitored) return 0; + mutex_lock(&nsm->mutex); + if (nsm->sm_monitored) { + mutex_unlock(&nsm->mutex); + return 0; + } + /* * Choose whether to record the caller_name or IP address of * this peer in the local rpc.statd's database. @@ -165,6 +171,7 @@ int nsm_monitor(const struct nlm_host *host) if (unlikely(res.status != 0)) status = -EIO; if (unlikely(status < 0)) { + mutex_unlock(&nsm->mutex); pr_notice_ratelimited("lockd: cannot monitor %s\n", nsm->sm_name); return status; } @@ -174,6 +181,8 @@ int nsm_monitor(const struct nlm_host *host) nsm_local_state = res.state; dprintk("lockd: NSM state changed to %d\n", nsm_local_state); } + + mutex_unlock(&nsm->mutex); return 0; } @@ -284,6 +293,7 @@ static struct nsm_handle *nsm_create_handle(const struct sockaddr *sap, memcpy(nsm_addr(new), sap, salen); new->sm_addrlen = salen; nsm_init_private(new); + mutex_init(&new->mutex); if (rpc_ntop(nsm_addr(new), new->sm_addrbuf, sizeof(new->sm_addrbuf)) == 0) diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h index b065ef4..c56069c 100644 --- a/include/linux/lockd/lockd.h +++ b/include/linux/lockd/lockd.h @@ -89,6 +89,7 @@ struct nsm_handle { char *sm_name; struct sockaddr_storage sm_addr; size_t sm_addrlen; + struct mutex mutex; /* should be send only once even more threads */ unsigned int sm_monitored : 1, sm_sticky : 1; /* don't unmonitor */ struct nsm_private sm_priv;