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];
106 RENAME_SAMEDIR_SIZE = 0,
107 RENAME_CROSSDIR_SRC_SIZE,
108 RENAME_CROSSDIR_TGT_SIZE,
112 struct rename_stats {
114 struct obd_histogram rs_hist[RENAME_LAST];
117 /* An lprocfs counter can be configured using the enum bit masks below.
119 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
120 * protects this counter from concurrent updates. If not specified,
121 * lprocfs an internal per-counter lock variable. External locks are
122 * not used to protect counter increments, but are used to protect
123 * counter readout and resets.
125 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
126 * (i.e. counter can be incremented by more than "1"). When specified,
127 * the counter maintains min, max and sum in addition to a simple
128 * invocation count. This allows averages to be be computed.
129 * If not specified, the counter is an increment-by-1 counter.
130 * min, max, sum, etc. are not maintained.
132 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
133 * squares (for multi-valued counter samples only). This allows
134 * external computation of standard deviation, but involves a 64-bit
135 * multiply per counter increment.
139 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
140 LPROCFS_CNTR_AVGMINMAX = 0x0002,
141 LPROCFS_CNTR_STDDEV = 0x0004,
143 /* counter data type */
144 LPROCFS_TYPE_REQS = 0x0100,
145 LPROCFS_TYPE_BYTES = 0x0200,
146 LPROCFS_TYPE_PAGES = 0x0400,
147 LPROCFS_TYPE_USEC = 0x0800,
149 LPROCFS_TYPE_LATENCY = LPROCFS_TYPE_USEC |
150 LPROCFS_CNTR_AVGMINMAX |
152 LPROCFS_TYPE_BYTES_FULL = LPROCFS_TYPE_BYTES |
153 LPROCFS_CNTR_AVGMINMAX |
156 #define LC_MIN_INIT ((~(__u64)0) >> 1)
158 struct lprocfs_counter_header {
159 unsigned int lc_config;
160 const char *lc_name; /* must be static */
161 const char *lc_units; /* must be static */
164 struct lprocfs_counter {
170 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
171 * for irq context counter, i.e. stats with
172 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
175 __s64 lc_array_sum[1];
177 #define lc_sum lc_array_sum[0]
178 #define lc_sum_irq lc_array_sum[1]
180 struct lprocfs_percpu {
181 struct lprocfs_counter lp_cntr[0];
184 enum lprocfs_stats_lock_ops {
185 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
186 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
189 enum lprocfs_stats_flags {
190 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
191 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
192 * area and need locking */
193 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
196 enum lprocfs_fields_flags {
197 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
198 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
199 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
200 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
201 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
202 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
203 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
206 struct lprocfs_stats {
208 unsigned short ls_num;
209 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
210 unsigned short ls_biggest_alloc_num;
211 enum lprocfs_stats_flags ls_flags;
213 /* Lock used when there are no percpu stats areas; For percpu stats,
214 * it is used to protect ls_biggest_alloc_num change */
217 /* has ls_num of counter headers */
218 struct lprocfs_counter_header *ls_cnt_header;
219 struct lprocfs_percpu *ls_percpu[0];
222 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
224 /* Pack all opcodes down into a single monotonically increasing index */
225 static inline int opcode_offset(__u32 opc) {
226 if (opc < OST_LAST_OPC) {
228 return (opc - OST_FIRST_OPC);
229 } else if (opc < MDS_LAST_OPC) {
231 return (opc - MDS_FIRST_OPC +
233 } else if (opc < LDLM_LAST_OPC) {
235 return (opc - LDLM_FIRST_OPC +
238 } else if (opc < MGS_LAST_OPC) {
240 return (opc - MGS_FIRST_OPC +
244 } else if (opc < OBD_LAST_OPC) {
246 return (opc - OBD_FIRST_OPC +
251 } else if (opc < LLOG_LAST_OPC) {
253 return (opc - LLOG_FIRST_OPC +
259 } else if (opc < QUOTA_LAST_OPC) {
261 return (opc - QUOTA_FIRST_OPC +
268 } else if (opc < SEQ_LAST_OPC) {
270 return (opc - SEQ_FIRST_OPC +
278 } else if (opc < SEC_LAST_OPC) {
280 return (opc - SEC_FIRST_OPC +
289 } else if (opc < FLD_LAST_OPC) {
291 return (opc - FLD_FIRST_OPC +
301 #ifdef HAVE_SERVER_SUPPORT
302 } else if (opc < OUT_UPDATE_LAST_OPC) {
304 return (opc - OUT_UPDATE_FIRST_OPC +
315 } else if (opc < LFSCK_LAST_OPC) {
317 return (opc - LFSCK_FIRST_OPC +
318 OPC_RANGE(OUT_UPDATE) +
329 #endif /* HAVE_SERVER_SUPPORT */
336 #define LUSTRE_MAX_OPCODES_CLIENT (OPC_RANGE(OST) + \
347 #ifdef HAVE_SERVER_SUPPORT
348 #define LUSTRE_MAX_OPCODES (LUSTRE_MAX_OPCODES_CLIENT + \
349 OPC_RANGE(OUT_UPDATE) + \
352 #define LUSTRE_MAX_OPCODES LUSTRE_MAX_OPCODES_CLIENT
355 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
359 PTLRPC_REQWAIT_CNTR = 0,
360 PTLRPC_REQQDEPTH_CNTR,
361 PTLRPC_REQACTIVE_CNTR,
363 PTLRPC_REQBUF_AVAIL_CNTR,
367 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
369 enum lprocfs_extra_opc {
370 LDLM_GLIMPSE_ENQUEUE = 0,
388 #ifdef HAVE_SERVER_SUPPORT
394 BRW_R_DISCONT_BLOCKS,
395 BRW_W_DISCONT_BLOCKS,
407 struct brw_stats_props {
408 const char *bsp_name;
409 const char *bsp_units;
415 struct obd_histogram bs_hist[BRW_RW_STATS_NUM];
416 struct brw_stats_props bs_props[BRW_RW_STATS_NUM / 2];
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 unsigned conf, const char *name,
530 extern void lprocfs_free_obd_stats(struct obd_device *obd);
531 extern void lprocfs_free_md_stats(struct obd_device *obd);
534 extern int lprocfs_add_clear_entry(struct obd_device *obd,
535 struct proc_dir_entry *entry);
536 #ifdef HAVE_SERVER_SUPPORT
537 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
538 extern int lprocfs_exp_cleanup(struct obd_export *exp);
539 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
540 const char *format, ...);
542 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
545 extern struct proc_dir_entry *
546 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
547 void *data, const struct proc_ops *ops);
548 extern struct proc_dir_entry *
549 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
550 const char *format, ...);
551 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
552 #ifdef HAVE_SERVER_SUPPORT
554 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
555 size_t count, loff_t *off);
556 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
558 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
559 struct lprocfs_stats *stats);
560 extern const struct file_operations ldebugfs_stats_seq_fops;
562 /* lprocfs_status.c */
563 extern void ldebugfs_add_vars(struct dentry *parent, struct ldebugfs_vars *var,
565 extern struct dentry *ldebugfs_register(const char *name,
566 struct dentry *parent,
567 struct ldebugfs_vars *list,
569 extern int lprocfs_add_vars(struct proc_dir_entry *root,
570 struct lprocfs_vars *var, void *data);
572 extern struct proc_dir_entry *
573 lprocfs_register(const char *name, struct proc_dir_entry *parent,
574 struct lprocfs_vars *list, void *data);
576 extern void lprocfs_remove(struct proc_dir_entry **root);
577 extern void lprocfs_remove_proc_entry(const char *name,
578 struct proc_dir_entry *parent);
579 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
580 extern int lprocfs_obd_cleanup(struct obd_device *obd);
582 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
583 mode_t mode, const struct proc_ops *seq_fops,
585 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
586 mode_t mode, const struct proc_ops *seq_fops,
588 extern void lprocfs_stats_header(struct seq_file *seq, ktime_t now,
589 ktime_t ts_init, int width, const char *colon,
592 /* Generic callbacks */
593 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
594 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
595 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
596 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
597 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
598 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
599 #ifdef HAVE_SERVER_SUPPORT
600 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
603 struct adaptive_timeout;
604 extern int lprocfs_at_hist_helper(struct seq_file *m,
605 struct adaptive_timeout *at);
606 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
608 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
609 size_t count, loff_t *off);
610 #ifdef HAVE_SERVER_SUPPORT
612 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
613 size_t count, loff_t *off);
615 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
616 const char *buffer, size_t count);
617 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
621 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
622 size_t count, loff_t *off);
623 static inline ssize_t
624 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
625 size_t count, loff_t *off)
627 return ldebugfs_import_seq_write(file, buffer, count, off);
630 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
632 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
633 size_t count, loff_t *off);
635 int string_to_size(u64 *size, const char *buffer, size_t count);
636 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
637 const char *defunit);
638 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
639 char *lprocfs_find_named_value(const char *buffer, const char *name,
641 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
642 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
643 void lprocfs_oh_clear(struct obd_histogram *oh);
644 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
646 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
647 struct lprocfs_counter *cnt);
649 #ifdef HAVE_SERVER_SUPPORT
650 /* lprocfs_status.c: recovery status */
651 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
653 /* lprocfs_status.c: hash statistics */
654 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
656 /* lprocfs_status.c: IR factor */
657 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
659 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
660 const char *buffer, size_t count);
663 /* lprocfs_status.c: dump pages on cksum error */
664 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
666 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
667 size_t count, loff_t *off);
669 extern int lprocfs_single_release(struct inode *, struct file *);
670 extern int lprocfs_seq_release(struct inode *, struct file *);
672 /* You must use these macros when you want to refer to
673 * the import in a client obd_device for a lprocfs entry
674 * Note that it is not safe to 'goto', 'return' or 'break'
675 * out of the body of this statement. It *IS* safe to
676 * 'goto' the a label inside the statement, or to 'continue'
677 * to get out of the statement.
680 #define with_imp_locked_nested(__obd, __imp, __rc, __nest) \
681 for (down_read_nested(&(__obd)->u.cli.cl_sem, __nest), \
682 __imp = (__obd)->u.cli.cl_import, \
683 __rc = __imp ? 0 : -ENODEV; \
684 __imp ? 1 : (up_read(&(__obd)->u.cli.cl_sem), 0); \
687 #define with_imp_locked(__obd, __imp, __rc) \
688 with_imp_locked_nested(__obd, __imp, __rc, 0)
690 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
691 * debugfs entries; otherwise, you will define name##_seq_write function also
692 * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
693 * Finally, call debugfs_create_file(filename, 0444, obd, data, &name#_fops);
695 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write) \
696 static int name##_single_open(struct inode *inode, struct file *file) \
698 return single_open(file, name##_seq_show, inode->i_private); \
700 static const struct file_operations name##_fops = { \
701 .owner = THIS_MODULE, \
702 .open = name##_single_open, \
704 .write = custom_seq_write, \
705 .llseek = seq_lseek, \
706 .release = single_release, \
709 #define LDEBUGFS_SEQ_FOPS_RO(name) __LDEBUGFS_SEQ_FOPS(name, NULL)
710 #define LDEBUGFS_SEQ_FOPS(name) __LDEBUGFS_SEQ_FOPS(name, \
713 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type) \
714 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
718 return lprocfs_##type##_seq_show(m, m->private); \
720 LDEBUGFS_SEQ_FOPS_RO(name##_##type)
722 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type) \
723 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
727 return lprocfs_##type##_seq_show(m, m->private); \
729 static ssize_t name##_##type##_seq_write(struct file *file, \
730 const char __user *buffer, size_t count, \
733 struct seq_file *seq = file->private_data; \
737 return ldebugfs_##type##_seq_write(file, buffer, count, \
740 LDEBUGFS_SEQ_FOPS(name##_##type);
742 #define LDEBUGFS_FOPS_WR_ONLY(name, type) \
743 static ssize_t name##_##type##_write(struct file *file, \
744 const char __user *buffer, size_t count, \
747 return ldebugfs_##type##_seq_write(file, buffer, count, \
750 static int name##_##type##_open(struct inode *inode, \
753 return single_open(file, NULL, inode->i_private); \
755 static const struct file_operations name##_##type##_fops = { \
756 .open = name##_##type##_open, \
757 .write = name##_##type##_write, \
758 .release = single_release, \
761 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
762 * proc entries; otherwise, you will define name##_seq_write function also for
763 * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
764 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
766 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
767 static int name##_single_open(struct inode *inode, struct file *file) \
769 return single_open(file, name##_seq_show, \
770 inode->i_private ? inode->i_private : \
773 static const struct proc_ops name##_fops = { \
774 PROC_OWNER(THIS_MODULE) \
775 .proc_open = name##_single_open, \
776 .proc_read = seq_read, \
777 .proc_write = custom_seq_write, \
778 .proc_lseek = seq_lseek, \
779 .proc_release = lprocfs_single_release, \
782 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
783 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
785 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
786 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
788 return lprocfs_##type##_seq_show(m, m->private); \
790 LPROC_SEQ_FOPS_RO(name##_##type)
792 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
793 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
795 return lprocfs_##type##_seq_show(m, m->private); \
797 static ssize_t name##_##type##_seq_write(struct file *file, \
798 const char __user *buffer, size_t count, \
801 struct seq_file *seq = file->private_data; \
802 return lprocfs_##type##_seq_write(file, buffer, \
803 count, seq->private); \
805 LPROC_SEQ_FOPS(name##_##type);
807 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
808 static ssize_t name##_##type##_write(struct file *file, \
809 const char __user *buffer, size_t count, \
812 return lprocfs_##type##_seq_write(file, buffer, count, off);\
814 static int name##_##type##_open(struct inode *inode, struct file *file)\
816 return single_open(file, NULL, \
817 inode->i_private ? inode->i_private : \
820 static const struct proc_ops name##_##type##_fops = { \
821 .proc_open = name##_##type##_open, \
822 .proc_write = name##_##type##_write, \
823 .proc_release = lprocfs_single_release, \
827 struct attribute attr;
828 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
830 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
831 const char *buf, size_t len);
834 #define LUSTRE_ATTR(name, mode, show, store) \
835 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
837 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
838 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
839 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
841 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
843 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
844 const char *buf, size_t len);
846 extern const struct sysfs_ops lustre_sysfs_ops;
849 struct ptlrpc_request;
850 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
852 #ifdef HAVE_SERVER_SUPPORT
853 /* lprocfs_jobstats.c */
854 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
855 int event, long amount);
856 void lprocfs_job_stats_fini(struct obd_device *obd);
857 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
858 cntr_init_callback fn);
859 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
861 ssize_t job_cleanup_interval_store(struct kobject *kobj,
862 struct attribute *attr,
863 const char *buffer, size_t count);
864 /* lproc_status_server.c */
865 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
867 ssize_t recovery_time_soft_store(struct kobject *kobj,
868 struct attribute *attr,
869 const char *buffer, size_t count);
870 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
872 ssize_t recovery_time_hard_store(struct kobject *kobj,
873 struct attribute *attr,
874 const char *buffer, size_t count);
875 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
879 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
880 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
881 const char __user *buffer,
882 size_t count, loff_t *off);
883 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
885 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
886 const char *buffer, size_t count);
888 struct root_squash_info;
889 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
890 struct root_squash_info *squash, char *name);
891 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
892 struct root_squash_info *squash, char *name);
894 #else /* !CONFIG_PROC_FS */
896 #define proc_lustre_root NULL
898 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
899 int index, long amount)
901 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
904 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
905 int index, long amount)
907 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
910 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
911 int index, unsigned conf,
912 const char *name, const char *units)
915 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
916 enum lprocfs_fields_flags field)
919 /* NB: we return !NULL to satisfy error checker */
920 static inline struct lprocfs_stats *
921 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
922 { return (struct lprocfs_stats *)1; }
923 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
925 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
927 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
929 struct lprocfs_stats *stats)
931 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
933 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
934 unsigned int num_stats)
936 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
937 unsigned int num_private_stats)
939 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
941 static inline void lprocfs_free_md_stats(struct obd_device *obd)
945 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
947 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
949 #ifdef HAVE_SERVER_SUPPORT
951 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
952 const char __user *buffer,
953 size_t count, loff_t *off)
956 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
958 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
961 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
963 static inline struct proc_dir_entry *
964 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
965 void *data, const struct file_operations *fops)
967 static inline struct proc_dir_entry *
968 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
969 const char *format, ...)
971 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
972 struct lprocfs_vars *var, void *data)
974 static inline struct proc_dir_entry *
975 lprocfs_register(const char *name, struct proc_dir_entry *parent,
976 struct lprocfs_vars *list, void *data)
978 static inline void lprocfs_remove(struct proc_dir_entry **root)
980 static inline void lprocfs_remove_proc_entry(const char *name,
981 struct proc_dir_entry *parent)
983 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
985 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
987 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
989 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
991 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
993 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
995 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
997 #ifdef HAVE_SERVER_SUPPORT
998 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
1001 struct adaptive_timeout;
1002 static inline int lprocfs_at_hist_helper(struct seq_file *m,
1003 struct adaptive_timeout *at)
1005 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1007 static inline ssize_t
1008 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
1009 size_t count, loff_t *off)
1011 #ifdef HAVE_SERVER_SUPPORT
1012 static inline ssize_t
1013 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
1014 size_t count, loff_t *off)
1017 static inline ssize_t
1018 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1019 size_t count, loff_t *off)
1021 static inline ssize_t
1022 ldebugfs_import_seq_write(struct file *file, const char __user *buffer,
1023 size_t count, loff_t *off)
1025 static inline ssize_t
1026 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1027 size_t count, loff_t *off)
1030 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1032 static inline ssize_t
1033 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1034 size_t count, loff_t *off)
1037 /* Statfs helpers */
1039 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1042 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1045 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1048 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1051 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1054 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1057 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1060 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1063 void lprocfs_oh_clear(struct obd_histogram *oh)
1066 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1069 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1070 struct lprocfs_counter *cnt)
1073 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1074 enum lprocfs_fields_flags field)
1075 { return (__u64)0; }
1077 #define LPROC_SEQ_FOPS_RO(name)
1078 #define LPROC_SEQ_FOPS(name)
1079 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1080 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1081 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1083 /* lprocfs_jobstats.c */
1085 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1089 void lprocfs_job_stats_fini(struct obd_device *obd)
1092 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1093 cntr_init_callback fn)
1097 /* lproc_ptlrpc.c */
1098 #define target_print_req NULL
1100 #endif /* CONFIG_PROC_FS */
1102 #endif /* LPROCFS_STATUS_H */