staging: lustre: remove top level ccflags variable
[deliverable/linux.git] / drivers / staging / lustre / lnet / lnet / router_proc.c
1 /*
2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Copyright (c) 2011, 2012, Intel Corporation.
5 *
6 * This file is part of Portals
7 * http://sourceforge.net/projects/sandiaportals/
8 *
9 * Portals is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
12 *
13 * Portals is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Portals; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24 #define DEBUG_SUBSYSTEM S_LNET
25 #include "../../include/linux/libcfs/libcfs.h"
26 #include "../../include/linux/lnet/lib-lnet.h"
27
28 #if defined(LNET_ROUTER)
29
30 /* This is really lnet_proc.c. You might need to update sanity test 215
31 * if any file format is changed. */
32
33 static ctl_table_header_t *lnet_table_header;
34
35 #define CTL_LNET (0x100)
36 enum {
37 PSDEV_LNET_STATS = 100,
38 PSDEV_LNET_ROUTES,
39 PSDEV_LNET_ROUTERS,
40 PSDEV_LNET_PEERS,
41 PSDEV_LNET_BUFFERS,
42 PSDEV_LNET_NIS,
43 PSDEV_LNET_PTL_ROTOR,
44 };
45
46 #define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
47 /*
48 * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
49 */
50 #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1)
51 /* change version, 16 bits or 8 bits */
52 #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
53
54 #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS
55 /*
56 * bits for peer hash offset
57 * NB: we don't use the highest bit of *ppos because it's signed
58 */
59 #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \
60 LNET_PROC_CPT_BITS - \
61 LNET_PROC_VER_BITS - \
62 LNET_PROC_HASH_BITS - 1)
63 /* bits for hash index + position */
64 #define LNET_PROC_HPOS_BITS (LNET_PROC_HASH_BITS + LNET_PROC_HOFF_BITS)
65 /* bits for peer hash table + hash version */
66 #define LNET_PROC_VPOS_BITS (LNET_PROC_HPOS_BITS + LNET_PROC_VER_BITS)
67
68 #define LNET_PROC_CPT_MASK ((1ULL << LNET_PROC_CPT_BITS) - 1)
69 #define LNET_PROC_VER_MASK ((1ULL << LNET_PROC_VER_BITS) - 1)
70 #define LNET_PROC_HASH_MASK ((1ULL << LNET_PROC_HASH_BITS) - 1)
71 #define LNET_PROC_HOFF_MASK ((1ULL << LNET_PROC_HOFF_BITS) - 1)
72
73 #define LNET_PROC_CPT_GET(pos) \
74 (int)(((pos) >> LNET_PROC_VPOS_BITS) & LNET_PROC_CPT_MASK)
75
76 #define LNET_PROC_VER_GET(pos) \
77 (int)(((pos) >> LNET_PROC_HPOS_BITS) & LNET_PROC_VER_MASK)
78
79 #define LNET_PROC_HASH_GET(pos) \
80 (int)(((pos) >> LNET_PROC_HOFF_BITS) & LNET_PROC_HASH_MASK)
81
82 #define LNET_PROC_HOFF_GET(pos) \
83 (int)((pos) & LNET_PROC_HOFF_MASK)
84
85 #define LNET_PROC_POS_MAKE(cpt, ver, hash, off) \
86 (((((loff_t)(cpt)) & LNET_PROC_CPT_MASK) << LNET_PROC_VPOS_BITS) | \
87 ((((loff_t)(ver)) & LNET_PROC_VER_MASK) << LNET_PROC_HPOS_BITS) | \
88 ((((loff_t)(hash)) & LNET_PROC_HASH_MASK) << LNET_PROC_HOFF_BITS) | \
89 ((off) & LNET_PROC_HOFF_MASK))
90
91 #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
92
93 static int __proc_lnet_stats(void *data, int write,
94 loff_t pos, void *buffer, int nob)
95 {
96 int rc;
97 lnet_counters_t *ctrs;
98 int len;
99 char *tmpstr;
100 const int tmpsiz = 256; /* 7 %u and 4 LPU64 */
101
102 if (write) {
103 lnet_counters_reset();
104 return 0;
105 }
106
107 /* read */
108
109 LIBCFS_ALLOC(ctrs, sizeof(*ctrs));
110 if (ctrs == NULL)
111 return -ENOMEM;
112
113 LIBCFS_ALLOC(tmpstr, tmpsiz);
114 if (tmpstr == NULL) {
115 LIBCFS_FREE(ctrs, sizeof(*ctrs));
116 return -ENOMEM;
117 }
118
119 lnet_counters_get(ctrs);
120
121 len = snprintf(tmpstr, tmpsiz,
122 "%u %u %u %u %u %u %u "LPU64" "LPU64" "
123 LPU64" "LPU64,
124 ctrs->msgs_alloc, ctrs->msgs_max,
125 ctrs->errors,
126 ctrs->send_count, ctrs->recv_count,
127 ctrs->route_count, ctrs->drop_count,
128 ctrs->send_length, ctrs->recv_length,
129 ctrs->route_length, ctrs->drop_length);
130
131 if (pos >= min_t(int, len, strlen(tmpstr)))
132 rc = 0;
133 else
134 rc = cfs_trace_copyout_string(buffer, nob,
135 tmpstr + pos, "\n");
136
137 LIBCFS_FREE(tmpstr, tmpsiz);
138 LIBCFS_FREE(ctrs, sizeof(*ctrs));
139 return rc;
140 }
141
142 DECLARE_PROC_HANDLER(proc_lnet_stats);
143
144 int LL_PROC_PROTO(proc_lnet_routes)
145 {
146 const int tmpsiz = 256;
147 char *tmpstr;
148 char *s;
149 int rc = 0;
150 int len;
151 int ver;
152 int off;
153
154 DECLARE_LL_PROC_PPOS_DECL;
155
156 CLASSERT(sizeof(loff_t) >= 4);
157
158 off = LNET_PROC_HOFF_GET(*ppos);
159 ver = LNET_PROC_VER_GET(*ppos);
160
161 LASSERT(!write);
162
163 if (*lenp == 0)
164 return 0;
165
166 LIBCFS_ALLOC(tmpstr, tmpsiz);
167 if (tmpstr == NULL)
168 return -ENOMEM;
169
170 s = tmpstr; /* points to current position in tmpstr[] */
171
172 if (*ppos == 0) {
173 s += snprintf(s, tmpstr + tmpsiz - s, "Routing %s\n",
174 the_lnet.ln_routing ? "enabled" : "disabled");
175 LASSERT(tmpstr + tmpsiz - s > 0);
176
177 s += snprintf(s, tmpstr + tmpsiz - s, "%-8s %4s %8s %7s %s\n",
178 "net", "hops", "priority", "state", "router");
179 LASSERT(tmpstr + tmpsiz - s > 0);
180
181 lnet_net_lock(0);
182 ver = (unsigned int)the_lnet.ln_remote_nets_version;
183 lnet_net_unlock(0);
184 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
185 } else {
186 struct list_head *n;
187 struct list_head *r;
188 lnet_route_t *route = NULL;
189 lnet_remotenet_t *rnet = NULL;
190 int skip = off - 1;
191 struct list_head *rn_list;
192 int i;
193
194 lnet_net_lock(0);
195
196 if (ver != LNET_PROC_VERSION(the_lnet.ln_remote_nets_version)) {
197 lnet_net_unlock(0);
198 LIBCFS_FREE(tmpstr, tmpsiz);
199 return -ESTALE;
200 }
201
202 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE && route == NULL;
203 i++) {
204 rn_list = &the_lnet.ln_remote_nets_hash[i];
205
206 n = rn_list->next;
207
208 while (n != rn_list && route == NULL) {
209 rnet = list_entry(n, lnet_remotenet_t,
210 lrn_list);
211
212 r = rnet->lrn_routes.next;
213
214 while (r != &rnet->lrn_routes) {
215 lnet_route_t *re =
216 list_entry(r, lnet_route_t,
217 lr_list);
218 if (skip == 0) {
219 route = re;
220 break;
221 }
222
223 skip--;
224 r = r->next;
225 }
226
227 n = n->next;
228 }
229 }
230
231 if (route != NULL) {
232 __u32 net = rnet->lrn_net;
233 unsigned int hops = route->lr_hops;
234 unsigned int priority = route->lr_priority;
235 lnet_nid_t nid = route->lr_gateway->lp_nid;
236 int alive = route->lr_gateway->lp_alive;
237
238 s += snprintf(s, tmpstr + tmpsiz - s,
239 "%-8s %4u %8u %7s %s\n",
240 libcfs_net2str(net), hops,
241 priority,
242 alive ? "up" : "down",
243 libcfs_nid2str(nid));
244 LASSERT(tmpstr + tmpsiz - s > 0);
245 }
246
247 lnet_net_unlock(0);
248 }
249
250 len = s - tmpstr; /* how many bytes was written */
251
252 if (len > *lenp) { /* linux-supplied buffer is too small */
253 rc = -EINVAL;
254 } else if (len > 0) { /* wrote something */
255 if (copy_to_user(buffer, tmpstr, len))
256 rc = -EFAULT;
257 else {
258 off += 1;
259 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
260 }
261 }
262
263 LIBCFS_FREE(tmpstr, tmpsiz);
264
265 if (rc == 0)
266 *lenp = len;
267
268 return rc;
269 }
270
271 int LL_PROC_PROTO(proc_lnet_routers)
272 {
273 int rc = 0;
274 char *tmpstr;
275 char *s;
276 const int tmpsiz = 256;
277 int len;
278 int ver;
279 int off;
280
281 DECLARE_LL_PROC_PPOS_DECL;
282
283 off = LNET_PROC_HOFF_GET(*ppos);
284 ver = LNET_PROC_VER_GET(*ppos);
285
286 LASSERT(!write);
287
288 if (*lenp == 0)
289 return 0;
290
291 LIBCFS_ALLOC(tmpstr, tmpsiz);
292 if (tmpstr == NULL)
293 return -ENOMEM;
294
295 s = tmpstr; /* points to current position in tmpstr[] */
296
297 if (*ppos == 0) {
298 s += snprintf(s, tmpstr + tmpsiz - s,
299 "%-4s %7s %9s %6s %12s %9s %8s %7s %s\n",
300 "ref", "rtr_ref", "alive_cnt", "state",
301 "last_ping", "ping_sent", "deadline",
302 "down_ni", "router");
303 LASSERT(tmpstr + tmpsiz - s > 0);
304
305 lnet_net_lock(0);
306 ver = (unsigned int)the_lnet.ln_routers_version;
307 lnet_net_unlock(0);
308 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
309 } else {
310 struct list_head *r;
311 struct lnet_peer *peer = NULL;
312 int skip = off - 1;
313
314 lnet_net_lock(0);
315
316 if (ver != LNET_PROC_VERSION(the_lnet.ln_routers_version)) {
317 lnet_net_unlock(0);
318
319 LIBCFS_FREE(tmpstr, tmpsiz);
320 return -ESTALE;
321 }
322
323 r = the_lnet.ln_routers.next;
324
325 while (r != &the_lnet.ln_routers) {
326 lnet_peer_t *lp = list_entry(r, lnet_peer_t,
327 lp_rtr_list);
328
329 if (skip == 0) {
330 peer = lp;
331 break;
332 }
333
334 skip--;
335 r = r->next;
336 }
337
338 if (peer != NULL) {
339 lnet_nid_t nid = peer->lp_nid;
340 cfs_time_t now = cfs_time_current();
341 cfs_time_t deadline = peer->lp_ping_deadline;
342 int nrefs = peer->lp_refcount;
343 int nrtrrefs = peer->lp_rtr_refcount;
344 int alive_cnt = peer->lp_alive_count;
345 int alive = peer->lp_alive;
346 int pingsent = !peer->lp_ping_notsent;
347 int last_ping = cfs_duration_sec(cfs_time_sub(now,
348 peer->lp_ping_timestamp));
349 int down_ni = 0;
350 lnet_route_t *rtr;
351
352 if ((peer->lp_ping_feats &
353 LNET_PING_FEAT_NI_STATUS) != 0) {
354 list_for_each_entry(rtr, &peer->lp_routes,
355 lr_gwlist) {
356 /* downis on any route should be the
357 * number of downis on the gateway */
358 if (rtr->lr_downis != 0) {
359 down_ni = rtr->lr_downis;
360 break;
361 }
362 }
363 }
364
365 if (deadline == 0)
366 s += snprintf(s, tmpstr + tmpsiz - s,
367 "%-4d %7d %9d %6s %12d %9d %8s %7d %s\n",
368 nrefs, nrtrrefs, alive_cnt,
369 alive ? "up" : "down", last_ping,
370 pingsent, "NA", down_ni,
371 libcfs_nid2str(nid));
372 else
373 s += snprintf(s, tmpstr + tmpsiz - s,
374 "%-4d %7d %9d %6s %12d %9d %8lu %7d %s\n",
375 nrefs, nrtrrefs, alive_cnt,
376 alive ? "up" : "down", last_ping,
377 pingsent,
378 cfs_duration_sec(cfs_time_sub(deadline, now)),
379 down_ni, libcfs_nid2str(nid));
380 LASSERT(tmpstr + tmpsiz - s > 0);
381 }
382
383 lnet_net_unlock(0);
384 }
385
386 len = s - tmpstr; /* how many bytes was written */
387
388 if (len > *lenp) { /* linux-supplied buffer is too small */
389 rc = -EINVAL;
390 } else if (len > 0) { /* wrote something */
391 if (copy_to_user(buffer, tmpstr, len))
392 rc = -EFAULT;
393 else {
394 off += 1;
395 *ppos = LNET_PROC_POS_MAKE(0, ver, 0, off);
396 }
397 }
398
399 LIBCFS_FREE(tmpstr, tmpsiz);
400
401 if (rc == 0)
402 *lenp = len;
403
404 return rc;
405 }
406
407 int LL_PROC_PROTO(proc_lnet_peers)
408 {
409 const int tmpsiz = 256;
410 struct lnet_peer_table *ptable;
411 char *tmpstr;
412 char *s;
413 int cpt = LNET_PROC_CPT_GET(*ppos);
414 int ver = LNET_PROC_VER_GET(*ppos);
415 int hash = LNET_PROC_HASH_GET(*ppos);
416 int hoff = LNET_PROC_HOFF_GET(*ppos);
417 int rc = 0;
418 int len;
419
420 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS);
421 LASSERT(!write);
422
423 if (*lenp == 0)
424 return 0;
425
426 if (cpt >= LNET_CPT_NUMBER) {
427 *lenp = 0;
428 return 0;
429 }
430
431 LIBCFS_ALLOC(tmpstr, tmpsiz);
432 if (tmpstr == NULL)
433 return -ENOMEM;
434
435 s = tmpstr; /* points to current position in tmpstr[] */
436
437 if (*ppos == 0) {
438 s += snprintf(s, tmpstr + tmpsiz - s,
439 "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n",
440 "nid", "refs", "state", "last", "max",
441 "rtr", "min", "tx", "min", "queue");
442 LASSERT(tmpstr + tmpsiz - s > 0);
443
444 hoff++;
445 } else {
446 struct lnet_peer *peer;
447 struct list_head *p;
448 int skip;
449 again:
450 p = NULL;
451 peer = NULL;
452 skip = hoff - 1;
453
454 lnet_net_lock(cpt);
455 ptable = the_lnet.ln_peer_tables[cpt];
456 if (hoff == 1)
457 ver = LNET_PROC_VERSION(ptable->pt_version);
458
459 if (ver != LNET_PROC_VERSION(ptable->pt_version)) {
460 lnet_net_unlock(cpt);
461 LIBCFS_FREE(tmpstr, tmpsiz);
462 return -ESTALE;
463 }
464
465 while (hash < LNET_PEER_HASH_SIZE) {
466 if (p == NULL)
467 p = ptable->pt_hash[hash].next;
468
469 while (p != &ptable->pt_hash[hash]) {
470 lnet_peer_t *lp = list_entry(p, lnet_peer_t,
471 lp_hashlist);
472 if (skip == 0) {
473 peer = lp;
474
475 /* minor optimization: start from idx+1
476 * on next iteration if we've just
477 * drained lp_hashlist */
478 if (lp->lp_hashlist.next ==
479 &ptable->pt_hash[hash]) {
480 hoff = 1;
481 hash++;
482 } else {
483 hoff++;
484 }
485
486 break;
487 }
488
489 skip--;
490 p = lp->lp_hashlist.next;
491 }
492
493 if (peer != NULL)
494 break;
495
496 p = NULL;
497 hoff = 1;
498 hash++;
499 }
500
501 if (peer != NULL) {
502 lnet_nid_t nid = peer->lp_nid;
503 int nrefs = peer->lp_refcount;
504 int lastalive = -1;
505 char *aliveness = "NA";
506 int maxcr = peer->lp_ni->ni_peertxcredits;
507 int txcr = peer->lp_txcredits;
508 int mintxcr = peer->lp_mintxcredits;
509 int rtrcr = peer->lp_rtrcredits;
510 int minrtrcr = peer->lp_minrtrcredits;
511 int txqnob = peer->lp_txqnob;
512
513 if (lnet_isrouter(peer) ||
514 lnet_peer_aliveness_enabled(peer))
515 aliveness = peer->lp_alive ? "up" : "down";
516
517 if (lnet_peer_aliveness_enabled(peer)) {
518 cfs_time_t now = cfs_time_current();
519 cfs_duration_t delta;
520
521 delta = cfs_time_sub(now, peer->lp_last_alive);
522 lastalive = cfs_duration_sec(delta);
523
524 /* No need to mess up peers contents with
525 * arbitrarily long integers - it suffices to
526 * know that lastalive is more than 10000s old
527 */
528 if (lastalive >= 10000)
529 lastalive = 9999;
530 }
531
532 lnet_net_unlock(cpt);
533
534 s += snprintf(s, tmpstr + tmpsiz - s,
535 "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n",
536 libcfs_nid2str(nid), nrefs, aliveness,
537 lastalive, maxcr, rtrcr, minrtrcr, txcr,
538 mintxcr, txqnob);
539 LASSERT(tmpstr + tmpsiz - s > 0);
540
541 } else { /* peer is NULL */
542 lnet_net_unlock(cpt);
543 }
544
545 if (hash == LNET_PEER_HASH_SIZE) {
546 cpt++;
547 hash = 0;
548 hoff = 1;
549 if (peer == NULL && cpt < LNET_CPT_NUMBER)
550 goto again;
551 }
552 }
553
554 len = s - tmpstr; /* how many bytes was written */
555
556 if (len > *lenp) { /* linux-supplied buffer is too small */
557 rc = -EINVAL;
558 } else if (len > 0) { /* wrote something */
559 if (copy_to_user(buffer, tmpstr, len))
560 rc = -EFAULT;
561 else
562 *ppos = LNET_PROC_POS_MAKE(cpt, ver, hash, hoff);
563 }
564
565 LIBCFS_FREE(tmpstr, tmpsiz);
566
567 if (rc == 0)
568 *lenp = len;
569
570 return rc;
571 }
572
573 static int __proc_lnet_buffers(void *data, int write,
574 loff_t pos, void *buffer, int nob)
575 {
576 char *s;
577 char *tmpstr;
578 int tmpsiz;
579 int idx;
580 int len;
581 int rc;
582 int i;
583
584 LASSERT(!write);
585
586 /* (4 %d) * 4 * LNET_CPT_NUMBER */
587 tmpsiz = 64 * (LNET_NRBPOOLS + 1) * LNET_CPT_NUMBER;
588 LIBCFS_ALLOC(tmpstr, tmpsiz);
589 if (tmpstr == NULL)
590 return -ENOMEM;
591
592 s = tmpstr; /* points to current position in tmpstr[] */
593
594 s += snprintf(s, tmpstr + tmpsiz - s,
595 "%5s %5s %7s %7s\n",
596 "pages", "count", "credits", "min");
597 LASSERT(tmpstr + tmpsiz - s > 0);
598
599 if (the_lnet.ln_rtrpools == NULL)
600 goto out; /* I'm not a router */
601
602 for (idx = 0; idx < LNET_NRBPOOLS; idx++) {
603 lnet_rtrbufpool_t *rbp;
604
605 lnet_net_lock(LNET_LOCK_EX);
606 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
607 s += snprintf(s, tmpstr + tmpsiz - s,
608 "%5d %5d %7d %7d\n",
609 rbp[idx].rbp_npages,
610 rbp[idx].rbp_nbuffers,
611 rbp[idx].rbp_credits,
612 rbp[idx].rbp_mincredits);
613 LASSERT(tmpstr + tmpsiz - s > 0);
614 }
615 lnet_net_unlock(LNET_LOCK_EX);
616 }
617
618 out:
619 len = s - tmpstr;
620
621 if (pos >= min_t(int, len, strlen(tmpstr)))
622 rc = 0;
623 else
624 rc = cfs_trace_copyout_string(buffer, nob,
625 tmpstr + pos, NULL);
626
627 LIBCFS_FREE(tmpstr, tmpsiz);
628 return rc;
629 }
630
631 DECLARE_PROC_HANDLER(proc_lnet_buffers);
632
633 int LL_PROC_PROTO(proc_lnet_nis)
634 {
635 int tmpsiz = 128 * LNET_CPT_NUMBER;
636 int rc = 0;
637 char *tmpstr;
638 char *s;
639 int len;
640
641 DECLARE_LL_PROC_PPOS_DECL;
642
643 LASSERT(!write);
644
645 if (*lenp == 0)
646 return 0;
647
648 LIBCFS_ALLOC(tmpstr, tmpsiz);
649 if (tmpstr == NULL)
650 return -ENOMEM;
651
652 s = tmpstr; /* points to current position in tmpstr[] */
653
654 if (*ppos == 0) {
655 s += snprintf(s, tmpstr + tmpsiz - s,
656 "%-24s %6s %5s %4s %4s %4s %5s %5s %5s\n",
657 "nid", "status", "alive", "refs", "peer",
658 "rtr", "max", "tx", "min");
659 LASSERT(tmpstr + tmpsiz - s > 0);
660 } else {
661 struct list_head *n;
662 lnet_ni_t *ni = NULL;
663 int skip = *ppos - 1;
664
665 lnet_net_lock(0);
666
667 n = the_lnet.ln_nis.next;
668
669 while (n != &the_lnet.ln_nis) {
670 lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
671
672 if (skip == 0) {
673 ni = a_ni;
674 break;
675 }
676
677 skip--;
678 n = n->next;
679 }
680
681 if (ni != NULL) {
682 struct lnet_tx_queue *tq;
683 char *stat;
684 long now = cfs_time_current_sec();
685 int last_alive = -1;
686 int i;
687 int j;
688
689 if (the_lnet.ln_routing)
690 last_alive = now - ni->ni_last_alive;
691
692 /* @lo forever alive */
693 if (ni->ni_lnd->lnd_type == LOLND)
694 last_alive = 0;
695
696 lnet_ni_lock(ni);
697 LASSERT(ni->ni_status != NULL);
698 stat = (ni->ni_status->ns_status ==
699 LNET_NI_STATUS_UP) ? "up" : "down";
700 lnet_ni_unlock(ni);
701
702 /* we actually output credits information for
703 * TX queue of each partition */
704 cfs_percpt_for_each(tq, i, ni->ni_tx_queues) {
705 for (j = 0; ni->ni_cpts != NULL &&
706 j < ni->ni_ncpts; j++) {
707 if (i == ni->ni_cpts[j])
708 break;
709 }
710
711 if (j == ni->ni_ncpts)
712 continue;
713
714 if (i != 0)
715 lnet_net_lock(i);
716
717 s += snprintf(s, tmpstr + tmpsiz - s,
718 "%-24s %6s %5d %4d %4d %4d %5d %5d %5d\n",
719 libcfs_nid2str(ni->ni_nid), stat,
720 last_alive, *ni->ni_refs[i],
721 ni->ni_peertxcredits,
722 ni->ni_peerrtrcredits,
723 tq->tq_credits_max,
724 tq->tq_credits, tq->tq_credits_min);
725 if (i != 0)
726 lnet_net_unlock(i);
727 }
728 LASSERT(tmpstr + tmpsiz - s > 0);
729 }
730
731 lnet_net_unlock(0);
732 }
733
734 len = s - tmpstr; /* how many bytes was written */
735
736 if (len > *lenp) { /* linux-supplied buffer is too small */
737 rc = -EINVAL;
738 } else if (len > 0) { /* wrote something */
739 if (copy_to_user(buffer, tmpstr, len))
740 rc = -EFAULT;
741 else
742 *ppos += 1;
743 }
744
745 LIBCFS_FREE(tmpstr, tmpsiz);
746
747 if (rc == 0)
748 *lenp = len;
749
750 return rc;
751 }
752
753 struct lnet_portal_rotors {
754 int pr_value;
755 const char *pr_name;
756 const char *pr_desc;
757 };
758
759 static struct lnet_portal_rotors portal_rotors[] = {
760 {
761 .pr_value = LNET_PTL_ROTOR_OFF,
762 .pr_name = "OFF",
763 .pr_desc = "Turn off message rotor for wildcard portals"
764 },
765 {
766 .pr_value = LNET_PTL_ROTOR_ON,
767 .pr_name = "ON",
768 .pr_desc = "round-robin dispatch all PUT messages for "
769 "wildcard portals"
770 },
771 {
772 .pr_value = LNET_PTL_ROTOR_RR_RT,
773 .pr_name = "RR_RT",
774 .pr_desc = "round-robin dispatch routed PUT message for "
775 "wildcard portals"
776 },
777 {
778 .pr_value = LNET_PTL_ROTOR_HASH_RT,
779 .pr_name = "HASH_RT",
780 .pr_desc = "dispatch routed PUT message by hashing source "
781 "NID for wildcard portals"
782 },
783 {
784 .pr_value = -1,
785 .pr_name = NULL,
786 .pr_desc = NULL
787 },
788 };
789
790 extern int portal_rotor;
791
792 static int __proc_lnet_portal_rotor(void *data, int write,
793 loff_t pos, void *buffer, int nob)
794 {
795 const int buf_len = 128;
796 char *buf;
797 char *tmp;
798 int rc;
799 int i;
800
801 LIBCFS_ALLOC(buf, buf_len);
802 if (buf == NULL)
803 return -ENOMEM;
804
805 if (!write) {
806 lnet_res_lock(0);
807
808 for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
809 if (portal_rotors[i].pr_value == portal_rotor)
810 break;
811 }
812
813 LASSERT(portal_rotors[i].pr_value == portal_rotor);
814 lnet_res_unlock(0);
815
816 rc = snprintf(buf, buf_len,
817 "{\n\tportals: all\n"
818 "\trotor: %s\n\tdescription: %s\n}",
819 portal_rotors[i].pr_name,
820 portal_rotors[i].pr_desc);
821
822 if (pos >= min_t(int, rc, buf_len)) {
823 rc = 0;
824 } else {
825 rc = cfs_trace_copyout_string(buffer, nob,
826 buf + pos, "\n");
827 }
828 goto out;
829 }
830
831 rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
832 if (rc < 0)
833 goto out;
834
835 tmp = cfs_trimwhite(buf);
836
837 rc = -EINVAL;
838 lnet_res_lock(0);
839 for (i = 0; portal_rotors[i].pr_name != NULL; i++) {
840 if (strncasecmp(portal_rotors[i].pr_name, tmp,
841 strlen(portal_rotors[i].pr_name)) == 0) {
842 portal_rotor = portal_rotors[i].pr_value;
843 rc = 0;
844 break;
845 }
846 }
847 lnet_res_unlock(0);
848 out:
849 LIBCFS_FREE(buf, buf_len);
850 return rc;
851 }
852 DECLARE_PROC_HANDLER(proc_lnet_portal_rotor);
853
854 static ctl_table_t lnet_table[] = {
855 /*
856 * NB No .strategy entries have been provided since sysctl(8) prefers
857 * to go via /proc for portability.
858 */
859 {
860 .procname = "stats",
861 .mode = 0644,
862 .proc_handler = &proc_lnet_stats,
863 },
864 {
865 .procname = "routes",
866 .mode = 0444,
867 .proc_handler = &proc_lnet_routes,
868 },
869 {
870 .procname = "routers",
871 .mode = 0444,
872 .proc_handler = &proc_lnet_routers,
873 },
874 {
875 .procname = "peers",
876 .mode = 0444,
877 .proc_handler = &proc_lnet_peers,
878 },
879 {
880 .procname = "buffers",
881 .mode = 0444,
882 .proc_handler = &proc_lnet_buffers,
883 },
884 {
885 .procname = "nis",
886 .mode = 0444,
887 .proc_handler = &proc_lnet_nis,
888 },
889 {
890 .procname = "portal_rotor",
891 .mode = 0644,
892 .proc_handler = &proc_lnet_portal_rotor,
893 },
894 {
895 }
896 };
897
898 static ctl_table_t top_table[] = {
899 {
900 .procname = "lnet",
901 .mode = 0555,
902 .data = NULL,
903 .maxlen = 0,
904 .child = lnet_table,
905 },
906 {
907 }
908 };
909
910 void
911 lnet_proc_init(void)
912 {
913 if (lnet_table_header == NULL)
914 lnet_table_header = register_sysctl_table(top_table);
915 }
916
917 void
918 lnet_proc_fini(void)
919 {
920 if (lnet_table_header != NULL)
921 unregister_sysctl_table(lnet_table_header);
922
923 lnet_table_header = NULL;
924 }
925
926 #else
927
928 void
929 lnet_proc_init(void)
930 {
931 }
932
933 void
934 lnet_proc_fini(void)
935 {
936 }
937
938 #endif
This page took 0.079453 seconds and 5 git commands to generate.