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