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