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
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>
34 #error Unsupported operating system.
38 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
44 cfs_read_proc_t *read_fptr;
45 cfs_write_proc_t *write_fptr;
49 struct lprocfs_static_vars {
50 struct lprocfs_vars *module_vars;
51 struct lprocfs_vars *obd_vars;
54 /* if we find more consumers this could be generalized */
55 #define OBD_HIST_MAX 32
56 struct obd_histogram {
58 unsigned long oh_buckets[OBD_HIST_MAX];
80 struct obd_histogram hist[BRW_LAST];
84 /* An lprocfs counter can be configured using the enum bit masks below.
86 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
87 * protects this counter from concurrent updates. If not specified,
88 * lprocfs an internal per-counter lock variable. External locks are
89 * not used to protect counter increments, but are used to protect
90 * counter readout and resets.
92 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
93 * (i.e. counter can be incremented by more than "1"). When specified,
94 * the counter maintains min, max and sum in addition to a simple
95 * invocation count. This allows averages to be be computed.
96 * If not specified, the counter is an increment-by-1 counter.
97 * min, max, sum, etc. are not maintained.
99 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
100 * squares (for multi-valued counter samples only). This allows
101 * external computation of standard deviation, but involves a 64-bit
102 * multiply per counter increment.
106 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
107 LPROCFS_CNTR_AVGMINMAX = 0x0002,
108 LPROCFS_CNTR_STDDEV = 0x0004,
110 /* counter data type */
111 LPROCFS_TYPE_REGS = 0x0100,
112 LPROCFS_TYPE_BYTES = 0x0200,
113 LPROCFS_TYPE_PAGES = 0x0400,
114 LPROCFS_TYPE_CYCLE = 0x0800,
117 struct lprocfs_atomic {
122 struct lprocfs_counter {
123 struct lprocfs_atomic lc_cntl; /* may need to move to per set */
124 unsigned int lc_config;
130 const char *lc_name; /* must be static */
131 const char *lc_units; /* must be static */
134 struct lprocfs_percpu {
135 struct lprocfs_counter lp_cntr[0];
139 struct lprocfs_stats {
140 unsigned int ls_num; /* # of counters */
141 unsigned int ls_percpu_size;
142 struct lprocfs_percpu *ls_percpu[0];
147 extern cfs_proc_dir_entry_t *proc_lustre_root;
151 struct obd_histogram;
155 /* Two optimized LPROCFS counter increment functions are provided:
156 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
157 * lprocfs_counter_add(cntr) - use for multi-valued counters
158 * Counter data layout allows config flag, counter lock and the
159 * count itself to reside within a single cache line.
162 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
165 struct lprocfs_counter *percpu_cntr;
169 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
170 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
171 percpu_cntr->lc_count++;
173 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
174 percpu_cntr->lc_sum += amount;
175 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
176 percpu_cntr->lc_sumsquare += (__u64)amount * amount;
177 if (amount < percpu_cntr->lc_min)
178 percpu_cntr->lc_min = amount;
179 if (amount > percpu_cntr->lc_max)
180 percpu_cntr->lc_max = amount;
182 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
185 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
187 struct lprocfs_counter *percpu_cntr;
191 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
192 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
193 percpu_cntr->lc_count++;
194 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
197 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
198 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
199 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
200 extern void lprocfs_init_ops_stats(int num_private_stats,
201 struct lprocfs_stats *stats);
202 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
203 unsigned int num_private_stats);
204 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
205 unsigned conf, const char *name,
207 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
209 extern int lprocfs_exp_setup(struct obd_export *exp);
210 extern int lprocfs_exp_cleanup(struct obd_export *exp);
211 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
212 struct lprocfs_stats *stats);
214 #define LPROCFS_INIT_VARS(name, vclass, vinstance) \
215 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x) \
217 x->module_vars = vclass; \
218 x->obd_vars = vinstance; \
221 #define lprocfs_init_vars(NAME, VAR) \
223 extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *); \
224 lprocfs_##NAME##_init_vars(VAR); \
227 /* lprocfs_status.c */
228 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
229 struct lprocfs_vars *var,
232 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
233 cfs_proc_dir_entry_t *parent,
234 struct lprocfs_vars *list,
237 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
239 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
242 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
243 extern int lprocfs_obd_cleanup(struct obd_device *obd);
245 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
246 mode_t mode, struct file_operations *seq_fops,
248 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
249 mode_t mode, struct file_operations *seq_fops,
252 /* Generic callbacks */
254 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
255 int count, int *eof, void *data);
256 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
257 int count, int *eof, void *data);
258 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
259 int count, int *eof, void *data);
260 extern int lprocfs_rd_name(char *page, char **start, off_t off,
261 int count, int *eof, void *data);
262 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
263 int count, int *eof, void *data);
264 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
265 int count, int *eof, void *data);
266 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
267 int count, int *eof, void *data);
268 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
269 int count, int *eof, void *data);
270 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
271 int count, int *eof, void *data);
272 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
273 int count, int *eof, void *data);
274 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
275 unsigned long count, void *data);
276 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
277 unsigned long count, void *data);
280 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
281 int count, int *eof, void *data);
282 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
283 int count, int *eof, void *data);
284 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
285 int count, int *eof, void *data);
286 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
287 int count, int *eof, void *data);
288 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
289 int count, int *eof, void *data);
290 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
291 int count, int *eof, void *data);
292 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
293 int count, int *eof, void *data);
295 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
297 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
299 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
301 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
303 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
304 __u64 *val, int mult);
305 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
306 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
307 void lprocfs_oh_clear(struct obd_histogram *oh);
308 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
310 /* lprocfs_status.c: counter read/write functions */
311 extern int lprocfs_counter_read(char *page, char **start, off_t off,
312 int count, int *eof, void *data);
313 extern int lprocfs_counter_write(struct file *file, const char *buffer,
314 unsigned long count, void *data);
316 /* lprocfs_status.c: recovery status */
317 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
318 int count, int *eof, void *data);
320 extern int lprocfs_seq_release(struct inode *, struct file *);
322 /* in lprocfs_stat.c, to protect the private data for proc entries */
323 extern struct rw_semaphore _lprocfs_lock;
324 #define LPROCFS_ENTRY() do { \
325 down_read(&_lprocfs_lock); \
327 #define LPROCFS_EXIT() do { \
328 up_read(&_lprocfs_lock); \
330 #define LPROCFS_ENTRY_AND_CHECK(dp) do { \
331 typecheck(struct proc_dir_entry *, dp); \
333 if ((dp)->deleted) { \
339 /* You must use these macros when you want to refer to
340 * the import in a client obd_device for a lprocfs entry */
341 #define LPROCFS_CLIMP_CHECK(obd) do { \
342 typecheck(struct obd_device *, obd); \
343 mutex_down(&(obd)->u.cli.cl_sem); \
344 if ((obd)->u.cli.cl_import == NULL) { \
345 mutex_up(&(obd)->u.cli.cl_sem); \
349 #define LPROCFS_CLIMP_EXIT(obd) \
350 mutex_up(&(obd)->u.cli.cl_sem);
353 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
354 proc entries; otherwise, you will define name##_seq_write function also for
355 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
356 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
357 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
358 static int name##_seq_open(struct inode *inode, struct file *file) { \
359 struct proc_dir_entry *dp = PDE(inode); \
361 LPROCFS_ENTRY_AND_CHECK(dp); \
362 rc = single_open(file, name##_seq_show, dp->data); \
369 struct file_operations name##_fops = { \
370 .owner = THIS_MODULE, \
371 .open = name##_seq_open, \
373 .write = custom_seq_write, \
374 .llseek = seq_lseek, \
375 .release = lprocfs_seq_release, \
378 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
379 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
382 /* LPROCFS is not defined */
383 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
384 int index, long amount) { return; }
385 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
386 int index) { return; }
387 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
388 int index, unsigned conf,
389 const char *name, const char *units)
392 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
394 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
396 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
398 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
400 struct lprocfs_stats *stats)
402 static inline void lprocfs_init_ops_stats(int num_private_stats,
403 struct lprocfs_stats *stats)
405 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
406 unsigned int num_private_stats)
408 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
412 static inline int lprocfs_exp_setup(struct obd_export *exp)
414 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
417 static inline cfs_proc_dir_entry_t *
418 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
419 struct lprocfs_vars *list, void *data) { return NULL; }
420 #define LPROCFS_INIT_VARS(name, vclass, vinstance)
421 #define lprocfs_init_vars(...) do {} while (0)
422 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
423 struct lprocfs_vars *var,
424 void *data) { return 0; }
425 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
426 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
427 const char *name) {return 0;}
428 static inline int lprocfs_obd_setup(struct obd_device *dev,
429 struct lprocfs_vars *list) { return 0; }
430 static inline int lprocfs_obd_cleanup(struct obd_device *dev) { return 0; }
431 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
432 int count, int *eof, void *data) { return 0; }
433 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
434 int count, int *eof, void *data) { return 0; }
435 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
436 int count, int *eof, void *data) { return 0; }
437 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
438 int count, int *eof, void *data)
440 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
441 int count, int *eof, void *data)
443 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
444 int count, int *eof, void *data)
446 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
447 int count, int *eof, void *data)
449 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
450 int count, int *eof, void *data)
452 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
453 unsigned long count, void *data)
455 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
456 unsigned long count, void *data)
462 int lprocfs_rd_blksize(char *page, char **start, off_t off,
463 int count, int *eof, void *data) { return 0; }
465 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
466 int count, int *eof, void *data) { return 0; }
468 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
469 int count, int *eof, void *data) { return 0; }
471 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
472 int count, int *eof, void *data) { return 0; }
474 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
475 int count, int *eof, void *data) { return 0; }
477 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
478 int count, int *eof, void *data) { return 0; }
480 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
481 int count, int *eof, void *data) { return 0; }
483 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
485 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
487 void lprocfs_oh_clear(struct obd_histogram *oh) {}
489 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
491 int lprocfs_counter_read(char *page, char **start, off_t off,
492 int count, int *eof, void *data) { return 0; }
494 int lprocfs_counter_write(struct file *file, const char *buffer,
495 unsigned long count, void *data) { return 0; }
497 #define LPROCFS_ENTRY()
498 #define LPROCFS_EXIT()
499 #define LPROCFS_ENTRY_AND_CHECK(dp)
500 #define LPROC_SEQ_FOPS_RO(name)
501 #define LPROC_SEQ_FOPS(name)
505 #endif /* LPROCFS_SNMP_H */