Whamcloud - gitweb
LU-5092 nodemap: save id maps to targets in new index file
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * snmp/lustre-snmp.c
37  *
38  * Author: PJ Kirner <pjkirner@clusterfs.com>
39  */
40  
41 #include <net-snmp/net-snmp-config.h>
42 #include <net-snmp/net-snmp-includes.h>
43 #include <net-snmp/agent/net-snmp-agent-includes.h>
44 #include <net-snmp/utilities.h>
45 #include <pthread.h>
46 #include "lustre-snmp.h"
47
48 #include <libcfs/util/param.h>
49
50 #define LNET_CHECK_INTERVAL 500
51
52 /* 
53  * clusterFileSystems_variables_oid:
54  *   this is the top level oid that we want to register under.  This
55  *   is essentially a prefix, with the suffix appearing in the
56  *   variable below.
57  */
58
59
60 oid clusterFileSystems_variables_oid[] = { 1,3,6,1,4,1,13140 };
61
62
63 /* 
64  * variable7 clusterFileSystems_variables:
65  *   this variable defines function callbacks and type return information 
66  *   for the clusterFileSystems mib section 
67  */
68
69
70 struct variable7 clusterFileSystems_variables[] = {
71 /*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
72
73   /* sytemInformation 2.1.1. */
74   { SYSVERSION          , ASN_OCTET_STR , RONLY , var_clusterFileSystems, 4, { 2,1,1,1 } },
75   { SYSKERNELVERSION    , ASN_OCTET_STR , RONLY , var_clusterFileSystems, 4, { 2,1,1,2 } },
76   { SYSHEALTHCHECK      , ASN_OCTET_STR , RONLY , var_clusterFileSystems, 4, { 2,1,1,3 } },
77   { SYSSTATUS           , ASN_INTEGER   , RWRITE, var_clusterFileSystems, 4, { 2,1,1,4 } },
78
79   /* objectStorageTargets 2.1.2 */
80   { OSDNUMBER           , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,2,1 } },
81
82   /* objectStorageTargets.osdTable.osdEntry 2.1.2.2.1 */
83   { OSDUUID             , ASN_OCTET_STR , RONLY , var_osdTable, 6, { 2,1,2,2,1,2 } },
84   { OSDCOMMONNAME       , ASN_OCTET_STR , RONLY , var_osdTable, 6, { 2,1,2,2,1,3 } },
85   { OSDCAPACITY         , ASN_COUNTER64 , RONLY , var_osdTable, 6, { 2,1,2,2,1,4 } },
86   { OSDFREECAPACITY     , ASN_COUNTER64 , RONLY , var_osdTable, 6, { 2,1,2,2,1,5 } },
87   { OSDOBJECTS          , ASN_COUNTER64 , RONLY , var_osdTable, 6, { 2,1,2,2,1,6 } },
88   { OSDFREEOBJECTS      , ASN_COUNTER64 , RONLY , var_osdTable, 6, { 2,1,2,2,1,7 } },
89
90   /* objectStorageClients 2.1.3 */
91   { OSCNUMBER           , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,3,1 } },
92
93   /* objectStorageClients.oscTable.oscEntry 2.1.3.2.1 */
94   { OSCUUID             , ASN_OCTET_STR , RONLY , var_oscTable, 6, { 2,1,3,2,1,2 } },
95   { OSCCOMMONNAME       , ASN_OCTET_STR , RONLY , var_oscTable, 6, { 2,1,3,2,1,3 } },
96   { OSCOSTSERVERUUID    , ASN_OCTET_STR , RONLY , var_oscTable, 6, { 2,1,3,2,1,4 } },
97   { OSCCAPACITY         , ASN_COUNTER64 , RONLY , var_oscTable, 6, { 2,1,3,2,1,5 } },
98   { OSCFREECAPACITY     , ASN_COUNTER64 , RONLY , var_oscTable, 6, { 2,1,3,2,1,6 } },
99   { OSCOBJECTS          , ASN_COUNTER64 , RONLY , var_oscTable, 6, { 2,1,3,2,1,7 } },
100   { OSCFREEOBJECTS      , ASN_COUNTER64 , RONLY , var_oscTable, 6, { 2,1,3,2,1,8 } },
101
102
103   /* metaDataServers 2.1.4 */
104   { MDDNUMBER           , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,4,1 } },
105
106   /* metaDataServers.mddTable.mddEntry 2.1.4.2.1 */
107   { MDDUUID             , ASN_OCTET_STR , RONLY , var_mdsTable, 6, { 2,1,4,2,1,2 } },
108   { MDDCOMMONNAME       , ASN_OCTET_STR , RONLY , var_mdsTable, 6, { 2,1,4,2,1,3 } },
109   { MDDCAPACITY         , ASN_COUNTER64 , RONLY , var_mdsTable, 6, { 2,1,4,2,1,4 } },
110   { MDDFREECAPACITY     , ASN_COUNTER64 , RONLY , var_mdsTable, 6, { 2,1,4,2,1,5 } },
111   { MDDFILES            , ASN_COUNTER64 , RONLY , var_mdsTable, 6, { 2,1,4,2,1,6 } },
112   { MDDFREEFILES        , ASN_COUNTER64 , RONLY , var_mdsTable, 6, { 2,1,4,2,1,7 } },
113   { MDSNBSAMPLEDREQ     , ASN_COUNTER64 , RONLY , var_mdsNbSampledReq, 4, { 2,1,4,3 } },
114
115   /* metaDataClients 2.1.5 */
116   { MDCNUMBER           , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,5,1 } },
117
118   /* metaDataClients.mdcTable.mdcEntry 2.1.5.2.1 */
119   { MDCUUID             , ASN_OCTET_STR , RONLY , var_mdcTable, 6, { 2,1,5,2,1,2 } },
120   { MDCCOMMONNAME       , ASN_OCTET_STR , RONLY , var_mdcTable, 6, { 2,1,5,2,1,3 } },
121   { MDCMDSSERVERUUID    , ASN_OCTET_STR , RONLY , var_mdcTable, 6, { 2,1,5,2,1,4 } },
122   { MDCCAPACITY         , ASN_COUNTER64 , RONLY , var_mdcTable, 6, { 2,1,5,2,1,5 } },
123   { MDCFREECAPACITY     , ASN_COUNTER64 , RONLY , var_mdcTable, 6, { 2,1,5,2,1,6 } },
124   { MDCOBJECTS          , ASN_COUNTER64 , RONLY , var_mdcTable, 6, { 2,1,5,2,1,7 } },
125   { MDCFREEOBJECTS      , ASN_COUNTER64 , RONLY , var_mdcTable, 6, { 2,1,5,2,1,8 } },
126
127   /* lustreClients 2.1.6 */
128   { CLIMOUNTNUMBER           , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,6,1 } },
129
130   /* lustreClients.cliMountTable.cliMountEntry 2.1.6.2.1 */
131   { CLIUUID             , ASN_OCTET_STR , RONLY , var_cliTable, 6, { 2,1,6,2,1,2 } },
132   { CLICOMMONNAME       , ASN_OCTET_STR , RONLY , var_cliTable, 6, { 2,1,6,2,1,3 } },
133   { CLIMDCUUID          , ASN_OCTET_STR , RONLY , var_cliTable, 6, { 2,1,6,2,1,4 } },
134   { CLIMDCCOMMONNAME    , ASN_OCTET_STR , RONLY , var_cliTable, 6, { 2,1,6,2,1,5 } },
135   { CLIUSESLOV          , ASN_INTEGER ,   RONLY , var_cliTable, 6, { 2,1,6,2,1,6 } },
136   { CLILOVUUID          , ASN_OCTET_STR , RONLY , var_cliTable, 6, { 2,1,6,2,1,7 } },
137   { CLILOVCOMMONNAME    , ASN_OCTET_STR , RONLY , var_cliTable, 6, { 2,1,6,2,1,8 } },
138
139   /* logicalObjectVolume 2.1.7 */
140   { LOVNUMBER           , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,7,1 } },
141
142   /* logicalObjectVolume.osdTable.lovTable 2.1.7.2.1 */
143   { LOVUUID             , ASN_OCTET_STR , RONLY , var_lovTable, 6, { 2,1,7,2,1,2 } },
144   { LOVCOMMONNAME       , ASN_OCTET_STR , RONLY , var_lovTable, 6, { 2,1,7,2,1,3 } },
145   { LOVNUMOBD           , ASN_UNSIGNED ,  RONLY , var_lovTable, 6, { 2,1,7,2,1,4 } },
146   { LOVNUMACTIVEOBD     , ASN_UNSIGNED ,  RONLY , var_lovTable, 6, { 2,1,7,2,1,5 } },
147   { LOVCAPACITY         , ASN_COUNTER64 , RONLY , var_lovTable, 6, { 2,1,7,2,1,6 } },
148   { LOVFREECAPACITY     , ASN_COUNTER64 , RONLY , var_lovTable, 6, { 2,1,7,2,1,7 } },
149   { LOVFILES            , ASN_COUNTER64 , RONLY , var_lovTable, 6, { 2,1,7,2,1,8 } },
150   { LOVFREEFILES        , ASN_COUNTER64 , RONLY , var_lovTable, 6, { 2,1,7,2,1,9 } },
151   { LOVSTRIPECOUNT      , ASN_UNSIGNED ,  RONLY , var_lovTable, 6, { 2,1,7,2,1,10} },
152   { LOVSTRIPEOFFSET     , ASN_UNSIGNED ,  RONLY , var_lovTable, 6, { 2,1,7,2,1,11} },
153   { LOVSTRIPESIZE       , ASN_UNSIGNED ,  RONLY , var_lovTable, 6, { 2,1,7,2,1,12} },
154   { LOVSTRIPETYPE       , ASN_UNSIGNED ,  RONLY , var_lovTable, 6, { 2,1,7,2,1,13} },
155
156   /* lustreLDLM 2.1.8 */
157   { LDLMNUMBER          , ASN_UNSIGNED  , RONLY , var_clusterFileSystems, 4, { 2,1,8,1 } },
158
159   /* lustreLDLM.ldlmTable.ldlmEntry 2.1.8.2.1 */
160   { LDLMNAMESPACE       , ASN_OCTET_STR , RONLY , var_ldlmTable, 6, { 2,1,8,2,1,2 } },
161   { LDLMLOCKCOUNT       , ASN_UNSIGNED  , RONLY , var_ldlmTable, 6, { 2,1,8,2,1,3 } },
162   { LDLMUNUSEDLOCKCOUNT , ASN_UNSIGNED  , RONLY , var_ldlmTable, 6, { 2,1,8,2,1,4 } },
163   { LDLMRESOURCECOUNT   , ASN_UNSIGNED  , RONLY , var_ldlmTable, 6, { 2,1,8,2,1,5 } },
164
165   /* lnetInformation 2.1.9 */
166   { LNETMSGSALLOC,  ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,1 } },
167   { LNETMSGSMAX,    ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,2 } },
168   { LNETERRORS,     ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,3 } },
169   { LNETSENDCOUNT,  ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,4 } },
170   { LNETRECVCOUNT,  ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,5 } },
171   { LNETROUTECOUNT, ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,6 } },
172   { LNETDROPCOUNT,  ASN_UNSIGNED,  RONLY, var_lnetInformation, 4, { 2,1,9,7 } },
173   { LNETSENDBYTES,  ASN_COUNTER64, RONLY, var_lnetInformation, 4, { 2,1,9,8 } },
174   { LNETRECVBYTES,  ASN_COUNTER64, RONLY, var_lnetInformation, 4, { 2,1,9,9 } },
175   { LNETROUTEBYTES, ASN_COUNTER64, RONLY, var_lnetInformation, 4, { 2,1,9,10 } },
176   { LNETDROPBYTES,  ASN_COUNTER64, RONLY, var_lnetInformation, 4, { 2,1,9,11 } },
177 };
178
179 /*****************************************************************************
180  * Function: init_cfsNetSNMPPlugin
181  *
182  * Description: Called when the agent starts up
183  *
184  * Input:   void
185  *
186  * Output:  None
187  *
188  ****************************************************************************/
189  
190 void init_lustresnmp(void) {
191
192         /* register ourselves with the agent to handle our mib tree */
193         REGISTER_MIB("clusterFileSystems",
194                      clusterFileSystems_variables, variable7,
195                      clusterFileSystems_variables_oid);
196
197         initialize_trap_handler();
198
199         DEBUGMSGTL(("lsnmpd", "%s %s\n", __func__, "Initialization Done"));
200 }
201
202 /*****************************************************************************
203  * Function: deinit_cfsNetSNMPPlugin
204  *
205  * Description: Called when the agent terminates up
206  *
207  * Input:   void
208  *
209  * Output:  None
210  *
211  ****************************************************************************/
212
213 void deinit_lustresnmp(void) {
214
215         /* deregister ourselves with the agent */
216         unregister_mib(clusterFileSystems_variables_oid,
217                        sizeof(clusterFileSystems_variables_oid)/
218                        sizeof(clusterFileSystems_variables_oid));
219
220         terminate_trap_handler();
221
222         DEBUGMSGTL(("lsnmpd", "%s %s\n", __func__, "Termination Done"));
223 }
224
225 /*****************************************************************************
226  * Function: var_clusterFileSystems
227  *
228  ****************************************************************************/
229 unsigned char *
230 var_clusterFileSystems(struct variable *vp, 
231                 oid     *name, 
232                 size_t  *length, 
233                 int     exact, 
234                 size_t  *var_len, 
235                 WriteMethod **write_method)
236 {
237
238
239   /* variables we may use later */
240   static long long_ret;
241   static u_long ulong_ret;
242   static unsigned char string[SPRINT_MAX_LEN];
243   glob_t path;
244   uint32_t num;
245   char *dir_list;
246
247   if (header_generic(vp,name,length,exact,var_len,write_method)
248                                   == MATCH_FAILED )
249     return NULL;
250
251
252   /* 
253    * this is where we do the value assignments for the mib results.
254    */
255   switch(vp->magic) {
256
257     case SYSVERSION:
258         if (cfs_get_param_paths(&path, "version") != 0)
259             return NULL;
260         if( SUCCESS != read_string(path.gl_pathv[0], (char *)string,sizeof(string))){
261             cfs_free_param_data(&path);
262             return NULL;
263         }
264         cfs_free_param_data(&path);
265         *var_len = strlen((char *)string);
266         return (unsigned char *) string;
267
268     case SYSKERNELVERSION:
269         if (cfs_get_param_paths(&path, "kernel_version") != 0)
270             return NULL;
271         if( SUCCESS != read_string(path.gl_pathv[0], (char *)string,sizeof(string))){
272             cfs_free_param_data(&path);
273             return NULL;
274         }
275         cfs_free_param_data(&path);
276         *var_len = strlen((char *)string);
277         return (unsigned char *) string;
278
279     case SYSHEALTHCHECK:
280         if (cfs_get_param_paths(&path, "health_check") != 0)
281             return NULL;
282         if( SUCCESS != read_string(path.gl_pathv[0], (char *)string,sizeof(string))){
283             cfs_free_param_data(&path);
284             return NULL;
285         }
286         cfs_free_param_data(&path);
287         *var_len = strlen((char*)string);
288         return (unsigned char *) string;
289
290     case SYSSTATUS:
291         *write_method = write_sysStatus;
292         long_ret = (long) get_sysstatus();
293         if (long_ret != ERROR)
294           return (unsigned char *) &long_ret;
295         return NULL;
296                       
297     case OSDNUMBER:
298         if (cfs_get_param_paths(&path, "obdfilter") != 0)
299             return NULL;
300         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
301             cfs_free_param_data(&path);
302             return NULL;
303         }
304         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
305         cfs_free_param_data(&path);
306         ulong_ret =  num;
307         free(dir_list);
308         return (unsigned char *) &ulong_ret;
309
310     case OSCNUMBER:
311         if (cfs_get_param_paths(&path, "osc") != 0)
312             return NULL;
313         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
314             cfs_free_param_data(&path);
315             return NULL;
316         }
317         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
318         cfs_free_param_data(&path);
319         ulong_ret =  num;
320         free(dir_list);
321         return (unsigned char *) &ulong_ret;
322
323     case MDDNUMBER:
324         if (cfs_get_param_paths(&path, "mds") != 0)
325             return NULL;
326         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
327             cfs_free_param_data(&path);
328             return NULL;
329         }
330         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
331         cfs_free_param_data(&path);
332         ulong_ret =  num;
333         free(dir_list);
334         return (unsigned char *) &ulong_ret;
335
336     case MDCNUMBER:
337         if (cfs_get_param_paths(&path, "mdc") != 0)
338             return NULL;
339         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
340             cfs_free_param_data(&path);
341             return NULL;
342         }
343         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
344         cfs_free_param_data(&path);
345         ulong_ret =  num;
346         free(dir_list);
347         return (unsigned char *) &ulong_ret;
348
349     case CLIMOUNTNUMBER:
350         if (cfs_get_param_paths(&path, "llite") != 0)
351             return NULL;
352         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
353             cfs_free_param_data(&path);
354             return NULL;
355         }
356         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
357         cfs_free_param_data(&path);
358         ulong_ret =  num;
359         free(dir_list);
360         return (unsigned char *) &ulong_ret;
361
362     case LOVNUMBER:
363         if (cfs_get_param_paths(&path, "lov") != 0)
364             return NULL;
365         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
366             cfs_free_param_data(&path);
367             return NULL;
368         }
369         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
370         cfs_free_param_data(&path);
371         ulong_ret =  num;
372         free(dir_list);
373         return (unsigned char *) &ulong_ret;
374
375     case LDLMNUMBER:
376         if (cfs_get_param_paths(&path, "ldlm/namespaces") != 0)
377             return NULL;
378         if( 0 == (dir_list = get_file_list(path.gl_pathv[0], DIR_TYPE, &num))){
379             cfs_free_param_data(&path);
380             return NULL;
381         }
382         DEBUGMSGTL(("lsnmpd","num(%s)=%d\n",path.gl_pathv[0],num));
383         cfs_free_param_data(&path);
384         ulong_ret =  num;
385         free(dir_list);
386         return (unsigned char *) &ulong_ret;
387
388     default:
389       ERROR_MSG("");
390   }
391   return NULL;
392 }
393
394 struct oid_table osd_table[] =
395
396     { OSDUUID,FILENAME_UUID,oid_table_string_handler},
397     { OSDCOMMONNAME,0,oid_table_obj_name_handler},
398     { OSDCAPACITY,FILENAME_KBYTES_TOTAL, oid_table_c64_kb_handler},
399     { OSDFREECAPACITY,FILENAME_KBYTES_FREE, oid_table_c64_kb_handler},
400     { OSDOBJECTS,FILENAME_FILES_TOTAL, oid_table_c64_kb_handler},
401     { OSDFREEOBJECTS,FILENAME_FILES_FREE, oid_table_c64_kb_handler},
402     { 0,0,0 } /*End of table*/
403 };
404
405
406 /*****************************************************************************
407  * Function: var_osdTable
408  *
409  ****************************************************************************/
410 unsigned char *
411 var_osdTable(struct variable *vp,
412             oid     *name,
413             size_t  *length,
414             int     exact,
415             size_t  *var_len,
416             WriteMethod **write_method)
417 {
418     unsigned char *table;
419     glob_t path;
420
421     if (cfs_get_param_paths(&path, "obdfilter") != 0)
422         return NULL;
423
424     table = var_genericTable(vp,name,length,exact,var_len,write_method,
425                              path.gl_pathv[0],osd_table);
426     cfs_free_param_data(&path);
427     return table;
428 }
429
430 struct oid_table osc_table[] =
431
432     { OSCUUID,FILENAME_UUID,oid_table_string_handler},
433     { OSCCOMMONNAME,0,oid_table_obj_name_handler},
434     { OSCOSTSERVERUUID,"ost_server_uuid",oid_table_string_handler},
435     { OSCCAPACITY,FILENAME_KBYTES_TOTAL, oid_table_c64_kb_handler},
436     { OSCFREECAPACITY,FILENAME_KBYTES_FREE, oid_table_c64_kb_handler},
437     { OSCOBJECTS,FILENAME_FILES_TOTAL, oid_table_c64_kb_handler},
438     { OSCFREEOBJECTS,FILENAME_FILES_FREE, oid_table_c64_kb_handler},
439     { 0,0,0 } /*End of table*/
440 };
441
442 /*****************************************************************************
443  * Function: var_oscTable
444  *
445  ****************************************************************************/
446 unsigned char *
447 var_oscTable(struct variable *vp,
448             oid     *name,
449             size_t  *length,
450             int     exact,
451             size_t  *var_len,
452             WriteMethod **write_method)
453 {
454     unsigned char *table;
455     glob_t path;
456
457     if (cfs_get_param_paths(&path, "osc") != 0)
458         return NULL;
459
460     table = var_genericTable(vp,name,length,exact,var_len,write_method,
461                              path.gl_pathv[0],osd_table);
462     cfs_free_param_data(&path);
463     return table;
464 }
465
466 struct oid_table mds_table[] =
467
468     { MDDUUID,FILENAME_UUID,oid_table_string_handler},
469     { MDDCOMMONNAME,0,oid_table_obj_name_handler},
470     { MDDCAPACITY,FILENAME_KBYTES_TOTAL, oid_table_c64_kb_handler},
471     { MDDFREECAPACITY,FILENAME_KBYTES_FREE, oid_table_c64_kb_handler},
472     { MDDFILES,FILENAME_FILES_TOTAL, oid_table_c64_kb_handler},
473     { MDDFREEFILES,FILENAME_FILES_FREE, oid_table_c64_kb_handler},
474     { 0,0,0 } /*End of table*/
475 };
476
477 /*****************************************************************************
478  * Function: var_mdsTable
479  *
480  ****************************************************************************/
481 unsigned char *
482 var_mdsTable(struct variable *vp,
483             oid     *name,
484             size_t  *length,
485             int     exact,
486             size_t  *var_len,
487             WriteMethod **write_method)
488 {
489     unsigned char *table;
490     glob_t path;
491
492     if (cfs_get_param_paths(&path, "mds") != 0)
493         return NULL;
494
495     table = var_genericTable(vp,name,length,exact,var_len,write_method,
496                              path.gl_pathv[0],osd_table);
497     cfs_free_param_data(&path);
498     return table;
499 }
500
501 struct oid_table mdc_table[] =
502
503     { MDCUUID,FILENAME_UUID,oid_table_string_handler},
504     { MDCCOMMONNAME,0,oid_table_obj_name_handler},
505     { MDCMDSSERVERUUID,"mds_server_uuid",oid_table_string_handler},
506     { MDCCAPACITY,FILENAME_KBYTES_TOTAL, oid_table_c64_kb_handler},
507     { MDCFREECAPACITY,FILENAME_KBYTES_FREE, oid_table_c64_kb_handler},
508     { MDCOBJECTS,FILENAME_FILES_TOTAL, oid_table_c64_kb_handler},
509     { MDCFREEOBJECTS,FILENAME_FILES_FREE, oid_table_c64_kb_handler},
510     { 0,0,0 } /*End of table*/
511 };
512
513
514 /*****************************************************************************
515  * Function: var_mdcTable
516  *
517  ****************************************************************************/
518 unsigned char *
519 var_mdcTable(struct variable *vp,
520             oid     *name,
521             size_t  *length,
522             int     exact,
523             size_t  *var_len,
524             WriteMethod **write_method)
525 {
526     unsigned char *table;
527     glob_t path;
528
529     if (cfs_get_param_paths(&path, "mdc") != 0)
530         return NULL;
531
532     table = var_genericTable(vp,name,length,exact,var_len,write_method,
533                              path.gl_pathv[0],osd_table);
534     cfs_free_param_data(&path);
535     return table;
536 }
537
538 struct oid_table cli_table[] =
539
540     { CLIUUID,FILENAME_UUID,oid_table_string_handler},
541     { CLICOMMONNAME,0,oid_table_obj_name_handler},
542     { CLIMDCUUID,"mdc/" FILENAME_UUID,oid_table_string_handler},
543     { CLIMDCCOMMONNAME,"mdc/" FILENAME_COMMON_NAME,oid_table_string_handler},
544     { CLIUSESLOV,"lov/",oid_table_is_directory_handler},
545     { CLILOVUUID,"lov/" FILENAME_UUID,oid_table_string_handler},
546     { CLILOVCOMMONNAME,"lov/" FILENAME_COMMON_NAME,oid_table_string_handler},
547     { 0,0,0 } /*End of table*/
548 };
549
550 /*****************************************************************************
551  * Function: var_cliTable
552  *
553  ****************************************************************************/
554 unsigned char *
555 var_cliTable(struct variable *vp,
556             oid     *name,
557             size_t  *length,
558             int     exact,
559             size_t  *var_len,
560             WriteMethod **write_method)
561 {
562     unsigned char *table;
563     glob_t path;
564
565     if (cfs_get_param_paths(&path, "llite") != 0)
566         return NULL;
567
568     table = var_genericTable(vp,name,length,exact,var_len,write_method,
569                              path.gl_pathv[0],osd_table);
570     cfs_free_param_data(&path);
571     return table;
572 }
573
574 struct oid_table lov_table[] =
575
576     { LOVUUID,FILENAME_UUID,oid_table_string_handler},
577     { LOVCOMMONNAME,0,oid_table_obj_name_handler},
578     { LOVNUMOBD,"numobd", oid_table_ulong_handler},
579     { LOVNUMACTIVEOBD,"activeobd", oid_table_ulong_handler},
580     { LOVCAPACITY,FILENAME_KBYTES_TOTAL, oid_table_c64_kb_handler},
581     { LOVFREECAPACITY,FILENAME_KBYTES_FREE, oid_table_c64_kb_handler},
582     { LOVFILES,FILENAME_FILES_TOTAL, oid_table_c64_kb_handler},
583     { LOVFREEFILES,FILENAME_FILES_FREE, oid_table_c64_kb_handler},
584     { LOVSTRIPECOUNT,"stripecount", oid_table_ulong_handler},
585     { LOVSTRIPEOFFSET,"stripeoffset", oid_table_ulong_handler},
586     { LOVSTRIPESIZE,"stripesize", oid_table_ulong_handler},
587     { LOVSTRIPETYPE,"stripetype", oid_table_ulong_handler},
588     { 0,0,0 } /*End of table*/
589 };
590
591
592 /*****************************************************************************
593  * Function: var_lovTable
594  *
595  ****************************************************************************/
596 unsigned char *
597 var_lovTable(struct variable *vp,
598             oid     *name,
599             size_t  *length,
600             int     exact,
601             size_t  *var_len,
602             WriteMethod **write_method)
603 {
604     unsigned char *table;
605     glob_t path;
606
607     if (cfs_get_param_paths(&path, "lov") != 0)
608         return NULL;
609
610     table = var_genericTable(vp,name,length,exact,var_len,write_method,
611                              path.gl_pathv[0],osd_table);
612     cfs_free_param_data(&path);
613     return table;
614 }
615
616 struct oid_table ldlm_table[] =
617
618     { LDLMNAMESPACE,0,oid_table_obj_name_handler},
619     { LDLMLOCKCOUNT,"lock_count", oid_table_ulong_handler},
620     { LDLMUNUSEDLOCKCOUNT,"lock_unused_count", oid_table_ulong_handler},
621     { LDLMRESOURCECOUNT,"resource_count", oid_table_ulong_handler},
622     { 0,0,0 } /*End of table*/
623 };
624
625
626 /*****************************************************************************
627  * Function: var_ldlmTable
628  *
629  ****************************************************************************/
630 unsigned char *
631 var_ldlmTable(struct variable *vp,
632             oid     *name,
633             size_t  *length,
634             int     exact,
635             size_t  *var_len,
636             WriteMethod **write_method)
637 {
638     unsigned char *table;
639     glob_t path;
640
641     if (cfs_get_param_paths(&path, "ldlm/namespaces") != 0)
642         return NULL;
643
644     table = var_genericTable(vp,name,length,exact,var_len,write_method,
645                              path.gl_pathv[0],osd_table);
646     cfs_free_param_data(&path);
647     return table;
648 }
649
650 /*****************************************************************************
651  * Function: var_lnetInformation
652  *
653  ****************************************************************************/
654 unsigned char *
655 var_lnetInformation(struct variable *vp,
656                     oid             *name,
657                     size_t          *length,
658                     int              exact,
659                     size_t          *var_len,
660                     WriteMethod    **write_method)
661 {
662         /* variables we may use later */
663         static unsigned char      string[SPRINT_MAX_LEN];
664         static unsigned int       i[7];
665         static unsigned long long ull[4];
666         static unsigned long      next_update;
667         static counter64          c64;
668         static unsigned int       c32;
669         struct timeval            current_tv;
670         unsigned long             current;
671         glob_t                    file_path;
672
673         /* Update at most every LNET_STATS_INTERVAL milliseconds */
674         gettimeofday(&current_tv, NULL);
675         current = current_tv.tv_sec * 1000000 + current_tv.tv_usec;
676         if (current >= next_update) {
677                 if (cfs_get_param_paths(&file_path, "stats") != 0)
678                         return NULL;
679                 if (read_string(file_path.gl_pathv[0], (char *) string, sizeof(string))
680                     != SUCCESS) {
681                         cfs_free_param_data(&file_path);
682                         return NULL;
683                 }
684                 cfs_free_param_data(&file_path);
685
686                 sscanf((char *) string,
687                        "%u %u %u %u %u %u %u %llu %llu %llu %llu",
688                        &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6],
689                        &ull[0], &ull[1], &ull[2], &ull[3]);
690
691                 next_update = current + (LNET_CHECK_INTERVAL * 1000);
692         }
693
694         if (header_generic(vp, name, length, exact, var_len, write_method)
695             == MATCH_FAILED)
696                 return NULL;
697
698         switch (vp->magic) {
699         case LNETMSGSALLOC:
700                 *var_len = sizeof(c32);
701                 c32 = i[0];
702                 return (unsigned char *) &c32;
703         case LNETMSGSMAX:
704                 *var_len = sizeof(c32);
705                 c32 = i[1];
706                 return (unsigned char *) &c32;
707         case LNETERRORS:
708                 *var_len = sizeof(c32);
709                 c32 = i[2];
710                 return (unsigned char *) &c32;
711         case LNETSENDCOUNT:
712                 *var_len = sizeof(c32);
713                 c32 = i[3];
714                 return (unsigned char *) &c32;
715         case LNETRECVCOUNT:
716                 *var_len = sizeof(c32);
717                 c32 = i[4];
718                 return (unsigned char *) &c32;
719         case LNETROUTECOUNT:
720                 *var_len = sizeof(c32);
721                 c32 = i[5];
722                 return (unsigned char *) &c32;
723         case LNETDROPCOUNT:
724                 *var_len = sizeof(c32);
725                 c32 = i[6];
726                 return (unsigned char *) &c32;
727         case LNETSENDBYTES:
728                 convert_ull(&c64, ull[0], var_len);
729                 return (unsigned char *) &c64;
730         case LNETRECVBYTES:
731                 convert_ull(&c64, ull[1], var_len);
732                 return (unsigned char *) &c64;
733         case LNETROUTEBYTES:
734                 convert_ull(&c64, ull[2], var_len);
735                 return (unsigned char *) &c64;
736         case LNETDROPBYTES:
737                 convert_ull(&c64, ull[3], var_len);
738                 return (unsigned char *) &c64;
739         default:
740                 return NULL;
741         }
742 }
743
744 /*****************************************************************************
745  * Function: var_mdsNbSampledReq
746  *
747  ****************************************************************************/
748 unsigned char *
749 var_mdsNbSampledReq(struct variable *vp,
750             oid     *name,
751             size_t  *length,
752             int     exact,
753             size_t  *var_len,
754             WriteMethod **write_method)
755 {
756   unsigned long long nb_sample=0,min=0,max=0,sum=0,sum_square=0;
757   static counter64 c64;
758
759   if (header_generic(vp,name,length,exact,var_len,write_method)
760                                   == MATCH_FAILED )
761     return NULL;
762
763   if( mds_stats_values(STR_REQ_WAITIME,&nb_sample,&min,&max,&sum,&sum_square) == ERROR) return NULL;
764
765   c64.low = (u_long) (0x0FFFFFFFF & nb_sample);
766   nb_sample >>= 32;
767   c64.high = (u_long) (0x0FFFFFFFF & nb_sample);
768
769   *var_len = sizeof(c64);
770   return (unsigned char *) &c64;
771 }
772
773
774 /*****************************************************************************
775  * Function: write_sysStatus
776  *
777  ****************************************************************************/
778 int
779 write_sysStatus(int      action,
780             u_char   *var_val,
781             u_char   var_val_type,
782             size_t   var_val_len,
783             u_char   *statP,
784             oid      *name,
785             size_t   name_len)
786 {
787   static long *long_ret;
788   int new_value;
789
790
791
792   switch ( action ) {
793         case RESERVE1:
794           if (var_val_type != ASN_INTEGER){
795               fprintf(stderr, "write to sysStatus not ASN_INTEGER\n");
796               return SNMP_ERR_WRONGTYPE;
797           }
798           if (var_val_len > sizeof(long_ret)){
799               fprintf(stderr,"write to sysStatus: bad length\n");
800               return SNMP_ERR_WRONGLENGTH;
801           }
802           if ((*var_val != ONLINE) &&
803               (*var_val !=  OFFLINE) &&
804               (*var_val !=  RESTART)){
805               report("%s %s:line %d %s", __FILE__, __FUNCTION__, __LINE__,
806                      "sysStatus value is invalid.");
807               return SNMP_ERR_WRONGVALUE;
808           }
809           break;
810
811
812         case RESERVE2:
813           long_ret = (long *) var_val;
814
815
816           break;
817
818
819         case FREE:
820              /* Release any resources that have been allocated */
821           break;
822
823
824         case ACTION:
825              /* The variable has been stored in long_ret for
826              you to use, and you have just been asked to do something with
827              it.  Note that anything done here must be reversable in the UNDO case */
828           new_value = *(int *) var_val;
829           switch (new_value) {
830             case ONLINE:
831                 lustrefs_ctrl(ONLINE);
832                 break;
833
834             case OFFLINE:
835                 lustrefs_ctrl(OFFLINE);
836                 break;
837
838             case RESTART:
839                 lustrefs_ctrl(RESTART);
840                 break;
841
842             default:
843                 break;
844           }
845           break;
846
847
848         case UNDO:
849              /* Back out any changes made in the ACTION case */
850           break;
851
852
853         case COMMIT:
854              /* Things are working well, so it's now safe to make the change
855              permanently.  Make sure that anything done here can't fail! */
856           break;
857   }
858   return SNMP_ERR_NOERROR;
859 }