Whamcloud - gitweb
LU-15103 tests: clean up busy cifs mount
[fs/lustre-release.git] / snmp / lustre-snmp.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * snmp/lustre-snmp.c
32  *
33  * Author: PJ Kirner <pjkirner@clusterfs.com>
34  */
35  
36 #include <net-snmp/net-snmp-config.h>
37 #include <net-snmp/net-snmp-includes.h>
38 #include <net-snmp/agent/net-snmp-agent-includes.h>
39 #include <net-snmp/utilities.h>
40 #include <pthread.h>
41 #include "lustre-snmp.h"
42
43 #include <libcfs/util/param.h>
44
45 #define LNET_CHECK_INTERVAL 500
46
47 /* 
48  * clusterFileSystems_variables_oid:
49  *   this is the top level oid that we want to register under.  This
50  *   is essentially a prefix, with the suffix appearing in the
51  *   variable below.
52  */
53
54
55 oid clusterFileSystems_variables_oid[] = { 1,3,6,1,4,1,13140 };
56
57
58 /* 
59  * variable7 clusterFileSystems_variables:
60  *   this variable defines function callbacks and type return information 
61  *   for the clusterFileSystems mib section 
62  */
63
64
65 struct variable7 clusterFileSystems_variables[] = {
66         /* systemInformation 2.1.1. */
67         {
68                 .magic          = SYSVERSION,
69                 .type           = ASN_OCTET_STR,
70                 .acl            = RONLY,
71                 .findVar        = var_clusterFileSystems,
72                 .namelen        = 4,
73                 .name           = { 2, 1, 1, 1 }
74         },
75         {
76                 .magic          = SYSKERNELVERSION,
77                 .type           = ASN_OCTET_STR,
78                 .acl            = RONLY,
79                 .findVar        = var_clusterFileSystems,
80                 .namelen        = 4,
81                 .name           = { 2, 1, 1, 2 }
82         },
83         {
84                 .magic          = SYSHEALTHCHECK,
85                 .type           = ASN_OCTET_STR,
86                 .acl            = RONLY,
87                 .findVar        = var_clusterFileSystems,
88                 .namelen        = 4,
89                 .name           = { 2, 1, 1, 3 }
90         },
91         {
92                 .magic          = SYSSTATUS,
93                 .type           = ASN_INTEGER,
94                 .acl            = RWRITE,
95                 .findVar        = var_clusterFileSystems,
96                 .namelen        = 4,
97                 .name           = { 2, 1, 1, 4 }
98         },
99
100         /* objectStorageTargets 2.1.2 */
101         {
102                 .magic          = OSDNUMBER,
103                 .type           = ASN_UNSIGNED,
104                 .acl            = RONLY,
105                 .findVar        = var_clusterFileSystems,
106                 .namelen        = 4,
107                 .name           = { 2, 1, 2, 1 }
108         },
109
110         /* objectStorageTargets.osdTable.osdEntry 2.1.2.2.1 */
111         {
112                 .magic          = OSDUUID,
113                 .type           = ASN_OCTET_STR,
114                 .acl            = RONLY,
115                 .findVar        = var_osdTable,
116                 .namelen        = 6,
117                 .name           = { 2, 1, 2, 2, 1, 2 }
118         },
119         {
120                 .magic          = OSDCOMMONNAME,
121                 .type           = ASN_OCTET_STR,
122                 .acl            = RONLY,
123                 .findVar        = var_osdTable,
124                 .namelen        = 6,
125                 .name           = { 2, 1, 2, 2, 1, 3 }
126         },
127         {
128                 .magic          = OSDCAPACITY,
129                 .type           = ASN_COUNTER64,
130                 .acl            = RONLY,
131                 .findVar        = var_osdTable,
132                 .namelen        = 6,
133                 .name           = { 2, 1, 2, 2, 1, 4 }
134         },
135         {
136                 .magic          = OSDFREECAPACITY,
137                 .type           = ASN_COUNTER64,
138                 .acl            = RONLY,
139                 .findVar        = var_osdTable,
140                 .namelen        = 6,
141                 .name           = { 2, 1, 2, 2, 1, 5 }
142         },
143         {
144                 .magic          = OSDOBJECTS,
145                 .type           = ASN_COUNTER64,
146                 .acl            = RONLY,
147                 .findVar        = var_osdTable,
148                 .namelen        = 6,
149                 .name           = { 2, 1, 2, 2, 1, 6 }
150         },
151         {
152                 .magic          = OSDFREEOBJECTS,
153                 .type           = ASN_COUNTER64,
154                 .acl            = RONLY,
155                 .findVar        = var_osdTable,
156                 .namelen        = 6,
157                 .name           = { 2, 1, 2, 2, 1, 7 }
158         },
159
160         /* objectStorageClients 2.1.3 */
161         {
162                 .magic          = OSCNUMBER,
163                 .type           = ASN_UNSIGNED,
164                 .acl            = RONLY,
165                 .findVar        = var_clusterFileSystems,
166                 .namelen        = 4,
167                 .name           = { 2, 1, 3, 1 }
168         },
169
170         /* objectStorageClients.oscTable.oscEntry 2.1.3.2.1 */
171         {
172                 .magic          = OSCUUID,
173                 .type           = ASN_OCTET_STR,
174                 .acl            = RONLY,
175                 .findVar        = var_oscTable,
176                 .namelen        = 6,
177                 .name           = { 2, 1, 3, 2, 1, 2 }
178         },
179         {
180                 .magic          = OSCCOMMONNAME,
181                 .type           = ASN_OCTET_STR,
182                 .acl            = RONLY,
183                 .findVar        = var_oscTable,
184                 .namelen        = 6,
185                 .name           = { 2, 1, 3, 2, 1, 3 }
186         },
187         {
188                 .magic          = OSCOSTSERVERUUID,
189                 .type           = ASN_OCTET_STR,
190                 .acl            = RONLY,
191                 .findVar        = var_oscTable,
192                 .namelen        = 6,
193                 .name           = { 2, 1, 3, 2, 1, 4 }
194         },
195         {
196                 .magic          = OSCCAPACITY,
197                 .type           = ASN_COUNTER64,
198                 .acl            = RONLY,
199                 .findVar        = var_oscTable,
200                 .namelen        = 6,
201                 .name           = { 2, 1, 3, 2, 1, 5 }
202         },
203         {
204                 .magic          = OSCFREECAPACITY,
205                 .type           = ASN_COUNTER64,
206                 .acl            = RONLY,
207                 .findVar        = var_oscTable,
208                 .namelen        = 6,
209                 .name           = { 2, 1, 3, 2, 1, 6 }
210         },
211         {
212                 .magic          = OSCOBJECTS,
213                 .type           = ASN_COUNTER64,
214                 .acl            = RONLY,
215                 .findVar        = var_oscTable,
216                 .namelen        = 6,
217                 .name           = { 2, 1, 3, 2, 1, 7 }
218         },
219         {
220                 .magic          = OSCFREEOBJECTS,
221                 .type           = ASN_COUNTER64,
222                 .acl            = RONLY,
223                 .findVar        = var_oscTable,
224                 .namelen        = 6,
225                 .name           = { 2, 1, 3, 2, 1, 8 }
226         },
227
228
229         /* metaDataServers 2.1.4 */
230         {
231                 .magic          = MDDNUMBER,
232                 .type           = ASN_UNSIGNED,
233                 .acl            = RONLY,
234                 .findVar        = var_clusterFileSystems,
235                 .namelen        = 4,
236                 .name           = { 2, 1, 4, 1 }
237         },
238
239         /* metaDataServers.mddTable.mddEntry 2.1.4.2.1 */
240         {
241                 .magic          = MDDUUID,
242                 .type           = ASN_OCTET_STR,
243                 .acl            = RONLY,
244                 .findVar        = var_mdsTable,
245                 .namelen        = 6,
246                 .name           = { 2, 1, 4, 2, 1, 2 }
247         },
248         {
249                 .magic          = MDDCOMMONNAME,
250                 .type           = ASN_OCTET_STR,
251                 .acl            = RONLY,
252                 .findVar        = var_mdsTable,
253                 .namelen        = 6,
254                 .name           = { 2, 1, 4, 2, 1, 3 }
255         },
256         {
257                 .magic          = MDDCAPACITY,
258                 .type           = ASN_COUNTER64,
259                 .acl            = RONLY,
260                 .findVar        = var_mdsTable,
261                 .namelen        = 6,
262                 .name           = { 2, 1, 4, 2, 1, 4 }
263         },
264         {
265                 .magic          = MDDFREECAPACITY,
266                 .type           = ASN_COUNTER64,
267                 .acl            = RONLY,
268                 .findVar        = var_mdsTable,
269                 .namelen        = 6,
270                 .name           = { 2, 1, 4, 2, 1, 5 }
271         },
272         {
273                 .magic          = MDDFILES,
274                 .type           = ASN_COUNTER64,
275                 .acl            = RONLY,
276                 .findVar        = var_mdsTable,
277                 .namelen        = 6,
278                 .name           = { 2, 1, 4, 2, 1, 6 }
279         },
280         {
281                 .magic          = MDDFREEFILES,
282                 .type           = ASN_COUNTER64,
283                 .acl            = RONLY,
284                 .findVar        = var_mdsTable,
285                 .namelen        = 6,
286                 .name           = { 2, 1, 4, 2, 1, 7 }
287         },
288         {
289                 .magic          = MDSNBSAMPLEDREQ,
290                 .type           = ASN_COUNTER64,
291                 .acl            = RONLY,
292                 .findVar        = var_mdsNbSampledReq,
293                 .namelen        = 4,
294                 .name           = { 2, 1, 4, 3 }
295         },
296
297         /* metaDataClients 2.1.5 */
298         {
299                 .magic          = MDCNUMBER,
300                 .type           = ASN_UNSIGNED,
301                 .acl            = RONLY,
302                 .findVar        = var_clusterFileSystems,
303                 .namelen        = 4,
304                 .name           = { 2, 1, 5, 1 }
305         },
306
307         /* metaDataClients.mdcTable.mdcEntry 2.1.5.2.1 */
308         {
309                 .magic          = MDCUUID,
310                 .type           = ASN_OCTET_STR,
311                 .acl            = RONLY,
312                 .findVar        = var_mdcTable,
313                 .namelen        = 6,
314                 .name           = { 2, 1, 5, 2, 1, 2 }
315         },
316         {
317                 .magic          = MDCCOMMONNAME,
318                 .type           = ASN_OCTET_STR,
319                 .acl            = RONLY,
320                 .findVar        = var_mdcTable,
321                 .namelen        = 6,
322                 .name           = { 2, 1, 5, 2, 1, 3 }
323         },
324         {
325                 .magic          = MDCMDSSERVERUUID,
326                 .type           = ASN_OCTET_STR,
327                 .acl            = RONLY,
328                 .findVar        = var_mdcTable,
329                 .namelen        = 6,
330                 .name           = { 2, 1, 5, 2, 1, 4 }
331         },
332         {
333                 .magic          = MDCCAPACITY,
334                 .type           = ASN_COUNTER64,
335                 .acl            = RONLY,
336                 .findVar        = var_mdcTable,
337                 .namelen        = 6,
338                 .name           = { 2, 1, 5, 2, 1, 5 }
339         },
340         {
341                 .magic          = MDCFREECAPACITY,
342                 .type           = ASN_COUNTER64,
343                 .acl            = RONLY,
344                 .findVar        = var_mdcTable,
345                 .namelen        = 6,
346                 .name           = { 2, 1, 5, 2, 1, 6 }
347         },
348         {
349                 .magic          = MDCOBJECTS,
350                 .type           = ASN_COUNTER64,
351                 .acl            = RONLY,
352                 .findVar        = var_mdcTable,
353                 .namelen        = 6,
354                 .name           = { 2, 1, 5, 2, 1, 7 }
355         },
356         {
357                 .magic          = MDCFREEOBJECTS,
358                 .type           = ASN_COUNTER64,
359                 .acl            = RONLY,
360                 .findVar        = var_mdcTable,
361                 .namelen        = 6,
362                 .name           = { 2, 1, 5, 2, 1, 8 }
363         },
364
365         /* lustreClients 2.1.6 */
366         {
367                 .magic          = CLIMOUNTNUMBER,
368                 .type           = ASN_UNSIGNED,
369                 .acl            = RONLY,
370                 .findVar        = var_clusterFileSystems,
371                 .namelen        = 4,
372                 .name           = { 2, 1, 6, 1 }
373         },
374
375         /* lustreClients.cliMountTable.cliMountEntry 2.1.6.2.1 */
376         {
377                 .magic          = CLIUUID,
378                 .type           = ASN_OCTET_STR,
379                 .acl            = RONLY,
380                 .findVar        = var_cliTable,
381                 .namelen        = 6,
382                 .name           = { 2, 1, 6, 2, 1, 2 }
383         },
384         {
385                 .magic          = CLICOMMONNAME,
386                 .type           = ASN_OCTET_STR,
387                 .acl            = RONLY,
388                 .findVar        = var_cliTable,
389                 .namelen        = 6,
390                 .name           = { 2, 1, 6, 2, 1, 3 }
391         },
392         {
393                 .magic          = CLIMDCUUID,
394                 .type           = ASN_OCTET_STR,
395                 .acl            = RONLY,
396                 .findVar        = var_cliTable,
397                 .namelen        = 6,
398                 .name           = { 2, 1, 6, 2, 1, 4 }
399         },
400         {
401                 .magic          = CLIMDCCOMMONNAME,
402                 .type           = ASN_OCTET_STR,
403                 .acl            = RONLY,
404                 .findVar        = var_cliTable,
405                 .namelen        = 6,
406                 .name           = { 2, 1, 6, 2, 1, 5 }
407         },
408         {
409                 .magic          = CLIUSESLOV,
410                 .type           = ASN_INTEGER,
411                 .acl            = RONLY,
412                 .findVar        = var_cliTable,
413                 .namelen        = 6,
414                 .name           = { 2, 1, 6, 2, 1, 6 }
415         },
416         {
417                 .magic          = CLILOVUUID,
418                 .type           = ASN_OCTET_STR,
419                 .acl            = RONLY,
420                 .findVar        = var_cliTable,
421                 .namelen        = 6,
422                 .name           = { 2, 1, 6, 2, 1, 7 }
423         },
424         {
425                 .magic          = CLILOVCOMMONNAME,
426                 .type           = ASN_OCTET_STR,
427                 .acl            = RONLY,
428                 .findVar        = var_cliTable,
429                 .namelen        = 6,
430                 .name           = { 2, 1, 6, 2, 1, 8 }
431         },
432
433         /* logicalObjectVolume 2.1.7 */
434         {
435                 .magic          = LOVNUMBER,
436                 .type           = ASN_UNSIGNED,
437                 .acl            = RONLY,
438                 .findVar        = var_clusterFileSystems,
439                 .namelen        = 4,
440                 .name           = { 2, 1, 7, 1 }
441         },
442
443         /* logicalObjectVolume.osdTable.lovTable 2.1.7.2.1 */
444         {
445                 .magic          = LOVUUID,
446                 .type           = ASN_OCTET_STR,
447                 .acl            = RONLY,
448                 .findVar        = var_lovTable,
449                 .namelen        = 6,
450                 .name           = { 2, 1, 7, 2, 1, 2 }
451         },
452         {
453                 .magic          = LOVCOMMONNAME,
454                 .type           = ASN_OCTET_STR,
455                 .acl            = RONLY,
456                 .findVar        = var_lovTable,
457                 .namelen        = 6,
458                 .name           = { 2, 1, 7, 2, 1, 3 }
459         },
460         {
461                 .magic          = LOVNUMOBD,
462                 .type           = ASN_UNSIGNED,
463                 .acl            = RONLY,
464                 .findVar        = var_lovTable,
465                 .namelen        = 6,
466                 .name           = { 2, 1, 7, 2, 1, 4 }
467         },
468         {
469                 .magic          = LOVNUMACTIVEOBD,
470                 .type           = ASN_UNSIGNED,
471                 .acl            = RONLY,
472                 .findVar        = var_lovTable,
473                 .namelen        = 6,
474                 .name           = { 2, 1, 7, 2, 1, 5 }
475         },
476         {
477                 .magic          = LOVCAPACITY,
478                 .type           = ASN_COUNTER64,
479                 .acl            = RONLY,
480                 .findVar        = var_lovTable,
481                 .namelen        = 6,
482                 .name           = { 2, 1, 7, 2, 1, 6 }
483         },
484         {
485                 .magic          = LOVFREECAPACITY,
486                 .type           = ASN_COUNTER64,
487                 .acl            = RONLY,
488                 .findVar        = var_lovTable,
489                 .namelen        = 6,
490                 .name           = { 2, 1, 7, 2, 1, 7 }
491         },
492         {
493                 .magic          = LOVFILES,
494                 .type           = ASN_COUNTER64,
495                 .acl            = RONLY,
496                 .findVar        = var_lovTable,
497                 .namelen        = 6,
498                 .name           = { 2, 1, 7, 2, 1, 8 }
499         },
500         {
501                 .magic          = LOVFREEFILES,
502                 .type           = ASN_COUNTER64,
503                 .acl            = RONLY,
504                 .findVar        = var_lovTable,
505                 .namelen        = 6,
506                 .name           = { 2, 1, 7, 2, 1, 9 }
507         },
508         {
509                 .magic          = LOVSTRIPECOUNT,
510                 .type           = ASN_UNSIGNED,
511                 .acl            = RONLY,
512                 .findVar        = var_lovTable,
513                 .namelen        = 6,
514                 .name           = { 2, 1, 7, 2, 1, 10}
515         },
516         {
517                 .magic          = LOVSTRIPEOFFSET,
518                 .type           = ASN_UNSIGNED,
519                 .acl            = RONLY,
520                 .findVar        = var_lovTable,
521                 .namelen        = 6,
522                 .name           = { 2, 1, 7, 2, 1, 11}
523         },
524         {
525                 .magic          = LOVSTRIPESIZE,
526                 .type           = ASN_UNSIGNED,
527                 .acl            = RONLY,
528                 .findVar        = var_lovTable,
529                 .namelen        = 6,
530                 .name           = { 2, 1, 7, 2, 1, 12}
531         },
532         {
533                 .magic          = LOVSTRIPETYPE,
534                 .type           = ASN_UNSIGNED,
535                 .acl            = RONLY,
536                 .findVar        = var_lovTable,
537                 .namelen        = 6,
538                 .name           = { 2, 1, 7, 2, 1, 13}
539         },
540
541         /* lustreLDLM 2.1.8 */
542         {
543                 .magic          = LDLMNUMBER,
544                 .type           = ASN_UNSIGNED,
545                 .acl            = RONLY,
546                 .findVar        = var_clusterFileSystems,
547                 .namelen        = 4,
548                 .name           = { 2, 1, 8, 1 }
549         },
550
551         /* lustreLDLM.ldlmTable.ldlmEntry 2.1.8.2.1 */
552         {
553                 .magic          = LDLMNAMESPACE,
554                 .type           = ASN_OCTET_STR,
555                 .acl            = RONLY,
556                 .findVar        = var_ldlmTable,
557                 .namelen        = 6,
558                 .name           = { 2, 1, 8, 2, 1, 2 }
559         },
560         {
561                 .magic          = LDLMLOCKCOUNT,
562                 .type           = ASN_UNSIGNED,
563                 .acl            = RONLY,
564                 .findVar        = var_ldlmTable,
565                 .namelen        = 6,
566                 .name           = { 2, 1, 8, 2, 1, 3 }
567         },
568         {
569                 .magic          = LDLMUNUSEDLOCKCOUNT,
570                 .type           = ASN_UNSIGNED,
571                 .acl            = RONLY,
572                 .findVar        = var_ldlmTable,
573                 .namelen        = 6,
574                 .name           = { 2, 1, 8, 2, 1, 4 }
575         },
576         {
577                 .magic          = LDLMRESOURCECOUNT,
578                 .type           = ASN_UNSIGNED,
579                 .acl            = RONLY,
580                 .findVar        = var_ldlmTable,
581                 .namelen        = 6,
582                 .name           = { 2, 1, 8, 2, 1, 5 }
583         },
584
585         /* lnetInformation 2.1.9 */
586         {
587                 .magic          = LNETMSGSALLOC,
588                 .type           = ASN_UNSIGNED,
589                 .acl            = RONLY,
590                 .findVar        = var_lnetInformation,
591                 .namelen        = 4,
592                 .name           = { 2, 1, 9, 1 }
593         },
594         {
595                 .magic          = LNETMSGSMAX,
596                 .type           = ASN_UNSIGNED,
597                 .acl            = RONLY,
598                 .findVar        = var_lnetInformation,
599                 .namelen        = 4,
600                 .name           = { 2, 1, 9, 2 }
601         },
602         {
603                 .magic          = LNETERRORS,
604                 .type           = ASN_UNSIGNED,
605                 .acl            = RONLY,
606                 .findVar        = var_lnetInformation,
607                 .namelen        = 4,
608                 .name           = { 2, 1, 9, 3 }
609         },
610         {
611                 .magic          = LNETSENDCOUNT,
612                 .type           = ASN_UNSIGNED,
613                 .acl            = RONLY,
614                 .findVar        = var_lnetInformation,
615                 .namelen        = 4,
616                 .name           = { 2, 1, 9, 4 }
617         },
618         {
619                 .magic          = LNETRECVCOUNT,
620                 .type           = ASN_UNSIGNED,
621                 .acl            = RONLY,
622                 .findVar        = var_lnetInformation,
623                 .namelen        = 4,
624                 .name           = { 2, 1, 9, 5 }
625         },
626         {
627                 .magic          = LNETROUTECOUNT,
628                 .type           = ASN_UNSIGNED,
629                 .acl            = RONLY,
630                 .findVar        = var_lnetInformation,
631                 .namelen        = 4,
632                 .name           = { 2, 1, 9, 6 }
633         },
634         {
635                 .magic          = LNETDROPCOUNT,
636                 .type           = ASN_UNSIGNED,
637                 .acl            = RONLY,
638                 .findVar        = var_lnetInformation,
639                 .namelen        = 4,
640                 .name           = { 2, 1, 9, 7 }
641         },
642         {
643                 .magic          = LNETSENDBYTES,
644                 .type           = ASN_COUNTER64,
645                 .acl            = RONLY,
646                 .findVar        = var_lnetInformation,
647                 .namelen        = 4,
648                 .name           = { 2, 1, 9, 8 }
649         },
650         {
651                 .magic          = LNETRECVBYTES,
652                 .type           = ASN_COUNTER64,
653                 .acl            = RONLY,
654                 .findVar        = var_lnetInformation,
655                 .namelen        = 4,
656                 .name           = { 2, 1, 9, 9 }
657         },
658         {
659                 .magic          = LNETROUTEBYTES,
660                 .type           = ASN_COUNTER64,
661                 .acl            = RONLY,
662                 .findVar        = var_lnetInformation,
663                 .namelen        = 4,
664                 .name           = { 2, 1, 9, 10 }
665         },
666         {
667                 .magic          = LNETDROPBYTES,
668                 .type           = ASN_COUNTER64,
669                 .acl            = RONLY,
670                 .findVar        = var_lnetInformation,
671                 .namelen        = 4,
672                 .name           = { 2, 1, 9, 11 }
673         },
674 };
675
676 /*****************************************************************************
677  * Function: init_cfsNetSNMPPlugin
678  *
679  * Description: Called when the agent starts up
680  *
681  * Input:   void
682  *
683  * Output:  None
684  *
685  ****************************************************************************/
686  
687 void init_lustresnmp(void) {
688
689         /* register ourselves with the agent to handle our mib tree */
690         REGISTER_MIB("clusterFileSystems",
691                      clusterFileSystems_variables, variable7,
692                      clusterFileSystems_variables_oid);
693
694         initialize_trap_handler();
695
696         DEBUGMSGTL(("lsnmpd", "%s %s\n", __func__, "Initialization Done"));
697 }
698
699 /*****************************************************************************
700  * Function: deinit_cfsNetSNMPPlugin
701  *
702  * Description: Called when the agent terminates up
703  *
704  * Input:   void
705  *
706  * Output:  None
707  *
708  ****************************************************************************/
709
710 void deinit_lustresnmp(void) {
711
712         /* deregister ourselves with the agent */
713         unregister_mib(clusterFileSystems_variables_oid,
714                        sizeof(clusterFileSystems_variables_oid)/
715                        sizeof(clusterFileSystems_variables_oid));
716
717         terminate_trap_handler();
718
719         DEBUGMSGTL(("lsnmpd", "%s %s\n", __func__, "Termination Done"));
720 }
721
722 /*****************************************************************************
723  * Function: var_clusterFileSystems
724  *
725  ****************************************************************************/
726 unsigned char *
727 var_clusterFileSystems(struct variable *vp, 
728                 oid     *name, 
729                 size_t  *length, 
730                 int     exact, 
731                 size_t  *var_len, 
732                 WriteMethod **write_method)
733 {
734
735
736   /* variables we may use later */
737   static long long_ret;
738   static u_long ulong_ret;
739   static unsigned char string[SPRINT_MAX_LEN];
740   glob_t path;
741   uint32_t num;
742   char *dir_list;
743
744   if (header_generic(vp,name,length,exact,var_len,write_method)
745                                   == MATCH_FAILED )
746     return NULL;
747
748
749   /* 
750    * this is where we do the value assignments for the mib results.
751    */
752   switch(vp->magic) {
753
754     case SYSVERSION:
755         if (cfs_get_param_paths(&path, "version") != 0)
756             return NULL;
757         if( SUCCESS != read_string(path.gl_pathv[0], (char *)string,sizeof(string))){
758             cfs_free_param_data(&path);
759             return NULL;
760         }
761         cfs_free_param_data(&path);
762         *var_len = strlen((char *)string);
763         return (unsigned char *) string;
764
765     case SYSKERNELVERSION:
766         if (cfs_get_param_paths(&path, "kernel_version") != 0)
767             return NULL;
768         if( SUCCESS != read_string(path.gl_pathv[0], (char *)string,sizeof(string))){
769             cfs_free_param_data(&path);
770             return NULL;
771         }
772         cfs_free_param_data(&path);
773         *var_len = strlen((char *)string);
774         return (unsigned char *) string;
775
776     case SYSHEALTHCHECK:
777         if (cfs_get_param_paths(&path, "health_check") != 0)
778             return NULL;
779         if( SUCCESS != read_string(path.gl_pathv[0], (char *)string,sizeof(string))){
780             cfs_free_param_data(&path);
781             return NULL;
782         }
783         cfs_free_param_data(&path);
784         *var_len = strlen((char*)string);
785         return (unsigned char *) string;
786
787     case SYSSTATUS:
788         *write_method = write_sysStatus;
789         long_ret = (long) get_sysstatus();
790         if (long_ret != ERROR)
791           return (unsigned char *) &long_ret;
792         return NULL;
793                       
794     case OSDNUMBER:
795         if (cfs_get_param_paths(&path, "obdfilter") != 0)
796             return NULL;
797         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
798             cfs_free_param_data(&path);
799             return NULL;
800         }
801         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
802         cfs_free_param_data(&path);
803         ulong_ret =  num;
804         free(dir_list);
805         return (unsigned char *) &ulong_ret;
806
807     case OSCNUMBER:
808         if (cfs_get_param_paths(&path, "osc") != 0)
809             return NULL;
810         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
811             cfs_free_param_data(&path);
812             return NULL;
813         }
814         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
815         cfs_free_param_data(&path);
816         ulong_ret =  num;
817         free(dir_list);
818         return (unsigned char *) &ulong_ret;
819
820     case MDDNUMBER:
821         if (cfs_get_param_paths(&path, "mds") != 0)
822             return NULL;
823         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
824             cfs_free_param_data(&path);
825             return NULL;
826         }
827         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
828         cfs_free_param_data(&path);
829         ulong_ret =  num;
830         free(dir_list);
831         return (unsigned char *) &ulong_ret;
832
833     case MDCNUMBER:
834         if (cfs_get_param_paths(&path, "mdc") != 0)
835             return NULL;
836         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
837             cfs_free_param_data(&path);
838             return NULL;
839         }
840         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
841         cfs_free_param_data(&path);
842         ulong_ret =  num;
843         free(dir_list);
844         return (unsigned char *) &ulong_ret;
845
846     case CLIMOUNTNUMBER:
847         if (cfs_get_param_paths(&path, "llite") != 0)
848             return NULL;
849         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
850             cfs_free_param_data(&path);
851             return NULL;
852         }
853         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
854         cfs_free_param_data(&path);
855         ulong_ret =  num;
856         free(dir_list);
857         return (unsigned char *) &ulong_ret;
858
859     case LOVNUMBER:
860         if (cfs_get_param_paths(&path, "lov") != 0)
861             return NULL;
862         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
863             cfs_free_param_data(&path);
864             return NULL;
865         }
866         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
867         cfs_free_param_data(&path);
868         ulong_ret =  num;
869         free(dir_list);
870         return (unsigned char *) &ulong_ret;
871
872     case LDLMNUMBER:
873         if (cfs_get_param_paths(&path, "ldlm/namespaces") != 0)
874             return NULL;
875         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
876             cfs_free_param_data(&path);
877             return NULL;
878         }
879         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
880         cfs_free_param_data(&path);
881         ulong_ret =  num;
882         free(dir_list);
883         return (unsigned char *) &ulong_ret;
884
885     default:
886       ERROR_MSG("");
887   }
888   return NULL;
889 }
890
891 struct oid_table osd_table[] = {
892         {
893                 .magic          = OSDUUID,
894                 .name           = FILENAME_UUID,
895                 .fhandler       = oid_table_string_handler
896         },
897         {
898                 .magic          = OSDCOMMONNAME,
899                 .name           = NULL,
900                 .fhandler       = oid_table_obj_name_handler
901         },
902         {
903                 .magic          = OSDCAPACITY,
904                 .name           = FILENAME_KBYTES_TOTAL,
905                 .fhandler       = oid_table_c64_kb_handler
906         },
907         {
908                 .magic          = OSDFREECAPACITY,
909                 .name           = FILENAME_KBYTES_FREE,
910                 .fhandler       = oid_table_c64_kb_handler
911         },
912         {
913                 .magic          = OSDOBJECTS,
914                 .name           = FILENAME_FILES_TOTAL,
915                 .fhandler       = oid_table_c64_kb_handler
916         },
917         {
918                 .magic          = OSDFREEOBJECTS,
919                 .name           = FILENAME_FILES_FREE,
920                 .fhandler       = oid_table_c64_kb_handler
921         },
922         {
923                 .magic          = 0,
924                 .name           = NULL,
925                 .fhandler       = NULL
926         } /*End of table*/
927 };
928
929
930 /*****************************************************************************
931  * Function: var_osdTable
932  *
933  ****************************************************************************/
934 unsigned char *
935 var_osdTable(struct variable *vp,
936             oid     *name,
937             size_t  *length,
938             int     exact,
939             size_t  *var_len,
940             WriteMethod **write_method)
941 {
942     unsigned char *table;
943     glob_t path;
944
945     if (cfs_get_param_paths(&path, "obdfilter") != 0)
946         return NULL;
947
948     table = var_genericTable(vp,name,length,exact,var_len,write_method,
949                              path.gl_pathv[0],osd_table);
950     cfs_free_param_data(&path);
951     return table;
952 }
953
954 struct oid_table osc_table[] = {
955         {
956                 .magic          = OSCUUID,
957                 .name           = FILENAME_UUID,
958                 .fhandler       = oid_table_string_handler
959         },
960         {
961                 .magic          = OSCCOMMONNAME,
962                 .name           = NULL,
963                 .fhandler       = oid_table_obj_name_handler
964         },
965         {
966                 .magic          = OSCOSTSERVERUUID,
967                 .name           = "ost_server_uuid",
968                 .fhandler       = oid_table_string_handler
969         },
970         {
971                 .magic          = OSCCAPACITY,
972                 .name           = FILENAME_KBYTES_TOTAL,
973                 .fhandler       = oid_table_c64_kb_handler
974         },
975         {
976                 .magic          = OSCFREECAPACITY,
977                 .name           = FILENAME_KBYTES_FREE,
978                 .fhandler       = oid_table_c64_kb_handler
979         },
980         {
981                 .magic          = OSCOBJECTS,
982                 .name           = FILENAME_FILES_TOTAL,
983                 .fhandler       = oid_table_c64_kb_handler
984         },
985         {
986                 .magic          = OSCFREEOBJECTS,
987                 .name           = FILENAME_FILES_FREE,
988                 .fhandler       = oid_table_c64_kb_handler
989         },
990         {
991                 .magic          = 0,
992                 .name           = NULL,
993                 .fhandler       = NULL
994         } /*End of table*/
995 };
996
997 /*****************************************************************************
998  * Function: var_oscTable
999  *
1000  ****************************************************************************/
1001 unsigned char *
1002 var_oscTable(struct variable *vp,
1003             oid     *name,
1004             size_t  *length,
1005             int     exact,
1006             size_t  *var_len,
1007             WriteMethod **write_method)
1008 {
1009     unsigned char *table;
1010     glob_t path;
1011
1012     if (cfs_get_param_paths(&path, "osc") != 0)
1013         return NULL;
1014
1015     table = var_genericTable(vp,name,length,exact,var_len,write_method,
1016                              path.gl_pathv[0],osd_table);
1017     cfs_free_param_data(&path);
1018     return table;
1019 }
1020
1021 struct oid_table mds_table[] = {
1022         {
1023                 .magic          = MDDUUID,
1024                 .name           = FILENAME_UUID,
1025                 .fhandler       = oid_table_string_handler
1026         },
1027         {
1028                 .magic          = MDDCOMMONNAME,
1029                 .name           = NULL,
1030                 .fhandler       = oid_table_obj_name_handler
1031         },
1032         {
1033                 .magic          = MDDCAPACITY,
1034                 .name           = FILENAME_KBYTES_TOTAL,
1035                 .fhandler       = oid_table_c64_kb_handler
1036         },
1037         {
1038                 .magic          = MDDFREECAPACITY,
1039                 .name           = FILENAME_KBYTES_FREE,
1040                 .fhandler       = oid_table_c64_kb_handler
1041         },
1042         {
1043                 .magic          = MDDFILES,
1044                 .name           = FILENAME_FILES_TOTAL,
1045                 .fhandler       = oid_table_c64_kb_handler
1046         },
1047         {
1048                 .magic          = MDDFREEFILES,
1049                 .name           = FILENAME_FILES_FREE,
1050                 .fhandler       = oid_table_c64_kb_handler
1051         },
1052         {
1053                 .magic          = 0,
1054                 .name           = NULL,
1055                 .fhandler       = NULL
1056         } /*End of table*/
1057 };
1058
1059 /*****************************************************************************
1060  * Function: var_mdsTable
1061  *
1062  ****************************************************************************/
1063 unsigned char *
1064 var_mdsTable(struct variable *vp,
1065             oid     *name,
1066             size_t  *length,
1067             int     exact,
1068             size_t  *var_len,
1069             WriteMethod **write_method)
1070 {
1071     unsigned char *table;
1072     glob_t path;
1073
1074     if (cfs_get_param_paths(&path, "mds") != 0)
1075         return NULL;
1076
1077     table = var_genericTable(vp,name,length,exact,var_len,write_method,
1078                              path.gl_pathv[0],osd_table);
1079     cfs_free_param_data(&path);
1080     return table;
1081 }
1082
1083 struct oid_table mdc_table[] = {
1084         {
1085                 .magic          = MDCUUID,
1086                 .name           = FILENAME_UUID,
1087                 .fhandler       = oid_table_string_handler
1088         },
1089         {
1090                 .magic          = MDCCOMMONNAME,
1091                 .name           = NULL,
1092                 .fhandler       = oid_table_obj_name_handler
1093         },
1094         {
1095                 .magic          = MDCMDSSERVERUUID,
1096                 .name           = "mds_server_uuid",
1097                 .fhandler       = oid_table_string_handler
1098         },
1099         {
1100                 .magic          = MDCCAPACITY,
1101                 .name           = FILENAME_KBYTES_TOTAL,
1102                 .fhandler       = oid_table_c64_kb_handler
1103         },
1104         {
1105                 .magic          = MDCFREECAPACITY,
1106                 .name           = FILENAME_KBYTES_FREE,
1107                 .fhandler       = oid_table_c64_kb_handler
1108         },
1109         {
1110                 .magic          = MDCOBJECTS,
1111                 .name           = FILENAME_FILES_TOTAL,
1112                 .fhandler       = oid_table_c64_kb_handler
1113         },
1114         {
1115                 .magic          = MDCFREEOBJECTS,
1116                 .name           = FILENAME_FILES_FREE,
1117                 .fhandler       = oid_table_c64_kb_handler
1118         },
1119         {
1120                 .magic          = 0,
1121                 .name           = NULL,
1122                 .fhandler       = NULL
1123         } /*End of table*/
1124 };
1125
1126
1127 /*****************************************************************************
1128  * Function: var_mdcTable
1129  *
1130  ****************************************************************************/
1131 unsigned char *
1132 var_mdcTable(struct variable *vp,
1133             oid     *name,
1134             size_t  *length,
1135             int     exact,
1136             size_t  *var_len,
1137             WriteMethod **write_method)
1138 {
1139     unsigned char *table;
1140     glob_t path;
1141
1142     if (cfs_get_param_paths(&path, "mdc") != 0)
1143         return NULL;
1144
1145     table = var_genericTable(vp,name,length,exact,var_len,write_method,
1146                              path.gl_pathv[0],osd_table);
1147     cfs_free_param_data(&path);
1148     return table;
1149 }
1150
1151 struct oid_table cli_table[] = {
1152         {
1153                 .magic          = CLIUUID,
1154                 .name           = FILENAME_UUID,
1155                 .fhandler       = oid_table_string_handler
1156         },
1157         {
1158                 .magic          = CLICOMMONNAME,
1159                 .name           = NULL,
1160                 .fhandler       = oid_table_obj_name_handler
1161         },
1162         {
1163                 .magic          = CLIMDCUUID,
1164                 .name           = "mdc/" FILENAME_UUID,
1165                 .fhandler       = oid_table_string_handler
1166         },
1167         {
1168                 .magic          = CLIMDCCOMMONNAME,
1169                 .name           = "mdc/" FILENAME_COMMON_NAME,
1170                 .fhandler       = oid_table_string_handler
1171         },
1172         {
1173                 .magic          = CLIUSESLOV,
1174                 .name           = "lov/",
1175                 .fhandler       = oid_table_is_directory_handler
1176         },
1177         {
1178                 .magic          = CLILOVUUID,
1179                 .name           = "lov/" FILENAME_UUID,
1180                 .fhandler       = oid_table_string_handler
1181         },
1182         {
1183                 .magic          = CLILOVCOMMONNAME,
1184                 .name           = "lov/" FILENAME_COMMON_NAME,
1185                 .fhandler       = oid_table_string_handler
1186         },
1187         {
1188                 .magic          = 0,
1189                 .name           = NULL,
1190                 .fhandler       = NULL
1191         } /*End of table*/
1192 };
1193
1194 /*****************************************************************************
1195  * Function: var_cliTable
1196  *
1197  ****************************************************************************/
1198 unsigned char *
1199 var_cliTable(struct variable *vp,
1200             oid     *name,
1201             size_t  *length,
1202             int     exact,
1203             size_t  *var_len,
1204             WriteMethod **write_method)
1205 {
1206     unsigned char *table;
1207     glob_t path;
1208
1209     if (cfs_get_param_paths(&path, "llite") != 0)
1210         return NULL;
1211
1212     table = var_genericTable(vp,name,length,exact,var_len,write_method,
1213                              path.gl_pathv[0],osd_table);
1214     cfs_free_param_data(&path);
1215     return table;
1216 }
1217
1218 struct oid_table lov_table[] = {
1219         {
1220                 .magic          = LOVUUID,
1221                 .name           = FILENAME_UUID,
1222                 .fhandler       = oid_table_string_handler
1223         },
1224         {
1225                 .magic          = LOVCOMMONNAME,
1226                 .name           = NULL,
1227                 .fhandler       = oid_table_obj_name_handler
1228         },
1229         {
1230                 .magic          = LOVNUMOBD,
1231                 .name           = "numobd",
1232                 .fhandler       = oid_table_ulong_handler
1233         },
1234         {
1235                 .magic          = LOVNUMACTIVEOBD,
1236                 .name           = "activeobd",
1237                 .fhandler       = oid_table_ulong_handler
1238         },
1239         {
1240                 .magic          = LOVCAPACITY,
1241                 .name           = FILENAME_KBYTES_TOTAL,
1242                 .fhandler       = oid_table_c64_kb_handler
1243         },
1244         {
1245                 .magic          = LOVFREECAPACITY,
1246                 .name           = FILENAME_KBYTES_FREE,
1247                 .fhandler       = oid_table_c64_kb_handler
1248         },
1249         {
1250                 .magic          = LOVFILES,
1251                 .name           = FILENAME_FILES_TOTAL,
1252                 .fhandler       = oid_table_c64_kb_handler
1253         },
1254         {
1255                 .magic          = LOVFREEFILES,
1256                 .name           = FILENAME_FILES_FREE,
1257                 .fhandler       = oid_table_c64_kb_handler
1258         },
1259         {
1260                 .magic          = LOVSTRIPECOUNT,
1261                 .name           = "stripecount",
1262                 .fhandler       = oid_table_ulong_handler
1263         },
1264         {
1265                 .magic          = LOVSTRIPEOFFSET,
1266                 .name           = "stripeoffset",
1267                 .fhandler       = oid_table_ulong_handler
1268         },
1269         {
1270                 .magic          = LOVSTRIPESIZE,
1271                 .name           = "stripesize",
1272                 .fhandler       = oid_table_ulong_handler
1273         },
1274         {
1275                 .magic          = LOVSTRIPETYPE,
1276                 .name           = "stripetype",
1277                 .fhandler       = oid_table_ulong_handler
1278         },
1279         {
1280                 .magic          = 0,
1281                 .name           = NULL,
1282                 .fhandler       = NULL
1283         } /*End of table*/
1284 };
1285
1286
1287 /*****************************************************************************
1288  * Function: var_lovTable
1289  *
1290  ****************************************************************************/
1291 unsigned char *
1292 var_lovTable(struct variable *vp,
1293             oid     *name,
1294             size_t  *length,
1295             int     exact,
1296             size_t  *var_len,
1297             WriteMethod **write_method)
1298 {
1299     unsigned char *table;
1300     glob_t path;
1301
1302     if (cfs_get_param_paths(&path, "lov") != 0)
1303         return NULL;
1304
1305     table = var_genericTable(vp,name,length,exact,var_len,write_method,
1306                              path.gl_pathv[0],osd_table);
1307     cfs_free_param_data(&path);
1308     return table;
1309 }
1310
1311 struct oid_table ldlm_table[] = {
1312         {
1313                 .magic          = LDLMNAMESPACE,
1314                 .name           = NULL,
1315                 .fhandler       = oid_table_obj_name_handler
1316         },
1317         {
1318                 .magic          = LDLMLOCKCOUNT,
1319                 .name           = "lock_count",
1320                 .fhandler       = oid_table_ulong_handler
1321         },
1322         {
1323                 .magic          = LDLMUNUSEDLOCKCOUNT,
1324                 .name           = "lock_unused_count",
1325                 .fhandler       = oid_table_ulong_handler
1326         },
1327         {
1328                 .magic          = LDLMRESOURCECOUNT,
1329                 .name           = "resource_count",
1330                 .fhandler       = oid_table_ulong_handler
1331         },
1332         {
1333                 .magic          = 0,
1334                 .name           = NULL,
1335                 .fhandler       = NULL
1336         } /*End of table*/
1337 };
1338
1339
1340 /*****************************************************************************
1341  * Function: var_ldlmTable
1342  *
1343  ****************************************************************************/
1344 unsigned char *
1345 var_ldlmTable(struct variable *vp,
1346             oid     *name,
1347             size_t  *length,
1348             int     exact,
1349             size_t  *var_len,
1350             WriteMethod **write_method)
1351 {
1352     unsigned char *table;
1353     glob_t path;
1354
1355     if (cfs_get_param_paths(&path, "ldlm/namespaces") != 0)
1356         return NULL;
1357
1358     table = var_genericTable(vp,name,length,exact,var_len,write_method,
1359                              path.gl_pathv[0],osd_table);
1360     cfs_free_param_data(&path);
1361     return table;
1362 }
1363
1364 /*****************************************************************************
1365  * Function: var_lnetInformation
1366  *
1367  ****************************************************************************/
1368 unsigned char *
1369 var_lnetInformation(struct variable *vp,
1370                     oid             *name,
1371                     size_t          *length,
1372                     int              exact,
1373                     size_t          *var_len,
1374                     WriteMethod    **write_method)
1375 {
1376         /* variables we may use later */
1377         static unsigned char      string[SPRINT_MAX_LEN];
1378         static unsigned int       i[7];
1379         static unsigned long long ull[4];
1380         static unsigned long      next_update;
1381         static counter64          c64;
1382         static unsigned int       c32;
1383         struct timeval            current_tv;
1384         unsigned long             current;
1385         glob_t                    file_path;
1386
1387         /* Update at most every LNET_STATS_INTERVAL milliseconds */
1388         gettimeofday(&current_tv, NULL);
1389         current = current_tv.tv_sec * 1000000 + current_tv.tv_usec;
1390         if (current >= next_update) {
1391                 if (cfs_get_param_paths(&file_path, "stats") != 0)
1392                         return NULL;
1393                 if (read_string(file_path.gl_pathv[0], (char *) string, sizeof(string))
1394                     != SUCCESS) {
1395                         cfs_free_param_data(&file_path);
1396                         return NULL;
1397                 }
1398                 cfs_free_param_data(&file_path);
1399
1400                 sscanf((char *) string,
1401                        "%u %u %u %u %u %u %u %llu %llu %llu %llu",
1402                        &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6],
1403                        &ull[0], &ull[1], &ull[2], &ull[3]);
1404
1405                 next_update = current + (LNET_CHECK_INTERVAL * 1000);
1406         }
1407
1408         if (header_generic(vp, name, length, exact, var_len, write_method)
1409             == MATCH_FAILED)
1410                 return NULL;
1411
1412         switch (vp->magic) {
1413         case LNETMSGSALLOC:
1414                 *var_len = sizeof(c32);
1415                 c32 = i[0];
1416                 return (unsigned char *) &c32;
1417         case LNETMSGSMAX:
1418                 *var_len = sizeof(c32);
1419                 c32 = i[1];
1420                 return (unsigned char *) &c32;
1421         case LNETERRORS:
1422                 *var_len = sizeof(c32);
1423                 c32 = i[2];
1424                 return (unsigned char *) &c32;
1425         case LNETSENDCOUNT:
1426                 *var_len = sizeof(c32);
1427                 c32 = i[3];
1428                 return (unsigned char *) &c32;
1429         case LNETRECVCOUNT:
1430                 *var_len = sizeof(c32);
1431                 c32 = i[4];
1432                 return (unsigned char *) &c32;
1433         case LNETROUTECOUNT:
1434                 *var_len = sizeof(c32);
1435                 c32 = i[5];
1436                 return (unsigned char *) &c32;
1437         case LNETDROPCOUNT:
1438                 *var_len = sizeof(c32);
1439                 c32 = i[6];
1440                 return (unsigned char *) &c32;
1441         case LNETSENDBYTES:
1442                 convert_ull(&c64, ull[0], var_len);
1443                 return (unsigned char *) &c64;
1444         case LNETRECVBYTES:
1445                 convert_ull(&c64, ull[1], var_len);
1446                 return (unsigned char *) &c64;
1447         case LNETROUTEBYTES:
1448                 convert_ull(&c64, ull[2], var_len);
1449                 return (unsigned char *) &c64;
1450         case LNETDROPBYTES:
1451                 convert_ull(&c64, ull[3], var_len);
1452                 return (unsigned char *) &c64;
1453         default:
1454                 return NULL;
1455         }
1456 }
1457
1458 /*****************************************************************************
1459  * Function: var_mdsNbSampledReq
1460  *
1461  ****************************************************************************/
1462 unsigned char *
1463 var_mdsNbSampledReq(struct variable *vp,
1464             oid     *name,
1465             size_t  *length,
1466             int     exact,
1467             size_t  *var_len,
1468             WriteMethod **write_method)
1469 {
1470   unsigned long long nb_sample=0,min=0,max=0,sum=0,sum_square=0;
1471   static counter64 c64;
1472
1473   if (header_generic(vp,name,length,exact,var_len,write_method)
1474                                   == MATCH_FAILED )
1475     return NULL;
1476
1477   if( mds_stats_values(STR_REQ_WAITIME,&nb_sample,&min,&max,&sum,&sum_square) == ERROR) return NULL;
1478
1479   c64.low = (u_long) (0x0FFFFFFFF & nb_sample);
1480   nb_sample >>= 32;
1481   c64.high = (u_long) (0x0FFFFFFFF & nb_sample);
1482
1483   *var_len = sizeof(c64);
1484   return (unsigned char *) &c64;
1485 }
1486
1487
1488 /*****************************************************************************
1489  * Function: write_sysStatus
1490  *
1491  ****************************************************************************/
1492 int
1493 write_sysStatus(int      action,
1494             u_char   *var_val,
1495             u_char   var_val_type,
1496             size_t   var_val_len,
1497             u_char   *statP,
1498             oid      *name,
1499             size_t   name_len)
1500 {
1501   static long *long_ret;
1502   int new_value;
1503
1504
1505
1506   switch ( action ) {
1507         case RESERVE1:
1508           if (var_val_type != ASN_INTEGER){
1509               fprintf(stderr, "write to sysStatus not ASN_INTEGER\n");
1510               return SNMP_ERR_WRONGTYPE;
1511           }
1512           if (var_val_len > sizeof(long_ret)){
1513               fprintf(stderr,"write to sysStatus: bad length\n");
1514               return SNMP_ERR_WRONGLENGTH;
1515           }
1516           if ((*var_val != ONLINE) &&
1517               (*var_val !=  OFFLINE) &&
1518               (*var_val !=  RESTART)){
1519               report("%s %s:line %d %s", __FILE__, __FUNCTION__, __LINE__,
1520                      "sysStatus value is invalid.");
1521               return SNMP_ERR_WRONGVALUE;
1522           }
1523           break;
1524
1525
1526         case RESERVE2:
1527           long_ret = (long *) var_val;
1528
1529
1530           break;
1531
1532
1533         case FREE:
1534              /* Release any resources that have been allocated */
1535           break;
1536
1537
1538         case ACTION:
1539              /* The variable has been stored in long_ret for
1540              you to use, and you have just been asked to do something with
1541              it.  Note that anything done here must be reversable in the UNDO case */
1542           new_value = *(int *) var_val;
1543           switch (new_value) {
1544             case ONLINE:
1545                 lustrefs_ctrl(ONLINE);
1546                 break;
1547
1548             case OFFLINE:
1549                 lustrefs_ctrl(OFFLINE);
1550                 break;
1551
1552             case RESTART:
1553                 lustrefs_ctrl(RESTART);
1554                 break;
1555
1556             default:
1557                 break;
1558           }
1559           break;
1560
1561
1562         case UNDO:
1563              /* Back out any changes made in the ACTION case */
1564           break;
1565
1566
1567         case COMMIT:
1568              /* Things are working well, so it's now safe to make the change
1569              permanently.  Make sure that anything done here can't fail! */
1570           break;
1571   }
1572   return SNMP_ERR_NOERROR;
1573 }