Whamcloud - gitweb
4331fd688f51b95d69b3fc655e0fcee079074cd6
[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 #define LC_MIN_INIT ((~(__u64)0) >> 1)
125
126 struct lprocfs_counter {
127         struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
128         unsigned int           lc_config;
129         __s64                  lc_count;
130         __s64                  lc_sum;
131         __s64                  lc_min;
132         __s64                  lc_max;
133         __s64                  lc_sumsquare;
134         const char            *lc_name;   /* must be static */
135         const char            *lc_units;  /* must be static */
136 };
137
138 struct lprocfs_percpu {
139         struct lprocfs_counter lp_cntr[0];
140 };
141
142 #define LPROCFS_GET_NUM_CPU 0x0001
143 #define LPROCFS_GET_SMP_ID  0x0002
144
145 enum lprocfs_stats_flags {
146         LPROCFS_STATS_FLAG_PERCPU   = 0x0000, /* per cpu counter */
147         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
148                                                * area and need locking */
149 };
150
151 enum lprocfs_fields_flags {
152         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
153         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
154         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
155         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
156         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
157         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
158         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
159 };
160
161 struct lprocfs_stats {
162         unsigned int           ls_num;     /* # of counters */
163         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
164         spinlock_t             ls_lock;  /* Lock used only when there are
165                                           * no percpu stats areas */
166         struct lprocfs_percpu *ls_percpu[0];
167 };
168
169 static inline int opcode_offset(__u32 opc) {
170         if (opc < OST_LAST_OPC) {
171                  /* OST opcode */
172                 return (opc - OST_FIRST_OPC);
173         } else if (opc < MDS_LAST_OPC) {
174                 /* MDS opcode */
175                 return (opc - MDS_FIRST_OPC +
176                         (OST_LAST_OPC - OST_FIRST_OPC));
177         } else if (opc < LDLM_LAST_OPC) {
178                 /* LDLM Opcode */
179                 return (opc - LDLM_FIRST_OPC +
180                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
181                         (OST_LAST_OPC - OST_FIRST_OPC));
182         } else if (opc < MGS_LAST_OPC) {
183                 /* MGS Opcode */
184                 return (opc - MGS_FIRST_OPC +
185                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
186                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
187                         (OST_LAST_OPC - OST_FIRST_OPC));
188         } else if (opc < OBD_LAST_OPC) {
189                 /* OBD Ping */
190                 return (opc - OBD_FIRST_OPC +
191                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
192                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
193                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
194                         (OST_LAST_OPC - OST_FIRST_OPC));
195         } else if (opc < LLOG_LAST_OPC) {
196                 /* LLOG Opcode */
197                 return (opc - LLOG_FIRST_OPC +
198                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
199                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
200                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
201                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
202                         (OST_LAST_OPC - OST_FIRST_OPC));
203 } else if (opc < FLD_LAST_OPC) {
204                 /* FLD opcode */
205                 return (opc - FLD_FIRST_OPC +
206                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
207                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
208                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
209                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
210                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
211                         (OST_LAST_OPC - OST_FIRST_OPC));
212         } else if (opc < SEQ_LAST_OPC) {
213                 /* SEQ opcode */
214                 return (opc - SEQ_FIRST_OPC +
215                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
216                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
217                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
218                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
219                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
220                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
221                         (OST_LAST_OPC - OST_FIRST_OPC));
222         } else if (opc < SEC_LAST_OPC) {
223                 /* SEC opcode */
224                 return (opc - SEC_FIRST_OPC +
225                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
226                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
227                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
228                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
229                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
230                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
231                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
232                         (OST_LAST_OPC - OST_FIRST_OPC));
233         } else {
234                 /* Unknown Opcode */
235                 return -1;
236         }
237 }
238
239 #define LUSTRE_MAX_OPCODES ((LDLM_LAST_OPC - LDLM_FIRST_OPC)   + \
240                             (MDS_LAST_OPC - MDS_FIRST_OPC)     + \
241                             (OST_LAST_OPC - OST_FIRST_OPC)     + \
242                             (OBD_LAST_OPC - OBD_FIRST_OPC)     + \
243                             (FLD_LAST_OPC - FLD_FIRST_OPC)     + \
244                             (SEQ_LAST_OPC - SEQ_FIRST_OPC)     + \
245                             (MGS_LAST_OPC - MGS_FIRST_OPC)     + \
246                             (LLOG_LAST_OPC - LLOG_FIRST_OPC)   + \
247                             (SEC_LAST_OPC - SEC_FIRST_OPC))
248
249 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
250                            (EXTRA_LAST_OPC - EXTRA_FIRST_OPC))
251
252 enum {
253         PTLRPC_REQWAIT_CNTR = 0,
254         PTLRPC_REQQDEPTH_CNTR,
255         PTLRPC_REQACTIVE_CNTR,
256         PTLRPC_TIMEOUT,
257         PTLRPC_REQBUF_AVAIL_CNTR,
258         PTLRPC_LAST_CNTR
259 };
260
261 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
262
263 enum {
264         LDLM_GLIMPSE_ENQUEUE = 0,
265         LDLM_PLAIN_ENQUEUE,
266         LDLM_EXTENT_ENQUEUE,
267         LDLM_FLOCK_ENQUEUE,
268         LDLM_IBITS_ENQUEUE,
269         MDS_REINT_CREATE,
270         MDS_REINT_LINK,
271         MDS_REINT_OPEN,
272         MDS_REINT_SETATTR,
273         MDS_REINT_RENAME,
274         MDS_REINT_UNLINK,
275         EXTRA_LAST_OPC
276 };
277
278 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
279 /* class_obd.c */
280 extern cfs_proc_dir_entry_t *proc_lustre_root;
281
282 struct obd_device;
283 struct file;
284 struct obd_histogram;
285
286 /* Days / hours / mins / seconds format */
287 struct dhms {
288         int d,h,m,s;
289 };
290 static inline void s2dhms(struct dhms *ts, time_t secs)
291 {
292         ts->d = secs / 86400;
293         secs = secs % 86400;
294         ts->h = secs / 3600;
295         secs = secs % 3600;
296         ts->m = secs / 60;
297         ts->s = secs % 60;
298 }
299 #define DHMS_FMT "%dd%dh%02dm%02ds"
300 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
301
302
303 #ifdef LPROCFS
304
305 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int type)
306 {
307         int rc = 0;
308
309         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
310                 if (type & LPROCFS_GET_NUM_CPU)
311                         rc = 1;
312                 if (type & LPROCFS_GET_SMP_ID)
313                         rc = 0;
314                 spin_lock(&stats->ls_lock);
315         } else {
316                 if (type & LPROCFS_GET_NUM_CPU)
317                         rc = num_possible_cpus();
318                 if (type & LPROCFS_GET_SMP_ID)
319                         rc = smp_processor_id();
320         }
321         return rc;
322 }
323
324 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats)
325 {
326         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
327                 spin_unlock(&stats->ls_lock);
328 }
329
330 /* Two optimized LPROCFS counter increment functions are provided:
331  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
332  *     lprocfs_counter_add(cntr) - use for multi-valued counters
333  * Counter data layout allows config flag, counter lock and the
334  * count itself to reside within a single cache line.
335  */
336
337 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
338                                 long amount);
339 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
340                                 long amount);
341
342 #define lprocfs_counter_incr(stats, idx) \
343         lprocfs_counter_add(stats, idx, 1)
344 #define lprocfs_counter_decr(stats, idx) \
345         lprocfs_counter_sub(stats, idx, 1)
346
347 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc, 
348                                  enum lprocfs_fields_flags field);
349 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, 
350                                             int idx, 
351                                             enum lprocfs_fields_flags field)
352 {
353         __u64 ret = 0;
354         int i;
355
356         LASSERT(stats != NULL);
357         for (i = 0; i < num_possible_cpus(); i++)
358                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
359                                            field);
360         return ret;
361 }
362
363 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
364                                                  enum lprocfs_stats_flags flags);
365 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
366 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
367 extern void lprocfs_init_ops_stats(int num_private_stats, 
368                                    struct lprocfs_stats *stats);
369 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
370                                    unsigned int num_private_stats);
371 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
372                                  unsigned conf, const char *name,
373                                  const char *units);
374 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
375 struct obd_export;
376 struct nid_stat;
377 extern int lprocfs_add_clear_entry(struct obd_device * obd,
378                                    cfs_proc_dir_entry_t *entry);
379 extern int lprocfs_exp_setup(struct obd_export *exp,
380                              lnet_nid_t *peer_nid, int *newnid);
381 extern int lprocfs_exp_cleanup(struct obd_export *exp);
382 extern int lprocfs_add_simple(struct proc_dir_entry *root,
383                               char *name, read_proc_t *read_proc,
384                               write_proc_t *write_proc, void *data);
385 extern struct proc_dir_entry *lprocfs_add_symlink(const char *name,
386                         struct proc_dir_entry *parent, const char *dest);
387 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
388 extern int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
389                                          unsigned long count, void *data);
390 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
391                                         int count, int *eof,  void *data);
392
393 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
394                                   struct lprocfs_stats *stats);
395
396 /* lprocfs_status.c */
397 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
398                             struct lprocfs_vars *var,
399                             void *data);
400
401 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
402                                                cfs_proc_dir_entry_t *parent,
403                                                struct lprocfs_vars *list,
404                                                void *data);
405
406 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
407 extern void lprocfs_remove_proc_entry(const char *name,
408                                       struct proc_dir_entry *parent);
409
410 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
411                                            const char *name);
412
413 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
414 extern int lprocfs_obd_cleanup(struct obd_device *obd);
415 extern int lprocfs_add_simple(struct proc_dir_entry *root, char *name,
416                               read_proc_t *read_proc, write_proc_t *write_proc,
417                               void *data);
418 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
419 extern struct file_operations lprocfs_evict_client_fops;
420
421 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name, 
422                               mode_t mode, struct file_operations *seq_fops,
423                               void *data);
424 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
425                                   mode_t mode, struct file_operations *seq_fops,
426                                   void *data);
427
428 /* Generic callbacks */
429
430 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
431                           int count, int *eof, void *data);
432 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
433                              int count, int *eof, void *data);
434 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
435                              unsigned long count, void *data);
436 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
437                            int count, int *eof, void *data);
438 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
439                            unsigned long count, void *data);
440 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
441                            int count, int *eof, void *data);
442 extern int lprocfs_rd_name(char *page, char **start, off_t off,
443                            int count, int *eof, void *data);
444 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
445                              int count, int *eof, void *data);
446 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
447                                   int count, int *eof, void *data);
448 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
449                                 int count, int *eof, void *data);
450 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
451                                     int count, int *eof, void *data);
452 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
453                                   int count, int *eof, void *data);
454 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
455                               int count, int *eof, void *data);
456 struct adaptive_timeout;
457 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
458                                   struct adaptive_timeout *at);
459 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
460                                int count, int *eof, void *data);
461 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
462                                unsigned long count, void *data);
463 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
464                                    unsigned long count, void *data);
465 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
466                            unsigned long count, void *data);
467
468 /* Statfs helpers */
469 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
470                               int count, int *eof, void *data);
471 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
472                                   int count, int *eof, void *data);
473 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
474                                  int count, int *eof, void *data);
475 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
476                                  int count, int *eof, void *data);
477 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
478                                  int count, int *eof, void *data);
479 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
480                                 int count, int *eof, void *data);
481 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
482                                  int count, int *eof, void *data);
483
484 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
485                                 int *val);
486 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
487                                      int *val, int mult);
488 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count, 
489                                     long val, int mult);
490 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
491                                     __u64 *val);
492 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
493                                          __u64 *val, int mult);
494 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
495 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
496 void lprocfs_oh_clear(struct obd_histogram *oh);
497 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
498
499 /* lprocfs_status.c: counter read/write functions */
500 extern int lprocfs_counter_read(char *page, char **start, off_t off,
501                                 int count, int *eof, void *data);
502 extern int lprocfs_counter_write(struct file *file, const char *buffer,
503                                  unsigned long count, void *data);
504
505 /* lprocfs_status.c: recovery status */
506 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
507                                    int count, int *eof, void *data);
508
509 extern int lprocfs_seq_release(struct inode *, struct file *);
510
511 /* in lprocfs_stat.c, to protect the private data for proc entries */
512 extern struct rw_semaphore _lprocfs_lock;
513 #define LPROCFS_ENTRY()           do {  \
514         down_read(&_lprocfs_lock);      \
515 } while(0)
516 #define LPROCFS_EXIT()            do {  \
517         up_read(&_lprocfs_lock);        \
518 } while(0)
519 #define LPROCFS_ENTRY_AND_CHECK(dp) do {        \
520         typecheck(struct proc_dir_entry *, dp); \
521         LPROCFS_ENTRY();                        \
522         if ((dp)->deleted) {                    \
523                 LPROCFS_EXIT();                 \
524                 return -ENODEV;                 \
525         }                                       \
526 } while(0)
527
528 /* You must use these macros when you want to refer to 
529  * the import in a client obd_device for a lprocfs entry */
530 #define LPROCFS_CLIMP_CHECK(obd) do {           \
531         typecheck(struct obd_device *, obd);    \
532         down_read(&(obd)->u.cli.cl_sem);        \
533         if ((obd)->u.cli.cl_import == NULL) {   \
534              up_read(&(obd)->u.cli.cl_sem);     \
535              return -ENODEV;                    \
536         }                                       \
537 } while(0)
538 #define LPROCFS_CLIMP_EXIT(obd)                 \
539         up_read(&(obd)->u.cli.cl_sem);
540
541
542 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only 
543   proc entries; otherwise, you will define name##_seq_write function also for 
544   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
545   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
546 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
547 static int name##_seq_open(struct inode *inode, struct file *file) {       \
548         struct proc_dir_entry *dp = PDE(inode);                            \
549         int rc;                                                            \
550         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
551         rc = single_open(file, name##_seq_show, dp->data);                 \
552         if (rc) {                                                          \
553                 LPROCFS_EXIT();                                            \
554                 return rc;                                                 \
555         }                                                                  \
556         return 0;                                                          \
557 }                                                                          \
558 struct file_operations name##_fops = {                                     \
559         .owner   = THIS_MODULE,                                            \
560         .open    = name##_seq_open,                                        \
561         .read    = seq_read,                                               \
562         .write   = custom_seq_write,                                       \
563         .llseek  = seq_lseek,                                              \
564         .release = lprocfs_seq_release,                                    \
565 }
566
567 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
568 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
569
570 /* lproc_ptlrpc.c */
571 struct ptlrpc_request;
572 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
573
574 /* lprocfs_status.c: read recovery max time bz13079 */
575 int lprocfs_obd_rd_recovery_maxtime(char *page, char **start, off_t off,
576                                     int count, int *eof, void *data);
577
578 /* lprocfs_status.c: write recovery max time bz13079 */
579 int lprocfs_obd_wr_recovery_maxtime(struct file *file, const char *buffer,
580                                     unsigned long count, void *data);
581 #else
582 /* LPROCFS is not defined */
583 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
584                                        int index, long amount) { return; }
585 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
586                                         int index) { return; }
587 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
588                                        int index, long amount) { return; }
589 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
590                                         int index, unsigned conf,
591                                         const char *name, const char *units)
592 { return; }
593
594 static inline __u64 lc_read_helper(struct lprocfs_counter *lc, 
595                                    enum lprocfs_fields_flags field) 
596 { return 0; }
597
598 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num,
599                                                         enum lprocfs_stats_flags flags)
600 { return NULL; }
601 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
602 { return; }
603 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
604 { return; }
605 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
606                                             const char *name,
607                                             struct lprocfs_stats *stats)
608 { return 0; }
609 static inline void lprocfs_init_ops_stats(int num_private_stats, 
610                                           struct lprocfs_stats *stats)
611 { return; }
612 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
613                                              unsigned int num_private_stats)
614 { return 0; }
615 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
616 { return; }
617
618 struct obd_export;
619 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
620 { return 0; }
621 static inline int lprocfs_exp_setup(struct obd_export *exp,
622                                     lnet_nid_t *peer_nid, int *newnid)
623 { return 0; }
624 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
625 { return 0; }
626 static inline int lprocfs_add_simple(struct proc_dir_entry *root,
627                                      char *name,
628                                      read_proc_t *read_proc,
629                                      write_proc_t *write_proc,
630                                      void *data)
631 {return 0; }
632 static inline struct proc_dir_entry *lprocfs_add_symlink(const char *name,
633                         struct proc_dir_entry *parent, const char *dest)
634 {return NULL; }
635 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
636 {}
637 static inline
638 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
639                                   unsigned long count, void *data)
640 {return count;}
641 static inline
642 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
643                                  int count, int *eof,  void *data)
644 {return count;}
645
646 static inline cfs_proc_dir_entry_t *
647 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
648                  struct lprocfs_vars *list, void *data) { return NULL; }
649 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
650                                    struct lprocfs_vars *var,
651                                    void *data) { return 0; }
652 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
653 static inline void lprocfs_remove_proc_entry(const char *name,
654                                              struct proc_dir_entry *parent) {};
655 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
656                                     const char *name) {return 0;}
657 static inline int lprocfs_obd_setup(struct obd_device *dev,
658                                     struct lprocfs_vars *list) { return 0; }
659 static inline int lprocfs_obd_cleanup(struct obd_device *dev)  { return 0; }
660 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
661                                  int count, int *eof, void *data) { return 0; }
662 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
663                                   int count, int *eof, void *data) { return 0; }
664 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
665                                   int count, int *eof, void *data) { return 0; }
666 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
667                                          int count, int *eof, void *data)
668 { return 0; }
669 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
670                                        int count, int *eof, void *data)
671 { return 0; }
672 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
673                                            int count, int *eof, void *data)
674 { return 0; }
675 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
676                                          int count, int *eof, void *data)
677 { return 0; }
678 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
679                                      int count, int *eof, void *data)
680 { return 0; }
681 struct adaptive_timeout;
682 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
683                                          struct adaptive_timeout *at)
684 { return 0; }
685 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
686                                       int count, int *eof, void *data)
687 { return 0; }
688 static inline int lprocfs_wr_timeouts(struct file *file, const char *buffer,
689                                       unsigned long count, void *data)
690 { return 0; }
691 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
692                                           unsigned long count, void *data)
693 { return 0; }
694 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
695                                   unsigned long count, void *data)
696 { return 0; }
697
698
699 /* Statfs helpers */
700 static inline
701 int lprocfs_rd_blksize(char *page, char **start, off_t off,
702                        int count, int *eof, void *data) { return 0; }
703 static inline
704 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
705                            int count, int *eof, void *data) { return 0; }
706 static inline
707 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
708                           int count, int *eof, void *data) { return 0; }
709 static inline
710 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
711                            int count, int *eof, void *data) { return 0; }
712 static inline
713 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
714                           int count, int *eof, void *data) { return 0; }
715 static inline
716 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
717                          int count, int *eof, void *data)  { return 0; }
718 static inline
719 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
720                           int count, int *eof, void *data) { return 0; }
721 static inline
722 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
723 static inline
724 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
725 static inline
726 void lprocfs_oh_clear(struct obd_histogram *oh) {}
727 static inline
728 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
729 static inline
730 int lprocfs_counter_read(char *page, char **start, off_t off,
731                          int count, int *eof, void *data) { return 0; }
732 static inline
733 int lprocfs_counter_write(struct file *file, const char *buffer,
734                           unsigned long count, void *data) { return 0; }
735
736 static inline
737 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx, 
738                                enum lprocfs_fields_flags field)
739 { return (__u64)0; }
740
741 #define LPROCFS_ENTRY()
742 #define LPROCFS_EXIT()
743 #define LPROCFS_ENTRY_AND_CHECK(dp)
744 #define LPROC_SEQ_FOPS_RO(name)
745 #define LPROC_SEQ_FOPS(name)
746
747 /* lproc_ptlrpc.c */
748 #define target_print_req NULL
749
750 #endif /* LPROCFS */
751
752 #endif /* LPROCFS_SNMP_H */