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