Skip to contentSkip to conversation

Three short patches for 2.6.31

PATCH In review Chuck Lever 2 participants 7 messages May 15, 2009 – Jun 12, 2009 3 messages not in the archive

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

cover Three short patches for 2.6.31

Hi Trond-

Please consider these for 2.6.31.

---

Chuck Lever (3):
SUNRPC: Use AUTH_NULL for GETPORT/GETADDR requests
lockd: Don't bother with RPC ping for NSM upcalls
lockd: Update NSM state from SM_MON replies

 fs/lockd/clntproc.c         |    2 +-
 fs/lockd/mon.c              |   19 +++++++++++++------
 include/linux/lockd/lockd.h |    2 +-
 net/sunrpc/rpcb_clnt.c      |    4 ++--
 4 files changed, 17 insertions(+), 10 deletions(-)
Signature · 1 line
Chuck Lever <[email protected]>

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

#2 lore raw

PATCH 1/3 lockd: Update NSM state from SM_MON replies

When rpc.statd starts up in user space at boot time, it attempts to write the latest NSM local state number into /proc/sys/fs/nfs/nsm_local_state.

If lockd.ko isn't loaded yet (as is the case in most configurations), that file doesn't exist, thus the kernel's NSM state remains set to its initial value of zero during lockd operation.

This is a problem because rpc.statd and lockd use the NSM state number to prevent repeated lock recovery on rebooted hosts. If lockd sends a zero NSM state, but then a delayed SM_NOTIFY with a real NSM state number is received, there is no way for lockd or rpc.statd to distinguish that stale SM_NOTIFY from an actual reboot. Thus lock recovery could be performed after the rebooted host has already started reclaiming locks, and those locks will be lost.

We could change /etc/init.d/nfslock so it always modprobes lockd.ko before starting rpc.statd. However, if lockd.ko is ever unloaded and reloaded, we are back at square one, since the NSM state is not preserved across an unload/reload cycle. This may happen frequently on clients that use automounter. A period of NFS inactivity causes lockd.ko to be unloaded, and the kernel loses its NSM state setting.

Instead, let's use the fact that rpc.statd plants the local system's NSM state in every SM_MON (and SM_UNMON) reply. lockd performs a synchronous SM_MON upcall to the local rpc.statd _before_ sending its first NLM request to a new remote. This would permit rpc.statd to provide the current NSM state to lockd, even after lockd.ko had been unloaded and reloaded.

Note that NLMPROC_LOCK arguments are constructed before the nsm_monitor() call, so we have to rearrange argument construction very slightly to make this all work out.

And, the kernel appears to treat NSM state as a u32 (see struct nlm_args and nsm_res). Make nsm_local_state a u32 as well, to ensure we don't get bogus comparison results.

---

 fs/lockd/clntproc.c         |    2 +-
 fs/lockd/mon.c              |   18 ++++++++++++------
 include/linux/lockd/lockd.h |    2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)
fs/lockd/clntproc.c +1 -1
index dd79570..f55b900 100644
@@ -126,7 +126,6 @@ static void nlmclnt_setlockargs(struct nlm_rqst *req, struct file_lock *fl)
 	struct nlm_lock	*lock = &argp->lock;
 
 	nlmclnt_next_cookie(&argp->cookie);
-	argp->state   = nsm_local_state;
 	memcpy(&lock->fh, NFS_FH(fl->fl_file->f_path.dentry->d_inode), sizeof(struct nfs_fh));
 	lock->caller  = utsname()->nodename;
 	lock->oh.data = req->a_owner;
@@ -519,6 +518,7 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
 
 	if (nsm_monitor(host) < 0)
 		goto out;
+	req->a_args.state = nsm_local_state;
 
 	fl->fl_flags |= FL_ACCESS;
 	status = do_vfs_lock(fl);
fs/lockd/mon.c +12 -6
index 6d5d4a4..3838533 100644
@@ -53,7 +53,7 @@ static				DEFINE_SPINLOCK(nsm_lock);
 /*
  * Local NSM state
  */
