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;
154 /* Days / hours / mins / seconds format */
158 static inline void s2dhms(struct dhms *ts, time_t secs)
160 ts->d = secs / 86400;
167 #define DHMS_FMT "%dd%dh%02dm%02ds"
168 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
173 /* Two optimized LPROCFS counter increment functions are provided:
174 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
175 * lprocfs_counter_add(cntr) - use for multi-valued counters
176 * Counter data layout allows config flag, counter lock and the
177 * count itself to reside within a single cache line.
180 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
183 struct lprocfs_counter *percpu_cntr;
187 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
188 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
189 percpu_cntr->lc_count++;
191 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
192 percpu_cntr->lc_sum += amount;
193 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
194 percpu_cntr->lc_sumsquare += (__u64)amount * amount;
195 if (amount < percpu_cntr->lc_min)
196 percpu_cntr->lc_min = amount;
197 if (amount > percpu_cntr->lc_max)
198 percpu_cntr->lc_max = amount;
200 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
203 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
205 struct lprocfs_counter *percpu_cntr;
209 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
210 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
211 percpu_cntr->lc_count++;
212 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
215 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
216 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
217 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
218 extern void lprocfs_init_ops_stats(int num_private_stats,
219 struct lprocfs_stats *stats);
220 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
221 unsigned int num_private_stats);
222 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
223 unsigned conf, const char *name,
225 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
227 extern int lprocfs_exp_setup(struct obd_export *exp);
228 extern int lprocfs_exp_cleanup(struct obd_export *exp);
229 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
230 struct lprocfs_stats *stats);
232 #define LPROCFS_INIT_VARS(name, vclass, vinstance) \
233 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x) \
235 x->module_vars = vclass; \
236 x->obd_vars = vinstance; \
239 #define lprocfs_init_vars(NAME, VAR) \
241 extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *); \
242 lprocfs_##NAME##_init_vars(VAR); \
245 /* lprocfs_status.c */
246 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
247 struct lprocfs_vars *var,
250 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
251 cfs_proc_dir_entry_t *parent,
252 struct lprocfs_vars *list,
255 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
257 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
260 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
261 extern int lprocfs_obd_cleanup(struct obd_device *obd);
262 extern struct file_operations lprocfs_evict_client_fops;
264 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
265 mode_t mode, struct file_operations *seq_fops,
267 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
268 mode_t mode, struct file_operations *seq_fops,
271 /* Generic callbacks */
273 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
274 int count, int *eof, void *data);
275 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
276 int count, int *eof, void *data);
277 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
278 unsigned long count, void *data);
279 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
280 int count, int *eof, void *data);
281 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
282 unsigned long count, void *data);
283 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
284 int count, int *eof, void *data);
285 extern int lprocfs_rd_name(char *page, char **start, off_t off,
286 int count, int *eof, void *data);
287 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
288 int count, int *eof, void *data);
289 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
290 int count, int *eof, void *data);
291 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
292 int count, int *eof, void *data);
293 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
294 int count, int *eof, void *data);
295 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
296 int count, int *eof, void *data);
297 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
298 int count, int *eof, void *data);
299 struct adaptive_timeout;
300 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
301 struct adaptive_timeout *at);
302 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
303 int count, int *eof, void *data);
304 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
305 unsigned long count, void *data);
306 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
307 unsigned long count, void *data);
308 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
309 unsigned long count, void *data);
312 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
313 int count, int *eof, void *data);
314 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
315 int count, int *eof, void *data);
316 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
317 int count, int *eof, void *data);
318 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
319 int count, int *eof, void *data);
320 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
321 int count, int *eof, void *data);
322 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
323 int count, int *eof, void *data);
324 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
325 int count, int *eof, void *data);
327 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
329 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
331 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
333 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
335 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
336 __u64 *val, int mult);
337 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
338 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
339 void lprocfs_oh_clear(struct obd_histogram *oh);
340 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
342 /* lprocfs_status.c: counter read/write functions */
343 extern int lprocfs_counter_read(char *page, char **start, off_t off,
344 int count, int *eof, void *data);
345 extern int lprocfs_counter_write(struct file *file, const char *buffer,
346 unsigned long count, void *data);
348 /* lprocfs_status.c: recovery status */
349 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
350 int count, int *eof, void *data);
352 extern int lprocfs_seq_release(struct inode *, struct file *);
354 /* in lprocfs_stat.c, to protect the private data for proc entries */
355 extern struct rw_semaphore _lprocfs_lock;
356 #define LPROCFS_ENTRY() do { \
357 down_read(&_lprocfs_lock); \
359 #define LPROCFS_EXIT() do { \
360 up_read(&_lprocfs_lock); \
362 #define LPROCFS_ENTRY_AND_CHECK(dp) do { \
363 typecheck(struct proc_dir_entry *, dp); \
365 if ((dp)->deleted) { \
371 /* You must use these macros when you want to refer to
372 * the import in a client obd_device for a lprocfs entry */
373 #define LPROCFS_CLIMP_CHECK(obd) do { \
374 typecheck(struct obd_device *, obd); \
375 mutex_down(&(obd)->u.cli.cl_sem); \
376 if ((obd)->u.cli.cl_import == NULL) { \
377 mutex_up(&(obd)->u.cli.cl_sem); \
381 #define LPROCFS_CLIMP_EXIT(obd) \
382 mutex_up(&(obd)->u.cli.cl_sem);
385 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
386 proc entries; otherwise, you will define name##_seq_write function also for
387 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
388 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
389 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
390 static int name##_seq_open(struct inode *inode, struct file *file) { \
391 struct proc_dir_entry *dp = PDE(inode); \
393 LPROCFS_ENTRY_AND_CHECK(dp); \
394 rc = single_open(file, name##_seq_show, dp->data); \
401 struct file_operations name##_fops = { \
402 .owner = THIS_MODULE, \
403 .open = name##_seq_open, \
405 .write = custom_seq_write, \
406 .llseek = seq_lseek, \
407 .release = lprocfs_seq_release, \
410 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
411 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
414 /* LPROCFS is not defined */
415 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
416 int index, long amount) { return; }
417 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
418 int index) { return; }
419 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
420 int index, unsigned conf,
421 const char *name, const char *units)
424 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
426 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
428 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
430 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
432 struct lprocfs_stats *stats)
434 static inline void lprocfs_init_ops_stats(int num_private_stats,
435 struct lprocfs_stats *stats)
437 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
438 unsigned int num_private_stats)
440 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
444 static inline int lprocfs_exp_setup(struct obd_export *exp)
446 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
449 static inline cfs_proc_dir_entry_t *
450 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
451 struct lprocfs_vars *list, void *data) { return NULL; }
452 #define LPROCFS_INIT_VARS(name, vclass, vinstance)
453 #define lprocfs_init_vars(...) do {} while (0)
454 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
455 struct lprocfs_vars *var,
456 void *data) { return 0; }
457 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
458 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
459 const char *name) {return 0;}
460 static inline int lprocfs_obd_setup(struct obd_device *dev,
461 struct lprocfs_vars *list) { return 0; }
462 static inline int lprocfs_obd_cleanup(struct obd_device *dev) { return 0; }
463 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
464 int count, int *eof, void *data) { return 0; }
465 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
466 int count, int *eof, void *data) { return 0; }
467 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
468 int count, int *eof, void *data) { return 0; }
469 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
470 int count, int *eof, void *data)
472 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
473 int count, int *eof, void *data)
475 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
476 int count, int *eof, void *data)
478 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
479 int count, int *eof, void *data)
481 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
482 int count, int *eof, void *data)
484 struct adaptive_timeout;
485 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
486 struct adaptive_timeout *at)
488 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
489 int count, int *eof, void *data)
491 static inline int lprocfs_wr_timeouts(struct file *file, const char *buffer,
492 unsigned long count, void *data)
494 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
495 unsigned long count, void *data)
497 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
498 unsigned long count, void *data)
504 int lprocfs_rd_blksize(char *page, char **start, off_t off,
505 int count, int *eof, void *data) { return 0; }
507 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
508 int count, int *eof, void *data) { return 0; }
510 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
511 int count, int *eof, void *data) { return 0; }
513 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
514 int count, int *eof, void *data) { return 0; }
516 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
517 int count, int *eof, void *data) { return 0; }
519 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
520 int count, int *eof, void *data) { return 0; }
522 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
523 int count, int *eof, void *data) { return 0; }
525 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
527 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
529 void lprocfs_oh_clear(struct obd_histogram *oh) {}
531 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
533 int lprocfs_counter_read(char *page, char **start, off_t off,
534 int count, int *eof, void *data) { return 0; }
536 int lprocfs_counter_write(struct file *file, const char *buffer,
537 unsigned long count, void *data) { return 0; }
539 #define LPROCFS_ENTRY()
540 #define LPROCFS_EXIT()
541 #define LPROCFS_ENTRY_AND_CHECK(dp)
542 #define LPROC_SEQ_FOPS_RO(name)
543 #define LPROC_SEQ_FOPS(name)
547 #endif /* LPROCFS_SNMP_H */