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