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