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