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, 2015, 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 SNMP
36 * Author: Hariharan Thantry thantry@users.sourceforge.net
38 #ifndef _LPROCFS_SNMP_H
39 #define _LPROCFS_SNMP_H
41 #include <linux/debugfs.h>
42 #include <linux/seq_file.h>
43 #include <linux/spinlock.h>
44 #include <linux/types.h>
46 #include <linux/libcfs/libcfs.h>
47 #include <uapi/linux/lustre/lustre_cfg.h>
48 #include <uapi/linux/lustre/lustre_idl.h>
52 const struct file_operations *fops;
60 struct lprocfs_static_vars {
61 struct lprocfs_vars *obd_vars;
62 const struct attribute_group *sysfs_vars;
65 /* if we find more consumers this could be generalized */
66 #define OBD_HIST_MAX 32
67 struct obd_histogram {
69 unsigned long oh_buckets[OBD_HIST_MAX];
91 struct obd_histogram hist[BRW_LAST];
95 RENAME_SAMEDIR_SIZE = 0,
96 RENAME_CROSSDIR_SRC_SIZE,
97 RENAME_CROSSDIR_TGT_SIZE,
101 struct rename_stats {
102 struct obd_histogram hist[RENAME_LAST];
105 /* An lprocfs counter can be configured using the enum bit masks below.
107 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
108 * protects this counter from concurrent updates. If not specified,
109 * lprocfs an internal per-counter lock variable. External locks are
110 * not used to protect counter increments, but are used to protect
111 * counter readout and resets.
113 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
114 * (i.e. counter can be incremented by more than "1"). When specified,
115 * the counter maintains min, max and sum in addition to a simple
116 * invocation count. This allows averages to be be computed.
117 * If not specified, the counter is an increment-by-1 counter.
118 * min, max, sum, etc. are not maintained.
120 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
121 * squares (for multi-valued counter samples only). This allows
122 * external computation of standard deviation, but involves a 64-bit
123 * multiply per counter increment.
127 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
128 LPROCFS_CNTR_AVGMINMAX = 0x0002,
129 LPROCFS_CNTR_STDDEV = 0x0004,
131 /* counter data type */
132 LPROCFS_TYPE_REGS = 0x0100,
133 LPROCFS_TYPE_BYTES = 0x0200,
134 LPROCFS_TYPE_PAGES = 0x0400,
135 LPROCFS_TYPE_CYCLE = 0x0800,
138 #define LC_MIN_INIT ((~(__u64)0) >> 1)
140 struct lprocfs_counter_header {
141 unsigned int lc_config;
142 const char *lc_name; /* must be static */
143 const char *lc_units; /* must be static */
146 struct lprocfs_counter {
152 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
153 * for irq context counter, i.e. stats with
154 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
157 __s64 lc_array_sum[1];
160 #define lc_sum lc_array_sum[0]
161 #define lc_sum_irq lc_array_sum[1]
163 struct lprocfs_percpu {
167 struct lprocfs_counter lp_cntr[0];
170 enum lprocfs_stats_lock_ops {
171 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
172 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
175 enum lprocfs_stats_flags {
176 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
177 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
178 * area and need locking
180 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
183 enum lprocfs_fields_flags {
184 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
185 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
186 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
187 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
188 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
189 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
190 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
193 struct lprocfs_stats {
195 unsigned short ls_num;
196 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
197 unsigned short ls_biggest_alloc_num;
198 enum lprocfs_stats_flags ls_flags;
199 /* Lock used when there are no percpu stats areas; For percpu stats,
200 * it is used to protect ls_biggest_alloc_num change
204 /* has ls_num of counter headers */
205 struct lprocfs_counter_header *ls_cnt_header;
206 struct lprocfs_percpu *ls_percpu[0];
209 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
211 /* Pack all opcodes down into a single monotonically increasing index */
212 static inline int opcode_offset(__u32 opc)
214 if (opc < OST_LAST_OPC) {
216 return (opc - OST_FIRST_OPC);
217 } else if (opc < MDS_LAST_OPC) {
219 return (opc - MDS_FIRST_OPC +
221 } else if (opc < LDLM_LAST_OPC) {
223 return (opc - LDLM_FIRST_OPC +
226 } else if (opc < MGS_LAST_OPC) {
228 return (opc - MGS_FIRST_OPC +
232 } else if (opc < OBD_LAST_OPC) {
234 return (opc - OBD_FIRST_OPC +
239 } else if (opc < LLOG_LAST_OPC) {
241 return (opc - LLOG_FIRST_OPC +
247 } else if (opc < QUOTA_LAST_OPC) {
249 return (opc - QUOTA_FIRST_OPC +
256 } else if (opc < SEQ_LAST_OPC) {
258 return (opc - SEQ_FIRST_OPC +
266 } else if (opc < SEC_LAST_OPC) {
268 return (opc - SEC_FIRST_OPC +
277 } else if (opc < FLD_LAST_OPC) {
279 return (opc - FLD_FIRST_OPC +
295 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
306 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
310 PTLRPC_REQWAIT_CNTR = 0,
311 PTLRPC_REQQDEPTH_CNTR,
312 PTLRPC_REQACTIVE_CNTR,
314 PTLRPC_REQBUF_AVAIL_CNTR,
318 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
321 LDLM_GLIMPSE_ENQUEUE = 0,
338 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
340 extern struct dentry *debugfs_lustre_root;
341 extern struct kobject *lustre_kobj;
344 struct obd_histogram;
346 /* Days / hours / mins / seconds format */
351 static inline void s2dhms(struct dhms *ts, time64_t secs64)
355 ts->d = div_u64_rem(secs64, 86400, &secs);
362 #define DHMS_FMT "%dd%dh%02dm%02ds"
363 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
365 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
366 #define JOBSTATS_DISABLE "disable"
367 #define JOBSTATS_PROCNAME_UID "procname_uid"
368 #define JOBSTATS_NODELOCAL "nodelocal"
371 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
373 int lprocfs_write_frac_helper(const char __user *buffer,
374 unsigned long count, int *val, int mult);
375 int lprocfs_read_frac_helper(char *buffer, unsigned long count,
378 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
380 int lprocfs_stats_lock(struct lprocfs_stats *stats,
381 enum lprocfs_stats_lock_ops opc,
382 unsigned long *flags);
383 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
384 enum lprocfs_stats_lock_ops opc,
385 unsigned long *flags);
387 static inline unsigned int
388 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
390 unsigned int percpusize;
392 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
394 /* irq safe stats need lc_array_sum[1] */
395 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
396 percpusize += stats->ls_num * sizeof(__s64);
398 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
399 percpusize = L1_CACHE_ALIGN(percpusize);
404 static inline struct lprocfs_counter *
405 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
408 struct lprocfs_counter *cntr;
410 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
412 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
413 cntr = (void *)cntr + index * sizeof(__s64);
418 /* Two optimized LPROCFS counter increment functions are provided:
419 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
420 * lprocfs_counter_add(cntr) - use for multi-valued counters
421 * Counter data layout allows config flag, counter lock and the
422 * count itself to reside within a single cache line.
425 void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount);
426 void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount);
428 #define lprocfs_counter_incr(stats, idx) \
429 lprocfs_counter_add(stats, idx, 1)
430 #define lprocfs_counter_decr(stats, idx) \
431 lprocfs_counter_sub(stats, idx, 1)
433 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
434 struct lprocfs_counter_header *header,
435 enum lprocfs_stats_flags flags,
436 enum lprocfs_fields_flags field);
437 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
438 enum lprocfs_fields_flags field);
440 extern struct lprocfs_stats *
441 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
442 void lprocfs_clear_stats(struct lprocfs_stats *stats);
443 void lprocfs_free_stats(struct lprocfs_stats **stats);
444 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
445 unsigned int conf, const char *name,
448 int lprocfs_exp_cleanup(struct obd_export *exp);
449 struct dentry *ldebugfs_add_simple(struct dentry *root,
452 const struct file_operations *fops);
454 int ldebugfs_register_stats(struct dentry *parent,
456 struct lprocfs_stats *stats);
458 /* lprocfs_status.c */
459 int ldebugfs_add_vars(struct dentry *parent,
460 struct lprocfs_vars *var,
463 struct dentry *ldebugfs_register(const char *name,
464 struct dentry *parent,
465 struct lprocfs_vars *list,
468 void ldebugfs_remove(struct dentry **entryp);
470 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list,
471 const struct attribute_group *attrs);
472 int lprocfs_obd_cleanup(struct obd_device *obd);
474 int ldebugfs_seq_create(struct dentry *parent,
477 const struct file_operations *seq_fops,
479 int ldebugfs_obd_seq_create(struct obd_device *dev,
482 const struct file_operations *seq_fops,
485 /* Generic callbacks */
487 int lprocfs_rd_uint(struct seq_file *m, void *data);
488 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
489 unsigned long count, void *data);
490 int lprocfs_rd_server_uuid(struct seq_file *m, void *data);
491 int lprocfs_rd_conn_uuid(struct seq_file *m, void *data);
492 int lprocfs_rd_import(struct seq_file *m, void *data);
493 int lprocfs_rd_state(struct seq_file *m, void *data);
494 int lprocfs_rd_connect_flags(struct seq_file *m, void *data);
496 struct adaptive_timeout;
497 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at);
498 int lprocfs_rd_timeouts(struct seq_file *m, void *data);
499 int lprocfs_wr_ping(struct file *file, const char __user *buffer,
500 size_t count, loff_t *off);
501 int lprocfs_wr_import(struct file *file, const char __user *buffer,
502 size_t count, loff_t *off);
503 int lprocfs_rd_pinger_recov(struct seq_file *m, void *n);
504 int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
505 size_t count, loff_t *off);
509 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
511 int lprocfs_write_u64_helper(const char __user *buffer,
512 unsigned long count, __u64 *val);
513 int lprocfs_write_frac_u64_helper(const char __user *buffer,
515 __u64 *val, int mult);
516 char *lprocfs_find_named_value(const char *buffer, const char *name,
518 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
519 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
520 void lprocfs_oh_clear(struct obd_histogram *oh);
521 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
523 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
524 struct lprocfs_counter *cnt);
526 int lprocfs_single_release(struct inode *inode, struct file *file);
527 int lprocfs_seq_release(struct inode *inode, struct file *file);
529 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
530 * proc entries; otherwise, you will define name##_seq_write function also for
531 * a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
532 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
534 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
535 static int name##_single_open(struct inode *inode, struct file *file) \
537 return single_open(file, name##_seq_show, inode->i_private); \
539 static const struct file_operations name##_fops = { \
540 .owner = THIS_MODULE, \
541 .open = name##_single_open, \
543 .write = custom_seq_write, \
544 .llseek = seq_lseek, \
545 .release = lprocfs_single_release, \
548 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
549 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
551 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
552 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
554 return lprocfs_rd_##type(m, m->private); \
556 LPROC_SEQ_FOPS_RO(name##_##type)
558 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
559 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
561 return lprocfs_rd_##type(m, m->private); \
563 static ssize_t name##_##type##_seq_write(struct file *file, \
564 const char __user *buffer, size_t count, \
567 struct seq_file *seq = file->private_data; \
568 return lprocfs_wr_##type(file, buffer, \
569 count, seq->private); \
571 LPROC_SEQ_FOPS(name##_##type)
573 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
574 static ssize_t name##_##type##_write(struct file *file, \
575 const char __user *buffer, size_t count, \
578 return lprocfs_wr_##type(file, buffer, count, off); \
580 static int name##_##type##_open(struct inode *inode, struct file *file) \
582 return single_open(file, NULL, inode->i_private); \
584 static const struct file_operations name##_##type##_fops = { \
585 .open = name##_##type##_open, \
586 .write = name##_##type##_write, \
587 .release = lprocfs_single_release, \
591 struct attribute attr;
592 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
594 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
595 const char *buf, size_t len);
598 #define LUSTRE_ATTR(name, mode, show, store) \
599 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
601 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
602 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
604 extern const struct sysfs_ops lustre_sysfs_ops;
606 struct root_squash_info;
607 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
608 struct root_squash_info *squash, char *name);
609 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
610 struct root_squash_info *squash, char *name);
612 /* all quota proc functions */
613 int lprocfs_quota_rd_bunit(char *page, char **start,
614 loff_t off, int count,
615 int *eof, void *data);
616 int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
617 unsigned long count, void *data);
618 int lprocfs_quota_rd_btune(char *page, char **start,
619 loff_t off, int count,
620 int *eof, void *data);
621 int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
622 unsigned long count, void *data);
623 int lprocfs_quota_rd_iunit(char *page, char **start,
624 loff_t off, int count,
625 int *eof, void *data);
626 int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
627 unsigned long count, void *data);
628 int lprocfs_quota_rd_itune(char *page, char **start,
629 loff_t off, int count,
630 int *eof, void *data);
631 int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
632 unsigned long count, void *data);
633 int lprocfs_quota_rd_type(char *page, char **start, loff_t off, int count,
634 int *eof, void *data);
635 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
636 unsigned long count, void *data);
637 int lprocfs_quota_rd_switch_seconds(char *page, char **start, loff_t off,
638 int count, int *eof, void *data);
639 int lprocfs_quota_wr_switch_seconds(struct file *file,
641 unsigned long count, void *data);
642 int lprocfs_quota_rd_sync_blk(char *page, char **start, loff_t off,
643 int count, int *eof, void *data);
644 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
645 unsigned long count, void *data);
646 int lprocfs_quota_rd_switch_qs(char *page, char **start, loff_t off,
647 int count, int *eof, void *data);
648 int lprocfs_quota_wr_switch_qs(struct file *file,
649 const char *buffer, unsigned long count,
651 int lprocfs_quota_rd_boundary_factor(char *page, char **start, loff_t off,
652 int count, int *eof, void *data);
653 int lprocfs_quota_wr_boundary_factor(struct file *file,
654 const char *buffer, unsigned long count,
656 int lprocfs_quota_rd_least_bunit(char *page, char **start, loff_t off,
657 int count, int *eof, void *data);
658 int lprocfs_quota_wr_least_bunit(struct file *file,
659 const char *buffer, unsigned long count,
661 int lprocfs_quota_rd_least_iunit(char *page, char **start, loff_t off,
662 int count, int *eof, void *data);
663 int lprocfs_quota_wr_least_iunit(struct file *file,
664 const char *buffer, unsigned long count,
666 int lprocfs_quota_rd_qs_factor(char *page, char **start, loff_t off,
667 int count, int *eof, void *data);
668 int lprocfs_quota_wr_qs_factor(struct file *file,
669 const char *buffer, unsigned long count,
671 #endif /* LPROCFS_SNMP_H */