From: Chuck Lever <chuck.lever@oracle.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v1 15/19] NFS: Add basic migration support to state manager thread
Date: Fri, 12 Jul 2013 12:33:38 -0400 [thread overview]
Message-ID: <20130712163338.1444.23823.stgit@seurat.1015granger.net> (raw)
In-Reply-To: <20130712155303.1444.62697.stgit@seurat.1015granger.net>
Migration recovery and state recovery must be serialized, so handle
both in the state manager thread.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfs/nfs4_fs.h | 2
fs/nfs/nfs4client.c | 1
fs/nfs/nfs4state.c | 186 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/nfs_fs_sb.h | 6 +
4 files changed, 195 insertions(+)
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 66c34c4..6391b94 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -30,6 +30,7 @@ enum nfs4_client_state {
NFS4CLNT_PURGE_STATE,
NFS4CLNT_BIND_CONN_TO_SESSION,
NFS4CLNT_BLOCK_XPRT,
+ NFS4CLNT_MOVED,
};
#define NFS4_RENEW_TIMEOUT 0x01
@@ -348,6 +349,7 @@ extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
extern void nfs4_schedule_state_manager(struct nfs_client *);
extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
+extern int nfs4_schedule_migration_recovery(struct inode *);
extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
extern void nfs41_handle_server_scope(struct nfs_client *,
struct nfs41_server_scope **);
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index dadd118..5050349 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -76,6 +76,7 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init)
init_completion(&clp->cl_xpcomplete);
rpc_init_wait_queue(&clp->cl_xpwaitq, "NFSv4.0 xprt");
}
+ clp->cl_mig_gen = 1;
return clp;
error:
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index ae482b2..4757188 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1210,6 +1210,54 @@ void nfs4_schedule_lease_recovery(struct nfs_client *clp)
}
EXPORT_SYMBOL_GPL(nfs4_schedule_lease_recovery);
+/**
+ * nfs4_schedule_migration_recovery - trigger migration recovery
+ *
+ * @inode: file residing on FSID that is migrating
+ *
+ * Returns zero if recovery has started, otherwise a negative NFS4ERR
+ * value is returned.
+ */
+int nfs4_schedule_migration_recovery(struct inode *inode)
+{
+ struct nfs_server *server;
+ struct nfs_client *clp;
+
+ if (inode == NULL) {
+ pr_err("%s: no inode for migration recovery\n",
+ __func__);
+ WARN_ON(1);
+ return -NFS4ERR_IO;
+ }
+ server = NFS_SERVER(inode);
+ clp = server->nfs_client;
+
+ if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags) == 0) {
+ pr_err("NFS: migration not supported (server %s)\n",
+ clp->cl_hostname);
+ return -NFS4ERR_IO;
+ }
+
+ if (server->fh_expire_type != NFS4_FH_PERSISTENT) {
+ pr_err("NFS: volatile file handles not supported (server %s)\n",
+ clp->cl_hostname);
+ return -NFS4ERR_IO;
+ }
+
+ dprintk("%s: scheduling migration recovery for (%llx:%llx) on %s\n",
+ __func__,
+ (unsigned long long)server->fsid.major,
+ (unsigned long long)server->fsid.minor,
+ clp->cl_hostname);
+
+ set_bit(NFS_MIG_IN_TRANSITION, &server->mig_status);
+ set_bit(NFS4CLNT_MOVED, &clp->cl_state);
+
+ nfs4_schedule_state_manager(clp);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(nfs4_schedule_migration_recovery);
+
int nfs4_wait_clnt_recover(struct nfs_client *clp)
{
int res;
@@ -1833,6 +1881,137 @@ static int nfs4_purge_lease(struct nfs_client *clp)
return 0;
}
+#ifdef CONFIG_NFS_V4_1
+static int nfs4_begin_drain(struct nfs_client *clp)
+{
+ if (clp->cl_session == NULL)
+ return nfs4_begin_drain_xprt(clp);
+ return nfs4_begin_drain_session(clp);
+}
+
+static void nfs4_end_drain(struct nfs_client *clp)
+{
+ if (clp->cl_session == NULL)
+ nfs4_end_drain_xprt(clp);
+ else
+ nfs4_end_drain_session(clp);
+}
+#else /* CONFIG_NFS_V4_1 */
+static int nfs4_begin_drain(struct nfs_client *clp)
+{
+ return nfs4_begin_drain_xprt(clp);
+}
+
+static void nfs4_end_drain(struct nfs_client *clp)
+{
+ nfs4_end_drain_xprt(clp);
+}
+#endif /* CONFIG_NFS_V4_1 */
+
+/*
+ * Try remote migration of one FSID from a source server to a
+ * destination server. The source server provides a list of
+ * potential destinations.
+ *
+ * Returns zero or a negative NFS4ERR status code.
+ */
+static int nfs4_try_migration(struct nfs_server *server)
+{
+ struct nfs_client *clp = server->nfs_client;
+ struct nfs4_fs_locations *locations = NULL;
+ struct inode *inode;
+ struct page *page;
+ int status, result;
+
+ dprintk("--> %s: FSID %llx:%llx on \"%s\"\n", __func__,
+ (unsigned long long)server->fsid.major,
+ (unsigned long long)server->fsid.minor,
+ clp->cl_hostname);
+
+ result = 0;
+ page = alloc_page(GFP_KERNEL);
+ locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
+ if (page == NULL || locations == NULL) {
+ dprintk("<-- %s: no memory\n", __func__);
+ goto out_err;
+ }
+
+ inode = server->super->s_root->d_inode;
+ result = nfs4_proc_get_locations(inode, locations, page);
+ if (result != NFS4_OK) {
+ dprintk("<-- %s: failed to retrieve fs_locations: %d\n",
+ __func__, result);
+ goto out_err;
+ }
+ if (!(locations->fattr.valid & NFS_ATTR_FATTR_V4_LOCATIONS)) {
+ dprintk("<-- %s: No fs_locations data available, "
+ "migration skipped\n", __func__);
+ goto out_err;
+ }
+
+ status = nfs4_begin_drain(clp);
+ if (status != 0) {
+ dprintk("<-- %s: failed to drain transport: %d\n",
+ __func__, status);
+ nfs4_end_drain(clp);
+ goto out_err;
+ }
+
+ status = nfs4_replace_transport(server, locations);
+ nfs4_end_drain(clp);
+ if (status != 0) {
+ dprintk("<-- %s: failed to replace transport: %d\n",
+ __func__, status);
+ goto out_err;
+ }
+
+ dprintk("<-- %s: migration succeeded\n", __func__);
+
+out_err:
+ if (page != NULL)
+ __free_page(page);
+ kfree(locations);
+ return result;
+}
+
+/*
+ * Returns zero or a negative NFS4ERR status code.
+ */
+static int nfs4_handle_migration(struct nfs_client *clp)
+{
+ struct nfs_server *server;
+
+ dprintk("--> %s: migration reported on \"%s\"\n", __func__,
+ clp->cl_hostname);
+
+ clp->cl_mig_gen++;
+restart:
+ rcu_read_lock();
+ list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
+ int status;
+
+ if (server->mig_gen == clp->cl_mig_gen)
+ continue;
+ server->mig_gen = clp->cl_mig_gen;
+
+ if (!test_and_clear_bit(NFS_MIG_IN_TRANSITION,
+ &server->mig_status))
+ continue;
+
+ rcu_read_unlock();
+ status = nfs4_try_migration(server);
+ if (status < 0) {
+ dprintk("<-- %s: %d\n", __func__, status);
+ return status;
+ }
+ goto restart;
+ }
+ rcu_read_unlock();
+
+ dprintk("<-- %s\n", __func__);
+ return 0;
+}
+
/**
* nfs4_discover_server_trunking - Detect server IP address trunking
*
@@ -2163,6 +2342,13 @@ static void nfs4_state_manager(struct nfs_client *clp)
status = nfs4_check_lease(clp);
if (status < 0)
goto out_error;
+ }
+
+ if (test_and_clear_bit(NFS4CLNT_MOVED, &clp->cl_state)) {
+ section = "migration";
+ status = nfs4_handle_migration(clp);
+ if (status < 0)
+ goto out_error;
continue;
}
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index 84d8f0c..4cfc58a 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -77,6 +77,7 @@ struct nfs_client {
char cl_ipaddr[48];
u32 cl_cb_ident; /* v4.0 callback identifier */
const struct nfs4_minor_version_ops *cl_mvops;
+ unsigned long cl_mig_gen;
atomic_t cl_xppending;
struct completion cl_xpcomplete;
@@ -174,6 +175,11 @@ struct nfs_server {
struct list_head state_owners_lru;
struct list_head layouts;
struct list_head delegations;
+
+ unsigned long mig_gen;
+ unsigned long mig_status;
+#define NFS_MIG_IN_TRANSITION (1)
+
void (*destroy)(struct nfs_server *);
atomic_t active; /* Keep trace of any activity to this server */
next prev parent reply other threads:[~2013-07-12 16:33 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 16:31 [PATCH v1 00/19] NFSv4 migration Chuck Lever
2013-07-12 16:31 ` [PATCH v1 01/19] NFS: Never use user credentials for lease renewal Chuck Lever
2013-07-22 18:33 ` Myklebust, Trond
2013-07-22 18:52 ` Chuck Lever
2013-07-22 18:53 ` Myklebust, Trond
2013-07-22 18:56 ` Chuck Lever
2013-07-12 16:31 ` [PATCH v1 02/19] NFS: Fix return type of nfs4_end_drain_session() stub Chuck Lever
2013-07-12 16:31 ` [PATCH v1 03/19] NFS: Introduce a vector of migration recovery ops Chuck Lever
2013-07-12 16:32 ` [PATCH v1 04/19] NFS: Refactor nfs4_call_data_sequence() Chuck Lever
2013-07-22 19:08 ` Myklebust, Trond
2013-07-12 16:32 ` [PATCH v1 05/19] NFS: Rename nfs41_call_sync_data as a common data structure Chuck Lever
2013-07-12 16:32 ` [PATCH v1 06/19] NFS: Clean up nfs4_setup_sequence() Chuck Lever
2013-07-12 16:32 ` [PATCH v1 07/19] NFS: Fix compiler warning in nfs_setup_sequence() Chuck Lever
2013-07-22 19:03 ` Myklebust, Trond
2013-07-22 20:16 ` Chuck Lever
2013-07-22 20:22 ` Myklebust, Trond
2013-07-22 20:24 ` Chuck Lever
2013-07-12 16:32 ` [PATCH v1 08/19] NFS: Use RPC callouts to start NFSv4.0 synchronous requests Chuck Lever
2013-07-12 16:32 ` [PATCH v1 09/19] NFS: Add a "struct nfs_server *" argument to nfs4_sequence_done() Chuck Lever
2013-07-22 19:27 ` Myklebust, Trond
2013-07-24 22:04 ` Chuck Lever
2013-07-12 16:32 ` [PATCH v1 10/19] NFS: Implement a transport blocking scheme for migration Chuck Lever
2013-07-12 16:33 ` [PATCH v1 11/19] SUNRPC: Add a helper to switch the transport of an rpc_clnt Chuck Lever
2013-07-12 16:33 ` [PATCH v1 12/19] NFS: Add a super_block backpointer to the nfs_server struct Chuck Lever
2013-07-12 16:33 ` [PATCH v1 13/19] NFS: Add functions to swap transports during migration recovery Chuck Lever
2013-07-12 16:33 ` [PATCH v1 14/19] NFS: Add method to retrieve fs_locations " Chuck Lever
2013-07-12 16:33 ` Chuck Lever [this message]
2013-07-12 16:33 ` [PATCH v1 16/19] NFS: Add migration recovery callouts in nfs4proc.c Chuck Lever
2013-07-12 16:33 ` [PATCH v1 17/19] NFS: Add method to detect whether an FSID is still on the server Chuck Lever
2013-07-12 16:34 ` [PATCH v1 18/19] NFS: Implement support for NFS4ERR_LEASE_MOVED Chuck Lever
2013-07-12 16:34 ` [PATCH v1 19/19] NFS: Set EXCHGID4_FLAG_SUPP_MOVED_MIGR Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130712163338.1444.23823.stgit@seurat.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).