NFSv4.1: Clean up create_session
Subsystems (2)
PATCH 1/4 NFSv4.1: Clean up create_session
Don't decode directly into the shared struct session
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/nfs4proc.c | 42 +++++++++++++++++++++++++++++------------- fs/nfs/nfs4session.h | 6 ++++++ fs/nfs/nfs4xdr.c | 16 +++++++--------- include/linux/nfs_xdr.h | 8 +++++++- 4 files changed, 49 insertions(+), 23 deletions(-)
fs/nfs/nfs4proc.c +29 -13
@@ -7166,10 +7166,11 @@ static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) args->bc_attrs.max_reqs); } -static int nfs4_verify_fore_channel_attrs (struct nfs41_create_session_args *args,struct nfs4_session *session) +static int nfs4_verify_fore_channel_attrs (struct nfs41_create_session_args *args, +struct nfs41_create_session_res *res) {struct nfs4_channel_attrs *sent = &args->fc_attrs; -struct nfs4_channel_attrs *rcvd = &session->fc_attrs; +struct nfs4_channel_attrs *rcvd = &res->fc_attrs;if (rcvd->max_resp_sz > sent->max_resp_sz)return -EINVAL ;
@@ -7188,10 +7189,11 @@ static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *argsreturn 0 ; } -static int nfs4_verify_back_channel_attrs (struct nfs41_create_session_args *args,struct nfs4_session *session) +static int nfs4_verify_back_channel_attrs (struct nfs41_create_session_args *args, +struct nfs41_create_session_res *res) {struct nfs4_channel_attrs *sent = &args->bc_attrs; -struct nfs4_channel_attrs *rcvd = &session->bc_attrs; +struct nfs4_channel_attrs *rcvd = &res->bc_attrs;if (rcvd->max_rqst_sz > sent->max_rqst_sz)return -EINVAL ;
@@ -7208,14 +7210,23 @@ static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args }static int nfs4_verify_channel_attrs (struct nfs41_create_session_args *args, -struct nfs4_session *session) +struct nfs41_create_session_res *res) {int ret; - ret =nfs4_verify_fore_channel_attrs (args, session); + ret =nfs4_verify_fore_channel_attrs (args, res);if (ret)return ret; -return nfs4_verify_back_channel_attrs (args, session); +return nfs4_verify_back_channel_attrs (args, res); +} + +static void nfs4_update_session (struct nfs4_session *session, +struct nfs41_create_session_res *res) +{ +nfs4_copy_sessionid (&session->sess_id, &res->sessionid); + session->flags = res->flags; +memcpy (&session->fc_attrs, &res->fc_attrs,sizeof (session->fc_attrs)); +memcpy (&session->bc_attrs, &res->bc_attrs,sizeof (session->bc_attrs)); } static int _nfs4_proc_create_session(struct nfs_client *clp,
@@ -7224,11 +7235,12 @@ static int _nfs4_proc_create_session(struct nfs_client *clp,struct nfs4_session *session = clp->cl_session;struct nfs41_create_session_args args = { .client = clp, + .clientid = clp->cl_clientid, + .seqid = clp->cl_seqid, .cb_program =NFS4_CALLBACK , }; -struct nfs41_create_session_res res = { - .client = clp, - }; +struct nfs41_create_session_res res; +struct rpc_message msg = { .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION ], .rpc_argp = &args,
@@ -7245,11 +7257,15 @@ static int _nfs4_proc_create_session(struct nfs_client *clp,if (!status) {/* Verify the session's negotiated channel_attrs values */ - status =nfs4_verify_channel_attrs (&args, session); + status =nfs4_verify_channel_attrs (&args, &res);/* Increment the clientid slot sequence id */ - clp->cl_seqid++; +if (clp->cl_seqid == res.seqid) + clp->cl_seqid++; +if (status) + goto out; +nfs4_update_session (session, &res); } - +out:return status; }
fs/nfs/nfs4session.h +6 -0
@@ -118,6 +118,12 @@ static inline int nfs4_has_persistent_session(const struct nfs_client *clp)return 0 ; } +static inline void nfs4_copy_sessionid (struct nfs4_sessionid *dst, +const struct nfs4_sessionid *src) +{ +memcpy (dst->data, src->data,NFS4_MAX_SESSIONID_LEN ); +} +#ifdef CONFIG_CRC32 /* * nfs_session_id_hash - calculate the crc32 hash for the session id
fs/nfs/nfs4xdr.c +7 -9
@@ -1806,8 +1806,8 @@ static void encode_create_session(struct xdr_stream *xdr,encode_op_hdr (xdr,OP_CREATE_SESSION , decode_create_session_maxsz, hdr); p =reserve_space (xdr,16 +2 *28 +20 + clnt->cl_nodelen +12 ); - p =xdr_encode_hyper (p, clp->cl_clientid); - *p++ =cpu_to_be32 (clp->cl_seqid);/*Sequence id */ + p =xdr_encode_hyper (p, args->clientid); + *p++ =cpu_to_be32 (args->seqid);/*Sequence id */ *p++ =cpu_to_be32 (args->flags);/*flags */ /* Fore Channel */
@@ -5641,12 +5641,10 @@ static int decode_create_session(struct xdr_stream *xdr, {__be32 *p;int status; -struct nfs_client *clp = res->client; -struct nfs4_session *session = clp->cl_session; status =decode_op_hdr (xdr,OP_CREATE_SESSION );if (!status) - status =decode_sessionid (xdr, &session->sess_id); + status =decode_sessionid (xdr, &res->sessionid);if (unlikely (status))return status;
@@ -5654,13 +5652,13 @@ static int decode_create_session(struct xdr_stream *xdr, p =xdr_inline_decode (xdr,8 );if (unlikely (!p)) goto out_overflow; - clp->cl_seqid =be32_to_cpup (p++); - session->flags =be32_to_cpup (p); + res->seqid =be32_to_cpup (p++); + res->flags =be32_to_cpup (p);/* Channel attributes */ - status =decode_chan_attrs (xdr, &session->fc_attrs); + status =decode_chan_attrs (xdr, &res->fc_attrs);if (!status) - status =decode_chan_attrs (xdr, &session->bc_attrs); + status =decode_chan_attrs (xdr, &res->bc_attrs);return status; out_overflow:print_overflow_msg (__func__, xdr);
include/linux/nfs_xdr.h +7 -1
@@ -1185,6 +1185,8 @@ struct nfs41_exchange_id_res {struct nfs41_create_session_args {struct nfs_client *client; +u64 clientid; +uint32_t seqid;uint32_t flags;uint32_t cb_program;struct nfs4_channel_attrs fc_attrs;/* Fore Channel */
@@ -1192,7 +1194,11 @@ struct nfs41_create_session_args { };struct nfs41_create_session_res { -struct nfs_client *client; +struct nfs4_sessionid sessionid; +uint32_t seqid; +uint32_t flags; +struct nfs4_channel_attrs fc_attrs;/* Fore Channel */ +struct nfs4_channel_attrs bc_attrs;/* Back Channel */ };struct nfs41_reclaim_complete_args {
Signature · 1 line
2.1.0
PATCH 2/4 NFSv4.1: Don't set up a backchannel if the server didn't agree to do so
If the server doesn't agree to out backchannel setup request, then don't set one up.
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/callback_proc.c | 2 ++ fs/nfs/nfs4proc.c | 7 ++++++- fs/nfs/nfs4session.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-)
fs/nfs/callback_proc.c +2 -0
@@ -427,6 +427,8 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,if (clp ==NULL ) goto out; +if (!(clp->cl_session->flags &SESSION4_BACK_CHAN )) + goto out; tbl = &clp->cl_session->bc_slot_table;spin_lock (&tbl->slot_tbl_lock);
fs/nfs/nfs4proc.c +6 -1
@@ -7195,6 +7195,8 @@ static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *argsstruct nfs4_channel_attrs *sent = &args->bc_attrs;struct nfs4_channel_attrs *rcvd = &res->bc_attrs; +if (!(res->flags &SESSION4_BACK_CHAN )) + goto out;if (rcvd->max_rqst_sz > sent->max_rqst_sz)return -EINVAL ;if (rcvd->max_resp_sz < sent->max_resp_sz)
@@ -7206,6 +7208,7 @@ static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *argsreturn -EINVAL ;if (rcvd->max_reqs != sent->max_reqs)return -EINVAL ; +out:return 0 ; }
@@ -7226,7 +7229,9 @@ static void nfs4_update_session(struct nfs4_session *session,nfs4_copy_sessionid (&session->sess_id, &res->sessionid); session->flags = res->flags;memcpy (&session->fc_attrs, &res->fc_attrs,sizeof (session->fc_attrs)); -memcpy (&session->bc_attrs, &res->bc_attrs,sizeof (session->bc_attrs)); +if (res->flags &SESSION4_BACK_CHAN ) +memcpy (&session->bc_attrs, &res->bc_attrs, +sizeof (session->bc_attrs)); } static int _nfs4_proc_create_session(struct nfs_client *clp,
fs/nfs/nfs4session.c +1 -1
@@ -450,7 +450,7 @@ int nfs4_setup_session_slot_tables(struct nfs4_session *ses) tbl = &ses->fc_slot_table; tbl->session = ses; status =nfs4_realloc_slot_table (tbl, ses->fc_attrs.max_reqs,1 ); -if (status)/* -ENOMEM */ +if (status || !(ses->flags &SESSION4_BACK_CHAN ))/* -ENOMEM */ return status;/* Back channel */ tbl = &ses->bc_slot_table;
Signature · 1 line
2.1.0
PATCH 3/4 NFSv4.1: Always set up a forward channel when binding the session
Currently, the client requests a back channel or a bidirectional connection when binding a new TCP channel to an existing session. Fix that to ask for a forward channel or bidirectional.
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/nfs4xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4xdr.c +1 -1
@@ -1724,7 +1724,7 @@ static void encode_bind_conn_to_session(struct xdr_stream *xdr, decode_bind_conn_to_session_maxsz, hdr);encode_opaque_fixed (xdr, session->sess_id.data,NFS4_MAX_SESSIONID_LEN ); p =xdr_reserve_space (xdr,8 ); - *p++ =cpu_to_be32 (NFS4_CDFC4_BACK_OR_BOTH ); + *p++ =cpu_to_be32 (NFS4_CDFC4_FORE_OR_BOTH ); *p =0 ;/* use_conn_in_rdma_mode = False */ }
Signature · 1 line
2.1.0
PATCH 4/4 NFSv4.1: Clean up bind_conn_to_session
We don't need to fake up an entire session in order retrieve the arguments.
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/nfs4proc.c | 28 ++++++++++++++-------------- fs/nfs/nfs4xdr.c | 16 ++++++++-------- include/linux/nfs_xdr.h | 9 ++++++++- 3 files changed, 30 insertions(+), 23 deletions(-)
fs/nfs/nfs4proc.c +14 -14
@@ -6648,47 +6648,47 @@ nfs41_same_server_scope(struct nfs41_server_scope *a,int nfs4_proc_bind_conn_to_session (struct nfs_client *clp,struct rpc_cred *cred) {int status; +struct nfs41_bind_conn_to_session_args args = { + .client = clp, + .dir =NFS4_CDFC4_FORE_OR_BOTH , + };struct nfs41_bind_conn_to_session_res res;struct rpc_message msg = { .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION ], - .rpc_argp = clp, + .rpc_argp = &args, .rpc_resp = &res, .rpc_cred = cred, };dprintk ("--> %s\n" , __func__); - res.session =kzalloc (sizeof (struct nfs4_session ),GFP_NOFS ); -if (unlikely (res.session ==NULL )) { - status = -ENOMEM ; - goto out; - } +nfs4_copy_sessionid (&args.sessionid, &clp->cl_session->sess_id); +if (!(clp->cl_session->flags &SESSION4_BACK_CHAN )) + args.dir =NFS4_CDFC4_FORE ; status =rpc_call_sync (clp->cl_rpcclient, &msg,RPC_TASK_TIMEOUT );trace_nfs4_bind_conn_to_session (clp, status);if (status ==0 ) { -if (memcmp (res.session->sess_id.data, +if (memcmp (res.sessionid.data, clp->cl_session->sess_id.data,NFS4_MAX_SESSIONID_LEN )) {dprintk ("NFS: %s: Session ID mismatch\n" , __func__); status = -EIO ; - goto out_session; + goto out; } -if (res.dir !=NFS4_CDFS4_BOTH ) { +if ((res.dir & args.dir) != res.dir || res.dir ==0 ) {dprintk ("NFS: %s: Unexpected direction from server\n" , __func__); status = -EIO ; - goto out_session; + goto out; } -if (res.use_conn_in_rdma_mode) { +if (res.use_conn_in_rdma_mode != args.use_conn_in_rdma_mode) {dprintk ("NFS: %s: Server returned RDMA mode = true\n" , __func__); status = -EIO ; - goto out_session; + goto out; } } -out_session: -kfree (res.session); out:dprintk ("<-- %s status= %d\n" , __func__, status);return status;
fs/nfs/nfs4xdr.c +8 -8
@@ -1715,17 +1715,17 @@ static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, stru#if defined(CONFIG_NFS_V4_1 )/* NFSv4.1 operations */ static void encode_bind_conn_to_session (struct xdr_stream *xdr, -struct nfs4_session *session, +struct nfs41_bind_conn_to_session_args *args,struct compound_hdr *hdr) {__be32 *p;encode_op_hdr (xdr,OP_BIND_CONN_TO_SESSION , decode_bind_conn_to_session_maxsz, hdr); -encode_opaque_fixed (xdr, session->sess_id.data,NFS4_MAX_SESSIONID_LEN ); +encode_opaque_fixed (xdr, args->sessionid.data,NFS4_MAX_SESSIONID_LEN ); p =xdr_reserve_space (xdr,8 ); - *p++ =cpu_to_be32 (NFS4_CDFC4_FORE_OR_BOTH ); - *p =0 ;/* use_conn_in_rdma_mode = False */ + *p++ =cpu_to_be32 (args->dir); + *p = (args->use_conn_in_rdma_mode) ?cpu_to_be32 (1 ) :cpu_to_be32 (0 ); }static void encode_op_map (struct xdr_stream *xdr,struct nfs4_op_map *op_map)
@@ -2734,14 +2734,14 @@ static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,*/ static void nfs4_xdr_enc_bind_conn_to_session (struct rpc_rqst *req,struct xdr_stream *xdr, -struct nfs_client *clp) +struct nfs41_bind_conn_to_session_args *args) {struct compound_hdr hdr = { - .minorversion = clp->cl_mvops->minor_version, + .minorversion = args->client->cl_mvops->minor_version, };encode_compound_hdr (xdr, req, &hdr); -encode_bind_conn_to_session (xdr, clp->cl_session, &hdr); +encode_bind_conn_to_session (xdr, args, &hdr);encode_nops (&hdr); }
@@ -5613,7 +5613,7 @@ static int decode_bind_conn_to_session(struct xdr_stream *xdr, status =decode_op_hdr (xdr,OP_BIND_CONN_TO_SESSION );if (!status) - status =decode_sessionid (xdr, &res->session->sess_id); + status =decode_sessionid (xdr, &res->sessionid);if (unlikely (status))return status;
include/linux/nfs_xdr.h +8 -1
@@ -1167,8 +1167,15 @@ struct nfs41_impl_id {struct nfstime4 date; }; +struct nfs41_bind_conn_to_session_args { +struct nfs_client *client; +struct nfs4_sessionid sessionid; +u32 dir; +bool use_conn_in_rdma_mode; +}; +struct nfs41_bind_conn_to_session_res { -struct nfs4_session *session; +struct nfs4_sessionid sessionid;u32 dir;bool use_conn_in_rdma_mode; };
Signature · 1 line
2.1.0