Skip to content

Commit 66697bf

Browse files
Stanislav KinsburskyTrond Myklebust
authored andcommitted
LockD: make nlm hosts network namespace aware
This object depends on RPC client, and thus on network namespace. So let's make it's allocation and lookup in network namespace context. Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent bb2224d commit 66697bf

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
6262

6363
host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen,
6464
nlm_init->protocol, nlm_version,
65-
nlm_init->hostname, nlm_init->noresvport);
65+
nlm_init->hostname, nlm_init->noresvport,
66+
nlm_init->net);
6667
if (host == NULL) {
6768
lockd_down();
6869
return ERR_PTR(-ENOLCK);

‎fs/lockd/host.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/lockd/lockd.h>
1818
#include <linux/mutex.h>
1919

20+
#include <linux/sunrpc/svc_xprt.h>
21+
2022
#include <net/ipv6.h>
2123

2224
#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
@@ -54,6 +56,7 @@ struct nlm_lookup_host_info {
5456
const char *hostname; /* remote's hostname */
5557
const size_t hostname_len; /* it's length */
5658
const int noresvport; /* use non-priv port */
59+
struct net *net; /* network namespace to bind */
5760
};
5861

5962
/*
@@ -155,6 +158,7 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
155158
INIT_LIST_HEAD(&host->h_reclaim);
156159
host->h_nsmhandle = nsm;
157160
host->h_addrbuf = nsm->sm_addrbuf;
161+
host->net = ni->net;
158162

159163
out:
160164
return host;
@@ -206,7 +210,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
206210
const unsigned short protocol,
207211
const u32 version,
208212
const char *hostname,
209-
int noresvport)
213+
int noresvport,
214+
struct net *net)
210215
{
211216
struct nlm_lookup_host_info ni = {
212217
.server = 0,
@@ -217,6 +222,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
217222
.hostname = hostname,
218223
.hostname_len = strlen(hostname),
219224
.noresvport = noresvport,
225+
.net = net,
220226
};
221227
struct hlist_head *chain;
222228
struct hlist_node *pos;
@@ -231,6 +237,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
231237

232238
chain = &nlm_client_hosts[nlm_hash_address(sap)];
233239
hlist_for_each_entry(host, pos, chain, h_hash) {
240+
if (host->net != net)
241+
continue;
234242
if (!rpc_cmp_addr(nlm_addr(host), sap))
235243
continue;
236244

@@ -318,6 +326,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
318326
struct nsm_handle *nsm = NULL;
319327
struct sockaddr *src_sap = svc_daddr(rqstp);
320328
size_t src_len = rqstp->rq_daddrlen;
329+
struct net *net = rqstp->rq_xprt->xpt_net;
321330
struct nlm_lookup_host_info ni = {
322331
.server = 1,
323332
.sap = svc_addr(rqstp),
@@ -326,6 +335,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
326335
.version = rqstp->rq_vers,
327336
.hostname = hostname,
328337
.hostname_len = hostname_len,
338+
.net = net,
329339
};
330340

331341
dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
@@ -339,6 +349,8 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
339349

340350
chain = &nlm_server_hosts[nlm_hash_address(ni.sap)];
341351
hlist_for_each_entry(host, pos, chain, h_hash) {
352+
if (host->net != net)
353+
continue;
342354
if (!rpc_cmp_addr(nlm_addr(host), ni.sap))
343355
continue;
344356

@@ -431,7 +443,7 @@ nlm_bind_host(struct nlm_host *host)
431443
.to_retries = 5U,
432444
};
433445
struct rpc_create_args args = {
434-
.net = &init_net,
446+
.net = host->net,
435447
.protocol = host->h_proto,
436448
.address = nlm_addr(host),
437449
.addrsize = host->h_addrlen,

‎fs/nfs/client.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ static int nfs_start_lockd(struct nfs_server *server)
707707
.nfs_version = clp->rpc_ops->version,
708708
.noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
709709
1 : 0,
710+
.net = clp->net,
710711
};
711712

712713
if (nlm_init.nfs_version > 3)

‎include/linux/lockd/bind.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct nlmclnt_initdata {
4242
unsigned short protocol;
4343
u32 nfs_version;
4444
int noresvport;
45+
struct net *net;
4546
};
4647

4748
/*

‎include/linux/lockd/lockd.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct nlm_host {
6767
struct list_head h_reclaim; /* Locks in RECLAIM state */
6868
struct nsm_handle *h_nsmhandle; /* NSM status handle */
6969
char *h_addrbuf; /* address eyecatcher */
70+
struct net *net; /* host net */
7071
};
7172

7273
/*
@@ -222,7 +223,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
222223
const unsigned short protocol,
223224
const u32 version,
224225
const char *hostname,
225-
int noresvport);
226+
int noresvport,
227+
struct net *net);
226228
void nlmclnt_release_host(struct nlm_host *);
227229
struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
228230
const char *hostname,

0 commit comments

Comments
 (0)