4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/include/lprocfs_status.h
33 * Top level header file for LProc
35 * Author: Hariharan Thantry thantry@users.sourceforge.net
37 #ifndef _LPROCFS_STATUS_H
38 #define _LPROCFS_STATUS_H
41 #include <linux/proc_fs.h>
42 #include <linux/debugfs.h>
43 #include <linux/rwsem.h>
44 #include <linux/spinlock.h>
45 #include <linux/string_helpers.h>
46 #include <linux/seq_file.h>
48 #include <libcfs/libcfs.h>
49 #include <libcfs/linux/linux-fs.h>
50 #include <uapi/linux/lustre/lustre_idl.h>
53 * Liuux 5.6 introduces proc_ops with v5.5-8862-gd56c0d45f0e2
54 * Now that proc and debugfs use separate operation vector types
55 * separate containers are also needed.
59 const struct proc_ops *fops;
61 /** /proc file mode. */
65 /** Provide a debugfs container */
66 struct ldebugfs_vars {
68 const struct file_operations *fops;
70 /** debugfs file mode. */
74 static inline unsigned int pct(unsigned long a, unsigned long b)
76 return b ? a * 100 / b : 0;
79 #define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))
80 #define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
83 * Append a space separated list of current set flags to str.
85 #define flag2str(port, flag) \
87 if ((port)->port##_##flag) { \
88 seq_printf(m, "%s" #flag, first ? "" : ", "); \
93 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
95 void obd_connect_data_seqprint(struct seq_file *m,
96 struct obd_connect_data *ocd);
98 /* if we find more consumers this could be generalized */
99 #define OBD_HIST_MAX 32
100 struct obd_histogram {
102 unsigned long oh_buckets[OBD_HIST_MAX];
114 BRW_R_DISCONT_BLOCKS,
115 BRW_W_DISCONT_BLOCKS,
124 struct obd_histogram hist[BRW_LAST];
128 RENAME_SAMEDIR_SIZE = 0,
129 RENAME_CROSSDIR_SRC_SIZE,
130 RENAME_CROSSDIR_TGT_SIZE,
134 struct rename_stats {
135 struct obd_histogram hist[RENAME_LAST];
138 /* An lprocfs counter can be configured using the enum bit masks below.
140 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
141 * protects this counter from concurrent updates. If not specified,
142 * lprocfs an internal per-counter lock variable. External locks are
143 * not used to protect counter increments, but are used to protect
144 * counter readout and resets.
146 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
147 * (i.e. counter can be incremented by more than "1"). When specified,
148 * the counter maintains min, max and sum in addition to a simple
149 * invocation count. This allows averages to be be computed.
150 * If not specified, the counter is an increment-by-1 counter.
151 * min, max, sum, etc. are not maintained.
153 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
154 * squares (for multi-valued counter samples only). This allows
155 * external computation of standard deviation, but involves a 64-bit
156 * multiply per counter increment.
160 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
161 LPROCFS_CNTR_AVGMINMAX = 0x0002,
162 LPROCFS_CNTR_STDDEV = 0x0004,
164 /* counter data type */
165 LPROCFS_TYPE_REQS = 0x0100,
166 LPROCFS_TYPE_BYTES = 0x0200,
167 LPROCFS_TYPE_PAGES = 0x0400,
168 LPROCFS_TYPE_USEC = 0x0800,
170 LPROCFS_TYPE_LATENCY = LPROCFS_TYPE_USEC |
171 LPROCFS_CNTR_AVGMINMAX |
173 LPROCFS_TYPE_BYTES_FULL = LPROCFS_TYPE_BYTES |
174 LPROCFS_CNTR_AVGMINMAX |
177 #define LC_MIN_INIT ((~(__u64)0) >> 1)
179 struct lprocfs_counter_header {
180 unsigned int lc_config;
181 const char *lc_name; /* must be static */
182 const char *lc_units; /* must be static */
185 struct lprocfs_counter {
191 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
192 * for irq context counter, i.e. stats with
193 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
196 __s64 lc_array_sum[1];
198 #define lc_sum lc_array_sum[0]
199 #define lc_sum_irq lc_array_sum[1]
201 struct lprocfs_percpu {
202 struct lprocfs_counter lp_cntr[0];
205 enum lprocfs_stats_lock_ops {
206 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
207 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
210 enum lprocfs_stats_flags {
211 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
212 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
213 * area and need locking */
214 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
217 enum lprocfs_fields_flags {
218 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
219 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
220 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
221 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
222 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
223 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
224 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
227 struct lprocfs_stats {
229 unsigned short ls_num;
230 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
231 unsigned short ls_biggest_alloc_num;
232 enum lprocfs_stats_flags ls_flags;
233 /* Lock used when there are no percpu stats areas; For percpu stats,
234 * it is used to protect ls_biggest_alloc_num change */
237 /* has ls_num of counter headers */
238 struct lprocfs_counter_header *ls_cnt_header;
239 struct lprocfs_percpu *ls_percpu[0];
242 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
244 /* Pack all opcodes down into a single monotonically increasing index */
245 static inline int opcode_offset(__u32 opc) {
246 if (opc < OST_LAST_OPC) {
248 return (opc - OST_FIRST_OPC);
249 } else if (opc < MDS_LAST_OPC) {
251 return (opc - MDS_FIRST_OPC +
253 } else if (opc < LDLM_LAST_OPC) {
255 return (opc - LDLM_FIRST_OPC +
258 } else if (opc < MGS_LAST_OPC) {
260 return (opc - MGS_FIRST_OPC +
264 } else if (opc < OBD_LAST_OPC) {
266 return (opc - OBD_FIRST_OPC +
271 } else if (opc < LLOG_LAST_OPC) {
273 return (opc - LLOG_FIRST_OPC +
279 } else if (opc < QUOTA_LAST_OPC) {
281 return (opc - QUOTA_FIRST_OPC +
288 } else if (opc < SEQ_LAST_OPC) {
290 return (opc - SEQ_FIRST_OPC +
298 } else if (opc < SEC_LAST_OPC) {
300 return (opc - SEC_FIRST_OPC +
309 } else if (opc < FLD_LAST_OPC) {
311 return (opc - FLD_FIRST_OPC +
321 #ifdef HAVE_SERVER_SUPPORT
322 } else if (opc < OUT_UPDATE_LAST_OPC) {
324 return (opc - OUT_UPDATE_FIRST_OPC +
335 } else if (opc < LFSCK_LAST_OPC) {
337 return (opc - LFSCK_FIRST_OPC +
338 OPC_RANGE(OUT_UPDATE) +
349 #endif /* HAVE_SERVER_SUPPORT */
356 #define LUSTRE_MAX_OPCODES_CLIENT (OPC_RANGE(OST) + \
367 #ifdef HAVE_SERVER_SUPPORT
368 #define LUSTRE_MAX_OPCODES (LUSTRE_MAX_OPCODES_CLIENT + \
369 OPC_RANGE(OUT_UPDATE) + \
372 #define LUSTRE_MAX_OPCODES LUSTRE_MAX_OPCODES_CLIENT
375 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
379 PTLRPC_REQWAIT_CNTR = 0,
380 PTLRPC_REQQDEPTH_CNTR,
381 PTLRPC_REQACTIVE_CNTR,
383 PTLRPC_REQBUF_AVAIL_CNTR,
387 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
389 enum lprocfs_extra_opc {
390 LDLM_GLIMPSE_ENQUEUE = 0,
408 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
410 extern struct proc_dir_entry *proc_lustre_root;
411 extern struct dentry *debugfs_lustre_root;
412 extern struct kset *lustre_kset;
415 struct obd_histogram;
417 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
418 #define JOBSTATS_DISABLE "disable"
419 #define JOBSTATS_PROCNAME_UID "procname_uid"
420 #define JOBSTATS_NODELOCAL "nodelocal"
421 #define JOBSTATS_SESSION "session"
423 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats,
424 unsigned int offset);
426 struct obd_job_stats {
427 struct cfs_hash *ojs_hash; /* hash of jobids */
428 struct list_head ojs_list; /* list of job_stat structs */
429 rwlock_t ojs_lock; /* protect ojs_list/js_list */
430 unsigned int ojs_cleanup_interval;/* seconds before expiry */
431 time64_t ojs_last_cleanup; /* previous cleanup time */
432 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
433 unsigned short ojs_cntr_num; /* number of stats in struct */
434 bool ojs_cleaning; /* currently expiring stats */
437 #ifdef CONFIG_PROC_FS
439 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
441 int lprocfs_stats_lock(struct lprocfs_stats *stats,
442 enum lprocfs_stats_lock_ops opc,
443 unsigned long *flags);
444 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
445 enum lprocfs_stats_lock_ops opc,
446 unsigned long *flags);
448 static inline unsigned int
449 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
451 unsigned int percpusize;
453 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
455 /* irq safe stats need lc_array_sum[1] */
456 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
457 percpusize += stats->ls_num * sizeof(__s64);
459 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
460 percpusize = L1_CACHE_ALIGN(percpusize);
465 static inline struct lprocfs_counter *
466 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
469 struct lprocfs_counter *cntr;
471 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
473 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
474 cntr = (void *)cntr + index * sizeof(__s64);
479 /* Two optimized LPROCFS counter increment functions are provided:
480 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
481 * lprocfs_counter_add(cntr) - use for multi-valued counters
482 * Counter data layout allows config flag, counter lock and the
483 * count itself to reside within a single cache line.
486 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
488 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
491 #define lprocfs_counter_incr(stats, idx) \
492 lprocfs_counter_add(stats, idx, 1)
493 #define lprocfs_counter_decr(stats, idx) \
494 lprocfs_counter_sub(stats, idx, 1)
496 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
497 struct lprocfs_counter_header *header,
498 enum lprocfs_stats_flags flags,
499 enum lprocfs_fields_flags field);
500 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
501 enum lprocfs_fields_flags field);
503 extern struct lprocfs_stats *
504 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
505 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
506 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
507 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
508 extern int lprocfs_alloc_obd_stats(struct obd_device *obd,
509 unsigned int num_stats);
510 extern int lprocfs_alloc_md_stats(struct obd_device *obd,
511 unsigned int num_private_stats);
512 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
513 unsigned conf, const char *name,
515 extern void lprocfs_free_obd_stats(struct obd_device *obd);
516 extern void lprocfs_free_md_stats(struct obd_device *obd);
519 extern int lprocfs_add_clear_entry(struct obd_device *obd,
520 struct proc_dir_entry *entry);
521 #ifdef HAVE_SERVER_SUPPORT
522 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
523 extern int lprocfs_exp_cleanup(struct obd_export *exp);
524 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
525 const char *format, ...);
527 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
530 extern struct proc_dir_entry *
531 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
532 void *data, const struct proc_ops *ops);
533 extern struct proc_dir_entry *
534 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
535 const char *format, ...);
536 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
537 #ifdef HAVE_SERVER_SUPPORT
539 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
540 size_t count, loff_t *off);
541 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
543 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
544 struct lprocfs_stats *stats);
545 extern const struct file_operations ldebugfs_stats_seq_fops;
547 /* lprocfs_status.c */
548 extern void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *var,
550 extern struct dentry *ldebugfs_register(const char *name,
551 struct dentry *parent,
552 struct ldebugfs_vars *list,
554 extern int lprocfs_add_vars(struct proc_dir_entry *root,
555 struct lprocfs_vars *var, void *data);
557 extern struct proc_dir_entry *
558 lprocfs_register(const char *name, struct proc_dir_entry *parent,
559 struct lprocfs_vars *list, void *data);
561 extern void lprocfs_remove(struct proc_dir_entry **root);
562 extern void lprocfs_remove_proc_entry(const char *name,
563 struct proc_dir_entry *parent);
564 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
565 extern int lprocfs_obd_cleanup(struct obd_device *obd);
567 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
568 mode_t mode, const struct proc_ops *seq_fops,
570 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
571 mode_t mode, const struct proc_ops *seq_fops,
574 /* Generic callbacks */
575 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
576 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
577 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
578 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
579 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
580 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
581 #ifdef HAVE_SERVER_SUPPORT
582 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
585 struct adaptive_timeout;
586 extern int lprocfs_at_hist_helper(struct seq_file *m,
587 struct adaptive_timeout *at);
588 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
590 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
591 size_t count, loff_t *off);
592 #ifdef HAVE_SERVER_SUPPORT
594 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
595 size_t count, loff_t *off);
597 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
598 const char *buffer, size_t count);
599 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
603 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
604 size_t count, loff_t *off);
605 static inline ssize_t
606 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
607 size_t count, loff_t *off)
609 return ldebugfs_import_seq_write(file, buffer, count, off);
612 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
614 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
615 size_t count, loff_t *off);
617 int string_to_size(u64 *size, const char *buffer, size_t count);
618 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
619 const char *defunit);
620 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
621 char *lprocfs_find_named_value(const char *buffer, const char *name,
623 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
624 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
625 void lprocfs_oh_clear(struct obd_histogram *oh);
626 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
628 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
629 struct lprocfs_counter *cnt);
631 #ifdef HAVE_SERVER_SUPPORT
632 /* lprocfs_status.c: recovery status */
633 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
635 /* lprocfs_status.c: hash statistics */
636 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
638 /* lprocfs_status.c: IR factor */
639 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
641 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
642 const char *buffer, size_t count);
645 /* lprocfs_status.c: dump pages on cksum error */
646 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
648 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
649 size_t count, loff_t *off);
651 extern int lprocfs_single_release(struct inode *, struct file *);
652 extern int lprocfs_seq_release(struct inode *, struct file *);
654 /* You must use these macros when you want to refer to
655 * the import in a client obd_device for a lprocfs entry
656 * Note that it is not safe to 'goto', 'return' or 'break'
657 * out of the body of this statement. It *IS* safe to
658 * 'goto' the a label inside the statement, or to 'continue'
659 * to get out of the statement.
662 #define with_imp_locked_nested(__obd, __imp, __rc, __nest) \
663 for (down_read_nested(&(__obd)->u.cli.cl_sem, __nest), \
664 __imp = (__obd)->u.cli.cl_import, \
665 __rc = __imp ? 0 : -ENODEV; \
666 __imp ? 1 : (up_read(&(__obd)->u.cli.cl_sem), 0); \
669 #define with_imp_locked(__obd, __imp, __rc) \
670 with_imp_locked_nested(__obd, __imp, __rc, 0)
672 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
673 * debugfs entries; otherwise, you will define name##_seq_write function also
674 * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
675 * Finally, call debugfs_create_file(filename, 0444, obd, data, &name#_fops);
677 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write) \
678 static int name##_single_open(struct inode *inode, struct file *file) \
680 return single_open(file, name##_seq_show, inode->i_private); \
682 static const struct file_operations name##_fops = { \
683 .owner = THIS_MODULE, \
684 .open = name##_single_open, \
686 .write = custom_seq_write, \
687 .llseek = seq_lseek, \
688 .release = single_release, \
691 #define LDEBUGFS_SEQ_FOPS_RO(name) __LDEBUGFS_SEQ_FOPS(name, NULL)
692 #define LDEBUGFS_SEQ_FOPS(name) __LDEBUGFS_SEQ_FOPS(name, \
695 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type) \
696 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
700 return lprocfs_##type##_seq_show(m, m->private); \
702 LDEBUGFS_SEQ_FOPS_RO(name##_##type)
704 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type) \
705 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
709 return lprocfs_##type##_seq_show(m, m->private); \
711 static ssize_t name##_##type##_seq_write(struct file *file, \
712 const char __user *buffer, size_t count, \
715 struct seq_file *seq = file->private_data; \
719 return ldebugfs_##type##_seq_write(file, buffer, count, \
722 LDEBUGFS_SEQ_FOPS(name##_##type);
724 #define LDEBUGFS_FOPS_WR_ONLY(name, type) \
725 static ssize_t name##_##type##_write(struct file *file, \
726 const char __user *buffer, size_t count, \
729 return ldebugfs_##type##_seq_write(file, buffer, count, \
732 static int name##_##type##_open(struct inode *inode, \
735 return single_open(file, NULL, inode->i_private); \
737 static const struct file_operations name##_##type##_fops = { \
738 .open = name##_##type##_open, \
739 .write = name##_##type##_write, \
740 .release = single_release, \
743 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
744 * proc entries; otherwise, you will define name##_seq_write function also for
745 * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
746 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
748 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
749 static int name##_single_open(struct inode *inode, struct file *file) \
751 return single_open(file, name##_seq_show, \
752 inode->i_private ? inode->i_private : \
755 static const struct proc_ops name##_fops = { \
756 PROC_OWNER(THIS_MODULE) \
757 .proc_open = name##_single_open, \
758 .proc_read = seq_read, \
759 .proc_write = custom_seq_write, \
760 .proc_lseek = seq_lseek, \
761 .proc_release = lprocfs_single_release, \
764 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
765 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
767 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
768 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
770 return lprocfs_##type##_seq_show(m, m->private); \
772 LPROC_SEQ_FOPS_RO(name##_##type)
774 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
775 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
777 return lprocfs_##type##_seq_show(m, m->private); \
779 static ssize_t name##_##type##_seq_write(struct file *file, \
780 const char __user *buffer, size_t count, \
783 struct seq_file *seq = file->private_data; \
784 return lprocfs_##type##_seq_write(file, buffer, \
785 count, seq->private); \
787 LPROC_SEQ_FOPS(name##_##type);
789 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
790 static ssize_t name##_##type##_write(struct file *file, \
791 const char __user *buffer, size_t count, \
794 return lprocfs_##type##_seq_write(file, buffer, count, off);\
796 static int name##_##type##_open(struct inode *inode, struct file *file)\
798 return single_open(file, NULL, \
799 inode->i_private ? inode->i_private : \
802 static const struct proc_ops name##_##type##_fops = { \
803 .proc_open = name##_##type##_open, \
804 .proc_write = name##_##type##_write, \
805 .proc_release = lprocfs_single_release, \
809 struct attribute attr;
810 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
812 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
813 const char *buf, size_t len);
816 #define LUSTRE_ATTR(name, mode, show, store) \
817 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
819 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
820 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
821 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
823 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
825 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
826 const char *buf, size_t len);
828 extern const struct sysfs_ops lustre_sysfs_ops;
831 struct ptlrpc_request;
832 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
834 #ifdef HAVE_SERVER_SUPPORT
835 /* lprocfs_jobstats.c */
836 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
837 int event, long amount);
838 void lprocfs_job_stats_fini(struct obd_device *obd);
839 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
840 cntr_init_callback fn);
841 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
843 ssize_t job_cleanup_interval_store(struct kobject *kobj,
844 struct attribute *attr,
845 const char *buffer, size_t count);
846 /* lproc_status_server.c */
847 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
849 ssize_t recovery_time_soft_store(struct kobject *kobj,
850 struct attribute *attr,
851 const char *buffer, size_t count);
852 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
854 ssize_t recovery_time_hard_store(struct kobject *kobj,
855 struct attribute *attr,
856 const char *buffer, size_t count);
857 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
861 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
862 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
863 const char __user *buffer,
864 size_t count, loff_t *off);
865 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
867 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
868 const char *buffer, size_t count);
870 struct root_squash_info;
871 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
872 struct root_squash_info *squash, char *name);
873 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
874 struct root_squash_info *squash, char *name);
876 #else /* !CONFIG_PROC_FS */
878 #define proc_lustre_root NULL
880 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
881 int index, long amount)
883 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
886 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
887 int index, long amount)
889 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
892 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
893 int index, unsigned conf,
894 const char *name, const char *units)
897 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
898 enum lprocfs_fields_flags field)
901 /* NB: we return !NULL to satisfy error checker */
902 static inline struct lprocfs_stats *
903 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
904 { return (struct lprocfs_stats *)1; }
905 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
907 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
909 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
911 struct lprocfs_stats *stats)
913 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
915 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
916 unsigned int num_stats)
918 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
919 unsigned int num_private_stats)
921 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
923 static inline void lprocfs_free_md_stats(struct obd_device *obd)
927 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
929 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
931 #ifdef HAVE_SERVER_SUPPORT
933 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
934 const char __user *buffer,
935 size_t count, loff_t *off)
938 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
940 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
943 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
945 static inline struct proc_dir_entry *
946 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
947 void *data, const struct file_operations *fops)
949 static inline struct proc_dir_entry *
950 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
951 const char *format, ...)
953 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
954 struct lprocfs_vars *var, void *data)
956 static inline struct proc_dir_entry *
957 lprocfs_register(const char *name, struct proc_dir_entry *parent,
958 struct lprocfs_vars *list, void *data)
960 static inline void lprocfs_remove(struct proc_dir_entry **root)
962 static inline void lprocfs_remove_proc_entry(const char *name,
963 struct proc_dir_entry *parent)
965 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
967 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
969 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
971 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
973 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
975 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
977 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
979 #ifdef HAVE_SERVER_SUPPORT
980 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
983 struct adaptive_timeout;
984 static inline int lprocfs_at_hist_helper(struct seq_file *m,
985 struct adaptive_timeout *at)
987 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
989 static inline ssize_t
990 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
991 size_t count, loff_t *off)
993 #ifdef HAVE_SERVER_SUPPORT
994 static inline ssize_t
995 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
996 size_t count, loff_t *off)
999 static inline ssize_t
1000 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1001 size_t count, loff_t *off)
1003 static inline ssize_t
1004 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
1005 size_t count, loff_t *off)
1007 static inline ssize_t
1008 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1009 size_t count, loff_t *off)
1012 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1014 static inline ssize_t
1015 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1016 size_t count, loff_t *off)
1019 /* Statfs helpers */
1021 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1024 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1027 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1030 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1033 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1036 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1039 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1042 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1045 void lprocfs_oh_clear(struct obd_histogram *oh)
1048 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1051 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1052 struct lprocfs_counter *cnt)
1055 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1056 enum lprocfs_fields_flags field)
1057 { return (__u64)0; }
1059 #define LPROC_SEQ_FOPS_RO(name)
1060 #define LPROC_SEQ_FOPS(name)
1061 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1062 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1063 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1065 /* lprocfs_jobstats.c */
1067 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1071 void lprocfs_job_stats_fini(struct obd_device *obd)
1074 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1075 cntr_init_callback fn)
1079 /* lproc_ptlrpc.c */
1080 #define target_print_req NULL
1082 #endif /* CONFIG_PROC_FS */
1084 #endif /* LPROCFS_STATUS_H */