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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/include/lprocfs_status.h
34 * Top level header file for LProc
36 * Author: Hariharan Thantry thantry@users.sourceforge.net
38 #ifndef _LPROCFS_STATUS_H
39 #define _LPROCFS_STATUS_H
42 #include <linux/proc_fs.h>
43 #include <linux/debugfs.h>
44 #include <linux/rwsem.h>
45 #include <linux/spinlock.h>
46 #include <linux/string_helpers.h>
47 #include <linux/seq_file.h>
49 #include <libcfs/libcfs.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 file_operations *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 } else if (opc < OUT_UPDATE_LAST_OPC) {
323 return (opc - OUT_UPDATE_FIRST_OPC +
334 } else if (opc < LFSCK_LAST_OPC) {
336 return (opc - LFSCK_FIRST_OPC +
337 OPC_RANGE(OUT_UPDATE) +
355 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
365 OPC_RANGE(OUT_UPDATE) + \
368 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
372 PTLRPC_REQWAIT_CNTR = 0,
373 PTLRPC_REQQDEPTH_CNTR,
374 PTLRPC_REQACTIVE_CNTR,
376 PTLRPC_REQBUF_AVAIL_CNTR,
380 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
382 enum lprocfs_extra_opc {
383 LDLM_GLIMPSE_ENQUEUE = 0,
401 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
403 extern struct proc_dir_entry *proc_lustre_root;
404 extern struct dentry *debugfs_lustre_root;
405 extern struct kset *lustre_kset;
408 struct obd_histogram;
410 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
411 #define JOBSTATS_DISABLE "disable"
412 #define JOBSTATS_PROCNAME_UID "procname_uid"
413 #define JOBSTATS_NODELOCAL "nodelocal"
414 #define JOBSTATS_SESSION "session"
416 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats,
417 unsigned int offset);
419 struct obd_job_stats {
420 struct cfs_hash *ojs_hash; /* hash of jobids */
421 struct list_head ojs_list; /* list of job_stat structs */
422 rwlock_t ojs_lock; /* protect ojs_list/js_list */
423 unsigned int ojs_cleanup_interval;/* seconds before expiry */
424 time64_t ojs_last_cleanup; /* previous cleanup time */
425 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
426 unsigned short ojs_cntr_num; /* number of stats in struct */
427 bool ojs_cleaning; /* currently expiring stats */
430 #ifdef CONFIG_PROC_FS
432 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
434 int lprocfs_stats_lock(struct lprocfs_stats *stats,
435 enum lprocfs_stats_lock_ops opc,
436 unsigned long *flags);
437 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
438 enum lprocfs_stats_lock_ops opc,
439 unsigned long *flags);
441 static inline unsigned int
442 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
444 unsigned int percpusize;
446 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
448 /* irq safe stats need lc_array_sum[1] */
449 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
450 percpusize += stats->ls_num * sizeof(__s64);
452 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
453 percpusize = L1_CACHE_ALIGN(percpusize);
458 static inline struct lprocfs_counter *
459 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
462 struct lprocfs_counter *cntr;
464 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
466 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
467 cntr = (void *)cntr + index * sizeof(__s64);
472 /* Two optimized LPROCFS counter increment functions are provided:
473 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
474 * lprocfs_counter_add(cntr) - use for multi-valued counters
475 * Counter data layout allows config flag, counter lock and the
476 * count itself to reside within a single cache line.
479 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
481 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
484 #define lprocfs_counter_incr(stats, idx) \
485 lprocfs_counter_add(stats, idx, 1)
486 #define lprocfs_counter_decr(stats, idx) \
487 lprocfs_counter_sub(stats, idx, 1)
489 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
490 struct lprocfs_counter_header *header,
491 enum lprocfs_stats_flags flags,
492 enum lprocfs_fields_flags field);
493 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
494 enum lprocfs_fields_flags field);
496 extern struct lprocfs_stats *
497 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
498 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
499 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
500 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
501 extern int lprocfs_alloc_obd_stats(struct obd_device *obd,
502 unsigned int num_stats);
503 extern int lprocfs_alloc_md_stats(struct obd_device *obd,
504 unsigned int num_private_stats);
505 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
506 unsigned conf, const char *name,
508 extern void lprocfs_free_obd_stats(struct obd_device *obd);
509 extern void lprocfs_free_md_stats(struct obd_device *obd);
512 extern int lprocfs_add_clear_entry(struct obd_device *obd,
513 struct proc_dir_entry *entry);
514 #ifdef HAVE_SERVER_SUPPORT
515 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
516 extern int lprocfs_exp_cleanup(struct obd_export *exp);
517 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
518 const char *format, ...);
520 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
523 extern struct proc_dir_entry *
524 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
525 void *data, const struct file_operations *fops);
526 extern struct proc_dir_entry *
527 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
528 const char *format, ...);
529 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
530 #ifdef HAVE_SERVER_SUPPORT
532 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
533 size_t count, loff_t *off);
534 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
536 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
537 struct lprocfs_stats *stats);
538 extern const struct file_operations ldebugfs_stats_seq_fops;
540 /* lprocfs_status.c */
541 extern void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *var,
543 extern struct dentry *ldebugfs_register(const char *name,
544 struct dentry *parent,
545 struct ldebugfs_vars *list,
547 extern int lprocfs_add_vars(struct proc_dir_entry *root,
548 struct lprocfs_vars *var, void *data);
550 extern struct proc_dir_entry *
551 lprocfs_register(const char *name, struct proc_dir_entry *parent,
552 struct lprocfs_vars *list, void *data);
554 extern void lprocfs_remove(struct proc_dir_entry **root);
555 extern void lprocfs_remove_proc_entry(const char *name,
556 struct proc_dir_entry *parent);
557 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
558 extern int lprocfs_obd_cleanup(struct obd_device *obd);
559 #ifdef HAVE_SERVER_SUPPORT
560 extern const struct file_operations lprocfs_evict_client_fops;
563 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
565 const struct file_operations *seq_fops,
567 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
569 const struct file_operations *seq_fops,
572 /* Generic callbacks */
573 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
574 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
575 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
576 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
577 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
578 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
579 #ifdef HAVE_SERVER_SUPPORT
580 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
583 struct adaptive_timeout;
584 extern int lprocfs_at_hist_helper(struct seq_file *m,
585 struct adaptive_timeout *at);
586 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
588 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
589 size_t count, loff_t *off);
590 #ifdef HAVE_SERVER_SUPPORT
592 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
593 size_t count, loff_t *off);
595 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
596 const char *buffer, size_t count);
597 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
601 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
602 size_t count, loff_t *off);
603 static inline ssize_t
604 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
605 size_t count, loff_t *off)
607 return ldebugfs_import_seq_write(file, buffer, count, off);
610 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
612 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
613 size_t count, loff_t *off);
615 int string_to_size(u64 *size, const char *buffer, size_t count);
616 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
617 const char *defunit);
618 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
619 char *lprocfs_find_named_value(const char *buffer, const char *name,
621 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
622 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
623 void lprocfs_oh_clear(struct obd_histogram *oh);
624 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
626 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
627 struct lprocfs_counter *cnt);
629 #ifdef HAVE_SERVER_SUPPORT
630 /* lprocfs_status.c: recovery status */
631 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
633 /* lprocfs_status.c: hash statistics */
634 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
636 /* lprocfs_status.c: IR factor */
637 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
639 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
640 const char *buffer, size_t count);
643 /* lprocfs_status.c: dump pages on cksum error */
644 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
646 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
647 size_t count, loff_t *off);
649 extern int lprocfs_single_release(struct inode *, struct file *);
650 extern int lprocfs_seq_release(struct inode *, struct file *);
652 /* You must use these macros when you want to refer to
653 * the import in a client obd_device for a lprocfs entry
655 #define with_imp_locked(__obd, __imp, __rc) \
656 for (down_read(&(__obd)->u.cli.cl_sem), \
657 __imp = (__obd)->u.cli.cl_import, \
658 __rc = __imp ? 0 : -ENODEV; \
659 __imp ? 1 : (up_read(&(__obd)->u.cli.cl_sem), 0); \
662 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
663 * debugfs entries; otherwise, you will define name##_seq_write function also
664 * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
665 * Finally, call debugfs_create_file(filename, 0444, obd, data, &name#_fops);
667 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write) \
668 static int name##_single_open(struct inode *inode, struct file *file) \
670 return single_open(file, name##_seq_show, inode->i_private); \
672 static const struct file_operations name##_fops = { \
673 .owner = THIS_MODULE, \
674 .open = name##_single_open, \
676 .write = custom_seq_write, \
677 .llseek = seq_lseek, \
678 .release = single_release, \
681 #define LDEBUGFS_SEQ_FOPS_RO(name) __LDEBUGFS_SEQ_FOPS(name, NULL)
682 #define LDEBUGFS_SEQ_FOPS(name) __LDEBUGFS_SEQ_FOPS(name, \
685 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type) \
686 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
690 return lprocfs_##type##_seq_show(m, m->private); \
692 LDEBUGFS_SEQ_FOPS_RO(name##_##type)
694 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type) \
695 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
699 return lprocfs_##type##_seq_show(m, m->private); \
701 static ssize_t name##_##type##_seq_write(struct file *file, \
702 const char __user *buffer, size_t count, \
705 struct seq_file *seq = file->private_data; \
709 return ldebugfs_##type##_seq_write(file, buffer, count, \
712 LDEBUGFS_SEQ_FOPS(name##_##type);
714 #define LDEBUGFS_FOPS_WR_ONLY(name, type) \
715 static ssize_t name##_##type##_write(struct file *file, \
716 const char __user *buffer, size_t count, \
719 return ldebugfs_##type##_seq_write(file, buffer, count, \
722 static int name##_##type##_open(struct inode *inode, \
725 return single_open(file, NULL, inode->i_private); \
727 static const struct file_operations name##_##type##_fops = { \
728 .open = name##_##type##_open, \
729 .write = name##_##type##_write, \
730 .release = single_release, \
733 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
734 * proc entries; otherwise, you will define name##_seq_write function also for
735 * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
736 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
738 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
739 static int name##_single_open(struct inode *inode, struct file *file) \
741 return single_open(file, name##_seq_show, \
742 inode->i_private ? inode->i_private : \
745 static const struct file_operations name##_fops = { \
746 .owner = THIS_MODULE, \
747 .open = name##_single_open, \
749 .write = custom_seq_write, \
750 .llseek = seq_lseek, \
751 .release = lprocfs_single_release, \
754 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
755 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
757 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
758 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
760 return lprocfs_##type##_seq_show(m, m->private); \
762 LPROC_SEQ_FOPS_RO(name##_##type)
764 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
765 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
767 return lprocfs_##type##_seq_show(m, m->private); \
769 static ssize_t name##_##type##_seq_write(struct file *file, \
770 const char __user *buffer, size_t count, \
773 struct seq_file *seq = file->private_data; \
774 return lprocfs_##type##_seq_write(file, buffer, \
775 count, seq->private); \
777 LPROC_SEQ_FOPS(name##_##type);
779 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
780 static ssize_t name##_##type##_write(struct file *file, \
781 const char __user *buffer, size_t count, \
784 return lprocfs_##type##_seq_write(file, buffer, count, off);\
786 static int name##_##type##_open(struct inode *inode, struct file *file)\
788 return single_open(file, NULL, \
789 inode->i_private ? inode->i_private : \
792 static const struct file_operations name##_##type##_fops = { \
793 .open = name##_##type##_open, \
794 .write = name##_##type##_write, \
795 .release = lprocfs_single_release, \
799 struct attribute attr;
800 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
802 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
803 const char *buf, size_t len);
806 #define LUSTRE_ATTR(name, mode, show, store) \
807 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
809 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
810 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
811 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
813 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
815 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
816 const char *buf, size_t len);
818 extern const struct sysfs_ops lustre_sysfs_ops;
821 struct ptlrpc_request;
822 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
824 #ifdef HAVE_SERVER_SUPPORT
825 /* lprocfs_jobstats.c */
826 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
827 int event, long amount);
828 void lprocfs_job_stats_fini(struct obd_device *obd);
829 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
830 cntr_init_callback fn);
831 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
833 ssize_t job_cleanup_interval_store(struct kobject *kobj,
834 struct attribute *attr,
835 const char *buffer, size_t count);
836 /* lproc_status_server.c */
837 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
839 ssize_t recovery_time_soft_store(struct kobject *kobj,
840 struct attribute *attr,
841 const char *buffer, size_t count);
842 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
844 ssize_t recovery_time_hard_store(struct kobject *kobj,
845 struct attribute *attr,
846 const char *buffer, size_t count);
847 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
851 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
852 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
853 const char __user *buffer,
854 size_t count, loff_t *off);
855 int lprocfs_obd_short_io_bytes_seq_show(struct seq_file *m, void *data);
856 ssize_t lprocfs_obd_short_io_bytes_seq_write(struct file *file,
857 const char __user *buffer,
858 size_t count, loff_t *off);
859 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
861 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
862 const char *buffer, size_t count);
864 struct root_squash_info;
865 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
866 struct root_squash_info *squash, char *name);
867 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
868 struct root_squash_info *squash, char *name);
870 #else /* !CONFIG_PROC_FS */
872 #define proc_lustre_root NULL
874 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
875 int index, long amount)
877 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
880 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
881 int index, long amount)
883 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
886 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
887 int index, unsigned conf,
888 const char *name, const char *units)
891 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
892 enum lprocfs_fields_flags field)
895 /* NB: we return !NULL to satisfy error checker */
896 static inline struct lprocfs_stats *
897 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
898 { return (struct lprocfs_stats *)1; }
899 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
901 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
903 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
905 struct lprocfs_stats *stats)
907 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
909 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
910 unsigned int num_stats)
912 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
913 unsigned int num_private_stats)
915 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
917 static inline void lprocfs_free_md_stats(struct obd_device *obd)
921 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
923 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
925 #ifdef HAVE_SERVER_SUPPORT
927 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
928 const char __user *buffer,
929 size_t count, loff_t *off)
932 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
934 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
937 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
939 static inline struct proc_dir_entry *
940 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
941 void *data, const struct file_operations *fops)
943 static inline struct proc_dir_entry *
944 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
945 const char *format, ...)
947 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
948 struct lprocfs_vars *var, void *data)
950 static inline struct proc_dir_entry *
951 lprocfs_register(const char *name, struct proc_dir_entry *parent,
952 struct lprocfs_vars *list, void *data)
954 static inline void lprocfs_remove(struct proc_dir_entry **root)
956 static inline void lprocfs_remove_proc_entry(const char *name,
957 struct proc_dir_entry *parent)
959 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
961 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
963 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
965 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
967 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
969 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
971 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
973 #ifdef HAVE_SERVER_SUPPORT
974 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
977 struct adaptive_timeout;
978 static inline int lprocfs_at_hist_helper(struct seq_file *m,
979 struct adaptive_timeout *at)
981 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
983 static inline ssize_t
984 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
985 size_t count, loff_t *off)
987 #ifdef HAVE_SERVER_SUPPORT
988 static inline ssize_t
989 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
990 size_t count, loff_t *off)
993 static inline ssize_t
994 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
995 size_t count, loff_t *off)
997 static inline ssize_t
998 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
999 size_t count, loff_t *off)
1001 static inline ssize_t
1002 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1003 size_t count, loff_t *off)
1006 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1008 static inline ssize_t
1009 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1010 size_t count, loff_t *off)
1013 /* Statfs helpers */
1015 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1018 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1021 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1024 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1027 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1030 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1033 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1036 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1039 void lprocfs_oh_clear(struct obd_histogram *oh)
1042 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1045 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1046 struct lprocfs_counter *cnt)
1049 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1050 enum lprocfs_fields_flags field)
1051 { return (__u64)0; }
1053 #define LPROC_SEQ_FOPS_RO(name)
1054 #define LPROC_SEQ_FOPS(name)
1055 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1056 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1057 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1059 /* lprocfs_jobstats.c */
1061 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1065 void lprocfs_job_stats_fini(struct obd_device *obd)
1068 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1069 cntr_init_callback fn)
1073 /* lproc_ptlrpc.c */
1074 #define target_print_req NULL
1076 #endif /* CONFIG_PROC_FS */
1078 #endif /* LPROCFS_STATUS_H */