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;
47 struct file_operations *fops;
50 struct lprocfs_static_vars {
51 struct lprocfs_vars *module_vars;
52 struct lprocfs_vars *obd_vars;
55 /* if we find more consumers this could be generalized */
56 #define OBD_HIST_MAX 32
57 struct obd_histogram {
59 unsigned long oh_buckets[OBD_HIST_MAX];
81 struct obd_histogram hist[BRW_LAST];
85 /* An lprocfs counter can be configured using the enum bit masks below.
87 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
88 * protects this counter from concurrent updates. If not specified,
89 * lprocfs an internal per-counter lock variable. External locks are
90 * not used to protect counter increments, but are used to protect
91 * counter readout and resets.
93 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
94 * (i.e. counter can be incremented by more than "1"). When specified,
95 * the counter maintains min, max and sum in addition to a simple
96 * invocation count. This allows averages to be be computed.
97 * If not specified, the counter is an increment-by-1 counter.
98 * min, max, sum, etc. are not maintained.
100 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
101 * squares (for multi-valued counter samples only). This allows
102 * external computation of standard deviation, but involves a 64-bit
103 * multiply per counter increment.
107 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
108 LPROCFS_CNTR_AVGMINMAX = 0x0002,
109 LPROCFS_CNTR_STDDEV = 0x0004,
111 /* counter data type */
112 LPROCFS_TYPE_REGS = 0x0100,
113 LPROCFS_TYPE_BYTES = 0x0200,
114 LPROCFS_TYPE_PAGES = 0x0400,
115 LPROCFS_TYPE_CYCLE = 0x0800,
118 struct lprocfs_atomic {
123 struct lprocfs_counter {
124 struct lprocfs_atomic lc_cntl; /* may need to move to per set */
125 unsigned int lc_config;
131 const char *lc_name; /* must be static */
132 const char *lc_units; /* must be static */
135 struct lprocfs_percpu {
136 struct lprocfs_counter lp_cntr[0];
140 struct lprocfs_stats {
141 unsigned int ls_num; /* # of counters */
142 unsigned int ls_percpu_size;
143 struct lprocfs_percpu *ls_percpu[0];
148 extern cfs_proc_dir_entry_t *proc_lustre_root;
152 struct obd_histogram;
156 /* Two optimized LPROCFS counter increment functions are provided:
157 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
158 * lprocfs_counter_add(cntr) - use for multi-valued counters
159 * Counter data layout allows config flag, counter lock and the
160 * count itself to reside within a single cache line.
163 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
166 struct lprocfs_counter *percpu_cntr;
170 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
171 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
172 percpu_cntr->lc_count++;
174 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
175 percpu_cntr->lc_sum += amount;
176 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
177 percpu_cntr->lc_sumsquare += (__u64)amount * amount;
178 if (amount < percpu_cntr->lc_min)
179 percpu_cntr->lc_min = amount;
180 if (amount > percpu_cntr->lc_max)
181 percpu_cntr->lc_max = amount;
183 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
186 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
188 struct lprocfs_counter *percpu_cntr;
192 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
193 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
194 percpu_cntr->lc_count++;
195 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
198 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
199 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
200 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
201 extern void lprocfs_init_ops_stats(int num_private_stats,
202 struct lprocfs_stats *stats);
203 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
204 unsigned int num_private_stats);
205 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
206 unsigned conf, const char *name,
208 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
210 extern int lprocfs_exp_setup(struct obd_export *exp);
211 extern int lprocfs_exp_cleanup(struct obd_export *exp);
212 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
213 struct lprocfs_stats *stats);
215 #define LPROCFS_INIT_VARS(name, vclass, vinstance) \
216 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x) \
218 x->module_vars = vclass; \
219 x->obd_vars = vinstance; \
222 #define lprocfs_init_vars(NAME, VAR) \
224 extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *); \
225 lprocfs_##NAME##_init_vars(VAR); \
228 /* lprocfs_status.c */
229 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
230 struct lprocfs_vars *var,
233 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
234 cfs_proc_dir_entry_t *parent,
235 struct lprocfs_vars *list,
238 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
240 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
243 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
244 extern int lprocfs_obd_cleanup(struct obd_device *obd);
245 extern struct file_operations lprocfs_evict_client_fops;
247 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
248 mode_t mode, struct file_operations *seq_fops,
250 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
251 mode_t mode, struct file_operations *seq_fops,
254 /* Generic callbacks */
256 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
257 int count, int *eof, void *data);
258 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
259 int count, int *eof, void *data);
260 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
261 unsigned long count, void *data);
262 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
263 int count, int *eof, void *data);
264 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
265 unsigned long count, void *data);
266 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
267 int count, int *eof, void *data);
268 extern int lprocfs_rd_name(char *page, char **start, off_t off,
269 int count, int *eof, void *data);
270 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
271 int count, int *eof, void *data);
272 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
273 int count, int *eof, void *data);
274 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
275 int count, int *eof, void *data);
276 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
277 int count, int *eof, void *data);
278 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
279 int count, int *eof, void *data);
280 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
281 int count, int *eof, void *data);
282 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
283 unsigned long count, void *data);
284 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
285 unsigned long count, void *data);
288 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
289 int count, int *eof, void *data);
290 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
291 int count, int *eof, void *data);
292 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
293 int count, int *eof, void *data);
294 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
295 int count, int *eof, void *data);
296 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
297 int count, int *eof, void *data);
298 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
299 int count, int *eof, void *data);
300 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
301 int count, int *eof, void *data);
303 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
305 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
307 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
309 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
311 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
312 __u64 *val, int mult);
313 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
314 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
315 void lprocfs_oh_clear(struct obd_histogram *oh);
316 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
318 /* lprocfs_status.c: counter read/write functions */
319 extern int lprocfs_counter_read(char *page, char **start, off_t off,
320 int count, int *eof, void *data);
321 extern int lprocfs_counter_write(struct file *file, const char *buffer,
322 unsigned long count, void *data);
324 /* lprocfs_status.c: recovery status */
325 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
326 int count, int *eof, void *data);
328 extern int lprocfs_seq_release(struct inode *, struct file *);
330 /* in lprocfs_stat.c, to protect the private data for proc entries */
331 extern struct rw_semaphore _lprocfs_lock;
332 #define LPROCFS_ENTRY() do { \
333 down_read(&_lprocfs_lock); \
335 #define LPROCFS_EXIT() do { \
336 up_read(&_lprocfs_lock); \
338 #define LPROCFS_ENTRY_AND_CHECK(dp) do { \
339 typecheck(struct proc_dir_entry *, dp); \
341 if ((dp)->deleted) { \
347 /* You must use these macros when you want to refer to
348 * the import in a client obd_device for a lprocfs entry */
349 #define LPROCFS_CLIMP_CHECK(obd) do { \
350 typecheck(struct obd_device *, obd); \
351 mutex_down(&(obd)->u.cli.cl_sem); \
352 if ((obd)->u.cli.cl_import == NULL) { \
353 mutex_up(&(obd)->u.cli.cl_sem); \
357 #define LPROCFS_CLIMP_EXIT(obd) \
358 mutex_up(&(obd)->u.cli.cl_sem);
361 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
362 proc entries; otherwise, you will define name##_seq_write function also for
363 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
364 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
365 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
366 static int name##_seq_open(struct inode *inode, struct file *file) { \
367 struct proc_dir_entry *dp = PDE(inode); \
369 LPROCFS_ENTRY_AND_CHECK(dp); \
370 rc = single_open(file, name##_seq_show, dp->data); \
377 struct file_operations name##_fops = { \
378 .owner = THIS_MODULE, \
379 .open = name##_seq_open, \
381 .write = custom_seq_write, \
382 .llseek = seq_lseek, \
383 .release = lprocfs_seq_release, \
386 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
387 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
390 /* LPROCFS is not defined */
391 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
392 int index, long amount) { return; }
393 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
394 int index) { return; }
395 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
396 int index, unsigned conf,
397 const char *name, const char *units)
400 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
402 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
404 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
406 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
408 struct lprocfs_stats *stats)
410 static inline void lprocfs_init_ops_stats(int num_private_stats,
411 struct lprocfs_stats *stats)
413 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
414 unsigned int num_private_stats)
416 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
420 static inline int lprocfs_exp_setup(struct obd_export *exp)
422 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
425 static inline cfs_proc_dir_entry_t *
426 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
427 struct lprocfs_vars *list, void *data) { return NULL; }
428 #define LPROCFS_INIT_VARS(name, vclass, vinstance)
429 #define lprocfs_init_vars(...) do {} while (0)
430 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
431 struct lprocfs_vars *var,
432 void *data) { return 0; }
433 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
434 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
435 const char *name) {return 0;}
436 static inline int lprocfs_obd_setup(struct obd_device *dev,
437 struct lprocfs_vars *list) { return 0; }
438 static inline int lprocfs_obd_cleanup(struct obd_device *dev) { return 0; }
439 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
440 int count, int *eof, void *data) { return 0; }
441 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
442 int count, int *eof, void *data) { return 0; }
443 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
444 int count, int *eof, void *data) { return 0; }
445 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
446 int count, int *eof, void *data)
448 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
449 int count, int *eof, void *data)
451 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
452 int count, int *eof, void *data)
454 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
455 int count, int *eof, void *data)
457 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
458 int count, int *eof, void *data)
460 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
461 unsigned long count, void *data)
463 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
464 unsigned long count, void *data)
470 int lprocfs_rd_blksize(char *page, char **start, off_t off,
471 int count, int *eof, void *data) { return 0; }
473 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
474 int count, int *eof, void *data) { return 0; }
476 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
477 int count, int *eof, void *data) { return 0; }
479 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
480 int count, int *eof, void *data) { return 0; }
482 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
483 int count, int *eof, void *data) { return 0; }
485 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
486 int count, int *eof, void *data) { return 0; }
488 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
489 int count, int *eof, void *data) { return 0; }
491 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
493 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
495 void lprocfs_oh_clear(struct obd_histogram *oh) {}
497 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
499 int lprocfs_counter_read(char *page, char **start, off_t off,
500 int count, int *eof, void *data) { return 0; }
502 int lprocfs_counter_write(struct file *file, const char *buffer,
503 unsigned long count, void *data) { return 0; }
505 #define LPROCFS_ENTRY()
506 #define LPROCFS_EXIT()
507 #define LPROCFS_ENTRY_AND_CHECK(dp)
508 #define LPROC_SEQ_FOPS_RO(name)
509 #define LPROC_SEQ_FOPS(name)
513 #endif /* LPROCFS_SNMP_H */