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