diff options
Diffstat (limited to 'fs/nfsd/nfs4callback.c')
-rw-r--r-- | fs/nfsd/nfs4callback.c | 245 |
1 files changed, 139 insertions, 106 deletions
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 988cbb3a19b6..143da2eecd7b 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c | |||
@@ -41,7 +41,6 @@ | |||
41 | 41 | ||
42 | #define NFSPROC4_CB_NULL 0 | 42 | #define NFSPROC4_CB_NULL 0 |
43 | #define NFSPROC4_CB_COMPOUND 1 | 43 | #define NFSPROC4_CB_COMPOUND 1 |
44 | #define NFS4_STATEID_SIZE 16 | ||
45 | 44 | ||
46 | /* Index of predefined Linux callback client operations */ | 45 | /* Index of predefined Linux callback client operations */ |
47 | 46 | ||
@@ -248,10 +247,11 @@ encode_cb_recall(struct xdr_stream *xdr, struct nfs4_delegation *dp, | |||
248 | } | 247 | } |
249 | 248 | ||
250 | static void | 249 | static void |
251 | encode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_cb_sequence *args, | 250 | encode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_callback *cb, |
252 | struct nfs4_cb_compound_hdr *hdr) | 251 | struct nfs4_cb_compound_hdr *hdr) |
253 | { | 252 | { |
254 | __be32 *p; | 253 | __be32 *p; |
254 | struct nfsd4_session *ses = cb->cb_clp->cl_cb_session; | ||
255 | 255 | ||
256 | if (hdr->minorversion == 0) | 256 | if (hdr->minorversion == 0) |
257 | return; | 257 | return; |
@@ -259,8 +259,8 @@ encode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_cb_sequence *args, | |||
259 | RESERVE_SPACE(1 + NFS4_MAX_SESSIONID_LEN + 20); | 259 | RESERVE_SPACE(1 + NFS4_MAX_SESSIONID_LEN + 20); |
260 | 260 | ||
261 | WRITE32(OP_CB_SEQUENCE); | 261 | WRITE32(OP_CB_SEQUENCE); |
262 | WRITEMEM(args->cbs_clp->cl_sessionid.data, NFS4_MAX_SESSIONID_LEN); | 262 | WRITEMEM(ses->se_sessionid.data, NFS4_MAX_SESSIONID_LEN); |
263 | WRITE32(args->cbs_clp->cl_cb_seq_nr); | 263 | WRITE32(ses->se_cb_seq_nr); |
264 | WRITE32(0); /* slotid, always 0 */ | 264 | WRITE32(0); /* slotid, always 0 */ |
265 | WRITE32(0); /* highest slotid always 0 */ | 265 | WRITE32(0); /* highest slotid always 0 */ |
266 | WRITE32(0); /* cachethis always 0 */ | 266 | WRITE32(0); /* cachethis always 0 */ |
@@ -280,18 +280,18 @@ nfs4_xdr_enc_cb_null(struct rpc_rqst *req, __be32 *p) | |||
280 | 280 | ||
281 | static int | 281 | static int |
282 | nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, __be32 *p, | 282 | nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, __be32 *p, |
283 | struct nfs4_rpc_args *rpc_args) | 283 | struct nfsd4_callback *cb) |
284 | { | 284 | { |
285 | struct xdr_stream xdr; | 285 | struct xdr_stream xdr; |
286 | struct nfs4_delegation *args = rpc_args->args_op; | 286 | struct nfs4_delegation *args = cb->cb_op; |
287 | struct nfs4_cb_compound_hdr hdr = { | 287 | struct nfs4_cb_compound_hdr hdr = { |
288 | .ident = args->dl_ident, | 288 | .ident = cb->cb_clp->cl_cb_ident, |
289 | .minorversion = rpc_args->args_seq.cbs_minorversion, | 289 | .minorversion = cb->cb_minorversion, |
290 | }; | 290 | }; |
291 | 291 | ||
292 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 292 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
293 | encode_cb_compound_hdr(&xdr, &hdr); | 293 | encode_cb_compound_hdr(&xdr, &hdr); |
294 | encode_cb_sequence(&xdr, &rpc_args->args_seq, &hdr); | 294 | encode_cb_sequence(&xdr, cb, &hdr); |
295 | encode_cb_recall(&xdr, args, &hdr); | 295 | encode_cb_recall(&xdr, args, &hdr); |
296 | encode_cb_nops(&hdr); | 296 | encode_cb_nops(&hdr); |
297 | return 0; | 297 | return 0; |
@@ -339,15 +339,16 @@ decode_cb_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) | |||
339 | * with a single slot. | 339 | * with a single slot. |
340 | */ | 340 | */ |
341 | static int | 341 | static int |
342 | decode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_cb_sequence *res, | 342 | decode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_callback *cb, |
343 | struct rpc_rqst *rqstp) | 343 | struct rpc_rqst *rqstp) |
344 | { | 344 | { |
345 | struct nfsd4_session *ses = cb->cb_clp->cl_cb_session; | ||
345 | struct nfs4_sessionid id; | 346 | struct nfs4_sessionid id; |
346 | int status; | 347 | int status; |
347 | u32 dummy; | 348 | u32 dummy; |
348 | __be32 *p; | 349 | __be32 *p; |
349 | 350 | ||
350 | if (res->cbs_minorversion == 0) | 351 | if (cb->cb_minorversion == 0) |
351 | return 0; | 352 | return 0; |
352 | 353 | ||
353 | status = decode_cb_op_hdr(xdr, OP_CB_SEQUENCE); | 354 | status = decode_cb_op_hdr(xdr, OP_CB_SEQUENCE); |
@@ -363,13 +364,12 @@ decode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_cb_sequence *res, | |||
363 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); | 364 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); |
364 | memcpy(id.data, p, NFS4_MAX_SESSIONID_LEN); | 365 | memcpy(id.data, p, NFS4_MAX_SESSIONID_LEN); |
365 | p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN); | 366 | p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN); |
366 | if (memcmp(id.data, res->cbs_clp->cl_sessionid.data, | 367 | if (memcmp(id.data, ses->se_sessionid.data, NFS4_MAX_SESSIONID_LEN)) { |
367 | NFS4_MAX_SESSIONID_LEN)) { | ||
368 | dprintk("%s Invalid session id\n", __func__); | 368 | dprintk("%s Invalid session id\n", __func__); |
369 | goto out; | 369 | goto out; |
370 | } | 370 | } |
371 | READ32(dummy); | 371 | READ32(dummy); |
372 | if (dummy != res->cbs_clp->cl_cb_seq_nr) { | 372 | if (dummy != ses->se_cb_seq_nr) { |
373 | dprintk("%s Invalid sequence number\n", __func__); | 373 | dprintk("%s Invalid sequence number\n", __func__); |
374 | goto out; | 374 | goto out; |
375 | } | 375 | } |
@@ -393,7 +393,7 @@ nfs4_xdr_dec_cb_null(struct rpc_rqst *req, __be32 *p) | |||
393 | 393 | ||
394 | static int | 394 | static int |
395 | nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, __be32 *p, | 395 | nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, __be32 *p, |
396 | struct nfsd4_cb_sequence *seq) | 396 | struct nfsd4_callback *cb) |
397 | { | 397 | { |
398 | struct xdr_stream xdr; | 398 | struct xdr_stream xdr; |
399 | struct nfs4_cb_compound_hdr hdr; | 399 | struct nfs4_cb_compound_hdr hdr; |
@@ -403,8 +403,8 @@ nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, __be32 *p, | |||
403 | status = decode_cb_compound_hdr(&xdr, &hdr); | 403 | status = decode_cb_compound_hdr(&xdr, &hdr); |
404 | if (status) | 404 | if (status) |
405 | goto out; | 405 | goto out; |
406 | if (seq) { | 406 | if (cb) { |
407 | status = decode_cb_sequence(&xdr, seq, rqstp); | 407 | status = decode_cb_sequence(&xdr, cb, rqstp); |
408 | if (status) | 408 | if (status) |
409 | goto out; | 409 | goto out; |
410 | } | 410 | } |
@@ -473,30 +473,34 @@ static int max_cb_time(void) | |||
473 | /* Reference counting, callback cleanup, etc., all look racy as heck. | 473 | /* Reference counting, callback cleanup, etc., all look racy as heck. |
474 | * And why is cl_cb_set an atomic? */ | 474 | * And why is cl_cb_set an atomic? */ |
475 | 475 | ||
476 | int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | 476 | int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *conn) |
477 | { | 477 | { |
478 | struct rpc_timeout timeparms = { | 478 | struct rpc_timeout timeparms = { |
479 | .to_initval = max_cb_time(), | 479 | .to_initval = max_cb_time(), |
480 | .to_retries = 0, | 480 | .to_retries = 0, |
481 | }; | 481 | }; |
482 | struct rpc_create_args args = { | 482 | struct rpc_create_args args = { |
483 | .protocol = XPRT_TRANSPORT_TCP, | 483 | .net = &init_net, |
484 | .address = (struct sockaddr *) &cb->cb_addr, | 484 | .address = (struct sockaddr *) &conn->cb_addr, |
485 | .addrsize = cb->cb_addrlen, | 485 | .addrsize = conn->cb_addrlen, |
486 | .timeout = &timeparms, | 486 | .timeout = &timeparms, |
487 | .program = &cb_program, | 487 | .program = &cb_program, |
488 | .prognumber = cb->cb_prog, | ||
489 | .version = 0, | 488 | .version = 0, |
490 | .authflavor = clp->cl_flavor, | 489 | .authflavor = clp->cl_flavor, |
491 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), | 490 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), |
492 | .client_name = clp->cl_principal, | ||
493 | }; | 491 | }; |
494 | struct rpc_clnt *client; | 492 | struct rpc_clnt *client; |
495 | 493 | ||
496 | if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) | 494 | if (clp->cl_minorversion == 0) { |
497 | return -EINVAL; | 495 | if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) |
498 | if (cb->cb_minorversion) { | 496 | return -EINVAL; |
499 | args.bc_xprt = cb->cb_xprt; | 497 | args.client_name = clp->cl_principal; |
498 | args.prognumber = conn->cb_prog, | ||
499 | args.protocol = XPRT_TRANSPORT_TCP; | ||
500 | clp->cl_cb_ident = conn->cb_ident; | ||
501 | } else { | ||
502 | args.bc_xprt = conn->cb_xprt; | ||
503 | args.prognumber = clp->cl_cb_session->se_cb_prog; | ||
500 | args.protocol = XPRT_TRANSPORT_BC_TCP; | 504 | args.protocol = XPRT_TRANSPORT_BC_TCP; |
501 | } | 505 | } |
502 | /* Create RPC client */ | 506 | /* Create RPC client */ |
@@ -506,7 +510,7 @@ int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | |||
506 | PTR_ERR(client)); | 510 | PTR_ERR(client)); |
507 | return PTR_ERR(client); | 511 | return PTR_ERR(client); |
508 | } | 512 | } |
509 | nfsd4_set_callback_client(clp, client); | 513 | clp->cl_cb_client = client; |
510 | return 0; | 514 | return 0; |
511 | 515 | ||
512 | } | 516 | } |
@@ -519,7 +523,7 @@ static void warn_no_callback_path(struct nfs4_client *clp, int reason) | |||
519 | 523 | ||
520 | static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) | 524 | static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) |
521 | { | 525 | { |
522 | struct nfs4_client *clp = calldata; | 526 | struct nfs4_client *clp = container_of(calldata, struct nfs4_client, cl_cb_null); |
523 | 527 | ||
524 | if (task->tk_status) | 528 | if (task->tk_status) |
525 | warn_no_callback_path(clp, task->tk_status); | 529 | warn_no_callback_path(clp, task->tk_status); |
@@ -528,6 +532,8 @@ static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) | |||
528 | } | 532 | } |
529 | 533 | ||
530 | static const struct rpc_call_ops nfsd4_cb_probe_ops = { | 534 | static const struct rpc_call_ops nfsd4_cb_probe_ops = { |
535 | /* XXX: release method to ensure we set the cb channel down if | ||
536 | * necessary on early failure? */ | ||
531 | .rpc_call_done = nfsd4_cb_probe_done, | 537 | .rpc_call_done = nfsd4_cb_probe_done, |
532 | }; | 538 | }; |
533 | 539 | ||
@@ -543,38 +549,42 @@ int set_callback_cred(void) | |||
543 | return 0; | 549 | return 0; |
544 | } | 550 | } |
545 | 551 | ||
552 | static struct workqueue_struct *callback_wq; | ||
546 | 553 | ||
547 | void do_probe_callback(struct nfs4_client *clp) | 554 | static void do_probe_callback(struct nfs4_client *clp) |
548 | { | 555 | { |
549 | struct rpc_message msg = { | 556 | struct nfsd4_callback *cb = &clp->cl_cb_null; |
550 | .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], | ||
551 | .rpc_argp = clp, | ||
552 | .rpc_cred = callback_cred | ||
553 | }; | ||
554 | int status; | ||
555 | 557 | ||
556 | status = rpc_call_async(clp->cl_cb_client, &msg, | 558 | cb->cb_op = NULL; |
557 | RPC_TASK_SOFT | RPC_TASK_SOFTCONN, | 559 | cb->cb_clp = clp; |
558 | &nfsd4_cb_probe_ops, (void *)clp); | 560 | |
559 | if (status) | 561 | cb->cb_msg.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL]; |
560 | warn_no_callback_path(clp, status); | 562 | cb->cb_msg.rpc_argp = NULL; |
563 | cb->cb_msg.rpc_resp = NULL; | ||
564 | cb->cb_msg.rpc_cred = callback_cred; | ||
565 | |||
566 | cb->cb_ops = &nfsd4_cb_probe_ops; | ||
567 | |||
568 | queue_work(callback_wq, &cb->cb_work); | ||
561 | } | 569 | } |
562 | 570 | ||
563 | /* | 571 | /* |
564 | * Set up the callback client and put a NFSPROC4_CB_NULL on the wire... | 572 | * Poke the callback thread to process any updates to the callback |
573 | * parameters, and send a null probe. | ||
565 | */ | 574 | */ |
566 | void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | 575 | void nfsd4_probe_callback(struct nfs4_client *clp) |
567 | { | 576 | { |
568 | int status; | 577 | set_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags); |
578 | do_probe_callback(clp); | ||
579 | } | ||
569 | 580 | ||
581 | void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn) | ||
582 | { | ||
570 | BUG_ON(atomic_read(&clp->cl_cb_set)); | 583 | BUG_ON(atomic_read(&clp->cl_cb_set)); |
571 | 584 | ||
572 | status = setup_callback_client(clp, cb); | 585 | spin_lock(&clp->cl_lock); |
573 | if (status) { | 586 | memcpy(&clp->cl_cb_conn, conn, sizeof(struct nfs4_cb_conn)); |
574 | warn_no_callback_path(clp, status); | 587 | spin_unlock(&clp->cl_lock); |
575 | return; | ||
576 | } | ||
577 | do_probe_callback(clp); | ||
578 | } | 588 | } |
579 | 589 | ||
580 | /* | 590 | /* |
@@ -585,8 +595,7 @@ void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | |||
585 | static int nfsd41_cb_setup_sequence(struct nfs4_client *clp, | 595 | static int nfsd41_cb_setup_sequence(struct nfs4_client *clp, |
586 | struct rpc_task *task) | 596 | struct rpc_task *task) |
587 | { | 597 | { |
588 | struct nfs4_rpc_args *args = task->tk_msg.rpc_argp; | 598 | u32 *ptr = (u32 *)clp->cl_cb_session->se_sessionid.data; |
589 | u32 *ptr = (u32 *)clp->cl_sessionid.data; | ||
590 | int status = 0; | 599 | int status = 0; |
591 | 600 | ||
592 | dprintk("%s: %u:%u:%u:%u\n", __func__, | 601 | dprintk("%s: %u:%u:%u:%u\n", __func__, |
@@ -598,14 +607,6 @@ static int nfsd41_cb_setup_sequence(struct nfs4_client *clp, | |||
598 | status = -EAGAIN; | 607 | status = -EAGAIN; |
599 | goto out; | 608 | goto out; |
600 | } | 609 | } |
601 | |||
602 | /* | ||
603 | * We'll need the clp during XDR encoding and decoding, | ||
604 | * and the sequence during decoding to verify the reply | ||
605 | */ | ||
606 | args->args_seq.cbs_clp = clp; | ||
607 | task->tk_msg.rpc_resp = &args->args_seq; | ||
608 | |||
609 | out: | 610 | out: |
610 | dprintk("%s status=%d\n", __func__, status); | 611 | dprintk("%s status=%d\n", __func__, status); |
611 | return status; | 612 | return status; |
@@ -617,13 +618,13 @@ out: | |||
617 | */ | 618 | */ |
618 | static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) | 619 | static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) |
619 | { | 620 | { |
620 | struct nfs4_delegation *dp = calldata; | 621 | struct nfsd4_callback *cb = calldata; |
622 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
621 | struct nfs4_client *clp = dp->dl_client; | 623 | struct nfs4_client *clp = dp->dl_client; |
622 | struct nfs4_rpc_args *args = task->tk_msg.rpc_argp; | 624 | u32 minorversion = clp->cl_minorversion; |
623 | u32 minorversion = clp->cl_cb_conn.cb_minorversion; | ||
624 | int status = 0; | 625 | int status = 0; |
625 | 626 | ||
626 | args->args_seq.cbs_minorversion = minorversion; | 627 | cb->cb_minorversion = minorversion; |
627 | if (minorversion) { | 628 | if (minorversion) { |
628 | status = nfsd41_cb_setup_sequence(clp, task); | 629 | status = nfsd41_cb_setup_sequence(clp, task); |
629 | if (status) { | 630 | if (status) { |
@@ -640,19 +641,20 @@ static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) | |||
640 | 641 | ||
641 | static void nfsd4_cb_done(struct rpc_task *task, void *calldata) | 642 | static void nfsd4_cb_done(struct rpc_task *task, void *calldata) |
642 | { | 643 | { |
643 | struct nfs4_delegation *dp = calldata; | 644 | struct nfsd4_callback *cb = calldata; |
645 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
644 | struct nfs4_client *clp = dp->dl_client; | 646 | struct nfs4_client *clp = dp->dl_client; |
645 | 647 | ||
646 | dprintk("%s: minorversion=%d\n", __func__, | 648 | dprintk("%s: minorversion=%d\n", __func__, |
647 | clp->cl_cb_conn.cb_minorversion); | 649 | clp->cl_minorversion); |
648 | 650 | ||
649 | if (clp->cl_cb_conn.cb_minorversion) { | 651 | if (clp->cl_minorversion) { |
650 | /* No need for lock, access serialized in nfsd4_cb_prepare */ | 652 | /* No need for lock, access serialized in nfsd4_cb_prepare */ |
651 | ++clp->cl_cb_seq_nr; | 653 | ++clp->cl_cb_session->se_cb_seq_nr; |
652 | clear_bit(0, &clp->cl_cb_slot_busy); | 654 | clear_bit(0, &clp->cl_cb_slot_busy); |
653 | rpc_wake_up_next(&clp->cl_cb_waitq); | 655 | rpc_wake_up_next(&clp->cl_cb_waitq); |
654 | dprintk("%s: freed slot, new seqid=%d\n", __func__, | 656 | dprintk("%s: freed slot, new seqid=%d\n", __func__, |
655 | clp->cl_cb_seq_nr); | 657 | clp->cl_cb_session->se_cb_seq_nr); |
656 | 658 | ||
657 | /* We're done looking into the sequence information */ | 659 | /* We're done looking into the sequence information */ |
658 | task->tk_msg.rpc_resp = NULL; | 660 | task->tk_msg.rpc_resp = NULL; |
@@ -662,7 +664,8 @@ static void nfsd4_cb_done(struct rpc_task *task, void *calldata) | |||
662 | 664 | ||
663 | static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) | 665 | static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) |
664 | { | 666 | { |
665 | struct nfs4_delegation *dp = calldata; | 667 | struct nfsd4_callback *cb = calldata; |
668 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
666 | struct nfs4_client *clp = dp->dl_client; | 669 | struct nfs4_client *clp = dp->dl_client; |
667 | struct rpc_clnt *current_rpc_client = clp->cl_cb_client; | 670 | struct rpc_clnt *current_rpc_client = clp->cl_cb_client; |
668 | 671 | ||
@@ -707,7 +710,8 @@ static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) | |||
707 | 710 | ||
708 | static void nfsd4_cb_recall_release(void *calldata) | 711 | static void nfsd4_cb_recall_release(void *calldata) |
709 | { | 712 | { |
710 | struct nfs4_delegation *dp = calldata; | 713 | struct nfsd4_callback *cb = calldata; |
714 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
711 | 715 | ||
712 | nfs4_put_delegation(dp); | 716 | nfs4_put_delegation(dp); |
713 | } | 717 | } |
@@ -718,8 +722,6 @@ static const struct rpc_call_ops nfsd4_cb_recall_ops = { | |||
718 | .rpc_release = nfsd4_cb_recall_release, | 722 | .rpc_release = nfsd4_cb_recall_release, |
719 | }; | 723 | }; |
720 | 724 | ||
721 | static struct workqueue_struct *callback_wq; | ||
722 | |||
723 | int nfsd4_create_callback_queue(void) | 725 | int nfsd4_create_callback_queue(void) |
724 | { | 726 | { |
725 | callback_wq = create_singlethread_workqueue("nfsd4_callbacks"); | 727 | callback_wq = create_singlethread_workqueue("nfsd4_callbacks"); |
@@ -734,57 +736,88 @@ void nfsd4_destroy_callback_queue(void) | |||
734 | } | 736 | } |
735 | 737 | ||
736 | /* must be called under the state lock */ | 738 | /* must be called under the state lock */ |
737 | void nfsd4_set_callback_client(struct nfs4_client *clp, struct rpc_clnt *new) | 739 | void nfsd4_shutdown_callback(struct nfs4_client *clp) |
738 | { | 740 | { |
739 | struct rpc_clnt *old = clp->cl_cb_client; | 741 | set_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags); |
740 | |||
741 | clp->cl_cb_client = new; | ||
742 | /* | 742 | /* |
743 | * After this, any work that saw the old value of cl_cb_client will | 743 | * Note this won't actually result in a null callback; |
744 | * be gone: | 744 | * instead, nfsd4_do_callback_rpc() will detect the killed |
745 | * client, destroy the rpc client, and stop: | ||
745 | */ | 746 | */ |
747 | do_probe_callback(clp); | ||
746 | flush_workqueue(callback_wq); | 748 | flush_workqueue(callback_wq); |
747 | /* So we can safely shut it down: */ | ||
748 | if (old) | ||
749 | rpc_shutdown_client(old); | ||
750 | } | 749 | } |
751 | 750 | ||
752 | /* | 751 | void nfsd4_release_cb(struct nfsd4_callback *cb) |
753 | * called with dp->dl_count inc'ed. | ||
754 | */ | ||
755 | static void _nfsd4_cb_recall(struct nfs4_delegation *dp) | ||
756 | { | 752 | { |
757 | struct nfs4_client *clp = dp->dl_client; | 753 | if (cb->cb_ops->rpc_release) |
758 | struct rpc_clnt *clnt = clp->cl_cb_client; | 754 | cb->cb_ops->rpc_release(cb); |
759 | struct nfs4_rpc_args *args = &dp->dl_recall.cb_args; | 755 | } |
760 | struct rpc_message msg = { | ||
761 | .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL], | ||
762 | .rpc_cred = callback_cred | ||
763 | }; | ||
764 | 756 | ||
765 | if (clnt == NULL) { | 757 | void nfsd4_process_cb_update(struct nfsd4_callback *cb) |
766 | nfs4_put_delegation(dp); | 758 | { |
767 | return; /* Client is shutting down; give up. */ | 759 | struct nfs4_cb_conn conn; |
760 | struct nfs4_client *clp = cb->cb_clp; | ||
761 | int err; | ||
762 | |||
763 | /* | ||
764 | * This is either an update, or the client dying; in either case, | ||
765 | * kill the old client: | ||
766 | */ | ||
767 | if (clp->cl_cb_client) { | ||
768 | rpc_shutdown_client(clp->cl_cb_client); | ||
769 | clp->cl_cb_client = NULL; | ||
768 | } | 770 | } |
771 | if (test_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags)) | ||
772 | return; | ||
773 | spin_lock(&clp->cl_lock); | ||
774 | /* | ||
775 | * Only serialized callback code is allowed to clear these | ||
776 | * flags; main nfsd code can only set them: | ||
777 | */ | ||
778 | BUG_ON(!clp->cl_cb_flags); | ||
779 | clear_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags); | ||
780 | memcpy(&conn, &cb->cb_clp->cl_cb_conn, sizeof(struct nfs4_cb_conn)); | ||
781 | spin_unlock(&clp->cl_lock); | ||
769 | 782 | ||
770 | args->args_op = dp; | 783 | err = setup_callback_client(clp, &conn); |
771 | msg.rpc_argp = args; | 784 | if (err) |
772 | dp->dl_retries = 1; | 785 | warn_no_callback_path(clp, err); |
773 | rpc_call_async(clnt, &msg, RPC_TASK_SOFT, &nfsd4_cb_recall_ops, dp); | ||
774 | } | 786 | } |
775 | 787 | ||
776 | void nfsd4_do_callback_rpc(struct work_struct *w) | 788 | void nfsd4_do_callback_rpc(struct work_struct *w) |
777 | { | 789 | { |
778 | /* XXX: for now, just send off delegation recall. */ | 790 | struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback, cb_work); |
779 | /* In future, generalize to handle any sort of callback. */ | 791 | struct nfs4_client *clp = cb->cb_clp; |
780 | struct nfsd4_callback *c = container_of(w, struct nfsd4_callback, cb_work); | 792 | struct rpc_clnt *clnt; |
781 | struct nfs4_delegation *dp = container_of(c, struct nfs4_delegation, dl_recall); | ||
782 | 793 | ||
783 | _nfsd4_cb_recall(dp); | 794 | if (clp->cl_cb_flags) |
784 | } | 795 | nfsd4_process_cb_update(cb); |
785 | 796 | ||
797 | clnt = clp->cl_cb_client; | ||
798 | if (!clnt) { | ||
799 | /* Callback channel broken, or client killed; give up: */ | ||
800 | nfsd4_release_cb(cb); | ||
801 | return; | ||
802 | } | ||
803 | rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN, | ||
804 | cb->cb_ops, cb); | ||
805 | } | ||
786 | 806 | ||
787 | void nfsd4_cb_recall(struct nfs4_delegation *dp) | 807 | void nfsd4_cb_recall(struct nfs4_delegation *dp) |
788 | { | 808 | { |
809 | struct nfsd4_callback *cb = &dp->dl_recall; | ||
810 | |||
811 | dp->dl_retries = 1; | ||
812 | cb->cb_op = dp; | ||
813 | cb->cb_clp = dp->dl_client; | ||
814 | cb->cb_msg.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL]; | ||
815 | cb->cb_msg.rpc_argp = cb; | ||
816 | cb->cb_msg.rpc_resp = cb; | ||
817 | cb->cb_msg.rpc_cred = callback_cred; | ||
818 | |||
819 | cb->cb_ops = &nfsd4_cb_recall_ops; | ||
820 | dp->dl_retries = 1; | ||
821 | |||
789 | queue_work(callback_wq, &dp->dl_recall.cb_work); | 822 | queue_work(callback_wq, &dp->dl_recall.cb_work); |
790 | } | 823 | } |