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.
130 * LPROCFS_CNTR_HISTOGRAM indicates that the counter should track a
131 * exponential histogram.
134 enum lprocfs_counter_config {
135 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
136 LPROCFS_CNTR_AVGMINMAX = 0x0002,
137 LPROCFS_CNTR_STDDEV = 0x0004,
138 LPROCFS_CNTR_HISTOGRAM = 0x0008,
140 /* counter unit type */
141 LPROCFS_TYPE_REQS = 0x0000, /* default if config = 0 */
142 LPROCFS_TYPE_BYTES = 0x0200,
143 LPROCFS_TYPE_PAGES = 0x0400,
144 LPROCFS_TYPE_LOCKS = 0x0500,
145 LPROCFS_TYPE_LOCKSPS = 0x0600,
146 LPROCFS_TYPE_SECS = 0x0700,
147 LPROCFS_TYPE_USECS = 0x0800,
148 LPROCFS_TYPE_MASK = 0x0f00,
150 LPROCFS_TYPE_LATENCY = LPROCFS_TYPE_USECS |
151 LPROCFS_CNTR_AVGMINMAX |
153 LPROCFS_TYPE_BYTES_FULL = LPROCFS_TYPE_BYTES |
154 LPROCFS_CNTR_AVGMINMAX |
156 LPROCFS_TYPE_BYTES_FULL_HISTOGRAM = LPROCFS_TYPE_BYTES_FULL |
157 LPROCFS_CNTR_HISTOGRAM,
159 #define LC_MIN_INIT ((~(__u64)0) >> 1)
161 struct lprocfs_counter_header {
162 enum lprocfs_counter_config lc_config;
163 const char *lc_name; /* must be static */
164 const char *lc_units; /* must be static */
165 struct obd_histogram *lc_hist;
168 struct lprocfs_counter {
176 struct lprocfs_percpu {
177 struct lprocfs_counter lp_cntr[0];
180 enum lprocfs_stats_lock_ops {
181 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
182 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
185 enum lprocfs_stats_flags {
186 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
187 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* need locking(no percpu area) */
190 enum lprocfs_fields_flags {
191 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
192 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
193 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
194 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
195 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
196 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
197 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
200 struct lprocfs_stats {
202 unsigned short ls_num;
203 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
204 unsigned short ls_biggest_alloc_num;
205 enum lprocfs_stats_flags ls_flags;
207 /* Lock used when there are no percpu stats areas; For percpu stats,
208 * it is used to protect ls_biggest_alloc_num change
212 /* has ls_num of counter headers */
213 struct lprocfs_counter_header *ls_cnt_header;
214 struct lprocfs_percpu *ls_percpu[0];
217 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
219 /* Pack all opcodes down into a single monotonically increasing index */
220 static inline int opcode_offset(__u32 opc)
222 if (opc < OST_LAST_OPC) {
224 return (opc - OST_FIRST_OPC);
225 } else if (opc < MDS_LAST_OPC) {
227 return (opc - MDS_FIRST_OPC +
229 } else if (opc < LDLM_LAST_OPC) {
231 return (opc - LDLM_FIRST_OPC +
234 } else if (opc < MGS_LAST_OPC) {
236 return (opc - MGS_FIRST_OPC +
240 } else if (opc < OBD_LAST_OPC) {
242 return (opc - OBD_FIRST_OPC +
247 } else if (opc < LLOG_LAST_OPC) {
249 return (opc - LLOG_FIRST_OPC +
255 } else if (opc < QUOTA_LAST_OPC) {
257 return (opc - QUOTA_FIRST_OPC +
264 } else if (opc < SEQ_LAST_OPC) {
266 return (opc - SEQ_FIRST_OPC +
274 } else if (opc < SEC_LAST_OPC) {
276 return (opc - SEC_FIRST_OPC +
285 } else if (opc < FLD_LAST_OPC) {
287 return (opc - FLD_FIRST_OPC +
297 #ifdef HAVE_SERVER_SUPPORT
298 } else if (opc < OUT_UPDATE_LAST_OPC) {
300 return (opc - OUT_UPDATE_FIRST_OPC +
311 } else if (opc < LFSCK_LAST_OPC) {
313 return (opc - LFSCK_FIRST_OPC +
314 OPC_RANGE(OUT_UPDATE) +
325 #endif /* HAVE_SERVER_SUPPORT */
332 #define LUSTRE_MAX_OPCODES_CLIENT (OPC_RANGE(OST) + \
343 #ifdef HAVE_SERVER_SUPPORT
344 #define LUSTRE_MAX_OPCODES (LUSTRE_MAX_OPCODES_CLIENT + \
345 OPC_RANGE(OUT_UPDATE) + \
348 #define LUSTRE_MAX_OPCODES LUSTRE_MAX_OPCODES_CLIENT
351 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
355 PTLRPC_REQWAIT_CNTR = 0,
356 PTLRPC_REQQDEPTH_CNTR,
357 PTLRPC_REQACTIVE_CNTR,
359 PTLRPC_REQBUF_AVAIL_CNTR,
363 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
365 enum lprocfs_extra_opc {
366 LDLM_GLIMPSE_ENQUEUE = 0,
384 #ifdef HAVE_SERVER_SUPPORT
390 BRW_R_DISCONT_BLOCKS,
391 BRW_W_DISCONT_BLOCKS,
405 struct brw_stats_props {
406 const char *bsp_name;
407 const char *bsp_units;
413 struct obd_hist_pcpu bs_hist[BRW_RW_STATS_NUM];
414 struct brw_stats_props bs_props[BRW_RW_STATS_NUM / 2];
417 int lprocfs_init_brw_stats(struct brw_stats *brw_stats);
418 void lprocfs_fini_brw_stats(struct brw_stats *brw_stats);
420 void ldebugfs_register_osd_stats(struct dentry *parent,
421 struct brw_stats *brw_stats,
422 struct lprocfs_stats *stats);
423 #endif /* HAVE_SERVER_SUPPORT */
425 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
427 extern struct proc_dir_entry *proc_lustre_root;
428 extern struct dentry *debugfs_lustre_root;
429 extern struct kset *lustre_kset;
433 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
434 #define JOBSTATS_DISABLE "disable"
435 #define JOBSTATS_PROCNAME_UID "procname_uid"
436 #define JOBSTATS_NODELOCAL "nodelocal"
437 #define JOBSTATS_SESSION "session"
439 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats,
441 enum lprocfs_counter_config cntr_umask);
442 struct obd_job_stats {
443 struct cfs_hash *ojs_hash; /* hash of jobids */
444 struct list_head ojs_list; /* list of job_stat structs */
445 spinlock_t ojs_lock; /* protect ojs_list/js_list */
446 ktime_t ojs_cleanup_interval;/* 1/2 expiry seconds */
447 ktime_t ojs_cleanup_last;/* previous cleanup time */
448 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
449 unsigned short ojs_cntr_num; /* number of stats in struct */
450 bool ojs_cleaning; /* currently expiring stats */
453 #ifdef CONFIG_PROC_FS
455 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
457 int lprocfs_stats_lock(struct lprocfs_stats *stats,
458 enum lprocfs_stats_lock_ops opc,
459 unsigned long *flags);
460 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
461 enum lprocfs_stats_lock_ops opc,
462 unsigned long *flags);
464 static inline unsigned int
465 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
467 unsigned int percpusize;
469 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
471 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
472 percpusize = L1_CACHE_ALIGN(percpusize);
477 static inline struct lprocfs_counter *
478 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
481 struct lprocfs_counter *cntr;
483 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
488 /* Two optimized LPROCFS counter increment functions are provided:
489 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
490 * lprocfs_counter_add(cntr) - use for multi-valued counters
491 * Counter data layout allows config flag, counter lock and the
492 * count itself to reside within a single cache line.
495 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
497 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
500 #define lprocfs_counter_incr(stats, idx) \
501 lprocfs_counter_add(stats, idx, 1)
502 #define lprocfs_counter_decr(stats, idx) \
503 lprocfs_counter_sub(stats, idx, 1)
505 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
506 struct lprocfs_counter_header *header,
507 enum lprocfs_stats_flags flags,
508 enum lprocfs_fields_flags field);
509 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
510 enum lprocfs_fields_flags field);
512 extern struct lprocfs_stats *
513 lprocfs_stats_alloc(unsigned int num, enum lprocfs_stats_flags flags);
514 extern void lprocfs_stats_clear(struct lprocfs_stats *stats);
515 extern void lprocfs_stats_free(struct lprocfs_stats **stats);
516 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
517 extern int lprocfs_alloc_obd_stats(struct obd_device *obd,
518 unsigned int num_stats);
519 extern int lprocfs_alloc_md_stats(struct obd_device *obd,
520 unsigned int num_private_stats);
521 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
522 enum lprocfs_counter_config config,
524 extern void lprocfs_counter_init_units(struct lprocfs_stats *stats, int index,
525 enum lprocfs_counter_config config,
526 const char *name, const char *units);
527 extern void lprocfs_free_obd_stats(struct obd_device *obd);
528 extern void lprocfs_free_md_stats(struct obd_device *obd);
531 extern int lprocfs_add_clear_entry(struct obd_device *obd,
532 struct proc_dir_entry *entry);
533 #ifdef HAVE_SERVER_SUPPORT
534 extern int lprocfs_exp_setup(struct obd_export *exp, struct lnet_nid *peer_nid);
535 extern int lprocfs_exp_cleanup(struct obd_export *exp);
536 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
537 const char *format, ...);
539 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
542 extern struct proc_dir_entry *
543 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
544 void *data, const struct proc_ops *ops);
545 extern struct proc_dir_entry *
546 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
547 const char *format, ...);
548 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
549 #ifdef HAVE_SERVER_SUPPORT
551 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
552 size_t count, loff_t *off);
553 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
555 extern int lprocfs_stats_register(struct proc_dir_entry *root, const char *name,
556 struct lprocfs_stats *stats);
557 extern const struct file_operations ldebugfs_stats_seq_fops;
559 /* lprocfs_status.c */
560 extern void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *var,
562 extern struct dentry *ldebugfs_register(const char *name,
563 struct dentry *parent,
564 struct ldebugfs_vars *list,
566 extern int lprocfs_add_vars(struct proc_dir_entry *root,
567 struct lprocfs_vars *var, void *data);
569 extern struct proc_dir_entry *
570 lprocfs_register(const char *name, struct proc_dir_entry *parent,
571 struct lprocfs_vars *list, void *data);
573 extern void lprocfs_remove(struct proc_dir_entry **root);
574 extern void lprocfs_remove_proc_entry(const char *name,
575 struct proc_dir_entry *parent);
576 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
577 extern int lprocfs_obd_cleanup(struct obd_device *obd);
579 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
580 mode_t mode, const struct proc_ops *seq_fops,
582 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
583 mode_t mode, const struct proc_ops *seq_fops,
585 extern void lprocfs_stats_header(struct seq_file *seq, ktime_t now,
586 ktime_t ts_init, int width, const char *colon,
587 bool show_units, const char *prefix);
588 extern unsigned int obd_enable_stats_header;
590 /* Generic callbacks */
591 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
592 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
593 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
594 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
595 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
596 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
597 #ifdef HAVE_SERVER_SUPPORT
598 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
600 ssize_t grant_check_threshold_show(struct kobject *kobj,
601 struct attribute *attr, char *buf);
602 ssize_t grant_check_threshold_store(struct kobject *kobj,
603 struct attribute *attr,
604 const char *buffer, size_t count);
605 ssize_t eviction_count_show(struct kobject *kobj, struct attribute *attr,
608 struct adaptive_timeout;
609 extern int lprocfs_at_hist_helper(struct seq_file *m,
610 struct adaptive_timeout *at);
611 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
613 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
614 size_t count, loff_t *off);
615 #ifdef HAVE_SERVER_SUPPORT
617 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
618 size_t count, loff_t *off);
620 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
621 const char *buffer, size_t count);
622 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
626 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
627 size_t count, loff_t *off);
628 static inline ssize_t
629 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
630 size_t count, loff_t *off)
632 return ldebugfs_import_seq_write(file, buffer, count, off);
635 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
637 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
638 size_t count, loff_t *off);
640 int string_to_size(u64 *size, const char *buffer, size_t count);
641 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
642 const char *defunit);
643 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
644 char *lprocfs_find_named_value(const char *buffer, const char *name,
646 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
647 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
648 void lprocfs_oh_clear(struct obd_histogram *oh);
649 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
651 void lprocfs_oh_tally_pcpu(struct obd_hist_pcpu *oh, unsigned int value);
652 void lprocfs_oh_tally_log2_pcpu(struct obd_hist_pcpu *oh, unsigned int value);
653 int lprocfs_oh_alloc_pcpu(struct obd_hist_pcpu *oh);
654 void lprocfs_oh_clear_pcpu(struct obd_hist_pcpu *oh);
655 void lprocfs_oh_release_pcpu(struct obd_hist_pcpu *oh);
656 unsigned long lprocfs_oh_sum_pcpu(struct obd_hist_pcpu *oh);
657 unsigned long lprocfs_oh_counter_pcpu(struct obd_hist_pcpu *oh,
660 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
661 struct lprocfs_counter *cnt);
663 #ifdef HAVE_SERVER_SUPPORT
664 /* lprocfs_status.c: recovery status */
665 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
667 /* lprocfs: display the uuid of stale clients */
668 int lprocfs_recovery_stale_clients_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 *i, struct file *f);
687 extern int lprocfs_seq_release(struct inode *i, struct file *f);
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;
865 #define LUSTRE_OBD_UINT_PARAM_ATTR(name)\
866 static ssize_t name##_show(struct kobject *kobj, struct attribute *attr,\
870 struct obd_device *obd = \
871 container_of(kobj, struct obd_device, obd_kset.kobj); \
872 rc = snprintf(buf, PAGE_SIZE, "%u\n", obd->obd_##name); \
875 static ssize_t name##_store(struct kobject *kobj, struct attribute *attr,\
876 const char *buffer, size_t count) \
880 struct obd_device *obd = \
881 container_of(kobj, struct obd_device, obd_kset.kobj); \
882 rc = kstrtouint(buffer, 10, &val); \
885 obd->obd_##name = val; \
891 struct ptlrpc_request;
892 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
894 #ifdef HAVE_SERVER_SUPPORT
895 /* lprocfs_jobstats.c */
896 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
897 int event, long amount);
898 void lprocfs_job_stats_fini(struct obd_device *obd);
899 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
900 cntr_init_callback fn);
901 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
903 ssize_t job_cleanup_interval_store(struct kobject *kobj,
904 struct attribute *attr,
905 const char *buffer, size_t count);
906 /* lproc_status_server.c */
907 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
909 ssize_t recovery_time_soft_store(struct kobject *kobj,
910 struct attribute *attr,
911 const char *buffer, size_t count);
912 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
914 ssize_t recovery_time_hard_store(struct kobject *kobj,
915 struct attribute *attr,
916 const char *buffer, size_t count);
917 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
921 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
922 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
923 const char __user *buffer,
924 size_t count, loff_t *off);
925 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
927 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
928 const char *buffer, size_t count);
930 struct root_squash_info;
931 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
932 struct root_squash_info *squash, char *name);
933 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
934 struct root_squash_info *squash, char *name);
936 #else /* !CONFIG_PROC_FS */
938 #define proc_lustre_root NULL
940 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
941 int index, long amount)
945 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int index)
949 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
950 int index, long amount)
954 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats, int index)
958 static inline void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
959 enum lprocfs_counter_config config,
964 static inline void lprocfs_counter_init_units(struct lprocfs_stats *stats,
965 int index, enum lprocfs_counter_config config,
966 const char *name, const char *units)
970 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
971 enum lprocfs_fields_flags field)
976 /* NB: we return !NULL to satisfy error checker */
977 static inline struct lprocfs_stats *
978 lprocfs_stats_alloc(unsigned int num, enum lprocfs_stats_flags flags)
980 return (struct lprocfs_stats *)1;
983 static inline void lprocfs_stats_clear(struct lprocfs_stats *stats)
987 static inline void lprocfs_stats_free(struct lprocfs_stats **stats)
991 static inline int lprocfs_stats_register(struct proc_dir_entry *root,
993 struct lprocfs_stats *stats)
998 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1002 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
1003 unsigned int num_stats)
1008 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
1009 unsigned int num_private_stats)
1014 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
1018 static inline void lprocfs_free_md_stats(struct obd_device *obd)
1023 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
1028 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
1032 #ifdef HAVE_SERVER_SUPPORT
1034 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
1035 const char __user *buffer,
1036 size_t count, loff_t *off)
1041 static inline int lprocfs_nid_stats_clear_seq_show(struct seq_file *m,
1047 static inline int lprocfs_exp_setup(struct obd_export *exp,
1048 struct lnet_nid *peer_nid)
1053 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
1058 static inline struct proc_dir_entry *
1059 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
1060 void *data, const struct file_operations *fops)
1065 static inline struct proc_dir_entry *
1066 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
1067 const char *format, ...)
1072 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
1073 struct lprocfs_vars *var, void *data)
1078 static inline struct proc_dir_entry *
1079 lprocfs_register(const char *name, struct proc_dir_entry *parent,
1080 struct lprocfs_vars *list, void *data)
1085 static inline void lprocfs_remove(struct proc_dir_entry **root)
1089 static inline void lprocfs_remove_proc_entry(const char *name,
1090 struct proc_dir_entry *parent)
1094 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
1099 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
1104 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
1109 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
1114 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
1119 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
1124 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1128 #ifdef HAVE_SERVER_SUPPORT
1129 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
1134 struct adaptive_timeout;
1135 static inline int lprocfs_at_hist_helper(struct seq_file *m,
1136 struct adaptive_timeout *at)
1141 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1146 static inline ssize_t
1147 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
1148 size_t count, loff_t *off)
1152 #ifdef HAVE_SERVER_SUPPORT
1153 static inline ssize_t
1154 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
1155 size_t count, loff_t *off)
1161 static inline ssize_t
1162 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1163 size_t count, loff_t *off)
1168 static inline ssize_t
1169 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
1170 size_t count, loff_t *off)
1175 static inline ssize_t
1176 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1177 size_t count, loff_t *off)
1183 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1188 static inline ssize_t
1189 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1190 size_t count, loff_t *off)
1195 /* Statfs helpers */
1197 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1203 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1209 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1215 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1221 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1227 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1233 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1238 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1243 void lprocfs_oh_clear(struct obd_histogram *oh)
1248 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1254 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1255 struct lprocfs_counter *cnt)
1260 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1261 enum lprocfs_fields_flags field)
1266 #define LPROC_SEQ_FOPS_RO(name)
1267 #define LPROC_SEQ_FOPS(name)
1268 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1269 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1270 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1272 /* lprocfs_jobstats.c */
1274 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1281 void lprocfs_job_stats_fini(struct obd_device *obd)
1286 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1287 cntr_init_callback fn)
1293 /* lproc_ptlrpc.c */
1294 #define target_print_req NULL
1296 #endif /* CONFIG_PROC_FS */
1298 #endif /* LPROCFS_STATUS_H */