Skip to contentSkip to conversation

Client-side migration support for 2.6.40 [take 3]

PATCH In review Chuck Lever 3 participants 23 messages May 9, 2011 – May 12, 2011 1 message not in the archive

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

cover Client-side migration support for 2.6.40 [take 3]

Hi-

Here is the latest pass at client-side support for NFS4.0 migration. Some 4.1 support is thrown in, but is not tested (no extant 4.1 servers in the wild support migration). Patches are against 2.6.39-rc6.

This series adds support for both NFS4ERR_MOVED and NFS4ERR_LEASE_MOVED. It can also re-establish a callback channel with the destination server, post-migration. I've attempted to address all comments and re-organization requests from pub night.

This series is what I am testing this week. I'm sure there are still some bugs, but let's get the review process rolling.

---

Chuck Lever (12):
NFS: Implement support for NFS4ERR_LEASE_MOVED
NFS: Add migration recovery callouts in nfs4proc.c
NFS: Remove "const" from "struct nfs_server *" fields
NFS: Add basic migration support to state manager thread
NFS: Add functions to swap transports during migration recovery
NFS: Add an API for cloning an nfs_client
NFS: Add infrastructure for updating callback data
NFS: Introduce nfs4_proc_get_mig_status()
NFS: Introduce NFS_ATTR_FATTR_V4_LOCATIONS
NFS: Save root file handle in nfs_server
NFS: Add a client-side function to display file handles
SUNRPC: Add API to acquire source address

Trond Myklebust (4):
SUNRPC: Add a helper to switch the transport of the rpc_client
SUNRPC: Move clnt->cl_server into struct rpc_xprt
SUNRPC: Use RCU to dereference the rpc_clnt.cl_xprt field
SUNRPC: Allow temporary blocking of an rpc client

 fs/nfs/callback.c            |    3 
 fs/nfs/callback_proc.c       |    9 -
 fs/nfs/client.c              |   88 +++++++-
 fs/nfs/getroot.c             |    5 
 fs/nfs/inode.c               |   45 ++++
 fs/nfs/internal.h            |    6 +
 fs/nfs/nfs4_fs.h             |    8 +
 fs/nfs/nfs4namespace.c       |  202 ++++++++++++++++++
 fs/nfs/nfs4proc.c            |  218 +++++++++++++++++---
 fs/nfs/nfs4state.c           |  227 ++++++++++++++++++++-
 fs/nfs/nfs4xdr.c             |   50 +++--
 fs/nfs/super.c               |    5 
 include/linux/nfs_fs.h       |   14 +
 include/linux/nfs_fs_sb.h    |    7 +
 include/linux/nfs_xdr.h      |   42 ++--
 include/linux/sunrpc/clnt.h  |   22 ++
 include/linux/sunrpc/debug.h |   11 +
 include/linux/sunrpc/xprt.h  |    2 
 net/sunrpc/clnt.c            |  461 +++++++++++++++++++++++++++++++++++++-----
 net/sunrpc/rpc_pipe.c        |    5 
 net/sunrpc/rpcb_clnt.c       |   24 +-
 net/sunrpc/stats.c           |    6 -
 net/sunrpc/xprt.c            |   14 +
 23 files changed, 1320 insertions(+), 154 deletions(-)
Signature · 1 line
Chuck Lever
#1 lore raw

PATCH 1/16 SUNRPC: Allow temporary blocking of an rpc client

From: Trond Myklebust <[email protected]>

Add a mechanism to allow us to temporarily block an rpc client while we do surgery on its transport and authentication code.

The new function rpc_lock_client() will block all new rpc calls from starting, and then wait for existing rpc calls to complete. If the wait times out before the rpc calls have completed, then the function returns the number of outstanding active tasks, otherwise it returns 0.

In the event of a non-zero return value, it is up to the caller either to cancel the lock (by calling rpc_unlock_client), or to take the appropriate action to ensure the existing rpc calls complete (e.g. by calling rpc_killall_tasks()).

---

 include/linux/sunrpc/clnt.h |   11 +++++++
 net/sunrpc/clnt.c           |   72 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 0 deletions(-)
include/linux/sunrpc/clnt.h +11 -0
index db7bcaf..1cab257 100644
@@ -23,6 +23,7 @@
 #include <asm/signal.h>
 #include <linux/path.h>
 #include <net/ipv6.h>
+#include <linux/completion.h>
 
 struct rpc_inode;
 
