staging/lustre/obd: remove unused lprocfs_exp_setup() and related functions
[firefly-linux-kernel-4.4.55.git] / drivers / staging / lustre / 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, Intel Corporation.
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 #include <linux/proc_fs.h>
46 #include <linux/debugfs.h>
47 #include <linux/seq_file.h>
48 #include <linux/spinlock.h>
49 #include <linux/types.h>
50
51 #include "lustre/lustre_idl.h"
52
53 struct lprocfs_vars {
54         const char              *name;
55         struct file_operations  *fops;
56         void                    *data;
57         /**
58          * /proc file mode.
59          */
60         umode_t                 proc_mode;
61 };
62
63 struct lprocfs_static_vars {
64         struct lprocfs_vars *obd_vars;
65         struct attribute_group *sysfs_vars;
66 };
67
68 /* if we find more consumers this could be generalized */
69 #define OBD_HIST_MAX 32
70 struct obd_histogram {
71         spinlock_t      oh_lock;
72         unsigned long   oh_buckets[OBD_HIST_MAX];
73 };
74
75 enum {
76         BRW_R_PAGES = 0,
77         BRW_W_PAGES,
78         BRW_R_RPC_HIST,
79         BRW_W_RPC_HIST,
80         BRW_R_IO_TIME,
81         BRW_W_IO_TIME,
82         BRW_R_DISCONT_PAGES,
83         BRW_W_DISCONT_PAGES,
84         BRW_R_DISCONT_BLOCKS,
85         BRW_W_DISCONT_BLOCKS,
86         BRW_R_DISK_IOSIZE,
87         BRW_W_DISK_IOSIZE,
88         BRW_R_DIO_FRAGS,
89         BRW_W_DIO_FRAGS,
90         BRW_LAST,
91 };
92
93 struct brw_stats {
94         struct obd_histogram hist[BRW_LAST];
95 };
96
97 enum {
98         RENAME_SAMEDIR_SIZE = 0,
99         RENAME_CROSSDIR_SRC_SIZE,
100         RENAME_CROSSDIR_TGT_SIZE,
101         RENAME_LAST,
102 };
103
104 struct rename_stats {
105         struct obd_histogram hist[RENAME_LAST];
106 };
107
108 /* An lprocfs counter can be configured using the enum bit masks below.
109  *
110  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
111  * protects this counter from concurrent updates. If not specified,
112  * lprocfs an internal per-counter lock variable. External locks are
113  * not used to protect counter increments, but are used to protect
114  * counter readout and resets.
115  *
116  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
117  * (i.e. counter can be incremented by more than "1"). When specified,
118  * the counter maintains min, max and sum in addition to a simple
119  * invocation count. This allows averages to be be computed.
120  * If not specified, the counter is an increment-by-1 counter.
121  * min, max, sum, etc. are not maintained.
122  *
123  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
124  * squares (for multi-valued counter samples only). This allows
125  * external computation of standard deviation, but involves a 64-bit
126  * multiply per counter increment.
127  */
128
129 enum {
130         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
131         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
132         LPROCFS_CNTR_STDDEV       = 0x0004,
133
134         /* counter data type */
135         LPROCFS_TYPE_REGS        = 0x0100,
136         LPROCFS_TYPE_BYTES      = 0x0200,
137         LPROCFS_TYPE_PAGES      = 0x0400,
138         LPROCFS_TYPE_CYCLE      = 0x0800,
139 };
140
141 #define LC_MIN_INIT ((~(__u64)0) >> 1)
142
143 struct lprocfs_counter_header {
144         unsigned int            lc_config;
145         const char              *lc_name;   /* must be static */
146         const char              *lc_units;  /* must be static */
147 };
148
149 struct lprocfs_counter {
150         __s64   lc_count;
151         __s64   lc_min;
152         __s64   lc_max;
153         __s64   lc_sumsquare;
154         /*
155          * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
156          * for irq context counter, i.e. stats with
157          * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
158          * lc_array_sum[1]
159          */
160         __s64   lc_array_sum[1];
161 };
162 #define lc_sum          lc_array_sum[0]
163 #define lc_sum_irq      lc_array_sum[1]
164
165 struct lprocfs_percpu {
166 #ifndef __GNUC__
167         __s64                   pad;
168 #endif
169         struct lprocfs_counter lp_cntr[0];
170 };
171
172 #define LPROCFS_GET_NUM_CPU 0x0001
173 #define LPROCFS_GET_SMP_ID  0x0002
174
175 enum lprocfs_stats_flags {
176         LPROCFS_STATS_FLAG_NONE     = 0x0000, /* per cpu counter */
177         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
178                                                * area and need locking */
179         LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
180 };
181
182 enum lprocfs_fields_flags {
183         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
184         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
185         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
186         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
187         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
188         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
189         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
190 };
191
192 struct lprocfs_stats {
193         /* # of counters */
194         unsigned short                  ls_num;
195         /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
196         unsigned short                  ls_biggest_alloc_num;
197         enum lprocfs_stats_flags        ls_flags;
198         /* Lock used when there are no percpu stats areas; For percpu stats,
199          * it is used to protect ls_biggest_alloc_num change */
200         spinlock_t                      ls_lock;
201
202         /* has ls_num of counter headers */
203         struct lprocfs_counter_header   *ls_cnt_header;
204         struct lprocfs_percpu           *ls_percpu[0];
205 };
206
207 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
208
209 /* Pack all opcodes down into a single monotonically increasing index */
210 static inline int opcode_offset(__u32 opc) {
211         if (opc < OST_LAST_OPC) {
212                  /* OST opcode */
213                 return (opc - OST_FIRST_OPC);
214         } else if (opc < MDS_LAST_OPC) {
215                 /* MDS opcode */
216                 return (opc - MDS_FIRST_OPC +
217                         OPC_RANGE(OST));
218         } else if (opc < LDLM_LAST_OPC) {
219                 /* LDLM Opcode */
220                 return (opc - LDLM_FIRST_OPC +
221                         OPC_RANGE(MDS) +
222                         OPC_RANGE(OST));
223         } else if (opc < MGS_LAST_OPC) {
224                 /* MGS Opcode */
225                 return (opc - MGS_FIRST_OPC +
226                         OPC_RANGE(LDLM) +
227                         OPC_RANGE(MDS) +
228                         OPC_RANGE(OST));
229         } else if (opc < OBD_LAST_OPC) {
230                 /* OBD Ping */
231                 return (opc - OBD_FIRST_OPC +
232                         OPC_RANGE(MGS) +
233                         OPC_RANGE(LDLM) +
234                         OPC_RANGE(MDS) +
235                         OPC_RANGE(OST));
236         } else if (opc < LLOG_LAST_OPC) {
237                 /* LLOG Opcode */
238                 return (opc - LLOG_FIRST_OPC +
239                         OPC_RANGE(OBD) +
240                         OPC_RANGE(MGS) +
241                         OPC_RANGE(LDLM) +
242                         OPC_RANGE(MDS) +
243                         OPC_RANGE(OST));
244         } else if (opc < QUOTA_LAST_OPC) {
245                 /* LQUOTA Opcode */
246                 return (opc - QUOTA_FIRST_OPC +
247                         OPC_RANGE(LLOG) +
248                         OPC_RANGE(OBD) +
249                         OPC_RANGE(MGS) +
250                         OPC_RANGE(LDLM) +
251                         OPC_RANGE(MDS) +
252                         OPC_RANGE(OST));
253         } else if (opc < SEQ_LAST_OPC) {
254                 /* SEQ opcode */
255                 return (opc - SEQ_FIRST_OPC +
256                         OPC_RANGE(QUOTA) +
257                         OPC_RANGE(LLOG) +
258                         OPC_RANGE(OBD) +
259                         OPC_RANGE(MGS) +
260                         OPC_RANGE(LDLM) +
261                         OPC_RANGE(MDS) +
262                         OPC_RANGE(OST));
263         } else if (opc < SEC_LAST_OPC) {
264                 /* SEC opcode */
265                 return (opc - SEC_FIRST_OPC +
266                         OPC_RANGE(SEQ) +
267                         OPC_RANGE(QUOTA) +
268                         OPC_RANGE(LLOG) +
269                         OPC_RANGE(OBD) +
270                         OPC_RANGE(MGS) +
271                         OPC_RANGE(LDLM) +
272                         OPC_RANGE(MDS) +
273                         OPC_RANGE(OST));
274         } else if (opc < FLD_LAST_OPC) {
275                 /* FLD opcode */
276                  return (opc - FLD_FIRST_OPC +
277                         OPC_RANGE(SEC) +
278                         OPC_RANGE(SEQ) +
279                         OPC_RANGE(QUOTA) +
280                         OPC_RANGE(LLOG) +
281                         OPC_RANGE(OBD) +
282                         OPC_RANGE(MGS) +
283                         OPC_RANGE(LDLM) +
284                         OPC_RANGE(MDS) +
285                         OPC_RANGE(OST));
286         } else if (opc < UPDATE_LAST_OPC) {
287                 /* update opcode */
288                 return (opc - UPDATE_FIRST_OPC +
289                         OPC_RANGE(FLD) +
290                         OPC_RANGE(SEC) +
291                         OPC_RANGE(SEQ) +
292                         OPC_RANGE(QUOTA) +
293                         OPC_RANGE(LLOG) +
294                         OPC_RANGE(OBD) +
295                         OPC_RANGE(MGS) +
296                         OPC_RANGE(LDLM) +
297                         OPC_RANGE(MDS) +
298                         OPC_RANGE(OST));
299         } else {
300                 /* Unknown Opcode */
301                 return -1;
302         }
303 }
304
305
306 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
307                             OPC_RANGE(MDS)  + \
308                             OPC_RANGE(LDLM) + \
309                             OPC_RANGE(MGS)  + \
310                             OPC_RANGE(OBD)  + \
311                             OPC_RANGE(LLOG) + \
312                             OPC_RANGE(SEC)  + \
313                             OPC_RANGE(SEQ)  + \
314                             OPC_RANGE(SEC)  + \
315                             OPC_RANGE(FLD)  + \
316                             OPC_RANGE(UPDATE))
317
318 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
319                             OPC_RANGE(EXTRA))
320
321 enum {
322         PTLRPC_REQWAIT_CNTR = 0,
323         PTLRPC_REQQDEPTH_CNTR,
324         PTLRPC_REQACTIVE_CNTR,
325         PTLRPC_TIMEOUT,
326         PTLRPC_REQBUF_AVAIL_CNTR,
327         PTLRPC_LAST_CNTR
328 };
329
330 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
331
332 enum {
333         LDLM_GLIMPSE_ENQUEUE = 0,
334         LDLM_PLAIN_ENQUEUE,
335         LDLM_EXTENT_ENQUEUE,
336         LDLM_FLOCK_ENQUEUE,
337         LDLM_IBITS_ENQUEUE,
338         MDS_REINT_SETATTR,
339         MDS_REINT_CREATE,
340         MDS_REINT_LINK,
341         MDS_REINT_UNLINK,
342         MDS_REINT_RENAME,
343         MDS_REINT_OPEN,
344         MDS_REINT_SETXATTR,
345         BRW_READ_BYTES,
346         BRW_WRITE_BYTES,
347         EXTRA_LAST_OPC
348 };
349
350 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
351 /* class_obd.c */
352 extern struct dentry *debugfs_lustre_root;
353 extern struct kobject *lustre_kobj;
354
355 struct obd_device;
356 struct obd_histogram;
357
358 /* Days / hours / mins / seconds format */
359 struct dhms {
360         int d, h, m, s;
361 };
362 static inline void s2dhms(struct dhms *ts, time_t secs)
363 {
364         ts->d = secs / 86400;
365         secs = secs % 86400;
366         ts->h = secs / 3600;
367         secs = secs % 3600;
368         ts->m = secs / 60;
369         ts->s = secs % 60;
370 }
371 #define DHMS_FMT "%dd%dh%02dm%02ds"
372 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
373
374 #define JOBSTATS_JOBID_VAR_MAX_LEN      20
375 #define JOBSTATS_DISABLE                "disable"
376 #define JOBSTATS_PROCNAME_UID           "procname_uid"
377 #define JOBSTATS_NODELOCAL              "nodelocal"
378
379 extern int lprocfs_write_frac_helper(const char __user *buffer,
380                                      unsigned long count, int *val, int mult);
381 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
382                                     long val, int mult);
383 #if defined (CONFIG_PROC_FS)
384
385 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
386                                    unsigned int cpuid);
387 /*
388  * \return value
389  *      < 0     : on error (only possible for opc as LPROCFS_GET_SMP_ID)
390  */
391 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int opc,
392                                      unsigned long *flags)
393 {
394         int             rc = 0;
395
396         switch (opc) {
397         default:
398                 LBUG();
399
400         case LPROCFS_GET_SMP_ID:
401                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
402                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
403                                 spin_lock_irqsave(&stats->ls_lock, *flags);
404                         else
405                                 spin_lock(&stats->ls_lock);
406                         return 0;
407                 } else {
408                         unsigned int cpuid = get_cpu();
409
410                         if (unlikely(stats->ls_percpu[cpuid] == NULL)) {
411                                 rc = lprocfs_stats_alloc_one(stats, cpuid);
412                                 if (rc < 0) {
413                                         put_cpu();
414                                         return rc;
415                                 }
416                         }
417                         return cpuid;
418                 }
419
420         case LPROCFS_GET_NUM_CPU:
421                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
422                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
423                                 spin_lock_irqsave(&stats->ls_lock, *flags);
424                         else
425                                 spin_lock(&stats->ls_lock);
426                         return 1;
427                 } else {
428                         return stats->ls_biggest_alloc_num;
429                 }
430         }
431 }
432
433 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc,
434                                         unsigned long *flags)
435 {
436         switch (opc) {
437         default:
438                 LBUG();
439
440         case LPROCFS_GET_SMP_ID:
441                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
442                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
443                                 spin_unlock_irqrestore(&stats->ls_lock,
444                                                            *flags);
445                         } else {
446                                 spin_unlock(&stats->ls_lock);
447                         }
448                 } else {
449                         put_cpu();
450                 }
451                 return;
452
453         case LPROCFS_GET_NUM_CPU:
454                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
455                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
456                                 spin_unlock_irqrestore(&stats->ls_lock,
457                                                            *flags);
458                         } else {
459                                 spin_unlock(&stats->ls_lock);
460                         }
461                 }
462                 return;
463         }
464 }
465
466 static inline unsigned int
467 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
468 {
469         unsigned int percpusize;
470
471         percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
472
473         /* irq safe stats need lc_array_sum[1] */
474         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
475                 percpusize += stats->ls_num * sizeof(__s64);
476
477         if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
478                 percpusize = L1_CACHE_ALIGN(percpusize);
479
480         return percpusize;
481 }
482
483 static inline struct lprocfs_counter *
484 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
485                           int index)
486 {
487         struct lprocfs_counter *cntr;
488
489         cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
490
491         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
492                 cntr = (void *)cntr + index * sizeof(__s64);
493
494         return cntr;
495 }
496
497 /* Two optimized LPROCFS counter increment functions are provided:
498  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
499  *     lprocfs_counter_add(cntr) - use for multi-valued counters
500  * Counter data layout allows config flag, counter lock and the
501  * count itself to reside within a single cache line.
502  */
503
504 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
505                                 long amount);
506 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
507                                 long amount);
508
509 #define lprocfs_counter_incr(stats, idx) \
510         lprocfs_counter_add(stats, idx, 1)
511 #define lprocfs_counter_decr(stats, idx) \
512         lprocfs_counter_sub(stats, idx, 1)
513
514 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
515                                  struct lprocfs_counter_header *header,
516                                  enum lprocfs_stats_flags flags,
517                                  enum lprocfs_fields_flags field);
518 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
519                                             int idx,
520                                             enum lprocfs_fields_flags field)
521 {
522         int           i;
523         unsigned int  num_cpu;
524         unsigned long flags     = 0;
525         __u64         ret       = 0;
526
527         LASSERT(stats != NULL);
528
529         num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
530         for (i = 0; i < num_cpu; i++) {
531                 if (stats->ls_percpu[i] == NULL)
532                         continue;
533                 ret += lprocfs_read_helper(
534                                 lprocfs_stats_counter_get(stats, i, idx),
535                                 &stats->ls_cnt_header[idx], stats->ls_flags,
536                                 field);
537         }
538         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
539         return ret;
540 }
541
542 extern struct lprocfs_stats *
543 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
544 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
545 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
546 extern void lprocfs_init_ops_stats(int num_private_stats,
547                                    struct lprocfs_stats *stats);
548 extern void lprocfs_init_mps_stats(int num_private_stats,
549                                    struct lprocfs_stats *stats);
550 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
551 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
552                                    unsigned int num_private_stats);
553 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
554                                   unsigned int num_private_stats);
555 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
556                                  unsigned conf, const char *name,
557                                  const char *units);
558 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
559 extern void lprocfs_free_md_stats(struct obd_device *obddev);
560 struct obd_export;
561 struct nid_stat;
562 extern int lprocfs_add_clear_entry(struct obd_device *obd,
563                                    struct proc_dir_entry *entry);
564 extern int lprocfs_exp_cleanup(struct obd_export *exp);
565 extern struct dentry *ldebugfs_add_simple(struct dentry *root,
566                                           char *name,
567                                           void *data,
568                                           struct file_operations *fops);
569 extern struct proc_dir_entry *lprocfs_add_simple(struct proc_dir_entry *root,
570                                                 char *name,
571                                                 void *data,
572                                                 struct file_operations *fops);
573 extern struct dentry *
574 ldebugfs_add_symlink(const char *name, struct dentry *parent,
575                     const char *format, ...);
576 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
577 extern int
578 lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
579                               unsigned long count, void *data);
580 extern int lprocfs_nid_stats_clear_read(struct seq_file *m, void *data);
581
582 extern int ldebugfs_register_stats(struct dentry *parent,
583                                    const char *name,
584                                    struct lprocfs_stats *stats);
585 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
586                                   struct lprocfs_stats *stats);
587
588 /* lprocfs_status.c */
589 extern int ldebugfs_add_vars(struct dentry *parent,
590                              struct lprocfs_vars *var,
591                              void *data);
592 extern int lprocfs_add_vars(struct proc_dir_entry *root,
593                             struct lprocfs_vars *var,
594                             void *data);
595
596 extern struct dentry *ldebugfs_register(const char *name,
597                                         struct dentry *parent,
598                                         struct lprocfs_vars *list,
599                                         void *data);
600 extern struct proc_dir_entry *lprocfs_register(const char *name,
601                                               struct proc_dir_entry *parent,
602                                               struct lprocfs_vars *list,
603                                               void *data);
604
605 extern void ldebugfs_remove(struct dentry **entryp);
606 extern void lprocfs_remove(struct proc_dir_entry **root);
607 extern void lprocfs_remove_proc_entry(const char *name,
608                                       struct proc_dir_entry *parent);
609
610 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list,
611                              struct attribute_group *attrs);
612 extern int lprocfs_obd_cleanup(struct obd_device *obd);
613
614 extern int ldebugfs_seq_create(struct dentry *parent,
615                                const char *name,
616                                umode_t mode,
617                                const struct file_operations *seq_fops,
618                                void *data);
619 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
620                               umode_t mode,
621                               const struct file_operations *seq_fops,
622                               void *data);
623 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
624                                   umode_t mode,
625                                   const struct file_operations *seq_fops,
626                                   void *data);
627
628 /* Generic callbacks */
629
630 extern int lprocfs_rd_u64(struct seq_file *m, void *data);
631 extern int lprocfs_rd_atomic(struct seq_file *m, void *data);
632 extern int lprocfs_wr_atomic(struct file *file, const char __user *buffer,
633                              unsigned long count, void *data);
634 extern int lprocfs_rd_uint(struct seq_file *m, void *data);
635 extern int lprocfs_wr_uint(struct file *file, const char __user *buffer,
636                            unsigned long count, void *data);
637 extern int lprocfs_rd_name(struct seq_file *m, void *data);
638 extern int lprocfs_rd_server_uuid(struct seq_file *m, void *data);
639 extern int lprocfs_rd_conn_uuid(struct seq_file *m, void *data);
640 extern int lprocfs_rd_import(struct seq_file *m, void *data);
641 extern int lprocfs_rd_state(struct seq_file *m, void *data);
642 extern int lprocfs_rd_connect_flags(struct seq_file *m, void *data);
643
644 struct adaptive_timeout;
645 extern int lprocfs_at_hist_helper(struct seq_file *m,
646                                   struct adaptive_timeout *at);
647 extern int lprocfs_rd_timeouts(struct seq_file *m, void *data);
648 extern int lprocfs_wr_timeouts(struct file *file, const char __user *buffer,
649                                unsigned long count, void *data);
650 extern int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
651                             size_t count, loff_t *off);
652 extern int lprocfs_wr_ping(struct file *file, const char __user *buffer,
653                            size_t count, loff_t *off);
654 extern int lprocfs_wr_import(struct file *file, const char __user *buffer,
655                       size_t count, loff_t *off);
656 extern int lprocfs_rd_pinger_recov(struct seq_file *m, void *n);
657 extern int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
658                                    size_t count, loff_t *off);
659
660 /* Statfs helpers */
661
662 extern int lprocfs_write_helper(const char __user *buffer, unsigned long count,
663                                 int *val);
664 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
665 extern int lprocfs_write_u64_helper(const char __user *buffer,
666                                 unsigned long count, __u64 *val);
667 extern int lprocfs_write_frac_u64_helper(const char *buffer,
668                                          unsigned long count,
669                                          __u64 *val, int mult);
670 extern char *lprocfs_find_named_value(const char *buffer, const char *name,
671                                       size_t *count);
672 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
673 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
674 void lprocfs_oh_clear(struct obd_histogram *oh);
675 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
676
677 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
678                            struct lprocfs_counter *cnt);
679
680 extern int lprocfs_single_release(struct inode *, struct file *);
681 extern int lprocfs_seq_release(struct inode *, struct file *);
682
683 /* You must use these macros when you want to refer to
684  * the import in a client obd_device for a lprocfs entry */
685 #define LPROCFS_CLIMP_CHECK(obd) do {      \
686         typecheck(struct obd_device *, obd);    \
687         down_read(&(obd)->u.cli.cl_sem);    \
688         if ((obd)->u.cli.cl_import == NULL) {   \
689              up_read(&(obd)->u.cli.cl_sem); \
690              return -ENODEV;                \
691         }                                      \
692 } while (0)
693 #define LPROCFS_CLIMP_EXIT(obd)          \
694         up_read(&(obd)->u.cli.cl_sem)
695
696
697 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
698   proc entries; otherwise, you will define name##_seq_write function also for
699   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
700   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
701 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                        \
702 static int name##_single_open(struct inode *inode, struct file *file)   \
703 {                                                                       \
704         return single_open(file, name##_seq_show,                       \
705                            inode->i_private ?: PDE_DATA(inode));        \
706 }                                                                       \
707 static struct file_operations name##_fops = {                           \
708         .owner   = THIS_MODULE,                                     \
709         .open    = name##_single_open,                               \
710         .read    = seq_read,                                           \
711         .write   = custom_seq_write,                                   \
712         .llseek  = seq_lseek,                                         \
713         .release = lprocfs_single_release,                               \
714 }
715
716 #define LPROC_SEQ_FOPS_RO(name)  __LPROC_SEQ_FOPS(name, NULL)
717 #define LPROC_SEQ_FOPS(name)        __LPROC_SEQ_FOPS(name, name##_seq_write)
718
719 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)                              \
720         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
721         {                                                               \
722                 return lprocfs_rd_##type(m, m->private);                \
723         }                                                               \
724         LPROC_SEQ_FOPS_RO(name##_##type)
725
726 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)                              \
727         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
728         {                                                               \
729                 return lprocfs_rd_##type(m, m->private);                \
730         }                                                               \
731         static ssize_t name##_##type##_seq_write(struct file *file,     \
732                         const char __user *buffer, size_t count,        \
733                                                 loff_t *off)            \
734         {                                                               \
735                 struct seq_file *seq = file->private_data;              \
736                 return lprocfs_wr_##type(file, buffer,                  \
737                                          count, seq->private);          \
738         }                                                               \
739         LPROC_SEQ_FOPS(name##_##type)
740
741 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)                              \
742         static ssize_t name##_##type##_write(struct file *file,         \
743                         const char __user *buffer, size_t count,        \
744                                                 loff_t *off)            \
745         {                                                               \
746                 return lprocfs_wr_##type(file, buffer, count, off);     \
747         }                                                               \
748         static int name##_##type##_open(struct inode *inode, struct file *file) \
749         {                                                               \
750                 return single_open(file, NULL,                          \
751                                    inode->i_private ?: PDE_DATA(inode));\
752         }                                                               \
753         static struct file_operations name##_##type##_fops = {  \
754                 .open   = name##_##type##_open,                         \
755                 .write  = name##_##type##_write,                        \
756                 .release = lprocfs_single_release,                      \
757         }
758
759 struct lustre_attr {
760         struct attribute attr;
761         ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
762                         char *buf);
763         ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
764                          const char *buf, size_t len);
765 };
766
767 #define LUSTRE_ATTR(name, mode, show, store) \
768 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
769
770 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
771 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
772
773 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
774                          char *buf);
775 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
776                           const char *buf, size_t len);
777
778 extern const struct sysfs_ops lustre_sysfs_ops;
779
780 /* lproc_ptlrpc.c */
781 struct ptlrpc_request;
782 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
783
784 /* lproc_status.c */
785 int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data);
786 int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer,
787                                      size_t count, loff_t *off);
788
789 /* all quota proc functions */
790 extern int lprocfs_quota_rd_bunit(char *page, char **start,
791                                   loff_t off, int count,
792                                   int *eof, void *data);
793 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
794                                   unsigned long count, void *data);
795 extern int lprocfs_quota_rd_btune(char *page, char **start,
796                                   loff_t off, int count,
797                                   int *eof, void *data);
798 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
799                                   unsigned long count, void *data);
800 extern int lprocfs_quota_rd_iunit(char *page, char **start,
801                                   loff_t off, int count,
802                                   int *eof, void *data);
803 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
804                                   unsigned long count, void *data);
805 extern int lprocfs_quota_rd_itune(char *page, char **start,
806                                   loff_t off, int count,
807                                   int *eof, void *data);
808 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
809                                   unsigned long count, void *data);
810 extern int lprocfs_quota_rd_type(char *page, char **start, loff_t off, int count,
811                                  int *eof, void *data);
812 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
813                                  unsigned long count, void *data);
814 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, loff_t off,
815                                            int count, int *eof, void *data);
816 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
817                                            const char *buffer,
818                                            unsigned long count, void *data);
819 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, loff_t off,
820                                      int count, int *eof, void *data);
821 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
822                                      unsigned long count, void *data);
823 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, loff_t off,
824                                       int count, int *eof, void *data);
825 extern int lprocfs_quota_wr_switch_qs(struct file *file,
826                                       const char *buffer,
827                                       unsigned long count, void *data);
828 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, loff_t off,
829                                             int count, int *eof, void *data);
830 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
831                                             const char *buffer,
832                                             unsigned long count, void *data);
833 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, loff_t off,
834                                         int count, int *eof, void *data);
835 extern int lprocfs_quota_wr_least_bunit(struct file *file,
836                                         const char *buffer,
837                                         unsigned long count, void *data);
838 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, loff_t off,
839                                         int count, int *eof, void *data);
840 extern int lprocfs_quota_wr_least_iunit(struct file *file,
841                                         const char *buffer,
842                                         unsigned long count, void *data);
843 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, loff_t off,
844                                       int count, int *eof, void *data);
845 extern int lprocfs_quota_wr_qs_factor(struct file *file,
846                                       const char *buffer,
847                                       unsigned long count, void *data);
848 #else
849 /* CONFIG_PROC_FS is not defined */
850
851 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
852                                        int index, long amount)
853 { return; }
854 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
855                                         int index)
856 { return; }
857 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
858                                        int index, long amount)
859 { return; }
860 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
861                                         int index)
862 { return; }
863 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
864                                         int index, unsigned conf,
865                                         const char *name, const char *units)
866 { return; }
867
868 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
869                                    enum lprocfs_fields_flags field)
870 { return 0; }
871
872 /* NB: we return !NULL to satisfy error checker */
873 static inline struct lprocfs_stats *
874 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
875 { return (struct lprocfs_stats *)1; }
876 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
877 { return; }
878 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
879 { return; }
880 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
881                                          const char *name,
882                                          struct lprocfs_stats *stats)
883 { return 0; }
884 static inline void lprocfs_init_ops_stats(int num_private_stats,
885                                           struct lprocfs_stats *stats)
886 { return; }
887 static inline void lprocfs_init_mps_stats(int num_private_stats,
888                                           struct lprocfs_stats *stats)
889 { return; }
890 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
891 { return; }
892 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
893                                           unsigned int num_private_stats)
894 { return 0; }
895 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
896                                          unsigned int num_private_stats)
897 { return 0; }
898 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
899 { return; }
900 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
901 { return; }
902
903 struct obd_export;
904 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
905 { return 0; }
906 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
907 { return 0; }
908 static inline struct proc_dir_entry *
909 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
910                    void *data, struct file_operations *fops)
911 {return 0; }
912 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
913 { return; }
914 static inline
915 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
916                                   unsigned long count, void *data)
917 {return count;}
918 static inline
919 int lprocfs_nid_stats_clear_read(struct seq_file *m, void *data)
920 { return 0; }
921
922 static inline struct proc_dir_entry *
923 lprocfs_register(const char *name, struct proc_dir_entry *parent,
924                  struct lprocfs_vars *list, void *data)
925 { return NULL; }
926 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
927                                    struct lprocfs_vars *var,
928                                    void *data)
929 { return 0; }
930 static inline void lprocfs_remove(struct proc_dir_entry **root)
931 { return; }
932 static inline void lprocfs_remove_proc_entry(const char *name,
933                                              struct proc_dir_entry *parent)
934 { return; }
935 static inline int lprocfs_obd_setup(struct obd_device *dev,
936                                     struct lprocfs_vars *list)
937 { return 0; }
938 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
939 { return 0; }
940 static inline int lprocfs_rd_u64(struct seq_file *m, void *data)
941 { return 0; }
942 static inline int lprocfs_rd_uuid(struct seq_file *m, void *data)
943 { return 0; }
944 static inline int lprocfs_rd_name(struct seq_file *m, void *data)
945 { return 0; }
946 static inline int lprocfs_rd_server_uuid(struct seq_file *m, void *data)
947 { return 0; }
948 static inline int lprocfs_rd_conn_uuid(struct seq_file *m, void *data)
949 { return 0; }
950 static inline int lprocfs_rd_import(struct seq_file *m, void *data)
951 { return 0; }
952 static inline int lprocfs_rd_pinger_recov(struct seq_file *m, void *n)
953 { return 0; }
954 static inline int lprocfs_rd_state(struct seq_file *m, void *data)
955 { return 0; }
956 static inline int lprocfs_rd_connect_flags(struct seq_file *m, void *data)
957 { return 0; }
958 static inline int lprocfs_rd_num_exports(struct seq_file *m, void *data)
959 { return 0; }
960 extern inline int lprocfs_rd_numrefs(struct seq_file *m, void *data)
961 { return 0; }
962 struct adaptive_timeout;
963 static inline int lprocfs_at_hist_helper(struct seq_file *m,
964                                          struct adaptive_timeout *at)
965 { return 0; }
966 static inline int lprocfs_rd_timeouts(struct seq_file *m, void *data)
967 { return 0; }
968 static inline int lprocfs_wr_timeouts(struct file *file,
969                                 const char __user *buffer,
970                                 unsigned long count, void *data)
971 { return 0; }
972 static inline int lprocfs_wr_evict_client(struct file *file,
973                                 const char __user *buffer,
974                                 size_t count, loff_t *off)
975 { return 0; }
976 static inline int lprocfs_wr_ping(struct file *file,
977                                 const char __user *buffer,
978                                 size_t count, loff_t *off)
979 { return 0; }
980 static inline int lprocfs_wr_import(struct file *file,
981                                 const char __user *buffer,
982                                 size_t count, loff_t *off)
983 { return 0; }
984 static inline int lprocfs_wr_pinger_recov(struct file *file,
985                                 const char __user *buffer,
986                                 size_t count, loff_t *off)
987 { return 0; }
988
989 /* Statfs helpers */
990 static inline
991 int lprocfs_rd_blksize(struct seq_file *m, void *data)
992 { return 0; }
993 static inline
994 int lprocfs_rd_kbytestotal(struct seq_file *m, void *data)
995 { return 0; }
996 static inline
997 int lprocfs_rd_kbytesfree(struct seq_file *m, void *data)
998 { return 0; }
999 static inline
1000 int lprocfs_rd_kbytesavail(struct seq_file *m, void *data)
1001 { return 0; }
1002 static inline
1003 int lprocfs_rd_filestotal(struct seq_file *m, void *data)
1004 { return 0; }
1005 static inline
1006 int lprocfs_rd_filesfree(struct seq_file *m, void *data)
1007 { return 0; }
1008 static inline
1009 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1010 { return; }
1011 static inline
1012 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1013 { return; }
1014 static inline
1015 void lprocfs_oh_clear(struct obd_histogram *oh)
1016 { return; }
1017 static inline
1018 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1019 { return 0; }
1020 static inline
1021 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1022                            struct lprocfs_counter *cnt)
1023 { return; }
1024 static inline
1025 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1026                                enum lprocfs_fields_flags field)
1027 { return (__u64)0; }
1028
1029 #define LPROC_SEQ_FOPS_RO(name)
1030 #define LPROC_SEQ_FOPS(name)
1031 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1032 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1033 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1034
1035 /* lproc_ptlrpc.c */
1036 #define target_print_req NULL
1037
1038 #endif /* CONFIG_PROC_FS */
1039
1040 #endif /* LPROCFS_SNMP_H */