7 #include <linux/sched.h>
8 #include <linux/errno.h>
11 #include <linux/slab.h>
17 #include <linux/module.h>
19 #define RPCDBG_FACILITY RPCDBG_SVCXPRT
22 static int svc_deferred_recv(
struct svc_rqst *rqstp);
24 static void svc_age_temp_xprts(
unsigned long closure);
25 static void svc_delete_xprt(
struct svc_xprt *xprt);
32 static int svc_conn_age_period = 6*60;
77 spin_lock(&svc_xprt_class_lock);
86 spin_unlock(&svc_xprt_class_lock);
94 spin_lock(&svc_xprt_class_lock);
96 spin_unlock(&svc_xprt_class_lock);
110 spin_lock(&svc_xprt_class_lock);
116 if (len + slen > maxlen)
121 spin_unlock(&svc_xprt_class_lock);
126 static void svc_xprt_free(
struct kref *
kref)
143 kref_put(&xprt->
xpt_ref, svc_xprt_free);
154 memset(xprt, 0,
sizeof(*xprt));
175 const unsigned short port,
181 .sin_port =
htons(port),
183 #if IS_ENABLED(CONFIG_IPV6)
187 .sin6_port =
htons(port),
198 #if IS_ENABLED(CONFIG_IPV6)
208 return xcl->
xcl_ops->xpo_create(serv, net, sap, len, flags);
219 static void svc_xprt_received(
struct svc_xprt *xprt)
236 spin_unlock_bh(&serv->
sv_lock);
237 svc_xprt_received(
new);
241 struct net *net,
const int family,
242 const unsigned short port,
int flags)
246 dprintk(
"svc: creating transport %s[%d]\n", xprt_name, port);
247 spin_lock(&svc_xprt_class_lock);
250 unsigned short newport;
258 spin_unlock(&svc_xprt_class_lock);
259 newxprt = __svc_xpo_create(xcl, serv, net, family, port, flags);
260 if (IS_ERR(newxprt)) {
262 return PTR_ERR(newxprt);
265 newport = svc_xprt_local_port(newxprt);
269 spin_unlock(&svc_xprt_class_lock);
270 dprintk(
"svc: transport %s not found\n", xprt_name);
304 return __svc_print_addr(svc_addr(rqstp), buf, len);
327 static bool svc_xprt_has_something_to_do(
struct svc_xprt *xprt)
332 return xprt->
xpt_ops->xpo_has_wspace(xprt);
347 if (!svc_xprt_has_something_to_do(xprt))
360 "threads and transports both waiting??\n");
371 dprintk(
"svc: transport %p busy, not enqueued\n", xprt);
379 dprintk(
"svc: transport %p served by daemon %p\n",
381 svc_thread_dequeue(pool, rqstp);
384 "svc_xprt_enqueue: server %p, rq_xprt=%p!\n",
391 dprintk(
"svc: transport %p put into queue\n", xprt);
397 spin_unlock_bh(&pool->
sp_lock);
415 dprintk(
"svc: transport %p dequeued, inuse=%d\n",
433 space += rqstp->
rq_res.head[0].iov_len;
435 if (space < rqstp->rq_reserved) {
445 static void svc_xprt_release(
struct svc_rqst *rqstp)
449 rqstp->
rq_xprt->xpt_ops->xpo_release_rqst(rqstp);
454 svc_free_res_pages(rqstp);
455 rqstp->
rq_res.page_len = 0;
456 rqstp->
rq_res.page_base = 0;
468 rqstp->
rq_res.head[0].iov_len = 0;
494 dprintk(
"svc: daemon %p woken up.\n", rqstp);
501 spin_unlock_bh(&pool->
sp_lock);
538 static void svc_check_conn_limits(
struct svc_serv *serv)
550 "max number of connections" :
551 "number of threads");
562 spin_unlock_bh(&serv->
sv_lock);
581 for (i = 0; i <
pages ; i++)
605 arg->tail[0].iov_len = 0;
622 xprt = svc_xprt_dequeue(pool);
634 svc_thread_enqueue(pool, rqstp);
651 spin_unlock_bh(&pool->
sp_lock);
652 return ERR_PTR(-
EINTR);
656 spin_unlock_bh(&pool->
sp_lock);
669 svc_thread_dequeue(pool, rqstp);
670 spin_unlock_bh(&pool->
sp_lock);
671 dprintk(
"svc: server %p, no data yet\n", rqstp);
673 return ERR_PTR(-
EINTR);
678 spin_unlock_bh(&pool->
sp_lock);
691 (
unsigned long)serv);
695 spin_unlock_bh(&serv->
sv_lock);
696 svc_xprt_received(newxpt);
705 dprintk(
"svc_recv: found XPT_CLOSE\n");
706 svc_delete_xprt(xprt);
716 __module_get(xprt->
xpt_class->xcl_owner);
718 newxpt = xprt->
xpt_ops->xpo_accept(xprt);
721 }
else if (xprt->
xpt_ops->xpo_has_wspace(xprt)) {
723 dprintk(
"svc: server %p, pool %u, transport %p, inuse=%d\n",
724 rqstp, rqstp->
rq_pool->sp_id, xprt,
728 len = svc_deferred_recv(rqstp);
730 len = xprt->
xpt_ops->xpo_recvfrom(rqstp);
731 dprintk(
"svc: got len=%d\n", len);
736 svc_xprt_received(xprt);
751 dprintk(
"svc: server %p waiting for data (to = %ld)\n",
756 "svc_recv: service %p, transport not NULL!\n",
758 if (waitqueue_active(&rqstp->
rq_wait))
760 "svc_recv: service %p, wait queue active!\n",
774 return PTR_ERR(xprt);
776 len = svc_handle_xprt(rqstp, xprt);
792 svc_xprt_release(rqstp);
803 svc_xprt_release(rqstp);
821 rqstp->
rq_xprt->xpt_ops->xpo_release_rqst(rqstp);
825 xb->len = xb->head[0].iov_len +
835 len = xprt->
xpt_ops->xpo_sendto(rqstp);
838 svc_xprt_release(rqstp);
849 static void svc_age_temp_xprts(
unsigned long closure)
856 dprintk(
"svc_age_temp_xprts\n");
858 if (!spin_trylock_bh(&serv->
sv_lock)) {
860 dprintk(
"svc_age_temp_xprts: busy\n");
876 list_move(le, &to_be_aged);
880 spin_unlock_bh(&serv->
sv_lock);
882 while (!list_empty(&to_be_aged)) {
883 le = to_be_aged.
next;
888 dprintk(
"queuing xprt %p for closing\n", xprt);
898 static void call_xpt_users(
struct svc_xprt *xprt)
914 static void svc_delete_xprt(
struct svc_xprt *xprt)
923 dprintk(
"svc: svc_delete_xprt(%p)\n", xprt);
924 xprt->
xpt_ops->xpo_detach(xprt);
932 spin_unlock_bh(&serv->
sv_lock);
934 while ((dr = svc_deferred_dequeue(xprt)) !=
NULL)
937 call_xpt_users(xprt);
953 svc_delete_xprt(xprt);
957 static void svc_close_list(
struct svc_serv *serv,
struct list_head *xprt_list,
struct net *net)
971 static void svc_clear_pools(
struct svc_serv *serv,
struct net *net)
987 spin_unlock_bh(&pool->
sp_lock);
991 static void svc_clear_list(
struct svc_serv *serv,
struct list_head *xprt_list,
struct net *net)
1001 list_move(&xprt->
xpt_list, &victims);
1006 svc_delete_xprt(xprt);
1011 svc_close_list(serv, &serv->sv_tempsocks, net);
1012 svc_close_list(serv, &serv->sv_permsocks, net);
1014 svc_clear_pools(serv, net);
1020 svc_clear_list(serv, &serv->sv_tempsocks, net);
1021 svc_clear_list(serv, &serv->sv_permsocks, net);
1038 dprintk(
"revisit canceled\n");
1084 dr->argslen = rqstp->
rq_arg.len >> 2;
1088 skip = rqstp->
rq_arg.len - rqstp->
rq_arg.head[0].iov_len;
1089 memcpy(dr->args, rqstp->
rq_arg.head[0].iov_base - skip,
1096 dr->handle.revisit = svc_revisit;
1103 static int svc_deferred_recv(
struct svc_rqst *rqstp)
1111 rqstp->
rq_arg.page_len = 0;
1136 list_del_init(&dr->
handle.recent);
1161 const unsigned short port)
1167 if (serv ==
NULL || xcl_name ==
NULL)
1178 if (port != 0 && port != svc_xprt_local_port(xprt))
1184 spin_unlock_bh(&serv->
sv_lock);
1189 static int svc_one_xprt_name(
const struct svc_xprt *xprt,
1190 char *
pos,
int remaining)
1194 len =
snprintf(pos, remaining,
"%s %u\n",
1196 svc_xprt_local_port(xprt));
1197 if (len >= remaining)
1229 len = svc_one_xprt_name(xprt, pos, buflen - totlen);
1241 spin_unlock_bh(&serv->
sv_lock);
1249 static void *svc_pool_stats_start(
struct seq_file *
m, loff_t *pos)
1251 unsigned int pidx = (
unsigned int)*pos;
1254 dprintk(
"svc_pool_stats_start, *pidx=%u\n", pidx);
1261 static void *svc_pool_stats_next(
struct seq_file *m,
void *
p, loff_t *pos)
1266 dprintk(
"svc_pool_stats_next, *pos=%llu\n", *pos);
1271 unsigned int pidx = (pool - &serv->
sv_pools[0]);
1281 static void svc_pool_stats_stop(
struct seq_file *m,
void *p)
1285 static int svc_pool_stats_show(
struct seq_file *m,
void *p)
1290 seq_puts(m,
"# pool packets-arrived sockets-enqueued threads-woken threads-timedout\n");
1305 .start = svc_pool_stats_start,
1306 .next = svc_pool_stats_next,
1307 .stop = svc_pool_stats_stop,
1308 .show = svc_pool_stats_show,
1315 err =
seq_open(file, &svc_pool_stats_seq_ops);