Whamcloud - gitweb
LU-2237 tests: new test for re-recreating last_rcvd
[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         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 #define LC_MIN_INIT ((~(__u64)0) >> 1)
148
149 struct lprocfs_counter {
150         unsigned int           lc_config;
151         __s64                  lc_count;
152         __s64                  lc_sum;
153         __s64                  lc_sum_irq;
154         __s64                  lc_min;
155         __s64                  lc_max;
156         __s64                  lc_sumsquare;
157         const char            *lc_name;   /* must be static */
158         const char            *lc_units;  /* must be static */
159 };
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         unsigned short          ls_num; /* # of counters */
190         unsigned short          ls_biggest_alloc_num;
191                                         /* 1 + the highest slot index which has
192                                          * been allocated, the 0th entry is
193                                          * a statically intialized template */
194         int                     ls_flags; /* See LPROCFS_STATS_FLAG_* */
195         /* Lock used when there are no percpu stats areas; For percpu stats,
196          * it is used to protect ls_biggest_alloc_num change */
197         spinlock_t              ls_lock;
198         struct lprocfs_percpu   *ls_percpu[0];
199 };
200
201 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
202
203 /* Pack all opcodes down into a single monotonically increasing index */
204 static inline int opcode_offset(__u32 opc) {
205         if (opc < OST_LAST_OPC) {
206                  /* OST opcode */
207                 return (opc - OST_FIRST_OPC);
208         } else if (opc < MDS_LAST_OPC) {
209                 /* MDS opcode */
210                 return (opc - MDS_FIRST_OPC +
211                         OPC_RANGE(OST));
212         } else if (opc < LDLM_LAST_OPC) {
213                 /* LDLM Opcode */
214                 return (opc - LDLM_FIRST_OPC +
215                         OPC_RANGE(MDS) +
216                         OPC_RANGE(OST));
217         } else if (opc < MGS_LAST_OPC) {
218                 /* MGS Opcode */
219                 return (opc - MGS_FIRST_OPC +
220                         OPC_RANGE(LDLM) +
221                         OPC_RANGE(MDS) +
222                         OPC_RANGE(OST));
223         } else if (opc < OBD_LAST_OPC) {
224                 /* OBD Ping */
225                 return (opc - OBD_FIRST_OPC +
226                         OPC_RANGE(MGS) +
227                         OPC_RANGE(LDLM) +
228                         OPC_RANGE(MDS) +
229                         OPC_RANGE(OST));
230         } else if (opc < LLOG_LAST_OPC) {
231                 /* LLOG Opcode */
232                 return (opc - LLOG_FIRST_OPC +
233                         OPC_RANGE(OBD) +
234                         OPC_RANGE(MGS) +
235                         OPC_RANGE(LDLM) +
236                         OPC_RANGE(MDS) +
237                         OPC_RANGE(OST));
238         } else if (opc < QUOTA_LAST_OPC) {
239                 /* LQUOTA Opcode */
240                 return (opc - QUOTA_FIRST_OPC +
241                         OPC_RANGE(LLOG) +
242                         OPC_RANGE(OBD) +
243                         OPC_RANGE(MGS) +
244                         OPC_RANGE(LDLM) +
245                         OPC_RANGE(MDS) +
246                         OPC_RANGE(OST));
247         } else if (opc < SEQ_LAST_OPC) {
248                 /* SEQ opcode */
249                 return (opc - SEQ_FIRST_OPC +
250                         OPC_RANGE(QUOTA) +
251                         OPC_RANGE(LLOG) +
252                         OPC_RANGE(OBD) +
253                         OPC_RANGE(MGS) +
254                         OPC_RANGE(LDLM) +
255                         OPC_RANGE(MDS) +
256                         OPC_RANGE(OST));
257         } else if (opc < SEC_LAST_OPC) {
258                 /* SEC opcode */
259                 return (opc - SEC_FIRST_OPC +
260                         OPC_RANGE(SEQ) +
261                         OPC_RANGE(QUOTA) +
262                         OPC_RANGE(LLOG) +
263                         OPC_RANGE(OBD) +
264                         OPC_RANGE(MGS) +
265                         OPC_RANGE(LDLM) +
266                         OPC_RANGE(MDS) +
267                         OPC_RANGE(OST));
268         } else if (opc < FLD_LAST_OPC) {
269                 /* FLD opcode */
270                  return (opc - FLD_FIRST_OPC +
271                         OPC_RANGE(SEC) +
272                         OPC_RANGE(SEQ) +
273                         OPC_RANGE(QUOTA) +
274                         OPC_RANGE(LLOG) +
275                         OPC_RANGE(OBD) +
276                         OPC_RANGE(MGS) +
277                         OPC_RANGE(LDLM) +
278                         OPC_RANGE(MDS) +
279                         OPC_RANGE(OST));
280         } else {
281                 /* Unknown Opcode */
282                 return -1;
283         }
284 }
285
286
287 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
288                             OPC_RANGE(MDS)  + \
289                             OPC_RANGE(LDLM) + \
290                             OPC_RANGE(MGS)  + \
291                             OPC_RANGE(OBD)  + \
292                             OPC_RANGE(LLOG) + \
293                             OPC_RANGE(SEC)  + \
294                             OPC_RANGE(SEQ)  + \
295                             OPC_RANGE(SEC)  + \
296                             OPC_RANGE(FLD)  )
297
298 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
299                             OPC_RANGE(EXTRA))
300
301 enum {
302         PTLRPC_REQWAIT_CNTR = 0,
303         PTLRPC_REQQDEPTH_CNTR,
304         PTLRPC_REQACTIVE_CNTR,
305         PTLRPC_TIMEOUT,
306         PTLRPC_REQBUF_AVAIL_CNTR,
307         PTLRPC_LAST_CNTR
308 };
309
310 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
311
312 enum {
313         LDLM_GLIMPSE_ENQUEUE = 0,
314         LDLM_PLAIN_ENQUEUE,
315         LDLM_EXTENT_ENQUEUE,
316         LDLM_FLOCK_ENQUEUE,
317         LDLM_IBITS_ENQUEUE,
318         MDS_REINT_SETATTR,
319         MDS_REINT_CREATE,
320         MDS_REINT_LINK,
321         MDS_REINT_UNLINK,
322         MDS_REINT_RENAME,
323         MDS_REINT_OPEN,
324         MDS_REINT_SETXATTR,
325         BRW_READ_BYTES,
326         BRW_WRITE_BYTES,
327         EXTRA_LAST_OPC
328 };
329
330 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
331 /* class_obd.c */
332 extern cfs_proc_dir_entry_t *proc_lustre_root;
333
334 struct obd_device;
335 struct obd_histogram;
336
337 /* Days / hours / mins / seconds format */
338 struct dhms {
339         int d,h,m,s;
340 };
341 static inline void s2dhms(struct dhms *ts, time_t secs)
342 {
343         ts->d = secs / 86400;
344         secs = secs % 86400;
345         ts->h = secs / 3600;
346         secs = secs % 3600;
347         ts->m = secs / 60;
348         ts->s = secs % 60;
349 }
350 #define DHMS_FMT "%dd%dh%02dm%02ds"
351 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
352
353 #define JOBSTATS_JOBID_VAR_MAX_LEN      20
354 #define JOBSTATS_DISABLE                "disable"
355 #define JOBSTATS_PROCNAME_UID           "procname_uid"
356
357 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
358
359 struct obd_job_stats {
360         cfs_hash_t        *ojs_hash;
361         cfs_list_t         ojs_list;
362         rwlock_t       ojs_lock; /* protect the obj_list */
363         cntr_init_callback ojs_cntr_init_fn;
364         int                ojs_cntr_num;
365         int                ojs_cleanup_interval;
366         time_t             ojs_last_cleanup;
367 };
368
369 #ifdef LPROCFS
370
371 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
372                                    unsigned int cpuid);
373 /*
374  * \return value
375  *      < 0     : on error (only possible for opc as LPROCFS_GET_SMP_ID)
376  */
377 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int opc,
378                                      unsigned long *flags)
379 {
380         int             rc = 0;
381         unsigned int    cpuid;
382
383         switch (opc) {
384         default:
385                 LBUG();
386
387         case LPROCFS_GET_SMP_ID:
388                 /* percpu counter stats */
389                 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0) {
390                         cpuid = cfs_get_cpu();
391
392                         if (unlikely(stats->ls_percpu[cpuid + 1] == NULL))
393                                 rc = lprocfs_stats_alloc_one(stats, cpuid + 1);
394                         return rc < 0 ? rc : cpuid + 1;
395                 }
396
397                 /* non-percpu counter stats */
398                 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
399                         spin_lock_irqsave(&stats->ls_lock, *flags);
400                 else
401                         spin_lock(&stats->ls_lock);
402                 return 0;
403
404         case LPROCFS_GET_NUM_CPU:
405                 /* percpu counter stats */
406                 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
407                         return stats->ls_biggest_alloc_num;
408
409                 /* non-percpu counter stats */
410                 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
411                         spin_lock_irqsave(&stats->ls_lock, *flags);
412                 else
413                         spin_lock(&stats->ls_lock);
414                 return 1;
415         }
416 }
417
418 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc,
419                                         unsigned long *flags)
420 {
421         switch (opc) {
422         default:
423                 LBUG();
424
425         case LPROCFS_GET_SMP_ID:
426                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
427                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
428                                 spin_unlock_irqrestore(&stats->ls_lock,
429                                                            *flags);
430                         } else {
431                                 spin_unlock(&stats->ls_lock);
432                         }
433                 } else {
434                         cfs_put_cpu();
435                 }
436                 return;
437
438         case LPROCFS_GET_NUM_CPU:
439                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
440                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
441                                 spin_unlock_irqrestore(&stats->ls_lock,
442                                                            *flags);
443                         } else {
444                                 spin_unlock(&stats->ls_lock);
445                         }
446                 }
447                 return;
448         }
449 }
450
451 /* Two optimized LPROCFS counter increment functions are provided:
452  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
453  *     lprocfs_counter_add(cntr) - use for multi-valued counters
454  * Counter data layout allows config flag, counter lock and the
455  * count itself to reside within a single cache line.
456  */
457
458 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
459                                 long amount);
460 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
461                                 long amount);
462
463 #define lprocfs_counter_incr(stats, idx) \
464         lprocfs_counter_add(stats, idx, 1)
465 #define lprocfs_counter_decr(stats, idx) \
466         lprocfs_counter_sub(stats, idx, 1)
467
468 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
469                                  enum lprocfs_fields_flags field);
470 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
471                                             int idx,
472                                             enum lprocfs_fields_flags field)
473 {
474         int           i;
475         unsigned int  num_cpu;
476         unsigned long flags     = 0;
477         __u64         ret       = 0;
478
479         LASSERT(stats != NULL);
480
481         num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
482         for (i = 0; i < num_cpu; i++) {
483                 if (stats->ls_percpu[i] == NULL)
484                         continue;
485                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
486                                            field);
487         }
488         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
489         return ret;
490 }
491
492 extern struct lprocfs_stats *
493 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
494 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
495 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
496 extern void lprocfs_init_ops_stats(int num_private_stats,
497                                    struct lprocfs_stats *stats);
498 extern void lprocfs_init_mps_stats(int num_private_stats,
499                                    struct lprocfs_stats *stats);
500 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
501 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
502                                    unsigned int num_private_stats);
503 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
504                                   unsigned int num_private_stats);
505 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
506                                  unsigned conf, const char *name,
507                                  const char *units);
508 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
509 extern void lprocfs_free_md_stats(struct obd_device *obddev);
510 struct obd_export;
511 struct nid_stat;
512 extern int lprocfs_add_clear_entry(struct obd_device * obd,
513                                    cfs_proc_dir_entry_t *entry);
514 extern int lprocfs_exp_setup(struct obd_export *exp,
515                              lnet_nid_t *peer_nid, int *newnid);
516 extern int lprocfs_exp_cleanup(struct obd_export *exp);
517 extern cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
518                                                 char *name,
519                                                 cfs_read_proc_t *read_proc,
520                                                 cfs_write_proc_t *write_proc,
521                                                 void *data,
522                                                 struct file_operations *fops);
523 extern struct proc_dir_entry *
524 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
525                     const char *format, ...);
526 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
527 extern int
528 lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
529                               unsigned long count, void *data);
530 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
531                                         int count, int *eof,  void *data);
532
533 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
534                                   struct lprocfs_stats *stats);
535
536 /* lprocfs_status.c */
537 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
538                             struct lprocfs_vars *var,
539                             void *data);
540
541 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
542                                               cfs_proc_dir_entry_t *parent,
543                                               struct lprocfs_vars *list,
544                                               void *data);
545
546 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
547 extern void lprocfs_remove_proc_entry(const char *name,
548                                       struct proc_dir_entry *parent);
549 extern void lprocfs_try_remove_proc_entry(const char *name,
550                                           struct proc_dir_entry *parent);
551
552 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
553                                           const char *name);
554
555 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
556 extern int lprocfs_obd_cleanup(struct obd_device *obd);
557 extern struct file_operations lprocfs_evict_client_fops;
558
559 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, const char *name,
560                               mode_t mode,
561                               const struct file_operations *seq_fops,
562                               void *data);
563 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
564                                   mode_t mode,
565                                   const struct file_operations *seq_fops,
566                                   void *data);
567
568 /* Generic callbacks */
569
570 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
571                           int count, int *eof, void *data);
572 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
573                              int count, int *eof, void *data);
574 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
575                              unsigned long count, void *data);
576 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
577                            int count, int *eof, void *data);
578 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
579                            unsigned long count, void *data);
580 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
581                            int count, int *eof, void *data);
582 extern int lprocfs_rd_name(char *page, char **start, off_t off,
583                            int count, int *eof, void *data);
584 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
585                                   int count, int *eof, void *data);
586 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
587                                 int count, int *eof, void *data);
588 extern int lprocfs_rd_import(char *page, char **start, off_t off, int count,
589                              int *eof, void *data);
590 extern int lprocfs_rd_state(char *page, char **start, off_t off, int count,
591                             int *eof, void *data);
592 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
593                                     int count, int *eof, void *data);
594 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
595                                   int count, int *eof, void *data);
596 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
597                               int count, int *eof, void *data);
598 struct adaptive_timeout;
599 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
600                                   struct adaptive_timeout *at);
601 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
602                                int count, int *eof, void *data);
603 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
604                                unsigned long count, void *data);
605 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
606                                    unsigned long count, void *data);
607 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
608                            unsigned long count, void *data);
609 extern int lprocfs_wr_import(struct file *file, const char *buffer,
610                              unsigned long count, void *data);
611 extern int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
612                                    int count, int *eof, void *data);
613 extern int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
614                                    unsigned long count, void *data);
615
616 /* Statfs helpers */
617 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
618                               int count, int *eof, void *data);
619 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
620                                   int count, int *eof, void *data);
621 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
622                                  int count, int *eof, void *data);
623 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
624                                  int count, int *eof, void *data);
625 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
626                                  int count, int *eof, void *data);
627 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
628                                 int count, int *eof, void *data);
629 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
630                                  int count, int *eof, void *data);
631 extern int lprocfs_osd_rd_blksize(char *page, char **start, off_t off,
632                                 int count, int *eof, void *data);
633 extern int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off,
634                                 int count, int *eof, void *data);
635 extern int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off,
636                                 int count, int *eof, void *data);
637 extern int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off,
638                                 int count, int *eof, void *data);
639 extern int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off,
640                                 int count, int *eof, void *data);
641 extern int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off,
642                                 int count, int *eof, void *data);
643
644
645 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
646                                 int *val);
647 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
648                                      int *val, int mult);
649 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
650                                     long val, int mult);
651 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
652                                     __u64 *val);
653 extern int lprocfs_write_frac_u64_helper(const char *buffer,
654                                          unsigned long count,
655                                          __u64 *val, int mult);
656 char *lprocfs_find_named_value(const char *buffer, const char *name,
657                                 unsigned long *count);
658 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
659 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
660 void lprocfs_oh_clear(struct obd_histogram *oh);
661 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
662
663 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
664                            struct lprocfs_counter *cnt);
665
666 /* lprocfs_status.c: recovery status */
667 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
668                                    int count, int *eof, void *data);
669
670 /* lprocfs_statuc.c: hash statistics */
671 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
672                         int count, int *eof, void *data);
673
674 /* lprocfs_status.c: IR factor */
675 int lprocfs_obd_rd_ir_factor(char *page, char **start, off_t off,
676                              int count, int *eof, void *data);
677 int lprocfs_obd_wr_ir_factor(struct file *file, const char *buffer,
678                              unsigned long count, void *data);
679
680 extern int lprocfs_single_release(cfs_inode_t *, struct file *);
681 extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
682
683 /* You must use these macros when you want to refer to
684  * the import in a client obd_device for a lprocfs entry */
685 #define LPROCFS_CLIMP_CHECK(obd) do {           \
686         typecheck(struct obd_device *, obd);    \
687         down_read(&(obd)->u.cli.cl_sem);    \
688         if ((obd)->u.cli.cl_import == NULL) {   \
689              up_read(&(obd)->u.cli.cl_sem); \
690              return -ENODEV;                    \
691         }                                       \
692 } while(0)
693 #define LPROCFS_CLIMP_EXIT(obd)                 \
694         up_read(&(obd)->u.cli.cl_sem);
695
696
697 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
698   proc entries; otherwise, you will define name##_seq_write function also for
699   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
700   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
701 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
702 static int name##_single_open(cfs_inode_t *inode, struct file *file) {     \
703         struct proc_dir_entry *dp = PDE(inode);                            \
704         int rc;                                                            \
705         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
706         rc = single_open(file, name##_seq_show, dp->data);                 \
707         if (rc) {                                                          \
708                 LPROCFS_EXIT();                                            \
709                 return rc;                                                 \
710         }                                                                  \
711         return 0;                                                          \
712 }                                                                          \
713 struct file_operations name##_fops = {                                     \
714         .owner   = THIS_MODULE,                                            \
715         .open    = name##_single_open,                                     \
716         .read    = seq_read,                                               \
717         .write   = custom_seq_write,                                       \
718         .llseek  = seq_lseek,                                              \
719         .release = lprocfs_single_release,                                 \
720 }
721
722 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
723 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
724
725 /* lprocfs_jobstats.c */
726 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
727                           int event, long amount);
728 void lprocfs_job_stats_fini(struct obd_device *obd);
729 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
730                            cntr_init_callback fn);
731 int lprocfs_rd_job_interval(char *page, char **start, off_t off,
732                             int count, int *eof, void *data);
733 int lprocfs_wr_job_interval(struct file *file, const char *buffer,
734                             unsigned long count, void *data);
735
736 /* lproc_ptlrpc.c */
737 struct ptlrpc_request;
738 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
739
740 /* lproc_status.c */
741 int lprocfs_obd_rd_recovery_time_soft(char *page, char **start, off_t off,
742                                       int count, int *eof, void *data);
743 int lprocfs_obd_wr_recovery_time_soft(struct file *file,
744                                       const char *buffer,
745                                       unsigned long count, void *data);
746 int lprocfs_obd_rd_recovery_time_hard(char *page, char **start, off_t off,
747                                       int count, int *eof, void *data);
748 int lprocfs_obd_wr_recovery_time_hard(struct file *file,
749                                       const char *buffer,
750                                       unsigned long count, void *data);
751 int lprocfs_obd_rd_mntdev(char *page, char **start, off_t off,
752                           int count, int *eof, void *data);
753 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
754                                      int count, int *eof, void *data);
755 int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer,
756                                      unsigned long count, void *data);
757 int lprocfs_target_rd_instance(char *page, char **start, off_t off,
758                                int count, int *eof, void *data);
759
760 /* all quota proc functions */
761 extern int lprocfs_quota_rd_bunit(char *page, char **start,
762                                   off_t off, int count,
763                                   int *eof, void *data);
764 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
765                                   unsigned long count, void *data);
766 extern int lprocfs_quota_rd_btune(char *page, char **start,
767                                   off_t off, int count,
768                                   int *eof, void *data);
769 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
770                                   unsigned long count, void *data);
771 extern int lprocfs_quota_rd_iunit(char *page, char **start,
772                                   off_t off, int count,
773                                   int *eof, void *data);
774 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
775                                   unsigned long count, void *data);
776 extern int lprocfs_quota_rd_itune(char *page, char **start,
777                                   off_t off, int count,
778                                   int *eof, void *data);
779 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
780                                   unsigned long count, void *data);
781 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
782                                  int *eof, void *data);
783 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
784                                  unsigned long count, void *data);
785 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
786                                            int count, int *eof, void *data);
787 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
788                                            const char *buffer,
789                                            unsigned long count, void *data);
790 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
791                                      int count, int *eof, void *data);
792 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
793                                      unsigned long count, void *data);
794 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
795                                       int count, int *eof, void *data);
796 extern int lprocfs_quota_wr_switch_qs(struct file *file,
797                                       const char *buffer,
798                                       unsigned long count, void *data);
799 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
800                                             int count, int *eof, void *data);
801 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
802                                             const char *buffer,
803                                             unsigned long count, void *data);
804 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
805                                         int count, int *eof, void *data);
806 extern int lprocfs_quota_wr_least_bunit(struct file *file,
807                                         const char *buffer,
808                                         unsigned long count, void *data);
809 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
810                                         int count, int *eof, void *data);
811 extern int lprocfs_quota_wr_least_iunit(struct file *file,
812                                         const char *buffer,
813                                         unsigned long count, void *data);
814 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
815                                       int count, int *eof, void *data);
816 extern int lprocfs_quota_wr_qs_factor(struct file *file,
817                                       const char *buffer,
818                                       unsigned long count, void *data);
819
820
821
822 #else
823 /* LPROCFS is not defined */
824
825 #define proc_lustre_root NULL
826
827 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
828                                        int index, long amount)
829 { return; }
830 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
831                                         int index)
832 { return; }
833 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
834                                        int index, long amount)
835 { return; }
836 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
837                                         int index)
838 { return; }
839 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
840                                         int index, unsigned conf,
841                                         const char *name, const char *units)
842 { return; }
843
844 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
845                                    enum lprocfs_fields_flags field)
846 { return 0; }
847
848 /* NB: we return !NULL to satisfy error checker */
849 static inline struct lprocfs_stats *
850 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
851 { return (struct lprocfs_stats *)1; }
852 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
853 { return; }
854 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
855 { return; }
856 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
857                                          const char *name,
858                                          struct lprocfs_stats *stats)
859 { return 0; }
860 static inline void lprocfs_init_ops_stats(int num_private_stats,
861                                           struct lprocfs_stats *stats)
862 { return; }
863 static inline void lprocfs_init_mps_stats(int num_private_stats,
864                                           struct lprocfs_stats *stats)
865 { return; }
866 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
867 { return; }
868 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
869                                           unsigned int num_private_stats)
870 { return 0; }
871 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
872                                          unsigned int num_private_stats)
873 { return 0; }
874 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
875 { return; }
876 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
877 { return; }
878
879 struct obd_export;
880 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
881 { return 0; }
882 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid,
883                                     int *newnid)
884 { return 0; }
885 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
886 { return 0; }
887 static inline cfs_proc_dir_entry_t *
888 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
889                    cfs_read_proc_t *read_proc, cfs_write_proc_t *write_proc,
890                    void *data, struct file_operations *fops)
891 {return 0; }
892 static inline struct proc_dir_entry *
893 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
894                     const char *format, ...)
895 {return NULL; }
896 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
897 { return; }
898 static inline
899 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
900                                   unsigned long count, void *data)
901 {return count;}
902 static inline
903 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
904                                  int count, int *eof,  void *data)
905 {return count;}
906
907 static inline cfs_proc_dir_entry_t *
908 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
909                  struct lprocfs_vars *list, void *data)
910 { return NULL; }
911 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
912                                    struct lprocfs_vars *var,
913                                    void *data)
914 { return 0; }
915 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root)
916 { return; }
917 static inline void lprocfs_remove_proc_entry(const char *name,
918                                              struct proc_dir_entry *parent)
919 { return; }
920 static inline void lprocfs_try_remove_proc_entry(const char *name,
921                                                  struct proc_dir_entry *parent)
922 { return; }
923 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
924                                                  const char *name)
925 { return 0; }
926 static inline int lprocfs_obd_setup(struct obd_device *dev,
927                                     struct lprocfs_vars *list)
928 { return 0; }
929 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
930 { return 0; }
931 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
932                                  int count, int *eof, void *data)
933 { return 0; }
934 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
935                                   int count, int *eof, void *data)
936 { return 0; }
937 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
938                                   int count, int *eof, void *data)
939 { return 0; }
940 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
941                                          int count, int *eof, void *data)
942 { return 0; }
943 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
944                                        int count, int *eof, void *data)
945 { return 0; }
946 static inline int lprocfs_rd_import(char *page, char **start, off_t off,
947                                     int count, int *eof, void *data)
948 { return 0; }
949 static inline int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
950                                           int count, int *eof, void *data)
951 { return 0; }
952 static inline int lprocfs_rd_state(char *page, char **start, off_t off,
953                                    int count, int *eof, void *data)
954 { return 0; }
955 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
956                                            int count, int *eof, void *data)
957 { return 0; }
958 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
959                                          int count, int *eof, void *data)
960 { return 0; }
961 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
962                                      int count, int *eof, void *data)
963 { return 0; }
964 struct adaptive_timeout;
965 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
966                                          struct adaptive_timeout *at)
967 { return 0; }
968 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
969                                       int count, int *eof, void *data)
970 { return 0; }
971 static inline int lprocfs_wr_timeouts(struct file *file,
972                                       const char *buffer,
973                                       unsigned long count, void *data)
974 { return 0; }
975 static inline int lprocfs_wr_evict_client(struct file *file,
976                                           const char *buffer,
977                                           unsigned long count, void *data)
978 { return 0; }
979 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
980                                   unsigned long count, void *data)
981 { return 0; }
982 static inline int lprocfs_wr_import(struct file *file, const char *buffer,
983                                     unsigned long count, void *data)
984 { return 0; }
985 static inline int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
986                                     unsigned long count, void *data)
987 { return 0; }
988
989 /* Statfs helpers */
990 static inline
991 int lprocfs_rd_blksize(char *page, char **start, off_t off,
992                        int count, int *eof, void *data)
993 { return 0; }
994 static inline
995 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
996                            int count, int *eof, void *data)
997 { return 0; }
998 static inline
999 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
1000                           int count, int *eof, void *data)
1001 { return 0; }
1002 static inline
1003 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
1004                            int count, int *eof, void *data)
1005 { return 0; }
1006 static inline
1007 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
1008                           int count, int *eof, void *data)
1009 { return 0; }
1010 static inline
1011 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
1012                          int count, int *eof, void *data)
1013 { return 0; }
1014 static inline
1015 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
1016                           int count, int *eof, void *data)
1017 { return 0; }
1018 static inline
1019 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1020 { return; }
1021 static inline
1022 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1023 { return; }
1024 static inline
1025 void lprocfs_oh_clear(struct obd_histogram *oh)
1026 { return; }
1027 static inline
1028 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1029 { return 0; }
1030 static inline
1031 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1032                            struct lprocfs_counter *cnt)
1033 { return; }
1034 static inline
1035 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1036                                enum lprocfs_fields_flags field)
1037 { return (__u64)0; }
1038
1039 #define LPROC_SEQ_FOPS_RO(name)
1040 #define LPROC_SEQ_FOPS(name)
1041
1042 /* lprocfs_jobstats.c */
1043 static inline
1044 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1045                           long amount)
1046 { return 0; }
1047 static inline
1048 void lprocfs_job_stats_fini(struct obd_device *obd)
1049 { return; }
1050 static inline
1051 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1052                            cntr_init_callback fn)
1053 { return 0; }
1054
1055
1056 /* lproc_ptlrpc.c */
1057 #define target_print_req NULL
1058
1059 #endif /* LPROCFS */
1060
1061 #endif /* LPROCFS_SNMP_H */