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