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
28 #include <linux/config.h>
29 #include <linux/autoconf.h>
30 #include <linux/proc_fs.h>
31 #include <linux/smp.h>
34 #include <linux/kp30.h>
37 #ifdef CONFIG_PROC_FS /* Ensure that /proc is configured */
44 read_proc_t *read_fptr;
45 write_proc_t *write_fptr;
49 struct lprocfs_static_vars {
50 struct lprocfs_vars *module_vars;
51 struct lprocfs_vars *obd_vars;
54 /* An lprocfs counter can be configured using the enum bit masks below.
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.
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.
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.
76 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
77 LPROCFS_CNTR_AVGMINMAX = 0x0002,
78 LPROCFS_CNTR_STDDEV = 0x0004,
80 /* counter data type */
81 LPROCFS_TYPE_REGS = 0x0100,
82 LPROCFS_TYPE_BYTES = 0x0200,
83 LPROCFS_TYPE_PAGES = 0x0400,
84 LPROCFS_TYPE_CYCLE = 0x0800,
87 struct lprocfs_atomic {
92 struct lprocfs_counter {
93 struct lprocfs_atomic lc_cntl; /* may need to move to per set */
94 unsigned int lc_config;
100 const char *lc_name; /* must be static */
101 const char *lc_units; /* must be static */
104 struct lprocfs_percpu {
105 struct lprocfs_counter lp_cntr[0];
109 struct lprocfs_stats {
110 unsigned int ls_num; /* # of counters */
111 unsigned int ls_percpu_size;
112 struct lprocfs_percpu *ls_percpu[0];
117 extern struct proc_dir_entry *proc_lustre_root;
120 extern struct file_operations ll_proc_target_fops;
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.
132 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
135 struct lprocfs_counter *percpu_cntr;
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++;
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;
151 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
154 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
156 struct lprocfs_counter *percpu_cntr;
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);
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,
172 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
173 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
174 struct lprocfs_stats *stats);
176 #define LPROCFS_INIT_MULTI_VARS(array, size) \
177 void lprocfs_init_multi_vars(unsigned int idx, \
178 struct lprocfs_static_vars *x) \
180 struct lprocfs_static_vars *glob = (struct lprocfs_static_vars*)array; \
181 LASSERT(glob != 0); \
182 LASSERT(idx < (unsigned int)(size)); \
183 x->module_vars = glob[idx].module_vars; \
184 x->obd_vars = glob[idx].obd_vars; \
187 #define LPROCFS_INIT_VARS(vclass, vinstance) \
188 void lprocfs_init_vars(struct lprocfs_static_vars *x) \
190 x->module_vars = vclass; \
191 x->obd_vars = vinstance; \
194 extern void lprocfs_init_vars(struct lprocfs_static_vars *var);
195 extern void lprocfs_init_multi_vars(unsigned int idx,
196 struct lprocfs_static_vars *var);
197 /* lprocfs_status.c */
198 extern int lprocfs_add_vars(struct proc_dir_entry *root,
199 struct lprocfs_vars *var,
202 extern struct proc_dir_entry *lprocfs_register(const char *name,
203 struct proc_dir_entry *parent,
204 struct lprocfs_vars *list,
207 extern void lprocfs_remove(struct proc_dir_entry *root);
209 extern struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *root,
212 extern int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list);
213 extern int lprocfs_obd_detach(struct obd_device *dev);
215 /* Generic callbacks */
217 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
218 int count, int *eof, void *data);
219 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
220 int count, int *eof, void *data);
221 extern int lprocfs_rd_name(char *page, char **start, off_t off,
222 int count, int *eof, void *data);
223 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
224 int count, int *eof, void *data);
225 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
226 int count, int *eof, void *data);
227 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
228 int count, int *eof, void *data);
232 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
233 int count, int *eof, struct statfs *sfs);
234 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
235 int count, int *eof, struct statfs *sfs);
236 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
237 int count, int *eof, struct statfs *sfs);
238 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
239 int count, int *eof, struct statfs *sfs);
240 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
241 int count, int *eof, struct statfs *sfs);
242 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
243 int count, int *eof, struct statfs *sfs);
245 /* lprocfs_status.c: counter read/write functions */
247 extern int lprocfs_counter_read(char *page, char **start, off_t off,
248 int count, int *eof, void *data);
249 extern int lprocfs_counter_write(struct file *file, const char *buffer,
250 unsigned long count, void *data);
252 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct) \
253 int fct_name(char *page, char **start, off_t off, \
254 int count, int *eof, void *data) \
257 int rc = get_statfs_fct((struct obd_device*)data, &sfs); \
259 lprocfs_##fct_name (page, start, off, count, eof, &sfs) : \
264 /* LPROCFS is not defined */
265 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
266 int index, long amount) { return; }
267 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
268 int index) { return; }
269 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
270 int index, unsigned conf,
271 const char *name, const char *units)
274 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
276 static inline void lprocfs_free_stats(struct lprocfs_stats *stats)
279 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
281 struct lprocfs_stats *stats)
283 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
284 unsigned int num_private_stats)
286 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
289 static inline struct proc_dir_entry *
290 lprocfs_register(const char *name, struct proc_dir_entry *parent,
291 struct lprocfs_vars *list, void *data) { return NULL; }
292 #define LPROCFS_INIT_MULTI_VARS(array, size)
293 static inline void lprocfs_init_multi_vars(unsigned int idx,
294 struct lprocfs_static_vars *x) { return; }
295 #define LPROCFS_INIT_VARS(vclass, vinstance)
296 static inline void lprocfs_init_vars(struct lprocfs_static_vars *x) { return; }
297 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
298 struct lprocfs_vars *var,
299 void *data) { return 0; }
300 static inline void lprocfs_remove(struct proc_dir_entry *root) {};
301 static inline struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
302 const char *name) {return 0;}
304 static inline int lprocfs_obd_attach(struct obd_device *dev,
305 struct lprocfs_vars *list) { return 0; }
306 static inline int lprocfs_obd_detach(struct obd_device *dev) { return 0; }
307 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
308 int count, int *eof, void *data) { return 0; }
309 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
310 int count, int *eof, void *data) { return 0; }
311 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
312 int count, int *eof, void *data) { return 0; }
313 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
314 int count, int *eof, void *data) { return 0; }
315 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
316 int count, int *eof, void *data) { return 0; }
317 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
318 int count, int *eof, void *data) { return 0; }
323 int lprocfs_rd_blksize(char *page, char **start, off_t off,
324 int count, int *eof, struct statfs *sfs) { return 0; }
326 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
327 int count, int *eof, struct statfs *sfs) { return 0; }
329 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
330 int count, int *eof, struct statfs *sfs) { return 0; }
332 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
333 int count, int *eof, struct statfs *sfs) { return 0; }
335 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
336 int count, int *eof, struct statfs *sfs) { return 0; }
338 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
339 int count, int *eof, struct statfs *sfs) { return 0; }
341 int lprocfs_counter_read(char *page, char **start, off_t off,
342 int count, int *eof, void *data) { return 0; }
345 int lprocfs_counter_write(struct file *file, const char *buffer,
346 unsigned long count, void *data) { return 0; }
348 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct) \
349 int fct_name(char *page, char **start, off_t off, \
350 int count, int *eof, void *data) { *eof = 1; return 0; }
354 #endif /* LPROCFS_SNMP_H */