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