public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: nfs@lists.sourceforge.net, linux-kernel@vger.kernel.org
Cc: Olaf Kirch <okir@suse.de>
Subject: [PATCH 003 of 19] knfsd: When looking up a lockd host, pass hostname & length
Date: Fri, 1 Sep 2006 14:38:20 +1000	[thread overview]
Message-ID: <1060901043820.27452@suse.de> (raw)
In-Reply-To: 20060901141639.27206.patches@notabene


From: Olaf Kirch <okir@suse.de>

  This patch adds the peer's hostname (and name length) to
  all calls to nlm*_lookup_host functions. A subsequent patch
  will make use of these (is requested by a sysctl).

Signed-off-by: okir@suse.de
Signed-off-by: Neil Brown <neilb@suse.de>

### Diffstat output
 ./fs/lockd/clntproc.c         |    5 ++++-
 ./fs/lockd/host.c             |   37 +++++++++++++++++++++++++------------
 ./fs/lockd/svc4proc.c         |    6 ++++--
 ./fs/lockd/svclock.c          |    3 ++-
 ./fs/lockd/svcproc.c          |    6 ++++--
 ./include/linux/lockd/lockd.h |    6 +++---
 6 files changed, 42 insertions(+), 21 deletions(-)

diff .prev/fs/lockd/clntproc.c ./fs/lockd/clntproc.c
--- .prev/fs/lockd/clntproc.c	2006-08-31 16:59:10.000000000 +1000
+++ ./fs/lockd/clntproc.c	2006-08-31 16:32:15.000000000 +1000
@@ -153,6 +153,7 @@ nlmclnt_proc(struct inode *inode, int cm
 {
 	struct rpc_clnt		*client = NFS_CLIENT(inode);
 	struct sockaddr_in	addr;
+	struct nfs_server	*nfssrv = NFS_SERVER(inode);
 	struct nlm_host		*host;
 	struct nlm_rqst		*call;
 	sigset_t		oldset;
@@ -166,7 +167,9 @@ nlmclnt_proc(struct inode *inode, int cm
 	}
 
 	rpc_peeraddr(client, (struct sockaddr *) &addr, sizeof(addr));
-	host = nlmclnt_lookup_host(&addr, client->cl_xprt->prot, vers);
+	host = nlmclnt_lookup_host(&addr, client->cl_xprt->prot, vers,
+				   nfssrv->nfs_client->cl_hostname,
+				   strlen(nfssrv->nfs_client->cl_hostname));
 	if (host == NULL)
 		return -ENOLCK;
 

diff .prev/fs/lockd/host.c ./fs/lockd/host.c
--- .prev/fs/lockd/host.c	2006-08-31 16:59:10.000000000 +1000
+++ ./fs/lockd/host.c	2006-08-31 16:23:12.000000000 +1000
@@ -39,19 +39,23 @@ static void			nlm_gc_hosts(void);
  * Find an NLM server handle in the cache. If there is none, create it.
  */
 struct nlm_host *
-nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version)
+nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version,
+			const char *hostname, int hostname_len)
 {
-	return nlm_lookup_host(0, sin, proto, version);
+	return nlm_lookup_host(0, sin, proto, version,
+			       hostname, hostname_len);
 }
 
 /*
  * Find an NLM client handle in the cache. If there is none, create it.
  */
 struct nlm_host *
