Whamcloud - gitweb
- update from b1_4_mountconf
[fs/lustre-release.git] / lustre / include / lprocfs_status.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  *   Top level header file for LProc SNMP
22  *   Author: Hariharan Thantry thantry@users.sourceforge.net
23  */
24 #ifndef _LPROCFS_SNMP_H
25 #define _LPROCFS_SNMP_H
26
27 #if defined(__linux__)
28 #include <linux/lprocfs_status.h>
29 #elif defined(__APPLE__)
30 #include <darwin/lprocfs_status.h>
31 #elif defined(__WINNT__)
32 #include <winnt/lprocfs_status.h>
33 #else
34 #error Unsupported operating system.
35 #endif
36
37 #undef LPROCFS
38 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
39 # define LPROCFS
40 #endif
41
42 struct lprocfs_vars {
43         const char   *name;
44         cfs_read_proc_t *read_fptr;
45         cfs_write_proc_t *write_fptr;
46         void *data;
47 };
48
49 struct lprocfs_static_vars {
50         struct lprocfs_vars *module_vars;
51         struct lprocfs_vars *obd_vars;
52 };
53
54 /* An lprocfs counter can be configured using the enum bit masks below.
55  *
56  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
57  * protects this counter from concurrent updates. If not specified,
58  * lprocfs an internal per-counter lock variable. External locks are
59  * not used to protect counter increments, but are used to protect
60  * counter readout and resets.
61  *
62  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
63  * (i.e. counter can be incremented by more than "1"). When specified,
64  * the counter maintains min, max and sum in addition to a simple
65  * invocation count. This allows averages to be be computed.
66  * If not specified, the counter is an increment-by-1 counter.
67  * min, max, sum, etc. are not maintained.
68  *
69  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
70  * squares (for multi-valued counter samples only). This allows
71  * external computation of standard deviation, but involves a 64-bit
72  * multiply per counter increment.
73  */
74
75 enum {
76         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
77         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
78         LPROCFS_CNTR_STDDEV       = 0x0004,
79
80         /* counter data type */
81         LPROCFS_TYPE_REGS         = 0x0100,
82         LPROCFS_TYPE_BYTES        = 0x0200,
83         LPROCFS_TYPE_PAGES        = 0x0400,
84         LPROCFS_TYPE_CYCLE        = 0x0800,
85 };
86
87 struct lprocfs_atomic {
88         atomic_t               la_entry;
89         atomic_t               la_exit;
90 };
91
92 struct lprocfs_counter {
93         struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
94         unsigned int           lc_config;
95         __u64                  lc_count;
96         __u64                  lc_sum;
97         __u64                  lc_min;
98         __u64                  lc_max;
99         __u64                  lc_sumsquare;
100         const char            *lc_name;   /* must be static */
101         const char            *lc_units;  /* must be static */
102 };
103
104 struct lprocfs_percpu {
105         struct lprocfs_counter lp_cntr[0];
106 };
107
108
109 struct lprocfs_stats {
110         unsigned int           ls_num;     /* # of counters */
111         unsigned int           ls_percpu_size;
112         struct lprocfs_percpu *ls_percpu[0];
113 };
114
115
116 /* class_obd.c */
117 extern cfs_proc_dir_entry_t *proc_lustre_root;
118
119 struct obd_device;
120 struct file;
121 struct obd_histogram;
122
123 #ifdef LPROCFS
124
125 /* Two optimized LPROCFS counter increment functions are provided:
126  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
127  *     lprocfs_counter_add(cntr) - use for multi-valued counters
128  * Counter data layout allows config flag, counter lock and the
129  * count itself to reside within a single cache line.
130  */
131
132 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
133                                        long amount)
134 {
135         struct lprocfs_counter *percpu_cntr;
136
137         LASSERT(stats != NULL);
138         percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
139         atomic_inc(&percpu_cntr->lc_cntl.la_entry);
140         percpu_cntr->lc_count++;
141
142         if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
143                 percpu_cntr->lc_sum += amount;
144                 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
145                         percpu_cntr->lc_sumsquare += (__u64)amount * amount;
146                 if (amount < percpu_cntr->lc_min)
147                         percpu_cntr->lc_min = amount;
148                 if (amount > percpu_cntr->lc_max)
149                         percpu_cntr->lc_max = amount;
150         }
151         atomic_inc(&percpu_cntr->lc_cntl.la_exit);
152 }
153
154 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
155 {
156         struct lprocfs_counter *percpu_cntr;
157
158         LASSERT(stats != NULL);
159         percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
160         atomic_inc(&percpu_cntr->lc_cntl.la_entry);
161         percpu_cntr->lc_count++;
162         atomic_inc(&percpu_cntr->lc_cntl.la_exit);
163 }
164
165 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
166 extern void lprocfs_free_stats(struct lprocfs_stats *stats);
167 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
168                                    unsigned int num_private_stats);
169 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
170                                  unsigned conf, const char *name,
171                                  const char *units);
172 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
173 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
174                                   struct lprocfs_stats *stats);
175
176 #define LPROCFS_INIT_VARS(name, vclass, vinstance)           \
177 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x)  \
178 {                                                      \
179         x->module_vars = vclass;                       \
180         x->obd_vars = vinstance;                       \
181 }                                                      \
182
183 #define lprocfs_init_vars(NAME, VAR)     \
184 do {      \
185         extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *);  \
186         lprocfs_##NAME##_init_vars(VAR);                                       \
187 } while (0)
188 /* lprocfs_status.c */
189 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
190                             struct lprocfs_vars *var,
191                             void *data);
192
193 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
194                                                cfs_proc_dir_entry_t *parent,
195                                                struct lprocfs_vars *list,
196                                                void *data);
197
198 extern void lprocfs_remove(cfs_proc_dir_entry_t *root);
199
200 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
201                                            const char *name);
202
203 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
204 extern int lprocfs_obd_cleanup(struct obd_device *obd);
205
206 /* Generic callbacks */
207
208 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
209                           int count, int *eof, void *data);
210 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
211                           int count, int *eof, void *data);
212 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
213                            int count, int *eof, void *data);
214 extern int lprocfs_rd_name(char *page, char **start, off_t off,
215                            int count, int *eof, void *data);
216 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
217                              int count, int *eof, void *data);
218 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
219                                   int count, int *eof, void *data);
220 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
221                                 int count, int *eof, void *data);
222 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
223                                     int count, int *eof, void *data);
224 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
225                                   int count, int *eof, void *data);
226 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
227                               int count, int *eof, void *data);
228 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
229                                    unsigned long count, void *data);
230 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
231                            unsigned long count, void *data);
232
233 /* Statfs helpers */
234 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
235                               int count, int *eof, void *data);
236 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
237                                   int count, int *eof, void *data);
238 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
239                                  int count, int *eof, void *data);
240 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
241                                  int count, int *eof, void *data);
242 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
243                                  int count, int *eof, void *data);
244 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
245                                 int count, int *eof, void *data);
246 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
247                                  int count, int *eof, void *data);
248
249 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
250                                 int *val);
251 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
252                                     __u64 *val);
253 int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
254                            struct file_operations *seq_fops, void *data);
255 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
256 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
257 void lprocfs_oh_clear(struct obd_histogram *oh);
258 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
259
260 /* lprocfs_status.c: counter read/write functions */
261 extern int lprocfs_counter_read(char *page, char **start, off_t off,
262                                 int count, int *eof, void *data);
263 extern int lprocfs_counter_write(struct file *file, const char *buffer,
264                                  unsigned long count, void *data);
265
266 /* lprocfs_status.c: recovery status */
267 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
268                                    int count, int *eof, void *data);
269 #else
270 /* LPROCFS is not defined */
271 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
272                                        int index, long amount) { return; }
273 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
274                                         int index) { return; }
275 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
276                                         int index, unsigned conf,
277                                         const char *name, const char *units)
278 { return; }
279
280 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
281 { return NULL; }
282 static inline void lprocfs_free_stats(struct lprocfs_stats *stats)
283 { return; }
284
285 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
286                                             const char *name,
287                                             struct lprocfs_stats *stats)
288 { return 0; }
289 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
290                                              unsigned int num_private_stats)
291 { return 0; }
292 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
293 { return; }
294
295 static inline cfs_proc_dir_entry_t *
296 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
297                  struct lprocfs_vars *list, void *data) { return NULL; }
298 #define LPROCFS_INIT_VARS(name, vclass, vinstance)
299 #define lprocfs_init_vars(...) do {} while (0)
300 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
301                                    struct lprocfs_vars *var,
302                                    void *data) { return 0; }
303 static inline void lprocfs_remove(cfs_proc_dir_entry_t *root) {};
304 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
305                                     const char *name) {return 0;}
306 static inline int lprocfs_obd_setup(struct obd_device *dev,
307                                     struct lprocfs_vars *list) { return 0; }
308 static inline int lprocfs_obd_cleanup(struct obd_device *dev)  { return 0; }
309 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
310                                  int count, int *eof, void *data) { return 0; }
311 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
312                                   int count, int *eof, void *data) { return 0; }
313 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
314                                   int count, int *eof, void *data) { return 0; }
315 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
316                                          int count, int *eof, void *data)
317 { return 0; }
318 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
319                                        int count, int *eof, void *data)
320 { return 0; }
321 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
322                                            int count, int *eof, void *data)
323 { return 0; }
324 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
325                                          int count, int *eof, void *data)
326 { return 0; }
327 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
328                                      int count, int *eof, void *data)
329 { return 0; }
330 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
331                                           unsigned long count, void *data)
332 { return 0; }
333 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
334                                   unsigned long count, void *data)
335 { return 0; }
336
337
338 /* Statfs helpers */
339 static inline
340 int lprocfs_rd_blksize(char *page, char **start, off_t off,
341                        int count, int *eof, void *data) { return 0; }
342 static inline
343 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
344                            int count, int *eof, void *data) { return 0; }
345 static inline
346 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
347                           int count, int *eof, void *data) { return 0; }
348 static inline
349 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
350                            int count, int *eof, void *data) { return 0; }
351 static inline
352 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
353                           int count, int *eof, void *data) { return 0; }
354 static inline
355 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
356                          int count, int *eof, void *data)  { return 0; }
357 static inline
358 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
359                           int count, int *eof, void *data) { return 0; }
360 static inline
361 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
362 static inline
363 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
364 static inline
365 void lprocfs_oh_clear(struct obd_histogram *oh) {}
366 static inline
367 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
368 static inline
369 int lprocfs_counter_read(char *page, char **start, off_t off,
370                          int count, int *eof, void *data) { return 0; }
371 static inline
372 int lprocfs_counter_write(struct file *file, const char *buffer,
373                           unsigned long count, void *data) { return 0; }
374 #endif /* LPROCFS */
375
376 #endif /* LPROCFS_SNMP_H */