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;
131 struct obd_histogram;
135 /* Two optimized LPROCFS counter increment functions are provided:
136 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
137 * lprocfs_counter_add(cntr) - use for multi-valued counters
138 * Counter data layout allows config flag, counter lock and the
139 * count itself to reside within a single cache line.
142 static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
145 struct lprocfs_counter *percpu_cntr;
147 LASSERT(stats != NULL);
148 percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
149 atomic_inc(&percpu_cntr->lc_cntl.la_entry);
150 percpu_cntr->lc_count++;
152 if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
153 percpu_cntr->lc_sum += amount;
154 if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
155 percpu_cntr->lc_sumsquare += (__u64)amount * amount;
156 if (amount < percpu_cntr->lc_min)
157 percpu_cntr->lc_min = amount;
158 if (amount > percpu_cntr->lc_max)
159 percpu_cntr->lc_max = amount;
161 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
164 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
166 struct lprocfs_counter *percpu_cntr;
168 LASSERT(stats != NULL);
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++;
172 atomic_inc(&percpu_cntr->lc_cntl.la_exit);
175 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
176 extern void lprocfs_free_stats(struct lprocfs_stats *stats);
177 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
178 unsigned int num_private_stats);
179 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
180 unsigned conf, const char *name,
182 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
183 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
184 struct lprocfs_stats *stats);
186 #define LPROCFS_INIT_VARS(name, vclass, vinstance) \
187 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x) \
189 x->module_vars = vclass; \
190 x->obd_vars = vinstance; \
193 #define lprocfs_init_vars(NAME, VAR) \
195 extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *); \
196 lprocfs_##NAME##_init_vars(VAR); \
198 /* lprocfs_status.c */
199 extern int lprocfs_add_vars(struct proc_dir_entry *root,
200 struct lprocfs_vars *var,
203 extern struct proc_dir_entry *lprocfs_register(const char *name,
204 struct proc_dir_entry *parent,
205 struct lprocfs_vars *list,
208 extern void lprocfs_remove(struct proc_dir_entry *root);
210 extern struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *root,
213 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
214 extern int lprocfs_obd_cleanup(struct obd_device *obd);
216 /* Generic callbacks */
218 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
219 int count, int *eof, void *data);
220 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
221 int count, int *eof, void *data);
222 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
223 int count, int *eof, void *data);
224 extern int lprocfs_rd_name(char *page, char **start, off_t off,
225 int count, int *eof, void *data);
226 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
227 int count, int *eof, void *data);
228 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
229 int count, int *eof, void *data);
230 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
231 int count, int *eof, void *data);
232 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
233 int count, int *eof, void *data);
234 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
235 int count, int *eof, void *data);
236 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
237 unsigned long count, void *data);
238 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
239 unsigned long count, void *data);
242 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
243 int count, int *eof, void *data);
244 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
245 int count, int *eof, void *data);
246 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
247 int count, int *eof, void *data);
248 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
249 int count, int *eof, void *data);
250 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
251 int count, int *eof, void *data);
252 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
253 int count, int *eof, void *data);
254 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
255 int count, int *eof, void *data);
257 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
259 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
261 int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
262 struct file_operations *seq_fops, void *data);
263 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
264 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
265 void lprocfs_oh_clear(struct obd_histogram *oh);
266 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
268 /* lprocfs_status.c: counter read/write functions */
269 extern int lprocfs_counter_read(char *page, char **start, off_t off,
270 int count, int *eof, void *data);
271 extern int lprocfs_counter_write(struct file *file, const char *buffer,
272 unsigned long count, void *data);
274 /* lprocfs_status.c: recovery status */
275 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
276 int count, int *eof, void *data);
278 /* LPROCFS is not defined */
279 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
280 int index, long amount) { return; }
281 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
282 int index) { return; }
283 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
284 int index, unsigned conf,
285 const char *name, const char *units)
288 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
290 static inline void lprocfs_free_stats(struct lprocfs_stats *stats)
293 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
295 struct lprocfs_stats *stats)
297 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
298 unsigned int num_private_stats)
300 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
303 static inline struct proc_dir_entry *
304 lprocfs_register(const char *name, struct proc_dir_entry *parent,
305 struct lprocfs_vars *list, void *data) { return NULL; }
306 #define LPROCFS_INIT_VARS(name, vclass, vinstance)
307 #define lprocfs_init_vars(...) do {} while (0)
308 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
309 struct lprocfs_vars *var,
310 void *data) { return 0; }
311 static inline void lprocfs_remove(struct proc_dir_entry *root) {};
312 static inline struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
313 const char *name) {return 0;}
314 static inline int lprocfs_obd_setup(struct obd_device *dev,
315 struct lprocfs_vars *list) { return 0; }
316 static inline int lprocfs_obd_cleanup(struct obd_device *dev) { return 0; }
317 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
318 int count, int *eof, void *data) { return 0; }
319 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
320 int count, int *eof, void *data) { return 0; }
321 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
322 int count, int *eof, void *data) { return 0; }
323 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
324 int count, int *eof, void *data)
326 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
327 int count, int *eof, void *data)
329 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
330 int count, int *eof, void *data)
332 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
333 int count, int *eof, void *data)
335 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
336 unsigned long count, void *data)
338 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
339 unsigned long count, void *data)
345 int lprocfs_rd_blksize(char *page, char **start, off_t off,
346 int count, int *eof, void *data) { return 0; }
348 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
349 int count, int *eof, void *data) { return 0; }
351 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
352 int count, int *eof, void *data) { return 0; }
354 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
355 int count, int *eof, void *data) { return 0; }
357 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
358 int count, int *eof, void *data) { return 0; }
360 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
361 int count, int *eof, void *data) { return 0; }
363 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
364 int count, int *eof, void *data) { return 0; }
366 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
368 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
370 void lprocfs_oh_clear(struct obd_histogram *oh) {}
372 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
374 int lprocfs_counter_read(char *page, char **start, off_t off,
375 int count, int *eof, void *data) { return 0; }
377 int lprocfs_counter_write(struct file *file, const char *buffer,
378 unsigned long count, void *data) { return 0; }
381 #endif /* LPROCFS_SNMP_H */