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