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