-int	__read_mostly		nsm_local_state;
+u32	__read_mostly		nsm_local_state;
 int	__read_mostly		nsm_use_hostnames;
 
 static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm)
@@ -184,13 +184,19 @@ int nsm_monitor(const struct nlm_host *host)
 	nsm->sm_mon_name = nsm_use_hostnames ? nsm->sm_name : nsm->sm_addrbuf;
 
 	status = nsm_mon_unmon(nsm, NSMPROC_MON, &res);
-	if (res.status != 0)
+	if (unlikely(res.status != 0))
 		status = -EIO;
-	if (status < 0)
+	if (unlikely(status < 0)) {
 		printk(KERN_NOTICE "lockd: cannot monitor %s\n", nsm->sm_name);
-	else
-		nsm->sm_monitored = 1;
-	return status;
+		return status;
+	}
+
+	nsm->sm_monitored = 1;
+	if (unlikely(nsm_local_state != res.state)) {
+		nsm_local_state = res.state;
+		dprintk("lockd: NSM state changed to %d\n", nsm_local_state);
+	}
+	return 0;
 }
 
 /**
include/linux/lockd/lockd.h +1 -1
index 51855df..c325b18 100644
@@ -195,7 +195,7 @@ extern struct svc_procedure	nlmsvc_procedures4[];
 extern int			nlmsvc_grace_period;
 extern unsigned long		nlmsvc_timeout;
 extern int			nsm_use_hostnames;
-extern int			nsm_local_state;
+extern u32			nsm_local_state;
 
 /*
  * Lockd client functions
#3 lore raw

PATCH 2/3 lockd: Don't bother with RPC ping for NSM upcalls

In reply to a message not in the archive

Cut NSM upcall RPC traffic in half -- don't do a NULL call first. The cases where a ping would be helpful are rare.

---

 fs/lockd/mon.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
fs/lockd/mon.c +1 -0
index 3838533..7fce1b5 100644
@@ -112,6 +112,7 @@ static struct rpc_clnt *nsm_create(void)
 		.program		= &nsm_program,
 		.version		= NSM_VERSION,
 		.authflavor		= RPC_AUTH_NULL,
+		.flags			= RPC_CLNT_CREATE_NOPING,
 	};
 
 	return rpc_create(&args);
#4 lore raw

PATCH 3/3 SUNRPC: Use AUTH_NULL for GETPORT/GETADDR requests

In reply to a message not in the archive

rpcbind servers do not require RPC authentication, so AUTH_NULL is all that is needed. This saves a few bytes on the wire, and a bit of computational expense on both ends.

---

 net/sunrpc/rpcb_clnt.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/rpcb_clnt.c +2 -2
index beee6da..3083597 100644
@@ -141,7 +141,7 @@ static struct rpc_clnt *rpcb_create_local(struct sockaddr *addr,
 		.servername	= "localhost",
 		.program	= &rpcb_program,
 		.version	= version,
-		.authflavor	= RPC_AUTH_UNIX,
+		.authflavor	= RPC_AUTH_NULL,
 		.flags		= RPC_CLNT_CREATE_NOPING,
 	};
 
@@ -158,7 +158,7 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
 		.servername	= hostname,
 		.program	= &rpcb_program,
 		.version	= version,
-		.authflavor	= RPC_AUTH_UNIX,
+		.authflavor	= RPC_AUTH_NULL,
 		.flags		= (RPC_CLNT_CREATE_NOPING |
 					RPC_CLNT_CREATE_NONPRIVPORT),
 	};

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

#6 lore raw

Re: [PATCH 3/3] SUNRPC: Use AUTH_NULL for GETPORT/GETADDR requests

Quoted 3 lines · Chuck Lever

rpcbind servers do not require RPC authentication, so AUTH_NULL is all that is needed. This saves a few bytes on the wire, and a bit of computational expense on both ends.

This certainly isn't the case for all portmap implementations. Are you sure this change is safe?

Quoted 29 lines

---

 net/sunrpc/rpcb_clnt.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/rpcb_clnt.c +2 -2
index beee6da..3083597 100644
@@ -141,7 +141,7 @@ static struct rpc_clnt *rpcb_create_local(struct sockaddr *addr,
 		.servername	= "localhost",
 		.program	= &rpcb_program,
 		.version	= version,
-		.authflavor	= RPC_AUTH_UNIX,
+		.authflavor	= RPC_AUTH_NULL,
 		.flags		= RPC_CLNT_CREATE_NOPING,
 	};
 
@@ -158,7 +158,7 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
 		.servername	= hostname,
 		.program	= &rpcb_program,
 		.version	= version,
-		.authflavor	= RPC_AUTH_UNIX,
+		.authflavor	= RPC_AUTH_NULL,
 		.flags		= (RPC_CLNT_CREATE_NOPING |
 					RPC_CLNT_CREATE_NONPRIVPORT),
 	};
Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

A message that is not in the archive (sent off-list or not yet received): 1244840937.32257.6.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org

#8 lore raw

Re: [PATCH 3/3] SUNRPC: Use AUTH_NULL for GETPORT/GETADDR requests

Quoted 6 lines · Trond Myklebust
Quoted 3 lines · Chuck Lever

rpcbind servers do not require RPC authentication, so AUTH_NULL is all that is needed. This saves a few bytes on the wire, and a bit of computational expense on both ends.

This certainly isn't the case for all portmap implementations.

What implementations require AUTH_SYS ? The libtirpc and glibc rpcb_getaddr/pmap_getport implementations use NULL, as far as I can tell. libtirpc rpcb_set uses a local socket, which does local authentication. pmap_set in glib uses NULL, I think.

Quoted 2 lines

Are you
sure this change is safe?

We can hold off if you like.

Quoted 21 lines
Quoted 21 lines

---

net/sunrpc/rpcb_clnt.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/rpcb_clnt.c +1 -1
index beee6da..3083597 100644
@@ -141,7 +141,7 @@ static struct rpc_clnt  
 *rpcb_create_local(struct sockaddr *addr,
 		.servername	= "localhost",
 		.program	= &rpcb_program,
 		.version	= version,
-		.authflavor	= RPC_AUTH_UNIX,
+		.authflavor	= RPC_AUTH_NULL,
 		.flags		= RPC_CLNT_CREATE_NOPING,
 	};
Quoted 19 lines
Quoted 11 lines
net/sunrpc/rpcb_clnt.c +1 -1
@@ -158,7 +158,7 @@ static struct rpc_clnt *rpcb_create(char  
 *hostname, struct sockaddr *srvaddr,
 		.servername	= hostname,
 		.program	= &rpcb_program,
 		.version	= version,
-		.authflavor	= RPC_AUTH_UNIX,
+		.authflavor	= RPC_AUTH_NULL,
 		.flags		= (RPC_CLNT_CREATE_NOPING |
 					RPC_CLNT_CREATE_NONPRIVPORT),
	};
Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

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

#9 lore raw

Re: [PATCH 3/3] SUNRPC: Use AUTH_NULL for GETPORT/GETADDR requests

Quoted 8 lines · Chuck Lever
Quoted 6 lines · Trond Myklebust
Quoted 4 lines · Chuck Lever

rpcbind servers do not require RPC authentication, so AUTH_NULL is all
that is needed. This saves a few bytes on the wire, and a bit of computational expense on both ends.

Quoted 6 lines
Quoted 1 line

This certainly isn't the case for all portmap implementations.

What implementations require AUTH_SYS ? The libtirpc and glibc rpcb_getaddr/pmap_getport implementations use NULL, as far as I can tell. libtirpc rpcb_set uses a local socket, which does local authentication. pmap_set in glib uses NULL, I think.

I just have a vague memory at the back of my head that the last time we tried this, we had to revert the change because some portmapper variant was rejecting it.

The right thing might be simply be to add a handler for the AUTH_TOO_WEAK error.

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com