1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * Top level header file for LProc SNMP
22 * Author: Hariharan Thantry thantry@users.sourceforge.net
24 #ifndef _LPROCFS_SNMP_H
25 #define _LPROCFS_SNMP_H
29 #include <linux/config.h>
30 #include <linux/autoconf.h>
31 #include <linux/proc_fs.h>
32 #include <linux/version.h>
33 #include <linux/smp.h>
34 #include <libcfs/kp30.h>
36 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
37 # include <linux/statfs.h>
39 # define kstatfs statfs
43 # define kstatfs statfs
48 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
54 read_proc_t *read_fptr;
55 write_proc_t *write_fptr;
59 struct lprocfs_static_vars {
60 struct lprocfs_vars *module_vars;
61 struct lprocfs_vars *obd_vars;
64 /* An lprocfs counter can be configured using the enum bit masks below.
66 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
67 * protects this counter from concurrent updates. If not specified,
68 * lprocfs an internal per-counter lock variable. External locks are
69 * not used to protect counter increments, but are used to protect
70 * counter readout and resets.
72 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
73 * (i.e. counter can be incremented by more than "1"). When specified,
74 * the counter maintains min, max and sum in addition to a simple
75 * invocation count. This allows averages to be be computed.
76 * If not specified, the counter is an increment-by-1 counter.
77 * min, max, sum, etc. are not maintained.
79 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
80 * squares (for multi-valued counter samples only). This allows
81 * external computation of standard deviation, but involves a 64-bit
82 * multiply per counter increment.
86 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
87 LPROCFS_CNTR_AVGMINMAX = 0x0002,
88 LPROCFS_CNTR_STDDEV = 0x0004,
90 /* counter data type */
91 LPROCFS_TYPE_REGS = 0x0100,
92 LPROCFS_TYPE_BYTES = 0x0200,
93 LPROCFS_TYPE_PAGES = 0x0400,
94 LPROCFS_TYPE_CYCLE = 0x0800,
97 struct lprocfs_atomic {
102 struct lprocfs_counter {
103 struct lprocfs_atomic lc_cntl; /* may need to move to per set */
104 unsigned int lc_config;
110 const char *lc_name; /* must be static */
111 const char *lc_units; /* must be static */
114 struct lprocfs_percpu {
115 struct lprocfs_counter lp_cntr[0];
119 struct lprocfs_stats {
120 unsigned int ls_num; /* # of counters */
121 unsigned int ls_percpu_size;
122 struct lprocfs_percpu *ls_percpu[0];
127 extern struct proc_dir_entry *proc_lustre_root;
134 /* Two optimized LPROCFS counter increment functions are provided:
135 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
136 * lprocfs_counter_add(cntr) - use for multi-valued counters
137 * Counter data layout allows config flag, counter lock and the
138 * count itself to reside within a single cache line.
141 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
144 struct lprocfs_counter *percpu_cntr;
146 LASSERT(stats != NULL);
147 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
148 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
149 percpu_cntr->lc_count++;
151 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
152 percpu_cntr->lc_sum += amount;
153 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
154 percpu_cntr->lc_sumsquare += (__u64)amount * amount;
155 if (amount < percpu_cntr->lc_min)
156 percpu_cntr->lc_min = amount;
157 if (amount > percpu_cntr->lc_max)
158 percpu_cntr->lc_max = amount;
160 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
163 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
165 struct lprocfs_counter *percpu_cntr;
167 LASSERT(stats != NULL);
168 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
169 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
170 percpu_cntr->lc_count++;
171 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
174 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
175 extern void lprocfs_free_stats(struct lprocfs_stats *stats);
176 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
177 unsigned conf, const char *name,
179 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
180 unsigned int num_private_stats);
181 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
182 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
183 unsigned int num_private_stats);
184 extern void lprocfs_free_md_stats(struct obd_device *obddev);
185 extern int lprocfs_register_stats(struct proc_dir_entry *root,
187 struct lprocfs_stats *stats);
189 #define LPROCFS_INIT_MULTI_VARS(array, size) \
190 void lprocfs_init_multi_vars(unsigned int idx, \
191 struct lprocfs_static_vars *x) \
193 struct lprocfs_static_vars *glob = (struct lprocfs_static_vars*)array; \
194 LASSERT(glob != 0); \
195 LASSERT(idx < (unsigned int)(size)); \
196 x->module_vars = glob[idx].module_vars; \
197 x->obd_vars = glob[idx].obd_vars; \
200 #define LPROCFS_INIT_VARS(name, vclass, vinstance) \
201 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x) \
203 x->module_vars = vclass; \
204 x->obd_vars = vinstance; \
207 #define lprocfs_init_vars(NAME, VAR) \
209 extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *); \
210 lprocfs_##NAME##_init_vars(VAR); \
213 extern void lprocfs_init_multi_vars(unsigned int idx,
214 struct lprocfs_static_vars *var);
215 /* lprocfs_status.c */
216 extern int lprocfs_add_vars(struct proc_dir_entry *root,
217 struct lprocfs_vars *var,
220 extern struct proc_dir_entry *lprocfs_register(const char *name,
221 struct proc_dir_entry *parent,
222 struct lprocfs_vars *list,
225 extern void lprocfs_remove(struct proc_dir_entry *root);
227 extern struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *root,
230 extern int lprocfs_obd_attach(struct obd_device *obd, struct lprocfs_vars *list);
231 extern int lprocfs_obd_detach(struct obd_device *obd);
233 /* Generic callbacks */
235 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
236 int count, int *eof, void *data);
237 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
238 int count, int *eof, void *data);
239 extern int lprocfs_rd_name(char *page, char **start, off_t off,
240 int count, int *eof, void *data);
241 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
242 int count, int *eof, void *data);
243 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
244 int count, int *eof, void *data);
245 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
246 int count, int *eof, void *data);
247 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
248 int count, int *eof, void *data);
249 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
250 int count, int *eof, void *data);
253 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
254 int count, int *eof, void *data);
255 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
256 int count, int *eof, void *data);
257 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
258 int count, int *eof, void *data);
259 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
260 int count, int *eof, void *data);
261 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
262 int count, int *eof, void *data);
263 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
264 int count, int *eof, void *data);
265 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
266 int count, int *eof, void *data);
268 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
270 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
272 int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
273 struct file_operations *seq_fops, void *data);
274 struct obd_histogram;
275 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
276 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
277 void lprocfs_oh_clear(struct obd_histogram *oh);
278 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
280 struct obd_service_time;
281 void lprocfs_stime_record(struct obd_service_time *stime,
282 struct timeval *large, struct timeval *small);
283 unsigned long lprocfs_stime_avg_ms(struct obd_service_time *stime);
284 unsigned long lprocfs_stime_avg_us(struct obd_service_time *stime);
286 /* lprocfs_status.c: counter read/write functions */
287 extern int lprocfs_counter_read(char *page, char **start, off_t off,
288 int count, int *eof, void *data);
289 extern int lprocfs_counter_write(struct file *file, const char *buffer,
290 unsigned long count, void *data);
292 /* lprocfs_status.c: recovery status */
293 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
294 int count, int *eof, void *data);
297 /* LPROCFS is not defined */
298 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
299 int index, long amount) { return; }
300 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
301 int index) { return; }
302 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
303 int index, unsigned conf,
304 const char *name, const char *units)
306 struct obd_service_time;
307 static inline void lprocfs_stime_record(struct obd_service_time *stime,
308 struct timeval *large, struct timeval *small)
312 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
314 static inline void lprocfs_free_stats(struct lprocfs_stats *stats)
317 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
319 struct lprocfs_stats *stats)
321 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
322 unsigned int num_private_stats)
324 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
327 static inline struct proc_dir_entry *
328 lprocfs_register(const char *name, struct proc_dir_entry *parent,
329 struct lprocfs_vars *list, void *data) { return NULL; }
330 #define LPROCFS_INIT_MULTI_VARS(array, size) do {} while (0)
331 static inline void lprocfs_init_multi_vars(unsigned int idx,
332 struct lprocfs_static_vars *x) { return; }
333 #define LPROCFS_INIT_VARS(name, vclass, vinstance) do {} while (0)
334 #define lprocfs_init_vars(...) do {} while (0)
335 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
336 struct lprocfs_vars *var,
337 void *data) { return 0; }
338 static inline void lprocfs_remove(struct proc_dir_entry *root) {};
339 static inline struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
340 const char *name) {return 0;}
341 static inline int lprocfs_obd_attach(struct obd_device *dev,
342 struct lprocfs_vars *list) { return 0; }
343 static inline int lprocfs_obd_detach(struct obd_device *dev) { return 0; }
344 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
345 int count, int *eof, void *data) { return 0; }
346 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
347 int count, int *eof, void *data) { return 0; }
348 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
349 int count, int *eof, void *data) { return 0; }
350 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
351 int count, int *eof, void *data)
353 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
354 int count, int *eof, void *data)
356 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
357 int count, int *eof, void *data)
359 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
360 int count, int *eof, void *data) { return 0; }
364 int lprocfs_rd_blksize(char *page, char **start, off_t off,
365 int count, int *eof, void *data) { return 0; }
367 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
368 int count, int *eof, void *data) { return 0; }
370 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
371 int count, int *eof, void *data) { return 0; }
373 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
374 int count, int *eof, void *data) { return 0; }
376 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
377 int count, int *eof, void *data) { return 0; }
379 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
380 int count, int *eof, void *data) { return 0; }
382 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
383 int count, int *eof, void *data) { return 0; }
385 int lprocfs_counter_read(char *page, char **start, off_t off,
386 int count, int *eof, void *data) { return 0; }
388 int lprocfs_counter_write(struct file *file, const char *buffer,
389 unsigned long count, void *data) { return 0; }
392 #endif /* LPROCFS_SNMP_H */