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