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