From: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
To: <zhangxiaoxu5@huawei.com>, <bfields@fieldses.org>,
<jlayton@kernel.org>, <trond.myklebust@hammerspace.com>,
<anna.schumaker@netapp.com>, <linux-nfs@vger.kernel.org>
Subject: [PATCH] lockd: NSMPROC_MON should be send only once even if in multithread
Date: Thu, 17 Jan 2019 14:15:46 +0800 [thread overview]
Message-ID: <1547705746-69554-1-git-send-email-zhangxiaoxu5@huawei.com> (raw)
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 <zhangxiaoxu5@huawei.com>
---
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;
--
2.7.4
next reply other threads:[~2019-01-17 6:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-17 6:15 ZhangXiaoxu [this message]
2019-01-17 14:33 ` [PATCH] lockd: NSMPROC_MON should be send only once even if in multithread Chuck Lever
2019-01-18 2:48 ` zhangxiaoxu (A)
2019-01-18 20:59 ` Chuck Lever
2019-01-24 12:29 ` zhangxiaoxu (A)
2019-01-24 19:17 ` Chuck Lever
2019-01-24 19:53 ` Trond Myklebust
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1547705746-69554-1-git-send-email-zhangxiaoxu5@huawei.com \
--to=zhangxiaoxu5@huawei.com \
--cc=anna.schumaker@netapp.com \
--cc=bfields@fieldses.org \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.