Skip to contentSkip to conversation

NFS: Use cached nlm_host when calling nlmclnt_proc()

PATCH In review Chuck Lever 2 participants 4 messages Jan 8, 2008 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 NFS: Use cached nlm_host when calling nlmclnt_proc()

Now that each NFS mount point caches its own nlm_host structure, it can be passed to nlmclnt_proc() for each lock request. By pinning an nlm_host for each mount point, we trade the overhead of looking up or creating a fresh nlm_host struct during every NLM procedure call for a little extra memory.

We also restrict the nlmclnt_proc symbol to limit the use of this call to in-tree modules.

Note that nlm_lookup_host() (just removed from the client's per-request NLM processing) could also trigger an nlm_host garbage collection. Now client-side nlm_host garbage collection occurs only during NFS mount processing. Since the NFS client now holds a reference on these nlm_host structures, they wouldn't have been affected by garbage collection anyway.

Given that nlm_lookup_host() reorders the global nlm_host chain after every successful lookup, and that a garbage collection could be triggered during the call, we've removed a significant amount of per-NLM-request CPU processing overhead.

Sidebar: there are only a few remaining references to the internals of NFS inodes in the client-side NLM code. The only references I found are related to extracting or comparing the inode's file handle via NFS_FH(). One is in nlmclnt_grant(); the other is in nlmclnt_setlockargs().

---

 fs/lockd/clntproc.c        |   22 ++++------------------
 fs/nfs/nfs3proc.c          |    5 ++++-
 fs/nfs/proc.c              |    5 ++++-
 include/linux/lockd/bind.h |    3 ++-
 4 files changed, 14 insertions(+), 21 deletions(-)
fs/lockd/clntproc.c +4 -18
index a10343b..40d498b 100644
@@ -148,30 +148,16 @@ static void nlmclnt_release_lockargs(struct nlm_rqst *req)
 /*
  * This is the main entry point for the NLM client.
  */
-int
-nlmclnt_proc(struct inode *inode, int cmd, struct file_lock *fl)
+int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
 {
-	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;
 	unsigned long		flags;
-	int			status, vers;
-
-	vers = (NFS_PROTO(inode)->version == 3) ? 4 : 1;
-	if (NFS_PROTO(inode)->version > 3) {
-		printk(KERN_NOTICE "NFSv4 file locking not implemented!\n");
-		return -ENOLCK;
-	}
+	int			status;
 
-	rpc_peeraddr(client, (struct sockaddr *) &addr, sizeof(addr));
-	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;
+	nlm_get_host(host);
 
 	call = nlm_alloc_call(host);
 	if (call == NULL)
@@ -219,7 +205,7 @@ nlmclnt_proc(struct inode *inode, int cmd, struct file_lock *fl)
 	dprintk("lockd: clnt proc returns %d\n", status);
 	return status;
 }
-EXPORT_SYMBOL(nlmclnt_proc);
+EXPORT_SYMBOL_GPL(nlmclnt_proc);
 
 /*
  * Allocate an NLM RPC call struct
fs/nfs/nfs3proc.c +4 -1
index 4cdc236..f07b8d7 100644
@@ -796,7 +796,10 @@ static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
 static int
 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
 {
-	return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct nlm_host *host = NFS_SERVER(inode)->nlm_host;
+
+	return nlmclnt_proc(host, cmd, fl);
 }
 
 const struct nfs_rpc_ops nfs_v3_clientops = {
fs/nfs/proc.c +4 -1
index 4f80d88..50cac6a 100644
@@ -609,7 +609,10 @@ nfs_proc_commit_setup(struct nfs_write_data *data, int how)
 static int
 nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
 {
-	return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct nlm_host *host = NFS_SERVER(inode)->nlm_host;
+
+	return nlmclnt_proc(host, cmd, fl);
 }
 
 
include/linux/lockd/bind.h +2 -1
index 372c8df..59d51f1 100644
@@ -42,7 +42,8 @@ extern struct nlm_host *nlmclnt_init(struct sockaddr *server_address,
 					unsigned short protocol);
 extern void	nlmclnt_done(struct nlm_host *host);
 
-extern int	nlmclnt_proc(struct inode *, int, struct file_lock *);
+extern int	nlmclnt_proc(struct nlm_host *host, int cmd,
+					struct file_lock *fl);
 extern int	lockd_up(int proto);
 extern void	lockd_down(void);
 

A message that is not in the archive (sent off-list or not yet received): 20080108153221.20097.13404.stgit-meopP2rzCrTwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org

#2 lore raw

fs/lockd/clntproc.c static void nlmclnt_release_lockargs(struct nlm_rqst *req) · line 159

Quoted 9 lines · Chuck Lever
fs/lockd/clntproc.c +2 -0
+int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
 {
 	struct nlm_rqst		*call;
 	sigset_t		oldset;
 	unsigned long		flags;
+	int			status;
 
 	if (host == NULL)
 		return -ENOLCK;

I think this check can just go away aswell. It's a quite catastrophic API useage error and deserves to get a crash instead of addition cargo cult checks. Might be good to add kerneldoc comments for all the exported APIs you touch/add btw to make this entirely clear.

Quoted 6 lines

nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) {

fs/nfs/proc.c +4 -0
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct nlm_host *host = NFS_SERVER(inode)->nlm_host;
+
+	return nlmclnt_proc(host, cmd, fl);

fs/nfs/proc.c nfs_proc_commit_setup(struct nfs_write_data *data, int how) · line 616

Quoted 10 lines
fs/nfs/proc.c +4 -0
 }
 
 static int
 nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
 {
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct nlm_host *host = NFS_SERVER(inode)->nlm_host;
+
+	return nlmclnt_proc(host, cmd, fl);
 }

These two are completely identical, any reason there's two copies here?

#3 lore raw

Hi Christoph-

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Chuck Lever

+int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
{

fs/lockd/clntproc.c +1 -0
 	struct nlm_rqst		*call;
 	sigset_t		oldset;
 	unsigned long		flags;
+	int			status;
Quoted 4 lines

fs/lockd/clntproc.c static void nlmclnt_release_lockargs(struct nlm_rqst *req) · line 159

Quoted 2 lines
fs/lockd/clntproc.c +0 -0
 	if (host == NULL)
 		return -ENOLCK;

I think this check can just go away aswell.

Yeah, I guess that's right. NFS_MOUNT_NONLM is set during mount processing if the NLM couldn't acquire an appropriate nlm_host for this mount point, and NFS_MOUNT_NONLM gates the call to the NFS version specific lock calls.

It should probably also dump a warning into the kernel log if the admin requested "lock" and got "nolock" instead. That could certainly change application behavior unexpectedly!

Quoted 2 lines

Might be good to add kerneldoc comments for all the
exported APIs you touch/add btw to make this entirely clear.

Yes, nlmclnt_proc() deserves a comment. I usually add one in these cases, and just forgot here.

I'll repost with these changes.

Quoted 8 lines
Quoted 8 lines

nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) {

fs/nfs/nfs3proc.c +4 -0
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct nlm_host *host = NFS_SERVER(inode)->nlm_host;
+
+	return nlmclnt_proc(host, cmd, fl);
 }
Quoted 10 lines

fs/nfs/nfs3proc.c static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how) · line 803

Quoted 8 lines

static int
nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) {

fs/nfs/nfs3proc.c +4 -0
+	struct inode *inode = filp->f_path.dentry->d_inode;
+	struct nlm_host *host = NFS_SERVER(inode)->nlm_host;
+
+	return nlmclnt_proc(host, cmd, fl);
 }

These two are completely identical, any reason there's two copies here?

One is for NFS version 2, one for NFS version 3.

If we decide to fold these two together, we should review all of the NFS proc routines and construct a common proc source file. I'm not sure it's worth the trouble.

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com

#4 lore raw
Quoted 12 lines · Chuck Lever

Hi Christoph-

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Chuck Lever

+int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
{

fs/lockd/clntproc.c +1 -0
 	struct nlm_rqst		*call;
 	sigset_t		oldset;
 	unsigned long		flags;
+	int			status;
Quoted 8 lines
Quoted 4 lines

fs/lockd/clntproc.c static void nlmclnt_release_lockargs(struct nlm_rqst *req) · line 159

Quoted 2 lines
fs/lockd/clntproc.c +0 -0
 	if (host == NULL)
 		return -ENOLCK;

I think this check can just go away aswell.

Yeah, I guess that's right. NFS_MOUNT_NONLM is set during mount processing if the NLM couldn't acquire an appropriate nlm_host for this mount point, and NFS_MOUNT_NONLM gates the call to the NFS version specific lock calls.

It should probably also dump a warning into the kernel log if the admin requested "lock" and got "nolock" instead. That could certainly change application behavior unexpectedly!

After a closer look at this, it appears that if nfs_start_lockd() fails, the whole mount request fails, so no new warning is needed, and setting NONLM is superfluous.

This is actually safer behavior -- if the admin requested locking and the client couldn't deliver, the safest thing to do is prevent the mount.

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com