Whamcloud - gitweb
07f5c8fdc5f0f3bb0f82126e6d83ca05e0730e46
[fs/lustre-release.git] / lustre / include / lprocfs_status.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  *   Top level header file for LProc SNMP
22  *   Author: Hariharan Thantry thantry@users.sourceforge.net
23  */
24 #ifndef _LPROCFS_SNMP_H
25 #define _LPROCFS_SNMP_H
26
27 #include <lustre/lustre_idl.h>
28 #if defined(__linux__)
29 #include <linux/lprocfs_status.h>
30 #elif defined(__APPLE__)
31 #include <darwin/lprocfs_status.h>
32 #elif defined(__WINNT__)
33 #include <winnt/lprocfs_status.h>
34 #else
35 #error Unsupported operating system.
36 #endif
37
38 #undef LPROCFS
39 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
40 # define LPROCFS
41 #endif
42
43 struct lprocfs_vars {
44         const char   *name;
45         cfs_read_proc_t *read_fptr;
46         cfs_write_proc_t *write_fptr;
47         void *data;
48         struct file_operations *fops;
49 };
50
51 struct lprocfs_static_vars {
52         struct lprocfs_vars *module_vars;
53         struct lprocfs_vars *obd_vars;
54 };
55
56 /* if we find more consumers this could be generalized */
57 #define OBD_HIST_MAX 32
58 struct obd_histogram {
59         spinlock_t      oh_lock;
60         unsigned long   oh_buckets[OBD_HIST_MAX];
61 };
62
63 enum {
64         BRW_R_PAGES = 0,
65         BRW_W_PAGES,
66         BRW_R_RPC_HIST,
67         BRW_W_RPC_HIST,
68         BRW_R_IO_TIME,
69         BRW_W_IO_TIME,
70         BRW_R_DISCONT_PAGES,
71         BRW_W_DISCONT_PAGES,
72         BRW_R_DISCONT_BLOCKS,
73         BRW_W_DISCONT_BLOCKS,
74         BRW_R_DISK_IOSIZE,
75         BRW_W_DISK_IOSIZE,
76         BRW_R_DIO_FRAGS,
77         BRW_W_DIO_FRAGS,
78         BRW_LAST,
79 };
80
81 struct brw_stats {
82         struct obd_histogram hist[BRW_LAST];
83 };
84
85
86 /* An lprocfs counter can be configured using the enum bit masks below.
87  *
88  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
89  * protects this counter from concurrent updates. If not specified,
90  * lprocfs an internal per-counter lock variable. External locks are
91  * not used to protect counter increments, but are used to protect
92  * counter readout and resets.
93  *
94  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
95  * (i.e. counter can be incremented by more than "1"). When specified,
96  * the counter maintains min, max and sum in addition to a simple
97  * invocation count. This allows averages to be be computed.
98  * If not specified, the counter is an increment-by-1 counter.
99  * min, max, sum, etc. are not maintained.
100  *
101  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
102  * squares (for multi-valued counter samples only). This allows
103  * external computation of standard deviation, but involves a 64-bit
104  * multiply per counter increment.
105  */
106
107 enum {
108         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
109         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
110         LPROCFS_CNTR_STDDEV       = 0x0004,
111
112         /* counter data type */
113         LPROCFS_TYPE_REGS         = 0x0100,
114         LPROCFS_TYPE_BYTES        = 0x0200,
115         LPROCFS_TYPE_PAGES        = 0x0400,
116         LPROCFS_TYPE_CYCLE        = 0x0800,
117 };
118
119 struct lprocfs_atomic {
120         atomic_t               la_entry;
121         atomic_t               la_exit;
122 };
123
124 struct lprocfs_counter {
125         struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
126         unsigned int           lc_config;
127         __s64                  lc_count;
128         __s64                  lc_sum;
129         __s64                  lc_min;
130         __s64                  lc_max;
131         __s64                  lc_sumsquare;
132         const char            *lc_name;   /* must be static */
133         const char            *lc_units;  /* must be static */
134 };
135
136 struct lprocfs_percpu {
137         struct lprocfs_counter lp_cntr[0];
138 };
139
140 #define LPROCFS_GET_NUM_CPU 0x0001
141 #define LPROCFS_GET_SMP_ID  0x0002
142
143 enum lprocfs_stats_flags {
144         LPROCFS_STATS_FLAG_PERCPU   = 0x0000, /* per cpu counter */
145         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
146                                                * area and need locking */
147 };
148
149 enum lprocfs_fields_flags {
150         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
151         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
152         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
153         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
154         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
155         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
156         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
157 };
158
159 struct lprocfs_stats {
160         unsigned int           ls_num;     /* # of counters */
161         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
162         spinlock_t             ls_lock;  /* Lock used only when there are
163                                           * no percpu stats areas */
164         struct lprocfs_percpu *ls_percpu[0];
165 };
166
167 static inline int opcode_offset(__u32 opc) {
168         if (opc < OST_LAST_OPC) {
169                  /* OST opcode */
170                 return (opc - OST_FIRST_OPC);
171         } else if (opc < MDS_LAST_OPC) {
172                 /* MDS opcode */
173                 return (opc - MDS_FIRST_OPC +
174                         (OST_LAST_OPC - OST_FIRST_OPC));
175         } else if (opc < LDLM_LAST_OPC) {
176                 /* LDLM Opcode */
177                 return (opc - LDLM_FIRST_OPC +
178                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
179                         (OST_LAST_OPC - OST_FIRST_OPC));
180         } else if (opc < MGS_LAST_OPC) {
181                 /* MGS Opcode */
182                 return (opc - MGS_FIRST_OPC +
183                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
184                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
185                         (OST_LAST_OPC - OST_FIRST_OPC));
186         } else if (opc < OBD_LAST_OPC) {
187                 /* OBD Ping */
188                 return (opc - OBD_FIRST_OPC +
189                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
190                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
191                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
192                         (OST_LAST_OPC - OST_FIRST_OPC));
193         } else if (opc < LLOG_LAST_OPC) {
194                 /* LLOG Opcode */
195                 return (opc - LLOG_FIRST_OPC +
196                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
197                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
198                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
199                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
200                         (OST_LAST_OPC - OST_FIRST_OPC));
201 } else if (opc < FLD_LAST_OPC) {
202                 /* FLD opcode */
203                 return (opc - FLD_FIRST_OPC +
204                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
205                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
206                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
207                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
208                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
209                         (OST_LAST_OPC - OST_FIRST_OPC));
210         } else if (opc < SEQ_LAST_OPC) {
211                 /* SEQ opcode */
212                 return (opc - SEQ_FIRST_OPC +
213                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
214                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
215                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
216                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
217                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
218                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
219                         (OST_LAST_OPC - OST_FIRST_OPC));
220         } else if (opc < SEC_LAST_OPC) {
221                 /* SEC opcode */
222                 return (opc - SEC_FIRST_OPC +
223                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
224                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
225                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
226                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
227                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
228                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
229                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
230                         (OST_LAST_OPC - OST_FIRST_OPC));
231         } else {
232                 /* Unknown Opcode */
233                 return -1;
234         }
235 }
236
237 #define LUSTRE_MAX_OPCODES ((LDLM_LAST_OPC - LDLM_FIRST_OPC)   + \
238                             (MDS_LAST_OPC - MDS_FIRST_OPC)     + \
239                             (OST_LAST_OPC - OST_FIRST_OPC)     + \
240                             (OBD_LAST_OPC - OBD_FIRST_OPC)     + \
241                             (FLD_LAST_OPC - FLD_FIRST_OPC)     + \
242                             (SEQ_LAST_OPC - SEQ_FIRST_OPC)     + \
243                             (MGS_LAST_OPC - MGS_FIRST_OPC)     + \
244                             (LLOG_LAST_OPC - LLOG_FIRST_OPC)   + \
245                             (SEC_LAST_OPC - SEC_FIRST_OPC))
246
247 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
248                            (EXTRA_LAST_OPC - EXTRA_FIRST_OPC))
249
250 enum {
251         PTLRPC_REQWAIT_CNTR = 0,
252         PTLRPC_REQQDEPTH_CNTR,
253         PTLRPC_REQACTIVE_CNTR,
254         PTLRPC_TIMEOUT,
255         PTLRPC_REQBUF_AVAIL_CNTR,
256         PTLRPC_LAST_CNTR
257 };
258
259 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
260
261 enum {
262         LDLM_GLIMPSE_ENQUEUE = 0,
263         LDLM_PLAIN_ENQUEUE,
264         LDLM_EXTENT_ENQUEUE,
265         LDLM_FLOCK_ENQUEUE,
266         LDLM_IBITS_ENQUEUE,
267         MDS_REINT_CREATE,
268         MDS_REINT_LINK,
269         MDS_REINT_OPEN,
270         MDS_REINT_SETATTR,
271         MDS_REINT_RENAME,
272         MDS_REINT_UNLINK,
273         EXTRA_LAST_OPC
274 };
275
276 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
277 /* class_obd.c */
278 extern cfs_proc_dir_entry_t *proc_lustre_root;
279
280 struct obd_device;
281 struct file;
282 struct obd_histogram;
283
284 #ifdef LPROCFS
285
286 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int type)
287 {
288         int rc = 0;
289
290         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
291                 if (type & LPROCFS_GET_NUM_CPU)
292                         rc = 1;
293                 if (type & LPROCFS_GET_SMP_ID)
294                         rc = 0;
295                 spin_lock(&stats->ls_lock);
296         } else {
297                 if (type & LPROCFS_GET_NUM_CPU)
298                         rc = num_possible_cpus();
299                 if (type & LPROCFS_GET_SMP_ID)
300                         rc = smp_processor_id();
301         }
302         return rc;
303 }
304
305 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats)
306 {
307         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
308                 spin_unlock(&stats->ls_lock);
309 }
310
311 /* Two optimized LPROCFS counter increment functions are provided:
312  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
313  *     lprocfs_counter_add(cntr) - use for multi-valued counters
314  * Counter data layout allows config flag, counter lock and the
315  * count itself to reside within a single cache line.
316  */
317
318 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
319                                 long amount);
320 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
321                                 long amount);
322
323 #define lprocfs_counter_incr(stats, idx) \
324         lprocfs_counter_add(stats, idx, 1)
325 #define lprocfs_counter_decr(stats, idx) \
326         lprocfs_counter_sub(stats, idx, 1)
327
328 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc, 
329                                  enum lprocfs_fields_flags field);
330 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, 
331                                             int idx, 
332                                             enum lprocfs_fields_flags field)
333 {
334         __u64 ret = 0;
335         int i;
336
337         LASSERT(stats != NULL);
338         for (i = 0; i < num_possible_cpus(); i++)
339                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
340                                            field);
341         return ret;
342 }
343
344 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
345                                                  enum lprocfs_stats_flags flags);
346 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
347 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
348 extern void lprocfs_init_ops_stats(int num_private_stats, 
349                                    struct lprocfs_stats *stats);
350 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
351                                    unsigned int num_private_stats);
352 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
353                                  unsigned conf, const char *name,
354                                  const char *units);
355 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
356 struct obd_export;
357 struct nid_stat;
358 extern int lprocfs_add_clear_entry(struct obd_device * obd,
359                                    cfs_proc_dir_entry_t *entry);
360 extern int lprocfs_exp_setup(struct obd_export *exp,
361                              lnet_nid_t *peer_nid, int *newnid);
362 extern int lprocfs_exp_cleanup(struct obd_export *exp);
363 extern int lprocfs_add_simple(struct proc_dir_entry *root,
364                               char *name, read_proc_t *read_proc,
365                               write_proc_t *write_proc, void *data);
366 extern struct proc_dir_entry *lprocfs_add_symlink(const char *name,
367                         struct proc_dir_entry *parent, const char *dest);
368 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
369 extern int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
370                                          unsigned long count, void *data);
371 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
372                                         int count, int *eof,  void *data);
373
374 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
375                                   struct lprocfs_stats *stats);
376
377 /* lprocfs_status.c */
378 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
379                             struct lprocfs_vars *var,
380                             void *data);
381
382 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
383                                                cfs_proc_dir_entry_t *parent,
384                                                struct lprocfs_vars *list,
385                                                void *data);
386
387 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
388 extern void lprocfs_remove_proc_entry(const char *name,
389                                       struct proc_dir_entry *parent);
390
391 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
392                                            const char *name);
393
394 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
395 extern int lprocfs_obd_cleanup(struct obd_device *obd);
396 extern int lprocfs_add_simple(struct proc_dir_entry *root, char *name,
397                               read_proc_t *read_proc, write_proc_t *write_proc,
398                               void *data);
399 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
400 extern struct file_operations lprocfs_evict_client_fops;
401
402 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name, 
403                               mode_t mode, struct file_operations *seq_fops,
404                               void *data);
405 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
406                                   mode_t mode, struct file_operations *seq_fops,
407                                   void *data);
408
409 /* Generic callbacks */
410
411 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
412                           int count, int *eof, void *data);
413 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
414                              int count, int *eof, void *data);
415 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
416                              unsigned long count, void *data);
417 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
418                            int count, int *eof, void *data);
419 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
420                            unsigned long count, void *data);
421 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
422                            int count, int *eof, void *data);
423 extern int lprocfs_rd_name(char *page, char **start, off_t off,
424                            int count, int *eof, void *data);
425 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
426                              int count, int *eof, void *data);
427 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
428                                   int count, int *eof, void *data);
429 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
430                                 int count, int *eof, void *data);
431 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
432                                     int count, int *eof, void *data);
433 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
434                                   int count, int *eof, void *data);
435 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
436                               int count, int *eof, void *data);
437 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
438                                    unsigned long count, void *data);
439 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
440                            unsigned long count, void *data);
441
442 /* Statfs helpers */
443 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
444                               int count, int *eof, void *data);
445 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
446                                   int count, int *eof, void *data);
447 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
448                                  int count, int *eof, void *data);
449 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
450                                  int count, int *eof, void *data);
451 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
452                                  int count, int *eof, void *data);
453 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
454                                 int count, int *eof, void *data);
455 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
456                                  int count, int *eof, void *data);
457
458 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
459                                 int *val);
460 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
461                                      int *val, int mult);
462 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count, 
463                                     long val, int mult);
464 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
465                                     __u64 *val);
466 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
467                                          __u64 *val, int mult);
468 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
469 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
470 void lprocfs_oh_clear(struct obd_histogram *oh);
471 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
472
473 /* lprocfs_status.c: counter read/write functions */
474 extern int lprocfs_counter_read(char *page, char **start, off_t off,
475                                 int count, int *eof, void *data);
476 extern int lprocfs_counter_write(struct file *file, const char *buffer,
477                                  unsigned long count, void *data);
478
479 /* lprocfs_status.c: recovery status */
480 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
481                                    int count, int *eof, void *data);
482
483 extern int lprocfs_seq_release(struct inode *, struct file *);
484
485 /* in lprocfs_stat.c, to protect the private data for proc entries */
486 extern struct rw_semaphore _lprocfs_lock;
487 #define LPROCFS_ENTRY()           do {  \
488         down_read(&_lprocfs_lock);      \
489 } while(0)
490 #define LPROCFS_EXIT()            do {  \
491         up_read(&_lprocfs_lock);        \
492 } while(0)
493 #define LPROCFS_ENTRY_AND_CHECK(dp) do {        \
494         typecheck(struct proc_dir_entry *, dp); \
495         LPROCFS_ENTRY();                        \
496         if ((dp)->deleted) {                    \
497                 LPROCFS_EXIT();                 \
498                 return -ENODEV;                 \
499         }                                       \
500 } while(0)
501
502 /* You must use these macros when you want to refer to 
503  * the import in a client obd_device for a lprocfs entry */
504 #define LPROCFS_CLIMP_CHECK(obd) do {           \
505         typecheck(struct obd_device *, obd);    \
506         mutex_down(&(obd)->u.cli.cl_sem);       \
507         if ((obd)->u.cli.cl_import == NULL) {   \
508              mutex_up(&(obd)->u.cli.cl_sem);    \
509              return -ENODEV;                    \
510         }                                       \
511 } while(0)
512 #define LPROCFS_CLIMP_EXIT(obd)                 \
513         mutex_up(&(obd)->u.cli.cl_sem);
514
515
516 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only 
517   proc entries; otherwise, you will define name##_seq_write function also for 
518   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
519   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
520 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
521 static int name##_seq_open(struct inode *inode, struct file *file) {       \
522         struct proc_dir_entry *dp = PDE(inode);                            \
523         int rc;                                                            \
524         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
525         rc = single_open(file, name##_seq_show, dp->data);                 \
526         if (rc) {                                                          \
527                 LPROCFS_EXIT();                                            \
528                 return rc;                                                 \
529         }                                                                  \
530         return 0;                                                          \
531 }                                                                          \
532 struct file_operations name##_fops = {                                     \
533         .owner   = THIS_MODULE,                                            \
534         .open    = name##_seq_open,                                        \
535         .read    = seq_read,                                               \
536         .write   = custom_seq_write,                                       \
537         .llseek  = seq_lseek,                                              \
538         .release = lprocfs_seq_release,                                    \
539 }
540
541 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
542 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
543
544 /* lprocfs_status.c: read recovery max time bz13079 */
545 int lprocfs_obd_rd_recovery_maxtime(char *page, char **start, off_t off,
546                                     int count, int *eof, void *data);
547
548 /* lprocfs_status.c: write recovery max time bz13079 */
549 int lprocfs_obd_wr_recovery_maxtime(struct file *file, const char *buffer,
550                                     unsigned long count, void *data);
551 #else
552 /* LPROCFS is not defined */
553 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
554                                        int index, long amount) { return; }
555 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
556                                         int index) { return; }
557 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
558                                        int index, long amount) { return; }
559 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
560                                         int index, unsigned conf,
561                                         const char *name, const char *units)
562 { return; }
563
564 static inline __u64 lc_read_helper(struct lprocfs_counter *lc, 
565                                    enum lprocfs_fields_flags field) 
566 { return 0; }
567
568 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num,
569                                                         enum lprocfs_stats_flags flags)
570 { return NULL; }
571 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
572 { return; }
573 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
574 { return; }
575 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
576                                             const char *name,
577                                             struct lprocfs_stats *stats)
578 { return 0; }
579 static inline void lprocfs_init_ops_stats(int num_private_stats, 
580                                           struct lprocfs_stats *stats)
581 { return; }
582 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
583                                              unsigned int num_private_stats)
584 { return 0; }
585 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
586 { return; }
587
588 struct obd_export;
589 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
590 { return 0; }
591 static inline int lprocfs_exp_setup(struct obd_export *exp,
592                                     lnet_nid_t *peer_nid, int *newnid)
593 { return 0; }
594 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
595 { return 0; }
596 static inline int lprocfs_add_simple(struct proc_dir_entry *root,
597                                      char *name,
598                                      read_proc_t *read_proc,
599                                      write_proc_t *write_proc,
600                                      void *data)
601 {return 0; }
602 static inline struct proc_dir_entry *lprocfs_add_symlink(const char *name,
603                         struct proc_dir_entry *parent, const char *dest)
604 {return NULL; }
605 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
606 {}
607 static inline
608 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
609                                   unsigned long count, void *data)
610 {return count;}
611 static inline
612 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
613                                  int count, int *eof,  void *data)
614 {return count;}
615
616 static inline cfs_proc_dir_entry_t *
617 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
618                  struct lprocfs_vars *list, void *data) { return NULL; }
619 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
620                                    struct lprocfs_vars *var,
621                                    void *data) { return 0; }
622 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
623 static inline void lprocfs_remove_proc_entry(const char *name,
624                                              struct proc_dir_entry *parent) {};
625 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
626                                     const char *name) {return 0;}
627 static inline int lprocfs_obd_setup(struct obd_device *dev,
628                                     struct lprocfs_vars *list) { return 0; }
629 static inline int lprocfs_obd_cleanup(struct obd_device *dev)  { return 0; }
630 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
631                                  int count, int *eof, void *data) { return 0; }
632 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
633                                   int count, int *eof, void *data) { return 0; }
634 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
635                                   int count, int *eof, void *data) { return 0; }
636 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
637                                          int count, int *eof, void *data)
638 { return 0; }
639 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
640                                        int count, int *eof, void *data)
641 { return 0; }
642 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
643                                            int count, int *eof, void *data)
644 { return 0; }
645 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
646                                          int count, int *eof, void *data)
647 { return 0; }
648 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
649                                      int count, int *eof, void *data)
650 { return 0; }
651 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
652                                           unsigned long count, void *data)
653 { return 0; }
654 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
655                                   unsigned long count, void *data)
656 { return 0; }
657
658
659 /* Statfs helpers */
660 static inline
661 int lprocfs_rd_blksize(char *page, char **start, off_t off,
662                        int count, int *eof, void *data) { return 0; }
663 static inline
664 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
665                            int count, int *eof, void *data) { return 0; }
666 static inline
667 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
668                           int count, int *eof, void *data) { return 0; }
669 static inline
670 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
671                            int count, int *eof, void *data) { return 0; }
672 static inline
673 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
674                           int count, int *eof, void *data) { return 0; }
675 static inline
676 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
677                          int count, int *eof, void *data)  { return 0; }
678 static inline
679 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
680                           int count, int *eof, void *data) { return 0; }
681 static inline
682 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
683 static inline
684 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
685 static inline
686 void lprocfs_oh_clear(struct obd_histogram *oh) {}
687 static inline
688 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
689 static inline
690 int lprocfs_counter_read(char *page, char **start, off_t off,
691                          int count, int *eof, void *data) { return 0; }
692 static inline
693 int lprocfs_counter_write(struct file *file, const char *buffer,
694                           unsigned long count, void *data) { return 0; }
695
696 static inline
697 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx, 
698                                enum lprocfs_fields_flags field)
699 { return (__u64)0; }
700
701 #define LPROCFS_ENTRY()
702 #define LPROCFS_EXIT()
703 #define LPROCFS_ENTRY_AND_CHECK(dp)
704 #define LPROC_SEQ_FOPS_RO(name)
705 #define LPROC_SEQ_FOPS(name)
706
707 #endif /* LPROCFS */
708
709 #endif /* LPROCFS_SNMP_H */