Whamcloud - gitweb
b=21670 revert new version of find_linux_devel_paths
[fs/lustre-release.git] / snmp / lustre-snmp-util.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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-util.h
37  *
38  * Author: PJ Kirner <pjkirner@clusterfs.com>
39  */
40
41 #ifndef LUSTRE_SNMP_UTIL_H
42 #define LUSTRE_SNMP_UTIL_H
43
44 /*
45  * Definitions of magic values
46  */
47
48 #define SYSVERSION          20
49 #define SYSKERNELVERSION    21
50 #define SYSHEALTHCHECK      22
51 #define SYSSTATUS           23
52
53 #define OSDNUMBER           30
54 #define OSDUUID             31
55 #define OSDCOMMONNAME       32
56 #define OSDCAPACITY         33
57 #define OSDFREECAPACITY     34
58 #define OSDOBJECTS          35
59 #define OSDFREEOBJECTS      36
60
61 #define OSCNUMBER           40
62 #define OSCUUID             41
63 #define OSCCOMMONNAME       42
64 #define OSCOSTSERVERUUID    43
65 #define OSCCAPACITY         44
66 #define OSCFREECAPACITY     45
67 #define OSCOBJECTS          46
68 #define OSCFREEOBJECTS      47
69
70 #define MDDNUMBER           50
71 #define MDDUUID             51
72 #define MDDCOMMONNAME       52
73 #define MDDCAPACITY         53
74 #define MDDFREECAPACITY     54
75 #define MDDFILES            55
76 #define MDDFREEFILES        56
77 #define MDSNBSAMPLEDREQ     57
78
79 #define MDCNUMBER           60
80 #define MDCUUID             61
81 #define MDCCOMMONNAME       62
82 #define MDCMDSSERVERUUID    63
83 #define MDCCAPACITY         64
84 #define MDCFREECAPACITY     65
85 #define MDCOBJECTS          66
86 #define MDCFREEOBJECTS      67
87
88 #define CLIMOUNTNUMBER      70
89 #define CLIUUID             71
90 #define CLICOMMONNAME       72
91 #define CLIMDCUUID          73
92 #define CLIMDCCOMMONNAME    74
93 #define CLIUSESLOV          75
94 #define CLILOVUUID          76
95 #define CLILOVCOMMONNAME    77
96
97 #define LOVNUMBER           80
98 #define LOVUUID             81
99 #define LOVCOMMONNAME       82
100 #define LOVNUMOBD           83
101 #define LOVNUMACTIVEOBD     84
102 #define LOVCAPACITY         85
103 #define LOVFREECAPACITY     86
104 #define LOVFILES            87
105 #define LOVFREEFILES        88
106 #define LOVSTRIPECOUNT      89
107 #define LOVSTRIPEOFFSET     90
108 #define LOVSTRIPESIZE       91
109 #define LOVSTRIPETYPE       92
110
111 #define LDLMNUMBER          100
112 #define LDLMNAMESPACE       101
113 #define LDLMLOCKCOUNT       102
114 #define LDLMUNUSEDLOCKCOUNT 103
115 #define LDLMRESOURCECOUNT   104
116
117 /* Defining the proc paths for Lustre file system */
118 #define LUSTRE_PATH                 "/proc/fs/lustre/"
119 #define OSD_PATH                    LUSTRE_PATH "obdfilter/"
120 #define OSC_PATH                    LUSTRE_PATH "osc/"
121 #define MDS_PATH                    LUSTRE_PATH "mds/"
122 #define MDC_PATH                    LUSTRE_PATH "mdc/"
123 #define CLIENT_PATH                 LUSTRE_PATH "llite/"
124 #define LOV_PATH                    LUSTRE_PATH "lov/"
125 #define LDLM_PATH                   LUSTRE_PATH "ldlm/namespaces/"
126 #define FILEPATH_MDS_SERVER_STATS             LUSTRE_PATH "mdt/MDS/mds/stats"
127 #define FILEPATH_MDS_SERVER_READPAGE_STATS             LUSTRE_PATH "mdt/MDS/mds_readpage/stats"
128 #define FILEPATH_MDS_SERVER_SETATTR_STATS             LUSTRE_PATH "mdt/MDS/mds_setattr/stats"
129
130 /* Common procfs file entries that are refrenced in mulitple locations*/
131 #define FILENAME_SYSHEALTHCHECK     "health_check"
132 #define FILENAME_SYS_STATUS         "/var/lustre/sysStatus"
133
134 #define FILENAME_NUM_REF            "num_refs"
135 #define FILENAME_UUID               "uuid"
136 #define FILENAME_COMMON_NAME        "common_name"
137 #define FILENAME_KBYTES_TOTAL       "kbytestotal"
138 #define FILENAME_KBYTES_FREE        "kbytesfree"
139 #define FILENAME_FILES_TOTAL        "filestotal"
140 #define FILENAME_FILES_FREE         "filesfree"
141 #define STR_REQ_WAITIME             "req_waittime"
142
143 /* strings which the file /var/lustre/sysStatus can hold */
144 #define STR_ONLINE                  "online"
145 #define STR_ONLINE_PENDING          "online pending"
146 #define STR_OFFLINE                 "offline"
147 #define STR_OFFLINE_PENDING         "offline pending"
148
149
150 /* Script required for starting/stopping lustre services */
151 #define LUSTRE_SERVICE              "/etc/init.d/lustre"
152
153 #define MIN_LEN(val1,val2)          (((val1)>(val2))?(val2):(val1))
154
155 /* The max size of a lustre procfs path name*/
156 #define MAX_PATH_SIZE               512
157
158 /* The max size of a string read from procfs */
159 #define MAX_LINE_SIZE               512
160
161 /* Types passed to get_file_list() */
162 #define DIR_TYPE                    1
163 #define FILE_TYPE                   0
164
165 /* Defining return values */
166 #define SUCCESS                     0
167 #define ERROR                       -1
168
169 typedef struct counter64 counter64;
170
171 typedef enum {
172     ONLINE = 1,
173     OFFLINE,
174     ONLINE_PENDING,
175     OFFLINE_PENDING,
176     RESTART
177 } lustre_sysstatus;
178
179 /* File operation related functions */
180 char *get_file_list(const char *dirname, int file_type, uint32_t *count);
181 extern int  is_directory(const char *filename);
182 extern int  read_string(const char *filepath, char *lustre_var,size_t var_size);
183 int read_counter64(const char *file_path, counter64 *c64,int factor);
184 int read_ulong(const char *file_path,unsigned long* valuep);
185
186 /* Start/Stop/Restart Lustre Services */
187 extern void lustrefs_ctrl(int command);
188 extern int get_sysstatus();
189
190 extern void report(const char *fmt, ...);
191
192 /* Table Driven SNMP OID Handler support*/
193 typedef unsigned char* (*f_oid_handler_t)(
194     const char* file_path,
195     size_t  *var_len);
196
197 struct oid_table
198 {
199     int magic;                  /*The magic number*/ 
200     const char *name;           /*The procfs name*/
201     f_oid_handler_t fhandler;   /*The handler */
202 };
203
204 unsigned char* oid_table_ulong_handler(const char* file_path,size_t  *var_len);
205 unsigned char* oid_table_c64_handler(const char* file_path,size_t  *var_len);
206 unsigned char* oid_table_c64_kb_handler(const char* file_path,size_t  *var_len);
207 unsigned char* oid_table_obj_name_handler(const char* file_path,size_t  *var_len);
208 unsigned char* oid_table_string_handler(const char* file_path,size_t *var_len);
209 unsigned char* oid_table_is_directory_handler(const char* file_path,size_t *var_len);
210 unsigned char *
211     var_genericTable(struct variable *vp,
212         oid     *name,
213         size_t  *length,
214         int     exact,
215         size_t  *var_len,
216         WriteMethod **write_method,
217         const char *path,
218         struct oid_table *ptable);
219
220 int stats_values(char * filepath,char * name_value, unsigned long long * nb_sample, unsigned long long * min, unsigned long long * max, unsigned long long * sum, unsigned long long * sum_square);
221 extern int mds_stats_values(char * name_value, unsigned long long * nb_sample, unsigned long long * min, unsigned long long * max, unsigned long long * sum, unsigned long long * sum_square);
222
223  /* export for net-snmp util-funcs */
224 int             header_simple_table(struct variable *, oid *, size_t *,
225                                     int, size_t *,
226                                     WriteMethod ** write_method, int);
227 int             header_generic(struct variable *, oid *, size_t *, int,
228                                size_t *, WriteMethod **);
229
230 #endif /* LUSTRE_SNMP_UTIL_H */