Whamcloud - gitweb
LU-80 lov: large stripe count support
[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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * Copyright (c) 2011 Whamcloud, Inc.
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  *
39  * lustre/include/lprocfs_status.h
40  *
41  * Top level header file for LProc SNMP
42  *
43  * Author: Hariharan Thantry thantry@users.sourceforge.net
44  */
45 #ifndef _LPROCFS_SNMP_H
46 #define _LPROCFS_SNMP_H
47
48 #if defined(__linux__)
49 #include <linux/lprocfs_status.h>
50 #elif defined(__APPLE__)
51 #include <darwin/lprocfs_status.h>
52 #elif defined(__WINNT__)
53 #include <winnt/lprocfs_status.h>
54 #else
55 #error Unsupported operating system.
56 #endif
57 #include <lustre/lustre_idl.h>
58 #include <libcfs/params_tree.h>
59
60 struct lprocfs_vars {
61         const char             *name;
62         cfs_read_proc_t        *read_fptr;
63         cfs_write_proc_t       *write_fptr;
64         void                   *data;
65         struct file_operations *fops;
66         /**
67          * /proc file mode.
68          */
69         mode_t                  proc_mode;
70 };
71
72 struct lprocfs_static_vars {
73         struct lprocfs_vars *module_vars;
74         struct lprocfs_vars *obd_vars;
75 };
76
77 /* if we find more consumers this could be generalized */
78 #define OBD_HIST_MAX 32
79 struct obd_histogram {
80         cfs_spinlock_t oh_lock;
81         unsigned long  oh_buckets[OBD_HIST_MAX];
82 };
83
84 enum {
85         BRW_R_PAGES = 0,
86         BRW_W_PAGES,
87         BRW_R_RPC_HIST,
88         BRW_W_RPC_HIST,
89         BRW_R_IO_TIME,
90         BRW_W_IO_TIME,
91         BRW_R_DISCONT_PAGES,
92         BRW_W_DISCONT_PAGES,
93         BRW_R_DISCONT_BLOCKS,
94         BRW_W_DISCONT_BLOCKS,
95         BRW_R_DISK_IOSIZE,
96         BRW_W_DISK_IOSIZE,
97         BRW_R_DIO_FRAGS,
98         BRW_W_DIO_FRAGS,
99         BRW_LAST,
100 };
101
102 struct brw_stats {
103         struct obd_histogram hist[BRW_LAST];
104 };
105
106
107 /* An lprocfs counter can be configured using the enum bit masks below.
108  *
109  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
110  * protects this counter from concurrent updates. If not specified,
111  * lprocfs an internal per-counter lock variable. External locks are
112  * not used to protect counter increments, but are used to protect
113  * counter readout and resets.
114  *
115  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
116  * (i.e. counter can be incremented by more than "1"). When specified,
117  * the counter maintains min, max and sum in addition to a simple
118  * invocation count. This allows averages to be be computed.
119  * If not specified, the counter is an increment-by-1 counter.
120  * min, max, sum, etc. are not maintained.
121  *
122  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
123  * squares (for multi-valued counter samples only). This allows
124  * external computation of standard deviation, but involves a 64-bit
125  * multiply per counter increment.
126  */
127
128 enum {
129         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
130         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
131         LPROCFS_CNTR_STDDEV       = 0x0004,
132
133         /* counter data type */
134         LPROCFS_TYPE_REGS         = 0x0100,
135         LPROCFS_TYPE_BYTES        = 0x0200,
136         LPROCFS_TYPE_PAGES        = 0x0400,
137         LPROCFS_TYPE_CYCLE        = 0x0800,
138 };
139
140 struct lprocfs_atomic {
141         cfs_atomic_t               la_entry;
142         cfs_atomic_t               la_exit;
143 };
144
145 #define LC_MIN_INIT ((~(__u64)0) >> 1)
146
147 struct lprocfs_counter {
148         struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
149         unsigned int           lc_config;
150         __s64                  lc_count;
151         __s64                  lc_sum;
152         __s64                  lc_sum_irq;
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 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
162         __s64                  pad;
163 #endif
164         struct lprocfs_counter lp_cntr[0];
165 };
166
167 #define LPROCFS_GET_NUM_CPU 0x0001
168 #define LPROCFS_GET_SMP_ID  0x0002
169
170 enum lprocfs_stats_flags {
171         LPROCFS_STATS_FLAG_NONE     = 0x0000, /* per cpu counter */
172         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
173                                                * area and need locking */
174 };
175
176 enum lprocfs_fields_flags {
177         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
178         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
179         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
180         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
181         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
182         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
183         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
184 };
185
186 struct lprocfs_stats {
187         unsigned int           ls_num;     /* # of counters */
188         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
189         cfs_spinlock_t         ls_lock;  /* Lock used only when there are
190                                           * no percpu stats areas */
191         struct lprocfs_percpu *ls_percpu[0];
192 };
193
194 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
195
196 /* Pack all opcodes down into a single monotonically increasing index */
197 static inline int opcode_offset(__u32 opc) {
198         if (opc < OST_LAST_OPC) {
199                  /* OST opcode */
200                 return (opc - OST_FIRST_OPC);
201         } else if (opc < MDS_LAST_OPC) {
202                 /* MDS opcode */
203                 return (opc - MDS_FIRST_OPC +
204                         OPC_RANGE(OST));
205         } else if (opc < LDLM_LAST_OPC) {
206                 /* LDLM Opcode */
207                 return (opc - LDLM_FIRST_OPC +
208                         OPC_RANGE(MDS) +
209                         OPC_RANGE(OST));
210         } else if (opc < MGS_LAST_OPC) {
211                 /* MGS Opcode */
212                 return (opc - MGS_FIRST_OPC +
213                         OPC_RANGE(LDLM) +
214                         OPC_RANGE(MDS) +
215                         OPC_RANGE(OST));
216         } else if (opc < OBD_LAST_OPC) {
217                 /* OBD Ping */
218                 return (opc - OBD_FIRST_OPC +
219                         OPC_RANGE(MGS) +
220                         OPC_RANGE(LDLM) +
221                         OPC_RANGE(MDS) +
222                         OPC_RANGE(OST));
223         } else if (opc < LLOG_LAST_OPC) {
224                 /* LLOG Opcode */
225                 return (opc - LLOG_FIRST_OPC +
226                         OPC_RANGE(OBD) +
227                         OPC_RANGE(MGS) +
228                         OPC_RANGE(LDLM) +
229                         OPC_RANGE(MDS) +
230                         OPC_RANGE(OST));
231         } else if (opc < QUOTA_LAST_OPC) {
232                 /* LQUOTA Opcode */
233                 return (opc - QUOTA_FIRST_OPC +
234                         OPC_RANGE(LLOG) +
235                         OPC_RANGE(OBD) +
236                         OPC_RANGE(MGS) +
237                         OPC_RANGE(LDLM) +
238                         OPC_RANGE(MDS) +
239                         OPC_RANGE(OST));
240         } else if (opc < SEQ_LAST_OPC) {
241                 /* SEQ opcode */
242                 return (opc - SEQ_FIRST_OPC +
243                         OPC_RANGE(QUOTA) +
244                         OPC_RANGE(LLOG) +
245                         OPC_RANGE(OBD) +
246                         OPC_RANGE(MGS) +
247                         OPC_RANGE(LDLM) +
248                         OPC_RANGE(MDS) +
249                         OPC_RANGE(OST));
250         } else if (opc < SEC_LAST_OPC) {
251                 /* SEC opcode */
252                 return (opc - SEC_FIRST_OPC +
253                         OPC_RANGE(SEQ) +
254                         OPC_RANGE(QUOTA) +
255                         OPC_RANGE(LLOG) +
256                         OPC_RANGE(OBD) +
257                         OPC_RANGE(MGS) +
258                         OPC_RANGE(LDLM) +
259                         OPC_RANGE(MDS) +
260                         OPC_RANGE(OST));
261         } else if (opc < FLD_LAST_OPC) {
262                 /* FLD opcode */
263                  return (opc - FLD_FIRST_OPC +
264                         OPC_RANGE(SEC) +
265                         OPC_RANGE(SEQ) +
266                         OPC_RANGE(QUOTA) +
267                         OPC_RANGE(LLOG) +
268                         OPC_RANGE(OBD) +
269                         OPC_RANGE(MGS) +
270                         OPC_RANGE(LDLM) +
271                         OPC_RANGE(MDS) +
272                         OPC_RANGE(OST));
273         } else {
274                 /* Unknown Opcode */
275                 return -1;
276         }
277 }
278
279
280 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
281                             OPC_RANGE(MDS)  + \
282                             OPC_RANGE(LDLM) + \
283                             OPC_RANGE(MGS)  + \
284                             OPC_RANGE(OBD)  + \
285                             OPC_RANGE(LLOG) + \
286                             OPC_RANGE(SEC)  + \
287                             OPC_RANGE(SEQ)  + \
288                             OPC_RANGE(SEC)  + \
289                             OPC_RANGE(FLD)  )
290
291 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
292                             OPC_RANGE(EXTRA))
293
294 enum {
295         PTLRPC_REQWAIT_CNTR = 0,
296         PTLRPC_REQQDEPTH_CNTR,
297         PTLRPC_REQACTIVE_CNTR,
298         PTLRPC_TIMEOUT,
299         PTLRPC_REQBUF_AVAIL_CNTR,
300         PTLRPC_LAST_CNTR
301 };
302
303 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
304
305 enum {
306         LDLM_GLIMPSE_ENQUEUE = 0,
307         LDLM_PLAIN_ENQUEUE,
308         LDLM_EXTENT_ENQUEUE,
309         LDLM_FLOCK_ENQUEUE,
310         LDLM_IBITS_ENQUEUE,
311         MDS_REINT_SETATTR,
312         MDS_REINT_CREATE,
313         MDS_REINT_LINK,
314         MDS_REINT_UNLINK,
315         MDS_REINT_RENAME,
316         MDS_REINT_OPEN,
317         MDS_REINT_SETXATTR,
318         BRW_READ_BYTES,
319         BRW_WRITE_BYTES,
320         EXTRA_LAST_OPC
321 };
322
323 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
324 /* class_obd.c */
325 extern cfs_proc_dir_entry_t *proc_lustre_root;
326
327 struct obd_device;
328 struct obd_histogram;
329
330 /* Days / hours / mins / seconds format */
331 struct dhms {
332         int d,h,m,s;
333 };
334 static inline void s2dhms(struct dhms *ts, time_t secs)
335 {
336         ts->d = secs / 86400;
337         secs = secs % 86400;
338         ts->h = secs / 3600;
339         secs = secs % 3600;
340         ts->m = secs / 60;
341         ts->s = secs % 60;
342 }
343 #define DHMS_FMT "%dd%dh%02dm%02ds"
344 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
345
346
347 #ifdef LPROCFS
348
349 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int opc)
350 {
351         switch (opc) {
352         default:
353                 LBUG();
354
355         case LPROCFS_GET_SMP_ID:
356                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
357                         cfs_spin_lock(&stats->ls_lock);
358                         return 0;
359                 } else {
360                         return cfs_get_cpu();
361                 }
362
363         case LPROCFS_GET_NUM_CPU:
364                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
365                         cfs_spin_lock(&stats->ls_lock);
366                         return 1;
367                 } else {
368                         return cfs_num_possible_cpus();
369                 }
370         }
371 }
372
373 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc)
374 {
375         switch (opc) {
376         default:
377                 LBUG();
378
379         case LPROCFS_GET_SMP_ID:
380                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
381                         cfs_spin_unlock(&stats->ls_lock);
382                 else
383                         cfs_put_cpu();
384                 return;
385
386         case LPROCFS_GET_NUM_CPU:
387                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
388                         cfs_spin_unlock(&stats->ls_lock);
389                 return;
390         }
391 }
392
393 /* Two optimized LPROCFS counter increment functions are provided:
394  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
395  *     lprocfs_counter_add(cntr) - use for multi-valued counters
396  * Counter data layout allows config flag, counter lock and the
397  * count itself to reside within a single cache line.
398  */
399
400 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
401                                 long amount);
402 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
403                                 long amount);
404
405 #define lprocfs_counter_incr(stats, idx) \
406         lprocfs_counter_add(stats, idx, 1)
407 #define lprocfs_counter_decr(stats, idx) \
408         lprocfs_counter_sub(stats, idx, 1)
409
410 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
411                                  enum lprocfs_fields_flags field);
412 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
413                                             int idx,
414                                             enum lprocfs_fields_flags field)
415 {
416         __u64 ret = 0;
417         int i;
418
419         LASSERT(stats != NULL);
420         for (i = 0; i < cfs_num_possible_cpus(); i++)
421                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
422                                            field);
423         return ret;
424 }
425
426 extern struct lprocfs_stats *
427 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
428 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
429 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
430 extern void lprocfs_init_ops_stats(int num_private_stats,
431                                    struct lprocfs_stats *stats);
432 extern void lprocfs_init_mps_stats(int num_private_stats,
433                                    struct lprocfs_stats *stats);
434 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
435 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
436                                    unsigned int num_private_stats);
437 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
438                                   unsigned int num_private_stats);
439 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
440                                  unsigned conf, const char *name,
441                                  const char *units);
442 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
443 extern void lprocfs_free_md_stats(struct obd_device *obddev);
444 struct obd_export;
445 struct nid_stat;
446 extern int lprocfs_add_clear_entry(struct obd_device * obd,
447                                    cfs_proc_dir_entry_t *entry);
448 extern int lprocfs_exp_setup(struct obd_export *exp,
449                              lnet_nid_t *peer_nid, int *newnid);
450 extern int lprocfs_exp_cleanup(struct obd_export *exp);
451 extern cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
452                                                 char *name,
453                                                 cfs_read_proc_t *read_proc,
454                                                 cfs_write_proc_t *write_proc,
455                                                 void *data,
456                                                 struct file_operations *fops);
457 extern struct proc_dir_entry *
458 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
459                     const char *format, ...);
460 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
461 extern int
462 lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
463                               unsigned long count, void *data);
464 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
465                                         int count, int *eof,  void *data);
466
467 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
468                                   struct lprocfs_stats *stats);
469
470 /* lprocfs_status.c */
471 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
472                             struct lprocfs_vars *var,
473                             void *data);
474
475 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
476                                               cfs_proc_dir_entry_t *parent,
477                                               struct lprocfs_vars *list,
478                                               void *data);
479
480 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
481 extern void lprocfs_remove_proc_entry(const char *name,
482                                       struct proc_dir_entry *parent);
483
484 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
485                                           const char *name);
486
487 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
488 extern int lprocfs_obd_cleanup(struct obd_device *obd);
489 extern struct file_operations lprocfs_evict_client_fops;
490
491 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
492                               mode_t mode, struct file_operations *seq_fops,
493                               void *data);
494 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
495                                   mode_t mode, struct file_operations *seq_fops,
496                                   void *data);
497
498 /* Generic callbacks */
499
500 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
501                           int count, int *eof, void *data);
502 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
503                              int count, int *eof, void *data);
504 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
505                              unsigned long count, void *data);
506 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
507                            int count, int *eof, void *data);
508 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
509                            unsigned long count, void *data);
510 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
511                            int count, int *eof, void *data);
512 extern int lprocfs_rd_name(char *page, char **start, off_t off,
513                            int count, int *eof, void *data);
514 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
515                              int count, int *eof, void *data);
516 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
517                                   int count, int *eof, void *data);
518 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
519                                 int count, int *eof, void *data);
520 extern int lprocfs_rd_import(char *page, char **start, off_t off, int count,
521                              int *eof, void *data);
522 extern int lprocfs_rd_state(char *page, char **start, off_t off, int count,
523                             int *eof, void *data);
524 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
525                                     int count, int *eof, void *data);
526 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
527                                   int count, int *eof, void *data);
528 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
529                               int count, int *eof, void *data);
530 struct adaptive_timeout;
531 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
532                                   struct adaptive_timeout *at);
533 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
534                                int count, int *eof, void *data);
535 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
536                                unsigned long count, void *data);
537 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
538                                    unsigned long count, void *data);
539 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
540                            unsigned long count, void *data);
541 extern int lprocfs_wr_import(struct file *file, const char *buffer,
542                              unsigned long count, void *data);
543 extern int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
544                                    int count, int *eof, void *data);
545 extern int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
546                                    unsigned long count, void *data);
547
548 /* Statfs helpers */
549 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
550                               int count, int *eof, void *data);
551 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
552                                   int count, int *eof, void *data);
553 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
554                                  int count, int *eof, void *data);
555 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
556                                  int count, int *eof, void *data);
557 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
558                                  int count, int *eof, void *data);
559 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
560                                 int count, int *eof, void *data);
561 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
562                                  int count, int *eof, void *data);
563
564 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
565                                 int *val);
566 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
567                                      int *val, int mult);
568 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
569                                     long val, int mult);
570 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
571                                     __u64 *val);
572 extern int lprocfs_write_frac_u64_helper(const char *buffer,
573                                          unsigned long count,
574                                          __u64 *val, int mult);
575 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
576 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
577 void lprocfs_oh_clear(struct obd_histogram *oh);
578 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
579
580 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
581                            struct lprocfs_counter *cnt);
582
583 /* lprocfs_status.c: recovery status */
584 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
585                                    int count, int *eof, void *data);
586
587 /* lprocfs_statuc.c: hash statistics */
588 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
589                         int count, int *eof, void *data);
590
591 /* lprocfs_status.c: IR factor */
592 int lprocfs_obd_rd_ir_factor(char *page, char **start, off_t off,
593                              int count, int *eof, void *data);
594 int lprocfs_obd_wr_ir_factor(struct file *file, const char *buffer,
595                              unsigned long count, void *data);
596
597 extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
598
599 /* You must use these macros when you want to refer to
600  * the import in a client obd_device for a lprocfs entry */
601 #define LPROCFS_CLIMP_CHECK(obd) do {           \
602         typecheck(struct obd_device *, obd);    \
603         cfs_down_read(&(obd)->u.cli.cl_sem);    \
604         if ((obd)->u.cli.cl_import == NULL) {   \
605              cfs_up_read(&(obd)->u.cli.cl_sem); \
606              return -ENODEV;                    \
607         }                                       \
608 } while(0)
609 #define LPROCFS_CLIMP_EXIT(obd)                 \
610         cfs_up_read(&(obd)->u.cli.cl_sem);
611
612
613 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
614   proc entries; otherwise, you will define name##_seq_write function also for
615   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
616   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
617 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
618 static int name##_seq_open(cfs_inode_t *inode, struct file *file) {        \
619         struct proc_dir_entry *dp = PDE(inode);                            \
620         int rc;                                                            \
621         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
622         rc = single_open(file, name##_seq_show, dp->data);                 \
623         if (rc) {                                                          \
624                 LPROCFS_EXIT();                                            \
625                 return rc;                                                 \
626         }                                                                  \
627         return 0;                                                          \
628 }                                                                          \
629 struct file_operations name##_fops = {                                     \
630         .owner   = THIS_MODULE,                                            \
631         .open    = name##_seq_open,                                        \
632         .read    = seq_read,                                               \
633         .write   = custom_seq_write,                                       \
634         .llseek  = seq_lseek,                                              \
635         .release = lprocfs_seq_release,                                    \
636 }
637
638 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
639 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
640
641 /* lproc_ptlrpc.c */
642 struct ptlrpc_request;
643 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
644
645 /* lproc_status.c */
646 int lprocfs_obd_rd_recovery_time_soft(char *page, char **start, off_t off,
647                                       int count, int *eof, void *data);
648 int lprocfs_obd_wr_recovery_time_soft(struct file *file,
649                                       const char *buffer,
650                                       unsigned long count, void *data);
651 int lprocfs_obd_rd_recovery_time_hard(char *page, char **start, off_t off,
652                                       int count, int *eof, void *data);
653 int lprocfs_obd_wr_recovery_time_hard(struct file *file,
654                                       const char *buffer,
655                                       unsigned long count, void *data);
656 int lprocfs_obd_rd_mntdev(char *page, char **start, off_t off,
657                           int count, int *eof, void *data);
658 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
659                                      int count, int *eof, void *data);
660 int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer,
661                                      unsigned long count, void *data);
662 int lprocfs_target_rd_instance(char *page, char **start, off_t off,
663                                int count, int *eof, void *data);
664
665 /* all quota proc functions */
666 extern int lprocfs_quota_rd_bunit(char *page, char **start,
667                                   off_t off, int count,
668                                   int *eof, void *data);
669 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
670                                   unsigned long count, void *data);
671 extern int lprocfs_quota_rd_btune(char *page, char **start,
672                                   off_t off, int count,
673                                   int *eof, void *data);
674 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
675                                   unsigned long count, void *data);
676 extern int lprocfs_quota_rd_iunit(char *page, char **start,
677                                   off_t off, int count,
678                                   int *eof, void *data);
679 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
680                                   unsigned long count, void *data);
681 extern int lprocfs_quota_rd_itune(char *page, char **start,
682                                   off_t off, int count,
683                                   int *eof, void *data);
684 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
685                                   unsigned long count, void *data);
686 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
687                                  int *eof, void *data);
688 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
689                                  unsigned long count, void *data);
690 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
691                                            int count, int *eof, void *data);
692 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
693                                            const char *buffer,
694                                            unsigned long count, void *data);
695 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
696                                      int count, int *eof, void *data);
697 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
698                                      unsigned long count, void *data);
699 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
700                                       int count, int *eof, void *data);
701 extern int lprocfs_quota_wr_switch_qs(struct file *file,
702                                       const char *buffer,
703                                       unsigned long count, void *data);
704 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
705                                             int count, int *eof, void *data);
706 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
707                                             const char *buffer,
708                                             unsigned long count, void *data);
709 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
710                                         int count, int *eof, void *data);
711 extern int lprocfs_quota_wr_least_bunit(struct file *file,
712                                         const char *buffer,
713                                         unsigned long count, void *data);
714 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
715                                         int count, int *eof, void *data);
716 extern int lprocfs_quota_wr_least_iunit(struct file *file,
717                                         const char *buffer,
718                                         unsigned long count, void *data);
719 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
720                                       int count, int *eof, void *data);
721 extern int lprocfs_quota_wr_qs_factor(struct file *file,
722                                       const char *buffer,
723                                       unsigned long count, void *data);
724
725
726
727 #else
728 /* LPROCFS is not defined */
729
730
731
732 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
733                                        int index, long amount)
734 { return; }
735 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
736                                         int index)
737 { return; }
738 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
739                                        int index, long amount)
740 { return; }
741 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
742                                         int index)
743 { return; }
744 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
745                                         int index, unsigned conf,
746                                         const char *name, const char *units)
747 { return; }
748
749 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
750                                    enum lprocfs_fields_flags field)
751 { return 0; }
752
753 /* NB: we return !NULL to satisfy error checker */
754 static inline struct lprocfs_stats *
755 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
756 { return (struct lprocfs_stats *)1; }
757 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
758 { return; }
759 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
760 { return; }
761 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
762                                          const char *name,
763                                          struct lprocfs_stats *stats)
764 { return 0; }
765 static inline void lprocfs_init_ops_stats(int num_private_stats,
766                                           struct lprocfs_stats *stats)
767 { return; }
768 static inline void lprocfs_init_mps_stats(int num_private_stats,
769                                           struct lprocfs_stats *stats)
770 { return; }
771 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
772 { return; }
773 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
774                                           unsigned int num_private_stats)
775 { return 0; }
776 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
777                                          unsigned int num_private_stats)
778 { return 0; }
779 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
780 { return; }
781 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
782 { return; }
783
784 struct obd_export;
785 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
786 { return 0; }
787 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid,
788                                     int *newnid)
789 { return 0; }
790 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
791 { return 0; }
792 static inline cfs_proc_dir_entry_t *
793 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
794                    cfs_read_proc_t *read_proc, cfs_write_proc_t *write_proc,
795                    void *data, struct file_operations *fops)
796 {return 0; }
797 static inline struct proc_dir_entry *
798 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
799                     const char *format, ...)
800 {return NULL; }
801 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
802 { return; }
803 static inline
804 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
805                                   unsigned long count, void *data)
806 {return count;}
807 static inline
808 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
809                                  int count, int *eof,  void *data)
810 {return count;}
811
812 static inline cfs_proc_dir_entry_t *
813 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
814                  struct lprocfs_vars *list, void *data)
815 { return NULL; }
816 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
817                                    struct lprocfs_vars *var,
818                                    void *data)
819 { return 0; }
820 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root)
821 { return; }
822 static inline void lprocfs_remove_proc_entry(const char *name,
823                                              struct proc_dir_entry *parent)
824 { return; }
825 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
826                                                  const char *name)
827 { return 0; }
828 static inline int lprocfs_obd_setup(struct obd_device *dev,
829                                     struct lprocfs_vars *list)
830 { return 0; }
831 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
832 { return 0; }
833 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
834                                  int count, int *eof, void *data)
835 { return 0; }
836 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
837                                   int count, int *eof, void *data)
838 { return 0; }
839 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
840                                   int count, int *eof, void *data)
841 { return 0; }
842 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
843                                          int count, int *eof, void *data)
844 { return 0; }
845 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
846                                        int count, int *eof, void *data)
847 { return 0; }
848 static inline int lprocfs_rd_import(char *page, char **start, off_t off,
849                                     int count, int *eof, void *data)
850 { return 0; }
851 static inline int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
852                                           int count, int *eof, void *data)
853 { return 0; }
854 static inline int lprocfs_rd_state(char *page, char **start, off_t off,
855                                    int count, int *eof, void *data)
856 { return 0; }
857 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
858                                            int count, int *eof, void *data)
859 { return 0; }
860 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
861                                          int count, int *eof, void *data)
862 { return 0; }
863 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
864                                      int count, int *eof, void *data)
865 { return 0; }
866 struct adaptive_timeout;
867 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
868                                          struct adaptive_timeout *at)
869 { return 0; }
870 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
871                                       int count, int *eof, void *data)
872 { return 0; }
873 static inline int lprocfs_wr_timeouts(struct file *file,
874                                       const char *buffer,
875                                       unsigned long count, void *data)
876 { return 0; }
877 static inline int lprocfs_wr_evict_client(struct file *file,
878                                           const char *buffer,
879                                           unsigned long count, void *data)
880 { return 0; }
881 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
882                                   unsigned long count, void *data)
883 { return 0; }
884 static inline int lprocfs_wr_import(struct file *file, const char *buffer,
885                                     unsigned long count, void *data)
886 { return 0; }
887 static inline int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
888                                     unsigned long count, void *data)
889 { return 0; }
890
891 /* Statfs helpers */
892 static inline
893 int lprocfs_rd_blksize(char *page, char **start, off_t off,
894                        int count, int *eof, void *data)
895 { return 0; }
896 static inline
897 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
898                            int count, int *eof, void *data)
899 { return 0; }
900 static inline
901 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
902                           int count, int *eof, void *data)
903 { return 0; }
904 static inline
905 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
906                            int count, int *eof, void *data)
907 { return 0; }
908 static inline
909 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
910                           int count, int *eof, void *data)
911 { return 0; }
912 static inline
913 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
914                          int count, int *eof, void *data)
915 { return 0; }
916 static inline
917 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
918                           int count, int *eof, void *data)
919 { return 0; }
920 static inline
921 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
922 { return; }
923 static inline
924 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
925 { return; }
926 static inline
927 void lprocfs_oh_clear(struct obd_histogram *oh)
928 { return; }
929 static inline
930 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
931 { return 0; }
932 static inline
933 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
934                            struct lprocfs_counter *cnt)
935 { return; }
936 static inline
937 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
938                                enum lprocfs_fields_flags field)
939 { return (__u64)0; }
940
941 #define LPROC_SEQ_FOPS_RO(name)
942 #define LPROC_SEQ_FOPS(name)
943
944 /* lproc_ptlrpc.c */
945 #define target_print_req NULL
946
947 #endif /* LPROCFS */
948
949 #endif /* LPROCFS_SNMP_H */