@@ -31,6 +32,7 @@ struct rpc_inode;
  */
 struct rpc_clnt {
 	atomic_t		cl_count;	/* Number of references */
+	atomic_t		cl_active_tasks;/* Number of active tasks */
 	struct list_head	cl_clients;	/* Global list of clients */
 	struct list_head	cl_tasks;	/* List of tasks */
 	spinlock_t		cl_lock;	/* spinlock */
@@ -46,6 +48,10 @@ struct rpc_clnt {
 	struct rpc_stat *	cl_stats;	/* per-program statistics */
 	struct rpc_iostats *	cl_metrics;	/* per-client statistics */
 
+	unsigned long		cl_flags;	/* Bit flags */
+	struct rpc_wait_queue	cl_waitqueue;
+	struct completion	cl_completion;
+
 	unsigned int		cl_softrtry : 1,/* soft timeouts */
 				cl_discrtry : 1,/* disconnect before retry */
 				cl_autobind : 1,/* use getport() */
@@ -65,6 +71,8 @@ struct rpc_clnt {
 	char			*cl_principal;	/* target to authenticate to */
 };
 
+#define RPC_CLIENT_LOCKED	0
+
 /*
  * General RPC program info
  */
@@ -135,6 +143,9 @@ void		rpc_shutdown_client(struct rpc_clnt *);
 void		rpc_release_client(struct rpc_clnt *);
 void		rpc_task_release_client(struct rpc_task *);
 
+int		rpc_lock_client(struct rpc_clnt *clnt, unsigned long timeout);
+void		rpc_unlock_client(struct rpc_clnt *clnt);
+
 int		rpcb_register(u32, u32, int, unsigned short);
 int		rpcb_v4_register(const u32 program, const u32 version,
 				 const struct sockaddr *address,
net/sunrpc/clnt.c +72 -0

101 lines not on this page · raw message

#2 lore raw

PATCH 2/16 SUNRPC: Use RCU to dereference the rpc_clnt.cl_xprt field

In reply to Chuck Lever

From: Trond Myklebust <[email protected]>

A migration event will replace the rpc_xprt used by an rpc_clnt. To ensure this can be done safely, all references to cl_xprt must now use a form of rcu_dereference().

Special care is taken with rpc_peeraddr2str(), which returns a pointer to memory whose lifetime is the same as the rpc_xprt.

[ cel: fix lockdep splats and layering violations ]

---

 fs/nfs/callback_proc.c       |    9 ++--
 fs/nfs/client.c              |   16 +++++--
 fs/nfs/nfs4proc.c            |   15 +++++--
 fs/nfs/nfs4state.c           |   14 +++++-
 fs/nfs/super.c               |    5 ++
 include/linux/sunrpc/clnt.h  |    4 +-
 include/linux/sunrpc/debug.h |   11 +++++
 net/sunrpc/clnt.c            |   94 +++++++++++++++++++++++++++++++++++-------
 net/sunrpc/rpc_pipe.c        |    3 +
 net/sunrpc/rpcb_clnt.c       |   15 +++++--
 net/sunrpc/stats.c           |    6 ++-
 11 files changed, 155 insertions(+), 37 deletions(-)
fs/nfs/callback_proc.c +5 -4
index 2f41dcce..d360b80 100644
@@ -8,6 +8,7 @@
 #include <linux/nfs4.h>
 #include <linux/nfs_fs.h>
 #include <linux/slab.h>
+#include <linux/rcupdate.h>
 #include "nfs4_fs.h"
 #include "callback.h"
 #include "delegation.h"
@@ -33,7 +34,7 @@ __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
 	res->bitmap[0] = res->bitmap[1] = 0;
 	res->status = htonl(NFS4ERR_BADHANDLE);
 
-	dprintk("NFS: GETATTR callback request from %s\n",
+	dprintk_rcu("NFS: GETATTR callback request from %s\n",
 		rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
 
 	inode = nfs_delegation_find_inode(cps->clp, &args->fh);
@@ -73,7 +74,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
 	if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
 		goto out;
 
-	dprintk("NFS: RECALL callback request from %s\n",
+	dprintk_rcu("NFS: RECALL callback request from %s\n",
 		rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
 
 	res = htonl(NFS4ERR_BADHANDLE);
@@ -442,7 +443,7 @@ __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy,
 	if (!cps->clp) /* set in cb_sequence */
 		goto out;
 
-	dprintk("NFS: RECALL_ANY callback request from %s\n",
+	dprintk_rcu("NFS: RECALL_ANY callback request from %s\n",
 		rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
 
 	status = cpu_to_be32(NFS4ERR_INVAL);
@@ -477,7 +478,7 @@ __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy,
 	if (!cps->clp) /* set in cb_sequence */
 		goto out;
 
-	dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
+	dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
 		rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
 		args->crsa_target_max_slots);
 
fs/nfs/client.c +11 -5
index 139be96..b55ef58 100644
@@ -1273,16 +1273,18 @@ static int nfs4_init_callback(struct nfs_client *clp)
 	int error;
 
 	if (clp->rpc_ops->version == 4) {
+		struct rpc_xprt *xprt;
+
+		xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
+
 		if (nfs4_has_session(clp)) {
-			error = xprt_setup_backchannel(
-						clp->cl_rpcclient->cl_xprt,
+			error = xprt_setup_backchannel(xprt,
 						NFS41_BC_MIN_CALLBACKS);
 			if (error < 0)
 				return error;
 		}
 
-		error = nfs_callback_up(clp->cl_mvops->minor_version,
-					clp->cl_rpcclient->cl_xprt);
+		error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
 		if (error < 0) {
 			dprintk("%s: failed to start callback. Error = %d\n",
 				__func__, error);
@@ -1663,7 +1665,7 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
 				data->addrlen,
 				parent_client->cl_ipaddr,
 				data->authflavor,
-				parent_server->client->cl_xprt->prot,
+				rpc_protocol(parent_server->client),
 				parent_server->client->cl_timeout,
 				parent_client->cl_mvops->minor_version);
 	if (error < 0)
@@ -1863,12 +1865,14 @@ static int nfs_server_list_show(struct seq_file *m, void *v)
 	/* display one transport per line on subsequent lines */
 	clp = list_entry(v, struct nfs_client, cl_share_link);
 
+	rcu_read_lock();
 	seq_printf(m, "v%u %s %s %3d %s\n",
 		   clp->rpc_ops->version,
 		   rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
 		   rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
 		   atomic_read(&clp->cl_count),
 		   clp->cl_hostname);
+	rcu_read_unlock();
 
 	return 0;
 }
@@ -1942,6 +1946,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
 		 (unsigned long long) server->fsid.major,
 		 (unsigned long long) server->fsid.minor);
 
+	rcu_read_lock();
 	seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
 		   clp->rpc_ops->version,
 		   rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
@@ -1949,6 +1954,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
 		   dev,
 		   fsid,
 		   nfs_server_fscache_state(server));
+	rcu_read_unlock();
 
 	return 0;
 }
fs/nfs/nfs4proc.c +11 -4
index 69c0f3c..5a87686 100644
@@ -3734,6 +3734,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
 	*p = htonl((u32)clp->cl_boot_time.tv_nsec);
 
 	for(;;) {
+		rcu_read_lock();
 		setclientid.sc_name_len = scnprintf(setclientid.sc_name,
 				sizeof(setclientid.sc_name), "%s/%s %s %s %u",
 				clp->cl_ipaddr,
@@ -3750,6 +3751,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
 		setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
 				sizeof(setclientid.sc_uaddr), "%s.%u.%u",
 				clp->cl_ipaddr, port >> 8, port & 255);
+		rcu_read_unlock();
 
 		status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
 		if (status != -NFS4ERR_CLID_INUSE)
@@ -5050,11 +5052,16 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
 
 void nfs4_destroy_session(struct nfs4_session *session)
 {
+	struct rpc_xprt *xprt;
+
 	nfs4_proc_destroy_session(session);
+
+	rcu_read_lock();
+	xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt);
+	rcu_read_unlock();
 	dprintk("%s Destroy backchannel for xprt %p\n",
-		__func__, session->clp->cl_rpcclient->cl_xprt);
-	xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
-				NFS41_BC_MIN_CALLBACKS);
+		__func__, xprt);
+	xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS);
 	nfs4_destroy_slot_tables(session);
 	kfree(session);
 }
@@ -5083,7 +5090,7 @@ static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
 	args->fc_attrs.max_rqst_sz = mxrqst_sz;
 	args->fc_attrs.max_resp_sz = mxresp_sz;
 	args->fc_attrs.max_ops = NFS4_MAX_OPS;
-	args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
+	args->fc_attrs.max_reqs = rpc_max_reqs(session->clp->cl_rpcclient);
 
 	dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
 		"max_ops=%u max_reqs=%u\n",
fs/nfs/nfs4state.c +11 -3
index 036f5ad..f6b268f 100644
@@ -1011,16 +1011,24 @@ static void nfs4_clear_state_manager_bit(struct nfs_client *clp)
 void nfs4_schedule_state_manager(struct nfs_client *clp)
 {
 	struct task_struct *task;
+	char buf[INET6_ADDRSTRLEN + sizeof("-manager") + 1];
 
 	if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
 		return;
 	__module_get(THIS_MODULE);
 	atomic_inc(&clp->cl_count);
-	task = kthread_run(nfs4_run_state_manager, clp, "%s-manager",
-				rpc_peeraddr2str(clp->cl_rpcclient,
-							RPC_DISPLAY_ADDR));
+
+	/* The rcu_read_lock() is not strictly necessary, as the state
+	 * manager is the only thread that ever changes the rpc_xprt
+	 * after it's initialized.  At this point, we're single threaded. */
+	rcu_read_lock();
+	snprintf(buf, sizeof(buf), "%s-manager",
+			rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
+	rcu_read_unlock();
+	task = kthread_run(nfs4_run_state_manager, clp, buf);
 	if (!IS_ERR(task))
 		return;
+
 	nfs4_clear_state_manager_bit(clp);
 	nfs_put_client(clp);
 	module_put(THIS_MODULE);
fs/nfs/super.c +5 -0
index e288f06..50c0482 100644
@@ -53,6 +53,7 @@
 #include <linux/nfs_xdr.h>
 #include <linux/magic.h>
 #include <linux/parser.h>
+#include <linux/rcupdate.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -676,8 +677,10 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
 		else
 			seq_puts(m, nfs_infop->nostr);
 	}
+	rcu_read_lock();
 	seq_printf(m, ",proto=%s",
 		   rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
+	rcu_read_unlock();
 	if (version == 4) {
 		if (nfss->port != NFS_PORT)
 			seq_printf(m, ",port=%u", nfss->port);
@@ -726,9 +729,11 @@ static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
 
 	nfs_show_mount_options(m, nfss, 0);
 
+	rcu_read_lock();
 	seq_printf(m, ",addr=%s",
 			rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
 							RPC_DISPLAY_ADDR));
+	rcu_read_unlock();
 
 	return 0;
 }
include/linux/sunrpc/clnt.h +3 -1
index 1cab257..7a1d124 100644
@@ -36,7 +36,7 @@ struct rpc_clnt {
 	struct list_head	cl_clients;	/* Global list of clients */
 	struct list_head	cl_tasks;	/* List of tasks */
 	spinlock_t		cl_lock;	/* spinlock */
-	struct rpc_xprt *	cl_xprt;	/* transport */
+	struct rpc_xprt __rcu *	cl_xprt;	/* transport */
 	struct rpc_procinfo *	cl_procinfo;	/* procedure info */
 	u32			cl_prog,	/* RPC program number */
 				cl_vers,	/* RPC version number */
@@ -164,6 +164,8 @@ struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
 int		rpc_restart_call_prepare(struct rpc_task *);
 int		rpc_restart_call(struct rpc_task *);
 void		rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
+int		rpc_protocol(struct rpc_clnt *);
+unsigned int	rpc_max_reqs(struct rpc_clnt *);
 size_t		rpc_max_payload(struct rpc_clnt *);
 void		rpc_force_rebind(struct rpc_clnt *);
 size_t		rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
include/linux/sunrpc/debug.h +11 -0
index c2786f2..28136fd 100644
@@ -47,15 +47,26 @@ extern unsigned int		nlm_debug;
 #endif
 
 #define dprintk(args...)	dfprintk(FACILITY, ## args)
+#define dprintk_rcu(args...)	dfprintk_rcu(FACILITY, ## args)
 
 #undef ifdebug
 #ifdef RPC_DEBUG			
 # define ifdebug(fac)		if (unlikely(rpc_debug & RPCDBG_##fac))
 # define dfprintk(fac, args...)	do { ifdebug(fac) printk(args); } while(0)
+
+# define dfprintk_rcu(fac, args...)	\
+	do { \
+		ifdebug(fac) { \
+			rcu_read_lock(); \
+			printk(args); \
+			rcu_read_unlock(); \
+		} \
+	} while (0)
 # define RPC_IFDEBUG(x)		x
 #else
 # define ifdebug(fac)		if (0)
 # define dfprintk(fac, args...)	do ; while (0)
+# define dfprintk_rcu(fac, args...)	do ; while (0)
 # define RPC_IFDEBUG(x)
 #endif
 
net/sunrpc/clnt.c +79 -15

183 lines not on this page · raw message

net/sunrpc/rpc_pipe.c +3 -0
index 72bc536..47053e5 100644
@@ -16,6 +16,7 @@
 #include <linux/namei.h>
 #include <linux/fsnotify.h>
 #include <linux/kernel.h>
+#include <linux/rcupdate.h>
 
 #include <asm/ioctls.h>
 #include <linux/fs.h>
@@ -359,12 +360,14 @@ rpc_show_info(struct seq_file *m, void *v)
 {
 	struct rpc_clnt *clnt = m->private;
 
+	rcu_read_lock();
 	seq_printf(m, "RPC server: %s\n", clnt->cl_server);
 	seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_protname,
 			clnt->cl_prog, clnt->cl_vers);
 	seq_printf(m, "address: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR));
 	seq_printf(m, "protocol: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PROTO));
 	seq_printf(m, "port: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PORT));
+	rcu_read_unlock();
 	return 0;
 }
 
net/sunrpc/rpcb_clnt.c +11 -4
index 9a80a92..a861e19 100644
@@ -571,9 +571,10 @@ static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbi
 static struct rpc_clnt *rpcb_find_transport_owner(struct rpc_clnt *clnt)
 {
 	struct rpc_clnt *parent = clnt->cl_parent;
+	struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt);
 
 	while (parent != clnt) {
-		if (parent->cl_xprt != clnt->cl_xprt)
+		if (rcu_dereference(parent->cl_xprt) != xprt)
 			break;
 		if (clnt->cl_autobind)
 			break;
@@ -604,8 +605,12 @@ void rpcb_getport_async(struct rpc_task *task)
 	size_t salen;
 	int status;
 
-	clnt = rpcb_find_transport_owner(task->tk_client);
-	xprt = clnt->cl_xprt;
+	rcu_read_lock();
+	do {
+		clnt = rpcb_find_transport_owner(task->tk_client);
+		xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
+	} while (xprt == NULL);
+	rcu_read_unlock();
 
 	dprintk("RPC: %5u %s(%s, %u, %u, %d)\n",
 		task->tk_pid, __func__,
@@ -618,6 +623,7 @@ void rpcb_getport_async(struct rpc_task *task)
 	if (xprt_test_and_set_binding(xprt)) {
 		dprintk("RPC: %5u %s: waiting for another binder\n",
 			task->tk_pid, __func__);
+		xprt_put(xprt);
 		return;
 	}
 
@@ -685,7 +691,7 @@ void rpcb_getport_async(struct rpc_task *task)
 	switch (bind_version) {
 	case RPCBVERS_4:
 	case RPCBVERS_3:
-		map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
+		map->r_netid = xprt->address_strings[RPC_DISPLAY_NETID];
 		map->r_addr = rpc_sockaddr2uaddr(sap);
 		map->r_owner = "";
 		break;
@@ -714,6 +720,7 @@ bailout_release_client:
 bailout_nofree:
 	rpcb_wake_rpcbind_waiters(xprt, status);
 	task->tk_status = status;
+	xprt_put(xprt);
 }
 EXPORT_SYMBOL_GPL(rpcb_getport_async);
 
net/sunrpc/stats.c +5 -1
index 80df89d..4084255 100644
@@ -22,6 +22,7 @@
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/svcsock.h>
 #include <linux/sunrpc/metrics.h>
+#include <linux/rcupdate.h>
 
 #include "netns.h"
 
@@ -179,7 +180,7 @@ static void _print_name(struct seq_file *seq, unsigned int op,
 void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt)
 {
 	struct rpc_iostats *stats = clnt->cl_metrics;
-	struct rpc_xprt *xprt = clnt->cl_xprt;
+	struct rpc_xprt *xprt;
 	unsigned int op, maxproc = clnt->cl_maxproc;
 
 	if (!stats)
@@ -189,8 +190,11 @@ void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt)
 	seq_printf(seq, "p/v: %u/%u (%s)\n",
 			clnt->cl_prog, clnt->cl_vers, clnt->cl_protname);
 
+	rcu_read_lock();
+	xprt = rcu_dereference(clnt->cl_xprt);
 	if (xprt)
 		xprt->ops->print_stats(xprt, seq);
+	rcu_read_unlock();
 
 	seq_printf(seq, "\tper-op statistics\n");
 	for (op = 0; op < maxproc; op++) {
#3 lore raw

PATCH 3/16 SUNRPC: Move clnt->cl_server into struct rpc_xprt

In reply to Chuck Lever

From: Trond Myklebust <[email protected]>

When the cl_xprt field is updated, the cl_server field will also have to change. Since the contents of cl_server follow the remote endpoint of cl_xprt, just move that field to the rpc_xprt.

[ cel: simplify check_gss_callback_principal(), whitespace changes ]

---

 fs/nfs/callback.c           |    3 +-
 include/linux/sunrpc/clnt.h |    3 +-
 include/linux/sunrpc/xprt.h |    2 +
 net/sunrpc/clnt.c           |   74 ++++++++++++++++++++-----------------------
 net/sunrpc/rpc_pipe.c       |    2 +
 net/sunrpc/rpcb_clnt.c      |    9 +++--
 net/sunrpc/xprt.c           |   14 ++++++++
 7 files changed, 58 insertions(+), 49 deletions(-)
fs/nfs/callback.c +1 -2
index e3d2942..1253540 100644
@@ -332,7 +332,6 @@ void nfs_callback_down(int minorversion)
 int
 check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
 {
-	struct rpc_clnt *r = clp->cl_rpcclient;
 	char *p = svc_gss_principal(rqstp);
 
 	if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
@@ -353,7 +352,7 @@ check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
 	if (memcmp(p, "nfs@", 4) != 0)
 		return 0;
 	p += 4;
-	if (strcmp(p, r->cl_server) != 0)
+	if (strcmp(p, clp->cl_hostname) != 0)
 		return 0;
 	return 1;
 }
include/linux/sunrpc/clnt.h +1 -2
index 7a1d124..2eea0d7 100644
@@ -42,7 +42,6 @@ struct rpc_clnt {
 				cl_vers,	/* RPC version number */
 				cl_maxproc;	/* max procedure number */
 
-	char *			cl_server;	/* server machine name */
 	char *			cl_protname;	/* protocol name */
 	struct rpc_auth *	cl_auth;	/* authenticator */
 	struct rpc_stat *	cl_stats;	/* per-program statistics */
@@ -116,7 +115,7 @@ struct rpc_create_args {
 	size_t			addrsize;
 	struct sockaddr		*saddress;
 	const struct rpc_timeout *timeout;
-	char			*servername;
+	const char		*servername;
 	struct rpc_program	*program;
 	u32			prognumber;	/* overrides program->number */
 	u32			version;
include/linux/sunrpc/xprt.h +2 -0
index 81cce3b..5a75b4b 100644
@@ -225,6 +225,7 @@ struct rpc_xprt {
 	} stat;
 
 	struct net		*xprt_net;
+	const char		*servername;
 	const char		*address_strings[RPC_DISPLAY_MAX];
 };
 
@@ -254,6 +255,7 @@ struct xprt_create {
 	struct sockaddr *	srcaddr;	/* optional local address */
 	struct sockaddr *	dstaddr;	/* remote peer address */
 	size_t			addrlen;
+	const char *		servername;
 	struct svc_xprt		*bc_xprt;	/* NFSv4.1 backchannel */
 };
 
net/sunrpc/clnt.c +35 -39

180 lines not on this page · raw message

net/sunrpc/rpc_pipe.c +1 -1
index 47053e5..e7b12b5 100644
@@ -361,7 +361,7 @@ rpc_show_info(struct seq_file *m, void *v)
 	struct rpc_clnt *clnt = m->private;
 
 	rcu_read_lock();
-	seq_printf(m, "RPC server: %s\n", clnt->cl_server);
+	seq_printf(m, "RPC server: %s\n", rcu_dereference(clnt->cl_xprt)->servername);
 	seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_protname,
 			clnt->cl_prog, clnt->cl_vers);
 	seq_printf(m, "address: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR));
net/sunrpc/rpcb_clnt.c +5 -4
index a861e19..9fa4cb4 100644
@@ -291,8 +291,9 @@ out:
 	return result;
 }
 
-static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
-				    size_t salen, int proto, u32 version)
+static struct rpc_clnt *rpcb_create(const char *hostname,
+				    struct sockaddr *srvaddr, size_t salen,
+				    int proto, u32 version)
 {
 	struct rpc_create_args args = {
 		.net		= &init_net,
@@ -614,7 +615,7 @@ void rpcb_getport_async(struct rpc_task *task)
 
 	dprintk("RPC: %5u %s(%s, %u, %u, %d)\n",
 		task->tk_pid, __func__,
-		clnt->cl_server, clnt->cl_prog, clnt->cl_vers, xprt->prot);
+		xprt->servername, clnt->cl_prog, clnt->cl_vers, xprt->prot);
 
 	/* Put self on the wait queue to ensure we get notified if
 	 * some other task is already attempting to bind the port */
@@ -665,7 +666,7 @@ void rpcb_getport_async(struct rpc_task *task)
 	dprintk("RPC: %5u %s: trying rpcbind version %u\n",
 		task->tk_pid, __func__, bind_version);
 
-	rpcb_clnt = rpcb_create(clnt->cl_server, sap, salen, xprt->prot,
+	rpcb_clnt = rpcb_create(xprt->servername, sap, salen, xprt->prot,
 				bind_version);
 	if (IS_ERR(rpcb_clnt)) {
 		status = PTR_ERR(rpcb_clnt);
net/sunrpc/xprt.c +13 -1
index ce5eb68..76879bc 100644
@@ -65,6 +65,7 @@
 static void	xprt_request_init(struct rpc_task *, struct rpc_xprt *);
 static void	xprt_connect_status(struct rpc_task *task);
 static int      __xprt_get_cong(struct rpc_xprt *, struct rpc_task *);
+static void	 xprt_destroy(struct rpc_xprt *xprt);
 
 static DEFINE_SPINLOCK(xprt_list_lock);
 static LIST_HEAD(xprt_list);
@@ -740,7 +741,7 @@ static void xprt_connect_status(struct rpc_task *task)
 	default:
 		dprintk("RPC: %5u xprt_connect_status: error %d connecting to "
 				"server %s\n", task->tk_pid, -task->tk_status,
-				task->tk_client->cl_server);
+				xprt->servername);
 		xprt_release_write(xprt, task);
 		task->tk_status = -EIO;
 	}
@@ -1138,6 +1139,16 @@ found:
 
 	xprt_init_xid(xprt);
 
+	if (strlen(args->servername) > RPC_MAXNETNAMELEN) {
+		xprt_destroy(xprt);
+		return ERR_PTR(-EINVAL);
+	}
+	xprt->servername = kstrdup(args->servername, GFP_KERNEL);
+	if (xprt->servername == NULL) {
+		xprt_destroy(xprt);
+		return ERR_PTR(-ENOMEM);
+	}
+
 	dprintk("RPC:       created transport %p with %u slots\n", xprt,
 			xprt->max_reqs);
 	return xprt;
@@ -1160,6 +1171,7 @@ static void xprt_destroy(struct rpc_xprt *xprt)
 	rpc_destroy_wait_queue(&xprt->resend);
 	rpc_destroy_wait_queue(&xprt->backlog);
 	cancel_work_sync(&xprt->task_cleanup);
+	kfree(xprt->servername);
 	/*
 	 * Tear down transport state and free the rpc_xprt
 	 */
#4 lore raw

PATCH 4/16 SUNRPC: Add a helper to switch the transport of the rpc_client

In reply to Chuck Lever

From: Trond Myklebust <[email protected]>

[ cel: fix whitespace ]

---

 include/linux/sunrpc/clnt.h |    3 ++
 net/sunrpc/clnt.c           |   76 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 73 insertions(+), 6 deletions(-)
include/linux/sunrpc/clnt.h +3 -0
index 2eea0d7..d18d952 100644
@@ -144,6 +144,9 @@ void		rpc_task_release_client(struct rpc_task *);
 
 int		rpc_lock_client(struct rpc_clnt *clnt, unsigned long timeout);
 void		rpc_unlock_client(struct rpc_clnt *clnt);
+int		rpc_switch_client_transport(struct rpc_clnt *,
+				struct xprt_create *,
+				const struct rpc_timeout *);
 
 int		rpcb_register(u32, u32, int, unsigned short);
 int		rpcb_v4_register(const u32 program, const u32 version,
net/sunrpc/clnt.c +70 -6

117 lines not on this page · raw message

#5 lore raw

PATCH 5/16 SUNRPC: Add API to acquire source address

In reply to Chuck Lever

NFSv4.0 clients must send endpoint information for their callback service to NFSv4.0 servers during their first contact with a server. Traditionally, user space provides the callback endpoint IP address via the "clientaddr=" mount option.

During an NFSv4 migration event, it is possible that an FSID may be migrated to a destination server that is accessible via a different client-side NIC than the source server was. The client must update callback endpoint information on the destination server so that it can maintain leases and allow delegation.

Without a new "clientaddr=" option from user space, however, the kernel itself must construct an appropriate IP address for the callback service. Provide an API in the RPC client for upper layer RPC consumers to acquire a source address for a remote.

The mechanism used by the mount command is copied: set up a connected UDP socket to the remote, then scrape the source address off the socket. We are careful to select the correct network namespace when setting up the temporary UDP socket.

---

 include/linux/sunrpc/clnt.h |    1 
 net/sunrpc/clnt.c           |  149 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+), 0 deletions(-)
include/linux/sunrpc/clnt.h +1 -0
index d18d952..c2d60c3 100644
@@ -172,6 +172,7 @@ size_t		rpc_max_payload(struct rpc_clnt *);
 void		rpc_force_rebind(struct rpc_clnt *);
 size_t		rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
 const char	*rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
+int		rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
 
 size_t		rpc_ntop(const struct sockaddr *, char *, const size_t);
 size_t		rpc_pton(const char *, const size_t,
net/sunrpc/clnt.c +149 -0

155 lines not on this page · raw message

#6 lore raw

PATCH 6/16 NFS: Add a client-side function to display file handles

In reply to Chuck Lever

For debugging, introduce a simplistic function to print file handles on the system console. It's hooked into the dprintk debugging facility, but you can call _nfs_display_fhandle() directly if you want to print a handle unconditionally.

---

 fs/nfs/inode.c         |   45 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/nfs_fs.h |   14 ++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
fs/nfs/inode.c +45 -0
index 57bb31a..9a444d0 100644
@@ -1039,6 +1039,51 @@ struct nfs_fh *nfs_alloc_fhandle(void)
 }
 
 /**
+ * _nfs_display_fhandle - display an NFS file handle on the console
+ *
+ * @fh: file handle to display
+ * @caption: display caption
+ *
+ * For debugging only.
+ */
+#ifdef RPC_DEBUG
+void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
+{
+	unsigned short i;
+
+	if (fh->size == 0 || fh == NULL) {
+		printk(KERN_NOTICE "%s at %p is empty\n", caption, fh);
+		return;
+	}
+
+	printk(KERN_NOTICE "%s at %p is %u bytes:\n", caption, fh, fh->size);
+	for (i = 0; i < fh->size; i += 16) {
+		__be32 *pos = (__be32 *)&fh->data[i];
+
+		switch ((fh->size - i - 1) >> 2) {
+		case 0:
+			printk(KERN_NOTICE " %08x",
+				be32_to_cpup(pos));
+			break;
+		case 1:
+			printk(KERN_NOTICE " %08x %08x\n",
+				be32_to_cpup(pos), be32_to_cpup(pos + 1));
+			break;
+		case 2:
+			printk(KERN_NOTICE " %08x %08x %08x\n",
+				be32_to_cpup(pos), be32_to_cpup(pos + 1),
+				be32_to_cpup(pos + 2));
+			break;
+		default:
+			printk(KERN_NOTICE " %08x %08x %08x %08x\n",
+				be32_to_cpup(pos), be32_to_cpup(pos + 1),
+				be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
+		}
+	}
+}
+#endif
+
+/**
  * nfs_inode_attrs_need_update - check if the inode attributes need updating
  * @inode - pointer to inode
  * @fattr - attributes
include/linux/nfs_fs.h +14 -0
index 1b93b9c..0e3eb70 100644
@@ -394,6 +394,20 @@ static inline void nfs_free_fhandle(const struct nfs_fh *fh)
 	kfree(fh);
 }
 
+#ifdef RPC_DEBUG
+extern void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption);
+#define nfs_display_fhandle(fh, caption)			\
+	do {							\
+		if (unlikely(nfs_debug & NFSDBG_FACILITY))	\
+			_nfs_display_fhandle(fh, caption);	\
+	} while (0)
+#else
+static inline void nfs_display_fhandle(const struct nfs_fh *fh,
+				       const char *caption)
+{
+}
+#endif
+
 /*
  * linux/fs/nfs/nfsroot.c
  */
#7 lore raw

PATCH 7/16 NFS: Save root file handle in nfs_server

In reply to Chuck Lever

Save each FSID's root directory file handle in the export's local nfs_server structure on the client. This file handle can later be used for migration recovery.

NB: Saving the root FH is done only for NFSv4 mounts.

---

 fs/nfs/client.c           |    1 +
 fs/nfs/getroot.c          |    5 +++++
 include/linux/nfs_fs_sb.h |    1 +
 3 files changed, 7 insertions(+), 0 deletions(-)
fs/nfs/client.c +1 -0
index b55ef58..bf40649 100644
@@ -1101,6 +1101,7 @@ void nfs_free_server(struct nfs_server *server)
 	nfs_put_client(server->nfs_client);
 
 	nfs_free_iostats(server->io_stats);
+	nfs_free_fhandle(server->rootfh);
 	bdi_destroy(&server->backing_dev_info);
 	kfree(server);
 	nfs_release_automount_timer();
fs/nfs/getroot.c +5 -0
index dcb6154..8d4fbe1 100644
@@ -232,6 +232,11 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh,
 		ret = ERR_CAST(inode);
 		goto out;
 	}
+	server->rootfh = nfs_alloc_fhandle();
+	if (server->rootfh != NULL) {
+		nfs_display_fhandle(mntfh, "nfs_get_root: new root FH");
+		nfs_copy_fh(server->rootfh, mntfh);
+	}
 
 	error = nfs_superblock_set_dummy_root(sb, inode);
 	if (error != 0) {
include/linux/nfs_fs_sb.h +1 -0
index 87694ca..aa3a912 100644
@@ -151,6 +151,7 @@ struct nfs_server {
 #endif
 	struct list_head	delegations;
 	void (*destroy)(struct nfs_server *);
+	struct nfs_fh		*rootfh;
 
 	atomic_t active; /* Keep trace of any activity to this server */
 
#8 lore raw

PATCH 8/16 NFS: Introduce NFS_ATTR_FATTR_V4_LOCATIONS

In reply to Chuck Lever

Our NFS client must distinguish between referral events (which it currently supports) and migration events (which it does not yet support).

In both types of events, an fs_locations array is returned. But upper layers should make the distinction between a referral and a migration, not the XDR layer. There really isn't a generic way for an XDR decoder function to tell one from the other.

Slightly adjust the FATTR flags returned by decode_fs_locations() to set NFS_ATTR_FATTR_V4_LOCATIONS only if a non-empty locations array was returned from the server. Then have logic in nfs4proc.c distinguish whether the locations array is for a referral or something else.

---

 fs/nfs/nfs4proc.c       |    5 +++--
 fs/nfs/nfs4xdr.c        |    2 +-
 include/linux/nfs_xdr.h |    7 ++++---
 3 files changed, 8 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +3 -2
index 5a87686..641691c 100644
@@ -2291,7 +2291,8 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct
 	}
 
 	memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
-	fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
+	if (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)
+		fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
 	if (!fattr->mode)
 		fattr->mode = S_IFDIR;
 	memset(fhandle, 0, sizeof(struct nfs_fh));
@@ -4656,7 +4657,7 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
 {
 	if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
 		(fattr->valid & NFS_ATTR_FATTR_FSID) &&
-		(fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
+		(fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
 		return;
 
 	fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
fs/nfs/nfs4xdr.c +1 -1
index c3ccd2c..be70be9 100644
@@ -3326,7 +3326,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
 			res->nlocations++;
 	}
 	if (res->nlocations != 0)
-		status = NFS_ATTR_FATTR_V4_REFERRAL;
+		status = NFS_ATTR_FATTR_V4_LOCATIONS;
 out:
 	dprintk("%s: fs_locations done, error = %d\n", __func__, status);
 	return status;
include/linux/nfs_xdr.h +4 -3
index 890dce2..26165a5 100644
@@ -82,9 +82,10 @@ struct nfs_fattr {
 #define NFS_ATTR_FATTR_PRECTIME		(1U << 16)
 #define NFS_ATTR_FATTR_CHANGE		(1U << 17)
 #define NFS_ATTR_FATTR_PRECHANGE	(1U << 18)
-#define NFS_ATTR_FATTR_V4_REFERRAL	(1U << 19)	/* NFSv4 referral */
-#define NFS_ATTR_FATTR_MOUNTPOINT	(1U << 20)	/* Treat as mountpoint */
-#define NFS_ATTR_FATTR_MOUNTED_ON_FILEID		(1U << 21)
+#define NFS_ATTR_FATTR_V4_LOCATIONS	(1U << 19)
+#define NFS_ATTR_FATTR_V4_REFERRAL	(1U << 20)	/* NFSv4 referral */
+#define NFS_ATTR_FATTR_MOUNTPOINT	(1U << 21) /* Treat as mountpoint */
+#define NFS_ATTR_FATTR_MOUNTED_ON_FILEID (1U << 22)
 
 #define NFS_ATTR_FATTR (NFS_ATTR_FATTR_TYPE \
 		| NFS_ATTR_FATTR_MODE \
#9 lore raw

PATCH 9/16 NFS: Introduce nfs4_proc_get_mig_status()

In reply to Chuck Lever

The nfs4_proc_fs_locations() function is invoked during referral processing to perform a GETATTR(fs_locations) on an object's parent directory in order to discover the target of the referral. It performs a LOOKUP, so the client needs to know the parent's file handle a priori.

o During migration recovery, we need to probe fs_locations informa- tion on an FSID's root directory. The "parent" of a root directory is not available for a LOOKUP operation.

o Recovering from NFS4ERR_LEASE_MOVED is a process of walking over a list of known FSIDs that reside on the server, and probing whether they have migrated. Once the server has detected that the client has probed all migrated file systems, it stops returning NFS4ERR_LEASE_MOVED.

A minor version zero server needs to know what client ID is requesting fs_locations information so it can clear the flag that forces it to continue returning NFS4ERR_LEASE_MOVED. This flag is set per client ID and per FSID. However, the client ID is not an argument of either the PUTFH or GETATTR operations. Later minor versions have client ID information embedded in the underlying session.

Therefore, by convention, minor version zero clients send a RENEW operation in the same compound as the GETATTR(fs_locations), since RENEW has one argument: the short-form client ID. This allows a minor version zero server to identify correctly the client that is probing for a migration.

o For various subtle reasons, servers can't return NFS4ERR_DELAY to state-changing operations while they are actually doing the migration. Instead, they put off clients during the brief window when the data is actually unavailable by returning DELAY to the GETATTR(fs_locations), since GETATTR doesn't mutate NFSv4 state. So our client must be able to deal properly with an NFS4ERR_DELAY reply during a migration status probe.

To handle all this random wackiness, we need a variant of nfs4_proc_fs_locations() that can operate directly on a target file handle, rather than taking a name and doing a LOOKUP as part of retrieving fs_locations from the server. It also must properly append a RENEW operation as needed, and it should retry NFS4ERR_DELAY as appropriate.

Introduce nfs4_proc_get_mig_status() to fill this role, and add the requisite XDR encoding and decoding paraphenalia. Under the covers, both nfs4_proc_foo functions use the FS_LOCATIONS XDR routines. This is a little awkward, but is necessary because it's currently not straightforward to add new NFSv4 procedures due to a bug in nfsstat.

---

 fs/nfs/nfs4_fs.h        |    2 +
 fs/nfs/nfs4proc.c       |   89 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/nfs/nfs4xdr.c        |   48 ++++++++++++++++++-------
 include/linux/nfs_xdr.h |    7 +++-
 4 files changed, 130 insertions(+), 16 deletions(-)
fs/nfs/nfs4_fs.h +2 -0
index c4a6983..4038c5b 100644
@@ -242,6 +242,8 @@ extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_
 extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
 extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
 		struct nfs4_fs_locations *fs_locations, struct page *page);
+extern int nfs4_proc_get_mig_status(struct nfs_server *server,
+		struct nfs4_fs_locations *fs_locations, struct page *page);
 extern void nfs4_release_lockowner(const struct nfs4_lock_state *);
 extern const struct xattr_handler *nfs4_xattr_handlers[];
 
fs/nfs/nfs4proc.c +87 -2

109 lines not on this page · raw message

fs/nfs/nfs4xdr.c +35 -13

72 lines not on this page · raw message

include/linux/nfs_xdr.h +6 -1
index 26165a5..22e34d3 100644
@@ -957,16 +957,21 @@ struct nfs4_fs_locations {
 };
 
 struct nfs4_fs_locations_arg {
+	const struct nfs_client *client;
 	const struct nfs_fh *dir_fh;
+	const struct nfs_fh *fh;
 	const struct qstr *name;
 	struct page *page;
 	const u32 *bitmask;
-	struct nfs4_sequence_args	seq_args;
+	struct nfs4_sequence_args seq_args;
+	unsigned char mig_status:1, renew:1;
 };
 
 struct nfs4_fs_locations_res {
 	struct nfs4_fs_locations       *fs_locations;
 	struct nfs4_sequence_res	seq_res;
+	unsigned char			mig_status:1,
+					renew:1;
 };
 
 struct nfs4_secinfo_oid {
#10 lore raw

PATCH 10/16 NFS: Add infrastructure for updating callback data

In reply to Chuck Lever

Currently the NFS client creates the long-form client ID in the XDR encoder for SETCLIENTID, just before it is sent to the server.

With transparent state migration, the long-form client ID used with the source server must be sent to the destination server when the client uses SETCLIENTID to update the destination server with fresh callback information. If a new long-form client ID is used here, the destination server will drop all the NFSv4 state the servers so carefully migrated for us.

So, the client must preserve the short-form and long-form client ID that are generated at SETCLIENTID/EXCHANGE_ID time. When it comes time to update the callback information, the preserved client IDs are used so the server doesn't drop state for this client.

---

 fs/nfs/client.c           |    1 +
 fs/nfs/nfs4_fs.h          |    1 +
 fs/nfs/nfs4proc.c         |   29 ++++++++++++++++++++++++++---
 fs/nfs/nfs4state.c        |    1 +
 include/linux/nfs_fs_sb.h |    1 +
 5 files changed, 30 insertions(+), 3 deletions(-)
fs/nfs/client.c +1 -0
index bf40649..536b0ba 100644
@@ -231,6 +231,7 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
 	nfs4_destroy_callback(clp);
 	if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
 		nfs_idmap_delete(clp);
+	kfree(clp->cl_cached_clientid);
 
 	rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
 }
fs/nfs/nfs4_fs.h +1 -0
index 4038c5b..1832fd6 100644
@@ -48,6 +48,7 @@ enum nfs4_client_state {
 	NFS4CLNT_SESSION_RESET,
 	NFS4CLNT_RECALL_SLOT,
 	NFS4CLNT_LEASE_CONFIRM,
+	NFS4CLNT_UPDATE_CALLBACK,
 };
 
 enum nfs4_session_state {
fs/nfs/nfs4proc.c +26 -3
index 57b7279..bb6b128 100644
@@ -3736,7 +3736,11 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
 
 	for(;;) {
 		rcu_read_lock();
-		setclientid.sc_name_len = scnprintf(setclientid.sc_name,
+		if (test_bit(NFS4CLNT_UPDATE_CALLBACK, &clp->cl_state)) {
+			strcpy(setclientid.sc_name, clp->cl_cached_clientid);
+			setclientid.sc_name_len = strlen(setclientid.sc_name);
+		} else {
+			setclientid.sc_name_len = scnprintf(setclientid.sc_name,
 				sizeof(setclientid.sc_name), "%s/%s %s %s %u",
 				clp->cl_ipaddr,
 				rpc_peeraddr2str(clp->cl_rpcclient,
@@ -3745,6 +3749,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
 							RPC_DISPLAY_PROTO),
 				clp->cl_rpcclient->cl_auth->au_ops->au_name,
 				clp->cl_id_uniquifier);
+		}
 		setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
 				sizeof(setclientid.sc_netid),
 				rpc_peeraddr2str(clp->cl_rpcclient,
@@ -3755,7 +3760,8 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
 		rcu_read_unlock();
 
 		status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
-		if (status != -NFS4ERR_CLID_INUSE)
+		if (clp->cl_cached_clientid != NULL ||
+		    status != -NFS4ERR_CLID_INUSE)
 			break;
 		if (loop != 0) {
 			++clp->cl_id_uniquifier;
@@ -3764,6 +3770,13 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
 		++loop;
 		ssleep(clp->cl_lease_time / HZ + 1);
 	}
+
+	if (status == 0 &&
+	    !test_bit(NFS4CLNT_UPDATE_CALLBACK, &clp->cl_state)) {
+		kfree(clp->cl_cached_clientid);
+		clp->cl_cached_clientid = kstrdup(setclientid.sc_name,
+								GFP_KERNEL);
+	}
 	return status;
 }
 
@@ -4874,16 +4887,26 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 	*p = htonl((u32)clp->cl_boot_time.tv_nsec);
 	args.verifier = &verifier;
 
-	args.id_len = scnprintf(args.id, sizeof(args.id),
+	if (test_bit(NFS4CLNT_UPDATE_CALLBACK, &clp->cl_state)) {
+		strcpy(args.id, clp->cl_cached_clientid);
+		args.id_len = strlen(args.id);
+	} else {
+		args.id_len = scnprintf(args.id, sizeof(args.id),
 				"%s/%s.%s/%u",
 				clp->cl_ipaddr,
 				init_utsname()->nodename,
 				init_utsname()->domainname,
 				clp->cl_rpcclient->cl_auth->au_flavor);
+	}
 
 	status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
 	if (!status)
 		status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
+	if (!status &&
+	    !test_bit(NFS4CLNT_UPDATE_CALLBACK, &clp->cl_state)) {
+		kfree(clp->cl_cached_clientid);
+		clp->cl_cached_clientid = kstrdup(args.id, GFP_KERNEL);
+	}
 	dprintk("<-- %s status= %d\n", __func__, status);
 	return status;
 }
fs/nfs/nfs4state.c +1 -0
index f6b268f..3285e40 100644
@@ -1646,6 +1646,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
 					nfs_mark_client_ready(clp, status);
 				goto out_error;
 			}
+			clear_bit(NFS4CLNT_UPDATE_CALLBACK, &clp->cl_state);
 			clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
 			set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
 			pnfs_destroy_all_layouts(clp);
include/linux/nfs_fs_sb.h +1 -0
index aa3a912..d0554c4 100644
@@ -70,6 +70,7 @@ struct nfs_client {
 	char			cl_ipaddr[48];
 	unsigned char		cl_id_uniquifier;
 	u32			cl_cb_ident;	/* v4.0 callback identifier */
+	char			*cl_cached_clientid;
 	const struct nfs4_minor_version_ops *cl_mvops;
 
 	/* The sequence id to use for the next CREATE_SESSION */
#11 lore raw

PATCH 11/16 NFS: Add an API for cloning an nfs_client

In reply to Chuck Lever

After a migration event, we have to preserve the client ID the client used with the source server, and introduce it to the destination server, in case the migration transparently migrated state for the migrating FSID.

Note that our RENEW and SETCLIENTID procs both take an nfs_client as an argument. Thus, after a successful migration recovery, we want to have a nfs_client with the correct long-form and short-form client ID for the destination server to pass these procs.

To preserve the client IDs, we clone the source server's nfs_client. The migrated FSID is moved from the original nfs_client to the cloned one.

This patch introduces an API for cloning an nfs_client and moving an FSID to it.

---

 fs/nfs/client.c   |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 fs/nfs/internal.h |    4 +++
 2 files changed, 71 insertions(+), 2 deletions(-)
fs/nfs/client.c +67 -2
index 536b0ba..2f5e29f 100644
@@ -135,6 +135,7 @@ struct nfs_client_initdata {
 	const struct nfs_rpc_ops *rpc_ops;
 	int proto;
 	u32 minorversion;
+	const char *long_clientid;
 };
 
 /*
@@ -184,6 +185,9 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
 	clp->cl_minorversion = cl_init->minorversion;
 	clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
+	if (cl_init->long_clientid != NULL)
+		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
+							GFP_KERNEL);
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
@@ -476,6 +480,10 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
 		/* Match the full socket address */
 		if (!nfs_sockaddr_cmp(sap, clap))
 			continue;
+		/* Match on long-form client ID */
+		if (data->long_clientid && clp->cl_cached_clientid &&
+		    strcmp(data->long_clientid, clp->cl_cached_clientid))
+			continue;
 
 		atomic_inc(&clp->cl_count);
 		return clp;
@@ -1426,8 +1434,65 @@ error:
 	return error;
 }
 
-/*
- * Set up a pNFS Data Server client.
+/**
+ * nfs4_clone_client - Clone a client after a migration event
+ * clp: nfs_client to clone
+ * sap: address of destination server
+ * salen: size of "sap" in bytes
+ * ip_addr: NUL-terminated string containing local presentation address
+ * server: nfs_server to move from "clp" to the new one
+ *
+ * Returns negative errno or zero.  nfs_client field of "server" is
+ * updated to refer to a new or existing nfs_client that matches
+ * [server address, port, version, minorversion, client ID].  The
+ * nfs_server is moved from the old nfs_client's cl_superblocks list
+ * to the new nfs_client's list.
+ */
+int nfs4_clone_client(struct nfs_client *clp, const struct sockaddr *sap,
+		      size_t salen, const char *ip_addr,
+		      struct nfs_server *server)
+{
+	struct rpc_clnt *rpcclnt = clp->cl_rpcclient;
+	struct nfs_client_initdata cl_init = {
+		.addr		= sap,
+		.addrlen	= salen,
+		.rpc_ops	= &nfs_v4_clientops,
+		.proto		= rpc_protocol(rpcclnt),
+		.minorversion	= clp->cl_minorversion,
+		.long_clientid	= clp->cl_cached_clientid,
+	};
+	struct nfs_client *new;
+	int status = 0;
+
+	dprintk("--> %s cloning \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	new = nfs_get_client(&cl_init, rpcclnt->cl_timeout, ip_addr,
+				rpcclnt->cl_auth->au_flavor, 0);
+	if (IS_ERR(new)) {
+		dprintk("<-- %s nfs_get_client failed\n", __func__);
+		status = PTR_ERR(new);
+		goto out;
+	}
+
+	nfs_server_remove_lists(server);
+	server->nfs_client = new;
+	nfs_server_insert_lists(server);
+
+	dprintk("<-- %s moved (%llx:%llx) to nfs_client %p\n", __func__,
+			(unsigned long long)server->fsid.major,
+			(unsigned long long)server->fsid.minor, new);
+
+out:
+	return status;
+}
+
+/**
+ * nfs4_set_ds_client - Set up a pNFS Data Server client
+ * mds_clp: nfs_client representing the MDS
+ * ds_addr: IP address of DS
+ * ds_addrlen: size of "ds_addr" in bytes
+ * ds_proto: transport protocol to use to contact DS
  *
  * Return any existing nfs_client that matches server address,port,version
  * and minorversion.
fs/nfs/internal.h +4 -0
index f6baf5b..0bf4e67 100644
@@ -154,6 +154,10 @@ extern struct nfs_server *nfs_clone_server(struct nfs_server *,
 					   struct nfs_fattr *);
 extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
 extern int nfs4_check_client_ready(struct nfs_client *clp);
+extern int nfs4_clone_client(struct nfs_client *clp,
+				const struct sockaddr *sap, size_t salen,
+				const char *ip_addr,
+				struct nfs_server *server);
 extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
 					     const struct sockaddr *ds_addr,
 					     int ds_addrlen, int ds_proto);
#12 lore raw

Re: [PATCH 11/16] NFS: Add an API for cloning an nfs_client

Quoted 101 lines · Chuck Lever

After a migration event, we have to preserve the client ID the client used with the source server, and introduce it to the destination server, in case the migration transparently migrated state for the migrating FSID.

Note that our RENEW and SETCLIENTID procs both take an nfs_client as an argument. Thus, after a successful migration recovery, we want to have a nfs_client with the correct long-form and short-form client ID for the destination server to pass these procs.

To preserve the client IDs, we clone the source server's nfs_client. The migrated FSID is moved from the original nfs_client to the cloned one.

This patch introduces an API for cloning an nfs_client and moving an FSID to it.

---

fs/nfs/client.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--
fs/nfs/internal.h | 4 +++

2 files changed, 71 insertions(+), 2 deletions(-)
fs/nfs/client.c +46 -2
index 536b0ba..2f5e29f 100644
@@ -135,6 +135,7 @@ struct nfs_client_initdata {
 	const struct nfs_rpc_ops *rpc_ops;
 	int proto;
 	u32 minorversion;
+	const char *long_clientid;
 };
 
 /*
@@ -184,6 +185,9 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
 	clp->cl_minorversion = cl_init->minorversion;
 	clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
+	if (cl_init->long_clientid != NULL)
+		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
+							GFP_KERNEL);
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
@@ -476,6 +480,10 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
 		/* Match the full socket address */
 		if (!nfs_sockaddr_cmp(sap, clap))
 			continue;
+		/* Match on long-form client ID */
+		if (data->long_clientid && clp->cl_cached_clientid &&
+		    strcmp(data->long_clientid, clp->cl_cached_clientid))
+			continue;
 
 		atomic_inc(&clp->cl_count);
 		return clp;
@@ -1426,8 +1434,65 @@ error:
 	return error;
 }
 
-/*
- * Set up a pNFS Data Server client.
+/**
+ * nfs4_clone_client - Clone a client after a migration event
+ * clp: nfs_client to clone
+ * sap: address of destination server
+ * salen: size of "sap" in bytes
+ * ip_addr: NUL-terminated string containing local presentation address
+ * server: nfs_server to move from "clp" to the new one
+ *
+ * Returns negative errno or zero.  nfs_client field of "server" is
+ * updated to refer to a new or existing nfs_client that matches
+ * [server address, port, version, minorversion, client ID].  The
+ * nfs_server is moved from the old nfs_client's cl_superblocks list
+ * to the new nfs_client's list.
+ */
+int nfs4_clone_client(struct nfs_client *clp, const struct sockaddr *sap,
+		      size_t salen, const char *ip_addr,
+		      struct nfs_server *server)
+{
+	struct rpc_clnt *rpcclnt = clp->cl_rpcclient;
+	struct nfs_client_initdata cl_init = {
+		.addr		= sap,
+		.addrlen	= salen,
+		.rpc_ops	= &nfs_v4_clientops,
+		.proto		= rpc_protocol(rpcclnt),
+		.minorversion	= clp->cl_minorversion,
+		.long_clientid	= clp->cl_cached_clientid,
+	};
+	struct nfs_client *new;
+	int status = 0;
+
+	dprintk("--> %s cloning \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	new = nfs_get_client(&cl_init, rpcclnt->cl_timeout, ip_addr,
+				rpcclnt->cl_auth->au_flavor, 0);
+	if (IS_ERR(new)) {
+		dprintk("<-- %s nfs_get_client failed\n", __func__);
+		status = PTR_ERR(new);

fs/nfs/client.c error: · line 1484

Quoted 10 lines
fs/nfs/client.c +10 -0
+		goto out;
+	}
+
+	nfs_server_remove_lists(server);
+	server->nfs_client = new;
+	nfs_server_insert_lists(server);
+
+	dprintk("<-- %s moved (%llx:%llx) to nfs_client %p\n", __func__,
+			(unsigned long long)server->fsid.major,
+			(unsigned long long)server->fsid.minor, new);

We may be in trouble here.

Solaris servers use the cb_ident field to recognize a callback update rather than a full SETCLIENTID. This is because a migrate-reboot-migrate sequence can leave a destination server with a group of short form client IDs associated with the same long-form client ID.

Cloning an nfs_client creates a new nfs_client in many cases, which bumps cb_ident. On Linux, a callback with the original cb_ident would get us the old nfs_client anyway (via idr_find()).

They are proposing that we use the callback RPC program number instead to find the right state information.

Quoted 34 lines
fs/nfs/client.c +11 -0
+
+out:
+	return status;
+}
+
+/**
+ * nfs4_set_ds_client - Set up a pNFS Data Server client
+ * mds_clp: nfs_client representing the MDS
+ * ds_addr: IP address of DS
+ * ds_addrlen: size of "ds_addr" in bytes
+ * ds_proto: transport protocol to use to contact DS
 *
 * Return any existing nfs_client that matches server address,port,version
 * and minorversion.
fs/nfs/internal.h +4 -1
index f6baf5b..0bf4e67 100644
@@ -154,6 +154,10 @@ extern struct nfs_server *nfs_clone_server(struct nfs_server *,
 					   struct nfs_fattr *);
 extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
 extern int nfs4_check_client_ready(struct nfs_client *clp);
+extern int nfs4_clone_client(struct nfs_client *clp,
+				const struct sockaddr *sap, size_t salen,
+				const char *ip_addr,
+				struct nfs_server *server);
 extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
 					     const struct sockaddr *ds_addr,
 					     int ds_addrlen, int ds_proto);
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#13 lore raw

Re: [PATCH 11/16] NFS: Add an API for cloning an nfs_client

Quoted 116 lines · Chuck Lever
Quoted 101 lines · Chuck Lever

After a migration event, we have to preserve the client ID the client used with the source server, and introduce it to the destination server, in case the migration transparently migrated state for the migrating FSID.

Note that our RENEW and SETCLIENTID procs both take an nfs_client as an argument. Thus, after a successful migration recovery, we want to have a nfs_client with the correct long-form and short-form client ID for the destination server to pass these procs.

To preserve the client IDs, we clone the source server's nfs_client. The migrated FSID is moved from the original nfs_client to the cloned one.

This patch introduces an API for cloning an nfs_client and moving an FSID to it.

---

fs/nfs/client.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--
fs/nfs/internal.h | 4 +++

2 files changed, 71 insertions(+), 2 deletions(-)
fs/nfs/client.c +46 -2
index 536b0ba..2f5e29f 100644
@@ -135,6 +135,7 @@ struct nfs_client_initdata {
 	const struct nfs_rpc_ops *rpc_ops;
 	int proto;
 	u32 minorversion;
+	const char *long_clientid;
 };
 
 /*
@@ -184,6 +185,9 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
 	clp->cl_minorversion = cl_init->minorversion;
 	clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion];
+	if (cl_init->long_clientid != NULL)
+		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
+							GFP_KERNEL);
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
@@ -476,6 +480,10 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
 		/* Match the full socket address */
 		if (!nfs_sockaddr_cmp(sap, clap))
 			continue;
+		/* Match on long-form client ID */
+		if (data->long_clientid && clp->cl_cached_clientid &&
+		    strcmp(data->long_clientid, clp->cl_cached_clientid))
+			continue;
 
 		atomic_inc(&clp->cl_count);
 		return clp;
@@ -1426,8 +1434,65 @@ error:
 	return error;
 }
 
-/*
- * Set up a pNFS Data Server client.
+/**
+ * nfs4_clone_client - Clone a client after a migration event
+ * clp: nfs_client to clone
+ * sap: address of destination server
+ * salen: size of "sap" in bytes
+ * ip_addr: NUL-terminated string containing local presentation address
+ * server: nfs_server to move from "clp" to the new one
+ *
+ * Returns negative errno or zero.  nfs_client field of "server" is
+ * updated to refer to a new or existing nfs_client that matches
+ * [server address, port, version, minorversion, client ID].  The
+ * nfs_server is moved from the old nfs_client's cl_superblocks list
+ * to the new nfs_client's list.
+ */
+int nfs4_clone_client(struct nfs_client *clp, const struct sockaddr *sap,
+		      size_t salen, const char *ip_addr,
+		      struct nfs_server *server)
+{
+	struct rpc_clnt *rpcclnt = clp->cl_rpcclient;
+	struct nfs_client_initdata cl_init = {
+		.addr		= sap,
+		.addrlen	= salen,
+		.rpc_ops	= &nfs_v4_clientops,
+		.proto		= rpc_protocol(rpcclnt),
+		.minorversion	= clp->cl_minorversion,
+		.long_clientid	= clp->cl_cached_clientid,
+	};
+	struct nfs_client *new;
+	int status = 0;
+
+	dprintk("--> %s cloning \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	new = nfs_get_client(&cl_init, rpcclnt->cl_timeout, ip_addr,
+				rpcclnt->cl_auth->au_flavor, 0);
+	if (IS_ERR(new)) {
+		dprintk("<-- %s nfs_get_client failed\n", __func__);
+		status = PTR_ERR(new);

fs/nfs/client.c error: · line 1484

Quoted 10 lines
fs/nfs/client.c +10 -0
+		goto out;
+	}
+
+	nfs_server_remove_lists(server);
+	server->nfs_client = new;
+	nfs_server_insert_lists(server);
+
+	dprintk("<-- %s moved (%llx:%llx) to nfs_client %p\n", __func__,
+			(unsigned long long)server->fsid.major,
+			(unsigned long long)server->fsid.minor, new);

We may be in trouble here.

Quoted 1 line

Solaris servers use the cb_ident field to recognize a callback update rather than a full SETCLIENTID. This is because a migrate-reboot-migrate sequence can leave a destination server with a group of short form client IDs associated with the same long-form client ID.

What part of the spec justifies that assumption?

I can't see any mention of this kind of use of callback_ident in section 14.2.33 (or anywhere else). On the contrary, that section states explicitly that the client is free at any time to modify both the callback and callback_ident by means of a SETCLIENTID call that preserves the client.id and client.verifier fields.

Worse: section 14.2.34 (SETCLIENTID_CONFIRM) says that if you confirm a given short clientid, then _all_ state associated with another short clientid value for that same long clientid is wiped.

IOW: I'm having trouble seeing how the 'multiple short clientid' model can work within the framework of the current spec. As far as I can see, it would require significant spec changes.

Quoted 1 line

Cloning an nfs_client creates a new nfs_client in many cases, which bumps cb_ident. On Linux, a callback with the original cb_ident would get us the old nfs_client anyway (via idr_find()).

Right. This is intentional.

Quoted 1 line

They are proposing that we use the callback RPC program number instead to find the right state information.

I'm very sceptical to that. For one thing, it is hard to implement within the framework of the Linux server model: we work much better with the single callback RPC program number and multiple callback_idents.

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
#14 lore raw

PATCH 12/16 NFS: Add functions to swap transports during migration recovery

In reply to Chuck Lever

Introduce functions that can walk through an array of returned fs_locations information and connect a transport to one of the destination servers listed therein.

Note that NFS minor version 1 introduces "fs_locations_info" which extends the locations array sorting criteria available to clients. This is not supported yet.

---

 fs/nfs/internal.h      |    2 
 fs/nfs/nfs4namespace.c |  202 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+), 0 deletions(-)
fs/nfs/internal.h +2 -0
index 0bf4e67..191c5b4 100644
@@ -177,6 +177,8 @@ static inline void nfs_fs_proc_exit(void)
 /* nfs4namespace.c */
 #ifdef CONFIG_NFS_V4
 extern struct vfsmount *nfs_do_refmount(struct dentry *dentry);
+extern int nfs4_replace_transport(struct nfs_server *server,
+		const struct nfs4_fs_locations *locations);
 #else
 static inline
 struct vfsmount *nfs_do_refmount(struct dentry *dentry)
fs/nfs/nfs4namespace.c +202 -0

211 lines not on this page · raw message

#15 lore raw

PATCH 13/16 NFS: Add basic migration support to state manager thread

In reply to Chuck Lever

Migration recovery will be handled separately from the normal synchronous and asynchronous NFS processes, much like the existing state manager thread. In fact state and migration recovery will have to be serialized.

Therefore add migration recovery support to the existing state manager infrastructure, reusing its rendevous mechanism and finite state machine.

Additional debugging is added so that, while we continue to shape our migration recovery implementation, the operation of the state manager is visible. If the extra clutter is objectionable, it can be removed once we are confident of the migration recovery implementation.

---

 fs/nfs/nfs4_fs.h          |    3 +
 fs/nfs/nfs4state.c        |  149 ++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/nfs_fs_sb.h |    3 +
 3 files changed, 153 insertions(+), 2 deletions(-)
fs/nfs/nfs4_fs.h +3 -0
index 1832fd6..c3e8641 100644
@@ -49,6 +49,8 @@ enum nfs4_client_state {
 	NFS4CLNT_RECALL_SLOT,
 	NFS4CLNT_LEASE_CONFIRM,
 	NFS4CLNT_UPDATE_CALLBACK,
+	NFS4CLNT_CLONED_CLIENT,
+	NFS4CLNT_MOVED,
 };
 
 enum nfs4_session_state {
@@ -348,6 +350,7 @@ extern void nfs4_close_state(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
+extern void nfs4_schedule_migration_recovery(struct nfs_server *);
 extern void nfs4_schedule_state_manager(struct nfs_client *);
 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
fs/nfs/nfs4state.c +147 -2

229 lines not on this page · raw message

include/linux/nfs_fs_sb.h +3 -0
index d0554c4..091abf0 100644
@@ -58,6 +58,9 @@ struct nfs_client {
 
 	struct rpc_wait_queue	cl_rpcwaitq;
 
+	/* accessed only when NFS4CLNT_MOVED bit is set */
+	struct nfs_server *	cl_moved_server;
+
 	/* used for the setclientid verifier */
 	struct timespec		cl_boot_time;
 
#16 lore raw

PATCH 14/16 NFS: Remove "const" from "struct nfs_server *" fields

In reply to Chuck Lever

We're about to pass the nfs_server pointer in some NFSv4 argument and result structures to functions that may change it, so it's no longer "const".

The preference here is to maintain existing whitespace style rather than answer all the nits called out by checkpatch.pl.

---

 fs/nfs/nfs4proc.c       |    2 +-
 include/linux/nfs_xdr.h |   28 ++++++++++++++--------------
 2 files changed, 15 insertions(+), 15 deletions(-)
fs/nfs/nfs4proc.c +1 -1
index bb6b128..1168bb2 100644
@@ -4027,7 +4027,7 @@ struct nfs4_unlockdata {
 	struct nfs4_lock_state *lsp;
 	struct nfs_open_context *ctx;
 	struct file_lock fl;
-	const struct nfs_server *server;
+	struct nfs_server *server;
 	unsigned long timestamp;
 };
 
include/linux/nfs_xdr.h +14 -14
index 22e34d3..ab17345 100644
@@ -288,7 +288,7 @@ struct nfs_openargs {
 		fmode_t		delegation_type;	/* CLAIM_PREVIOUS */
 	} u;
 	const struct qstr *	name;
-	const struct nfs_server *server;	 /* Needed for ID mapping */
+	struct nfs_server *	server;		/* Needed for ID mapping */
 	const u32 *		bitmask;
 	__u32			claim;
 	struct nfs4_sequence_args	seq_args;
@@ -302,7 +302,7 @@ struct nfs_openres {
 	struct nfs_fattr *      f_attr;
 	struct nfs_fattr *      dir_attr;
 	struct nfs_seqid *	seqid;
-	const struct nfs_server *server;
+	struct nfs_server *	server;
 	fmode_t			delegation_type;
 	nfs4_stateid		delegation;
 	__u32			do_recall;
@@ -341,7 +341,7 @@ struct nfs_closeres {
 	nfs4_stateid            stateid;
 	struct nfs_fattr *	fattr;
 	struct nfs_seqid *	seqid;
-	const struct nfs_server *server;
+	struct nfs_server *	server;
 	struct nfs4_sequence_res	seq_res;
 };
 /*
@@ -413,7 +413,7 @@ struct nfs4_delegreturnargs {
 
 struct nfs4_delegreturnres {
 	struct nfs_fattr * fattr;
-	const struct nfs_server *server;
+	struct nfs_server * server;
 	struct nfs4_sequence_res	seq_res;
 };
 
@@ -463,7 +463,7 @@ struct nfs_writeres {
 	struct nfs_fattr *	fattr;
 	struct nfs_writeverf *	verf;
 	__u32			count;
-	const struct nfs_server *server;
+	struct nfs_server *	server;
 	struct nfs4_sequence_res	seq_res;
 };
 
@@ -478,7 +478,7 @@ struct nfs_removeargs {
 };
 
 struct nfs_removeres {
-	const struct nfs_server *server;
+	struct nfs_server	*server;
 	struct nfs_fattr	*dir_attr;
 	struct nfs4_change_info	cinfo;
 	struct nfs4_sequence_res 	seq_res;
@@ -497,7 +497,7 @@ struct nfs_renameargs {
 };
 
 struct nfs_renameres {
-	const struct nfs_server		*server;
+	struct nfs_server		*server;
 	struct nfs4_change_info		old_cinfo;
 	struct nfs_fattr		*old_fattr;
 	struct nfs4_change_info		new_cinfo;
@@ -578,7 +578,7 @@ struct nfs_getaclres {
 
 struct nfs_setattrres {
 	struct nfs_fattr *              fattr;
-	const struct nfs_server *	server;
+	struct nfs_server *		server;
 	struct nfs4_sequence_res	seq_res;
 };
 
@@ -751,7 +751,7 @@ struct nfs4_accessargs {
 };
 
 struct nfs4_accessres {
-	const struct nfs_server *	server;
+	struct nfs_server *		server;
 	struct nfs_fattr *		fattr;
 	u32				supported;
 	u32				access;
@@ -779,7 +779,7 @@ struct nfs4_create_arg {
 };
 
 struct nfs4_create_res {
-	const struct nfs_server *	server;
+	struct nfs_server *		server;
 	struct nfs_fh *			fh;
 	struct nfs_fattr *		fattr;
 	struct nfs4_change_info		dir_cinfo;
@@ -805,7 +805,7 @@ struct nfs4_getattr_arg {
 };
 
 struct nfs4_getattr_res {
-	const struct nfs_server *	server;
+	struct nfs_server *		server;
 	struct nfs_fattr *		fattr;
 	struct nfs4_sequence_res	seq_res;
 };
@@ -819,7 +819,7 @@ struct nfs4_link_arg {
 };
 
 struct nfs4_link_res {
-	const struct nfs_server *	server;
+	struct nfs_server *		server;
 	struct nfs_fattr *		fattr;
 	struct nfs4_change_info		cinfo;
 	struct nfs_fattr *		dir_attr;
@@ -835,7 +835,7 @@ struct nfs4_lookup_arg {
 };
 
 struct nfs4_lookup_res {
-	const struct nfs_server *	server;
+	struct nfs_server *		server;
 	struct nfs_fattr *		fattr;
 	struct nfs_fh *			fh;
 	struct nfs4_sequence_res	seq_res;
@@ -950,7 +950,7 @@ struct nfs4_fs_location {
 #define NFS4_FS_LOCATIONS_MAXENTRIES 10
 struct nfs4_fs_locations {
 	struct nfs_fattr fattr;
-	const struct nfs_server *server;
+	struct nfs_server *server;
 	struct nfs4_pathname fs_path;
 	int nlocations;
 	struct nfs4_fs_location locations[NFS4_FS_LOCATIONS_MAXENTRIES];
#17 lore raw

PATCH 15/16 NFS: Add migration recovery callouts in nfs4proc.c

In reply to Chuck Lever

Finally, to enable support for migration, insert migration recovery callouts in the synchronous and asynchronous error handling paths for NFSv4 procedures.

---

 fs/nfs/nfs4proc.c |   67 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 49 insertions(+), 18 deletions(-)
fs/nfs/nfs4proc.c +49 -18
index 1168bb2..a545d46 100644
@@ -72,10 +72,11 @@ struct nfs4_opendata;
 static int _nfs4_proc_open(struct nfs4_opendata *data);
 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
-static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
-static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir,
-			     const struct qstr *name, struct nfs_fh *fhandle,
-			     struct nfs_fattr *fattr);
+static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *,
+				struct nfs4_state *);
+static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
+		const struct qstr *name, struct nfs_fh *fhandle,
+		struct nfs_fattr *fattr);
 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
 			    struct nfs_fattr *fattr, struct iattr *sattr,
@@ -247,10 +248,17 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
 	return res;
 }
 
-/* This is the error handling routine for processes that are allowed
- * to sleep.
+/**
+ * nfs4_handle_exception - Common error handling for callers allowed to sleep
+ *
+ * @server: local state context for the server
+ * @errorcode: NFS4ERR value returned from the server
+ * @exception: exception handling state
+ *
+ * Returns zero on success, or a negative errno value.
  */
-static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
+static int nfs4_handle_exception(struct nfs_server *server, int errorcode,
+				 struct nfs4_exception *exception)
 {
 	struct nfs_client *clp = server->nfs_client;
 	struct nfs4_state *state = exception->state;
@@ -286,6 +294,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
 			exception->retry = 1;
 			break;
 #endif /* defined(CONFIG_NFS_V4_1) */
+		case -NFS4ERR_MOVED:
+			nfs4_schedule_migration_recovery(server);
+			goto wait_on_recovery;
 		case -NFS4ERR_FILE_OPEN:
 			if (exception->timeout > HZ) {
 				/* We have retried a decent amount, time to
@@ -2283,10 +2294,14 @@ static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct
 	status = nfs4_proc_fs_locations(dir, name, locations, page);
 	if (status != 0)
 		goto out;
-	/* Make sure server returned a different fsid for the referral */
+
+	/*
+	 * If the fsid didn't change, this is a migration event, not a
+	 * referral.  Cause us to drop into the exception handler, which
+	 * will kick off migration recovery.
+	 */
 	if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
-		dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
-		status = -EIO;
+		status = -NFS4ERR_MOVED;
 		goto out;
 	}
 
@@ -3655,8 +3670,18 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
 	return err;
 }
 
-static int
-nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
+/**
+ * nfs4_async_handle_error - Common error handling for callers who cannot sleep
+ *
+ * @task: active RPC task
+ * @server: local state for the server
+ * @state: NFSv4 state for active operation
+ *
+ * Returns zero on success, or a negative errno value.
+ */
+static int nfs4_async_handle_error(struct rpc_task *task,
+				   struct nfs_server *server,
+				   struct nfs4_state *state)
 {
 	struct nfs_client *clp = server->nfs_client;
 
@@ -3686,19 +3711,24 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
 			dprintk("%s ERROR %d, Reset session\n", __func__,
 				task->tk_status);
 			nfs4_schedule_session_recovery(clp->cl_session);
-			task->tk_status = 0;
-			return -EAGAIN;
+			goto restart_call;
 #endif /* CONFIG_NFS_V4_1 */
+		case -NFS4ERR_MOVED:
+			rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
+			nfs4_schedule_migration_recovery(server);
+			if (test_bit(NFS4CLNT_MANAGER_RUNNING,
+							&clp->cl_state) == 0)
+				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
+									task);
+			goto restart_call;
 		case -NFS4ERR_DELAY:
 			nfs_inc_server_stats(server, NFSIOS_DELAY);
 		case -NFS4ERR_GRACE:
 		case -EKEYEXPIRED:
 			rpc_delay(task, NFS4_POLL_RETRY_MAX);
-			task->tk_status = 0;
-			return -EAGAIN;
+			goto restart_call;
 		case -NFS4ERR_OLD_STATEID:
-			task->tk_status = 0;
-			return -EAGAIN;
+			goto restart_call;
 	}
 	task->tk_status = nfs4_map_errors(task->tk_status);
 	return 0;
@@ -3706,6 +3736,7 @@ wait_on_recovery:
 	rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
 	if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
 		rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
+restart_call:
 	task->tk_status = 0;
 	return -EAGAIN;
 }
#18 lore raw

PATCH 16/16 NFS: Implement support for NFS4ERR_LEASE_MOVED

In reply to Chuck Lever

To recover from NFS4ERR_LEASE_MOVED, walk the cl_superblocks list and invoke nfs4_try_migration() on each server's root file handle. nfs4_try_migration() should automatically determine whether that file system has migrated, and then perform recovery for it.

The per-filesystem migration probe also informs minor version zero servers that this client should no longer receive NFS4ERR_LEASE_MOVED.

---

 fs/nfs/client.c           |    1 +
 fs/nfs/nfs4_fs.h          |    2 +
 fs/nfs/nfs4proc.c         |   11 ++++++++
 fs/nfs/nfs4state.c        |   63 ++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/nfs_fs_sb.h |    2 +
 5 files changed, 77 insertions(+), 2 deletions(-)
fs/nfs/client.c +1 -0
index 2f5e29f..b89af4d 100644
@@ -188,6 +188,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	if (cl_init->long_clientid != NULL)
 		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
 							GFP_KERNEL);
+	clp->cl_mig_counter = 1;
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
fs/nfs/nfs4_fs.h +2 -0
index c3e8641..2ad6c9b 100644
@@ -51,6 +51,7 @@ enum nfs4_client_state {
 	NFS4CLNT_UPDATE_CALLBACK,
 	NFS4CLNT_CLONED_CLIENT,
 	NFS4CLNT_MOVED,
+	NFS4CLNT_LEASE_MOVED,
 };
 
 enum nfs4_session_state {
@@ -351,6 +352,7 @@ extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
 extern void nfs4_schedule_migration_recovery(struct nfs_server *);
+extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
 extern void nfs4_schedule_state_manager(struct nfs_client *);
 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
fs/nfs/nfs4proc.c +11 -0
index a545d46..f4e07ba 100644
@@ -297,6 +297,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode,
 		case -NFS4ERR_MOVED:
 			nfs4_schedule_migration_recovery(server);
 			goto wait_on_recovery;
+		case -NFS4ERR_LEASE_MOVED:
+			nfs4_schedule_lease_moved_recovery(clp);
+			goto wait_on_recovery;
 		case -NFS4ERR_FILE_OPEN:
 			if (exception->timeout > HZ) {
 				/* We have retried a decent amount, time to
@@ -3721,6 +3724,14 @@ static int nfs4_async_handle_error(struct rpc_task *task,
 				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
 									task);
 			goto restart_call;
+		case -NFS4ERR_LEASE_MOVED:
+			rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
+			nfs4_schedule_lease_moved_recovery(clp);
+			if (test_bit(NFS4CLNT_MANAGER_RUNNING,
+							&clp->cl_state) == 0)
+				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
+									task);
+			goto restart_call;
 		case -NFS4ERR_DELAY:
 			nfs_inc_server_stats(server, NFSIOS_DELAY);
 		case -NFS4ERR_GRACE:
fs/nfs/nfs4state.c +61 -2

87 lines not on this page · raw message

include/linux/nfs_fs_sb.h +2 -0
index 091abf0..58050db 100644
@@ -60,6 +60,7 @@ struct nfs_client {
 
 	/* accessed only when NFS4CLNT_MOVED bit is set */
 	struct nfs_server *	cl_moved_server;
+	unsigned long		cl_mig_counter;
 
 	/* used for the setclientid verifier */
 	struct timespec		cl_boot_time;
@@ -156,6 +157,7 @@ struct nfs_server {
 	struct list_head	delegations;
 	void (*destroy)(struct nfs_server *);
 	struct nfs_fh		*rootfh;
+	unsigned long		mig_counter;
 
 	atomic_t active; /* Keep trace of any activity to this server */
 
#19 lore raw

Re: [PATCH 16/16] NFS: Implement support for NFS4ERR_LEASE_MOVED

Quoted 7 lines · Chuck Lever

To recover from NFS4ERR_LEASE_MOVED, walk the cl_superblocks list and invoke nfs4_try_migration() on each server's root file handle. nfs4_try_migration() should automatically determine whether that file system has migrated, and then perform recovery for it.

The per-filesystem migration probe also informs minor version zero servers that this client should no longer receive NFS4ERR_LEASE_MOVED.

I see one thing that may be missing here.

RFC 3530, section 8.14.3, lists OPEN, CLOSE, READ, WRITE, RENEW, LOCK, LOCKU, and LOCKT as the only procedures that return NFS4ERR_LEASE_MOVED. A code audit suggests that handling NFS4ERR_LEASE_MOVED in the two generic error handlers in nfs4proc.c is sufficient for all of these but RENEW and OPEN.

RENEW is part of the lease_moved recovery logic, so I've left NFS4ERR_LEASE_MOVED handling there pretty sparse. The caller wants to deal with it.

OPEN, as far as I can tell, won't deal with it at all, at least not directly. Should we look for it in nfs4_open_done() and invoke nfs4_schedule_lease_moved_recovery()?

Quoted 191 lines

---

fs/nfs/client.c           |    1 +
fs/nfs/nfs4_fs.h          |    2 +
fs/nfs/nfs4proc.c         |   11 ++++++++
fs/nfs/nfs4state.c        |   63 ++++++++++++++++++++++++++++++++++++++++++++-
include/linux/nfs_fs_sb.h |    2 +
5 files changed, 77 insertions(+), 2 deletions(-)
fs/nfs/client.c +1 -0
index 2f5e29f..b89af4d 100644
@@ -188,6 +188,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	if (cl_init->long_clientid != NULL)
 		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
 							GFP_KERNEL);
+	clp->cl_mig_counter = 1;
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
fs/nfs/nfs4_fs.h +2 -0
index c3e8641..2ad6c9b 100644
@@ -51,6 +51,7 @@ enum nfs4_client_state {
 	NFS4CLNT_UPDATE_CALLBACK,
 	NFS4CLNT_CLONED_CLIENT,
 	NFS4CLNT_MOVED,
+	NFS4CLNT_LEASE_MOVED,
 };
 
 enum nfs4_session_state {
@@ -351,6 +352,7 @@ extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
 extern void nfs4_schedule_migration_recovery(struct nfs_server *);
+extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
 extern void nfs4_schedule_state_manager(struct nfs_client *);
 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
fs/nfs/nfs4proc.c +11 -0
index a545d46..f4e07ba 100644
@@ -297,6 +297,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode,
 		case -NFS4ERR_MOVED:
 			nfs4_schedule_migration_recovery(server);
 			goto wait_on_recovery;
+		case -NFS4ERR_LEASE_MOVED:
+			nfs4_schedule_lease_moved_recovery(clp);
+			goto wait_on_recovery;
 		case -NFS4ERR_FILE_OPEN:
 			if (exception->timeout > HZ) {
 				/* We have retried a decent amount, time to
@@ -3721,6 +3724,14 @@ static int nfs4_async_handle_error(struct rpc_task *task,
 				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
 									task);
 			goto restart_call;
+		case -NFS4ERR_LEASE_MOVED:
+			rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
+			nfs4_schedule_lease_moved_recovery(clp);
+			if (test_bit(NFS4CLNT_MANAGER_RUNNING,
+							&clp->cl_state) == 0)
+				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
+									task);
+			goto restart_call;
 		case -NFS4ERR_DELAY:
 			nfs_inc_server_stats(server, NFSIOS_DELAY);
 		case -NFS4ERR_GRACE:
fs/nfs/nfs4state.c +61 -2
index c7b414a..8bef9d8 100644
@@ -1071,7 +1071,32 @@ void nfs4_schedule_migration_recovery(struct nfs_server *server)
 	dprintk("<-- %s\n", __func__);
 }
 
-static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
+/**
+ * nfs4_schedule_lease_moved_recovery - start lease moved recovery
+ *
+ * @clp: nfs_client of server that may have migrated file systems
+ *
+ */
+void nfs4_schedule_lease_moved_recovery(struct nfs_client *clp)
+{
+	dprintk("--> %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	if (test_and_set_bit(NFS4CLNT_LEASE_MOVED, &clp->cl_state) == 0)
+		nfs4_schedule_state_manager(clp);
+
+	dprintk("<-- %s\n", __func__);
+}
+
+/**
+ * nfs4_state_mark_reclaim_reboot - Mark nfs_client for reboot recovery
+ * @clp: nfs_client of server that may have rebooted
+ * @state: state flags to test
+ *
+ * Returns 1 if reboot recovery is needed.
+ */
+int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp,
+				   struct nfs4_state *state)
 {
 
 	set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
@@ -1384,7 +1409,6 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
 			nfs4_state_end_reclaim_reboot(clp);
 			return 0;
 		case -NFS4ERR_STALE_CLIENTID:
-		case -NFS4ERR_LEASE_MOVED:
 			set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
 			nfs4_state_clear_reclaim_reboot(clp);
 			nfs4_state_start_reclaim_reboot(clp);
@@ -1597,6 +1621,37 @@ out_err:
 	kfree(locations);
 }
 
+static void nfs4_handle_lease_moved(struct nfs_client *clp)
+{
+	struct nfs_server *server;
+
+	dprintk("--> %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	/*
+	 * rcu_read_lock() must be dropped before trying each individual
+	 * migration.  cl_mig_counter is used to skip servers that have
+	 * already been visited for this lease_moved event when the list
+	 * walk is restarted.
+	 */
+	clp->cl_mig_counter++;
+
+restart:
+	rcu_read_lock();
+	list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
+		if (server->mig_counter != clp->cl_mig_counter) {
+			server->mig_counter = clp->cl_mig_counter;
+			rcu_read_unlock();
+			nfs4_try_migration(server);
+			/* Ask the server if there's more work to do */
+			if (nfs4_check_lease(clp) == NFS4ERR_LEASE_MOVED)
+				goto restart;
+			break;
+		}
+	rcu_read_unlock();
+	dprintk("<-- %s\n", __func__);
+}
+
 #ifdef CONFIG_NFS_V4_1
 void nfs4_schedule_session_recovery(struct nfs4_session *session)
 {
@@ -1814,6 +1869,10 @@ static void nfs4_state_manager(struct nfs_client *clp)
 			nfs4_try_migration(clp->cl_moved_server);
 			continue;
 		}
+		if (test_and_clear_bit(NFS4CLNT_LEASE_MOVED, &clp->cl_state)) {
+			nfs4_handle_lease_moved(clp);
+			continue;
+		}
 
 		/* First recover reboot state... */
 		if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
include/linux/nfs_fs_sb.h +2 -1
index 091abf0..58050db 100644
@@ -60,6 +60,7 @@ struct nfs_client {
 
 	/* accessed only when NFS4CLNT_MOVED bit is set */
 	struct nfs_server *	cl_moved_server;
+	unsigned long		cl_mig_counter;
 
 	/* used for the setclientid verifier */
 	struct timespec		cl_boot_time;
@@ -156,6 +157,7 @@ struct nfs_server {
 	struct list_head	delegations;
 	void (*destroy)(struct nfs_server *);
 	struct nfs_fh		*rootfh;
+	unsigned long		mig_counter;
 
 	atomic_t active; /* Keep trace of any activity to this server */
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#20 lore raw

Re: [PATCH 16/16] NFS: Implement support for NFS4ERR_LEASE_MOVED

Quoted 7 lines · Chuck Lever
Quoted 5 lines · Chuck Lever

To recover from NFS4ERR_LEASE_MOVED, walk the cl_superblocks list and invoke nfs4_try_migration() on each server's root file handle. nfs4_try_migration() should automatically determine whether that file system has migrated, and then perform recovery for it.

Quoted 5 lines
Quoted 2 lines

The per-filesystem migration probe also informs minor version zero servers that this client should no longer receive NFS4ERR_LEASE_MOVED.

I see one thing that may be missing here.

RFC 3530, section 8.14.3, lists OPEN, CLOSE, READ, WRITE, RENEW, LOCK, LOCKU, and LOCKT as the only procedures that return NFS4ERR_LEASE_MOVED. A code audit suggests that handling NFS4ERR_LEASE_MOVED in the two generic error handlers in nfs4proc.c is sufficient for all of these but RENEW and OPEN.

3503bis, section 13.4:

   | NFS4ERR_LEASE_MOVED      | CLOSE, DELEGPURGE, DELEGRETURN, LOCK,  |
   |                          | LOCKT, LOCKU, OPEN_CONFIRM,            |
   |                          | OPEN_DOWNGRADE, READ,                  |
   |                          | RELEASE_LOCKOWNER, RENEW, SETATTR,     |
   |                          | WRITE                                  |

And the equivalent text as to what is in 3530 is section 9.14.3:

To accomplish this, all
operations which implicitly renew leases for a client (such as OPEN, CLOSE, READ, WRITE, RENEW, LOCK, and others), will return the error NFS4ERR_LEASE_MOVED if responsibility for any of the leases to be renewed has been transferred to a new server.

Quoted 195 lines

RENEW is part of the lease_moved recovery logic, so I've left NFS4ERR_LEASE_MOVED handling there pretty sparse. The caller wants to deal with it.

OPEN, as far as I can tell, won't deal with it at all, at least not directly. Should we look for it in nfs4_open_done() and invoke nfs4_schedule_lease_moved_recovery()?

Quoted 191 lines

---

fs/nfs/client.c           |    1 +
fs/nfs/nfs4_fs.h          |    2 +
fs/nfs/nfs4proc.c         |   11 ++++++++
fs/nfs/nfs4state.c        |   63 ++++++++++++++++++++++++++++++++++++++++++++-
include/linux/nfs_fs_sb.h |    2 +
5 files changed, 77 insertions(+), 2 deletions(-)
fs/nfs/client.c +1 -0
index 2f5e29f..b89af4d 100644
@@ -188,6 +188,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	if (cl_init->long_clientid != NULL)
 		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
 							GFP_KERNEL);
+	clp->cl_mig_counter = 1;
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
fs/nfs/nfs4_fs.h +2 -0
index c3e8641..2ad6c9b 100644
@@ -51,6 +51,7 @@ enum nfs4_client_state {
 	NFS4CLNT_UPDATE_CALLBACK,
 	NFS4CLNT_CLONED_CLIENT,
 	NFS4CLNT_MOVED,
+	NFS4CLNT_LEASE_MOVED,
 };
 
 enum nfs4_session_state {
@@ -351,6 +352,7 @@ extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
 extern void nfs4_schedule_migration_recovery(struct nfs_server *);
+extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
 extern void nfs4_schedule_state_manager(struct nfs_client *);
 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
fs/nfs/nfs4proc.c +11 -0
index a545d46..f4e07ba 100644
@@ -297,6 +297,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode,
 		case -NFS4ERR_MOVED:
 			nfs4_schedule_migration_recovery(server);
 			goto wait_on_recovery;
+		case -NFS4ERR_LEASE_MOVED:
+			nfs4_schedule_lease_moved_recovery(clp);
+			goto wait_on_recovery;
 		case -NFS4ERR_FILE_OPEN:
 			if (exception->timeout>  HZ) {
 				/* We have retried a decent amount, time to
@@ -3721,6 +3724,14 @@ static int nfs4_async_handle_error(struct rpc_task *task,
 				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
 									task);
 			goto restart_call;
+		case -NFS4ERR_LEASE_MOVED:
+			rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
+			nfs4_schedule_lease_moved_recovery(clp);
+			if (test_bit(NFS4CLNT_MANAGER_RUNNING,
+							&clp->cl_state) == 0)
+				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
+									task);
+			goto restart_call;
 		case -NFS4ERR_DELAY:
 			nfs_inc_server_stats(server, NFSIOS_DELAY);
 		case -NFS4ERR_GRACE:
fs/nfs/nfs4state.c +61 -2
index c7b414a..8bef9d8 100644
@@ -1071,7 +1071,32 @@ void nfs4_schedule_migration_recovery(struct nfs_server *server)
 	dprintk("<-- %s\n", __func__);
 }
 
-static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
+/**
+ * nfs4_schedule_lease_moved_recovery - start lease moved recovery
+ *
+ * @clp: nfs_client of server that may have migrated file systems
+ *
+ */
+void nfs4_schedule_lease_moved_recovery(struct nfs_client *clp)
+{
+	dprintk("-->  %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	if (test_and_set_bit(NFS4CLNT_LEASE_MOVED,&clp->cl_state) == 0)
+		nfs4_schedule_state_manager(clp);
+
+	dprintk("<-- %s\n", __func__);
+}
+
+/**
+ * nfs4_state_mark_reclaim_reboot - Mark nfs_client for reboot recovery
+ * @clp: nfs_client of server that may have rebooted
+ * @state: state flags to test
+ *
+ * Returns 1 if reboot recovery is needed.
+ */
+int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp,
+				   struct nfs4_state *state)
 {
 
 	set_bit(NFS_STATE_RECLAIM_REBOOT,&state->flags);
@@ -1384,7 +1409,6 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
 			nfs4_state_end_reclaim_reboot(clp);
 			return 0;
 		case -NFS4ERR_STALE_CLIENTID:
-		case -NFS4ERR_LEASE_MOVED:
 			set_bit(NFS4CLNT_LEASE_EXPIRED,&clp->cl_state);
 			nfs4_state_clear_reclaim_reboot(clp);
 			nfs4_state_start_reclaim_reboot(clp);
@@ -1597,6 +1621,37 @@ out_err:
 	kfree(locations);
 }
 
+static void nfs4_handle_lease_moved(struct nfs_client *clp)
+{
+	struct nfs_server *server;
+
+	dprintk("-->  %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	/*
+	 * rcu_read_lock() must be dropped before trying each individual
+	 * migration.  cl_mig_counter is used to skip servers that have
+	 * already been visited for this lease_moved event when the list
+	 * walk is restarted.
+	 */
+	clp->cl_mig_counter++;
+
+restart:
+	rcu_read_lock();
+	list_for_each_entry_rcu(server,&clp->cl_superblocks, client_link)
+		if (server->mig_counter != clp->cl_mig_counter) {
+			server->mig_counter = clp->cl_mig_counter;
+			rcu_read_unlock();
+			nfs4_try_migration(server);
+			/* Ask the server if there's more work to do */
+			if (nfs4_check_lease(clp) == NFS4ERR_LEASE_MOVED)
+				goto restart;
+			break;
+		}
+	rcu_read_unlock();
+	dprintk("<-- %s\n", __func__);
+}
+
 #ifdef CONFIG_NFS_V4_1
 void nfs4_schedule_session_recovery(struct nfs4_session *session)
 {
@@ -1814,6 +1869,10 @@ static void nfs4_state_manager(struct nfs_client *clp)
 			nfs4_try_migration(clp->cl_moved_server);
 			continue;
 		}
+		if (test_and_clear_bit(NFS4CLNT_LEASE_MOVED,&clp->cl_state)) {
+			nfs4_handle_lease_moved(clp);
+			continue;
+		}
 
 		/* First recover reboot state... */
 		if (test_bit(NFS4CLNT_RECLAIM_REBOOT,&clp->cl_state)) {
include/linux/nfs_fs_sb.h +2 -1
index 091abf0..58050db 100644
@@ -60,6 +60,7 @@ struct nfs_client {
 
 	/* accessed only when NFS4CLNT_MOVED bit is set */
 	struct nfs_server *	cl_moved_server;
+	unsigned long		cl_mig_counter;
 
 	/* used for the setclientid verifier */
 	struct timespec		cl_boot_time;
@@ -156,6 +157,7 @@ struct nfs_server {
 	struct list_head	delegations;
 	void (*destroy)(struct nfs_server *);
 	struct nfs_fh		*rootfh;
+	unsigned long		mig_counter;
 
 	atomic_t active; /* Keep trace of any activity to this server */
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#22 lore raw

Re: [PATCH 16/16] NFS: Implement support for NFS4ERR_LEASE_MOVED

Quoted 22 lines · Tom Haynes
Quoted 7 lines · Chuck Lever
Quoted 5 lines · Chuck Lever

To recover from NFS4ERR_LEASE_MOVED, walk the cl_superblocks list and invoke nfs4_try_migration() on each server's root file handle. nfs4_try_migration() should automatically determine whether that file system has migrated, and then perform recovery for it.

Quoted 5 lines
Quoted 2 lines

The per-filesystem migration probe also informs minor version zero servers that this client should no longer receive NFS4ERR_LEASE_MOVED.

I see one thing that may be missing here.

RFC 3530, section 8.14.3, lists OPEN, CLOSE, READ, WRITE, RENEW, LOCK, LOCKU, and LOCKT as the only procedures that return NFS4ERR_LEASE_MOVED. A code audit suggests that handling NFS4ERR_LEASE_MOVED in the two generic error handlers in nfs4proc.c is sufficient for all of these but RENEW and OPEN.

3503bis, section 13.4:

  | NFS4ERR_LEASE_MOVED      | CLOSE, DELEGPURGE, DELEGRETURN, LOCK,  |
  |                          | LOCKT, LOCKU, OPEN_CONFIRM,            |
  |                          | OPEN_DOWNGRADE, READ,                  |
  |                          | RELEASE_LOCKOWNER, RENEW, SETATTR,     |
  |                          | WRITE                                  |
Quoted 7 lines

And the equivalent text as to what is in 3530 is section 9.14.3:

To accomplish this, all
operations which implicitly renew leases for a client (such as OPEN, CLOSE, READ, WRITE, RENEW, LOCK, and others), will return the error NFS4ERR_LEASE_MOVED if responsibility for any of the leases to be renewed has been transferred to a new server.

Thanks, will take a look (and refresh my copy of 3530... oops).

Quoted 200 lines
Quoted 199 lines

RENEW is part of the lease_moved recovery logic, so I've left NFS4ERR_LEASE_MOVED handling there pretty sparse. The caller wants to deal with it.

OPEN, as far as I can tell, won't deal with it at all, at least not directly. Should we look for it in nfs4_open_done() and invoke nfs4_schedule_lease_moved_recovery()?

Quoted 191 lines

---

fs/nfs/client.c           |    1 +
fs/nfs/nfs4_fs.h          |    2 +
fs/nfs/nfs4proc.c         |   11 ++++++++
fs/nfs/nfs4state.c        |   63 ++++++++++++++++++++++++++++++++++++++++++++-
include/linux/nfs_fs_sb.h |    2 +
5 files changed, 77 insertions(+), 2 deletions(-)
fs/nfs/client.c +1 -0
index 2f5e29f..b89af4d 100644
@@ -188,6 +188,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	if (cl_init->long_clientid != NULL)
 		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
 							GFP_KERNEL);
+	clp->cl_mig_counter = 1;
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
fs/nfs/nfs4_fs.h +2 -0
index c3e8641..2ad6c9b 100644
@@ -51,6 +51,7 @@ enum nfs4_client_state {
 	NFS4CLNT_UPDATE_CALLBACK,
 	NFS4CLNT_CLONED_CLIENT,
 	NFS4CLNT_MOVED,
+	NFS4CLNT_LEASE_MOVED,
 };
 
 enum nfs4_session_state {
@@ -351,6 +352,7 @@ extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
 extern void nfs4_schedule_migration_recovery(struct nfs_server *);
+extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
 extern void nfs4_schedule_state_manager(struct nfs_client *);
 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
fs/nfs/nfs4proc.c +11 -0
index a545d46..f4e07ba 100644
@@ -297,6 +297,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode,
 		case -NFS4ERR_MOVED:
 			nfs4_schedule_migration_recovery(server);
 			goto wait_on_recovery;
+		case -NFS4ERR_LEASE_MOVED:
+			nfs4_schedule_lease_moved_recovery(clp);
+			goto wait_on_recovery;
 		case -NFS4ERR_FILE_OPEN:
 			if (exception->timeout>  HZ) {
 				/* We have retried a decent amount, time to
@@ -3721,6 +3724,14 @@ static int nfs4_async_handle_error(struct rpc_task *task,
 				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
 									task);
 			goto restart_call;
+		case -NFS4ERR_LEASE_MOVED:
+			rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
+			nfs4_schedule_lease_moved_recovery(clp);
+			if (test_bit(NFS4CLNT_MANAGER_RUNNING,
+							&clp->cl_state) == 0)
+				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
+									task);
+			goto restart_call;
 		case -NFS4ERR_DELAY:
 			nfs_inc_server_stats(server, NFSIOS_DELAY);
 		case -NFS4ERR_GRACE:
fs/nfs/nfs4state.c +61 -2
index c7b414a..8bef9d8 100644
@@ -1071,7 +1071,32 @@ void nfs4_schedule_migration_recovery(struct nfs_server *server)
 	dprintk("<-- %s\n", __func__);
 }
 
-static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
+/**
+ * nfs4_schedule_lease_moved_recovery - start lease moved recovery
+ *
+ * @clp: nfs_client of server that may have migrated file systems
+ *
+ */
+void nfs4_schedule_lease_moved_recovery(struct nfs_client *clp)
+{
+	dprintk("-->  %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	if (test_and_set_bit(NFS4CLNT_LEASE_MOVED,&clp->cl_state) == 0)
+		nfs4_schedule_state_manager(clp);
+
+	dprintk("<-- %s\n", __func__);
+}
+
+/**
+ * nfs4_state_mark_reclaim_reboot - Mark nfs_client for reboot recovery
+ * @clp: nfs_client of server that may have rebooted
+ * @state: state flags to test
+ *
+ * Returns 1 if reboot recovery is needed.
+ */
+int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp,
+				   struct nfs4_state *state)
 {
 
 	set_bit(NFS_STATE_RECLAIM_REBOOT,&state->flags);
@@ -1384,7 +1409,6 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
 			nfs4_state_end_reclaim_reboot(clp);
 			return 0;
 		case -NFS4ERR_STALE_CLIENTID:
-		case -NFS4ERR_LEASE_MOVED:
 			set_bit(NFS4CLNT_LEASE_EXPIRED,&clp->cl_state);
 			nfs4_state_clear_reclaim_reboot(clp);
 			nfs4_state_start_reclaim_reboot(clp);
@@ -1597,6 +1621,37 @@ out_err:
 	kfree(locations);
 }
 
+static void nfs4_handle_lease_moved(struct nfs_client *clp)
+{
+	struct nfs_server *server;
+
+	dprintk("-->  %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	/*
+	 * rcu_read_lock() must be dropped before trying each individual
+	 * migration.  cl_mig_counter is used to skip servers that have
+	 * already been visited for this lease_moved event when the list
+	 * walk is restarted.
+	 */
+	clp->cl_mig_counter++;
+
+restart:
+	rcu_read_lock();
+	list_for_each_entry_rcu(server,&clp->cl_superblocks, client_link)
+		if (server->mig_counter != clp->cl_mig_counter) {
+			server->mig_counter = clp->cl_mig_counter;
+			rcu_read_unlock();
+			nfs4_try_migration(server);
+			/* Ask the server if there's more work to do */
+			if (nfs4_check_lease(clp) == NFS4ERR_LEASE_MOVED)
+				goto restart;
+			break;
+		}
+	rcu_read_unlock();
+	dprintk("<-- %s\n", __func__);
+}
+
 #ifdef CONFIG_NFS_V4_1
 void nfs4_schedule_session_recovery(struct nfs4_session *session)
 {
@@ -1814,6 +1869,10 @@ static void nfs4_state_manager(struct nfs_client *clp)
 			nfs4_try_migration(clp->cl_moved_server);
 			continue;
 		}
+		if (test_and_clear_bit(NFS4CLNT_LEASE_MOVED,&clp->cl_state)) {
+			nfs4_handle_lease_moved(clp);
+			continue;
+		}
 
 		/* First recover reboot state... */
 		if (test_bit(NFS4CLNT_RECLAIM_REBOOT,&clp->cl_state)) {
include/linux/nfs_fs_sb.h +2 -1
index 091abf0..58050db 100644
@@ -60,6 +60,7 @@ struct nfs_client {
 
 	/* accessed only when NFS4CLNT_MOVED bit is set */
 	struct nfs_server *	cl_moved_server;
+	unsigned long		cl_mig_counter;
 
 	/* used for the setclientid verifier */
 	struct timespec		cl_boot_time;
@@ -156,6 +157,7 @@ struct nfs_server {
 	struct list_head	delegations;
 	void (*destroy)(struct nfs_server *);
 	struct nfs_fh		*rootfh;
+	unsigned long		mig_counter;
 
 	atomic_t active; /* Keep trace of any activity to this server */
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#23 lore raw

Re: [PATCH 16/16] NFS: Implement support for NFS4ERR_LEASE_MOVED

In reply to Tom Haynes
Quoted 22 lines · Tom Haynes
Quoted 7 lines · Chuck Lever
Quoted 5 lines · Chuck Lever

To recover from NFS4ERR_LEASE_MOVED, walk the cl_superblocks list and invoke nfs4_try_migration() on each server's root file handle. nfs4_try_migration() should automatically determine whether that file system has migrated, and then perform recovery for it.

Quoted 5 lines
Quoted 2 lines

The per-filesystem migration probe also informs minor version zero servers that this client should no longer receive NFS4ERR_LEASE_MOVED.

I see one thing that may be missing here.

RFC 3530, section 8.14.3, lists OPEN, CLOSE, READ, WRITE, RENEW, LOCK, LOCKU, and LOCKT as the only procedures that return NFS4ERR_LEASE_MOVED. A code audit suggests that handling NFS4ERR_LEASE_MOVED in the two generic error handlers in nfs4proc.c is sufficient for all of these but RENEW and OPEN.

3503bis, section 13.4:

  | NFS4ERR_LEASE_MOVED      | CLOSE, DELEGPURGE, DELEGRETURN, LOCK,  |
  |                          | LOCKT, LOCKU, OPEN_CONFIRM,            |
  |                          | OPEN_DOWNGRADE, READ,                  |
  |                          | RELEASE_LOCKOWNER, RENEW, SETATTR,     |
  |                          | WRITE                                  |
Quoted 7 lines

And the equivalent text as to what is in 3530 is section 9.14.3:

To accomplish this, all
operations which implicitly renew leases for a client (such as OPEN, CLOSE, READ, WRITE, RENEW, LOCK, and others), will return the error NFS4ERR_LEASE_MOVED if responsibility for any of the leases to be renewed has been transferred to a new server.

DELEGPURGE doesn't appear to be implemented.

DELEGRETURN uses nfs4_handle_exception(), so it's covered.

OPEN_CONFIRM is in the same boat as OPEN. Error handling is ad hoc, both MOVED and LEASE_MOVED are ignored.

OPEN_DOWNGRADE is done only during close processing, and the returned status code is ignored.

RELEASE_LOCKOWNER ignores the returned status code. It's entirely asynchronous. This is probably OK to leave alone.

SETATTR uses nfs4_handle_exception(), so it's covered.

So we have OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE to consider.

Quoted 196 lines
Quoted 195 lines

RENEW is part of the lease_moved recovery logic, so I've left NFS4ERR_LEASE_MOVED handling there pretty sparse. The caller wants to deal with it.

OPEN, as far as I can tell, won't deal with it at all, at least not directly. Should we look for it in nfs4_open_done() and invoke nfs4_schedule_lease_moved_recovery()?

Quoted 191 lines

---

fs/nfs/client.c           |    1 +
fs/nfs/nfs4_fs.h          |    2 +
fs/nfs/nfs4proc.c         |   11 ++++++++
fs/nfs/nfs4state.c        |   63 ++++++++++++++++++++++++++++++++++++++++++++-
include/linux/nfs_fs_sb.h |    2 +
5 files changed, 77 insertions(+), 2 deletions(-)
fs/nfs/client.c +1 -0
index 2f5e29f..b89af4d 100644
@@ -188,6 +188,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
 	if (cl_init->long_clientid != NULL)
 		clp->cl_cached_clientid = kstrdup(cl_init->long_clientid,
 							GFP_KERNEL);
+	clp->cl_mig_counter = 1;
 #endif
 	cred = rpc_lookup_machine_cred();
 	if (!IS_ERR(cred))
fs/nfs/nfs4_fs.h +2 -0
index c3e8641..2ad6c9b 100644
@@ -51,6 +51,7 @@ enum nfs4_client_state {
 	NFS4CLNT_UPDATE_CALLBACK,
 	NFS4CLNT_CLONED_CLIENT,
 	NFS4CLNT_MOVED,
+	NFS4CLNT_LEASE_MOVED,
 };
 
 enum nfs4_session_state {
@@ -351,6 +352,7 @@ extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
 extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
 extern void nfs4_schedule_lease_recovery(struct nfs_client *);
 extern void nfs4_schedule_migration_recovery(struct nfs_server *);
+extern void nfs4_schedule_lease_moved_recovery(struct nfs_client *);
 extern void nfs4_schedule_state_manager(struct nfs_client *);
 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
fs/nfs/nfs4proc.c +11 -0
index a545d46..f4e07ba 100644
@@ -297,6 +297,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode,
 		case -NFS4ERR_MOVED:
 			nfs4_schedule_migration_recovery(server);
 			goto wait_on_recovery;
+		case -NFS4ERR_LEASE_MOVED:
+			nfs4_schedule_lease_moved_recovery(clp);
+			goto wait_on_recovery;
 		case -NFS4ERR_FILE_OPEN:
 			if (exception->timeout>  HZ) {
 				/* We have retried a decent amount, time to
@@ -3721,6 +3724,14 @@ static int nfs4_async_handle_error(struct rpc_task *task,
 				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
 									task);
 			goto restart_call;
+		case -NFS4ERR_LEASE_MOVED:
+			rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
+			nfs4_schedule_lease_moved_recovery(clp);
+			if (test_bit(NFS4CLNT_MANAGER_RUNNING,
+							&clp->cl_state) == 0)
+				rpc_wake_up_queued_task(&clp->cl_rpcwaitq,
+									task);
+			goto restart_call;
 		case -NFS4ERR_DELAY:
 			nfs_inc_server_stats(server, NFSIOS_DELAY);
 		case -NFS4ERR_GRACE:
fs/nfs/nfs4state.c +61 -2
index c7b414a..8bef9d8 100644
@@ -1071,7 +1071,32 @@ void nfs4_schedule_migration_recovery(struct nfs_server *server)
 	dprintk("<-- %s\n", __func__);
 }
 
-static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
+/**
+ * nfs4_schedule_lease_moved_recovery - start lease moved recovery
+ *
+ * @clp: nfs_client of server that may have migrated file systems
+ *
+ */
+void nfs4_schedule_lease_moved_recovery(struct nfs_client *clp)
+{
+	dprintk("-->  %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	if (test_and_set_bit(NFS4CLNT_LEASE_MOVED,&clp->cl_state) == 0)
+		nfs4_schedule_state_manager(clp);
+
+	dprintk("<-- %s\n", __func__);
+}
+
+/**
+ * nfs4_state_mark_reclaim_reboot - Mark nfs_client for reboot recovery
+ * @clp: nfs_client of server that may have rebooted
+ * @state: state flags to test
+ *
+ * Returns 1 if reboot recovery is needed.
+ */
+int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp,
+				   struct nfs4_state *state)
 {
 
 	set_bit(NFS_STATE_RECLAIM_REBOOT,&state->flags);
@@ -1384,7 +1409,6 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
 			nfs4_state_end_reclaim_reboot(clp);
 			return 0;
 		case -NFS4ERR_STALE_CLIENTID:
-		case -NFS4ERR_LEASE_MOVED:
 			set_bit(NFS4CLNT_LEASE_EXPIRED,&clp->cl_state);
 			nfs4_state_clear_reclaim_reboot(clp);
 			nfs4_state_start_reclaim_reboot(clp);
@@ -1597,6 +1621,37 @@ out_err:
 	kfree(locations);
 }
 
+static void nfs4_handle_lease_moved(struct nfs_client *clp)
+{
+	struct nfs_server *server;
+
+	dprintk("-->  %s: \"%s\" (client ID %llx)\n",
+		__func__, clp->cl_hostname, clp->cl_clientid);
+
+	/*
+	 * rcu_read_lock() must be dropped before trying each individual
+	 * migration.  cl_mig_counter is used to skip servers that have
+	 * already been visited for this lease_moved event when the list
+	 * walk is restarted.
+	 */
+	clp->cl_mig_counter++;
+
+restart:
+	rcu_read_lock();
+	list_for_each_entry_rcu(server,&clp->cl_superblocks, client_link)
+		if (server->mig_counter != clp->cl_mig_counter) {
+			server->mig_counter = clp->cl_mig_counter;
+			rcu_read_unlock();
+			nfs4_try_migration(server);
+			/* Ask the server if there's more work to do */
+			if (nfs4_check_lease(clp) == NFS4ERR_LEASE_MOVED)
+				goto restart;
+			break;
+		}
+	rcu_read_unlock();
+	dprintk("<-- %s\n", __func__);
+}
+
 #ifdef CONFIG_NFS_V4_1
 void nfs4_schedule_session_recovery(struct nfs4_session *session)
 {
@@ -1814,6 +1869,10 @@ static void nfs4_state_manager(struct nfs_client *clp)
 			nfs4_try_migration(clp->cl_moved_server);
 			continue;
 		}
+		if (test_and_clear_bit(NFS4CLNT_LEASE_MOVED,&clp->cl_state)) {
+			nfs4_handle_lease_moved(clp);
+			continue;
+		}
 
 		/* First recover reboot state... */
 		if (test_bit(NFS4CLNT_RECLAIM_REBOOT,&clp->cl_state)) {
include/linux/nfs_fs_sb.h +2 -1
index 091abf0..58050db 100644
@@ -60,6 +60,7 @@ struct nfs_client {
 
 	/* accessed only when NFS4CLNT_MOVED bit is set */
 	struct nfs_server *	cl_moved_server;
+	unsigned long		cl_mig_counter;
 
 	/* used for the setclientid verifier */
 	struct timespec		cl_boot_time;
@@ -156,6 +157,7 @@ struct nfs_server {
 	struct list_head	delegations;
 	void (*destroy)(struct nfs_server *);
 	struct nfs_fh		*rootfh;
+	unsigned long		mig_counter;
 
 	atomic_t active; /* Keep trace of any activity to this server */
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com