* [PATCH 1/3] sunrpc: Fix potential race conditions in rpc_sysfs_xprt_state_change()
@ 2021-11-15 16:58 schumaker.anna
2021-11-15 16:58 ` [PATCH 2/3] sunrpc: Provide a helper function for accessing the number of xprts schumaker.anna
2021-11-15 16:58 ` [PATCH 3/3] nfs: show dynamic nconnect schumaker.anna
0 siblings, 2 replies; 3+ messages in thread
From: schumaker.anna @ 2021-11-15 16:58 UTC (permalink / raw)
To: Trond.Myklebust, linux-nfs; +Cc: Anna.Schumaker
From: Anna Schumaker <Anna.Schumaker@Netapp.com>
We need to use test_and_set_bit() when changing xprt state flags to
avoid potentially getting xps->xps_nactive out of sync.
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
net/sunrpc/sysfs.c | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index 77e7d011c1ab..8f309bcdf84f 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -309,25 +309,28 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
goto release_tasks;
}
if (offline) {
- set_bit(XPRT_OFFLINE, &xprt->state);
- spin_lock(&xps->xps_lock);
- xps->xps_nactive--;
- spin_unlock(&xps->xps_lock);
+ if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
+ spin_lock(&xps->xps_lock);
+ xps->xps_nactive--;
+ spin_unlock(&xps->xps_lock);
+ }
} else if (online) {
- clear_bit(XPRT_OFFLINE, &xprt->state);
- spin_lock(&xps->xps_lock);
- xps->xps_nactive++;
- spin_unlock(&xps->xps_lock);
+ if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
+ spin_lock(&xps->xps_lock);
+ xps->xps_nactive++;
+ spin_unlock(&xps->xps_lock);
+ }
} else if (remove) {
if (test_bit(XPRT_OFFLINE, &xprt->state)) {
- set_bit(XPRT_REMOVE, &xprt->state);
- xprt_force_disconnect(xprt);
- if (test_bit(XPRT_CONNECTED, &xprt->state)) {
- if (!xprt->sending.qlen &&
- !xprt->pending.qlen &&
- !xprt->backlog.qlen &&
- !atomic_long_read(&xprt->queuelen))
- rpc_xprt_switch_remove_xprt(xps, xprt);
+ if (!test_and_set_bit(XPRT_REMOVE, &xprt->state)) {
+ xprt_force_disconnect(xprt);
+ if (test_bit(XPRT_CONNECTED, &xprt->state)) {
+ if (!xprt->sending.qlen &&
+ !xprt->pending.qlen &&
+ !xprt->backlog.qlen &&
+ !atomic_long_read(&xprt->queuelen))
+ rpc_xprt_switch_remove_xprt(xps, xprt);
+ }
}
} else {
count = -EINVAL;
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/3] sunrpc: Provide a helper function for accessing the number of xprts
2021-11-15 16:58 [PATCH 1/3] sunrpc: Fix potential race conditions in rpc_sysfs_xprt_state_change() schumaker.anna
@ 2021-11-15 16:58 ` schumaker.anna
2021-11-15 16:58 ` [PATCH 3/3] nfs: show dynamic nconnect schumaker.anna
1 sibling, 0 replies; 3+ messages in thread
From: schumaker.anna @ 2021-11-15 16:58 UTC (permalink / raw)
To: Trond.Myklebust, linux-nfs; +Cc: Anna.Schumaker
From: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
include/linux/sunrpc/clnt.h | 1 +
net/sunrpc/clnt.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index 267b7aeaf1a6..0a94fe1036a8 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -238,6 +238,7 @@ const char *rpc_proc_name(const struct rpc_task *task);
void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
+unsigned int rpc_clnt_xprt_switch_num_xprts(struct rpc_clnt *);
bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
const struct sockaddr *sap);
void rpc_cleanup_clids(void);
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index a312ea2bc440..399768a443ea 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -2994,6 +2994,16 @@ void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
}
EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt);
+unsigned int rpc_clnt_xprt_switch_num_xprts(struct rpc_clnt *clnt)
+{
+ unsigned int num;
+ rcu_read_lock();
+ num = rcu_dereference(clnt->cl_xpi.xpi_xpswitch)->xps_nxprts;
+ rcu_read_unlock();
+ return num;
+}
+EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_num_xprts);
+
bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
const struct sockaddr *sap)
{
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 3/3] nfs: show dynamic nconnect
2021-11-15 16:58 [PATCH 1/3] sunrpc: Fix potential race conditions in rpc_sysfs_xprt_state_change() schumaker.anna
2021-11-15 16:58 ` [PATCH 2/3] sunrpc: Provide a helper function for accessing the number of xprts schumaker.anna
@ 2021-11-15 16:58 ` schumaker.anna
1 sibling, 0 replies; 3+ messages in thread
From: schumaker.anna @ 2021-11-15 16:58 UTC (permalink / raw)
To: Trond.Myklebust, linux-nfs; +Cc: Anna.Schumaker
From: Anna Schumaker <Anna.Schumaker@Netapp.com>
Through sysfs we can change the number of xprts attached to an
rpc_client. This lets us change the displayed nconnect= value to reflect
the actual number of connected xprts for the given mount.
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
fs/nfs/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 3aced401735c..f6ede7bf18f9 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -478,7 +478,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
rcu_read_unlock();
if (clp->cl_nconnect > 0)
- seq_printf(m, ",nconnect=%u", clp->cl_nconnect);
+ seq_printf(m, ",nconnect=%u", rpc_clnt_xprt_switch_num_xprts(clp->cl_rpcclient));
if (version == 4) {
if (clp->cl_max_connect > 1)
seq_printf(m, ",max_connect=%u", clp->cl_max_connect);
--
2.33.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-15 16:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-15 16:58 [PATCH 1/3] sunrpc: Fix potential race conditions in rpc_sysfs_xprt_state_change() schumaker.anna
2021-11-15 16:58 ` [PATCH 2/3] sunrpc: Provide a helper function for accessing the number of xprts schumaker.anna
2021-11-15 16:58 ` [PATCH 3/3] nfs: show dynamic nconnect schumaker.anna
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox