Skip to content

Commit e9406db

Browse files
Stanislav KinsburskyTrond Myklebust
authored andcommitted
lockd: per-net NSM client creation and destruction helpers introduced
NSM RPC client can be required on NFSv3 umount, when child reaper is dying (and destroying it's mount namespace). It means, that current nsproxy is set to NULL already, but creation of RPC client requires UTS namespace for gaining hostname string. This patch introduces reference counted NFS RPC clients creation and destruction helpers (similar to RPCBIND RPC clients). Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Cc: <stable@vger.kernel.org> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 1dc42e0 commit e9406db

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎fs/lockd/mon.c‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <asm/unaligned.h>
2121

22+
#include "netns.h"
23+
2224
#define NLMDBG_FACILITY NLMDBG_MONITOR
2325
#define NSM_PROGRAM 100024
2426
#define NSM_VERSION 1
@@ -70,7 +72,7 @@ static struct rpc_clnt *nsm_create(struct net *net)
7072
};
7173
struct rpc_create_args args = {
7274
.net = net,
73-
.protocol = XPRT_TRANSPORT_UDP,
75+
.protocol = XPRT_TRANSPORT_TCP,
7476
.address = (struct sockaddr *)&sin,
7577
.addrsize = sizeof(sin),
7678
.servername = "rpc.statd",
@@ -83,6 +85,51 @@ static struct rpc_clnt *nsm_create(struct net *net)
8385
return rpc_create(&args);
8486
}
8587

88+
__maybe_unused static struct rpc_clnt *nsm_client_get(struct net *net)
89+
{
90+
static DEFINE_MUTEX(nsm_create_mutex);
91+
struct rpc_clnt *clnt;
92+
struct lockd_net *ln = net_generic(net, lockd_net_id);
93+
94+
spin_lock(&ln->nsm_clnt_lock);
95+
if (ln->nsm_users) {
96+
ln->nsm_users++;
97+
clnt = ln->nsm_clnt;
98+
spin_unlock(&ln->nsm_clnt_lock);
99+
goto out;
100+
}
101+
spin_unlock(&ln->nsm_clnt_lock);
102+
103+
mutex_lock(&nsm_create_mutex);
104+
clnt = nsm_create(net);
105+
if (!IS_ERR(clnt)) {
106+
ln->nsm_clnt = clnt;
107+
smp_wmb();
108+
ln->nsm_users = 1;
109+
}
110+
mutex_unlock(&nsm_create_mutex);
111+
out:
112+
return clnt;
113+
}
114+
115+
__maybe_unused static void nsm_client_put(struct net *net)
116+
{
117+
struct lockd_net *ln = net_generic(net, lockd_net_id);
118+
struct rpc_clnt *clnt = ln->nsm_clnt;
119+
int shutdown = 0;
120+
121+
spin_lock(&ln->nsm_clnt_lock);
122+
if (ln->nsm_users) {
123+
if (--ln->nsm_users)
124+
ln->nsm_clnt = NULL;
125+
shutdown = !ln->nsm_users;
126+
}
127+
spin_unlock(&ln->nsm_clnt_lock);
128+
129+
if (shutdown)
130+
rpc_shutdown_client(clnt);
131+
}
132+
86133
static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res,
87134
struct net *net)
88135
{
@@ -111,7 +158,7 @@ static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res,
111158
memset(res, 0, sizeof(*res));
112159

113160
msg.rpc_proc = &clnt->cl_procinfo[proc];
114-
status = rpc_call_sync(clnt, &msg, 0);
161+
status = rpc_call_sync(clnt, &msg, RPC_TASK_SOFTCONN);
115162
if (status < 0)
116163
dprintk("lockd: NSM upcall RPC failed, status=%d\n",
117164
status);

‎fs/lockd/netns.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ struct lockd_net {
1212
struct delayed_work grace_period_end;
1313
struct lock_manager lockd_manager;
1414
struct list_head grace_list;
15+
16+
spinlock_t nsm_clnt_lock;
17+
unsigned int nsm_users;
18+
struct rpc_clnt *nsm_clnt;
1519
};
1620

1721
extern int lockd_net_id;

‎fs/lockd/svc.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ static int lockd_init_net(struct net *net)
596596

597597
INIT_DELAYED_WORK(&ln->grace_period_end, grace_ender);
598598
INIT_LIST_HEAD(&ln->grace_list);
599+
spin_lock_init(&ln->nsm_clnt_lock);
599600
return 0;
600601
}
601602

0 commit comments

Comments
 (0)