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