[PATCH] RPC: Allow multiple RPC client programs to share the same transport
authorAndreas Gruenbacher <agruen@suse.de>
Wed, 22 Jun 2005 17:16:23 +0000 (17:16 +0000)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 22 Jun 2005 20:07:18 +0000 (16:07 -0400)
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
Acked-by: Olaf Kirch <okir@suse.de>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
include/linux/sunrpc/clnt.h
net/sunrpc/clnt.c
net/sunrpc/pmap_clnt.c
net/sunrpc/sunrpc_syms.c

index d25e80f77ff5f533134b4c72067525b216be8701..ab151bbb66df601a6a815e385d43289e93239e05 100644 (file)
@@ -114,6 +114,8 @@ struct rpc_clnt *rpc_create_client(struct rpc_xprt *xprt, char *servname,
 struct rpc_clnt *rpc_new_client(struct rpc_xprt *xprt, char *servname,
                                struct rpc_program *info,
                                u32 version, rpc_authflavor_t authflavor);
+struct rpc_clnt        *rpc_bind_new_program(struct rpc_clnt *,
+                               struct rpc_program *, int);
 struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
 int            rpc_shutdown_client(struct rpc_clnt *);
 int            rpc_destroy_client(struct rpc_clnt *);
index 33f12b84e265fd760a57feff789a52d795e824c2..c979fcf8879887da96d0765b37c6140cc7b979ca 100644 (file)
@@ -241,6 +241,8 @@ rpc_clone_client(struct rpc_clnt *clnt)
        rpc_init_rtt(&new->cl_rtt_default, clnt->cl_xprt->timeout.to_initval);
        if (new->cl_auth)
                atomic_inc(&new->cl_auth->au_count);
+       new->cl_pmap            = &new->cl_pmap_default;
+       rpc_init_wait_queue(&new->cl_pmap_default.pm_bindwait, "bindwait");
        return new;
 out_no_clnt:
        printk(KERN_INFO "RPC: out of memory in %s\n", __FUNCTION__);
@@ -329,6 +331,44 @@ rpc_release_client(struct rpc_clnt *clnt)
                rpc_destroy_client(clnt);
 }
 
+/**
+ * rpc_bind_new_program - bind a new RPC program to an existing client
+ * @old - old rpc_client
+ * @program - rpc program to set
+ * @vers - rpc program version
+ *
+ * Clones the rpc client and sets up a new RPC program. This is mainly
+ * of use for enabling different RPC programs to share the same transport.
+ * The Sun NFSv2/v3 ACL protocol can do this.
+ */
+struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
+                                     struct rpc_program *program,
+                                     int vers)
+{
+       struct rpc_clnt *clnt;
+       struct rpc_version *version;
+       int err;
+
+       BUG_ON(vers >= program->nrvers || !program->version[vers]);
+       version = program->version[vers];
+       clnt = rpc_clone_client(old);
+       if (IS_ERR(clnt))
+               goto out;
+       clnt->cl_procinfo = version->procs;
+       clnt->cl_maxproc  = version->nrprocs;
+       clnt->cl_protname = program->name;
+       clnt->cl_prog     = program->number;
+       clnt->cl_vers     = version->number;
+       clnt->cl_stats    = program->stats;
+       err = rpc_ping(clnt, RPC_TASK_SOFT|RPC_TASK_NOINTR);
+       if (err != 0) {
+               rpc_shutdown_client(clnt);
+               clnt = ERR_PTR(err);
+       }
+out:   
+       return clnt;
+}
+
 /*
  * Default callback for async RPC calls
  */
index df4d84c9020def6432a97ea89a39d9f374cd1578..4e81f27669239cbf9a4ca83d7d7af2040d30317a 100644 (file)
@@ -53,6 +53,9 @@ rpc_getport(struct rpc_task *task, struct rpc_clnt *clnt)
                        task->tk_pid, clnt->cl_server,
                        map->pm_prog, map->pm_vers, map->pm_prot);
 
+       /* Autobind on cloned rpc clients is discouraged */
+       BUG_ON(clnt->cl_parent != clnt);
+
        spin_lock(&pmap_lock);
        if (map->pm_binding) {
                rpc_sleep_on(&map->pm_bindwait, task, NULL, NULL);
index 1b0ff7e0e86977d4a9b9ff6505ad0ee1805dbfbc..d8673f66acc3f71364d10d31deca12b63efc6170 100644 (file)
@@ -42,6 +42,7 @@ EXPORT_SYMBOL(rpc_release_task);
 /* RPC client functions */
 EXPORT_SYMBOL(rpc_create_client);
 EXPORT_SYMBOL(rpc_clone_client);
+EXPORT_SYMBOL(rpc_bind_new_program);
 EXPORT_SYMBOL(rpc_destroy_client);
 EXPORT_SYMBOL(rpc_shutdown_client);
 EXPORT_SYMBOL(rpc_release_client);