36 #include <linux/slab.h>
40 #define NFSDDBG_FACILITY NFSDDBG_PROC
44 #define NFSPROC4_CB_NULL 0
45 #define NFSPROC4_CB_COMPOUND 1
55 #define NFS4_MAXTAGLEN 20
57 #define NFS4_enc_cb_null_sz 0
58 #define NFS4_dec_cb_null_sz 0
59 #define cb_compound_enc_hdr_sz 4
60 #define cb_compound_dec_hdr_sz (3 + (NFS4_MAXTAGLEN >> 2))
61 #define sessionid_sz (NFS4_MAX_SESSIONID_LEN >> 2)
62 #define cb_sequence_enc_sz (sessionid_sz + 4 + \
64 #define cb_sequence_dec_sz (op_dec_sz + sessionid_sz + 4)
68 #define enc_nfs4_fh_sz (1 + (NFS4_FHSIZE >> 2))
69 #define enc_stateid_sz (NFS4_STATEID_SIZE >> 2)
70 #define NFS4_enc_cb_recall_sz (cb_compound_enc_hdr_sz + \
71 cb_sequence_enc_sz + \
72 1 + enc_stateid_sz + \
75 #define NFS4_dec_cb_recall_sz (cb_compound_dec_hdr_sz + \
76 cb_sequence_dec_sz + \
92 static void print_overflow_msg(
const char *
func,
const struct xdr_stream *xdr)
94 dprintk(
"NFS: %s prematurely hit the end of our receive buffer. "
95 "Remaining buffer length is %tu words.\n",
96 func, xdr->end - xdr->p);
138 static void encode_nfs_cb_opnum4(
struct xdr_stream *xdr,
enum nfs_cb_opnum4 op)
151 static void encode_nfs_fh4(
struct xdr_stream *xdr,
const struct knfsd_fh *fh)
169 static void encode_stateid4(
struct xdr_stream *xdr,
const stateid_t *
sid)
183 static void encode_sessionid4(
struct xdr_stream *xdr,
196 static const struct {
199 } nfs_cb_errtbl[] = {
240 static int nfs_cb_stat_to_errno(
int status)
244 for (i = 0; nfs_cb_errtbl[
i].stat != -1; i++) {
245 if (nfs_cb_errtbl[i].
stat == status)
246 return nfs_cb_errtbl[
i].errno;
249 dprintk(
"NFSD: Unrecognized NFS CB status value: %u\n", status);
253 static int decode_cb_op_status(
struct xdr_stream *xdr,
enum nfs_opnum4 expected,
268 print_overflow_msg(__func__, xdr);
271 dprintk(
"NFSD: Callback server returned operation %d but "
272 "we issued a request for %d\n", op, expected);
286 static void encode_cb_compound4args(
struct xdr_stream *xdr,
292 p = xdr_encode_empty_array(p);
318 static int decode_cb_compound4res(
struct xdr_stream *xdr,
336 print_overflow_msg(__func__, xdr);
349 static void encode_cb_recall4args(
struct xdr_stream *xdr,
356 encode_stateid4(xdr, &dp->
dl_stid.sc_stateid);
361 encode_nfs_fh4(xdr, &dp->
dl_fh);
378 static void encode_cb_sequence4args(
struct xdr_stream *xdr,
389 encode_sessionid4(xdr, session);
396 xdr_encode_empty_array(p);
422 static int decode_cb_sequence4resok(
struct xdr_stream *xdr,
443 dprintk(
"NFS: %s Invalid session id\n", __func__);
450 dprintk(
"NFS: %s Invalid sequence number\n", __func__);
456 dprintk(
"NFS: %s Invalid slotid\n", __func__);
466 nfsd4_mark_cb_fault(cb->
cb_clp, status);
469 print_overflow_msg(__func__, xdr);
473 static int decode_cb_sequence4res(
struct xdr_stream *xdr,
487 status = decode_cb_sequence4resok(xdr, cb);
491 return nfs_cb_stat_to_errno(nfserr);
506 static void nfs4_xdr_enc_cb_null(
struct rpc_rqst *
req,
struct xdr_stream *xdr,
515 static void nfs4_xdr_enc_cb_recall(
struct rpc_rqst *
req,
struct xdr_stream *xdr,
524 encode_cb_compound4args(xdr, &hdr);
525 encode_cb_sequence4args(xdr, cb, &hdr);
526 encode_cb_recall4args(xdr, args, &hdr);
527 encode_cb_nops(&hdr);
540 static int nfs4_xdr_dec_cb_null(
struct rpc_rqst *
req,
struct xdr_stream *xdr,
549 static int nfs4_xdr_dec_cb_recall(
struct rpc_rqst *rqstp,
550 struct xdr_stream *xdr,
557 status = decode_cb_compound4res(xdr, &hdr);
562 status = decode_cb_sequence4res(xdr, cb);
567 status = decode_cb_op_status(xdr,
OP_CB_RECALL, &nfserr);
571 status = nfs_cb_stat_to_errno(nfserr);
579 #define PROC(proc, call, argtype, restype) \
580 [NFSPROC4_CLNT_##proc] = { \
581 .p_proc = NFSPROC4_CB_##call, \
582 .p_encode = (kxdreproc_t)nfs4_xdr_enc_##argtype, \
583 .p_decode = (kxdrdproc_t)nfs4_xdr_dec_##restype, \
584 .p_arglen = NFS4_enc_##argtype##_sz, \
585 .p_replen = NFS4_dec_##restype##_sz, \
586 .p_statidx = NFSPROC4_CB_##call, \
592 PROC(CB_RECALL, COMPOUND, cb_recall, cb_recall),
605 .procs = nfs4_cb_procedures
608 static const struct rpc_version *nfs_cb_version[] = {
615 .program = &cb_program
618 #define NFS4_CALLBACK 0x40000000
623 .version = nfs_cb_version,
625 .pipe_dir_name =
"nfsd4_cb",
628 static int max_cb_time(
void)
636 struct rpc_timeout timeparms = {
637 .to_initval = max_cb_time(),
640 struct rpc_create_args
args = {
645 .timeout = &timeparms,
646 .program = &cb_program,
648 .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
653 if (!clp->
cl_cred.cr_principal &&
654 (clp->
cl_cred.cr_flavor >= RPC_AUTH_GSS_KRB5))
656 args.client_name = clp->
cl_cred.cr_principal;
657 args.prognumber = conn->
cb_prog,
658 args.protocol = XPRT_TRANSPORT_TCP;
659 args.authflavor = clp->
cl_cred.cr_flavor;
668 args.protocol = XPRT_TRANSPORT_BC_TCP;
669 args.authflavor = RPC_AUTH_UNIX;
673 if (IS_ERR(client)) {
674 dprintk(
"NFSD: couldn't create callback client: %ld\n",
676 return PTR_ERR(client);
685 dprintk(
"NFSD: warning: no callback path to client %.*s: error %d\n",
689 static void nfsd4_mark_cb_down(
struct nfs4_client *clp,
int reason)
692 warn_no_callback_path(clp, reason);
695 static void nfsd4_mark_cb_fault(
struct nfs4_client *clp,
int reason)
698 warn_no_callback_path(clp, reason);
701 static void nfsd4_cb_probe_done(
struct rpc_task *
task,
void *calldata)
706 nfsd4_mark_cb_down(clp, task->
tk_status);
714 .rpc_call_done = nfsd4_cb_probe_done,
717 static struct rpc_cred *callback_cred;
736 static void do_probe_callback(
struct nfs4_client *clp)
746 cb->
cb_msg.rpc_cred = callback_cred;
748 cb->
cb_ops = &nfsd4_cb_probe_ops;
761 do_probe_callback(clp);
787 dprintk(
"%s slot is busy\n", __func__);
797 static void nfsd4_cb_prepare(
struct rpc_task *task,
void *calldata)
806 if (!nfsd41_cb_get_slot(clp, task))
819 static void nfsd4_cb_done(
struct rpc_task *task,
void *calldata)
825 dprintk(
"%s: minorversion=%d\n", __func__,
833 dprintk(
"%s: freed slot, new seqid=%d\n", __func__,
842 static void nfsd4_cb_recall_done(
struct rpc_task *task,
void *calldata)
849 nfsd4_cb_done(task, calldata);
851 if (current_rpc_client != task->
tk_client) {
871 nfsd4_mark_cb_down(clp, task->
tk_status);
879 nfsd4_mark_cb_down(clp, task->
tk_status);
883 static void nfsd4_cb_recall_release(
void *calldata)
897 static const struct rpc_call_ops nfsd4_cb_recall_ops = {
898 .rpc_call_prepare = nfsd4_cb_prepare,
899 .rpc_call_done = nfsd4_cb_recall_done,
900 .rpc_release = nfsd4_cb_recall_release,
925 do_probe_callback(clp);
931 if (cb->
cb_ops->rpc_release)
932 cb->
cb_ops->rpc_release(cb);
980 c = __nfsd4_find_backchannel(clp);
988 err = setup_callback_client(clp, &conn, ses);
990 nfsd4_mark_cb_down(clp, err);
1005 nfsd4_process_cb_update(cb);
1010 nfsd4_release_cb(cb);
1026 cb->
cb_msg.rpc_argp = cb;
1027 cb->
cb_msg.rpc_resp = cb;
1028 cb->
cb_msg.rpc_cred = callback_cred;
1030 cb->
cb_ops = &nfsd4_cb_recall_ops;