aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-16 18:25:31 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-16 18:25:31 -0500
commit0b233b7c79d2ba92c7fb5d60d4116693f1b3b0fe (patch)
tree440a6093bacfadf46782592fff22c4a2b2b51443 /net
parent6f51ee709e4c6b56f2c2a071da2d056a109b9d26 (diff)
parentbf7491f1be5e125eece2ec67e0f79d513caa6c7e (diff)
Merge branch 'for-3.19' of git://linux-nfs.org/~bfields/linux
Pull nfsd updates from Bruce Fields: "A comparatively quieter cycle for nfsd this time, but still with two larger changes: - RPC server scalability improvements from Jeff Layton (using RCU instead of a spinlock to find idle threads). - server-side NFSv4.2 ALLOCATE/DEALLOCATE support from Anna Schumaker, enabling fallocate on new clients" * 'for-3.19' of git://linux-nfs.org/~bfields/linux: (32 commits) nfsd4: fix xdr4 count of server in fs_location4 nfsd4: fix xdr4 inclusion of escaped char sunrpc/cache: convert to use string_escape_str() sunrpc: only call test_bit once in svc_xprt_received fs: nfsd: Fix signedness bug in compare_blob sunrpc: add some tracepoints around enqueue and dequeue of svc_xprt sunrpc: convert to lockless lookup of queued server threads sunrpc: fix potential races in pool_stats collection sunrpc: add a rcu_head to svc_rqst and use kfree_rcu to free it sunrpc: require svc_create callers to pass in meaningful shutdown routine sunrpc: have svc_wake_up only deal with pool 0 sunrpc: convert sp_task_pending flag to use atomic bitops sunrpc: move rq_cachetype field to better optimize space sunrpc: move rq_splice_ok flag into rq_flags sunrpc: move rq_dropme flag into rq_flags sunrpc: move rq_usedeferral flag to rq_flags sunrpc: move rq_local field to rq_flags sunrpc: add a generic rq_flags field to svc_rqst and move rq_secure to it nfsd: minor off by one checks in __write_versions() sunrpc: release svc_pool_map reference when serv allocation fails ...
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c2
-rw-r--r--net/sunrpc/cache.c26
-rw-r--r--net/sunrpc/svc.c42
-rw-r--r--net/sunrpc/svc_xprt.c292
-rw-r--r--net/sunrpc/svcsock.c5
-rw-r--r--net/sunrpc/xdr.c9
6 files changed, 200 insertions, 176 deletions
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index de856ddf5fed..224a82f24d3c 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -886,7 +886,7 @@ unwrap_priv_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct gs
886 u32 priv_len, maj_stat; 886 u32 priv_len, maj_stat;
887 int pad, saved_len, remaining_len, offset; 887 int pad, saved_len, remaining_len, offset;
888 888
889 rqstp->rq_splice_ok = false; 889 clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
890 890
891 priv_len = svc_getnl(&buf->head[0]); 891 priv_len = svc_getnl(&buf->head[0]);
892 if (rqstp->rq_deferred) { 892 if (rqstp->rq_deferred) {
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 066362141133..33fb105d4352 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -20,6 +20,7 @@
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/ctype.h> 22#include <linux/ctype.h>
23#include <linux/string_helpers.h>
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24#include <linux/poll.h> 25#include <linux/poll.h>
25#include <linux/seq_file.h> 26#include <linux/seq_file.h>
@@ -1067,30 +1068,15 @@ void qword_add(char **bpp, int *lp, char *str)
1067{ 1068{
1068 char *bp = *bpp; 1069 char *bp = *bpp;
1069 int len = *lp; 1070 int len = *lp;
1070 char c; 1071 int ret;
1071 1072
1072 if (len < 0) return; 1073 if (len < 0) return;
1073 1074
1074 while ((c=*str++) && len) 1075 ret = string_escape_str(str, &bp, len, ESCAPE_OCTAL, "\\ \n\t");
1075 switch(c) { 1076 if (ret < 0 || ret == len)
1076 case ' ': 1077 len = -1;
1077 case '\t':
1078 case '\n':
1079 case '\\':
1080 if (len >= 4) {
1081 *bp++ = '\\';
1082 *bp++ = '0' + ((c & 0300)>>6);
1083 *bp++ = '0' + ((c & 0070)>>3);
1084 *bp++ = '0' + ((c & 0007)>>0);
1085 }
1086 len -= 4;
1087 break;
1088 default:
1089 *bp++ = c;
1090 len--;
1091 }
1092 if (c || len <1) len = -1;
1093 else { 1078 else {
1079 len -= ret;
1094 *bp++ = ' '; 1080 *bp++ = ' ';
1095 len--; 1081 len--;
1096 } 1082 }
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 2783fd80c229..91eaef1844c8 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -191,7 +191,7 @@ svc_pool_map_init_percpu(struct svc_pool_map *m)
191 return err; 191 return err;
192 192
193 for_each_online_cpu(cpu) { 193 for_each_online_cpu(cpu) {
194 BUG_ON(pidx > maxpools); 194 BUG_ON(pidx >= maxpools);
195 m->to_pool[cpu] = pidx; 195 m->to_pool[cpu] = pidx;
196 m->pool_to[pidx] = cpu; 196 m->pool_to[pidx] = cpu;
197 pidx++; 197 pidx++;
@@ -476,15 +476,11 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
476 i, serv->sv_name); 476 i, serv->sv_name);
477 477
478 pool->sp_id = i; 478 pool->sp_id = i;
479 INIT_LIST_HEAD(&pool->sp_threads);
480 INIT_LIST_HEAD(&pool->sp_sockets); 479 INIT_LIST_HEAD(&pool->sp_sockets);
481 INIT_LIST_HEAD(&pool->sp_all_threads); 480 INIT_LIST_HEAD(&pool->sp_all_threads);
482 spin_lock_init(&pool->sp_lock); 481 spin_lock_init(&pool->sp_lock);
483 } 482 }
484 483
485 if (svc_uses_rpcbind(serv) && (!serv->sv_shutdown))
486 serv->sv_shutdown = svc_rpcb_cleanup;
487
488 return serv; 484 return serv;
489} 485}
490 486
@@ -505,13 +501,15 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
505 unsigned int npools = svc_pool_map_get(); 501 unsigned int npools = svc_pool_map_get();
506 502
507 serv = __svc_create(prog, bufsize, npools, shutdown); 503 serv = __svc_create(prog, bufsize, npools, shutdown);
504 if (!serv)
505 goto out_err;
508 506
509 if (serv != NULL) { 507 serv->sv_function = func;
510 serv->sv_function = func; 508 serv->sv_module = mod;
511 serv->sv_module = mod;
512 }
513
514 return serv; 509 return serv;
510out_err:
511 svc_pool_map_put();
512 return NULL;
515} 513}
516EXPORT_SYMBOL_GPL(svc_create_pooled); 514EXPORT_SYMBOL_GPL(svc_create_pooled);
517 515
@@ -615,12 +613,14 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)
615 goto out_enomem; 613 goto out_enomem;
616 614
617 serv->sv_nrthreads++; 615 serv->sv_nrthreads++;
616 __set_bit(RQ_BUSY, &rqstp->rq_flags);
617 spin_lock_init(&rqstp->rq_lock);
618 rqstp->rq_server = serv;
619 rqstp->rq_pool = pool;
618 spin_lock_bh(&pool->sp_lock); 620 spin_lock_bh(&pool->sp_lock);
619 pool->sp_nrthreads++; 621 pool->sp_nrthreads++;
620 list_add(&rqstp->rq_all, &pool->sp_all_threads); 622 list_add_rcu(&rqstp->rq_all, &pool->sp_all_threads);
621 spin_unlock_bh(&pool->sp_lock); 623 spin_unlock_bh(&pool->sp_lock);
622 rqstp->rq_server = serv;
623 rqstp->rq_pool = pool;
624 624
625 rqstp->rq_argp = kmalloc_node(serv->sv_xdrsize, GFP_KERNEL, node); 625 rqstp->rq_argp = kmalloc_node(serv->sv_xdrsize, GFP_KERNEL, node);
626 if (!rqstp->rq_argp) 626 if (!rqstp->rq_argp)
@@ -685,7 +685,8 @@ found_pool:
685 * so we don't try to kill it again. 685 * so we don't try to kill it again.
686 */ 686 */
687 rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all); 687 rqstp = list_entry(pool->sp_all_threads.next, struct svc_rqst, rq_all);
688 list_del_init(&rqstp->rq_all); 688 set_bit(RQ_VICTIM, &rqstp->rq_flags);
689 list_del_rcu(&rqstp->rq_all);
689 task = rqstp->rq_task; 690 task = rqstp->rq_task;
690 } 691 }
691 spin_unlock_bh(&pool->sp_lock); 692 spin_unlock_bh(&pool->sp_lock);
@@ -783,10 +784,11 @@ svc_exit_thread(struct svc_rqst *rqstp)
783 784
784 spin_lock_bh(&pool->sp_lock); 785 spin_lock_bh(&pool->sp_lock);
785 pool->sp_nrthreads--; 786 pool->sp_nrthreads--;
786 list_del(&rqstp->rq_all); 787 if (!test_and_set_bit(RQ_VICTIM, &rqstp->rq_flags))
788 list_del_rcu(&rqstp->rq_all);
787 spin_unlock_bh(&pool->sp_lock); 789 spin_unlock_bh(&pool->sp_lock);
788 790
789 kfree(rqstp); 791 kfree_rcu(rqstp, rq_rcu_head);
790 792
791 /* Release the server */ 793 /* Release the server */
792 if (serv) 794 if (serv)
@@ -1086,10 +1088,10 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
1086 goto err_short_len; 1088 goto err_short_len;
1087 1089
1088 /* Will be turned off only in gss privacy case: */ 1090 /* Will be turned off only in gss privacy case: */
1089 rqstp->rq_splice_ok = true; 1091 set_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
1090 /* Will be turned off only when NFSv4 Sessions are used */ 1092 /* Will be turned off only when NFSv4 Sessions are used */
1091 rqstp->rq_usedeferral = true; 1093 set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
1092 rqstp->rq_dropme = false; 1094 clear_bit(RQ_DROPME, &rqstp->rq_flags);
1093 1095
1094 /* Setup reply header */ 1096 /* Setup reply header */
1095 rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr(rqstp); 1097 rqstp->rq_xprt->xpt_ops->xpo_prep_reply_hdr(rqstp);
@@ -1189,7 +1191,7 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
1189 *statp = procp->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp); 1191 *statp = procp->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp);
1190 1192
1191 /* Encode reply */ 1193 /* Encode reply */
1192 if (rqstp->rq_dropme) { 1194 if (test_bit(RQ_DROPME, &rqstp->rq_flags)) {
1193 if (procp->pc_release) 1195 if (procp->pc_release)
1194 procp->pc_release(rqstp, NULL, rqstp->rq_resp); 1196 procp->pc_release(rqstp, NULL, rqstp->rq_resp);
1195 goto dropit; 1197 goto dropit;
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index bbb3b044b877..c69358b3cf7f 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -220,9 +220,11 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl,
220 */ 220 */
221static void svc_xprt_received(struct svc_xprt *xprt) 221static void svc_xprt_received(struct svc_xprt *xprt)
222{ 222{
223 WARN_ON_ONCE(!test_bit(XPT_BUSY, &xprt->xpt_flags)); 223 if (!test_bit(XPT_BUSY, &xprt->xpt_flags)) {
224 if (!test_bit(XPT_BUSY, &xprt->xpt_flags)) 224 WARN_ONCE(1, "xprt=0x%p already busy!", xprt);
225 return; 225 return;
226 }
227
226 /* As soon as we clear busy, the xprt could be closed and 228 /* As soon as we clear busy, the xprt could be closed and
227 * 'put', so we need a reference to call svc_xprt_do_enqueue with: 229 * 'put', so we need a reference to call svc_xprt_do_enqueue with:
228 */ 230 */
@@ -310,25 +312,6 @@ char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len)
310} 312}
311EXPORT_SYMBOL_GPL(svc_print_addr); 313EXPORT_SYMBOL_GPL(svc_print_addr);
312 314
313/*
314 * Queue up an idle server thread. Must have pool->sp_lock held.
315 * Note: this is really a stack rather than a queue, so that we only
316 * use as many different threads as we need, and the rest don't pollute
317 * the cache.
318 */
319static void svc_thread_enqueue(struct svc_pool *pool, struct svc_rqst *rqstp)
320{
321 list_add(&rqstp->rq_list, &pool->sp_threads);
322}
323
324/*
325 * Dequeue an nfsd thread. Must have pool->sp_lock held.
326 */
327static void svc_thread_dequeue(struct svc_pool *pool, struct svc_rqst *rqstp)
328{
329 list_del(&rqstp->rq_list);
330}
331
332static bool svc_xprt_has_something_to_do(struct svc_xprt *xprt) 315static bool svc_xprt_has_something_to_do(struct svc_xprt *xprt)
333{ 316{
334 if (xprt->xpt_flags & ((1<<XPT_CONN)|(1<<XPT_CLOSE))) 317 if (xprt->xpt_flags & ((1<<XPT_CONN)|(1<<XPT_CLOSE)))
@@ -341,11 +324,12 @@ static bool svc_xprt_has_something_to_do(struct svc_xprt *xprt)
341static void svc_xprt_do_enqueue(struct svc_xprt *xprt) 324static void svc_xprt_do_enqueue(struct svc_xprt *xprt)
342{ 325{
343 struct svc_pool *pool; 326 struct svc_pool *pool;
344 struct svc_rqst *rqstp; 327 struct svc_rqst *rqstp = NULL;
345 int cpu; 328 int cpu;
329 bool queued = false;
346 330
347 if (!svc_xprt_has_something_to_do(xprt)) 331 if (!svc_xprt_has_something_to_do(xprt))
348 return; 332 goto out;
349 333
350 /* Mark transport as busy. It will remain in this state until 334 /* Mark transport as busy. It will remain in this state until
351 * the provider calls svc_xprt_received. We update XPT_BUSY 335 * the provider calls svc_xprt_received. We update XPT_BUSY
@@ -355,43 +339,69 @@ static void svc_xprt_do_enqueue(struct svc_xprt *xprt)
355 if (test_and_set_bit(XPT_BUSY, &xprt->xpt_flags)) { 339 if (test_and_set_bit(XPT_BUSY, &xprt->xpt_flags)) {
356 /* Don't enqueue transport while already enqueued */ 340 /* Don't enqueue transport while already enqueued */
357 dprintk("svc: transport %p busy, not enqueued\n", xprt); 341 dprintk("svc: transport %p busy, not enqueued\n", xprt);
358 return; 342 goto out;
359 } 343 }
360 344
361 cpu = get_cpu(); 345 cpu = get_cpu();
362 pool = svc_pool_for_cpu(xprt->xpt_server, cpu); 346 pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
363 spin_lock_bh(&pool->sp_lock);
364 347
365 pool->sp_stats.packets++; 348 atomic_long_inc(&pool->sp_stats.packets);
366 349
367 if (!list_empty(&pool->sp_threads)) { 350redo_search:
368 rqstp = list_entry(pool->sp_threads.next, 351 /* find a thread for this xprt */
369 struct svc_rqst, 352 rcu_read_lock();
370 rq_list); 353 list_for_each_entry_rcu(rqstp, &pool->sp_all_threads, rq_all) {
371 dprintk("svc: transport %p served by daemon %p\n", 354 /* Do a lockless check first */
372 xprt, rqstp); 355 if (test_bit(RQ_BUSY, &rqstp->rq_flags))
373 svc_thread_dequeue(pool, rqstp); 356 continue;
374 if (rqstp->rq_xprt) 357
375 printk(KERN_ERR 358 /*
376 "svc_xprt_enqueue: server %p, rq_xprt=%p!\n", 359 * Once the xprt has been queued, it can only be dequeued by
377 rqstp, rqstp->rq_xprt); 360 * the task that intends to service it. All we can do at that
378 /* Note the order of the following 3 lines: 361 * point is to try to wake this thread back up so that it can
379 * We want to assign xprt to rqstp->rq_xprt only _after_ 362 * do so.
380 * we've woken up the process, so that we don't race with
381 * the lockless check in svc_get_next_xprt().
382 */ 363 */
383 svc_xprt_get(xprt); 364 if (!queued) {
365 spin_lock_bh(&rqstp->rq_lock);
366 if (test_and_set_bit(RQ_BUSY, &rqstp->rq_flags)) {
367 /* already busy, move on... */
368 spin_unlock_bh(&rqstp->rq_lock);
369 continue;
370 }
371
372 /* this one will do */
373 rqstp->rq_xprt = xprt;
374 svc_xprt_get(xprt);
375 spin_unlock_bh(&rqstp->rq_lock);
376 }
377 rcu_read_unlock();
378
379 atomic_long_inc(&pool->sp_stats.threads_woken);
384 wake_up_process(rqstp->rq_task); 380 wake_up_process(rqstp->rq_task);
385 rqstp->rq_xprt = xprt; 381 put_cpu();
386 pool->sp_stats.threads_woken++; 382 goto out;
387 } else { 383 }
384 rcu_read_unlock();
385
386 /*
387 * We didn't find an idle thread to use, so we need to queue the xprt.
388 * Do so and then search again. If we find one, we can't hook this one
389 * up to it directly but we can wake the thread up in the hopes that it
390 * will pick it up once it searches for a xprt to service.
391 */
392 if (!queued) {
393 queued = true;
388 dprintk("svc: transport %p put into queue\n", xprt); 394 dprintk("svc: transport %p put into queue\n", xprt);
395 spin_lock_bh(&pool->sp_lock);
389 list_add_tail(&xprt->xpt_ready, &pool->sp_sockets); 396 list_add_tail(&xprt->xpt_ready, &pool->sp_sockets);
390 pool->sp_stats.sockets_queued++; 397 pool->sp_stats.sockets_queued++;
398 spin_unlock_bh(&pool->sp_lock);
399 goto redo_search;
391 } 400 }
392 401 rqstp = NULL;
393 spin_unlock_bh(&pool->sp_lock);
394 put_cpu(); 402 put_cpu();
403out:
404 trace_svc_xprt_do_enqueue(xprt, rqstp);
395} 405}
396 406
397/* 407/*
@@ -408,22 +418,28 @@ void svc_xprt_enqueue(struct svc_xprt *xprt)
408EXPORT_SYMBOL_GPL(svc_xprt_enqueue); 418EXPORT_SYMBOL_GPL(svc_xprt_enqueue);
409 419
410/* 420/*
411 * Dequeue the first transport. Must be called with the pool->sp_lock held. 421 * Dequeue the first transport, if there is one.
412 */ 422 */
413static struct svc_xprt *svc_xprt_dequeue(struct svc_pool *pool) 423static struct svc_xprt *svc_xprt_dequeue(struct svc_pool *pool)
414{ 424{
415 struct svc_xprt *xprt; 425 struct svc_xprt *xprt = NULL;
416 426
417 if (list_empty(&pool->sp_sockets)) 427 if (list_empty(&pool->sp_sockets))
418 return NULL; 428 goto out;
419
420 xprt = list_entry(pool->sp_sockets.next,
421 struct svc_xprt, xpt_ready);
422 list_del_init(&xprt->xpt_ready);
423 429
424 dprintk("svc: transport %p dequeued, inuse=%d\n", 430 spin_lock_bh(&pool->sp_lock);
425 xprt, atomic_read(&xprt->xpt_ref.refcount)); 431 if (likely(!list_empty(&pool->sp_sockets))) {
432 xprt = list_first_entry(&pool->sp_sockets,
433 struct svc_xprt, xpt_ready);
434 list_del_init(&xprt->xpt_ready);
435 svc_xprt_get(xprt);
426 436
437 dprintk("svc: transport %p dequeued, inuse=%d\n",
438 xprt, atomic_read(&xprt->xpt_ref.refcount));
439 }
440 spin_unlock_bh(&pool->sp_lock);
441out:
442 trace_svc_xprt_dequeue(xprt);
427 return xprt; 443 return xprt;
428} 444}
429 445
@@ -484,34 +500,36 @@ static void svc_xprt_release(struct svc_rqst *rqstp)
484} 500}
485 501
486/* 502/*
487 * External function to wake up a server waiting for data 503 * Some svc_serv's will have occasional work to do, even when a xprt is not
488 * This really only makes sense for services like lockd 504 * waiting to be serviced. This function is there to "kick" a task in one of
489 * which have exactly one thread anyway. 505 * those services so that it can wake up and do that work. Note that we only
506 * bother with pool 0 as we don't need to wake up more than one thread for
507 * this purpose.
490 */ 508 */
491void svc_wake_up(struct svc_serv *serv) 509void svc_wake_up(struct svc_serv *serv)
492{ 510{
493 struct svc_rqst *rqstp; 511 struct svc_rqst *rqstp;
494 unsigned int i;
495 struct svc_pool *pool; 512 struct svc_pool *pool;
496 513
497 for (i = 0; i < serv->sv_nrpools; i++) { 514 pool = &serv->sv_pools[0];
498 pool = &serv->sv_pools[i];
499 515
500 spin_lock_bh(&pool->sp_lock); 516 rcu_read_lock();
501 if (!list_empty(&pool->sp_threads)) { 517 list_for_each_entry_rcu(rqstp, &pool->sp_all_threads, rq_all) {
502 rqstp = list_entry(pool->sp_threads.next, 518 /* skip any that aren't queued */
503 struct svc_rqst, 519 if (test_bit(RQ_BUSY, &rqstp->rq_flags))
504 rq_list); 520 continue;
505 dprintk("svc: daemon %p woken up.\n", rqstp); 521 rcu_read_unlock();
506 /* 522 dprintk("svc: daemon %p woken up.\n", rqstp);
507 svc_thread_dequeue(pool, rqstp); 523 wake_up_process(rqstp->rq_task);
508 rqstp->rq_xprt = NULL; 524 trace_svc_wake_up(rqstp->rq_task->pid);
509 */ 525 return;
510 wake_up_process(rqstp->rq_task);
511 } else
512 pool->sp_task_pending = 1;
513 spin_unlock_bh(&pool->sp_lock);
514 } 526 }
527 rcu_read_unlock();
528
529 /* No free entries available */
530 set_bit(SP_TASK_PENDING, &pool->sp_flags);
531 smp_wmb();
532 trace_svc_wake_up(0);
515} 533}
516EXPORT_SYMBOL_GPL(svc_wake_up); 534EXPORT_SYMBOL_GPL(svc_wake_up);
517 535
@@ -622,75 +640,86 @@ static int svc_alloc_arg(struct svc_rqst *rqstp)
622 return 0; 640 return 0;
623} 641}
624 642
643static bool
644rqst_should_sleep(struct svc_rqst *rqstp)
645{
646 struct svc_pool *pool = rqstp->rq_pool;
647
648 /* did someone call svc_wake_up? */
649 if (test_and_clear_bit(SP_TASK_PENDING, &pool->sp_flags))
650 return false;
651
652 /* was a socket queued? */
653 if (!list_empty(&pool->sp_sockets))
654 return false;
655
656 /* are we shutting down? */
657 if (signalled() || kthread_should_stop())
658 return false;
659
660 /* are we freezing? */
661 if (freezing(current))
662 return false;
663
664 return true;
665}
666
625static struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout) 667static struct svc_xprt *svc_get_next_xprt(struct svc_rqst *rqstp, long timeout)
626{ 668{
627 struct svc_xprt *xprt; 669 struct svc_xprt *xprt;
628 struct svc_pool *pool = rqstp->rq_pool; 670 struct svc_pool *pool = rqstp->rq_pool;
629 long time_left = 0; 671 long time_left = 0;
630 672
673 /* rq_xprt should be clear on entry */
674 WARN_ON_ONCE(rqstp->rq_xprt);
675
631 /* Normally we will wait up to 5 seconds for any required 676 /* Normally we will wait up to 5 seconds for any required
632 * cache information to be provided. 677 * cache information to be provided.
633 */ 678 */
634 rqstp->rq_chandle.thread_wait = 5*HZ; 679 rqstp->rq_chandle.thread_wait = 5*HZ;
635 680
636 spin_lock_bh(&pool->sp_lock);
637 xprt = svc_xprt_dequeue(pool); 681 xprt = svc_xprt_dequeue(pool);
638 if (xprt) { 682 if (xprt) {
639 rqstp->rq_xprt = xprt; 683 rqstp->rq_xprt = xprt;
640 svc_xprt_get(xprt);
641 684
642 /* As there is a shortage of threads and this request 685 /* As there is a shortage of threads and this request
643 * had to be queued, don't allow the thread to wait so 686 * had to be queued, don't allow the thread to wait so
644 * long for cache updates. 687 * long for cache updates.
645 */ 688 */
646 rqstp->rq_chandle.thread_wait = 1*HZ; 689 rqstp->rq_chandle.thread_wait = 1*HZ;
647 pool->sp_task_pending = 0; 690 clear_bit(SP_TASK_PENDING, &pool->sp_flags);
648 } else { 691 return xprt;
649 if (pool->sp_task_pending) { 692 }
650 pool->sp_task_pending = 0;
651 xprt = ERR_PTR(-EAGAIN);
652 goto out;
653 }
654 /*
655 * We have to be able to interrupt this wait
656 * to bring down the daemons ...
657 */
658 set_current_state(TASK_INTERRUPTIBLE);
659 693
660 /* No data pending. Go to sleep */ 694 /*
661 svc_thread_enqueue(pool, rqstp); 695 * We have to be able to interrupt this wait
662 spin_unlock_bh(&pool->sp_lock); 696 * to bring down the daemons ...
697 */
698 set_current_state(TASK_INTERRUPTIBLE);
699 clear_bit(RQ_BUSY, &rqstp->rq_flags);
700 smp_mb();
663 701
664 if (!(signalled() || kthread_should_stop())) { 702 if (likely(rqst_should_sleep(rqstp)))
665 time_left = schedule_timeout(timeout); 703 time_left = schedule_timeout(timeout);
666 __set_current_state(TASK_RUNNING); 704 else
705 __set_current_state(TASK_RUNNING);
667 706
668 try_to_freeze(); 707 try_to_freeze();
669 708
670 xprt = rqstp->rq_xprt; 709 spin_lock_bh(&rqstp->rq_lock);
671 if (xprt != NULL) 710 set_bit(RQ_BUSY, &rqstp->rq_flags);
672 return xprt; 711 spin_unlock_bh(&rqstp->rq_lock);
673 } else
674 __set_current_state(TASK_RUNNING);
675 712
676 spin_lock_bh(&pool->sp_lock); 713 xprt = rqstp->rq_xprt;
677 if (!time_left) 714 if (xprt != NULL)
678 pool->sp_stats.threads_timedout++; 715 return xprt;
679 716
680 xprt = rqstp->rq_xprt; 717 if (!time_left)
681 if (!xprt) { 718 atomic_long_inc(&pool->sp_stats.threads_timedout);
682 svc_thread_dequeue(pool, rqstp); 719
683 spin_unlock_bh(&pool->sp_lock); 720 if (signalled() || kthread_should_stop())
684 dprintk("svc: server %p, no data yet\n", rqstp); 721 return ERR_PTR(-EINTR);
685 if (signalled() || kthread_should_stop()) 722 return ERR_PTR(-EAGAIN);
686 return ERR_PTR(-EINTR);
687 else
688 return ERR_PTR(-EAGAIN);
689 }
690 }
691out:
692 spin_unlock_bh(&pool->sp_lock);
693 return xprt;
694} 723}
695 724
696static void svc_add_new_temp_xprt(struct svc_serv *serv, struct svc_xprt *newxpt) 725static void svc_add_new_temp_xprt(struct svc_serv *serv, struct svc_xprt *newxpt)
@@ -719,7 +748,7 @@ static int svc_handle_xprt(struct svc_rqst *rqstp, struct svc_xprt *xprt)
719 dprintk("svc_recv: found XPT_CLOSE\n"); 748 dprintk("svc_recv: found XPT_CLOSE\n");
720 svc_delete_xprt(xprt); 749 svc_delete_xprt(xprt);
721 /* Leave XPT_BUSY set on the dead xprt: */ 750 /* Leave XPT_BUSY set on the dead xprt: */
722 return 0; 751 goto out;
723 } 752 }
724 if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) { 753 if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) {
725 struct svc_xprt *newxpt; 754 struct svc_xprt *newxpt;
@@ -750,6 +779,8 @@ static int svc_handle_xprt(struct svc_rqst *rqstp, struct svc_xprt *xprt)
750 } 779 }
751 /* clear XPT_BUSY: */ 780 /* clear XPT_BUSY: */
752 svc_xprt_received(xprt); 781 svc_xprt_received(xprt);
782out:
783 trace_svc_handle_xprt(xprt, len);
753 return len; 784 return len;
754} 785}
755 786
@@ -797,7 +828,10 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
797 828
798 clear_bit(XPT_OLD, &xprt->xpt_flags); 829 clear_bit(XPT_OLD, &xprt->xpt_flags);
799 830
800 rqstp->rq_secure = xprt->xpt_ops->xpo_secure_port(rqstp); 831 if (xprt->xpt_ops->xpo_secure_port(rqstp))
832 set_bit(RQ_SECURE, &rqstp->rq_flags);
833 else
834 clear_bit(RQ_SECURE, &rqstp->rq_flags);
801 rqstp->rq_chandle.defer = svc_defer; 835 rqstp->rq_chandle.defer = svc_defer;
802 rqstp->rq_xid = svc_getu32(&rqstp->rq_arg.head[0]); 836 rqstp->rq_xid = svc_getu32(&rqstp->rq_arg.head[0]);
803 837
@@ -895,7 +929,6 @@ static void svc_age_temp_xprts(unsigned long closure)
895 continue; 929 continue;
896 list_del_init(le); 930 list_del_init(le);
897 set_bit(XPT_CLOSE, &xprt->xpt_flags); 931 set_bit(XPT_CLOSE, &xprt->xpt_flags);
898 set_bit(XPT_DETACHED, &xprt->xpt_flags);
899 dprintk("queuing xprt %p for closing\n", xprt); 932 dprintk("queuing xprt %p for closing\n", xprt);
900 933
901 /* a thread will dequeue and close it soon */ 934 /* a thread will dequeue and close it soon */
@@ -935,8 +968,7 @@ static void svc_delete_xprt(struct svc_xprt *xprt)
935 xprt->xpt_ops->xpo_detach(xprt); 968 xprt->xpt_ops->xpo_detach(xprt);
936 969
937 spin_lock_bh(&serv->sv_lock); 970 spin_lock_bh(&serv->sv_lock);
938 if (!test_and_set_bit(XPT_DETACHED, &xprt->xpt_flags)) 971 list_del_init(&xprt->xpt_list);
939 list_del_init(&xprt->xpt_list);
940 WARN_ON_ONCE(!list_empty(&xprt->xpt_ready)); 972 WARN_ON_ONCE(!list_empty(&xprt->xpt_ready));
941 if (test_bit(XPT_TEMP, &xprt->xpt_flags)) 973 if (test_bit(XPT_TEMP, &xprt->xpt_flags))
942 serv->sv_tmpcnt--; 974 serv->sv_tmpcnt--;
@@ -1080,7 +1112,7 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req)
1080 struct svc_rqst *rqstp = container_of(req, struct svc_rqst, rq_chandle); 1112 struct svc_rqst *rqstp = container_of(req, struct svc_rqst, rq_chandle);
1081 struct svc_deferred_req *dr; 1113 struct svc_deferred_req *dr;
1082 1114
1083 if (rqstp->rq_arg.page_len || !rqstp->rq_usedeferral) 1115 if (rqstp->rq_arg.page_len || !test_bit(RQ_USEDEFERRAL, &rqstp->rq_flags))
1084 return NULL; /* if more than a page, give up FIXME */ 1116 return NULL; /* if more than a page, give up FIXME */
1085 if (rqstp->rq_deferred) { 1117 if (rqstp->rq_deferred) {
1086 dr = rqstp->rq_deferred; 1118 dr = rqstp->rq_deferred;
@@ -1109,7 +1141,7 @@ static struct cache_deferred_req *svc_defer(struct cache_req *req)
1109 } 1141 }
1110 svc_xprt_get(rqstp->rq_xprt); 1142 svc_xprt_get(rqstp->rq_xprt);
1111 dr->xprt = rqstp->rq_xprt; 1143 dr->xprt = rqstp->rq_xprt;
1112 rqstp->rq_dropme = true; 1144 set_bit(RQ_DROPME, &rqstp->rq_flags);
1113 1145
1114 dr->handle.revisit = svc_revisit; 1146 dr->handle.revisit = svc_revisit;
1115 return &dr->handle; 1147 return &dr->handle;
@@ -1311,10 +1343,10 @@ static int svc_pool_stats_show(struct seq_file *m, void *p)
1311 1343
1312 seq_printf(m, "%u %lu %lu %lu %lu\n", 1344 seq_printf(m, "%u %lu %lu %lu %lu\n",
1313 pool->sp_id, 1345 pool->sp_id,
1314 pool->sp_stats.packets, 1346 (unsigned long)atomic_long_read(&pool->sp_stats.packets),
1315 pool->sp_stats.sockets_queued, 1347 pool->sp_stats.sockets_queued,
1316 pool->sp_stats.threads_woken, 1348 (unsigned long)atomic_long_read(&pool->sp_stats.threads_woken),
1317 pool->sp_stats.threads_timedout); 1349 (unsigned long)atomic_long_read(&pool->sp_stats.threads_timedout));
1318 1350
1319 return 0; 1351 return 0;
1320} 1352}
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index f9c052d508f0..cc331b6cf573 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1145,7 +1145,10 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
1145 1145
1146 rqstp->rq_xprt_ctxt = NULL; 1146 rqstp->rq_xprt_ctxt = NULL;
1147 rqstp->rq_prot = IPPROTO_TCP; 1147 rqstp->rq_prot = IPPROTO_TCP;
1148 rqstp->rq_local = !!test_bit(XPT_LOCAL, &svsk->sk_xprt.xpt_flags); 1148 if (test_bit(XPT_LOCAL, &svsk->sk_xprt.xpt_flags))
1149 set_bit(RQ_LOCAL, &rqstp->rq_flags);
1150 else
1151 clear_bit(RQ_LOCAL, &rqstp->rq_flags);
1149 1152
1150 p = (__be32 *)rqstp->rq_arg.head[0].iov_base; 1153 p = (__be32 *)rqstp->rq_arg.head[0].iov_base;
1151 calldir = p[1]; 1154 calldir = p[1];
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 290af97bf6f9..1cb61242e55e 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -617,9 +617,10 @@ void xdr_truncate_encode(struct xdr_stream *xdr, size_t len)
617 fraglen = min_t(int, buf->len - len, tail->iov_len); 617 fraglen = min_t(int, buf->len - len, tail->iov_len);
618 tail->iov_len -= fraglen; 618 tail->iov_len -= fraglen;
619 buf->len -= fraglen; 619 buf->len -= fraglen;
620 if (tail->iov_len && buf->len == len) { 620 if (tail->iov_len) {
621 xdr->p = tail->iov_base + tail->iov_len; 621 xdr->p = tail->iov_base + tail->iov_len;
622 /* xdr->end, xdr->iov should be set already */ 622 WARN_ON_ONCE(!xdr->end);
623 WARN_ON_ONCE(!xdr->iov);
623 return; 624 return;
624 } 625 }
625 WARN_ON_ONCE(fraglen); 626 WARN_ON_ONCE(fraglen);
@@ -631,11 +632,11 @@ void xdr_truncate_encode(struct xdr_stream *xdr, size_t len)
631 old = new + fraglen; 632 old = new + fraglen;
632 xdr->page_ptr -= (old >> PAGE_SHIFT) - (new >> PAGE_SHIFT); 633 xdr->page_ptr -= (old >> PAGE_SHIFT) - (new >> PAGE_SHIFT);
633 634
634 if (buf->page_len && buf->len == len) { 635 if (buf->page_len) {
635 xdr->p = page_address(*xdr->page_ptr); 636 xdr->p = page_address(*xdr->page_ptr);
636 xdr->end = (void *)xdr->p + PAGE_SIZE; 637 xdr->end = (void *)xdr->p + PAGE_SIZE;
637 xdr->p = (void *)xdr->p + (new % PAGE_SIZE); 638 xdr->p = (void *)xdr->p + (new % PAGE_SIZE);
638 /* xdr->iov should already be NULL */ 639 WARN_ON_ONCE(xdr->iov);
639 return; 640 return;
640 } 641 }
641 if (fraglen) { 642 if (fraglen) {