NFSV4.1,2 session trunking
Subsystems (3)
cover NFSV4.1,2 session trunking
From: Andy Adamson <[email protected]>
This patch set requires changes to mount.nfs in the "Add multihostname support for NFSv4.1,2" nfs-utils patchset.
Note: I did not call EXCHANGE_ID on the mulihostnames in the state manager, as they are synchronous RPC calls that occur directly after the nfs_client->cl_rpcclient has been established. I can change this if needed.
Also note that I do not have code to call BIND_CONN_TO_SESSION if sp4_how is not SP4_NONE. I can add this in the next version.
Andy Adamson (8):
NFS parse multiple hostnames
NFS default callback ops
NFS refactor nfs4_match_clientids
NFS refactor nfs4_check_serverowner_major_id NFS detect session trunking
NFS refactor _nfs4_proc_exchange_id for session trunking SUNRPC add flag to rpc_task_release_client
NFS test and add multi-addrs for session trunking
fs/nfs/internal.h | 21 +++++++++ fs/nfs/nfs4_fs.h | 9 ++++ fs/nfs/nfs4client.c | 110 ++++++++++++++++++++++++++++++++++++++++---- fs/nfs/nfs4proc.c | 78 +++++++++++++++++++++++++++---- fs/nfs/super.c | 40 ++++++++++++++++ include/linux/sunrpc/clnt.h | 2 +- net/sunrpc/clnt.c | 6 +-- net/sunrpc/sched.c | 2 +- net/sunrpc/xprtmultipath.c | 3 ++ 9 files changed, 246 insertions(+), 25 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/8 NFS parse multiple hostnames
From: Andy Adamson <[email protected]>
--- fs/nfs/internal.h | 17 +++++++++++++++++ fs/nfs/nfs4_fs.h | 9 +++++++++ fs/nfs/super.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+)
fs/nfs/internal.h +17 -0
@@ -75,6 +75,20 @@ struct nfs_client_initdata {struct net *net; }; +/** +* NFS_MAXHOSTNAME of 255 limits the number of multiple hostnames on the +* mount stanza. 16 is a reasonable maximum number +*/ +#define NFS_MAX_MULTIADDR 16 + + +/* hold multiple hostname info */ +struct multi_addr { +struct sockaddr_storage addr; +size_t addrlen; +char *hostname; +}; +/* * In-kernel mount arguments */
@@ -113,6 +127,9 @@ struct nfs_parsed_mount_data {unsigned short protocol; } nfs_server; +unsigned int num_multi; +struct multi_addr *multiaddrs; +struct security_mnt_opts lsm_opts;struct net *net; };
fs/nfs/nfs4_fs.h +9 -0
@@ -214,6 +214,15 @@ struct nfs4_mig_recovery_ops {int (*fsid_present)(struct inode *,struct rpc_cred *); }; +struct nfs4_add_xprt_data { +struct nfs_client *clp; +struct rpc_cred *cred; +}; +extern int nfs4_test_session_trunk_and_add_xprt (struct rpc_clnt *clnt, +struct rpc_xprt_switch *xps, +struct rpc_xprt *xprt, +void *data); +extern const struct dentry_operations nfs4_dentry_operations;/* dir.c */
fs/nfs/super.c +40 -0
@@ -107,6 +107,7 @@ enum { Opt_nfsvers, Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_multiaddr, Opt_lookupcache, Opt_fscache_uniq, Opt_local_lock,
@@ -178,6 +179,7 @@ static const match_table_t nfs_mount_option_tokens = { { Opt_clientaddr, "clientaddr=%s" }, { Opt_mounthost, "mounthost=%s" }, { Opt_mountaddr, "mountaddr=%s" }, + { Opt_multiaddr, "multiaddr=%s" }, { Opt_lookupcache, "lookupcache=%s" }, { Opt_fscache_uniq, "fsc=%s" },
@@ -921,6 +923,12 @@ static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void) data =kzalloc (sizeof (*data),GFP_KERNEL );if (data) { + data->multiaddrs =kzalloc (sizeof (*data->multiaddrs) * +NFS_MAX_MULTIADDR ,GFP_KERNEL ); +if (!data->multiaddrs) { +kfree (data); +return NULL ; + } data->acregmin =NFS_DEF_ACREGMIN ; data->acregmax =NFS_DEF_ACREGMAX ; data->acdirmin =NFS_DEF_ACDIRMIN ;
@@ -939,12 +947,20 @@ static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void)static void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data) { +struct multi_addr *multip = data->multiaddrs; +int i; +if (data) {kfree (data->client_address);kfree (data->mount_server.hostname);kfree (data->nfs_server.export_path);kfree (data->nfs_server.hostname);kfree (data->fscache_uniq); +for (i =0 ; i < data->num_multi; i++) { +kfree (multip->hostname); + multip++; + } +kfree (data->multiaddrs);security_free_mnt_opts (&data->lsm_opts);kfree (data); }
@@ -1200,6 +1216,7 @@ static int nfs_parse_mount_options(char *raw,int rc, sloppy =0 , invalid_option =0 ;unsigned short protofamily =AF_UNSPEC ;unsigned short mountfamily =AF_UNSPEC ; +struct multi_addr *multip = mnt->multiaddrs;if (!raw) {dfprintk (MOUNT ,"NFS: mount options string was NULL.\n" );
@@ -1589,6 +1606,25 @@ static int nfs_parse_mount_options(char *raw,return 0 ; };break ; +case Opt_multiaddr: +if (mnt->num_multi ==NFS_MAX_MULTIADDR ) + goto out_too_many_multiaddrs; + +if (nfs_get_option_str (args, &multip->hostname)) + goto out_nomem; + + multip->addrlen =rpc_pton (mnt->net, multip->hostname, +strlen (multip->hostname), + (struct sockaddr *) + &multip->addr, +sizeof (multip->addr)); + +dfprintk (MOUNT ,"NFS: Added multiaddr %s\n" , + multip->hostname); + mnt->num_multi++; + multip++; + +break ;/* * Special options
@@ -1640,6 +1676,10 @@ static int nfs_parse_mount_options(char *raw,return 1 ; +out_too_many_multiaddrs: +printk (KERN_INFO "NFS: %d is too many multiple hostnames.\n" , + mnt->num_multi); +return 0 ; out_mountproto_mismatch:printk (KERN_INFO "NFS: mount server address does not match mountproto= " "option\n" );
Signature · 1 line
1.8.3.1
PATCH 2/8 NFS default callback ops
In reply to [email protected]From: Andy Adamson <[email protected]>
Also use with refactored exchange_id for session trunking
--- fs/nfs/nfs4proc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/nfs/nfs4proc.c +4 -4
@@ -6783,12 +6783,12 @@ nfs41_same_server_scope(struct nfs41_server_scope *a, }static void -nfs4_bind_one_conn_to_session_done (struct rpc_task *task,void *calldata) +nfs4_proc_default_done (struct rpc_task *task,void *calldata) { } -static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { - .rpc_call_done = &nfs4_bind_one_conn_to_session_done, +static const struct rpc_call_ops nfs4_proc_default_ops = { + .rpc_call_done = &nfs4_proc_default_done, };/*
@@ -6819,7 +6819,7 @@ int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt,struct rpc_task_setup task_setup_data = { .rpc_client = clnt, .rpc_xprt = xprt, - .callback_ops = &nfs4_bind_one_conn_to_session_ops, + .callback_ops = &nfs4_proc_default_ops, .rpc_message = &msg, .flags =RPC_TASK_TIMEOUT , };
Signature · 1 line
1.8.3.1
PATCH 3/8 NFS refactor nfs4_match_clientids
In reply to [email protected]From: Andy Adamson <[email protected]>
For session trunking, to compare nfs41_exchange_id_res with exiting nfs_client.
--- fs/nfs/nfs4client.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/nfs/nfs4client.c +5 -5
@@ -562,15 +562,15 @@ out:/* * Returns true if the client IDs match */ -static bool nfs4_match_clientids (struct nfs_client *a,struct nfs_client *b) +static bool nfs4_match_clientids (u64 a,u64 b) { -if (a->cl_clientid != b->cl_clientid) { +if (a != b) {dprintk ("NFS: --> %s client ID %llx does not match %llx\n" , - __func__, a->cl_clientid, b->cl_clientid); + __func__, a, b);return false; }dprintk ("NFS: --> %s client ID %llx matches %llx\n" , - __func__, a->cl_clientid, b->cl_clientid); + __func__, a, b);return true; }
@@ -650,7 +650,7 @@ int nfs41_walk_client_list(struct nfs_client *new,if (pos->cl_cons_state !=NFS_CS_READY )continue ; -if (!nfs4_match_clientids (pos, new)) +if (!nfs4_match_clientids (pos->cl_clientid, new->cl_clientid))continue ;/*
Signature · 1 line
1.8.3.1
PATCH 4/8 NFS refactor nfs4_check_serverowner_major_id
In reply to [email protected]From: Andy Adamson <[email protected]>
For session trunking, to compare nfs41_exchange_id_res with existing nfs_client
--- fs/nfs/nfs4client.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/nfs/nfs4client.c +4 -5
@@ -578,11 +578,9 @@ static bool nfs4_match_clientids(u64 a, u64 b)* Returns true if the server major ids match */ static bool -nfs4_check_clientid_trunking (struct nfs_client *a,struct nfs_client *b) +nfs4_check_serverowner_major_id (struct nfs41_server_owner *o1, +struct nfs41_server_owner *o2) { -struct nfs41_server_owner *o1 = a->cl_serverowner; -struct nfs41_server_owner *o2 = b->cl_serverowner; -if (o1->major_id_sz != o2->major_id_sz) goto out_major_mismatch;if (memcmp (o1->major_id, o2->major_id, o1->major_id_sz) !=0 )
@@ -658,7 +656,8 @@ int nfs41_walk_client_list(struct nfs_client *new,* client id trunking. In either case, we want to fall back * to using the existing nfs_client. */ -if (!nfs4_check_clientid_trunking (pos, new)) +if (!nfs4_check_serverowner_major_id (pos->cl_serverowner, + new->cl_serverowner))continue ;/* Unlike NFSv4.0, we know that NFSv4.1 always uses the
Signature · 1 line
1.8.3.1
PATCH 5/8 NFS detect session trunking
In reply to [email protected]From: Andy Adamson <[email protected]>
--- fs/nfs/internal.h | 2 ++ fs/nfs/nfs4client.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
fs/nfs/internal.h +2 -0
@@ -549,6 +549,8 @@ extern int nfs40_walk_client_list(struct nfs_client *clp,extern int nfs41_walk_client_list (struct nfs_client *clp,struct nfs_client **result,struct rpc_cred *cred); +extern int nfs4_detect_session_trunking (struct nfs_client *clp, +struct nfs41_exchange_id_res *res);static inline struct inode *nfs_igrab_and_active (struct inode *inode) {
fs/nfs/nfs4client.c +52 -0
58 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 6/8 NFS refactor _nfs4_proc_exchange_id for session trunking
In reply to [email protected]From: Andy Adamson <[email protected]>
Add an rpc_xprt parameter to test it's connection for session trunking
--- fs/nfs/nfs4proc.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
fs/nfs/nfs4proc.c +28 -6
@@ -7023,7 +7023,7 @@ static int nfs4_sp4_select_mode(struct nfs_client *clp,* Wrapper for EXCHANGE_ID operation. */ static int _nfs4_proc_exchange_id (struct nfs_client *clp,struct rpc_cred *cred, -u32 sp4_how) +u32 sp4_how,struct rpc_xprt *xprt) {nfs4_verifier verifier;struct nfs41_exchange_id_args args = {
@@ -7048,6 +7048,18 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, .rpc_resp = &res, .rpc_cred = cred, }; +struct rpc_task_setup task_setup_data = { + .rpc_client = clp->cl_rpcclient, + .rpc_xprt = xprt, + .callback_ops = &nfs4_proc_default_ops, + .rpc_message = &msg, + .flags =RPC_TASK_TIMEOUT , + }; +struct rpc_task *task; + +/* Do not run exchange_id against the established mount connection */ +if (xprt && xprt ==rcu_access_pointer (clp->cl_rpcclient->cl_xprt)) +return 1 ;nfs4_init_boot_verifier (clp, &verifier);
@@ -7095,11 +7107,17 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, goto out_impl_id; } - status =rpc_call_sync (clp->cl_rpcclient, &msg,RPC_TASK_TIMEOUT ); + task =rpc_run_task (&task_setup_data); +if (!IS_ERR (task)) { + status = task->tk_status; +rpc_put_task (task); + }else + status =PTR_ERR (task);trace_nfs4_exchange_id (clp, status);if (status ==0 ) status =nfs4_check_cl_exchange_flags (res.flags); - +if (xprt) + goto session_trunk;if (status ==0 ) status =nfs4_sp4_select_mode (clp, &res.state_protect);
@@ -7137,7 +7155,6 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, res.server_scope =NULL ; } } - out_impl_id:kfree (res.impl_id); out_server_scope:
@@ -7153,6 +7170,11 @@ out: clp->cl_implid->date.nseconds);dprintk ("NFS reply exchange_id: %d\n" , status);return status; + +session_trunk: +if (status ==0 ) + status =nfs4_detect_session_trunking (clp, &res); + goto out_impl_id; }/*
@@ -7175,13 +7197,13 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)/* try SP4_MACH_CRED if krb5i/p */ if (authflavor ==RPC_AUTH_GSS_KRB5I || authflavor ==RPC_AUTH_GSS_KRB5P ) { - status =_nfs4_proc_exchange_id (clp, cred,SP4_MACH_CRED ); + status =_nfs4_proc_exchange_id (clp, cred,SP4_MACH_CRED ,NULL );if (!status)return 0 ; }/* try SP4_NONE */ -return _nfs4_proc_exchange_id (clp, cred,SP4_NONE ); +return _nfs4_proc_exchange_id (clp, cred,SP4_NONE ,NULL ); } static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
Signature · 1 line
1.8.3.1
PATCH 7/8 SUNRPC add flag to rpc_task_release_client
In reply to [email protected]From: Andy Adamson <[email protected]>
Want to specify which rpc_xprt to use in rpc_run_task.
Don't pass in an rpc_xprt in rpc_init_task just to have it not used as it is removed in rpc_task_release_client.
--- include/linux/sunrpc/clnt.h | 2 +- net/sunrpc/clnt.c | 6 +++--- net/sunrpc/sched.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/linux/sunrpc/clnt.h +1 -1
@@ -150,7 +150,7 @@ int rpc_switch_client_transport(struct rpc_clnt *,void rpc_shutdown_client (struct rpc_clnt *);void rpc_release_client (struct rpc_clnt *); -void rpc_task_release_client (struct rpc_task *); +void rpc_task_release_client (struct rpc_task *,int );int rpcb_create_local (struct net *);void rpcb_put_local (struct net *);
net/sunrpc/clnt.c +3 -3
@@ -942,7 +942,7 @@ out: }EXPORT_SYMBOL_GPL (rpc_bind_new_program); -void rpc_task_release_client (struct rpc_task *task) +void rpc_task_release_client (struct rpc_task *task,int rm_xprt) {struct rpc_clnt *clnt = task->tk_client;struct rpc_xprt *xprt = task->tk_xprt;
@@ -957,7 +957,7 @@ void rpc_task_release_client(struct rpc_task *task)rpc_release_client (clnt); } -if (xprt !=NULL ) { +if (rm_xprt && xprt) { task->tk_xprt =NULL ;xprt_put (xprt);
@@ -969,7 +969,7 @@ void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt) {if (clnt !=NULL ) { -rpc_task_release_client (task); +rpc_task_release_client (task,0 );if (task->tk_xprt ==NULL ) task->tk_xprt =xprt_iter_get_next (&clnt->cl_xpi); task->tk_client = clnt;
net/sunrpc/sched.c +1 -1
@@ -993,7 +993,7 @@ static void rpc_release_resources_task(struct rpc_task *task)put_rpccred (task->tk_msg.rpc_cred); task->tk_msg.rpc_cred =NULL ; } -rpc_task_release_client (task); +rpc_task_release_client (task,1 ); } static void rpc_final_put_task(struct rpc_task *task,
Signature · 1 line
1.8.3.1
PATCH 8/8 NFS test and add multi-addrs for session trunking
In reply to [email protected]From: Andy Adamson <[email protected]>
--- fs/nfs/internal.h | 2 ++ fs/nfs/nfs4client.c | 39 +++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 36 ++++++++++++++++++++++++++++++++++++ net/sunrpc/xprtmultipath.c | 3 +++ 4 files changed, 80 insertions(+)
fs/nfs/internal.h +2 -0
@@ -214,6 +214,8 @@ extern struct nfs_client *nfs3_set_ds_client(struct nfs_client *mds_clp, const struct sockaddr *ds_addr, int ds_addrlen, int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans, rpc_authflavor_t au_flavor); +extern void nfs_try_multiaddr (struct nfs_parsed_mount_data *mnt, +struct rpc_clnt *clnt);#ifdef CONFIG_PROC_FS extern int __init nfs_fs_proc_init (void );extern void nfs_fs_proc_exit (void );
fs/nfs/nfs4client.c +39 -0
@@ -1012,6 +1012,43 @@ out:return error; } +/** +* Add rpc_xprts to an existing RPC client +*/ +void nfs4_try_multiaddr (struct nfs_parsed_mount_data *mnt, +struct nfs_client *clp) +{ +struct multi_addr *multip = mnt->multiaddrs; +struct nfs4_add_xprt_data xprtdata = { + .clp = clp, + }; +int i; + +dprintk ("NFS: Try adding %u multi addrs\n" , mnt->num_multi); + +if (mnt->num_multi ==0 ) +return ; + + xprtdata.cred =nfs4_get_clid_cred (clp); + +for (i =0 ; i < mnt->num_multi; i++) { +struct xprt_create xprt_args = { + .ident =XPRT_TRANSPORT_TCP , + .net = mnt->net, + .dstaddr = (struct sockaddr *)&multip->addr, + .addrlen = multip->addrlen, + .servername = multip->hostname, + }; +/* Add this address as an alias */ +rpc_clnt_add_xprt (clp->cl_rpcclient, &xprt_args, + nfs4_test_session_trunk_and_add_xprt, + &xprtdata); + multip++; + } +if (xprtdata.cred) +put_rpccred (xprtdata.cred); +} +/* * Create a version 4 volume record */
@@ -1068,6 +1105,8 @@ static int nfs4_init_server(struct nfs_server *server, error =nfs_init_server_rpcclient (server, &timeparms, data->selected_flavor); +if (!error) +nfs4_try_multiaddr (data, server->nfs_client); error:/* Done */ dprintk ("<-- nfs4_init_server() = %d\n" , error);
fs/nfs/nfs4proc.c +36 -0
@@ -7206,6 +7206,42 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)return _nfs4_proc_exchange_id (clp, cred,SP4_NONE ,NULL ); } +/** +* nfs4_test_session_trunk_and_add_xprt - Test for session trunking with a +* synchronous exchange_id call, and add a new transport to the rpc_clnt +* +* @clnt: struct rpc_clnt to get new transport +* @xps: the rpc_xprt_switch to hold the new transport +* @xprt: the rpc_xprt to test +* @data: call data for _nfs4_proc_exchange_id. +* +*/ +int nfs4_test_session_trunk_and_add_xprt (struct rpc_clnt *clnt, +struct rpc_xprt_switch *xps, +struct rpc_xprt *xprt, +void *data) +{ +struct nfs4_add_xprt_data *xdata = (struct nfs4_add_xprt_data *)data; +u32 sp4_how; +int status; + + sp4_how = (xdata->clp->cl_sp4_flags ==0 ?SP4_NONE :SP4_MACH_CRED ); +dprintk ("--> %s sp4_how %d\n" , __func__, sp4_how); + +/* Ensure these stick around for the rpc call */ + xps =xprt_switch_get (xps); + xprt =xprt_get (xprt); + +/* Sync call */ + status =_nfs4_proc_exchange_id (xdata->clp, xdata->cred, sp4_how, xprt); + +xprt_put (xprt); +xprt_switch_put (xps); + +dprintk ("<-- %s status %d\n" , __func__, status); +return status; +} +static int _nfs4_proc_destroy_clientid (struct nfs_client *clp,struct rpc_cred *cred) {
net/sunrpc/xprtmultipath.c +3 -0
@@ -53,6 +53,7 @@ void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,xprt_switch_add_xprt_locked (xps, xprt);spin_unlock (&xps->xps_lock); } +EXPORT_SYMBOL_GPL (rpc_xprt_switch_add_xprt);static void xprt_switch_remove_xprt_locked (struct rpc_xprt_switch *xps,struct rpc_xprt *xprt)
@@ -145,6 +146,7 @@ struct rpc_xprt_switch *xprt_switch_get(struct rpc_xprt_switch *xps)return xps;return NULL ; } +EXPORT_SYMBOL_GPL (xprt_switch_get);/** * xprt_switch_put - Release a reference to a rpc_xprt_switch
@@ -157,6 +159,7 @@ void xprt_switch_put(struct rpc_xprt_switch *xps)if (xps !=NULL )kref_put (&xps->xps_kref, xprt_switch_free); } +EXPORT_SYMBOL_GPL (xprt_switch_put);/** * rpc_xprt_switch_set_roundrobin - Set a round-robin policy on rpc_xprt_switch
Signature · 1 line
1.8.3.1