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