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