Whamcloud - gitweb
LU-14291 ptlrpc: format UPDATE messages in server-only code
[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/string_helpers.h>
47 #include <linux/seq_file.h>
48
49 #include <libcfs/libcfs.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 file_operations    *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 file_operations *fops);
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,
562                               const struct file_operations *seq_fops,
563                               void *data);
564 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
565                                   mode_t mode,
566                                   const struct file_operations *seq_fops,
567                                   void *data);
568
569 /* Generic callbacks */
570 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
571 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
572 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
573 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
574 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
575 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
576 #ifdef HAVE_SERVER_SUPPORT
577 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
578                          char *buf);
579 #endif
580 struct adaptive_timeout;
581 extern int lprocfs_at_hist_helper(struct seq_file *m,
582                                   struct adaptive_timeout *at);
583 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
584 extern ssize_t
585 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
586                            size_t count, loff_t *off);
587 #ifdef HAVE_SERVER_SUPPORT
588 extern ssize_t
589 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
590                                 size_t count, loff_t *off);
591 #endif
592 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
593                    const char *buffer, size_t count);
594 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
595                   char *buffer);
596
597 extern ssize_t
598 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
599                           size_t count, loff_t *off);
600 static inline ssize_t
601 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
602                          size_t count, loff_t *off)
603 {
604         return ldebugfs_import_seq_write(file, buffer, count, off);
605 }
606
607 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
608 extern ssize_t
609 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
610                                size_t count, loff_t *off);
611
612 int string_to_size(u64 *size, const char *buffer, size_t count);
613 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
614                     const char *defunit);
615 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
616 char *lprocfs_find_named_value(const char *buffer, const char *name,
617                                 size_t *count);
618 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
619 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
620 void lprocfs_oh_clear(struct obd_histogram *oh);
621 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
622
623 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
624                            struct lprocfs_counter *cnt);
625
626 #ifdef HAVE_SERVER_SUPPORT
627 /* lprocfs_status.c: recovery status */
628 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
629
630 /* lprocfs_status.c: hash statistics */
631 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
632
633 /* lprocfs_status.c: IR factor */
634 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
635                        char *buf);
636 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
637                         const char *buffer, size_t count);
638 #endif
639
640 /* lprocfs_status.c: dump pages on cksum error */
641 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
642 ssize_t
643 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
644                                 size_t count, loff_t *off);
645
646 extern int lprocfs_single_release(struct inode *, struct file *);
647 extern int lprocfs_seq_release(struct inode *, struct file *);
648
649 /* You must use these macros when you want to refer to
650  * the import in a client obd_device for a lprocfs entry
651  * Note that it is not safe to 'goto', 'return' or 'break'
652  * out of the body of this statement.  It *IS* safe to
653  * 'goto' the a label inside the statement, or to 'continue'
654  * to get out of the statement.
655  */
656
657 #define with_imp_locked_nested(__obd, __imp, __rc, __nest)              \
658         for (down_read_nested(&(__obd)->u.cli.cl_sem, __nest),          \
659              __imp = (__obd)->u.cli.cl_import,                          \
660              __rc = __imp ? 0 : -ENODEV;                                \
661              __imp ? 1 : (up_read(&(__obd)->u.cli.cl_sem), 0);          \
662              __imp = NULL)
663
664 #define with_imp_locked(__obd, __imp, __rc)     \
665         with_imp_locked_nested(__obd, __imp, __rc, 0)
666
667 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
668  * debugfs entries; otherwise, you will define name##_seq_write function also
669  * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
670  * Finally, call debugfs_create_file(filename, 0444, obd, data, &name#_fops);
671  */
672 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write)                     \
673 static int name##_single_open(struct inode *inode, struct file *file)   \
674 {                                                                       \
675         return single_open(file, name##_seq_show, inode->i_private);    \
676 }                                                                       \
677 static const struct file_operations name##_fops = {                     \
678         .owner   = THIS_MODULE,                                         \
679         .open    = name##_single_open,                                  \
680         .read    = seq_read,                                            \
681         .write   = custom_seq_write,                                    \
682         .llseek  = seq_lseek,                                           \
683         .release = single_release,                                      \
684 }
685
686 #define LDEBUGFS_SEQ_FOPS_RO(name)      __LDEBUGFS_SEQ_FOPS(name, NULL)
687 #define LDEBUGFS_SEQ_FOPS(name)         __LDEBUGFS_SEQ_FOPS(name, \
688                                                             name##_seq_write)
689
690 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type)                           \
691         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
692         {                                                               \
693                 if (!m->private)                                        \
694                         return -ENODEV;                                 \
695                 return lprocfs_##type##_seq_show(m, m->private);        \
696         }                                                               \
697         LDEBUGFS_SEQ_FOPS_RO(name##_##type)
698
699 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type)                           \
700         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
701         {                                                               \
702                 if (!m->private)                                        \
703                         return -ENODEV;                                 \
704                 return lprocfs_##type##_seq_show(m, m->private);        \
705         }                                                               \
706         static ssize_t name##_##type##_seq_write(struct file *file,     \
707                         const char __user *buffer, size_t count,        \
708                         loff_t *off)                                    \
709         {                                                               \
710                 struct seq_file *seq = file->private_data;              \
711                                                                         \
712                 if (!seq->private)                                      \
713                         return -ENODEV;                                 \
714                 return ldebugfs_##type##_seq_write(file, buffer, count, \
715                                                    seq->private);       \
716         }                                                               \
717         LDEBUGFS_SEQ_FOPS(name##_##type);
718
719 #define LDEBUGFS_FOPS_WR_ONLY(name, type)                               \
720         static ssize_t name##_##type##_write(struct file *file,         \
721                         const char __user *buffer, size_t count,        \
722                         loff_t *off)                                    \
723         {                                                               \
724                 return ldebugfs_##type##_seq_write(file, buffer, count, \
725                                                    off);                \
726         }                                                               \
727         static int name##_##type##_open(struct inode *inode,            \
728                                         struct file *file)              \
729         {                                                               \
730                 return single_open(file, NULL, inode->i_private);       \
731         }                                                               \
732         static const struct file_operations name##_##type##_fops = {    \
733                 .open    = name##_##type##_open,                        \
734                 .write   = name##_##type##_write,                       \
735                 .release = single_release,                              \
736         };
737
738 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
739  * proc entries; otherwise, you will define name##_seq_write function also for
740  * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
741  * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
742  */
743 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                        \
744 static int name##_single_open(struct inode *inode, struct file *file)   \
745 {                                                                       \
746         return single_open(file, name##_seq_show,                       \
747                            inode->i_private ? inode->i_private :        \
748                                               PDE_DATA(inode));         \
749 }                                                                       \
750 static const struct file_operations name##_fops = {                     \
751         .owner   = THIS_MODULE,                                         \
752         .open    = name##_single_open,                                  \
753         .read    = seq_read,                                            \
754         .write   = custom_seq_write,                                    \
755         .llseek  = seq_lseek,                                           \
756         .release = lprocfs_single_release,                              \
757 }
758
759 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
760 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
761
762 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)                              \
763         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
764         {                                                               \
765                 return lprocfs_##type##_seq_show(m, m->private);        \
766         }                                                               \
767         LPROC_SEQ_FOPS_RO(name##_##type)
768
769 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)                              \
770         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
771         {                                                               \
772                 return lprocfs_##type##_seq_show(m, m->private);        \
773         }                                                               \
774         static ssize_t name##_##type##_seq_write(struct file *file,     \
775                         const char __user *buffer, size_t count,        \
776                         loff_t *off)                                    \
777         {                                                               \
778                 struct seq_file *seq = file->private_data;              \
779                 return lprocfs_##type##_seq_write(file, buffer,         \
780                                                   count, seq->private); \
781         }                                                               \
782         LPROC_SEQ_FOPS(name##_##type);
783
784 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)                              \
785         static ssize_t name##_##type##_write(struct file *file,         \
786                         const char __user *buffer, size_t count,        \
787                         loff_t *off)                                    \
788         {                                                               \
789                 return lprocfs_##type##_seq_write(file, buffer, count, off);\
790         }                                                               \
791         static int name##_##type##_open(struct inode *inode, struct file *file)\
792         {                                                               \
793                 return single_open(file, NULL,                          \
794                                    inode->i_private ? inode->i_private : \
795                                    PDE_DATA(inode));                    \
796         }                                                               \
797         static const struct file_operations name##_##type##_fops = {    \
798                 .open    = name##_##type##_open,                        \
799                 .write   = name##_##type##_write,                       \
800                 .release = lprocfs_single_release,                      \
801         };
802
803 struct lustre_attr {
804         struct attribute attr;
805         ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
806                         char *buf);
807         ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
808                          const char *buf, size_t len);
809 };
810
811 #define LUSTRE_ATTR(name, mode, show, store) \
812 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
813
814 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
815 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
816 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
817
818 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
819                          char *buf);
820 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
821                           const char *buf, size_t len);
822
823 extern const struct sysfs_ops lustre_sysfs_ops;
824
825 /* lproc_ptlrpc.c */
826 struct ptlrpc_request;
827 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
828
829 #ifdef HAVE_SERVER_SUPPORT
830 /* lprocfs_jobstats.c */
831 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
832                           int event, long amount);
833 void lprocfs_job_stats_fini(struct obd_device *obd);
834 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
835                            cntr_init_callback fn);
836 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
837                                   char *buf);
838 ssize_t job_cleanup_interval_store(struct kobject *kobj,
839                                    struct attribute *attr,
840                                    const char *buffer, size_t count);
841 /* lproc_status_server.c */
842 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
843                                 char *buf);
844 ssize_t recovery_time_soft_store(struct kobject *kobj,
845                                  struct attribute *attr,
846                                  const char *buffer, size_t count);
847 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
848                                 char *buf);
849 ssize_t recovery_time_hard_store(struct kobject *kobj,
850                                  struct attribute *attr,
851                                  const char *buffer, size_t count);
852 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
853                       char *buf);
854 #endif
855 /* lproc_status.c */
856 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
857 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
858                                                 const char __user *buffer,
859                                                 size_t count, loff_t *off);
860 int lprocfs_obd_short_io_bytes_seq_show(struct seq_file *m, void *data);
861 ssize_t lprocfs_obd_short_io_bytes_seq_write(struct file *file,
862                                              const char __user *buffer,
863                                              size_t count, loff_t *off);
864 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
865                             char *buf);
866 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
867                              const char *buffer, size_t count);
868
869 struct root_squash_info;
870 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
871                            struct root_squash_info *squash, char *name);
872 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
873                              struct root_squash_info *squash, char *name);
874
875 #else /* !CONFIG_PROC_FS */
876
877 #define proc_lustre_root NULL
878
879 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
880                                        int index, long amount)
881 { return; }
882 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
883                                         int index)
884 { return; }
885 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
886                                        int index, long amount)
887 { return; }
888 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
889                                         int index)
890 { return; }
891 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
892                                         int index, unsigned conf,
893                                         const char *name, const char *units)
894 { return; }
895
896 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
897                                    enum lprocfs_fields_flags field)
898 { return 0; }
899
900 /* NB: we return !NULL to satisfy error checker */
901 static inline struct lprocfs_stats *
902 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
903 { return (struct lprocfs_stats *)1; }
904 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
905 { return; }
906 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
907 { return; }
908 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
909                                          const char *name,
910                                          struct lprocfs_stats *stats)
911 { return 0; }
912 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
913 { return; }
914 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
915                                           unsigned int num_stats)
916 { return 0; }
917 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
918                                          unsigned int num_private_stats)
919 { return 0; }
920 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
921 { return; }
922 static inline void lprocfs_free_md_stats(struct obd_device *obd)
923 { return; }
924
925 struct obd_export;
926 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
927 { return 0; }
928 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
929 { return; }
930 #ifdef HAVE_SERVER_SUPPORT
931 static inline
932 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
933                                     const char __user *buffer,
934                                     size_t count, loff_t *off)
935 {return 0;}
936 static inline
937 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
938 {return 0;}
939 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
940 { return 0; }
941 #endif
942 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
943 { return 0; }
944 static inline struct proc_dir_entry *
945 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
946                    void *data, const struct file_operations *fops)
947 {return 0; }
948 static inline struct proc_dir_entry *
949 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
950                     const char *format, ...)
951 {return NULL; }
952 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
953                                    struct lprocfs_vars *var, void *data)
954 { return 0; }
955 static inline struct proc_dir_entry *
956 lprocfs_register(const char *name, struct proc_dir_entry *parent,
957                  struct lprocfs_vars *list, void *data)
958 { return NULL; }
959 static inline void lprocfs_remove(struct proc_dir_entry **root)
960 { return; }
961 static inline void lprocfs_remove_proc_entry(const char *name,
962                                              struct proc_dir_entry *parent)
963 { return; }
964 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
965 { return 0; }
966 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
967 { return 0; }
968 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
969 { return 0; }
970 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
971 { return 0; }
972 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
973 { return 0; }
974 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
975 { return 0; }
976 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
977 { return 0; }
978 #ifdef HAVE_SERVER_SUPPORT
979 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
980 { return 0; }
981 #endif
982 struct adaptive_timeout;
983 static inline int lprocfs_at_hist_helper(struct seq_file *m,
984                                          struct adaptive_timeout *at)
985 { return 0; }
986 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
987 { return 0; }
988 static inline ssize_t
989 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
990                            size_t count, loff_t *off)
991 { return 0; }
992 #ifdef HAVE_SERVER_SUPPORT
993 static inline ssize_t
994 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
995                                size_t count, loff_t *off)
996 { return 0; }
997 #endif
998 static inline ssize_t
999 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1000                        size_t count, loff_t *off)
1001 { return 0; }
1002 static inline ssize_t
1003 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
1004                           size_t count, loff_t *off)
1005 { return 0; }
1006 static inline ssize_t
1007 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1008                          size_t count, loff_t *off)
1009 { return 0; }
1010 static inline int
1011 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1012 { return 0; }
1013 static inline ssize_t
1014 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1015                                size_t count, loff_t *off)
1016 { return 0; }
1017
1018 /* Statfs helpers */
1019 static inline
1020 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1021 { return 0; }
1022 static inline
1023 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1024 { return 0; }
1025 static inline
1026 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1027 { return 0; }
1028 static inline
1029 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1030 { return 0; }
1031 static inline
1032 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1033 { return 0; }
1034 static inline
1035 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1036 { return 0; }
1037 static inline
1038 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1039 { return; }
1040 static inline
1041 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1042 { return; }
1043 static inline
1044 void lprocfs_oh_clear(struct obd_histogram *oh)
1045 { return; }
1046 static inline
1047 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1048 { return 0; }
1049 static inline
1050 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1051                            struct lprocfs_counter *cnt)
1052 { return; }
1053 static inline
1054 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1055                             enum lprocfs_fields_flags field)
1056 { return (__u64)0; }
1057
1058 #define LPROC_SEQ_FOPS_RO(name)
1059 #define LPROC_SEQ_FOPS(name)
1060 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1061 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1062 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1063
1064 /* lprocfs_jobstats.c */
1065 static inline
1066 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1067                           long amount)
1068 { return 0; }
1069 static inline
1070 void lprocfs_job_stats_fini(struct obd_device *obd)
1071 { return; }
1072 static inline
1073 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1074                            cntr_init_callback fn)
1075 { return 0; }
1076
1077
1078 /* lproc_ptlrpc.c */
1079 #define target_print_req NULL
1080
1081 #endif /* CONFIG_PROC_FS */
1082
1083 #endif /* LPROCFS_STATUS_H */