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