Whamcloud - gitweb
LU-10212 test: ESTALE read
[fs/lustre-release.git] / snmp / lustre-snmp-util.h
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 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  * Lustre is a trademark of Sun Microsystems, Inc.
29  *
30  * snmp/lustre-snmp-util.h
31  *
32  * Author: PJ Kirner <pjkirner@clusterfs.com>
33  */
34
35 #ifndef LUSTRE_SNMP_UTIL_H
36 #define LUSTRE_SNMP_UTIL_H
37
38 #include <libcfs/util/param.h>
39
40 /*
41  * Definitions of magic values
42  */
43
44 #define SYSVERSION          20
45 #define SYSKERNELVERSION    21
46 #define SYSHEALTHCHECK      22
47 #define SYSSTATUS           23
48
49 #define OSDNUMBER           30
50 #define OSDUUID             31
51 #define OSDCOMMONNAME       32
52 #define OSDCAPACITY         33
53 #define OSDFREECAPACITY     34
54 #define OSDOBJECTS          35
55 #define OSDFREEOBJECTS      36
56
57 #define OSCNUMBER           40
58 #define OSCUUID             41
59 #define OSCCOMMONNAME       42
60 #define OSCOSTSERVERUUID    43
61 #define OSCCAPACITY         44
62 #define OSCFREECAPACITY     45
63 #define OSCOBJECTS          46
64 #define OSCFREEOBJECTS      47
65
66 #define MDDNUMBER           50
67 #define MDDUUID             51
68 #define MDDCOMMONNAME       52
69 #define MDDCAPACITY         53
70 #define MDDFREECAPACITY     54
71 #define MDDFILES            55
72 #define MDDFREEFILES        56
73 #define MDSNBSAMPLEDREQ     57
74
75 #define MDCNUMBER           60
76 #define MDCUUID             61
77 #define MDCCOMMONNAME       62
78 #define MDCMDSSERVERUUID    63
79 #define MDCCAPACITY         64
80 #define MDCFREECAPACITY     65
81 #define MDCOBJECTS          66
82 #define MDCFREEOBJECTS      67
83
84 #define CLIMOUNTNUMBER      70
85 #define CLIUUID             71
86 #define CLICOMMONNAME       72
87 #define CLIMDCUUID          73
88 #define CLIMDCCOMMONNAME    74
89 #define CLIUSESLOV          75
90 #define CLILOVUUID          76
91 #define CLILOVCOMMONNAME    77
92
93 #define LOVNUMBER           80
94 #define LOVUUID             81
95 #define LOVCOMMONNAME       82
96 #define LOVNUMOBD           83
97 #define LOVNUMACTIVEOBD     84
98 #define LOVCAPACITY         85
99 #define LOVFREECAPACITY     86
100 #define LOVFILES            87
101 #define LOVFREEFILES        88
102 #define LOVSTRIPECOUNT      89
103 #define LOVSTRIPEOFFSET     90
104 #define LOVSTRIPESIZE       91
105 #define LOVSTRIPETYPE       92
106
107 #define LDLMNUMBER          100
108 #define LDLMNAMESPACE       101
109 #define LDLMLOCKCOUNT       102
110 #define LDLMUNUSEDLOCKCOUNT 103
111 #define LDLMRESOURCECOUNT   104
112
113 #define LNETNUMBER          110
114 #define LNETMSGSALLOC       111
115 #define LNETMSGSMAX         112
116 #define LNETERRORS          113
117 #define LNETSENDCOUNT       114
118 #define LNETRECVCOUNT       115
119 #define LNETROUTECOUNT      116
120 #define LNETDROPCOUNT       117
121 #define LNETSENDBYTES       118
122 #define LNETRECVBYTES       119
123 #define LNETROUTEBYTES      120
124 #define LNETDROPBYTES       121
125
126 /* Common procfs file entries that are refrenced in mulitple locations*/
127 #define FILENAME_SYS_STATUS         "/var/lustre/sysStatus"
128
129 #define FILENAME_NUM_REF            "num_refs"
130 #define FILENAME_UUID               "uuid"
131 #define FILENAME_COMMON_NAME        "common_name"
132 #define FILENAME_KBYTES_TOTAL       "kbytestotal"
133 #define FILENAME_KBYTES_FREE        "kbytesfree"
134 #define FILENAME_FILES_TOTAL        "filestotal"
135 #define FILENAME_FILES_FREE         "filesfree"
136 #define STR_REQ_WAITIME             "req_waittime"
137
138 /* strings which the file /var/lustre/sysStatus can hold */
139 #define STR_ONLINE                  "online"
140 #define STR_ONLINE_PENDING          "online pending"
141 #define STR_OFFLINE                 "offline"
142 #define STR_OFFLINE_PENDING         "offline pending"
143
144
145 /* Script required for starting/stopping lustre services */
146 #define LUSTRE_SERVICE              "/etc/init.d/lustre"
147
148 #define MIN_LEN(val1,val2)          (((val1)>(val2))?(val2):(val1))
149
150 /* The max size of a lustre procfs path name*/
151 #define MAX_PATH_SIZE               512
152
153 /* The max size of a string read from procfs */
154 #define MAX_LINE_SIZE               512
155
156 /* Types passed to get_file_list() */
157 #define DIR_TYPE                    1
158 #define FILE_TYPE                   0
159
160 /* Defining return values */
161 #define SUCCESS                     0
162 #define ERROR                       -1
163
164 typedef struct counter64 counter64;
165
166 typedef enum {
167     ONLINE = 1,
168     OFFLINE,
169     ONLINE_PENDING,
170     OFFLINE_PENDING,
171     RESTART
172 } lustre_sysstatus;
173
174 /* File operation related functions */
175 char *get_file_list(const char *dirname, int file_type, uint32_t *count);
176 extern int  is_directory(const char *filename);
177 extern int  read_string(const char *filepath, char *lustre_var,size_t var_size);
178 int read_counter64(const char *file_path, counter64 *c64,int factor);
179 int read_ulong(const char *file_path,unsigned long* valuep);
180
181 /* Start/Stop/Restart Lustre Services */
182 extern void lustrefs_ctrl(int command);
183 extern int get_sysstatus();
184
185 extern void report(const char *fmt, ...);
186
187 /* Table Driven SNMP OID Handler support*/
188 typedef unsigned char* (*f_oid_handler_t)(
189     const char* file_path,
190     size_t  *var_len);
191
192 struct oid_table
193 {
194     int magic;                  /*The magic number*/ 
195     const char *name;           /*The procfs name*/
196     f_oid_handler_t fhandler;   /*The handler */
197 };
198
199 unsigned char* oid_table_ulong_handler(const char* file_path,size_t  *var_len);
200 unsigned char* oid_table_c64_handler(const char* file_path,size_t  *var_len);
201 unsigned char* oid_table_c64_kb_handler(const char* file_path,size_t  *var_len);
202 unsigned char* oid_table_obj_name_handler(const char* file_path,size_t  *var_len);
203 unsigned char* oid_table_string_handler(const char* file_path,size_t *var_len);
204 unsigned char* oid_table_is_directory_handler(const char* file_path,size_t *var_len);
205 unsigned char *
206     var_genericTable(struct variable *vp,
207         oid     *name,
208         size_t  *length,
209         int     exact,
210         size_t  *var_len,
211         WriteMethod **write_method,
212         const char *path,
213         struct oid_table *ptable);
214
215 void convert_ull(counter64 *c64, unsigned long long ull, size_t *var_len);
216 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);
217 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);
218
219  /* export for net-snmp util-funcs */
220 int             header_simple_table(struct variable *, oid *, size_t *,
221                                     int, size_t *,
222                                     WriteMethod ** write_method, int);
223 int             header_generic(struct variable *, oid *, size_t *, int,
224                                size_t *, WriteMethod **);
225
226 #endif /* LUSTRE_SNMP_UTIL_H */