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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/lprocfs_status.c
38 * Author: Hariharan Thantry <thantry@users.sourceforge.net>
41 #define DEBUG_SUBSYSTEM S_CLASS
44 #include "../include/obd_class.h"
45 #include "../include/lprocfs_status.h"
46 #include "../include/lustre/lustre_idl.h"
47 #include <linux/seq_file.h>
48 #include <linux/ctype.h>
50 static const char * const obd_connect_names[] = {
64 "join_file(obsolete)",
68 "remote_client_by_force",
80 "alt_checksum_algorithm",
108 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
113 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
115 ret += snprintf(page + ret, count - ret, "%s%s",
116 ret ? sep : "", obd_connect_names[i]);
118 if (flags & ~(mask - 1))
119 ret += snprintf(page + ret, count - ret,
120 "%sunknown flags %#llx",
121 ret ? sep : "", flags & ~(mask - 1));
124 EXPORT_SYMBOL(obd_connect_flags2str);
126 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
129 long decimal_val, frac_val;
135 decimal_val = val / mult;
136 prtn = snprintf(buffer, count, "%ld", decimal_val);
137 frac_val = val % mult;
139 if (prtn < (count - 4) && frac_val > 0) {
141 int i, temp_mult = 1, frac_bits = 0;
143 temp_frac = frac_val * 10;
144 buffer[prtn++] = '.';
145 while (frac_bits < 2 && (temp_frac / mult) < 1) {
146 /* only reserved 2 bits fraction */
147 buffer[prtn++] = '0';
152 * Need to think these cases :
153 * 1. #echo x.00 > /proc/xxx output result : x
154 * 2. #echo x.0x > /proc/xxx output result : x.0x
155 * 3. #echo x.x0 > /proc/xxx output result : x.x
156 * 4. #echo x.xx > /proc/xxx output result : x.xx
157 * Only reserved 2 bits fraction.
159 for (i = 0; i < (5 - prtn); i++)
162 frac_bits = min((int)count - prtn, 3 - frac_bits);
163 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
164 frac_val * temp_mult / mult);
167 while (buffer[prtn] < '1' || buffer[prtn] > '9') {
169 if (buffer[prtn] == '.') {
176 buffer[prtn++] = '\n';
179 EXPORT_SYMBOL(lprocfs_read_frac_helper);
181 int lprocfs_write_frac_helper(const char __user *buffer, unsigned long count,
184 char kernbuf[20], *end, *pbuf;
186 if (count > (sizeof(kernbuf) - 1))
189 if (copy_from_user(kernbuf, buffer, count))
192 kernbuf[count] = '\0';
199 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
203 if (end != NULL && *end == '.') {
204 int temp_val, pow = 1;
208 if (strlen(pbuf) > 5)
209 pbuf[5] = '\0'; /*only allow 5bits fractional*/
211 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
214 for (i = 0; i < (end - pbuf); i++)
217 *val += temp_val / pow;
222 EXPORT_SYMBOL(lprocfs_write_frac_helper);
224 #if defined (CONFIG_PROC_FS)
226 static int lprocfs_no_percpu_stats;
227 module_param(lprocfs_no_percpu_stats, int, 0644);
228 MODULE_PARM_DESC(lprocfs_no_percpu_stats, "Do not alloc percpu data for lprocfs stats");
230 #define MAX_STRING_SIZE 128
232 int lprocfs_single_release(struct inode *inode, struct file *file)
234 return single_release(inode, file);
236 EXPORT_SYMBOL(lprocfs_single_release);
238 int lprocfs_seq_release(struct inode *inode, struct file *file)
240 return seq_release(inode, file);
242 EXPORT_SYMBOL(lprocfs_seq_release);
244 /* lprocfs API calls */
246 struct dentry *ldebugfs_add_simple(struct dentry *root,
247 char *name, void *data,
248 struct file_operations *fops)
250 struct dentry *entry;
253 if (root == NULL || name == NULL || fops == NULL)
254 return ERR_PTR(-EINVAL);
260 entry = debugfs_create_file(name, mode, root, data, fops);
261 if (IS_ERR_OR_NULL(entry)) {
262 CERROR("LprocFS: No memory to create <debugfs> entry %s", name);
263 return entry ?: ERR_PTR(-ENOMEM);
267 EXPORT_SYMBOL(ldebugfs_add_simple);
269 struct proc_dir_entry *lprocfs_add_simple(struct proc_dir_entry *root,
270 char *name, void *data,
271 struct file_operations *fops)
273 struct proc_dir_entry *proc;
276 if (root == NULL || name == NULL || fops == NULL)
277 return ERR_PTR(-EINVAL);
283 proc = proc_create_data(name, mode, root, fops, data);
285 CERROR("LprocFS: No memory to create /proc entry %s", name);
286 return ERR_PTR(-ENOMEM);
290 EXPORT_SYMBOL(lprocfs_add_simple);
292 struct dentry *ldebugfs_add_symlink(const char *name, struct dentry *parent,
293 const char *format, ...)
295 struct dentry *entry;
299 if (parent == NULL || format == NULL)
302 dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL);
306 va_start(ap, format);
307 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
310 entry = debugfs_create_symlink(name, parent, dest);
311 if (IS_ERR_OR_NULL(entry)) {
312 CERROR("LdebugFS: Could not create symbolic link from %s to %s",
320 EXPORT_SYMBOL(ldebugfs_add_symlink);
322 static struct file_operations lprocfs_generic_fops = { };
324 int ldebugfs_add_vars(struct dentry *parent,
325 struct lprocfs_vars *list,
328 if (IS_ERR_OR_NULL(parent) || IS_ERR_OR_NULL(list))
331 while (list->name != NULL) {
332 struct dentry *entry;
335 if (list->proc_mode != 0000) {
336 mode = list->proc_mode;
337 } else if (list->fops) {
338 if (list->fops->read)
340 if (list->fops->write)
343 entry = debugfs_create_file(list->name, mode, parent,
345 list->fops ?: &lprocfs_generic_fops
347 if (IS_ERR_OR_NULL(entry))
348 return entry ? PTR_ERR(entry) : -ENOMEM;
353 EXPORT_SYMBOL(ldebugfs_add_vars);
358 * \param root [in] The parent proc entry on which new entry will be added.
359 * \param list [in] Array of proc entries to be added.
360 * \param data [in] The argument to be passed when entries read/write routines
361 * are called through /proc file.
363 * \retval 0 on success
366 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
369 if (root == NULL || list == NULL)
372 while (list->name != NULL) {
373 struct proc_dir_entry *proc;
376 if (list->proc_mode != 0000) {
377 mode = list->proc_mode;
378 } else if (list->fops) {
379 if (list->fops->read)
381 if (list->fops->write)
384 proc = proc_create_data(list->name, mode, root,
385 list->fops ?: &lprocfs_generic_fops,
393 EXPORT_SYMBOL(lprocfs_add_vars);
395 void ldebugfs_remove(struct dentry **entryp)
397 debugfs_remove(*entryp);
400 EXPORT_SYMBOL(ldebugfs_remove);
402 void lprocfs_remove(struct proc_dir_entry **rooth)
407 EXPORT_SYMBOL(lprocfs_remove);
409 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
411 LASSERT(parent != NULL);
412 remove_proc_entry(name, parent);
414 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
416 struct dentry *ldebugfs_register(const char *name,
417 struct dentry *parent,
418 struct lprocfs_vars *list, void *data)
420 struct dentry *entry;
422 entry = debugfs_create_dir(name, parent);
423 if (IS_ERR_OR_NULL(entry)) {
424 entry = entry ?: ERR_PTR(-ENOMEM);
428 if (!IS_ERR_OR_NULL(list)) {
431 rc = ldebugfs_add_vars(entry, list, data);
433 debugfs_remove(entry);
440 EXPORT_SYMBOL(ldebugfs_register);
442 struct proc_dir_entry *lprocfs_register(const char *name,
443 struct proc_dir_entry *parent,
444 struct lprocfs_vars *list, void *data)
446 struct proc_dir_entry *entry;
448 entry = proc_mkdir(name, parent);
450 entry = ERR_PTR(-ENOMEM);
455 int rc = lprocfs_add_vars(entry, list, data);
457 lprocfs_remove(&entry);
464 EXPORT_SYMBOL(lprocfs_register);
466 /* Generic callbacks */
467 int lprocfs_rd_uint(struct seq_file *m, void *data)
469 seq_printf(m, "%u\n", *(unsigned int *)data);
472 EXPORT_SYMBOL(lprocfs_rd_uint);
474 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
475 unsigned long count, void *data)
478 char dummy[MAX_STRING_SIZE + 1], *end;
481 dummy[MAX_STRING_SIZE] = '\0';
482 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
485 tmp = simple_strtoul(dummy, &end, 0);
489 *p = (unsigned int)tmp;
492 EXPORT_SYMBOL(lprocfs_wr_uint);
494 int lprocfs_rd_u64(struct seq_file *m, void *data)
496 seq_printf(m, "%llu\n", *(__u64 *)data);
499 EXPORT_SYMBOL(lprocfs_rd_u64);
501 int lprocfs_rd_atomic(struct seq_file *m, void *data)
503 atomic_t *atom = data;
504 LASSERT(atom != NULL);
505 seq_printf(m, "%d\n", atomic_read(atom));
508 EXPORT_SYMBOL(lprocfs_rd_atomic);
510 int lprocfs_wr_atomic(struct file *file, const char __user *buffer,
511 unsigned long count, void *data)
513 atomic_t *atm = data;
517 rc = lprocfs_write_helper(buffer, count, &val);
524 atomic_set(atm, val);
527 EXPORT_SYMBOL(lprocfs_wr_atomic);
529 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
532 struct obd_device *obd = container_of(kobj, struct obd_device,
535 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
537 LUSTRE_RO_ATTR(uuid);
539 int lprocfs_rd_name(struct seq_file *m, void *data)
541 struct obd_device *dev = data;
543 LASSERT(dev != NULL);
544 seq_printf(m, "%s\n", dev->obd_name);
547 EXPORT_SYMBOL(lprocfs_rd_name);
549 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
552 struct obd_device *obd = container_of(kobj, struct obd_device,
554 struct obd_statfs osfs;
555 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
556 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
559 return sprintf(buf, "%u\n", osfs.os_bsize);
563 LUSTRE_RO_ATTR(blocksize);
565 static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
568 struct obd_device *obd = container_of(kobj, struct obd_device,
570 struct obd_statfs osfs;
571 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
572 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
575 __u32 blk_size = osfs.os_bsize >> 10;
576 __u64 result = osfs.os_blocks;
578 while (blk_size >>= 1)
581 return sprintf(buf, "%llu\n", result);
586 LUSTRE_RO_ATTR(kbytestotal);
588 static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
591 struct obd_device *obd = container_of(kobj, struct obd_device,
593 struct obd_statfs osfs;
594 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
595 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
598 __u32 blk_size = osfs.os_bsize >> 10;
599 __u64 result = osfs.os_bfree;
601 while (blk_size >>= 1)
604 return sprintf(buf, "%llu\n", result);
609 LUSTRE_RO_ATTR(kbytesfree);
611 static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
614 struct obd_device *obd = container_of(kobj, struct obd_device,
616 struct obd_statfs osfs;
617 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
618 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
621 __u32 blk_size = osfs.os_bsize >> 10;
622 __u64 result = osfs.os_bavail;
624 while (blk_size >>= 1)
627 return sprintf(buf, "%llu\n", result);
632 LUSTRE_RO_ATTR(kbytesavail);
634 static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
637 struct obd_device *obd = container_of(kobj, struct obd_device,
639 struct obd_statfs osfs;
640 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
641 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
644 return sprintf(buf, "%llu\n", osfs.os_files);
648 LUSTRE_RO_ATTR(filestotal);
650 static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
653 struct obd_device *obd = container_of(kobj, struct obd_device,
655 struct obd_statfs osfs;
656 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
657 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
660 return sprintf(buf, "%llu\n", osfs.os_ffree);
664 LUSTRE_RO_ATTR(filesfree);
666 int lprocfs_rd_server_uuid(struct seq_file *m, void *data)
668 struct obd_device *obd = data;
669 struct obd_import *imp;
670 char *imp_state_name = NULL;
672 LASSERT(obd != NULL);
673 LPROCFS_CLIMP_CHECK(obd);
674 imp = obd->u.cli.cl_import;
675 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
676 seq_printf(m, "%s\t%s%s\n",
677 obd2cli_tgt(obd), imp_state_name,
678 imp->imp_deactive ? "\tDEACTIVATED" : "");
680 LPROCFS_CLIMP_EXIT(obd);
684 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
686 int lprocfs_rd_conn_uuid(struct seq_file *m, void *data)
688 struct obd_device *obd = data;
689 struct ptlrpc_connection *conn;
691 LASSERT(obd != NULL);
693 LPROCFS_CLIMP_CHECK(obd);
694 conn = obd->u.cli.cl_import->imp_connection;
695 if (conn && obd->u.cli.cl_import)
696 seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
698 seq_puts(m, "<none>\n");
700 LPROCFS_CLIMP_EXIT(obd);
704 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
706 /** add up per-cpu counters */
707 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
708 struct lprocfs_counter *cnt)
710 unsigned int num_entry;
711 struct lprocfs_counter *percpu_cntr;
713 unsigned long flags = 0;
715 memset(cnt, 0, sizeof(*cnt));
718 /* set count to 1 to avoid divide-by-zero errs in callers */
723 cnt->lc_min = LC_MIN_INIT;
725 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
727 for (i = 0; i < num_entry; i++) {
728 if (stats->ls_percpu[i] == NULL)
730 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
732 cnt->lc_count += percpu_cntr->lc_count;
733 cnt->lc_sum += percpu_cntr->lc_sum;
734 if (percpu_cntr->lc_min < cnt->lc_min)
735 cnt->lc_min = percpu_cntr->lc_min;
736 if (percpu_cntr->lc_max > cnt->lc_max)
737 cnt->lc_max = percpu_cntr->lc_max;
738 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
741 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
743 EXPORT_SYMBOL(lprocfs_stats_collect);
746 * Append a space separated list of current set flags to str.
748 #define flag2str(flag, first) \
750 if (imp->imp_##flag) \
751 seq_printf(m, "%s" #flag, first ? "" : ", "); \
753 static int obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
757 if (imp->imp_obd->obd_no_recov) {
758 seq_printf(m, "no_recov");
762 flag2str(invalid, first);
764 flag2str(deactive, first);
765 flag2str(replayable, first);
766 flag2str(pingable, first);
771 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
777 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
779 seq_printf(m, "%s%s",
780 first ? sep : "", obd_connect_names[i]);
784 if (flags & ~(mask - 1))
785 seq_printf(m, "%sunknown flags %#llx",
786 first ? sep : "", flags & ~(mask - 1));
789 int lprocfs_rd_import(struct seq_file *m, void *data)
791 struct lprocfs_counter ret;
792 struct lprocfs_counter_header *header;
793 struct obd_device *obd = (struct obd_device *)data;
794 struct obd_import *imp;
795 struct obd_import_conn *conn;
800 LASSERT(obd != NULL);
801 LPROCFS_CLIMP_CHECK(obd);
802 imp = obd->u.cli.cl_import;
813 ptlrpc_import_state_name(imp->imp_state),
814 imp->imp_connect_data.ocd_instance);
815 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags, ", ");
819 obd_import_flags2str(imp, m);
824 " failover_nids: [");
825 spin_lock(&imp->imp_lock);
827 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
828 seq_printf(m, "%s%s", j ? ", " : "",
829 libcfs_nid2str(conn->oic_conn->c_peer.nid));
834 " current_connection: %s\n"
835 " connection_attempts: %u\n"
837 " in-progress_invalidations: %u\n",
838 imp->imp_connection == NULL ? "<none>" :
839 libcfs_nid2str(imp->imp_connection->c_peer.nid),
842 atomic_read(&imp->imp_inval_count));
843 spin_unlock(&imp->imp_lock);
845 if (obd->obd_svc_stats == NULL)
848 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
849 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
850 if (ret.lc_count != 0) {
851 /* first argument to do_div MUST be __u64 */
852 __u64 sum = ret.lc_sum;
853 do_div(sum, ret.lc_count);
860 " unregistering: %u\n"
862 " avg_waittime: %llu %s\n",
863 atomic_read(&imp->imp_inflight),
864 atomic_read(&imp->imp_unregistering),
865 atomic_read(&imp->imp_timeouts),
866 ret.lc_sum, header->lc_units);
869 for (j = 0; j < IMP_AT_MAX_PORTALS; j++) {
870 if (imp->imp_at.iat_portal[j] == 0)
872 k = max_t(unsigned int, k,
873 at_get(&imp->imp_at.iat_service_estimate[j]));
876 " service_estimates:\n"
877 " services: %u sec\n"
878 " network: %u sec\n",
880 at_get(&imp->imp_at.iat_net_latency));
884 " last_replay: %llu\n"
885 " peer_committed: %llu\n"
886 " last_checked: %llu\n",
887 imp->imp_last_replay_transno,
888 imp->imp_peer_committed_transno,
889 imp->imp_last_transno_checked);
892 for (rw = 0; rw <= 1; rw++) {
893 lprocfs_stats_collect(obd->obd_svc_stats,
894 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
896 if (ret.lc_sum > 0 && ret.lc_count > 0) {
897 /* first argument to do_div MUST be __u64 */
898 __u64 sum = ret.lc_sum;
899 do_div(sum, ret.lc_count);
902 " %s_data_averages:\n"
903 " bytes_per_rpc: %llu\n",
904 rw ? "write" : "read",
908 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
909 header = &obd->obd_svc_stats->ls_cnt_header[j];
910 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
911 if (ret.lc_sum > 0 && ret.lc_count != 0) {
912 /* first argument to do_div MUST be __u64 */
913 __u64 sum = ret.lc_sum;
914 do_div(sum, ret.lc_count);
917 " %s_per_rpc: %llu\n",
918 header->lc_units, ret.lc_sum);
922 " MB_per_sec: %u.%.02u\n",
923 k / j, (100 * k / j) % 100);
928 LPROCFS_CLIMP_EXIT(obd);
931 EXPORT_SYMBOL(lprocfs_rd_import);
933 int lprocfs_rd_state(struct seq_file *m, void *data)
935 struct obd_device *obd = (struct obd_device *)data;
936 struct obd_import *imp;
939 LASSERT(obd != NULL);
940 LPROCFS_CLIMP_CHECK(obd);
941 imp = obd->u.cli.cl_import;
943 seq_printf(m, "current_state: %s\n",
944 ptlrpc_import_state_name(imp->imp_state));
945 seq_printf(m, "state_history:\n");
946 k = imp->imp_state_hist_idx;
947 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
948 struct import_state_hist *ish =
949 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
950 if (ish->ish_state == 0)
952 seq_printf(m, " - ["CFS_TIME_T", %s]\n",
954 ptlrpc_import_state_name(ish->ish_state));
957 LPROCFS_CLIMP_EXIT(obd);
960 EXPORT_SYMBOL(lprocfs_rd_state);
962 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
965 for (i = 0; i < AT_BINS; i++)
966 seq_printf(m, "%3u ", at->at_hist[i]);
970 EXPORT_SYMBOL(lprocfs_at_hist_helper);
972 /* See also ptlrpc_lprocfs_rd_timeouts */
973 int lprocfs_rd_timeouts(struct seq_file *m, void *data)
975 struct obd_device *obd = (struct obd_device *)data;
976 struct obd_import *imp;
977 unsigned int cur, worst;
982 LASSERT(obd != NULL);
983 LPROCFS_CLIMP_CHECK(obd);
984 imp = obd->u.cli.cl_import;
988 /* Some network health info for kicks */
989 s2dhms(&ts, now - imp->imp_last_reply_time);
990 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
991 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
993 cur = at_get(&imp->imp_at.iat_net_latency);
994 worst = imp->imp_at.iat_net_latency.at_worst_ever;
995 worstt = imp->imp_at.iat_net_latency.at_worst_time;
996 s2dhms(&ts, now - worstt);
997 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
998 "network", cur, worst, worstt, DHMS_VARS(&ts));
999 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
1001 for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1002 if (imp->imp_at.iat_portal[i] == 0)
1004 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
1005 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
1006 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
1007 s2dhms(&ts, now - worstt);
1008 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
1009 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
1010 cur, worst, worstt, DHMS_VARS(&ts));
1011 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
1014 LPROCFS_CLIMP_EXIT(obd);
1017 EXPORT_SYMBOL(lprocfs_rd_timeouts);
1019 int lprocfs_rd_connect_flags(struct seq_file *m, void *data)
1021 struct obd_device *obd = data;
1024 LPROCFS_CLIMP_CHECK(obd);
1025 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
1026 seq_printf(m, "flags=%#llx\n", flags);
1027 obd_connect_seq_flags2str(m, flags, "\n");
1028 seq_printf(m, "\n");
1029 LPROCFS_CLIMP_EXIT(obd);
1032 EXPORT_SYMBOL(lprocfs_rd_connect_flags);
1034 static struct attribute *obd_def_attrs[] = {
1035 &lustre_attr_blocksize.attr,
1036 &lustre_attr_kbytestotal.attr,
1037 &lustre_attr_kbytesfree.attr,
1038 &lustre_attr_kbytesavail.attr,
1039 &lustre_attr_filestotal.attr,
1040 &lustre_attr_filesfree.attr,
1041 &lustre_attr_uuid.attr,
1045 static void obd_sysfs_release(struct kobject *kobj)
1047 struct obd_device *obd = container_of(kobj, struct obd_device,
1050 complete(&obd->obd_kobj_unregister);
1053 static struct kobj_type obd_ktype = {
1054 .default_attrs = obd_def_attrs,
1055 .sysfs_ops = &lustre_sysfs_ops,
1056 .release = obd_sysfs_release,
1059 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list,
1060 struct attribute_group *attrs)
1064 init_completion(&obd->obd_kobj_unregister);
1065 rc = kobject_init_and_add(&obd->obd_kobj, &obd_ktype,
1066 obd->obd_type->typ_kobj,
1067 "%s", obd->obd_name);
1072 rc = sysfs_create_group(&obd->obd_kobj, attrs);
1074 kobject_put(&obd->obd_kobj);
1079 obd->obd_debugfs_entry = ldebugfs_register(obd->obd_name,
1080 obd->obd_type->typ_debugfs_entry,
1082 if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
1083 rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
1085 CERROR("error %d setting up lprocfs for %s\n",
1087 obd->obd_debugfs_entry = NULL;
1092 EXPORT_SYMBOL(lprocfs_obd_setup);
1094 int lprocfs_obd_cleanup(struct obd_device *obd)
1099 if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
1100 ldebugfs_remove(&obd->obd_debugfs_entry);
1102 kobject_put(&obd->obd_kobj);
1103 wait_for_completion(&obd->obd_kobj_unregister);
1107 EXPORT_SYMBOL(lprocfs_obd_cleanup);
1109 static void lprocfs_free_client_stats(struct nid_stat *client_stat)
1111 CDEBUG(D_CONFIG, "stat %p - data %p/%p\n", client_stat,
1112 client_stat->nid_proc, client_stat->nid_stats);
1114 LASSERTF(atomic_read(&client_stat->nid_exp_ref_count) == 0,
1115 "nid %s:count %d\n", libcfs_nid2str(client_stat->nid),
1116 atomic_read(&client_stat->nid_exp_ref_count));
1118 if (client_stat->nid_proc)
1119 lprocfs_remove(&client_stat->nid_proc);
1121 if (client_stat->nid_stats)
1122 lprocfs_free_stats(&client_stat->nid_stats);
1124 if (client_stat->nid_ldlm_stats)
1125 lprocfs_free_stats(&client_stat->nid_ldlm_stats);
1132 void lprocfs_free_per_client_stats(struct obd_device *obd)
1134 struct cfs_hash *hash = obd->obd_nid_stats_hash;
1135 struct nid_stat *stat;
1137 /* we need extra list - because hash_exit called to early */
1138 /* not need locking because all clients is died */
1139 while (!list_empty(&obd->obd_nid_stats)) {
1140 stat = list_entry(obd->obd_nid_stats.next,
1141 struct nid_stat, nid_list);
1142 list_del_init(&stat->nid_list);
1143 cfs_hash_del(hash, &stat->nid, &stat->nid_hash);
1144 lprocfs_free_client_stats(stat);
1147 EXPORT_SYMBOL(lprocfs_free_per_client_stats);
1149 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1151 struct lprocfs_counter *cntr;
1152 unsigned int percpusize;
1154 unsigned long flags = 0;
1157 LASSERT(stats->ls_percpu[cpuid] == NULL);
1158 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1160 percpusize = lprocfs_stats_counter_size(stats);
1161 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1162 if (stats->ls_percpu[cpuid] != NULL) {
1164 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1165 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1166 spin_lock_irqsave(&stats->ls_lock, flags);
1168 spin_lock(&stats->ls_lock);
1169 if (stats->ls_biggest_alloc_num <= cpuid)
1170 stats->ls_biggest_alloc_num = cpuid + 1;
1171 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1172 spin_unlock_irqrestore(&stats->ls_lock, flags);
1174 spin_unlock(&stats->ls_lock);
1176 /* initialize the ls_percpu[cpuid] non-zero counter */
1177 for (i = 0; i < stats->ls_num; ++i) {
1178 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1179 cntr->lc_min = LC_MIN_INIT;
1184 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1186 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1187 enum lprocfs_stats_flags flags)
1189 struct lprocfs_stats *stats;
1190 unsigned int num_entry;
1191 unsigned int percpusize = 0;
1197 if (lprocfs_no_percpu_stats != 0)
1198 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1200 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1203 num_entry = num_possible_cpus();
1205 /* alloc percpu pointers for all possible cpu slots */
1206 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1210 stats->ls_num = num;
1211 stats->ls_flags = flags;
1212 spin_lock_init(&stats->ls_lock);
1214 /* alloc num of counter headers */
1215 LIBCFS_ALLOC(stats->ls_cnt_header,
1216 stats->ls_num * sizeof(struct lprocfs_counter_header));
1217 if (stats->ls_cnt_header == NULL)
1220 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1221 /* contains only one set counters */
1222 percpusize = lprocfs_stats_counter_size(stats);
1223 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1224 if (stats->ls_percpu[0] == NULL)
1226 stats->ls_biggest_alloc_num = 1;
1227 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1228 /* alloc all percpu data, currently only obd_memory use this */
1229 for (i = 0; i < num_entry; ++i)
1230 if (lprocfs_stats_alloc_one(stats, i) < 0)
1237 lprocfs_free_stats(&stats);
1240 EXPORT_SYMBOL(lprocfs_alloc_stats);
1242 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1244 struct lprocfs_stats *stats = *statsh;
1245 unsigned int num_entry;
1246 unsigned int percpusize;
1249 if (stats == NULL || stats->ls_num == 0)
1253 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1256 num_entry = num_possible_cpus();
1258 percpusize = lprocfs_stats_counter_size(stats);
1259 for (i = 0; i < num_entry; i++)
1260 if (stats->ls_percpu[i] != NULL)
1261 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1262 if (stats->ls_cnt_header != NULL)
1263 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1264 sizeof(struct lprocfs_counter_header));
1265 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1267 EXPORT_SYMBOL(lprocfs_free_stats);
1269 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1271 struct lprocfs_counter *percpu_cntr;
1274 unsigned int num_entry;
1275 unsigned long flags = 0;
1277 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1279 for (i = 0; i < num_entry; i++) {
1280 if (stats->ls_percpu[i] == NULL)
1282 for (j = 0; j < stats->ls_num; j++) {
1283 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1284 percpu_cntr->lc_count = 0;
1285 percpu_cntr->lc_min = LC_MIN_INIT;
1286 percpu_cntr->lc_max = 0;
1287 percpu_cntr->lc_sumsquare = 0;
1288 percpu_cntr->lc_sum = 0;
1289 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1290 percpu_cntr->lc_sum_irq = 0;
1294 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1296 EXPORT_SYMBOL(lprocfs_clear_stats);
1298 static ssize_t lprocfs_stats_seq_write(struct file *file,
1299 const char __user *buf,
1300 size_t len, loff_t *off)
1302 struct seq_file *seq = file->private_data;
1303 struct lprocfs_stats *stats = seq->private;
1305 lprocfs_clear_stats(stats);
1310 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1312 struct lprocfs_stats *stats = p->private;
1314 return (*pos < stats->ls_num) ? pos : NULL;
1317 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1321 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1324 return lprocfs_stats_seq_start(p, pos);
1327 /* seq file export of one lprocfs counter */
1328 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1330 struct lprocfs_stats *stats = p->private;
1331 struct lprocfs_counter_header *hdr;
1332 struct lprocfs_counter ctr;
1333 int idx = *(loff_t *)v;
1337 do_gettimeofday(&now);
1338 seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
1340 now.tv_sec, (unsigned long)now.tv_usec);
1343 hdr = &stats->ls_cnt_header[idx];
1344 lprocfs_stats_collect(stats, idx, &ctr);
1346 if (ctr.lc_count != 0) {
1347 seq_printf(p, "%-25s %lld samples [%s]",
1348 hdr->lc_name, ctr.lc_count, hdr->lc_units);
1350 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) &&
1351 (ctr.lc_count > 0)) {
1352 seq_printf(p, " %lld %lld %lld",
1353 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1354 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1355 seq_printf(p, " %lld", ctr.lc_sumsquare);
1363 static const struct seq_operations lprocfs_stats_seq_sops = {
1364 .start = lprocfs_stats_seq_start,
1365 .stop = lprocfs_stats_seq_stop,
1366 .next = lprocfs_stats_seq_next,
1367 .show = lprocfs_stats_seq_show,
1370 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1372 struct seq_file *seq;
1375 rc = seq_open(file, &lprocfs_stats_seq_sops);
1379 seq = file->private_data;
1380 seq->private = inode->i_private ?: PDE_DATA(inode);
1385 struct file_operations lprocfs_stats_seq_fops = {
1386 .owner = THIS_MODULE,
1387 .open = lprocfs_stats_seq_open,
1389 .write = lprocfs_stats_seq_write,
1390 .llseek = seq_lseek,
1391 .release = lprocfs_seq_release,
1394 int ldebugfs_register_stats(struct dentry *parent, const char *name,
1395 struct lprocfs_stats *stats)
1397 struct dentry *entry;
1399 LASSERT(!IS_ERR_OR_NULL(parent));
1401 entry = debugfs_create_file(name, 0644, parent, stats,
1402 &lprocfs_stats_seq_fops);
1403 if (IS_ERR_OR_NULL(entry))
1404 return entry ? PTR_ERR(entry) : -ENOMEM;
1408 EXPORT_SYMBOL(ldebugfs_register_stats);
1410 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1411 struct lprocfs_stats *stats)
1413 struct proc_dir_entry *entry;
1414 LASSERT(root != NULL);
1416 entry = proc_create_data(name, 0644, root,
1417 &lprocfs_stats_seq_fops, stats);
1423 EXPORT_SYMBOL(lprocfs_register_stats);
1425 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1426 unsigned conf, const char *name, const char *units)
1428 struct lprocfs_counter_header *header;
1429 struct lprocfs_counter *percpu_cntr;
1430 unsigned long flags = 0;
1432 unsigned int num_cpu;
1434 LASSERT(stats != NULL);
1436 header = &stats->ls_cnt_header[index];
1437 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1438 index, name, units);
1440 header->lc_config = conf;
1441 header->lc_name = name;
1442 header->lc_units = units;
1444 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1445 for (i = 0; i < num_cpu; ++i) {
1446 if (stats->ls_percpu[i] == NULL)
1448 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1449 percpu_cntr->lc_count = 0;
1450 percpu_cntr->lc_min = LC_MIN_INIT;
1451 percpu_cntr->lc_max = 0;
1452 percpu_cntr->lc_sumsquare = 0;
1453 percpu_cntr->lc_sum = 0;
1454 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1455 percpu_cntr->lc_sum_irq = 0;
1457 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1459 EXPORT_SYMBOL(lprocfs_counter_init);
1461 #define LPROCFS_OBD_OP_INIT(base, stats, op) \
1463 unsigned int coffset = base + OBD_COUNTER_OFFSET(op); \
1464 LASSERT(coffset < stats->ls_num); \
1465 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1468 void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
1470 LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
1471 LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
1472 LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info_async);
1473 LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);
1474 LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);
1475 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
1476 LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
1477 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
1478 LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);
1479 LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
1480 LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);
1481 LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);
1482 LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
1483 LPROCFS_OBD_OP_INIT(num_private_stats, stats, reconnect);
1484 LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
1485 LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_init);
1486 LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_fini);
1487 LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_alloc);
1488 LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
1489 LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);
1490 LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
1491 LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
1492 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
1493 LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
1494 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
1495 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
1496 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr_async);
1497 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
1498 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
1499 LPROCFS_OBD_OP_INIT(num_private_stats, stats, adjust_kms);
1500 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
1501 LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
1502 LPROCFS_OBD_OP_INIT(num_private_stats, stats, find_cbdata);
1503 LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
1504 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
1505 LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
1506 LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
1507 LPROCFS_OBD_OP_INIT(num_private_stats, stats, health_check);
1508 LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_uuid);
1509 LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotacheck);
1510 LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotactl);
1511 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_new);
1512 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_rem);
1513 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_add);
1514 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_del);
1515 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getref);
1516 LPROCFS_OBD_OP_INIT(num_private_stats, stats, putref);
1518 EXPORT_SYMBOL(lprocfs_init_ops_stats);
1520 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
1522 struct lprocfs_stats *stats;
1523 unsigned int num_stats;
1526 LASSERT(obd->obd_stats == NULL);
1527 LASSERT(obd->obd_debugfs_entry != NULL);
1528 LASSERT(obd->obd_cntr_base == 0);
1530 num_stats = ((int)sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
1531 num_private_stats - 1 /* o_owner */;
1532 stats = lprocfs_alloc_stats(num_stats, 0);
1536 lprocfs_init_ops_stats(num_private_stats, stats);
1538 for (i = num_private_stats; i < num_stats; i++) {
1539 /* If this LBUGs, it is likely that an obd
1540 * operation was added to struct obd_ops in
1541 * <obd.h>, and that the corresponding line item
1542 * LPROCFS_OBD_OP_INIT(.., .., opname)
1543 * is missing from the list above. */
1544 LASSERTF(stats->ls_cnt_header[i].lc_name != NULL,
1545 "Missing obd_stat initializer obd_op operation at offset %d.\n",
1546 i - num_private_stats);
1548 rc = ldebugfs_register_stats(obd->obd_debugfs_entry, "stats", stats);
1550 lprocfs_free_stats(&stats);
1552 obd->obd_stats = stats;
1553 obd->obd_cntr_base = num_private_stats;
1557 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
1559 void lprocfs_free_obd_stats(struct obd_device *obd)
1562 lprocfs_free_stats(&obd->obd_stats);
1564 EXPORT_SYMBOL(lprocfs_free_obd_stats);
1566 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1568 unsigned int coffset = base + MD_COUNTER_OFFSET(op); \
1569 LASSERT(coffset < stats->ls_num); \
1570 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1573 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
1575 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
1576 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
1577 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
1578 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
1579 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
1580 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
1581 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
1582 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
1583 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
1584 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
1585 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
1586 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
1587 LPROCFS_MD_OP_INIT(num_private_stats, stats, is_subdir);
1588 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
1589 LPROCFS_MD_OP_INIT(num_private_stats, stats, sync);
1590 LPROCFS_MD_OP_INIT(num_private_stats, stats, readpage);
1591 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
1592 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
1593 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
1594 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
1595 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
1596 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
1597 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
1598 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
1599 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
1600 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
1601 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
1602 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
1603 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
1604 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
1605 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
1606 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
1608 EXPORT_SYMBOL(lprocfs_init_mps_stats);
1610 int lprocfs_alloc_md_stats(struct obd_device *obd,
1611 unsigned num_private_stats)
1613 struct lprocfs_stats *stats;
1614 unsigned int num_stats;
1617 LASSERT(obd->md_stats == NULL);
1618 LASSERT(obd->obd_debugfs_entry != NULL);
1619 LASSERT(obd->md_cntr_base == 0);
1621 num_stats = 1 + MD_COUNTER_OFFSET(revalidate_lock) +
1623 stats = lprocfs_alloc_stats(num_stats, 0);
1627 lprocfs_init_mps_stats(num_private_stats, stats);
1629 for (i = num_private_stats; i < num_stats; i++) {
1630 if (stats->ls_cnt_header[i].lc_name == NULL) {
1631 CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
1632 i - num_private_stats);
1636 rc = ldebugfs_register_stats(obd->obd_debugfs_entry, "md_stats", stats);
1638 lprocfs_free_stats(&stats);
1640 obd->md_stats = stats;
1641 obd->md_cntr_base = num_private_stats;
1645 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1647 void lprocfs_free_md_stats(struct obd_device *obd)
1649 struct lprocfs_stats *stats = obd->md_stats;
1651 if (stats != NULL) {
1652 obd->md_stats = NULL;
1653 obd->md_cntr_base = 0;
1654 lprocfs_free_stats(&stats);
1657 EXPORT_SYMBOL(lprocfs_free_md_stats);
1659 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1661 lprocfs_counter_init(ldlm_stats,
1662 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1663 0, "ldlm_enqueue", "reqs");
1664 lprocfs_counter_init(ldlm_stats,
1665 LDLM_CONVERT - LDLM_FIRST_OPC,
1666 0, "ldlm_convert", "reqs");
1667 lprocfs_counter_init(ldlm_stats,
1668 LDLM_CANCEL - LDLM_FIRST_OPC,
1669 0, "ldlm_cancel", "reqs");
1670 lprocfs_counter_init(ldlm_stats,
1671 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1672 0, "ldlm_bl_callback", "reqs");
1673 lprocfs_counter_init(ldlm_stats,
1674 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1675 0, "ldlm_cp_callback", "reqs");
1676 lprocfs_counter_init(ldlm_stats,
1677 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1678 0, "ldlm_gl_callback", "reqs");
1680 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1682 int lprocfs_nid_stats_clear_read(struct seq_file *m, void *data)
1684 seq_printf(m, "%s\n",
1685 "Write into this file to clear all nid stats and stale nid entries");
1688 EXPORT_SYMBOL(lprocfs_nid_stats_clear_read);
1690 static int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
1692 struct nid_stat *stat = obj;
1694 CDEBUG(D_INFO, "refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
1695 if (atomic_read(&stat->nid_exp_ref_count) == 1) {
1696 /* object has only hash references. */
1697 spin_lock(&stat->nid_obd->obd_nid_lock);
1698 list_move(&stat->nid_list, data);
1699 spin_unlock(&stat->nid_obd->obd_nid_lock);
1702 /* we has reference to object - only clear data*/
1703 if (stat->nid_stats)
1704 lprocfs_clear_stats(stat->nid_stats);
1709 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
1710 unsigned long count, void *data)
1712 struct obd_device *obd = (struct obd_device *)data;
1713 struct nid_stat *client_stat;
1714 LIST_HEAD(free_list);
1716 cfs_hash_cond_del(obd->obd_nid_stats_hash,
1717 lprocfs_nid_stats_clear_write_cb, &free_list);
1719 while (!list_empty(&free_list)) {
1720 client_stat = list_entry(free_list.next, struct nid_stat,
1722 list_del_init(&client_stat->nid_list);
1723 lprocfs_free_client_stats(client_stat);
1728 EXPORT_SYMBOL(lprocfs_nid_stats_clear_write);
1730 int lprocfs_exp_cleanup(struct obd_export *exp)
1732 struct nid_stat *stat = exp->exp_nid_stats;
1734 if (!stat || !exp->exp_obd)
1737 nidstat_putref(exp->exp_nid_stats);
1738 exp->exp_nid_stats = NULL;
1742 EXPORT_SYMBOL(lprocfs_exp_cleanup);
1744 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1745 struct lprocfs_counter_header *header,
1746 enum lprocfs_stats_flags flags,
1747 enum lprocfs_fields_flags field)
1751 if (lc == NULL || header == NULL)
1755 case LPROCFS_FIELDS_FLAGS_CONFIG:
1756 ret = header->lc_config;
1758 case LPROCFS_FIELDS_FLAGS_SUM:
1760 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1761 ret += lc->lc_sum_irq;
1763 case LPROCFS_FIELDS_FLAGS_MIN:
1766 case LPROCFS_FIELDS_FLAGS_MAX:
1769 case LPROCFS_FIELDS_FLAGS_AVG:
1770 ret = (lc->lc_max - lc->lc_min) / 2;
1772 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1773 ret = lc->lc_sumsquare;
1775 case LPROCFS_FIELDS_FLAGS_COUNT:
1784 EXPORT_SYMBOL(lprocfs_read_helper);
1786 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
1789 return lprocfs_write_frac_helper(buffer, count, val, 1);
1791 EXPORT_SYMBOL(lprocfs_write_helper);
1793 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1795 long decimal_val, frac_val;
1797 decimal_val = val / mult;
1798 seq_printf(m, "%ld", decimal_val);
1799 frac_val = val % mult;
1806 /* Three cases: x0, xx, 0x */
1807 if ((frac_val % 10) != 0)
1808 seq_printf(m, ".%ld", frac_val);
1810 seq_printf(m, ".%ld", frac_val / 10);
1813 seq_printf(m, "\n");
1816 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1818 int lprocfs_write_u64_helper(const char __user *buffer, unsigned long count,
1821 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
1823 EXPORT_SYMBOL(lprocfs_write_u64_helper);
1825 int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
1826 __u64 *val, int mult)
1828 char kernbuf[22], *end, *pbuf;
1829 __u64 whole, frac = 0, units;
1830 unsigned frac_d = 1;
1833 if (count > (sizeof(kernbuf) - 1))
1836 if (copy_from_user(kernbuf, buffer, count))
1839 kernbuf[count] = '\0';
1846 whole = simple_strtoull(pbuf, &end, 10);
1854 /* need to limit frac_d to a __u32 */
1855 if (strlen(pbuf) > 10)
1858 frac = simple_strtoull(pbuf, &end, 10);
1859 /* count decimal places */
1860 for (i = 0; i < (end - pbuf); i++)
1865 switch (tolower(*end)) {
1877 /* Specified units override the multiplier */
1882 do_div(frac, frac_d);
1883 *val = sign * (whole * mult + frac);
1886 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
1888 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
1897 if (!memcmp(s1, s2, l2))
1905 * Find the string \a name in the input \a buffer, and return a pointer to the
1906 * value immediately following \a name, reducing \a count appropriately.
1907 * If \a name is not found the original \a buffer is returned.
1909 char *lprocfs_find_named_value(const char *buffer, const char *name,
1913 size_t buflen = *count;
1915 /* there is no strnstr() in rhel5 and ubuntu kernels */
1916 val = lprocfs_strnstr(buffer, name, buflen);
1918 return (char *)buffer;
1920 val += strlen(name); /* skip prefix */
1921 while (val < buffer + buflen && isspace(*val)) /* skip separator */
1925 while (val < buffer + buflen && isalnum(*val)) {
1930 return val - *count;
1932 EXPORT_SYMBOL(lprocfs_find_named_value);
1934 int ldebugfs_seq_create(struct dentry *parent,
1937 const struct file_operations *seq_fops,
1940 struct dentry *entry;
1942 /* Disallow secretly (un)writable entries. */
1943 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
1945 entry = debugfs_create_file(name, mode, parent, data, seq_fops);
1946 if (IS_ERR_OR_NULL(entry))
1947 return entry ? PTR_ERR(entry) : -ENOMEM;
1951 EXPORT_SYMBOL(ldebugfs_seq_create);
1953 int lprocfs_seq_create(struct proc_dir_entry *parent,
1956 const struct file_operations *seq_fops,
1959 struct proc_dir_entry *entry;
1961 /* Disallow secretly (un)writable entries. */
1962 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
1963 entry = proc_create_data(name, mode, parent, seq_fops, data);
1970 EXPORT_SYMBOL(lprocfs_seq_create);
1972 int lprocfs_obd_seq_create(struct obd_device *dev,
1975 const struct file_operations *seq_fops,
1978 return ldebugfs_seq_create(dev->obd_debugfs_entry, name,
1979 mode, seq_fops, data);
1981 EXPORT_SYMBOL(lprocfs_obd_seq_create);
1983 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1985 if (value >= OBD_HIST_MAX)
1986 value = OBD_HIST_MAX - 1;
1988 spin_lock(&oh->oh_lock);
1989 oh->oh_buckets[value]++;
1990 spin_unlock(&oh->oh_lock);
1992 EXPORT_SYMBOL(lprocfs_oh_tally);
1994 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1998 for (val = 0; ((1 << val) < value) && (val <= OBD_HIST_MAX); val++)
2001 lprocfs_oh_tally(oh, val);
2003 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2005 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2007 unsigned long ret = 0;
2010 for (i = 0; i < OBD_HIST_MAX; i++)
2011 ret += oh->oh_buckets[i];
2014 EXPORT_SYMBOL(lprocfs_oh_sum);
2016 void lprocfs_oh_clear(struct obd_histogram *oh)
2018 spin_lock(&oh->oh_lock);
2019 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2020 spin_unlock(&oh->oh_lock);
2022 EXPORT_SYMBOL(lprocfs_oh_clear);
2024 int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data)
2026 struct obd_device *dev = data;
2027 struct client_obd *cli = &dev->u.cli;
2029 client_obd_list_lock(&cli->cl_loi_list_lock);
2030 seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2031 client_obd_list_unlock(&cli->cl_loi_list_lock);
2035 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
2039 ssize_t lustre_attr_show(struct kobject *kobj,
2040 struct attribute *attr, char *buf)
2042 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2044 return a->show ? a->show(kobj, attr, buf) : 0;
2046 EXPORT_SYMBOL_GPL(lustre_attr_show);
2048 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
2049 const char *buf, size_t len)
2051 struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
2053 return a->store ? a->store(kobj, attr, buf, len) : len;
2055 EXPORT_SYMBOL_GPL(lustre_attr_store);
2057 const struct sysfs_ops lustre_sysfs_ops = {
2058 .show = lustre_attr_show,
2059 .store = lustre_attr_store,
2061 EXPORT_SYMBOL_GPL(lustre_sysfs_ops);