NFS: Add global helper to set up a stand-along nfs4_slot_table
authorChuck Lever <chuck.lever@oracle.com>
Fri, 9 Aug 2013 16:48:53 +0000 (12:48 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Tue, 3 Sep 2013 19:26:34 +0000 (15:26 -0400)
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/nfs4session.c
fs/nfs/nfs4session.h

index 746675b74624daee5fe08585aff72879f478c834..be273c589b039930fa2541c83af26a15b0c94822 100644 (file)
 
 #define NFSDBG_FACILITY                NFSDBG_STATE
 
+static void nfs4_init_slot_table(struct nfs4_slot_table *tbl, const char *queue)
+{
+       tbl->highest_used_slotid = NFS4_NO_SLOT;
+       spin_lock_init(&tbl->slot_tbl_lock);
+       rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, queue);
+       init_completion(&tbl->complete);
+}
+
 /*
  * nfs4_shrink_slot_table - free retired slots from the slot table
  */
@@ -223,6 +231,21 @@ out:
        return ret;
 }
 
+/**
+ * nfs4_setup_slot_table - prepare a stand-alone slot table for use
+ * @tbl: slot table to set up
+ * @max_reqs: maximum number of requests allowed
+ * @queue: name to give RPC wait queue
+ *
+ * Returns zero on success, or a negative errno.
+ */
+int nfs4_setup_slot_table(struct nfs4_slot_table *tbl, unsigned int max_reqs,
+               const char *queue)
+{
+       nfs4_init_slot_table(tbl, queue);
+       return nfs4_realloc_slot_table(tbl, max_reqs, 0);
+}
+
 static bool nfs41_assign_slot(struct rpc_task *task, void *pslot)
 {
        struct nfs4_sequence_args *args = task->tk_msg.rpc_argp;
@@ -425,24 +448,13 @@ int nfs4_setup_session_slot_tables(struct nfs4_session *ses)
 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
 {
        struct nfs4_session *session;
-       struct nfs4_slot_table *tbl;
 
        session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
        if (!session)
                return NULL;
 
-       tbl = &session->fc_slot_table;
-       tbl->highest_used_slotid = NFS4_NO_SLOT;
-       spin_lock_init(&tbl->slot_tbl_lock);
-       rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
-       init_completion(&tbl->complete);
-
-       tbl = &session->bc_slot_table;
-       tbl->highest_used_slotid = NFS4_NO_SLOT;
-       spin_lock_init(&tbl->slot_tbl_lock);
-       rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
-       init_completion(&tbl->complete);
-
+       nfs4_init_slot_table(&session->fc_slot_table, "ForeChannel Slot table");
+       nfs4_init_slot_table(&session->bc_slot_table, "BackChannel Slot table");
        session->session_state = 1<<NFS4_SESSION_INITING;
 
        session->clp = clp;
index e069cf2d8c5f6520252858d754de8067f646e88b..f223a7648f9ec317e85964e3f7db07e61bfad515 100644 (file)
@@ -72,6 +72,8 @@ enum nfs4_session_state {
        NFS4_SESSION_INITING,
 };
 
+extern int nfs4_setup_slot_table(struct nfs4_slot_table *tbl,
+               unsigned int max_reqs, const char *queue);
 extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl);
 extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
 extern void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl);