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