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