-nlmsvc_lookup_host(struct svc_rqst *rqstp)
+nlmsvc_lookup_host(struct svc_rqst *rqstp,
+			const char *hostname, int hostname_len)
 {
 	return nlm_lookup_host(1, &rqstp->rq_addr,
-			       rqstp->rq_prot, rqstp->rq_vers);
+			       rqstp->rq_prot, rqstp->rq_vers,
+			       hostname, hostname_len);
 }
 
 /*
@@ -59,14 +63,20 @@ nlmsvc_lookup_host(struct svc_rqst *rqst
  */
 struct nlm_host *
 nlm_lookup_host(int server, const struct sockaddr_in *sin,
-					int proto, int version)
+					int proto, int version,
+					const char *hostname,
+					int hostname_len)
 {
 	struct nlm_host	*host, **hp;
 	u32		addr;
 	int		hash;
 
-	dprintk("lockd: nlm_lookup_host(%08x, p=%d, v=%d)\n",
-			(unsigned)(sin? ntohl(sin->sin_addr.s_addr) : 0), proto, version);
+	dprintk("lockd: nlm_lookup_host(%u.%u.%u.%u, p=%d, v=%d, my role=%s, name=%.*s)\n",
+			NIPQUAD(sin->sin_addr.s_addr), proto, version,
+			server? "server" : "client",
+			hostname_len,
+			hostname? hostname : "<none>");
+
 
 	hash = NLM_ADDRHASH(sin->sin_addr.s_addr);
 
@@ -267,19 +277,22 @@ void nlm_release_host(struct nlm_host *h
 void nlm_host_rebooted(const struct sockaddr_in *sin, const struct nlm_reboot *argp)
 {
 	struct nlm_host *host;
+	int server;
 
 	/* Obtain the host pointer for this NFS server and try to
 	 * reclaim all locks we hold on this server.
 	 */
-	if ((argp->proto & 1)==0) {
+	server = (argp->proto & 1)? 1 : 0;
+	host = nlm_lookup_host(server, sin, argp->proto >> 1, argp->vers,
+			argp->mon, argp->len);
+	if (host == NULL)
+		return;
+
+	if (server == 0) {
 		/* We are client, he's the server: try to reclaim all locks. */
-		if ((host = nlmclnt_lookup_host(sin, argp->proto >> 1, argp->vers)) == NULL)
-			return;
 		nlmclnt_recovery(host, argp->state);
 	} else {
 		/* He's the client, we're the server: delete all locks held by the client */
-		if ((host = nlm_lookup_host(1, sin, argp->proto >> 1, argp->vers)) == NULL)
-			return;
 		nlmsvc_free_host_resources(host);
 	}
 	nlm_release_host(host);

diff .prev/fs/lockd/svc4proc.c ./fs/lockd/svc4proc.c
--- .prev/fs/lockd/svc4proc.c	2006-08-31 16:59:10.000000000 +1000
+++ ./fs/lockd/svc4proc.c	2006-08-31 16:59:53.000000000 +1000
@@ -38,7 +38,7 @@ nlm4svc_retrieve_args(struct svc_rqst *r
 		return nlm_lck_denied_nolocks;
 
 	/* Obtain host handle */
-	if (!(host = nlmsvc_lookup_host(rqstp))
+	if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len))
 	 || (argp->monitor && nsm_monitor(host) < 0))
 		goto no_locks;
 	*hostp = host;
@@ -260,7 +260,9 @@ static int nlm4svc_callback(struct svc_r
 	struct nlm_rqst	*call;
 	int stat;
 
-	host = nlmsvc_lookup_host(rqstp);
+	host = nlmsvc_lookup_host(rqstp,
+				  argp->lock.caller,
+				  argp->lock.len);
 	if (host == NULL)
 		return rpc_system_err;
 

diff .prev/fs/lockd/svclock.c ./fs/lockd/svclock.c
--- .prev/fs/lockd/svclock.c	2006-08-31 16:59:10.000000000 +1000
+++ ./fs/lockd/svclock.c	2006-08-31 16:23:12.000000000 +1000
@@ -179,7 +179,7 @@ nlmsvc_create_block(struct svc_rqst *rqs
 	struct nlm_rqst		*call = NULL;
 
 	/* Create host handle for callback */
-	host = nlmsvc_lookup_host(rqstp);
+	host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len);
 	if (host == NULL)
 		return NULL;
 
@@ -451,6 +451,7 @@ nlmsvc_testlock(struct nlm_file *file, s
 				(long long)conflock->fl.fl_start,
 				(long long)conflock->fl.fl_end);
 		conflock->caller = "somehost";	/* FIXME */
+		conflock->len = strlen(conflock->caller);
 		conflock->oh.len = 0;		/* don't return OH info */
 		conflock->svid = conflock->fl.fl_pid;
 		return nlm_lck_denied;

diff .prev/fs/lockd/svcproc.c ./fs/lockd/svcproc.c
--- .prev/fs/lockd/svcproc.c	2006-08-31 16:59:10.000000000 +1000
+++ ./fs/lockd/svcproc.c	2006-08-31 16:59:39.000000000 +1000
@@ -66,7 +66,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rq
 		return nlm_lck_denied_nolocks;
 
 	/* Obtain host handle */
-	if (!(host = nlmsvc_lookup_host(rqstp))
+	if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len))
 	 || (argp->monitor && nsm_monitor(host) < 0))
 		goto no_locks;
 	*hostp = host;
@@ -287,7 +287,9 @@ static int nlmsvc_callback(struct svc_rq
 	struct nlm_rqst	*call;
 	int stat;
 
-	host = nlmsvc_lookup_host(rqstp);
+	host = nlmsvc_lookup_host(rqstp,
+				  argp->lock.caller,
+				  argp->lock.len);
 	if (host == NULL)
 		return rpc_system_err;
 

diff .prev/include/linux/lockd/lockd.h ./include/linux/lockd/lockd.h
--- .prev/include/linux/lockd/lockd.h	2006-08-31 16:59:10.000000000 +1000
+++ ./include/linux/lockd/lockd.h	2006-08-31 16:23:12.000000000 +1000
@@ -161,9 +161,9 @@ int		  nlmclnt_reclaim(struct nlm_host *
 /*
  * Host cache
  */
-struct nlm_host * nlmclnt_lookup_host(const struct sockaddr_in *, int, int);
-struct nlm_host * nlmsvc_lookup_host(struct svc_rqst *);
-struct nlm_host * nlm_lookup_host(int server, const struct sockaddr_in *, int, int);
+struct nlm_host * nlmclnt_lookup_host(const struct sockaddr_in *, int, int, const char *, int);
+struct nlm_host * nlmsvc_lookup_host(struct svc_rqst *, const char *, int);
+struct nlm_host * nlm_lookup_host(int server, const struct sockaddr_in *, int, int, const char *, int);
 struct rpc_clnt * nlm_bind_host(struct nlm_host *);
 void		  nlm_rebind_host(struct nlm_host *);
 struct nlm_host * nlm_get_host(struct nlm_host *);

  parent reply	other threads:[~2006-09-01  4:38 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-01  4:38 [PATCH 000 of 19] knfsd: lockd improvements NeilBrown
2006-09-01  4:38 ` [PATCH 001 of 19] knfsd: Hide use of lockd's h_monitored flag NeilBrown
2006-09-01  4:38 ` [PATCH 002 of 19] knfsd: Consolidate common code for statd->lockd notification NeilBrown
2006-09-01  4:38 ` NeilBrown [this message]
2006-09-01  4:38 ` [PATCH 004 of 19] knfsd: lockd: introduce nsm_handle NeilBrown
2006-09-01  6:17   ` Andrew Morton
2006-09-01 23:48     ` Neil Brown
2006-09-01  6:20   ` Andrew Morton
2006-09-01 23:50     ` Neil Brown
2006-09-01 15:50   ` [NFS] " Trond Myklebust
2006-09-01 16:11     ` Olaf Kirch
2006-09-01 16:41       ` Trond Myklebust
2006-09-04  8:48         ` Olaf Kirch
2006-09-01  4:38 ` [PATCH 005 of 19] knfsd: Misc minor fixes, indentation changes NeilBrown
2006-09-01  4:38 ` [PATCH 006 of 19] knfsd: lockd: Make nlm_host_rebooted use the nsm_handle NeilBrown
2006-09-01  4:38 ` [PATCH 007 of 19] knfsd: lockd: make the nsm upcalls " NeilBrown
2006-09-01  4:38 ` [PATCH 008 of 19] knfsd: lockd: make the hash chains use a hlist_node NeilBrown
2006-09-01  4:38 ` [PATCH 009 of 19] knfsd: lockd: Change list of blocked list to list_node NeilBrown
2006-09-01  4:39 ` [PATCH 010 of 19] knfsd: Change nlm_file to use a hlist NeilBrown
2006-09-01  4:39 ` [PATCH 011 of 19] knfsd: lockd: make nlm_traverse_* more flexible NeilBrown
2006-09-01  4:39 ` [PATCH 012 of 19] knfsd: lockd: Add nlm_destroy_host NeilBrown
2006-09-01  4:39 ` [PATCH 013 of 19] knfsd: Simplify nlmsvc_invalidate_all NeilBrown
2006-09-01  4:39 ` [PATCH 014 of 19] knfsd: lockd: optionally use hostnames for identifying peers NeilBrown
2006-09-01  4:39 ` [PATCH 015 of 19] knfsd: make nlmclnt_next_cookie SMP safe NeilBrown
2006-09-01  4:39 ` [PATCH 016 of 19] knfsd: match GRANTED_RES replies using cookies NeilBrown
2006-09-01 16:03   ` [NFS] " Trond Myklebust
2006-09-04  9:09     ` Olaf Kirch
2006-09-05 16:12       ` Trond Myklebust
2006-09-05 17:39         ` Olaf Kirch
2006-09-01  4:39 ` [PATCH 017 of 19] knfsd: Export nsm_local_state to user space via sysctl NeilBrown
2006-09-01  4:39 ` [PATCH 018 of 19] knfsd: lockd: fix use of h_nextrebind NeilBrown
2006-09-01 16:05   ` [NFS] " Trond Myklebust
2006-09-01  4:39 ` [PATCH 019 of 19] knfsd: Register all RPC programs with portmapper by default NeilBrown
2006-09-01 13:25   ` [NFS] " Peter Staubach
2006-09-01 13:29   ` Peter Staubach
2006-09-01 13:47     ` Olaf Kirch
2006-09-01 15:31   ` Chuck Lever
2006-09-01 15:54     ` Olaf Kirch
2006-09-01 16:08       ` Chuck Lever
2006-09-01 16:34         ` Peter Staubach
2006-09-01 16:13     ` 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=1060901043820.27452@suse.de \
    --to=neilb@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nfs@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox