Commit 7c44f1ae authored by Weston Andros Adamson's avatar Weston Andros Adamson Committed by Trond Myklebust

nfs4.1: add BIND_CONN_TO_SESSION operation

This patch adds the BIND_CONN_TO_SESSION operation which is needed for
upcoming SP4_MACH_CRED work and useful for recovering from broken connections
without destroying the session.
Signed-off-by: default avatarWeston Andros Adamson <dros@netapp.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent d23d61c8
...@@ -211,6 +211,7 @@ struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *, ...@@ -211,6 +211,7 @@ struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
extern int nfs4_proc_bind_conn_to_session(struct nfs_client *);
extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred); extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
......
...@@ -5099,6 +5099,60 @@ nfs41_same_server_scope(struct nfs41_server_scope *a, ...@@ -5099,6 +5099,60 @@ nfs41_same_server_scope(struct nfs41_server_scope *a,
return false; return false;
} }
/*
* nfs4_proc_bind_conn_to_session()
*
* The 4.1 client currently uses the same TCP connection for the
* fore and backchannel.
*/
int nfs4_proc_bind_conn_to_session(struct nfs_client *clp)
{
int status;
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_resp = &res,
};
dprintk("--> %s\n", __func__);
BUG_ON(clp == NULL);
res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
if (unlikely(res.session == NULL)) {
status = -ENOMEM;
goto out;
}
status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
if (status == 0) {
if (memcmp(res.session->sess_id.data,
clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
dprintk("NFS: %s: Session ID mismatch\n", __func__);
status = -EIO;
goto out_session;
}
if (res.dir != NFS4_CDFS4_BOTH) {
dprintk("NFS: %s: Unexpected direction from server\n",
__func__);
status = -EIO;
goto out_session;
}
if (res.use_conn_in_rdma_mode) {
dprintk("NFS: %s: Server returned RDMA mode = true\n",
__func__);
status = -EIO;
goto out_session;
}
}
out_session:
kfree(res.session);
out:
dprintk("<-- %s status= %d\n", __func__, status);
return status;
}
/* /*
* nfs4_proc_exchange_id() * nfs4_proc_exchange_id()
* *
......
...@@ -326,6 +326,16 @@ static int nfs4_stat_to_errno(int); ...@@ -326,6 +326,16 @@ static int nfs4_stat_to_errno(int);
1 /* csr_flags */ + \ 1 /* csr_flags */ + \
decode_channel_attrs_maxsz + \ decode_channel_attrs_maxsz + \
decode_channel_attrs_maxsz) decode_channel_attrs_maxsz)
#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
/* bctsa_sessid */ \
XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
1 /* bctsa_dir */ + \
1 /* bctsa_use_conn_in_rdma_mode */)
#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
/* bctsr_sessid */ \
XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
1 /* bctsr_dir */ + \
1 /* bctsr_use_conn_in_rdma_mode */)
#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4) #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
#define decode_destroy_session_maxsz (op_decode_hdr_maxsz) #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
#define encode_sequence_maxsz (op_encode_hdr_maxsz + \ #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
...@@ -719,6 +729,12 @@ static int nfs4_stat_to_errno(int); ...@@ -719,6 +729,12 @@ static int nfs4_stat_to_errno(int);
decode_putfh_maxsz + \ decode_putfh_maxsz + \
decode_secinfo_maxsz) decode_secinfo_maxsz)
#if defined(CONFIG_NFS_V4_1) #if defined(CONFIG_NFS_V4_1)
#define NFS4_enc_bind_conn_to_session_sz \
(compound_encode_hdr_maxsz + \
encode_bind_conn_to_session_maxsz)
#define NFS4_dec_bind_conn_to_session_sz \
(compound_decode_hdr_maxsz + \
decode_bind_conn_to_session_maxsz)
#define NFS4_enc_exchange_id_sz \ #define NFS4_enc_exchange_id_sz \
(compound_encode_hdr_maxsz + \ (compound_encode_hdr_maxsz + \
encode_exchange_id_maxsz) encode_exchange_id_maxsz)
...@@ -1669,6 +1685,20 @@ static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, stru ...@@ -1669,6 +1685,20 @@ static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, stru
#if defined(CONFIG_NFS_V4_1) #if defined(CONFIG_NFS_V4_1)
/* NFSv4.1 operations */ /* NFSv4.1 operations */
static void encode_bind_conn_to_session(struct xdr_stream *xdr,
struct nfs4_session *session,
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);
p = xdr_reserve_space(xdr, 8);
*p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
*p = 0; /* use_conn_in_rdma_mode = False */
}
static void encode_exchange_id(struct xdr_stream *xdr, static void encode_exchange_id(struct xdr_stream *xdr,
struct nfs41_exchange_id_args *args, struct nfs41_exchange_id_args *args,
struct compound_hdr *hdr) struct compound_hdr *hdr)
...@@ -2629,6 +2659,22 @@ static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req, ...@@ -2629,6 +2659,22 @@ static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
} }
#if defined(CONFIG_NFS_V4_1) #if defined(CONFIG_NFS_V4_1)
/*
* BIND_CONN_TO_SESSION request
*/
static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
struct xdr_stream *xdr,
struct nfs_client *clp)
{
struct compound_hdr hdr = {
.minorversion = clp->cl_mvops->minor_version,
};
encode_compound_hdr(xdr, req, &hdr);
encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
encode_nops(&hdr);
}
/* /*
* EXCHANGE_ID request * EXCHANGE_ID request
*/ */
...@@ -5366,6 +5412,37 @@ static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid) ...@@ -5366,6 +5412,37 @@ static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN); return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
} }
static int decode_bind_conn_to_session(struct xdr_stream *xdr,
struct nfs41_bind_conn_to_session_res *res)
{
__be32 *p;
int status;
status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
if (!status)
status = decode_sessionid(xdr, &res->session->sess_id);
if (unlikely(status))
return status;
/* dir flags, rdma mode bool */
p = xdr_inline_decode(xdr, 8);
if (unlikely(!p))
goto out_overflow;
res->dir = be32_to_cpup(p++);
if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
return -EIO;
if (be32_to_cpup(p) == 0)
res->use_conn_in_rdma_mode = false;
else
res->use_conn_in_rdma_mode = true;
return 0;
out_overflow:
print_overflow_msg(__func__, xdr);
return -EIO;
}
static int decode_create_session(struct xdr_stream *xdr, static int decode_create_session(struct xdr_stream *xdr,
struct nfs41_create_session_res *res) struct nfs41_create_session_res *res)
{ {
...@@ -6647,6 +6724,22 @@ static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp, ...@@ -6647,6 +6724,22 @@ static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
} }
#if defined(CONFIG_NFS_V4_1) #if defined(CONFIG_NFS_V4_1)
/*
* Decode BIND_CONN_TO_SESSION response
*/
static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
struct xdr_stream *xdr,
void *res)
{
struct compound_hdr hdr;
int status;
status = decode_compound_hdr(xdr, &hdr);
if (!status)
status = decode_bind_conn_to_session(xdr, res);
return status;
}
/* /*
* Decode EXCHANGE_ID response * Decode EXCHANGE_ID response
*/ */
...@@ -7128,6 +7221,8 @@ struct rpc_procinfo nfs4_procedures[] = { ...@@ -7128,6 +7221,8 @@ struct rpc_procinfo nfs4_procedures[] = {
PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
PROC(SECINFO, enc_secinfo, dec_secinfo), PROC(SECINFO, enc_secinfo, dec_secinfo),
#if defined(CONFIG_NFS_V4_1) #if defined(CONFIG_NFS_V4_1)
PROC(BIND_CONN_TO_SESSION,
enc_bind_conn_to_session, dec_bind_conn_to_session),
PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
PROC(CREATE_SESSION, enc_create_session, dec_create_session), PROC(CREATE_SESSION, enc_create_session, dec_create_session),
PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
......
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
#define NFS4_CDFC4_FORE_OR_BOTH 0x3 #define NFS4_CDFC4_FORE_OR_BOTH 0x3
#define NFS4_CDFC4_BACK_OR_BOTH 0x7 #define NFS4_CDFC4_BACK_OR_BOTH 0x7
#define NFS4_CDFS4_FORE 0x1
#define NFS4_CDFS4_BACK 0x2
#define NFS4_CDFS4_BOTH 0x3
#define NFS4_SET_TO_SERVER_TIME 0 #define NFS4_SET_TO_SERVER_TIME 0
#define NFS4_SET_TO_CLIENT_TIME 1 #define NFS4_SET_TO_CLIENT_TIME 1
...@@ -589,6 +593,7 @@ enum { ...@@ -589,6 +593,7 @@ enum {
NFSPROC4_CLNT_SECINFO, NFSPROC4_CLNT_SECINFO,
/* nfs41 */ /* nfs41 */
NFSPROC4_CLNT_BIND_CONN_TO_SESSION,
NFSPROC4_CLNT_EXCHANGE_ID, NFSPROC4_CLNT_EXCHANGE_ID,
NFSPROC4_CLNT_CREATE_SESSION, NFSPROC4_CLNT_CREATE_SESSION,
NFSPROC4_CLNT_DESTROY_SESSION, NFSPROC4_CLNT_DESTROY_SESSION,
......
...@@ -1125,6 +1125,12 @@ struct nfs41_impl_id { ...@@ -1125,6 +1125,12 @@ struct nfs41_impl_id {
struct nfstime4 date; struct nfstime4 date;
}; };
struct nfs41_bind_conn_to_session_res {
struct nfs4_session *session;
u32 dir;
bool use_conn_in_rdma_mode;
};
struct nfs41_exchange_id_res { struct nfs41_exchange_id_res {
struct nfs_client *client; struct nfs_client *client;
u32 flags; u32 flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment