SUNRPC: Rename "call_" functions that are no longer FSM states
[safe/jmp/linux-2.6] / net / sunrpc / svc.c
index b7503c1..01c7e31 100644 (file)
@@ -300,7 +300,6 @@ static inline int
 svc_pool_map_set_cpumask(unsigned int pidx, cpumask_t *oldmask)
 {
        struct svc_pool_map *m = &svc_pool_map;
-       unsigned int node; /* or cpu */
 
        /*
         * The caller checks for sv_nrpools > 1, which
@@ -313,16 +312,23 @@ svc_pool_map_set_cpumask(unsigned int pidx, cpumask_t *oldmask)
        default:
                return 0;
        case SVC_POOL_PERCPU:
-               node = m->pool_to[pidx];
+       {
+               unsigned int cpu = m->pool_to[pidx];
+
                *oldmask = current->cpus_allowed;
-               set_cpus_allowed(current, cpumask_of_cpu(node));
+               set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
                return 1;
+       }
        case SVC_POOL_PERNODE:
-               node = m->pool_to[pidx];
+       {
+               unsigned int node = m->pool_to[pidx];
+               node_to_cpumask_ptr(nodecpumask, node);
+
                *oldmask = current->cpus_allowed;
-               set_cpus_allowed(current, node_to_cpumask(node));
+               set_cpus_allowed_ptr(current, nodecpumask);
                return 1;
        }
+       }
 }
 
 /*
@@ -363,7 +369,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
           void (*shutdown)(struct svc_serv *serv))
 {
        struct svc_serv *serv;
-       int vers;
+       unsigned int vers;
        unsigned int xdrsize;
        unsigned int i;
 
@@ -432,6 +438,7 @@ svc_create(struct svc_program *prog, unsigned int bufsize,
 {
        return __svc_create(prog, bufsize, /*npools*/1, shutdown);
 }
+EXPORT_SYMBOL(svc_create);
 
 struct svc_serv *
 svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
@@ -451,6 +458,7 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
 
        return serv;
 }
+EXPORT_SYMBOL(svc_create_pooled);
 
 /*
  * Destroy an RPC service.  Should be called with the BKL held
@@ -458,9 +466,6 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
 void
 svc_destroy(struct svc_serv *serv)
 {
-       struct svc_sock *svsk;
-       struct svc_sock *tmp;
-
        dprintk("svc: svc_destroy(%s, %d)\n",
                                serv->sv_program->pg_name,
                                serv->sv_nrthreads);
@@ -475,14 +480,12 @@ svc_destroy(struct svc_serv *serv)
 
        del_timer_sync(&serv->sv_temptimer);
 
-       list_for_each_entry_safe(svsk, tmp, &serv->sv_tempsocks, sk_list)
-               svc_force_close_socket(svsk);
+       svc_close_all(&serv->sv_tempsocks);
 
        if (serv->sv_shutdown)
                serv->sv_shutdown(serv);
 
-       list_for_each_entry_safe(svsk, tmp, &serv->sv_permsocks, sk_list)
-               svc_force_close_socket(svsk);
+       svc_close_all(&serv->sv_permsocks);
 
        BUG_ON(!list_empty(&serv->sv_permsocks));
        BUG_ON(!list_empty(&serv->sv_tempsocks));
@@ -497,6 +500,7 @@ svc_destroy(struct svc_serv *serv)
        kfree(serv->sv_pools);
        kfree(serv);
 }
+EXPORT_SYMBOL(svc_destroy);
 
 /*
  * Allocate an RPC server's buffer space.
@@ -505,8 +509,7 @@ svc_destroy(struct svc_serv *serv)
 static int
 svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
 {
-       int pages;
-       int arghi;
+       unsigned int pages, arghi;
 
        pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply.
                                       * We assume one is at most one page
@@ -520,7 +523,7 @@ svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
                rqstp->rq_pages[arghi++] = p;
                pages--;
        }
-       return ! pages;
+       return pages == 0;
 }
 
 /*
@@ -529,37 +532,24 @@ svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
 static void
 svc_release_buffer(struct svc_rqst *rqstp)
 {
-       int i;
-       for (i=0; i<ARRAY_SIZE(rqstp->rq_pages); i++)
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(rqstp->rq_pages); i++)
                if (rqstp->rq_pages[i])
                        put_page(rqstp->rq_pages[i]);
 }
 
-/*
- * Create a thread in the given pool.  Caller must hold BKL.
- * On a NUMA or SMP machine, with a multi-pool serv, the thread
- * will be restricted to run on the cpus belonging to the pool.
- */
-static int
-__svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
-                   struct svc_pool *pool)
+struct svc_rqst *
+svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool)
 {
        struct svc_rqst *rqstp;
-       int             error = -ENOMEM;
-       int             have_oldmask = 0;
-       cpumask_t       oldmask;
 
        rqstp = kzalloc(sizeof(*rqstp), GFP_KERNEL);
        if (!rqstp)
-               goto out;
+               goto out_enomem;
 
        init_waitqueue_head(&rqstp->rq_wait);
 
-       if (!(rqstp->rq_argp = kmalloc(serv->sv_xdrsize, GFP_KERNEL))
-        || !(rqstp->rq_resp = kmalloc(serv->sv_xdrsize, GFP_KERNEL))
-        || !svc_init_buffer(rqstp, serv->sv_max_mesg))
-               goto out_thread;
-
        serv->sv_nrthreads++;
        spin_lock_bh(&pool->sp_lock);
        pool->sp_nrthreads++;
@@ -568,6 +558,45 @@ __svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
        rqstp->rq_server = serv;
        rqstp->rq_pool = pool;
 
+       rqstp->rq_argp = kmalloc(serv->sv_xdrsize, GFP_KERNEL);
+       if (!rqstp->rq_argp)
+               goto out_thread;
+
+       rqstp->rq_resp = kmalloc(serv->sv_xdrsize, GFP_KERNEL);
+       if (!rqstp->rq_resp)
+               goto out_thread;
+
+       if (!svc_init_buffer(rqstp, serv->sv_max_mesg))
+               goto out_thread;
+
+       return rqstp;
+out_thread:
+       svc_exit_thread(rqstp);
+out_enomem:
+       return ERR_PTR(-ENOMEM);
+}
+EXPORT_SYMBOL(svc_prepare_thread);
+
+/*
+ * Create a thread in the given pool.  Caller must hold BKL.
+ * On a NUMA or SMP machine, with a multi-pool serv, the thread
+ * will be restricted to run on the cpus belonging to the pool.
+ */
+static int
+__svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
+                   struct svc_pool *pool)
+{
+       struct svc_rqst *rqstp;
+       int             error = -ENOMEM;
+       int             have_oldmask = 0;
+       cpumask_t       uninitialized_var(oldmask);
+
+       rqstp = svc_prepare_thread(serv, pool);
+       if (IS_ERR(rqstp)) {
+               error = PTR_ERR(rqstp);
+               goto out;
+       }
+
        if (serv->sv_nrpools > 1)
                have_oldmask = svc_pool_map_set_cpumask(pool->sp_id, &oldmask);
 
@@ -589,15 +618,6 @@ out_thread:
 }
 
 /*
- * Create a thread in the default pool.  Caller must hold BKL.
- */
-int
-svc_create_thread(svc_thread_fn func, struct svc_serv *serv)
-{
-       return __svc_create_thread(func, serv, &serv->sv_pools[0]);
-}
-
-/*
  * Choose a pool in which to create a new thread, for svc_set_num_threads
  */
 static inline struct svc_pool *
@@ -699,6 +719,7 @@ svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 
        return error;
 }
+EXPORT_SYMBOL(svc_set_num_threads);
 
 /*
  * Called from a server thread as it's exiting.  Caller must hold BKL.
@@ -725,6 +746,7 @@ svc_exit_thread(struct svc_rqst *rqstp)
        if (serv)
                svc_destroy(serv);
 }
+EXPORT_SYMBOL(svc_exit_thread);
 
 /*
  * Register an RPC service with the local portmapper.
@@ -736,7 +758,8 @@ svc_register(struct svc_serv *serv, int proto, unsigned short port)
 {
        struct svc_program      *progp;
        unsigned long           flags;
-       int                     i, error = 0, dummy;
+       unsigned int            i;
+       int                     error = 0, dummy;
 
        if (!port)
                clear_thread_flag(TIF_SIGPENDING);
@@ -777,6 +800,30 @@ svc_register(struct svc_serv *serv, int proto, unsigned short port)
 }
 
 /*
+ * Printk the given error with the address of the client that caused it.
+ */
+static int
+__attribute__ ((format (printf, 2, 3)))
+svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
+{
+       va_list args;
+       int     r;
+       char    buf[RPC_MAX_ADDRBUFLEN];
+
+       if (!net_ratelimit())
+               return 0;
+
+       printk(KERN_WARNING "svc: %s: ",
+               svc_print_addr(rqstp, buf, sizeof(buf)));
+
+       va_start(args, fmt);
+       r = vprintk(fmt, args);
+       va_end(args);
+
+       return r;
+}
+
+/*
  * Process the RPC request.
  */
 int
@@ -814,10 +861,10 @@ svc_process(struct svc_rqst *rqstp)
        rqstp->rq_res.tail[0].iov_base = NULL;
        rqstp->rq_res.tail[0].iov_len = 0;
        /* Will be turned off only in gss privacy case: */
-       rqstp->rq_sendfile_ok = 1;
-       /* tcp needs a space for the record length... */
-       if (rqstp->rq_prot == IPPROTO_TCP)
-               svc_putnl(resv, 0);
+       rqstp->rq_splice_ok = 1;
+
+       /* Setup reply header */
+       rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr(rqstp);
 
        rqstp->rq_xid = svc_getu32(argv);
        svc_putu32(resv, rqstp->rq_xid);
@@ -863,8 +910,7 @@ svc_process(struct svc_rqst *rqstp)
        case SVC_OK:
                break;
        case SVC_GARBAGE:
-               rpc_stat = rpc_garbage_args;
-               goto err_bad;
+               goto err_garbage;
        case SVC_SYSERR:
                rpc_stat = rpc_system_err;
                goto err_bad;
@@ -907,7 +953,7 @@ svc_process(struct svc_rqst *rqstp)
         * better idea of reply size
         */
        if (procp->pc_xdrressize)
-               svc_reserve(rqstp, procp->pc_xdrressize<<2);
+               svc_reserve_auth(rqstp, procp->pc_xdrressize<<2);
 
        /* Call the function that processes the request. */
        if (!versp->vs_dispatch) {
@@ -963,14 +1009,13 @@ svc_process(struct svc_rqst *rqstp)
        return 0;
 
 err_short_len:
-       if (net_ratelimit())
-               printk("svc: short len %Zd, dropping request\n", argv->iov_len);
+       svc_printk(rqstp, "short len %Zd, dropping request\n",
+                       argv->iov_len);
 
        goto dropit;                    /* drop request */
 
 err_bad_dir:
-       if (net_ratelimit())
-               printk("svc: bad direction %d, dropping request\n", dir);
+       svc_printk(rqstp, "bad direction %d, dropping request\n", dir);
 
        serv->sv_stats->rpcbadfmt++;
        goto dropit;                    /* drop request */
@@ -1000,8 +1045,7 @@ err_bad_prog:
        goto sendit;
 
 err_bad_vers:
-       if (net_ratelimit())
-               printk("svc: unknown version (%d for prog %d, %s)\n",
+       svc_printk(rqstp, "unknown version (%d for prog %d, %s)\n",
                       vers, prog, progp->pg_name);
 
        serv->sv_stats->rpcbadfmt++;
@@ -1011,16 +1055,14 @@ err_bad_vers:
        goto sendit;
 
 err_bad_proc:
-       if (net_ratelimit())
-               printk("svc: unknown procedure (%d)\n", proc);
+       svc_printk(rqstp, "unknown procedure (%d)\n", proc);
 
        serv->sv_stats->rpcbadfmt++;
        svc_putnl(resv, RPC_PROC_UNAVAIL);
        goto sendit;
 
 err_garbage:
-       if (net_ratelimit())
-               printk("svc: failed to decode args\n");
+       svc_printk(rqstp, "failed to decode args\n");
 
        rpc_stat = rpc_garbage_args;
 err_bad:
@@ -1028,16 +1070,15 @@ err_bad:
        svc_putnl(resv, ntohl(rpc_stat));
        goto sendit;
 }
+EXPORT_SYMBOL(svc_process);
 
 /*
  * Return (transport-specific) limit on the rpc payload.
  */
 u32 svc_max_payload(const struct svc_rqst *rqstp)
 {
-       int max = RPCSVC_MAXPAYLOAD_TCP;
+       u32 max = rqstp->rq_xprt->xpt_class->xcl_max_payload;
 
-       if (rqstp->rq_sock->sk_sock->type == SOCK_DGRAM)
-               max = RPCSVC_MAXPAYLOAD_UDP;
        if (rqstp->rq_server->sv_max_payload < max)
                max = rqstp->rq_server->sv_max_payload;
        return max;