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>
54 const struct file_operations *fops;
62 static inline unsigned int pct(unsigned long a, unsigned long b)
64 return b ? a * 100 / b : 0;
67 #define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))
68 #define MiB_TO_PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
71 * Append a space separated list of current set flags to str.
73 #define flag2str(port, flag) \
75 if ((port)->port##_##flag) { \
76 seq_printf(m, "%s" #flag, first ? "" : ", "); \
81 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
83 void obd_connect_data_seqprint(struct seq_file *m,
84 struct obd_connect_data *ocd);
86 /* if we find more consumers this could be generalized */
87 #define OBD_HIST_MAX 32
88 struct obd_histogram {
90 unsigned long oh_buckets[OBD_HIST_MAX];
102 BRW_R_DISCONT_BLOCKS,
103 BRW_W_DISCONT_BLOCKS,
112 struct obd_histogram hist[BRW_LAST];
116 RENAME_SAMEDIR_SIZE = 0,
117 RENAME_CROSSDIR_SRC_SIZE,
118 RENAME_CROSSDIR_TGT_SIZE,
122 struct rename_stats {
123 struct obd_histogram hist[RENAME_LAST];
126 /* An lprocfs counter can be configured using the enum bit masks below.
128 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
129 * protects this counter from concurrent updates. If not specified,
130 * lprocfs an internal per-counter lock variable. External locks are
131 * not used to protect counter increments, but are used to protect
132 * counter readout and resets.
134 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
135 * (i.e. counter can be incremented by more than "1"). When specified,
136 * the counter maintains min, max and sum in addition to a simple
137 * invocation count. This allows averages to be be computed.
138 * If not specified, the counter is an increment-by-1 counter.
139 * min, max, sum, etc. are not maintained.
141 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
142 * squares (for multi-valued counter samples only). This allows
143 * external computation of standard deviation, but involves a 64-bit
144 * multiply per counter increment.
148 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
149 LPROCFS_CNTR_AVGMINMAX = 0x0002,
150 LPROCFS_CNTR_STDDEV = 0x0004,
152 /* counter data type */
153 LPROCFS_TYPE_REQS = 0x0100,
154 LPROCFS_TYPE_BYTES = 0x0200,
155 LPROCFS_TYPE_PAGES = 0x0400,
156 LPROCFS_TYPE_USEC = 0x0800,
159 #define LC_MIN_INIT ((~(__u64)0) >> 1)
161 struct lprocfs_counter_header {
162 unsigned int lc_config;
163 const char *lc_name; /* must be static */
164 const char *lc_units; /* must be static */
167 struct lprocfs_counter {
173 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
174 * for irq context counter, i.e. stats with
175 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
178 __s64 lc_array_sum[1];
180 #define lc_sum lc_array_sum[0]
181 #define lc_sum_irq lc_array_sum[1]
183 struct lprocfs_percpu {
184 struct lprocfs_counter lp_cntr[0];
187 enum lprocfs_stats_lock_ops {
188 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
189 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
192 enum lprocfs_stats_flags {
193 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
194 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
195 * area and need locking */
196 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
199 enum lprocfs_fields_flags {
200 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
201 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
202 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
203 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
204 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
205 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
206 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
209 struct lprocfs_stats {
211 unsigned short ls_num;
212 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
213 unsigned short ls_biggest_alloc_num;
214 enum lprocfs_stats_flags ls_flags;
215 /* Lock used when there are no percpu stats areas; For percpu stats,
216 * it is used to protect ls_biggest_alloc_num change */
219 /* has ls_num of counter headers */
220 struct lprocfs_counter_header *ls_cnt_header;
221 struct lprocfs_percpu *ls_percpu[0];
224 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
226 /* Pack all opcodes down into a single monotonically increasing index */
227 static inline int opcode_offset(__u32 opc) {
228 if (opc < OST_LAST_OPC) {
230 return (opc - OST_FIRST_OPC);
231 } else if (opc < MDS_LAST_OPC) {
233 return (opc - MDS_FIRST_OPC +
235 } else if (opc < LDLM_LAST_OPC) {
237 return (opc - LDLM_FIRST_OPC +
240 } else if (opc < MGS_LAST_OPC) {
242 return (opc - MGS_FIRST_OPC +
246 } else if (opc < OBD_LAST_OPC) {
248 return (opc - OBD_FIRST_OPC +
253 } else if (opc < LLOG_LAST_OPC) {
255 return (opc - LLOG_FIRST_OPC +
261 } else if (opc < QUOTA_LAST_OPC) {
263 return (opc - QUOTA_FIRST_OPC +
270 } else if (opc < SEQ_LAST_OPC) {
272 return (opc - SEQ_FIRST_OPC +
280 } else if (opc < SEC_LAST_OPC) {
282 return (opc - SEC_FIRST_OPC +
291 } else if (opc < FLD_LAST_OPC) {
293 return (opc - FLD_FIRST_OPC +
303 } else if (opc < OUT_UPDATE_LAST_OPC) {
305 return (opc - OUT_UPDATE_FIRST_OPC +
316 } else if (opc < LFSCK_LAST_OPC) {
318 return (opc - LFSCK_FIRST_OPC +
319 OPC_RANGE(OUT_UPDATE) +
337 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
347 OPC_RANGE(OUT_UPDATE) + \
350 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
354 PTLRPC_REQWAIT_CNTR = 0,
355 PTLRPC_REQQDEPTH_CNTR,
356 PTLRPC_REQACTIVE_CNTR,
358 PTLRPC_REQBUF_AVAIL_CNTR,
362 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
364 enum lprocfs_extra_opc {
365 LDLM_GLIMPSE_ENQUEUE = 0,
383 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
385 extern struct proc_dir_entry *proc_lustre_root;
386 extern struct dentry *debugfs_lustre_root;
387 extern struct kset *lustre_kset;
390 struct obd_histogram;
392 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
393 #define JOBSTATS_DISABLE "disable"
394 #define JOBSTATS_PROCNAME_UID "procname_uid"
395 #define JOBSTATS_NODELOCAL "nodelocal"
396 #define JOBSTATS_SESSION "session"
398 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
400 struct obd_job_stats {
401 struct cfs_hash *ojs_hash; /* hash of jobids */
402 struct list_head ojs_list; /* list of job_stat structs */
403 rwlock_t ojs_lock; /* protect ojs_list/js_list */
404 unsigned int ojs_cleanup_interval;/* seconds before expiry */
405 time64_t ojs_last_cleanup; /* previous cleanup time */
406 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
407 unsigned short ojs_cntr_num; /* number of stats in struct */
408 bool ojs_cleaning; /* currently expiring stats */
411 #ifdef CONFIG_PROC_FS
413 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
415 int lprocfs_stats_lock(struct lprocfs_stats *stats,
416 enum lprocfs_stats_lock_ops opc,
417 unsigned long *flags);
418 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
419 enum lprocfs_stats_lock_ops opc,
420 unsigned long *flags);
422 static inline unsigned int
423 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
425 unsigned int percpusize;
427 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
429 /* irq safe stats need lc_array_sum[1] */
430 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
431 percpusize += stats->ls_num * sizeof(__s64);
433 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
434 percpusize = L1_CACHE_ALIGN(percpusize);
439 static inline struct lprocfs_counter *
440 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
443 struct lprocfs_counter *cntr;
445 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
447 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
448 cntr = (void *)cntr + index * sizeof(__s64);
453 /* Two optimized LPROCFS counter increment functions are provided:
454 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
455 * lprocfs_counter_add(cntr) - use for multi-valued counters
456 * Counter data layout allows config flag, counter lock and the
457 * count itself to reside within a single cache line.
460 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
462 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
465 #define lprocfs_counter_incr(stats, idx) \
466 lprocfs_counter_add(stats, idx, 1)
467 #define lprocfs_counter_decr(stats, idx) \
468 lprocfs_counter_sub(stats, idx, 1)
470 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
471 struct lprocfs_counter_header *header,
472 enum lprocfs_stats_flags flags,
473 enum lprocfs_fields_flags field);
474 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
475 enum lprocfs_fields_flags field);
477 extern struct lprocfs_stats *
478 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
479 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
480 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
481 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
482 extern int lprocfs_alloc_obd_stats(struct obd_device *obd,
483 unsigned int num_stats);
484 extern int lprocfs_alloc_md_stats(struct obd_device *obd,
485 unsigned int num_private_stats);
486 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
487 unsigned conf, const char *name,
489 extern void lprocfs_free_obd_stats(struct obd_device *obd);
490 extern void lprocfs_free_md_stats(struct obd_device *obd);
493 extern int lprocfs_add_clear_entry(struct obd_device *obd,
494 struct proc_dir_entry *entry);
495 #ifdef HAVE_SERVER_SUPPORT
496 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
497 extern int lprocfs_exp_cleanup(struct obd_export *exp);
498 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
499 const char *format, ...);
501 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
504 extern struct proc_dir_entry *
505 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
506 void *data, const struct file_operations *fops);
507 extern struct proc_dir_entry *
508 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
509 const char *format, ...);
510 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
511 #ifdef HAVE_SERVER_SUPPORT
513 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
514 size_t count, loff_t *off);
515 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
517 extern const struct file_operations lprocfs_stats_seq_fops;
518 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
519 struct lprocfs_stats *stats);
521 /* lprocfs_status.c */
522 extern void ldebugfs_add_vars(struct dentry *parent, struct lprocfs_vars *var,
524 extern int lprocfs_add_vars(struct proc_dir_entry *root,
525 struct lprocfs_vars *var, void *data);
527 extern struct proc_dir_entry *
528 lprocfs_register(const char *name, struct proc_dir_entry *parent,
529 struct lprocfs_vars *list, void *data);
531 extern void lprocfs_remove(struct proc_dir_entry **root);
532 extern void lprocfs_remove_proc_entry(const char *name,
533 struct proc_dir_entry *parent);
534 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
535 extern int lprocfs_obd_cleanup(struct obd_device *obd);
536 #ifdef HAVE_SERVER_SUPPORT
537 extern const struct file_operations lprocfs_evict_client_fops;
540 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
542 const struct file_operations *seq_fops,
544 extern int lprocfs_obd_seq_create(struct obd_device *obd, const char *name,
546 const struct file_operations *seq_fops,
549 /* Generic callbacks */
550 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
551 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
552 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
553 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
554 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
555 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
556 #ifdef HAVE_SERVER_SUPPORT
557 ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
560 struct adaptive_timeout;
561 extern int lprocfs_at_hist_helper(struct seq_file *m,
562 struct adaptive_timeout *at);
563 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
565 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
566 size_t count, loff_t *off);
567 #ifdef HAVE_SERVER_SUPPORT
569 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
570 size_t count, loff_t *off);
572 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
573 const char *buffer, size_t count);
574 ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
578 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
579 size_t count, loff_t *off);
580 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
582 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
583 size_t count, loff_t *off);
585 int string_to_size(u64 *size, const char *buffer, size_t count);
586 int sysfs_memparse(const char *buffer, size_t count, u64 *val,
587 const char *defunit);
588 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
589 char *lprocfs_find_named_value(const char *buffer, const char *name,
591 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
592 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
593 void lprocfs_oh_clear(struct obd_histogram *oh);
594 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
596 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
597 struct lprocfs_counter *cnt);
599 #ifdef HAVE_SERVER_SUPPORT
600 /* lprocfs_status.c: recovery status */
601 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
603 /* lprocfs_status.c: hash statistics */
604 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
606 /* lprocfs_status.c: IR factor */
607 ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
609 ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
610 const char *buffer, size_t count);
613 /* lprocfs_status.c: dump pages on cksum error */
614 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
616 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
617 size_t count, loff_t *off);
619 extern int lprocfs_single_release(struct inode *, struct file *);
620 extern int lprocfs_seq_release(struct inode *, struct file *);
622 /* You must use these macros when you want to refer to
623 * the import in a client obd_device for a lprocfs entry
625 #define with_imp_locked(__obd, __imp, __rc) \
626 for (down_read(&(__obd)->u.cli.cl_sem), \
627 __imp = (__obd)->u.cli.cl_import, \
628 __rc = __imp ? 0 : -ENODEV; \
629 __imp ? 1 : (up_read(&(__obd)->u.cli.cl_sem), 0); \
632 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
633 * debugfs entries; otherwise, you will define name##_seq_write function also
634 * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
635 * Finally, call debugfs_create_file(filename, 0444, obd, data, &name#_fops);
637 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write) \
638 static int name##_single_open(struct inode *inode, struct file *file) \
640 return single_open(file, name##_seq_show, inode->i_private); \
642 static const struct file_operations name##_fops = { \
643 .owner = THIS_MODULE, \
644 .open = name##_single_open, \
646 .write = custom_seq_write, \
647 .llseek = seq_lseek, \
648 .release = single_release, \
651 #define LDEBUGFS_SEQ_FOPS_RO(name) __LDEBUGFS_SEQ_FOPS(name, NULL)
652 #define LDEBUGFS_SEQ_FOPS(name) __LDEBUGFS_SEQ_FOPS(name, \
655 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type) \
656 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
660 return lprocfs_##type##_seq_show(m, m->private); \
662 LDEBUGFS_SEQ_FOPS_RO(name##_##type)
664 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type) \
665 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
669 return lprocfs_##type##_seq_show(m, m->private); \
671 static ssize_t name##_##type##_seq_write(struct file *file, \
672 const char __user *buffer, size_t count, \
675 struct seq_file *seq = file->private_data; \
679 return ldebugfs_##type##_seq_write(file, buffer, count, \
682 LDEBUGFS_SEQ_FOPS(name##_##type);
684 #define LDEBUGFS_FOPS_WR_ONLY(name, type) \
685 static ssize_t name##_##type##_write(struct file *file, \
686 const char __user *buffer, size_t count, \
689 return ldebugfs_##type##_seq_write(file, buffer, count, \
692 static int name##_##type##_open(struct inode *inode, \
695 return single_open(file, NULL, inode->i_private); \
697 static const struct file_operations name##_##type##_fops = { \
698 .open = name##_##type##_open, \
699 .write = name##_##type##_write, \
700 .release = single_release, \
703 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
704 * proc entries; otherwise, you will define name##_seq_write function also for
705 * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
706 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
708 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
709 static int name##_single_open(struct inode *inode, struct file *file) \
711 return single_open(file, name##_seq_show, \
712 inode->i_private ? inode->i_private : \
715 static const struct file_operations name##_fops = { \
716 .owner = THIS_MODULE, \
717 .open = name##_single_open, \
719 .write = custom_seq_write, \
720 .llseek = seq_lseek, \
721 .release = lprocfs_single_release, \
724 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
725 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
727 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
728 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
730 return lprocfs_##type##_seq_show(m, m->private); \
732 LPROC_SEQ_FOPS_RO(name##_##type)
734 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
735 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
737 return lprocfs_##type##_seq_show(m, m->private); \
739 static ssize_t name##_##type##_seq_write(struct file *file, \
740 const char __user *buffer, size_t count, \
743 struct seq_file *seq = file->private_data; \
744 return lprocfs_##type##_seq_write(file, buffer, \
745 count, seq->private); \
747 LPROC_SEQ_FOPS(name##_##type);
749 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
750 static ssize_t name##_##type##_write(struct file *file, \
751 const char __user *buffer, size_t count, \
754 return lprocfs_##type##_seq_write(file, buffer, count, off);\
756 static int name##_##type##_open(struct inode *inode, struct file *file)\
758 return single_open(file, NULL, \
759 inode->i_private ? inode->i_private : \
762 static const struct file_operations name##_##type##_fops = { \
763 .open = name##_##type##_open, \
764 .write = name##_##type##_write, \
765 .release = lprocfs_single_release, \
769 struct attribute attr;
770 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
772 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
773 const char *buf, size_t len);
776 #define LUSTRE_ATTR(name, mode, show, store) \
777 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
779 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
780 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
781 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
783 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
785 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
786 const char *buf, size_t len);
788 extern const struct sysfs_ops lustre_sysfs_ops;
791 struct ptlrpc_request;
792 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
794 #ifdef HAVE_SERVER_SUPPORT
795 /* lprocfs_jobstats.c */
796 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
797 int event, long amount);
798 void lprocfs_job_stats_fini(struct obd_device *obd);
799 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
800 cntr_init_callback fn);
801 ssize_t job_cleanup_interval_show(struct kobject *kobj, struct attribute *attr,
803 ssize_t job_cleanup_interval_store(struct kobject *kobj,
804 struct attribute *attr,
805 const char *buffer, size_t count);
806 /* lproc_status_server.c */
807 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
809 ssize_t recovery_time_soft_store(struct kobject *kobj,
810 struct attribute *attr,
811 const char *buffer, size_t count);
812 ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
814 ssize_t recovery_time_hard_store(struct kobject *kobj,
815 struct attribute *attr,
816 const char *buffer, size_t count);
817 ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
821 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
822 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
823 const char __user *buffer,
824 size_t count, loff_t *off);
825 int lprocfs_obd_short_io_bytes_seq_show(struct seq_file *m, void *data);
826 ssize_t lprocfs_obd_short_io_bytes_seq_write(struct file *file,
827 const char __user *buffer,
828 size_t count, loff_t *off);
829 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
831 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
832 const char *buffer, size_t count);
834 struct root_squash_info;
835 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
836 struct root_squash_info *squash, char *name);
837 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
838 struct root_squash_info *squash, char *name);
840 #else /* !CONFIG_PROC_FS */
842 #define proc_lustre_root NULL
844 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
845 int index, long amount)
847 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
850 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
851 int index, long amount)
853 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
856 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
857 int index, unsigned conf,
858 const char *name, const char *units)
861 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
862 enum lprocfs_fields_flags field)
865 /* NB: we return !NULL to satisfy error checker */
866 static inline struct lprocfs_stats *
867 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
868 { return (struct lprocfs_stats *)1; }
869 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
871 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
873 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
875 struct lprocfs_stats *stats)
877 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
879 static inline int lprocfs_alloc_obd_stats(struct obd_device *obd,
880 unsigned int num_stats)
882 static inline int lprocfs_alloc_md_stats(struct obd_device *obd,
883 unsigned int num_private_stats)
885 static inline void lprocfs_free_obd_stats(struct obd_device *obd)
887 static inline void lprocfs_free_md_stats(struct obd_device *obd)
891 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
893 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
895 #ifdef HAVE_SERVER_SUPPORT
897 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
898 const char __user *buffer,
899 size_t count, loff_t *off)
902 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
904 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
907 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
909 static inline struct proc_dir_entry *
910 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
911 void *data, const struct file_operations *fops)
913 static inline struct proc_dir_entry *
914 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
915 const char *format, ...)
917 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
918 struct lprocfs_vars *var, void *data)
920 static inline struct proc_dir_entry *
921 lprocfs_register(const char *name, struct proc_dir_entry *parent,
922 struct lprocfs_vars *list, void *data)
924 static inline void lprocfs_remove(struct proc_dir_entry **root)
926 static inline void lprocfs_remove_proc_entry(const char *name,
927 struct proc_dir_entry *parent)
929 static inline int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
931 static inline int lprocfs_obd_cleanup(struct obd_device *obd)
933 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
935 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
937 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
939 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
941 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
943 #ifdef HAVE_SERVER_SUPPORT
944 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
947 struct adaptive_timeout;
948 static inline int lprocfs_at_hist_helper(struct seq_file *m,
949 struct adaptive_timeout *at)
951 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
953 static inline ssize_t
954 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
955 size_t count, loff_t *off)
957 #ifdef HAVE_SERVER_SUPPORT
958 static inline ssize_t
959 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
960 size_t count, loff_t *off)
963 static inline ssize_t
964 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
965 size_t count, loff_t *off)
967 static inline ssize_t
968 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
969 size_t count, loff_t *off)
972 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
974 static inline ssize_t
975 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
976 size_t count, loff_t *off)
981 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
984 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
987 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
990 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
993 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
996 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
999 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1002 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1005 void lprocfs_oh_clear(struct obd_histogram *oh)
1008 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1011 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1012 struct lprocfs_counter *cnt)
1015 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1016 enum lprocfs_fields_flags field)
1017 { return (__u64)0; }
1019 #define LPROC_SEQ_FOPS_RO(name)
1020 #define LPROC_SEQ_FOPS(name)
1021 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1022 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1023 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1025 /* lprocfs_jobstats.c */
1027 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1031 void lprocfs_job_stats_fini(struct obd_device *obd)
1034 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1035 cntr_init_callback fn)
1039 /* lproc_ptlrpc.c */
1040 #define target_print_req NULL
1042 #endif /* CONFIG_PROC_FS */
1044 #endif /* LPROCFS_STATUS_H */