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