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