aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/nfs4callback.c
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@citi.umich.edu>2010-06-04 20:04:45 -0400
committerJ. Bruce Fields <bfields@redhat.com>2010-10-01 19:29:44 -0400
commit6ff8da088766d70f0441feb982b82978a6cbf7ef (patch)
tree7d0e90e4e03323fec67a972cdff60c9b8a96925a /fs/nfsd/nfs4callback.c
parentfb003923263c3f0cb02adbd56a22fe16ef5c0e77 (diff)
nfsd4: Move callback setup to callback queue
Instead of creating the new rpc client from a regular server thread, set a flag, kick off a null call, and allow the null call to do the work of setting up the client on the callback workqueue. Use a spinlock to ensure the callback work gets a consistent view of the callback parameters. This allows, for example, changing the callback from contexts where sleeping is not allowed. I hope it will also keep the locking simple as we add more session and trunking features, by serializing most of the callback-specific work. This also closes a small race where the the new cb_ident could be used with an old connection (or vice-versa). Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'fs/nfsd/nfs4callback.c')
-rw-r--r--fs/nfsd/nfs4callback.c73
1 files changed, 52 insertions, 21 deletions
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 07c3be6eea6..a269dbeff15 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -284,7 +284,7 @@ nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, __be32 *p,
284 struct xdr_stream xdr; 284 struct xdr_stream xdr;
285 struct nfs4_delegation *args = cb->cb_op; 285 struct nfs4_delegation *args = cb->cb_op;
286 struct nfs4_cb_compound_hdr hdr = { 286 struct nfs4_cb_compound_hdr hdr = {
287 .ident = args->dl_ident, 287 .ident = cb->cb_clp->cl_cb_ident,
288 .minorversion = cb->cb_minorversion, 288 .minorversion = cb->cb_minorversion,
289 }; 289 };
290 290
@@ -506,7 +506,8 @@ int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
506 PTR_ERR(client)); 506 PTR_ERR(client));
507 return PTR_ERR(client); 507 return PTR_ERR(client);
508 } 508 }
509 nfsd4_set_callback_client(clp, client); 509 clp->cl_cb_ident = conn->cb_ident;
510 clp->cl_cb_client = client;
510 return 0; 511 return 0;
511 512
512} 513}
@@ -569,15 +570,12 @@ void do_probe_callback(struct nfs4_client *clp)
569 */ 570 */
570void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn) 571void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
571{ 572{
572 int status;
573
574 BUG_ON(atomic_read(&clp->cl_cb_set)); 573 BUG_ON(atomic_read(&clp->cl_cb_set));
575 574
576 status = setup_callback_client(clp, conn); 575 spin_lock(&clp->cl_lock);
577 if (status) { 576 memcpy(&clp->cl_cb_conn, conn, sizeof(struct nfs4_cb_conn));
578 warn_no_callback_path(clp, status); 577 set_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags);
579 return; 578 spin_unlock(&clp->cl_lock);
580 }
581 do_probe_callback(clp); 579 do_probe_callback(clp);
582} 580}
583 581
@@ -730,19 +728,16 @@ void nfsd4_destroy_callback_queue(void)
730} 728}
731 729
732/* must be called under the state lock */ 730/* must be called under the state lock */
733void nfsd4_set_callback_client(struct nfs4_client *clp, struct rpc_clnt *new) 731void nfsd4_shutdown_callback(struct nfs4_client *clp)
734{ 732{
735 struct rpc_clnt *old = clp->cl_cb_client; 733 set_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags);
736
737 clp->cl_cb_client = new;
738 /* 734 /*
739 * After this, any work that saw the old value of cl_cb_client will 735 * Note this won't actually result in a null callback;
740 * be gone: 736 * instead, nfsd4_do_callback_rpc() will detect the killed
737 * client, destroy the rpc client, and stop:
741 */ 738 */
739 do_probe_callback(clp);
742 flush_workqueue(callback_wq); 740 flush_workqueue(callback_wq);
743 /* So we can safely shut it down: */
744 if (old)
745 rpc_shutdown_client(old);
746} 741}
747 742
748void nfsd4_release_cb(struct nfsd4_callback *cb) 743void nfsd4_release_cb(struct nfsd4_callback *cb)
@@ -751,15 +746,51 @@ void nfsd4_release_cb(struct nfsd4_callback *cb)
751 cb->cb_ops->rpc_release(cb); 746 cb->cb_ops->rpc_release(cb);
752} 747}
753 748
749void nfsd4_process_cb_update(struct nfsd4_callback *cb)
750{
751 struct nfs4_cb_conn conn;
752 struct nfs4_client *clp = cb->cb_clp;
753 int err;
754
755 /*
756 * This is either an update, or the client dying; in either case,
757 * kill the old client:
758 */
759 if (clp->cl_cb_client) {
760 rpc_shutdown_client(clp->cl_cb_client);
761 clp->cl_cb_client = NULL;
762 }
763 if (test_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags))
764 return;
765 spin_lock(&clp->cl_lock);
766 /*
767 * Only serialized callback code is allowed to clear these
768 * flags; main nfsd code can only set them:
769 */
770 BUG_ON(!clp->cl_cb_flags);
771 clear_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags);
772 memcpy(&conn, &cb->cb_clp->cl_cb_conn, sizeof(struct nfs4_cb_conn));
773 spin_unlock(&clp->cl_lock);
774
775 err = setup_callback_client(clp, &conn);
776 if (err)
777 warn_no_callback_path(clp, err);
778}
779
754void nfsd4_do_callback_rpc(struct work_struct *w) 780void nfsd4_do_callback_rpc(struct work_struct *w)
755{ 781{
756 struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback, cb_work); 782 struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback, cb_work);
757 struct nfs4_client *clp = cb->cb_clp; 783 struct nfs4_client *clp = cb->cb_clp;
758 struct rpc_clnt *clnt = clp->cl_cb_client; 784 struct rpc_clnt *clnt;
759 785
760 if (clnt == NULL) { 786 if (clp->cl_cb_flags)
787 nfsd4_process_cb_update(cb);
788
789 clnt = clp->cl_cb_client;
790 if (!clnt) {
791 /* Callback channel broken, or client killed; give up: */
761 nfsd4_release_cb(cb); 792 nfsd4_release_cb(cb);
762 return; /* Client is shutting down; give up. */ 793 return;
763 } 794 }
764 rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN, 795 rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
765 cb->cb_ops, cb); 796 cb->cb_ops, cb);