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>
49 static const char * const obd_connect_names[] = {
63 "join_file(obsolete)",
67 "remote_client_by_force",
79 "alt_checksum_algorithm",
107 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
112 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
114 ret += snprintf(page + ret, count - ret, "%s%s",
115 ret ? sep : "", obd_connect_names[i]);
117 if (flags & ~(mask - 1))
118 ret += snprintf(page + ret, count - ret,
119 "%sunknown flags %#llx",
120 ret ? sep : "", flags & ~(mask - 1));
123 EXPORT_SYMBOL(obd_connect_flags2str);
125 int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
128 long decimal_val, frac_val;
134 decimal_val = val / mult;
135 prtn = snprintf(buffer, count, "%ld", decimal_val);
136 frac_val = val % mult;
138 if (prtn < (count - 4) && frac_val > 0) {
140 int i, temp_mult = 1, frac_bits = 0;
142 temp_frac = frac_val * 10;
143 buffer[prtn++] = '.';
144 while (frac_bits < 2 && (temp_frac / mult) < 1) {
145 /* only reserved 2 bits fraction */
146 buffer[prtn++] = '0';
151 * Need to think these cases :
152 * 1. #echo x.00 > /proc/xxx output result : x
153 * 2. #echo x.0x > /proc/xxx output result : x.0x
154 * 3. #echo x.x0 > /proc/xxx output result : x.x
155 * 4. #echo x.xx > /proc/xxx output result : x.xx
156 * Only reserved 2 bits fraction.
158 for (i = 0; i < (5 - prtn); i++)
161 frac_bits = min((int)count - prtn, 3 - frac_bits);
162 prtn += snprintf(buffer + prtn, frac_bits, "%ld",
163 frac_val * temp_mult / mult);
166 while (buffer[prtn] < '1' || buffer[prtn] > '9') {
168 if (buffer[prtn] == '.') {
175 buffer[prtn++] = '\n';
178 EXPORT_SYMBOL(lprocfs_read_frac_helper);
180 int lprocfs_write_frac_helper(const char __user *buffer, unsigned long count,
183 char kernbuf[20], *end, *pbuf;
185 if (count > (sizeof(kernbuf) - 1))
188 if (copy_from_user(kernbuf, buffer, count))
191 kernbuf[count] = '\0';
198 *val = (int)simple_strtoul(pbuf, &end, 10) * mult;
202 if (end != NULL && *end == '.') {
203 int temp_val, pow = 1;
207 if (strlen(pbuf) > 5)
208 pbuf[5] = '\0'; /*only allow 5bits fractional*/
210 temp_val = (int)simple_strtoul(pbuf, &end, 10) * mult;
213 for (i = 0; i < (end - pbuf); i++)
216 *val += temp_val / pow;
221 EXPORT_SYMBOL(lprocfs_write_frac_helper);
223 #if defined (CONFIG_PROC_FS)
225 static int lprocfs_no_percpu_stats = 0;
226 module_param(lprocfs_no_percpu_stats, int, 0644);
227 MODULE_PARM_DESC(lprocfs_no_percpu_stats, "Do not alloc percpu data for lprocfs stats");
229 #define MAX_STRING_SIZE 128
231 int lprocfs_single_release(struct inode *inode, struct file *file)
233 return single_release(inode, file);
235 EXPORT_SYMBOL(lprocfs_single_release);
237 int lprocfs_seq_release(struct inode *inode, struct file *file)
239 return seq_release(inode, file);
241 EXPORT_SYMBOL(lprocfs_seq_release);
243 /* lprocfs API calls */
245 struct proc_dir_entry *lprocfs_add_simple(struct proc_dir_entry *root,
246 char *name, void *data,
247 struct file_operations *fops)
249 struct proc_dir_entry *proc;
252 if (root == NULL || name == NULL || fops == NULL)
253 return ERR_PTR(-EINVAL);
259 proc = proc_create_data(name, mode, root, fops, data);
261 CERROR("LprocFS: No memory to create /proc entry %s", name);
262 return ERR_PTR(-ENOMEM);
266 EXPORT_SYMBOL(lprocfs_add_simple);
268 struct proc_dir_entry *lprocfs_add_symlink(const char *name,
269 struct proc_dir_entry *parent, const char *format, ...)
271 struct proc_dir_entry *entry;
275 if (parent == NULL || format == NULL)
278 OBD_ALLOC_WAIT(dest, MAX_STRING_SIZE + 1);
282 va_start(ap, format);
283 vsnprintf(dest, MAX_STRING_SIZE, format, ap);
286 entry = proc_symlink(name, parent, dest);
288 CERROR("LprocFS: Could not create symbolic link from %s to %s",
291 OBD_FREE(dest, MAX_STRING_SIZE + 1);
294 EXPORT_SYMBOL(lprocfs_add_symlink);
296 static struct file_operations lprocfs_generic_fops = { };
301 * \param root [in] The parent proc entry on which new entry will be added.
302 * \param list [in] Array of proc entries to be added.
303 * \param data [in] The argument to be passed when entries read/write routines
304 * are called through /proc file.
306 * \retval 0 on success
309 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
312 if (root == NULL || list == NULL)
315 while (list->name != NULL) {
316 struct proc_dir_entry *proc;
319 if (list->proc_mode != 0000) {
320 mode = list->proc_mode;
321 } else if (list->fops) {
322 if (list->fops->read)
324 if (list->fops->write)
327 proc = proc_create_data(list->name, mode, root,
328 list->fops ?: &lprocfs_generic_fops,
336 EXPORT_SYMBOL(lprocfs_add_vars);
338 void lprocfs_remove(struct proc_dir_entry **rooth)
343 EXPORT_SYMBOL(lprocfs_remove);
345 void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent)
347 LASSERT(parent != NULL);
348 remove_proc_entry(name, parent);
350 EXPORT_SYMBOL(lprocfs_remove_proc_entry);
352 struct proc_dir_entry *lprocfs_register(const char *name,
353 struct proc_dir_entry *parent,
354 struct lprocfs_vars *list, void *data)
356 struct proc_dir_entry *entry;
358 entry = proc_mkdir(name, parent);
360 entry = ERR_PTR(-ENOMEM);
365 int rc = lprocfs_add_vars(entry, list, data);
367 lprocfs_remove(&entry);
374 EXPORT_SYMBOL(lprocfs_register);
376 /* Generic callbacks */
377 int lprocfs_rd_uint(struct seq_file *m, void *data)
379 return seq_printf(m, "%u\n", *(unsigned int *)data);
381 EXPORT_SYMBOL(lprocfs_rd_uint);
383 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
384 unsigned long count, void *data)
387 char dummy[MAX_STRING_SIZE + 1], *end;
390 dummy[MAX_STRING_SIZE] = '\0';
391 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
394 tmp = simple_strtoul(dummy, &end, 0);
398 *p = (unsigned int)tmp;
401 EXPORT_SYMBOL(lprocfs_wr_uint);
403 int lprocfs_rd_u64(struct seq_file *m, void *data)
405 return seq_printf(m, "%llu\n", *(__u64 *)data);
407 EXPORT_SYMBOL(lprocfs_rd_u64);
409 int lprocfs_rd_atomic(struct seq_file *m, void *data)
411 atomic_t *atom = data;
412 LASSERT(atom != NULL);
413 return seq_printf(m, "%d\n", atomic_read(atom));
415 EXPORT_SYMBOL(lprocfs_rd_atomic);
417 int lprocfs_wr_atomic(struct file *file, const char __user *buffer,
418 unsigned long count, void *data)
420 atomic_t *atm = data;
424 rc = lprocfs_write_helper(buffer, count, &val);
431 atomic_set(atm, val);
434 EXPORT_SYMBOL(lprocfs_wr_atomic);
436 int lprocfs_rd_uuid(struct seq_file *m, void *data)
438 struct obd_device *obd = data;
440 LASSERT(obd != NULL);
441 return seq_printf(m, "%s\n", obd->obd_uuid.uuid);
443 EXPORT_SYMBOL(lprocfs_rd_uuid);
445 int lprocfs_rd_name(struct seq_file *m, void *data)
447 struct obd_device *dev = data;
449 LASSERT(dev != NULL);
450 return seq_printf(m, "%s\n", dev->obd_name);
452 EXPORT_SYMBOL(lprocfs_rd_name);
454 int lprocfs_rd_blksize(struct seq_file *m, void *data)
456 struct obd_device *obd = data;
457 struct obd_statfs osfs;
458 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
459 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
462 rc = seq_printf(m, "%u\n", osfs.os_bsize);
465 EXPORT_SYMBOL(lprocfs_rd_blksize);
467 int lprocfs_rd_kbytestotal(struct seq_file *m, void *data)
469 struct obd_device *obd = data;
470 struct obd_statfs osfs;
471 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
472 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
475 __u32 blk_size = osfs.os_bsize >> 10;
476 __u64 result = osfs.os_blocks;
478 while (blk_size >>= 1)
481 rc = seq_printf(m, "%llu\n", result);
485 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);
487 int lprocfs_rd_kbytesfree(struct seq_file *m, void *data)
489 struct obd_device *obd = data;
490 struct obd_statfs osfs;
491 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
492 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
495 __u32 blk_size = osfs.os_bsize >> 10;
496 __u64 result = osfs.os_bfree;
498 while (blk_size >>= 1)
501 rc = seq_printf(m, "%llu\n", result);
505 EXPORT_SYMBOL(lprocfs_rd_kbytesfree);
507 int lprocfs_rd_kbytesavail(struct seq_file *m, void *data)
509 struct obd_device *obd = data;
510 struct obd_statfs osfs;
511 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
512 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
515 __u32 blk_size = osfs.os_bsize >> 10;
516 __u64 result = osfs.os_bavail;
518 while (blk_size >>= 1)
521 rc = seq_printf(m, "%llu\n", result);
525 EXPORT_SYMBOL(lprocfs_rd_kbytesavail);
527 int lprocfs_rd_filestotal(struct seq_file *m, void *data)
529 struct obd_device *obd = data;
530 struct obd_statfs osfs;
531 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
532 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
535 rc = seq_printf(m, "%llu\n", osfs.os_files);
539 EXPORT_SYMBOL(lprocfs_rd_filestotal);
541 int lprocfs_rd_filesfree(struct seq_file *m, void *data)
543 struct obd_device *obd = data;
544 struct obd_statfs osfs;
545 int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
546 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
549 rc = seq_printf(m, "%llu\n", osfs.os_ffree);
552 EXPORT_SYMBOL(lprocfs_rd_filesfree);
554 int lprocfs_rd_server_uuid(struct seq_file *m, void *data)
556 struct obd_device *obd = data;
557 struct obd_import *imp;
558 char *imp_state_name = NULL;
561 LASSERT(obd != NULL);
562 LPROCFS_CLIMP_CHECK(obd);
563 imp = obd->u.cli.cl_import;
564 imp_state_name = ptlrpc_import_state_name(imp->imp_state);
565 rc = seq_printf(m, "%s\t%s%s\n", obd2cli_tgt(obd), imp_state_name,
566 imp->imp_deactive ? "\tDEACTIVATED" : "");
568 LPROCFS_CLIMP_EXIT(obd);
571 EXPORT_SYMBOL(lprocfs_rd_server_uuid);
573 int lprocfs_rd_conn_uuid(struct seq_file *m, void *data)
575 struct obd_device *obd = data;
576 struct ptlrpc_connection *conn;
579 LASSERT(obd != NULL);
581 LPROCFS_CLIMP_CHECK(obd);
582 conn = obd->u.cli.cl_import->imp_connection;
583 if (conn && obd->u.cli.cl_import)
584 rc = seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
586 rc = seq_printf(m, "%s\n", "<none>");
588 LPROCFS_CLIMP_EXIT(obd);
591 EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
593 /** add up per-cpu counters */
594 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
595 struct lprocfs_counter *cnt)
597 unsigned int num_entry;
598 struct lprocfs_counter *percpu_cntr;
600 unsigned long flags = 0;
602 memset(cnt, 0, sizeof(*cnt));
605 /* set count to 1 to avoid divide-by-zero errs in callers */
610 cnt->lc_min = LC_MIN_INIT;
612 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
614 for (i = 0; i < num_entry; i++) {
615 if (stats->ls_percpu[i] == NULL)
617 percpu_cntr = lprocfs_stats_counter_get(stats, i, idx);
619 cnt->lc_count += percpu_cntr->lc_count;
620 cnt->lc_sum += percpu_cntr->lc_sum;
621 if (percpu_cntr->lc_min < cnt->lc_min)
622 cnt->lc_min = percpu_cntr->lc_min;
623 if (percpu_cntr->lc_max > cnt->lc_max)
624 cnt->lc_max = percpu_cntr->lc_max;
625 cnt->lc_sumsquare += percpu_cntr->lc_sumsquare;
628 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
630 EXPORT_SYMBOL(lprocfs_stats_collect);
633 * Append a space separated list of current set flags to str.
635 #define flag2str(flag, first) \
637 if (imp->imp_##flag) \
638 seq_printf(m, "%s" #flag, first ? "" : ", "); \
640 static int obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
644 if (imp->imp_obd->obd_no_recov) {
645 seq_printf(m, "no_recov");
649 flag2str(invalid, first);
651 flag2str(deactive, first);
652 flag2str(replayable, first);
653 flag2str(pingable, first);
658 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
664 for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
666 seq_printf(m, "%s%s",
667 first ? sep : "", obd_connect_names[i]);
671 if (flags & ~(mask - 1))
672 seq_printf(m, "%sunknown flags %#llx",
673 first ? sep : "", flags & ~(mask - 1));
676 int lprocfs_rd_import(struct seq_file *m, void *data)
678 struct lprocfs_counter ret;
679 struct lprocfs_counter_header *header;
680 struct obd_device *obd = (struct obd_device *)data;
681 struct obd_import *imp;
682 struct obd_import_conn *conn;
687 LASSERT(obd != NULL);
688 LPROCFS_CLIMP_CHECK(obd);
689 imp = obd->u.cli.cl_import;
700 ptlrpc_import_state_name(imp->imp_state),
701 imp->imp_connect_data.ocd_instance);
702 obd_connect_seq_flags2str(m, imp->imp_connect_data.ocd_connect_flags, ", ");
706 obd_import_flags2str(imp, m);
711 " failover_nids: [");
712 spin_lock(&imp->imp_lock);
714 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
715 seq_printf(m, "%s%s", j ? ", " : "",
716 libcfs_nid2str(conn->oic_conn->c_peer.nid));
721 " current_connection: %s\n"
722 " connection_attempts: %u\n"
724 " in-progress_invalidations: %u\n",
725 imp->imp_connection == NULL ? "<none>" :
726 libcfs_nid2str(imp->imp_connection->c_peer.nid),
729 atomic_read(&imp->imp_inval_count));
730 spin_unlock(&imp->imp_lock);
732 if (obd->obd_svc_stats == NULL)
735 header = &obd->obd_svc_stats->ls_cnt_header[PTLRPC_REQWAIT_CNTR];
736 lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
737 if (ret.lc_count != 0) {
738 /* first argument to do_div MUST be __u64 */
739 __u64 sum = ret.lc_sum;
740 do_div(sum, ret.lc_count);
747 " unregistering: %u\n"
749 " avg_waittime: %llu %s\n",
750 atomic_read(&imp->imp_inflight),
751 atomic_read(&imp->imp_unregistering),
752 atomic_read(&imp->imp_timeouts),
753 ret.lc_sum, header->lc_units);
756 for (j = 0; j < IMP_AT_MAX_PORTALS; j++) {
757 if (imp->imp_at.iat_portal[j] == 0)
759 k = max_t(unsigned int, k,
760 at_get(&imp->imp_at.iat_service_estimate[j]));
763 " service_estimates:\n"
764 " services: %u sec\n"
765 " network: %u sec\n",
767 at_get(&imp->imp_at.iat_net_latency));
771 " last_replay: %llu\n"
772 " peer_committed: %llu\n"
773 " last_checked: %llu\n",
774 imp->imp_last_replay_transno,
775 imp->imp_peer_committed_transno,
776 imp->imp_last_transno_checked);
779 for (rw = 0; rw <= 1; rw++) {
780 lprocfs_stats_collect(obd->obd_svc_stats,
781 PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
783 if (ret.lc_sum > 0 && ret.lc_count > 0) {
784 /* first argument to do_div MUST be __u64 */
785 __u64 sum = ret.lc_sum;
786 do_div(sum, ret.lc_count);
789 " %s_data_averages:\n"
790 " bytes_per_rpc: %llu\n",
791 rw ? "write" : "read",
795 j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
796 header = &obd->obd_svc_stats->ls_cnt_header[j];
797 lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
798 if (ret.lc_sum > 0 && ret.lc_count != 0) {
799 /* first argument to do_div MUST be __u64 */
800 __u64 sum = ret.lc_sum;
801 do_div(sum, ret.lc_count);
804 " %s_per_rpc: %llu\n",
805 header->lc_units, ret.lc_sum);
809 " MB_per_sec: %u.%.02u\n",
810 k / j, (100 * k / j) % 100);
815 LPROCFS_CLIMP_EXIT(obd);
818 EXPORT_SYMBOL(lprocfs_rd_import);
820 int lprocfs_rd_state(struct seq_file *m, void *data)
822 struct obd_device *obd = (struct obd_device *)data;
823 struct obd_import *imp;
826 LASSERT(obd != NULL);
827 LPROCFS_CLIMP_CHECK(obd);
828 imp = obd->u.cli.cl_import;
830 seq_printf(m, "current_state: %s\n",
831 ptlrpc_import_state_name(imp->imp_state));
832 seq_printf(m, "state_history:\n");
833 k = imp->imp_state_hist_idx;
834 for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
835 struct import_state_hist *ish =
836 &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
837 if (ish->ish_state == 0)
839 seq_printf(m, " - ["CFS_TIME_T", %s]\n",
841 ptlrpc_import_state_name(ish->ish_state));
844 LPROCFS_CLIMP_EXIT(obd);
847 EXPORT_SYMBOL(lprocfs_rd_state);
849 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
852 for (i = 0; i < AT_BINS; i++)
853 seq_printf(m, "%3u ", at->at_hist[i]);
857 EXPORT_SYMBOL(lprocfs_at_hist_helper);
859 /* See also ptlrpc_lprocfs_rd_timeouts */
860 int lprocfs_rd_timeouts(struct seq_file *m, void *data)
862 struct obd_device *obd = (struct obd_device *)data;
863 struct obd_import *imp;
864 unsigned int cur, worst;
869 LASSERT(obd != NULL);
870 LPROCFS_CLIMP_CHECK(obd);
871 imp = obd->u.cli.cl_import;
875 /* Some network health info for kicks */
876 s2dhms(&ts, now - imp->imp_last_reply_time);
877 seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
878 "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
880 cur = at_get(&imp->imp_at.iat_net_latency);
881 worst = imp->imp_at.iat_net_latency.at_worst_ever;
882 worstt = imp->imp_at.iat_net_latency.at_worst_time;
883 s2dhms(&ts, now - worstt);
884 seq_printf(m, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
885 "network", cur, worst, worstt, DHMS_VARS(&ts));
886 lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
888 for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
889 if (imp->imp_at.iat_portal[i] == 0)
891 cur = at_get(&imp->imp_at.iat_service_estimate[i]);
892 worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
893 worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
894 s2dhms(&ts, now - worstt);
895 seq_printf(m, "portal %-2d : cur %3u worst %3u (at %ld, "
896 DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
897 cur, worst, worstt, DHMS_VARS(&ts));
898 lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
901 LPROCFS_CLIMP_EXIT(obd);
904 EXPORT_SYMBOL(lprocfs_rd_timeouts);
906 int lprocfs_rd_connect_flags(struct seq_file *m, void *data)
908 struct obd_device *obd = data;
911 LPROCFS_CLIMP_CHECK(obd);
912 flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
913 seq_printf(m, "flags=%#llx\n", flags);
914 obd_connect_seq_flags2str(m, flags, "\n");
916 LPROCFS_CLIMP_EXIT(obd);
919 EXPORT_SYMBOL(lprocfs_rd_connect_flags);
921 int lprocfs_rd_num_exports(struct seq_file *m, void *data)
923 struct obd_device *obd = data;
925 LASSERT(obd != NULL);
926 return seq_printf(m, "%u\n", obd->obd_num_exports);
928 EXPORT_SYMBOL(lprocfs_rd_num_exports);
930 int lprocfs_rd_numrefs(struct seq_file *m, void *data)
932 struct obd_type *class = (struct obd_type *) data;
934 LASSERT(class != NULL);
935 return seq_printf(m, "%d\n", class->typ_refcnt);
937 EXPORT_SYMBOL(lprocfs_rd_numrefs);
939 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
943 LASSERT(obd != NULL);
944 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
945 LASSERT(obd->obd_type->typ_procroot != NULL);
947 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
948 obd->obd_type->typ_procroot,
950 if (IS_ERR(obd->obd_proc_entry)) {
951 rc = PTR_ERR(obd->obd_proc_entry);
952 CERROR("error %d setting up lprocfs for %s\n",
954 obd->obd_proc_entry = NULL;
958 EXPORT_SYMBOL(lprocfs_obd_setup);
960 int lprocfs_obd_cleanup(struct obd_device *obd)
964 if (obd->obd_proc_exports_entry) {
965 /* Should be no exports left */
966 lprocfs_remove(&obd->obd_proc_exports_entry);
967 obd->obd_proc_exports_entry = NULL;
969 if (obd->obd_proc_entry) {
970 lprocfs_remove(&obd->obd_proc_entry);
971 obd->obd_proc_entry = NULL;
975 EXPORT_SYMBOL(lprocfs_obd_cleanup);
977 static void lprocfs_free_client_stats(struct nid_stat *client_stat)
979 CDEBUG(D_CONFIG, "stat %p - data %p/%p\n", client_stat,
980 client_stat->nid_proc, client_stat->nid_stats);
982 LASSERTF(atomic_read(&client_stat->nid_exp_ref_count) == 0,
983 "nid %s:count %d\n", libcfs_nid2str(client_stat->nid),
984 atomic_read(&client_stat->nid_exp_ref_count));
986 if (client_stat->nid_proc)
987 lprocfs_remove(&client_stat->nid_proc);
989 if (client_stat->nid_stats)
990 lprocfs_free_stats(&client_stat->nid_stats);
992 if (client_stat->nid_ldlm_stats)
993 lprocfs_free_stats(&client_stat->nid_ldlm_stats);
995 OBD_FREE_PTR(client_stat);
1000 void lprocfs_free_per_client_stats(struct obd_device *obd)
1002 struct cfs_hash *hash = obd->obd_nid_stats_hash;
1003 struct nid_stat *stat;
1005 /* we need extra list - because hash_exit called to early */
1006 /* not need locking because all clients is died */
1007 while (!list_empty(&obd->obd_nid_stats)) {
1008 stat = list_entry(obd->obd_nid_stats.next,
1009 struct nid_stat, nid_list);
1010 list_del_init(&stat->nid_list);
1011 cfs_hash_del(hash, &stat->nid, &stat->nid_hash);
1012 lprocfs_free_client_stats(stat);
1015 EXPORT_SYMBOL(lprocfs_free_per_client_stats);
1017 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
1019 struct lprocfs_counter *cntr;
1020 unsigned int percpusize;
1022 unsigned long flags = 0;
1025 LASSERT(stats->ls_percpu[cpuid] == NULL);
1026 LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
1028 percpusize = lprocfs_stats_counter_size(stats);
1029 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
1030 if (stats->ls_percpu[cpuid] != NULL) {
1032 if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
1033 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1034 spin_lock_irqsave(&stats->ls_lock, flags);
1036 spin_lock(&stats->ls_lock);
1037 if (stats->ls_biggest_alloc_num <= cpuid)
1038 stats->ls_biggest_alloc_num = cpuid + 1;
1039 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1040 spin_unlock_irqrestore(&stats->ls_lock, flags);
1042 spin_unlock(&stats->ls_lock);
1044 /* initialize the ls_percpu[cpuid] non-zero counter */
1045 for (i = 0; i < stats->ls_num; ++i) {
1046 cntr = lprocfs_stats_counter_get(stats, cpuid, i);
1047 cntr->lc_min = LC_MIN_INIT;
1052 EXPORT_SYMBOL(lprocfs_stats_alloc_one);
1054 struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
1055 enum lprocfs_stats_flags flags)
1057 struct lprocfs_stats *stats;
1058 unsigned int num_entry;
1059 unsigned int percpusize = 0;
1065 if (lprocfs_no_percpu_stats != 0)
1066 flags |= LPROCFS_STATS_FLAG_NOPERCPU;
1068 if (flags & LPROCFS_STATS_FLAG_NOPERCPU)
1071 num_entry = num_possible_cpus();
1073 /* alloc percpu pointers for all possible cpu slots */
1074 LIBCFS_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1078 stats->ls_num = num;
1079 stats->ls_flags = flags;
1080 spin_lock_init(&stats->ls_lock);
1082 /* alloc num of counter headers */
1083 LIBCFS_ALLOC(stats->ls_cnt_header,
1084 stats->ls_num * sizeof(struct lprocfs_counter_header));
1085 if (stats->ls_cnt_header == NULL)
1088 if ((flags & LPROCFS_STATS_FLAG_NOPERCPU) != 0) {
1089 /* contains only one set counters */
1090 percpusize = lprocfs_stats_counter_size(stats);
1091 LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[0], percpusize);
1092 if (stats->ls_percpu[0] == NULL)
1094 stats->ls_biggest_alloc_num = 1;
1095 } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
1096 /* alloc all percpu data, currently only obd_memory use this */
1097 for (i = 0; i < num_entry; ++i)
1098 if (lprocfs_stats_alloc_one(stats, i) < 0)
1105 lprocfs_free_stats(&stats);
1108 EXPORT_SYMBOL(lprocfs_alloc_stats);
1110 void lprocfs_free_stats(struct lprocfs_stats **statsh)
1112 struct lprocfs_stats *stats = *statsh;
1113 unsigned int num_entry;
1114 unsigned int percpusize;
1117 if (stats == NULL || stats->ls_num == 0)
1121 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
1124 num_entry = num_possible_cpus();
1126 percpusize = lprocfs_stats_counter_size(stats);
1127 for (i = 0; i < num_entry; i++)
1128 if (stats->ls_percpu[i] != NULL)
1129 LIBCFS_FREE(stats->ls_percpu[i], percpusize);
1130 if (stats->ls_cnt_header != NULL)
1131 LIBCFS_FREE(stats->ls_cnt_header, stats->ls_num *
1132 sizeof(struct lprocfs_counter_header));
1133 LIBCFS_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_entry]));
1135 EXPORT_SYMBOL(lprocfs_free_stats);
1137 void lprocfs_clear_stats(struct lprocfs_stats *stats)
1139 struct lprocfs_counter *percpu_cntr;
1142 unsigned int num_entry;
1143 unsigned long flags = 0;
1145 num_entry = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1147 for (i = 0; i < num_entry; i++) {
1148 if (stats->ls_percpu[i] == NULL)
1150 for (j = 0; j < stats->ls_num; j++) {
1151 percpu_cntr = lprocfs_stats_counter_get(stats, i, j);
1152 percpu_cntr->lc_count = 0;
1153 percpu_cntr->lc_min = LC_MIN_INIT;
1154 percpu_cntr->lc_max = 0;
1155 percpu_cntr->lc_sumsquare = 0;
1156 percpu_cntr->lc_sum = 0;
1157 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
1158 percpu_cntr->lc_sum_irq = 0;
1162 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1164 EXPORT_SYMBOL(lprocfs_clear_stats);
1166 static ssize_t lprocfs_stats_seq_write(struct file *file,
1167 const char __user *buf,
1168 size_t len, loff_t *off)
1170 struct seq_file *seq = file->private_data;
1171 struct lprocfs_stats *stats = seq->private;
1173 lprocfs_clear_stats(stats);
1178 static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos)
1180 struct lprocfs_stats *stats = p->private;
1182 return (*pos < stats->ls_num) ? pos : NULL;
1185 static void lprocfs_stats_seq_stop(struct seq_file *p, void *v)
1189 static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
1192 return lprocfs_stats_seq_start(p, pos);
1195 /* seq file export of one lprocfs counter */
1196 static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
1198 struct lprocfs_stats *stats = p->private;
1199 struct lprocfs_counter_header *hdr;
1200 struct lprocfs_counter ctr;
1201 int idx = *(loff_t *)v;
1206 do_gettimeofday(&now);
1207 rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
1208 "snapshot_time", now.tv_sec, (unsigned long)now.tv_usec);
1212 hdr = &stats->ls_cnt_header[idx];
1213 lprocfs_stats_collect(stats, idx, &ctr);
1215 if (ctr.lc_count == 0)
1218 rc = seq_printf(p, "%-25s %lld samples [%s]", hdr->lc_name,
1219 ctr.lc_count, hdr->lc_units);
1224 if ((hdr->lc_config & LPROCFS_CNTR_AVGMINMAX) && (ctr.lc_count > 0)) {
1225 rc = seq_printf(p, " %lld %lld %lld",
1226 ctr.lc_min, ctr.lc_max, ctr.lc_sum);
1229 if (hdr->lc_config & LPROCFS_CNTR_STDDEV)
1230 rc = seq_printf(p, " %lld", ctr.lc_sumsquare);
1234 rc = seq_printf(p, "\n");
1236 return (rc < 0) ? rc : 0;
1239 static const struct seq_operations lprocfs_stats_seq_sops = {
1240 .start = lprocfs_stats_seq_start,
1241 .stop = lprocfs_stats_seq_stop,
1242 .next = lprocfs_stats_seq_next,
1243 .show = lprocfs_stats_seq_show,
1246 static int lprocfs_stats_seq_open(struct inode *inode, struct file *file)
1248 struct seq_file *seq;
1251 rc = seq_open(file, &lprocfs_stats_seq_sops);
1254 seq = file->private_data;
1255 seq->private = PDE_DATA(inode);
1259 struct file_operations lprocfs_stats_seq_fops = {
1260 .owner = THIS_MODULE,
1261 .open = lprocfs_stats_seq_open,
1263 .write = lprocfs_stats_seq_write,
1264 .llseek = seq_lseek,
1265 .release = lprocfs_seq_release,
1268 int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
1269 struct lprocfs_stats *stats)
1271 struct proc_dir_entry *entry;
1272 LASSERT(root != NULL);
1274 entry = proc_create_data(name, 0644, root,
1275 &lprocfs_stats_seq_fops, stats);
1281 EXPORT_SYMBOL(lprocfs_register_stats);
1283 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
1284 unsigned conf, const char *name, const char *units)
1286 struct lprocfs_counter_header *header;
1287 struct lprocfs_counter *percpu_cntr;
1288 unsigned long flags = 0;
1290 unsigned int num_cpu;
1292 LASSERT(stats != NULL);
1294 header = &stats->ls_cnt_header[index];
1295 LASSERTF(header != NULL, "Failed to allocate stats header:[%d]%s/%s\n",
1296 index, name, units);
1298 header->lc_config = conf;
1299 header->lc_name = name;
1300 header->lc_units = units;
1302 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
1303 for (i = 0; i < num_cpu; ++i) {
1304 if (stats->ls_percpu[i] == NULL)
1306 percpu_cntr = lprocfs_stats_counter_get(stats, i, index);
1307 percpu_cntr->lc_count = 0;
1308 percpu_cntr->lc_min = LC_MIN_INIT;
1309 percpu_cntr->lc_max = 0;
1310 percpu_cntr->lc_sumsquare = 0;
1311 percpu_cntr->lc_sum = 0;
1312 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1313 percpu_cntr->lc_sum_irq = 0;
1315 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
1317 EXPORT_SYMBOL(lprocfs_counter_init);
1319 #define LPROCFS_OBD_OP_INIT(base, stats, op) \
1321 unsigned int coffset = base + OBD_COUNTER_OFFSET(op); \
1322 LASSERT(coffset < stats->ls_num); \
1323 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1326 void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
1328 LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
1329 LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
1330 LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info_async);
1331 LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);
1332 LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);
1333 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
1334 LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
1335 LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
1336 LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);
1337 LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
1338 LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);
1339 LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);
1340 LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
1341 LPROCFS_OBD_OP_INIT(num_private_stats, stats, reconnect);
1342 LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
1343 LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_init);
1344 LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_fini);
1345 LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_alloc);
1346 LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
1347 LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);
1348 LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
1349 LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
1350 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
1351 LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
1352 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
1353 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
1354 LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr_async);
1355 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
1356 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
1357 LPROCFS_OBD_OP_INIT(num_private_stats, stats, adjust_kms);
1358 LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
1359 LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
1360 LPROCFS_OBD_OP_INIT(num_private_stats, stats, find_cbdata);
1361 LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
1362 LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
1363 LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
1364 LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
1365 LPROCFS_OBD_OP_INIT(num_private_stats, stats, health_check);
1366 LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_uuid);
1367 LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotacheck);
1368 LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotactl);
1369 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_new);
1370 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_rem);
1371 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_add);
1372 LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_del);
1373 LPROCFS_OBD_OP_INIT(num_private_stats, stats, getref);
1374 LPROCFS_OBD_OP_INIT(num_private_stats, stats, putref);
1376 EXPORT_SYMBOL(lprocfs_init_ops_stats);
1378 int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
1380 struct lprocfs_stats *stats;
1381 unsigned int num_stats;
1384 LASSERT(obd->obd_stats == NULL);
1385 LASSERT(obd->obd_proc_entry != NULL);
1386 LASSERT(obd->obd_cntr_base == 0);
1388 num_stats = ((int)sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
1389 num_private_stats - 1 /* o_owner */;
1390 stats = lprocfs_alloc_stats(num_stats, 0);
1394 lprocfs_init_ops_stats(num_private_stats, stats);
1396 for (i = num_private_stats; i < num_stats; i++) {
1397 /* If this LBUGs, it is likely that an obd
1398 * operation was added to struct obd_ops in
1399 * <obd.h>, and that the corresponding line item
1400 * LPROCFS_OBD_OP_INIT(.., .., opname)
1401 * is missing from the list above. */
1402 LASSERTF(stats->ls_cnt_header[i].lc_name != NULL,
1403 "Missing obd_stat initializer obd_op "
1404 "operation at offset %d.\n", i - num_private_stats);
1406 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
1408 lprocfs_free_stats(&stats);
1410 obd->obd_stats = stats;
1411 obd->obd_cntr_base = num_private_stats;
1415 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
1417 void lprocfs_free_obd_stats(struct obd_device *obd)
1420 lprocfs_free_stats(&obd->obd_stats);
1422 EXPORT_SYMBOL(lprocfs_free_obd_stats);
1424 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1426 unsigned int coffset = base + MD_COUNTER_OFFSET(op); \
1427 LASSERT(coffset < stats->ls_num); \
1428 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1431 void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
1433 LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
1434 LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
1435 LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
1436 LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
1437 LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
1438 LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
1439 LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
1440 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
1441 LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
1442 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
1443 LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
1444 LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
1445 LPROCFS_MD_OP_INIT(num_private_stats, stats, is_subdir);
1446 LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
1447 LPROCFS_MD_OP_INIT(num_private_stats, stats, sync);
1448 LPROCFS_MD_OP_INIT(num_private_stats, stats, readpage);
1449 LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
1450 LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
1451 LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
1452 LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
1453 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
1454 LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
1455 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
1456 LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
1457 LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
1458 LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
1459 LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
1460 LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
1461 LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
1462 LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
1463 LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
1464 LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
1466 EXPORT_SYMBOL(lprocfs_init_mps_stats);
1468 int lprocfs_alloc_md_stats(struct obd_device *obd,
1469 unsigned num_private_stats)
1471 struct lprocfs_stats *stats;
1472 unsigned int num_stats;
1475 LASSERT(obd->md_stats == NULL);
1476 LASSERT(obd->obd_proc_entry != NULL);
1477 LASSERT(obd->md_cntr_base == 0);
1479 num_stats = 1 + MD_COUNTER_OFFSET(revalidate_lock) +
1481 stats = lprocfs_alloc_stats(num_stats, 0);
1485 lprocfs_init_mps_stats(num_private_stats, stats);
1487 for (i = num_private_stats; i < num_stats; i++) {
1488 if (stats->ls_cnt_header[i].lc_name == NULL) {
1489 CERROR("Missing md_stat initializer md_op "
1490 "operation at offset %d. Aborting.\n",
1491 i - num_private_stats);
1495 rc = lprocfs_register_stats(obd->obd_proc_entry, "md_stats", stats);
1497 lprocfs_free_stats(&stats);
1499 obd->md_stats = stats;
1500 obd->md_cntr_base = num_private_stats;
1504 EXPORT_SYMBOL(lprocfs_alloc_md_stats);
1506 void lprocfs_free_md_stats(struct obd_device *obd)
1508 struct lprocfs_stats *stats = obd->md_stats;
1510 if (stats != NULL) {
1511 obd->md_stats = NULL;
1512 obd->md_cntr_base = 0;
1513 lprocfs_free_stats(&stats);
1516 EXPORT_SYMBOL(lprocfs_free_md_stats);
1518 void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1520 lprocfs_counter_init(ldlm_stats,
1521 LDLM_ENQUEUE - LDLM_FIRST_OPC,
1522 0, "ldlm_enqueue", "reqs");
1523 lprocfs_counter_init(ldlm_stats,
1524 LDLM_CONVERT - LDLM_FIRST_OPC,
1525 0, "ldlm_convert", "reqs");
1526 lprocfs_counter_init(ldlm_stats,
1527 LDLM_CANCEL - LDLM_FIRST_OPC,
1528 0, "ldlm_cancel", "reqs");
1529 lprocfs_counter_init(ldlm_stats,
1530 LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
1531 0, "ldlm_bl_callback", "reqs");
1532 lprocfs_counter_init(ldlm_stats,
1533 LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
1534 0, "ldlm_cp_callback", "reqs");
1535 lprocfs_counter_init(ldlm_stats,
1536 LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
1537 0, "ldlm_gl_callback", "reqs");
1539 EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
1541 int lprocfs_exp_print_uuid(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1542 struct hlist_node *hnode, void *data)
1545 struct obd_export *exp = cfs_hash_object(hs, hnode);
1546 struct seq_file *m = (struct seq_file *)data;
1548 if (exp->exp_nid_stats)
1549 seq_printf(m, "%s\n", obd_uuid2str(&exp->exp_client_uuid));
1555 lproc_exp_uuid_seq_show(struct seq_file *m, void *unused)
1557 struct nid_stat *stats = (struct nid_stat *)m->private;
1558 struct obd_device *obd = stats->nid_obd;
1560 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
1561 lprocfs_exp_print_uuid, m);
1565 LPROC_SEQ_FOPS_RO(lproc_exp_uuid);
1567 struct exp_hash_cb_data {
1572 int lprocfs_exp_print_hash(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1573 struct hlist_node *hnode, void *cb_data)
1576 struct exp_hash_cb_data *data = (struct exp_hash_cb_data *)cb_data;
1577 struct obd_export *exp = cfs_hash_object(hs, hnode);
1579 if (exp->exp_lock_hash != NULL) {
1581 cfs_hash_debug_header(data->m);
1582 data->first = false;
1584 cfs_hash_debug_str(hs, data->m);
1591 lproc_exp_hash_seq_show(struct seq_file *m, void *unused)
1593 struct nid_stat *stats = (struct nid_stat *)m->private;
1594 struct obd_device *obd = stats->nid_obd;
1595 struct exp_hash_cb_data cb_data = {
1600 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
1601 lprocfs_exp_print_hash, &cb_data);
1605 LPROC_SEQ_FOPS_RO(lproc_exp_hash);
1607 int lprocfs_nid_stats_clear_read(struct seq_file *m, void *data)
1609 return seq_printf(m, "%s\n",
1610 "Write into this file to clear all nid stats and "
1611 "stale nid entries");
1613 EXPORT_SYMBOL(lprocfs_nid_stats_clear_read);
1615 static int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
1617 struct nid_stat *stat = obj;
1619 CDEBUG(D_INFO, "refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
1620 if (atomic_read(&stat->nid_exp_ref_count) == 1) {
1621 /* object has only hash references. */
1622 spin_lock(&stat->nid_obd->obd_nid_lock);
1623 list_move(&stat->nid_list, data);
1624 spin_unlock(&stat->nid_obd->obd_nid_lock);
1627 /* we has reference to object - only clear data*/
1628 if (stat->nid_stats)
1629 lprocfs_clear_stats(stat->nid_stats);
1634 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
1635 unsigned long count, void *data)
1637 struct obd_device *obd = (struct obd_device *)data;
1638 struct nid_stat *client_stat;
1639 LIST_HEAD(free_list);
1641 cfs_hash_cond_del(obd->obd_nid_stats_hash,
1642 lprocfs_nid_stats_clear_write_cb, &free_list);
1644 while (!list_empty(&free_list)) {
1645 client_stat = list_entry(free_list.next, struct nid_stat,
1647 list_del_init(&client_stat->nid_list);
1648 lprocfs_free_client_stats(client_stat);
1653 EXPORT_SYMBOL(lprocfs_nid_stats_clear_write);
1655 int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
1657 struct nid_stat *new_stat, *old_stat;
1658 struct obd_device *obd = NULL;
1659 struct proc_dir_entry *entry;
1660 char *buffer = NULL;
1665 if (!exp || !exp->exp_obd || !exp->exp_obd->obd_proc_exports_entry ||
1666 !exp->exp_obd->obd_nid_stats_hash)
1669 /* not test against zero because eric say:
1670 * You may only test nid against another nid, or LNET_NID_ANY.
1671 * Anything else is nonsense.*/
1672 if (!nid || *nid == LNET_NID_ANY)
1677 CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
1679 OBD_ALLOC_PTR(new_stat);
1680 if (new_stat == NULL)
1683 new_stat->nid = *nid;
1684 new_stat->nid_obd = exp->exp_obd;
1685 /* we need set default refcount to 1 to balance obd_disconnect */
1686 atomic_set(&new_stat->nid_exp_ref_count, 1);
1688 old_stat = cfs_hash_findadd_unique(obd->obd_nid_stats_hash,
1689 nid, &new_stat->nid_hash);
1690 CDEBUG(D_INFO, "Found stats %p for nid %s - ref %d\n",
1691 old_stat, libcfs_nid2str(*nid),
1692 atomic_read(&new_stat->nid_exp_ref_count));
1694 /* We need to release old stats because lprocfs_exp_cleanup() hasn't
1695 * been and will never be called. */
1696 if (exp->exp_nid_stats) {
1697 nidstat_putref(exp->exp_nid_stats);
1698 exp->exp_nid_stats = NULL;
1701 /* Return -EALREADY here so that we know that the /proc
1702 * entry already has been created */
1703 if (old_stat != new_stat) {
1704 exp->exp_nid_stats = old_stat;
1708 /* not found - create */
1709 OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
1710 if (buffer == NULL) {
1715 memcpy(buffer, libcfs_nid2str(*nid), LNET_NIDSTR_SIZE);
1716 new_stat->nid_proc = lprocfs_register(buffer,
1717 obd->obd_proc_exports_entry,
1719 OBD_FREE(buffer, LNET_NIDSTR_SIZE);
1721 if (IS_ERR(new_stat->nid_proc)) {
1722 CERROR("Error making export directory for nid %s\n",
1723 libcfs_nid2str(*nid));
1724 rc = PTR_ERR(new_stat->nid_proc);
1725 new_stat->nid_proc = NULL;
1726 goto destroy_new_ns;
1729 entry = lprocfs_add_simple(new_stat->nid_proc, "uuid",
1730 new_stat, &lproc_exp_uuid_fops);
1731 if (IS_ERR(entry)) {
1732 CWARN("Error adding the NID stats file\n");
1733 rc = PTR_ERR(entry);
1734 goto destroy_new_ns;
1737 entry = lprocfs_add_simple(new_stat->nid_proc, "hash",
1738 new_stat, &lproc_exp_hash_fops);
1739 if (IS_ERR(entry)) {
1740 CWARN("Error adding the hash file\n");
1741 rc = PTR_ERR(entry);
1742 goto destroy_new_ns;
1745 exp->exp_nid_stats = new_stat;
1747 /* protect competitive add to list, not need locking on destroy */
1748 spin_lock(&obd->obd_nid_lock);
1749 list_add(&new_stat->nid_list, &obd->obd_nid_stats);
1750 spin_unlock(&obd->obd_nid_lock);
1755 if (new_stat->nid_proc != NULL)
1756 lprocfs_remove(&new_stat->nid_proc);
1757 cfs_hash_del(obd->obd_nid_stats_hash, nid, &new_stat->nid_hash);
1760 nidstat_putref(new_stat);
1761 OBD_FREE_PTR(new_stat);
1764 EXPORT_SYMBOL(lprocfs_exp_setup);
1766 int lprocfs_exp_cleanup(struct obd_export *exp)
1768 struct nid_stat *stat = exp->exp_nid_stats;
1770 if (!stat || !exp->exp_obd)
1773 nidstat_putref(exp->exp_nid_stats);
1774 exp->exp_nid_stats = NULL;
1778 EXPORT_SYMBOL(lprocfs_exp_cleanup);
1780 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1781 struct lprocfs_counter_header *header,
1782 enum lprocfs_stats_flags flags,
1783 enum lprocfs_fields_flags field)
1787 if (lc == NULL || header == NULL)
1791 case LPROCFS_FIELDS_FLAGS_CONFIG:
1792 ret = header->lc_config;
1794 case LPROCFS_FIELDS_FLAGS_SUM:
1796 if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
1797 ret += lc->lc_sum_irq;
1799 case LPROCFS_FIELDS_FLAGS_MIN:
1802 case LPROCFS_FIELDS_FLAGS_MAX:
1805 case LPROCFS_FIELDS_FLAGS_AVG:
1806 ret = (lc->lc_max - lc->lc_min) / 2;
1808 case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
1809 ret = lc->lc_sumsquare;
1811 case LPROCFS_FIELDS_FLAGS_COUNT:
1820 EXPORT_SYMBOL(lprocfs_read_helper);
1822 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
1825 return lprocfs_write_frac_helper(buffer, count, val, 1);
1827 EXPORT_SYMBOL(lprocfs_write_helper);
1829 int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
1831 long decimal_val, frac_val;
1833 decimal_val = val / mult;
1834 seq_printf(m, "%ld", decimal_val);
1835 frac_val = val % mult;
1842 /* Three cases: x0, xx, 0x */
1843 if ((frac_val % 10) != 0)
1844 seq_printf(m, ".%ld", frac_val);
1846 seq_printf(m, ".%ld", frac_val / 10);
1849 seq_printf(m, "\n");
1852 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
1854 int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
1857 return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
1859 EXPORT_SYMBOL(lprocfs_write_u64_helper);
1861 int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
1862 __u64 *val, int mult)
1864 char kernbuf[22], *end, *pbuf;
1865 __u64 whole, frac = 0, units;
1866 unsigned frac_d = 1;
1868 if (count > (sizeof(kernbuf) - 1))
1871 if (copy_from_user(kernbuf, buffer, count))
1874 kernbuf[count] = '\0';
1881 whole = simple_strtoull(pbuf, &end, 10);
1885 if (end != NULL && *end == '.') {
1889 /* need to limit frac_d to a __u32 */
1890 if (strlen(pbuf) > 10)
1893 frac = simple_strtoull(pbuf, &end, 10);
1894 /* count decimal places */
1895 for (i = 0; i < (end - pbuf); i++)
1912 /* Specified units override the multiplier */
1914 mult = mult < 0 ? -units : units;
1917 do_div(frac, frac_d);
1918 *val = whole * mult + frac;
1921 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper);
1923 static char *lprocfs_strnstr(const char *s1, const char *s2, size_t len)
1932 if (!memcmp(s1, s2, l2))
1940 * Find the string \a name in the input \a buffer, and return a pointer to the
1941 * value immediately following \a name, reducing \a count appropriately.
1942 * If \a name is not found the original \a buffer is returned.
1944 char *lprocfs_find_named_value(const char *buffer, const char *name,
1948 size_t buflen = *count;
1950 /* there is no strnstr() in rhel5 and ubuntu kernels */
1951 val = lprocfs_strnstr(buffer, name, buflen);
1953 return (char *)buffer;
1955 val += strlen(name); /* skip prefix */
1956 while (val < buffer + buflen && isspace(*val)) /* skip separator */
1960 while (val < buffer + buflen && isalnum(*val)) {
1965 return val - *count;
1967 EXPORT_SYMBOL(lprocfs_find_named_value);
1969 int lprocfs_seq_create(struct proc_dir_entry *parent,
1972 const struct file_operations *seq_fops,
1975 struct proc_dir_entry *entry;
1977 /* Disallow secretly (un)writable entries. */
1978 LASSERT((seq_fops->write == NULL) == ((mode & 0222) == 0));
1979 entry = proc_create_data(name, mode, parent, seq_fops, data);
1986 EXPORT_SYMBOL(lprocfs_seq_create);
1988 int lprocfs_obd_seq_create(struct obd_device *dev,
1991 const struct file_operations *seq_fops,
1994 return lprocfs_seq_create(dev->obd_proc_entry, name,
1995 mode, seq_fops, data);
1997 EXPORT_SYMBOL(lprocfs_obd_seq_create);
1999 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
2001 if (value >= OBD_HIST_MAX)
2002 value = OBD_HIST_MAX - 1;
2004 spin_lock(&oh->oh_lock);
2005 oh->oh_buckets[value]++;
2006 spin_unlock(&oh->oh_lock);
2008 EXPORT_SYMBOL(lprocfs_oh_tally);
2010 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
2014 for (val = 0; ((1 << val) < value) && (val <= OBD_HIST_MAX); val++)
2017 lprocfs_oh_tally(oh, val);
2019 EXPORT_SYMBOL(lprocfs_oh_tally_log2);
2021 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
2023 unsigned long ret = 0;
2026 for (i = 0; i < OBD_HIST_MAX; i++)
2027 ret += oh->oh_buckets[i];
2030 EXPORT_SYMBOL(lprocfs_oh_sum);
2032 void lprocfs_oh_clear(struct obd_histogram *oh)
2034 spin_lock(&oh->oh_lock);
2035 memset(oh->oh_buckets, 0, sizeof(oh->oh_buckets));
2036 spin_unlock(&oh->oh_lock);
2038 EXPORT_SYMBOL(lprocfs_oh_clear);
2040 int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data)
2042 struct obd_device *dev = data;
2043 struct client_obd *cli = &dev->u.cli;
2046 client_obd_list_lock(&cli->cl_loi_list_lock);
2047 rc = seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
2048 client_obd_list_unlock(&cli->cl_loi_list_lock);
2051 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);