Whamcloud - gitweb
b=10778,i=eeb:
[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  *  Copyright (c) 2005 Cluster File Systems, Inc.
5  *   Author: PJ Kirner <pjkirner@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #ifndef LUSTRE_SNMP_UTIL_H
24 #define LUSTRE_SNMP_UTIL_H
25
26 /*
27  * Definitions of magic values
28  */
29
30 #define SYSVERSION          20
31 #define SYSKERNELVERSION    21
32 #define SYSHEALTHCHECK      22
33 #define SYSSTATUS           23
34
35 #define OSDNUMBER           30
36 #define OSDUUID             31
37 #define OSDCOMMONNAME       32
38 #define OSDCAPACITY         33
39 #define OSDFREECAPACITY     34
40 #define OSDOBJECTS          35
41 #define OSDFREEOBJECTS      36
42
43 #define OSCNUMBER           40
44 #define OSCUUID             41
45 #define OSCCOMMONNAME       42
46 #define OSCOSTSERVERUUID    43
47 #define OSCCAPACITY         44
48 #define OSCFREECAPACITY     45
49 #define OSCOBJECTS          46
50 #define OSCFREEOBJECTS      47
51
52 #define MDDNUMBER           50
53 #define MDDUUID             51
54 #define MDDCOMMONNAME       52
55 #define MDDCAPACITY         53
56 #define MDDFREECAPACITY     54
57 #define MDDFILES            55
58 #define MDDFREEFILES        56
59
60 #define MDCNUMBER           60
61 #define MDCUUID             61
62 #define MDCCOMMONNAME       62
63 #define MDCMDSSERVERUUID    63
64 #define MDCCAPACITY         64
65 #define MDCFREECAPACITY     65
66 #define MDCOBJECTS          66
67 #define MDCFREEOBJECTS      67
68
69 #define CLIMOUNTNUMBER      70
70 #define CLIUUID             71
71 #define CLICOMMONNAME       72
72 #define CLIMDCUUID          73
73 #define CLIMDCCOMMONNAME    74
74 #define CLIUSESLOV          75
75 #define CLILOVUUID          76
76 #define CLILOVCOMMONNAME    77
77
78 #define LOVNUMBER           80
79 #define LOVUUID             81
80 #define LOVCOMMONNAME       82
81 #define LOVNUMOBD           83
82 #define LOVNUMACTIVEOBD     84
83 #define LOVCAPACITY         85
84 #define LOVFREECAPACITY     86
85 #define LOVFILES            87
86 #define LOVFREEFILES        88
87 #define LOVSTRIPECOUNT      89
88 #define LOVSTRIPEOFFSET     90
89 #define LOVSTRIPESIZE       91
90 #define LOVSTRIPETYPE       92
91
92 #define LDLMNUMBER          100
93 #define LDLMNAMESPACE       101
94 #define LDLMLOCKCOUNT       102
95 #define LDLMUNUSEDLOCKCOUNT 103
96 #define LDLMRESOURCECOUNT   104
97
98 /* Defining the proc paths for Lustre file system */
99 #define LUSTRE_PATH                 "/proc/fs/lustre/"
100 #define OSD_PATH                    LUSTRE_PATH "obdfilter/"
101 #define OSC_PATH                    LUSTRE_PATH "osc/"
102 #define MDS_PATH                    LUSTRE_PATH "mds/"
103 #define MDC_PATH                    LUSTRE_PATH "mdc/"
104 #define CLIENT_PATH                 LUSTRE_PATH "llite/"
105 #define LOV_PATH                    LUSTRE_PATH "lov/"
106 #define LDLM_PATH                   LUSTRE_PATH "ldlm/namespaces/"
107
108 /* Common procfs file entries that are refrenced in mulitple locations*/
109 #define FILENAME_SYSHEALTHCHECK     "health_check"
110 #define FILENAME_SYS_STATUS         "/var/lustre/sysStatus"
111
112 #define FILENAME_NUM_REF            "num_refs"
113 #define FILENAME_UUID               "uuid"
114 #define FILENAME_COMMON_NAME        "common_name"
115 #define FILENAME_KBYTES_TOTAL       "kbytestotal"
116 #define FILENAME_KBYTES_FREE        "kbytesfree"
117 #define FILENAME_FILES_TOTAL        "filestotal"
118 #define FILENAME_FILES_FREE         "filesfree"
119
120 /* strings which the file /var/lustre/sysStatus can hold */
121 #define STR_ONLINE                  "online"
122 #define STR_ONLINE_PENDING          "online pending"
123 #define STR_OFFLINE                 "offline"
124 #define STR_OFFLINE_PENDING         "offline pending"
125
126
127 /* Script required for starting/stopping lustre services */
128 #define LUSTRE_SERVICE              "/etc/init.d/lustre"
129
130 #define MIN_LEN(val1,val2)          (((val1)>(val2))?(val2):(val1))
131
132 /* The max size of a lustre procfs path name*/
133 #define MAX_PATH_SIZE               512
134
135 /* The max size of a string read from procfs */
136 #define MAX_LINE_SIZE               512
137
138 /* Types passed to get_file_list() */
139 #define DIR_TYPE                    1
140 #define FILE_TYPE                   0
141
142 /* Defining return values */
143 #define SUCCESS                     0
144 #define ERROR                       -1
145
146 typedef struct counter64 counter64;
147
148 typedef enum {
149     ONLINE = 1,
150     OFFLINE,
151     ONLINE_PENDING,
152     OFFLINE_PENDING,
153     RESTART
154 } lustre_sysstatus;
155
156 /* File operation related functions */
157 char *get_file_list(const char *dirname, int file_type, uint32_t *count);
158 extern int  is_directory(const char *filename);
159 extern int  read_string(const char *filepath, char *lustre_var,size_t var_size);
160 int read_counter64(const char *file_path, counter64 *c64,int factor);
161 int read_ulong(const char *file_path,unsigned long* valuep);
162
163 /* Start/Stop/Restart Lustre Services */
164 extern void lustrefs_ctrl(int command);
165 extern int get_sysstatus();
166
167 extern void report(const char *fmt, ...);
168
169 /* Table Driven SNMP OID Handler support*/
170 typedef unsigned char* (*f_oid_handler_t)(
171     const char* file_path,
172     size_t  *var_len);
173
174 struct oid_table
175 {
176     int magic;                  /*The magic number*/ 
177     const char *name;           /*The procfs name*/
178     f_oid_handler_t fhandler;   /*The handler */
179 };
180
181 unsigned char* oid_table_ulong_handler(const char* file_path,size_t  *var_len);
182 unsigned char* oid_table_c64_handler(const char* file_path,size_t  *var_len);
183 unsigned char* oid_table_c64_kb_handler(const char* file_path,size_t  *var_len);
184 unsigned char* oid_table_obj_name_handler(const char* file_path,size_t  *var_len);
185 unsigned char* oid_table_string_handler(const char* file_path,size_t *var_len);
186 unsigned char* oid_table_is_directory_handler(const char* file_path,size_t *var_len);
187 unsigned char *
188     var_genericTable(struct variable *vp,
189         oid     *name,
190         size_t  *length,
191         int     exact,
192         size_t  *var_len,
193         WriteMethod **write_method,
194         const char *path,
195         struct oid_table *ptable);
196
197 #endif /* LUSTRE_SNMP_UTIL_H */