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