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];
105 struct obd_hist_pcpu {
106 struct percpu_counter oh_pc_buckets[OBD_HIST_MAX];
110 /* An lprocfs counter can be configured using the enum bit masks below.
112 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
113 * protects this counter from concurrent updates. If not specified,
114 * lprocfs an internal per-counter lock variable. External locks are
115 * not used to protect counter increments, but are used to protect
116 * counter readout and resets.
118 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
119 * (i.e. counter can be incremented by more than "1"). When specified,
120 * the counter maintains min, max and sum in addition to a simple
121 * invocation count. This allows averages to be be computed.
122 * If not specified, the counter is an increment-by-1 counter.
123 * min, max, sum, etc. are not maintained.
125 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
126 * squares (for multi-valued counter samples only). This allows
127 * external computation of standard deviation, but involves a 64-bit
128 * multiply per counter increment.
131 enum lprocfs_counter_config {
132 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
133 LPROCFS_CNTR_AVGMINMAX = 0x0002,
134 LPROCFS_CNTR_STDDEV = 0x0004,
136 /* counter unit type */
137 LPROCFS_TYPE_REQS = 0x0000, /* default if config = 0 */
138 LPROCFS_TYPE_BYTES = 0x0200,
139 LPROCFS_TYPE_PAGES = 0x0400,
140 LPROCFS_TYPE_LOCKS = 0x0500,
141 LPROCFS_TYPE_LOCKSPS = 0x0600,
142 LPROCFS_TYPE_SECS = 0x0700,
143 LPROCFS_TYPE_USECS = 0x0800,
144 LPROCFS_TYPE_MASK = 0x0f00,
146 LPROCFS_TYPE_LATENCY = LPROCFS_TYPE_USECS |
147 LPROCFS_CNTR_AVGMINMAX |
149 LPROCFS_TYPE_BYTES_FULL = LPROCFS_TYPE_BYTES |
150 LPROCFS_CNTR_AVGMINMAX |
153 #define LC_MIN_INIT ((~(__u64)0) >> 1)
155 struct lprocfs_counter_header {
156 enum lprocfs_counter_config lc_config;
157 const char *lc_name; /* must be static */
158 const char *lc_units; /* must be static */
161 struct lprocfs_counter {
167 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
168 * for irq context counter, i.e. stats with
169 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
172 __s64 lc_array_sum[1];
174 #define lc_sum lc_array_sum[0]
175 #define lc_sum_irq lc_array_sum[1]
177 struct lprocfs_percpu {
178 struct lprocfs_counter lp_cntr[0];
181 enum lprocfs_stats_lock_ops {
182 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
183 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
186 enum lprocfs_stats_flags {
187 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
188 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
189 * area and need locking */
190 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
193 enum lprocfs_fields_flags {
194 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
195 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
196 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
197 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
198 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
199 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
200 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
203 struct lprocfs_stats {
205 unsigned short ls_num;
206 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
207 unsigned short ls_biggest_alloc_num;
208 enum lprocfs_stats_flags ls_flags;
210 /* Lock used when there are no percpu stats areas; For percpu stats,
211 * it is used to protect ls_biggest_alloc_num change */
214 /* has ls_num of counter headers */
215 struct lprocfs_counter_header *ls_cnt_header;
216 struct lprocfs_percpu *ls_percpu[0];
219 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
221 /* Pack all opcodes down into a single monotonically increasing index */
222 static inline int opcode_offset(__u32 opc) {
223 if (opc < OST_LAST_OPC) {
225 return (opc - OST_FIRST_OPC);
226 } else if (opc < MDS_LAST_OPC) {
228 return (opc - MDS_FIRST_OPC +
230 } else if (opc < LDLM_LAST_OPC) {
232 return (opc - LDLM_FIRST_OPC +
235 } else if (opc < MGS_LAST_OPC) {
237 return (opc - MGS_FIRST_OPC +
241 } else if (opc < OBD_LAST_OPC) {
243 return (opc - OBD_FIRST_OPC +
248 } else if (opc < LLOG_LAST_OPC) {
250 return (opc - LLOG_FIRST_OPC +
256 } else if (opc < QUOTA_LAST_OPC) {
258 return (opc - QUOTA_FIRST_OPC +
265 } else if (opc < SEQ_LAST_OPC) {
267 return (opc - SEQ_FIRST_OPC +
275 } else if (opc < SEC_LAST_OPC) {
277 return (opc - SEC_FIRST_OPC +
286 } else if (opc < FLD_LAST_OPC) {
288 return (opc - FLD_FIRST_OPC +
298 #ifdef HAVE_SERVER_SUPPORT
299 } else if (opc < OUT_UPDATE_LAST_OPC) {
301 return (opc - OUT_UPDATE_FIRST_OPC +
312 } else if (opc < LFSCK_LAST_OPC) {
314 return (opc - LFSCK_FIRST_OPC +
315 OPC_RANGE(OUT_UPDATE) +
326 #endif /* HAVE_SERVER_SUPPORT */
333 #define LUSTRE_MAX_OPCODES_CLIENT (OPC_RANGE(OST) + \
344 #ifdef HAVE_SERVER_SUPPORT
345 #define LUSTRE_MAX_OPCODES (LUSTRE_MAX_OPCODES_CLIENT + \
346 OPC_RANGE(OUT_UPDATE) + \
349 #define LUSTRE_MAX_OPCODES LUSTRE_MAX_OPCODES_CLIENT
352 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
356 PTLRPC_REQWAIT_CNTR = 0,
357 PTLRPC_REQQDEPTH_CNTR,
358 PTLRPC_REQACTIVE_CNTR,
360 PTLRPC_REQBUF_AVAIL_CNTR,
364 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
366 enum lprocfs_extra_opc {
367 LDLM_GLIMPSE_ENQUEUE = 0,
385 #ifdef HAVE_SERVER_SUPPORT
391 BRW_R_DISCONT_BLOCKS,
392 BRW_W_DISCONT_BLOCKS,
404 struct brw_stats_props {
405 const char *bsp_name;
406 const char *bsp_units;
412 struct obd_hist_pcpu bs_hist[BRW_RW_STATS_NUM];
413 struct brw_stats_props bs_props[BRW_RW_STATS_NUM / 2];
416 int lprocfs_init_brw_stats(struct brw_stats *brw_stats);
417 void lprocfs_fini_brw_stats(struct brw_stats *brw_stats);
419 void ldebugfs_register_osd_stats(struct dentry *parent,
420 struct brw_stats *brw_stats,
421 struct lprocfs_stats *stats);
422 #endif /* HAVE_SERVER_SUPPORT */
424 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
426 extern struct proc_dir_entry *proc_lustre_root;
427 extern struct dentry *debugfs_lustre_root;
428 extern struct kset *lustre_kset;
432 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
433 #define JOBSTATS_DISABLE "disable"
434 #define JOBSTATS_PROCNAME_UID "procname_uid"
435 #define JOBSTATS_NODELOCAL "nodelocal"
436 #define JOBSTATS_SESSION "session"
438 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats,
439 unsigned int offset);
441 struct obd_job_stats {
442 struct cfs_hash *ojs_hash; /* hash of jobids */
443 struct list_head ojs_list; /* list of job_stat structs */
444 rwlock_t ojs_lock; /* protect ojs_list/js_list */
445 ktime_t ojs_cleanup_interval;/* 1/2 expiry seconds */
446 ktime_t ojs_cleanup_last;/* previous cleanup time */
447 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
448 unsigned short ojs_cntr_num; /* number of stats in struct */
449 bool ojs_cleaning; /* currently expiring stats */
452 #ifdef CONFIG_PROC_FS
454 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
456 int lprocfs_stats_lock(struct lprocfs_stats *stats,
457 enum lprocfs_stats_lock_ops opc,
458 unsigned long *flags);
459 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
460 enum lprocfs_stats_lock_ops opc,
461 unsigned long *flags);
463 static inline unsigned int
464 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
466 unsigned int percpusize;
468 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
470 /* irq safe stats need lc_array_sum[1] */
471 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
472 percpusize += stats->ls_num * sizeof(__s64);
474 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
475 percpusize = L1_CACHE_ALIGN(percpusize);
480 static inline struct lprocfs_counter *
481 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
484 struct lprocfs_counter *cntr;
486 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
488 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
489 cntr = (void *)cntr + index * sizeof(__s64);
494 /* Two optimized LPROCFS counter increment functions are provided:
495 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
496 * lprocfs_counter_add(cntr) - use for multi-valued counters
497 * Counter data layout allows config flag, counter lock and the
498 * count itself to reside within a single cache line.
501 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
503 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
506 #define lprocfs_counter_incr(stats, idx) \
507 lprocfs_counter_add(stats, idx, 1)
508 #define lprocfs_counter_decr(stats, idx) \
509 lprocfs_counter_sub(stats, idx, 1)
511 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
512 struct lprocfs_counter_header *header,
513 enum lprocfs_stats_flags flags,
514 enum lprocfs_fields_flags field);
515 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
516 enum lprocfs_fields_flags field);
518 extern struct lprocfs_stats *
519 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
520 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
521 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
522 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
523 extern int lprocfs_alloc_obd_stats(struct obd_device *obd,
524 unsigned int num_stats);
525 extern int lprocfs_alloc_md_stats(struct obd_device *obd,
526 unsigned int num_private_stats);
527 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
528 enum lprocfs_counter_config config,
530 extern void lprocfs_counter_init_units(struct lprocfs_stats *stats, int index,
531 enum lprocfs_counter_config config,
532 const char *name, const char *units);
533 extern void lprocfs_free_obd_stats(struct obd_device *obd);
534 extern void lprocfs_free_md_stats(struct obd_device *obd);
537 extern int lprocfs_add_clear_entry(struct obd_device *obd,
538 struct proc_dir_entry *entry);
539 #ifdef HAVE_SERVER_SUPPORT
540 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
541 extern int lprocfs_exp_cleanup(struct obd_export *exp);
542 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
543 const char *format, ...);
545 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
548 extern struct proc_dir_entry *
549 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
550 void *data, const struct proc_ops *ops);
551 extern struct proc_dir_entry *
552 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
553 const char *format, ...);
554 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
555 #ifdef HAVE_SERVER_SUPPORT
557 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
558 size_t count, loff_t *off);
559 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
561 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
562 struct lprocfs_stats *stats);
563 extern const struct file_operations ldebugfs_stats_seq_fops;
565 /* lprocfs_status.c */
566 extern void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *var,
568 extern struct dentry *ldebugfs_register(const char *name,
569 struct dentry *parent,
570 struct ldebugfs_vars *list,
572 extern int lprocfs_add_vars(struct proc_dir_entry *root,
573 struct lprocfs_vars *var, void *data);
575 extern struct proc_dir_entry *
576 lprocfs_register(const char *name, struct proc_dir_entry *parent,
577 struct lprocfs_vars *list, void *data);
579 extern void lprocfs_remove(struct proc_dir_entry **root);
580 extern void lprocfs_remove_proc_entry(const char *name,
581 struct proc_dir_entry *parent);
582 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
583 extern int lprocfs_obd_cleanup(struct obd_device *obd);
585 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
586 mode_t mode, const struct proc_ops *seq_fops,
588 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
589 mode_t mode, const struct proc_ops *seq_fops,
591 extern void lprocfs_stats_header(struct seq_file *seq, ktime_t now,
592 ktime_t ts_init, int width, const char *colon,
595 /* Generic callbacks */
596 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
597 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
598 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
599 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
600 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
601 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
602 #ifdef HAVE_SERVER_SUPPORT
603 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
605 ssize_t grant_check_threshold_show(struct kobject *kobj,
606 struct attribute *attr, char *buf);
607 ssize_t grant_check_threshold_store(struct kobject *kobj,
608 struct attribute *attr,
609 const char *buffer, size_t count);
611 struct adaptive_timeout;
612 extern int lprocfs_at_hist_helper(struct seq_file *m,
613 struct adaptive_timeout *at);
614 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
616 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
617 size_t count, loff_t *off);
618 #ifdef HAVE_SERVER_SUPPORT
620 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
621 size_t count, loff_t *off);
623 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
624 const char *buffer, size_t count);
625 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
629 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
630 size_t count, loff_t *off);
631 static inline ssize_t
632 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
633 size_t count, loff_t *off)
635 return ldebugfs_import_seq_write(file, buffer, count, off);
638 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
640 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
641 size_t count, loff_t *off);
643 int string_to_size(u64 *size, const char *buffer, size_t count);
644 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
645 const char *defunit);
646 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
647 char *lprocfs_find_named_value(const char *buffer, const char *name,
649 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
650 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
651 void lprocfs_oh_clear(struct obd_histogram *oh);
652 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
654 void lprocfs_oh_tally_pcpu(struct obd_hist_pcpu *oh, unsigned int value);
655 void lprocfs_oh_tally_log2_pcpu(struct obd_hist_pcpu *oh, unsigned int value);
656 int lprocfs_oh_alloc_pcpu(struct obd_hist_pcpu *oh);
657 void lprocfs_oh_clear_pcpu(struct obd_hist_pcpu *oh);
658 void lprocfs_oh_release_pcpu(struct obd_hist_pcpu *oh);
659 unsigned long lprocfs_oh_sum_pcpu(struct obd_hist_pcpu *oh);
660 unsigned long lprocfs_oh_counter_pcpu(struct obd_hist_pcpu *oh,
663 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
664 struct lprocfs_counter *cnt);
666 #ifdef HAVE_SERVER_SUPPORT
667 /* lprocfs_status.c: recovery status */
668 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
670 /* lprocfs_status.c: hash statistics */
671 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
673 /* lprocfs_status.c: IR factor */
674 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
676 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
677 const char *buffer, size_t count);
680 /* lprocfs_status.c: dump pages on cksum error */
681 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
683 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
684 size_t count, loff_t *off);
686 extern int lprocfs_single_release(struct inode *, struct file *);
687 extern int lprocfs_seq_release(struct inode *, struct file *);
689 /* You must use these macros when you want to refer to
690 * the import in a client obd_device for a lprocfs entry
691 * Note that it is not safe to 'goto', 'return' or 'break'
692 * out of the body of this statement. It *IS* safe to
693 * 'goto' the a label inside the statement, or to 'continue'
694 * to get out of the statement.
697 #define with_imp_locked_nested(__obd, __imp, __rc, __nest) \
698 for (down_read_nested(&(__obd)->u.cli.cl_sem, __nest), \
699 __imp = (__obd)->u.cli.cl_import, \
700 __rc = __imp ? 0 : -ENODEV; \
701 __imp ? 1 : (up_read(&(__obd)->u.cli.cl_sem), 0); \
704 #define with_imp_locked(__obd, __imp, __rc) \
705 with_imp_locked_nested(__obd, __imp, __rc, 0)
707 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
708 * debugfs entries; otherwise, you will define name##_seq_write function also
709 * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
710 * Finally, call debugfs_create_file(filename, 0444, obd, data, &name#_fops);
712 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write) \
713 static int name##_single_open(struct inode *inode, struct file *file) \
715 return single_open(file, name##_seq_show, inode->i_private); \
717 static const struct file_operations name##_fops = { \
718 .owner = THIS_MODULE, \
719 .open = name##_single_open, \
721 .write = custom_seq_write, \
722 .llseek = seq_lseek, \
723 .release = single_release, \
726 #define LDEBUGFS_SEQ_FOPS_RO(name) __LDEBUGFS_SEQ_FOPS(name, NULL)
727 #define LDEBUGFS_SEQ_FOPS(name) __LDEBUGFS_SEQ_FOPS(name, \
730 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type) \
731 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
735 return lprocfs_##type##_seq_show(m, m->private); \
737 LDEBUGFS_SEQ_FOPS_RO(name##_##type)
739 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type) \
740 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
744 return lprocfs_##type##_seq_show(m, m->private); \
746 static ssize_t name##_##type##_seq_write(struct file *file, \
747 const char __user *buffer, size_t count, \
750 struct seq_file *seq = file->private_data; \
754 return ldebugfs_##type##_seq_write(file, buffer, count, \
757 LDEBUGFS_SEQ_FOPS(name##_##type);
759 #define LDEBUGFS_FOPS_WR_ONLY(name, type) \
760 static ssize_t name##_##type##_write(struct file *file, \
761 const char __user *buffer, size_t count, \
764 return ldebugfs_##type##_seq_write(file, buffer, count, \
767 static int name##_##type##_open(struct inode *inode, \
770 return single_open(file, NULL, inode->i_private); \
772 static const struct file_operations name##_##type##_fops = { \
773 .open = name##_##type##_open, \
774 .write = name##_##type##_write, \
775 .release = single_release, \
778 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
779 * proc entries; otherwise, you will define name##_seq_write function also for
780 * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
781 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
783 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
784 static int name##_single_open(struct inode *inode, struct file *file) \
786 return single_open(file, name##_seq_show, \
787 inode->i_private ? inode->i_private : \
790 static const struct proc_ops name##_fops = { \
791 PROC_OWNER(THIS_MODULE) \
792 .proc_open = name##_single_open, \
793 .proc_read = seq_read, \
794 .proc_write = custom_seq_write, \
795 .proc_lseek = seq_lseek, \
796 .proc_release = lprocfs_single_release, \
799 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
800 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
802 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
803 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
805 return lprocfs_##type##_seq_show(m, m->private); \
807 LPROC_SEQ_FOPS_RO(name##_##type)
809 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
810 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
812 return lprocfs_##type##_seq_show(m, m->private); \
814 static ssize_t name##_##type##_seq_write(struct file *file, \
815 const char __user *buffer, size_t count, \
818 struct seq_file *seq = file->private_data; \
819 return lprocfs_##type##_seq_write(file, buffer, \
820 count, seq->private); \
822 LPROC_SEQ_FOPS(name##_##type);
824 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
825 static ssize_t name##_##type##_write(struct file *file, \
826 const char __user *buffer, size_t count, \
829 return lprocfs_##type##_seq_write(file, buffer, count, off);\
831 static int name##_##type##_open(struct inode *inode, struct file *file)\
833 return single_open(file, NULL, \
834 inode->i_private ? inode->i_private : \
837 static const struct proc_ops name##_##type##_fops = { \
838 .proc_open = name##_##type##_open, \
839 .proc_write = name##_##type##_write, \
840 .proc_release = lprocfs_single_release, \
844 struct attribute attr;
845 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
847 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
848 const char *buf, size_t len);
851 #define LUSTRE_ATTR(name, mode, show, store) \
852 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
854 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
855 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
856 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
858 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
860 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
861 const char *buf, size_t len);
863 extern const struct sysfs_ops lustre_sysfs_ops;
866 struct ptlrpc_request;
867 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
869 #ifdef HAVE_SERVER_SUPPORT
870 /* lprocfs_jobstats.c */
871 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
872 int event, long amount);
873 void lprocfs_job_stats_fini(struct obd_device *obd);
874 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
875 cntr_init_callback fn);
876 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
878 ssize_t job_cleanup_interval_store(struct kobject *kobj,
879 struct attribute *attr,
880 const char *buffer, size_t count);
881 /* lproc_status_server.c */
882 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
884 ssize_t recovery_time_soft_store(struct kobject *kobj,
885 struct attribute *attr,
886 const char *buffer, size_t count);
887 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
889 ssize_t recovery_time_hard_store(struct kobject *kobj,
890 struct attribute *attr,
891 const char *buffer, size_t count);
892 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
896 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
897 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
898 const char __user *buffer,
899 size_t count, loff_t *off);
900 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
902 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
903 const char *buffer, size_t count);
905 struct root_squash_info;
906 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
907 struct root_squash_info *squash, char *name);
908 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
909 struct root_squash_info *squash, char *name);
911 #else /* !CONFIG_PROC_FS */
913 #define proc_lustre_root NULL
915 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
916 int index, long amount)
918 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int index)
920 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
921 int index, long amount)
923 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats, int index)
925 static inline void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
926 enum lprocfs_counter_config config,
929 static inline void lprocfs_counter_init_units(struct lprocfs_stats *stats,
930 int index, enum lprocfs_counter_config config,
931 const char *name, const char *units)
934 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
935 enum lprocfs_fields_flags field)
938 /* NB: we return !NULL to satisfy error checker */
939 static inline struct lprocfs_stats *
940 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
941 { return (struct lprocfs_stats *)1; }
942 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
944 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
946 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
948 struct lprocfs_stats *stats)
950 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
952 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
953 unsigned int num_stats)
955 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
956 unsigned int num_private_stats)
958 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
960 static inline void lprocfs_free_md_stats(struct obd_device *obd)
964 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
966 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
968 #ifdef HAVE_SERVER_SUPPORT
970 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
971 const char __user *buffer,
972 size_t count, loff_t *off)
975 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
977 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
980 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
982 static inline struct proc_dir_entry *
983 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
984 void *data, const struct file_operations *fops)
986 static inline struct proc_dir_entry *
987 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
988 const char *format, ...)
990 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
991 struct lprocfs_vars *var, void *data)
993 static inline struct proc_dir_entry *
994 lprocfs_register(const char *name, struct proc_dir_entry *parent,
995 struct lprocfs_vars *list, void *data)
997 static inline void lprocfs_remove(struct proc_dir_entry **root)
999 static inline void lprocfs_remove_proc_entry(const char *name,
1000 struct proc_dir_entry *parent)
1002 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1004 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
1006 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
1008 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
1010 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
1012 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
1014 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1016 #ifdef HAVE_SERVER_SUPPORT
1017 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
1020 struct adaptive_timeout;
1021 static inline int lprocfs_at_hist_helper(struct seq_file *m,
1022 struct adaptive_timeout *at)
1024 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1026 static inline ssize_t
1027 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
1028 size_t count, loff_t *off)
1030 #ifdef HAVE_SERVER_SUPPORT
1031 static inline ssize_t
1032 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
1033 size_t count, loff_t *off)
1036 static inline ssize_t
1037 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1038 size_t count, loff_t *off)
1040 static inline ssize_t
1041 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
1042 size_t count, loff_t *off)
1044 static inline ssize_t
1045 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1046 size_t count, loff_t *off)
1049 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1051 static inline ssize_t
1052 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1053 size_t count, loff_t *off)
1056 /* Statfs helpers */
1058 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1061 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1064 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1067 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1070 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1073 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1076 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1079 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1082 void lprocfs_oh_clear(struct obd_histogram *oh)
1085 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1088 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1089 struct lprocfs_counter *cnt)
1092 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1093 enum lprocfs_fields_flags field)
1094 { return (__u64)0; }
1096 #define LPROC_SEQ_FOPS_RO(name)
1097 #define LPROC_SEQ_FOPS(name)
1098 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1099 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1100 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1102 /* lprocfs_jobstats.c */
1104 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1108 void lprocfs_job_stats_fini(struct obd_device *obd)
1111 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1112 cntr_init_callback fn)
1116 /* lproc_ptlrpc.c */
1117 #define target_print_req NULL
1119 #endif /* CONFIG_PROC_FS */
1121 #endif /* LPROCFS_STATUS_H */