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 /* 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 cfs_proc_dir_entry_t *proc_lustre_root;
121 struct obd_histogram;
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(cfs_proc_dir_entry_t *root, const char *name,
174 struct lprocfs_stats *stats);
176 #define LPROCFS_INIT_VARS(name, vclass, vinstance) \
177 void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x) \
179 x->module_vars = vclass; \
180 x->obd_vars = vinstance; \
183 #define lprocfs_init_vars(NAME, VAR) \
185 extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *); \
186 lprocfs_##NAME##_init_vars(VAR); \
188 /* lprocfs_status.c */
189 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
190 struct lprocfs_vars *var,
193 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
194 cfs_proc_dir_entry_t *parent,
195 struct lprocfs_vars *list,
198 extern void lprocfs_remove(cfs_proc_dir_entry_t *root);
200 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
203 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
204 extern int lprocfs_obd_cleanup(struct obd_device *obd);
206 /* Generic callbacks */
208 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
209 int count, int *eof, void *data);
210 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
211 int count, int *eof, void *data);
212 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
213 int count, int *eof, void *data);
214 extern int lprocfs_rd_name(char *page, char **start, off_t off,
215 int count, int *eof, void *data);
216 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
217 int count, int *eof, void *data);
218 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
219 int count, int *eof, void *data);
220 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
221 int count, int *eof, void *data);
222 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
223 int count, int *eof, void *data);
224 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
225 int count, int *eof, void *data);
226 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
227 int count, int *eof, void *data);
228 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
229 unsigned long count, void *data);
230 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
231 unsigned long count, void *data);
234 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
235 int count, int *eof, void *data);
236 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
237 int count, int *eof, void *data);
238 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
239 int count, int *eof, void *data);
240 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
241 int count, int *eof, void *data);
242 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
243 int count, int *eof, void *data);
244 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
245 int count, int *eof, void *data);
246 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
247 int count, int *eof, void *data);
249 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
251 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
253 int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
254 struct file_operations *seq_fops, void *data);
255 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
256 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
257 void lprocfs_oh_clear(struct obd_histogram *oh);
258 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
260 /* lprocfs_status.c: counter read/write functions */
261 extern int lprocfs_counter_read(char *page, char **start, off_t off,
262 int count, int *eof, void *data);
263 extern int lprocfs_counter_write(struct file *file, const char *buffer,
264 unsigned long count, void *data);
266 /* lprocfs_status.c: recovery status */
267 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
268 int count, int *eof, void *data);
270 /* LPROCFS is not defined */
271 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
272 int index, long amount) { return; }
273 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
274 int index) { return; }
275 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
276 int index, unsigned conf,
277 const char *name, const char *units)
280 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
282 static inline void lprocfs_free_stats(struct lprocfs_stats *stats)
285 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
287 struct lprocfs_stats *stats)
289 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
290 unsigned int num_private_stats)
292 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
295 static inline cfs_proc_dir_entry_t *
296 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
297 struct lprocfs_vars *list, void *data) { return NULL; }
298 #define LPROCFS_INIT_VARS(name, vclass, vinstance)
299 #define lprocfs_init_vars(...) do {} while (0)
300 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
301 struct lprocfs_vars *var,
302 void *data) { return 0; }
303 static inline void lprocfs_remove(cfs_proc_dir_entry_t *root) {};
304 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
305 const char *name) {return 0;}
306 static inline int lprocfs_obd_setup(struct obd_device *dev,
307 struct lprocfs_vars *list) { return 0; }
308 static inline int lprocfs_obd_cleanup(struct obd_device *dev) { return 0; }
309 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
310 int count, int *eof, void *data) { return 0; }
311 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
312 int count, int *eof, void *data) { return 0; }
313 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
314 int count, int *eof, void *data) { return 0; }
315 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
316 int count, int *eof, void *data)
318 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
319 int count, int *eof, void *data)
321 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
322 int count, int *eof, void *data)
324 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
325 int count, int *eof, void *data)
327 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
328 int count, int *eof, void *data)
330 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
331 unsigned long count, void *data)
333 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
334 unsigned long count, void *data)
340 int lprocfs_rd_blksize(char *page, char **start, off_t off,
341 int count, int *eof, void *data) { return 0; }
343 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
344 int count, int *eof, void *data) { return 0; }
346 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
347 int count, int *eof, void *data) { return 0; }
349 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
350 int count, int *eof, void *data) { return 0; }
352 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
353 int count, int *eof, void *data) { return 0; }
355 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
356 int count, int *eof, void *data) { return 0; }
358 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
359 int count, int *eof, void *data) { return 0; }
361 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
363 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
365 void lprocfs_oh_clear(struct obd_histogram *oh) {}
367 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
369 int lprocfs_counter_read(char *page, char **start, off_t off,
370 int count, int *eof, void *data) { return 0; }
372 int lprocfs_counter_write(struct file *file, const char *buffer,
373 unsigned long count, void *data) { return 0; }
376 #endif /* LPROCFS_SNMP_H */