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
= 0;
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 proc_dir_entry
*lprocfs_add_simple(struct proc_dir_entry
*root
,
247 char *name
, void *data
,
248 struct file_operations
*fops
)
250 struct proc_dir_entry
*proc
;
253 if (root
== NULL
|| name
== NULL
|| fops
== NULL
)
254 return ERR_PTR(-EINVAL
);
260 proc
= proc_create_data(name
, mode
, root
, fops
, data
);
262 CERROR("LprocFS: No memory to create /proc entry %s", name
);
263 return ERR_PTR(-ENOMEM
);
267 EXPORT_SYMBOL(lprocfs_add_simple
);
269 struct proc_dir_entry
*lprocfs_add_symlink(const char *name
,
270 struct proc_dir_entry
*parent
, const char *format
, ...)
272 struct proc_dir_entry
*entry
;
276 if (parent
== NULL
|| format
== NULL
)
279 OBD_ALLOC_WAIT(dest
, MAX_STRING_SIZE
+ 1);
283 va_start(ap
, format
);
284 vsnprintf(dest
, MAX_STRING_SIZE
, format
, ap
);
287 entry
= proc_symlink(name
, parent
, dest
);
289 CERROR("LprocFS: Could not create symbolic link from %s to %s",
292 OBD_FREE(dest
, MAX_STRING_SIZE
+ 1);
295 EXPORT_SYMBOL(lprocfs_add_symlink
);
297 static struct file_operations lprocfs_generic_fops
= { };
302 * \param root [in] The parent proc entry on which new entry will be added.
303 * \param list [in] Array of proc entries to be added.
304 * \param data [in] The argument to be passed when entries read/write routines
305 * are called through /proc file.
307 * \retval 0 on success
310 int lprocfs_add_vars(struct proc_dir_entry
*root
, struct lprocfs_vars
*list
,
313 if (root
== NULL
|| list
== NULL
)
316 while (list
->name
!= NULL
) {
317 struct proc_dir_entry
*proc
;
320 if (list
->proc_mode
!= 0000) {
321 mode
= list
->proc_mode
;
322 } else if (list
->fops
) {
323 if (list
->fops
->read
)
325 if (list
->fops
->write
)
328 proc
= proc_create_data(list
->name
, mode
, root
,
329 list
->fops
?: &lprocfs_generic_fops
,
337 EXPORT_SYMBOL(lprocfs_add_vars
);
339 void lprocfs_remove(struct proc_dir_entry
**rooth
)
344 EXPORT_SYMBOL(lprocfs_remove
);
346 void lprocfs_remove_proc_entry(const char *name
, struct proc_dir_entry
*parent
)
348 LASSERT(parent
!= NULL
);
349 remove_proc_entry(name
, parent
);
351 EXPORT_SYMBOL(lprocfs_remove_proc_entry
);
353 struct proc_dir_entry
*lprocfs_register(const char *name
,
354 struct proc_dir_entry
*parent
,
355 struct lprocfs_vars
*list
, void *data
)
357 struct proc_dir_entry
*entry
;
359 entry
= proc_mkdir(name
, parent
);
361 entry
= ERR_PTR(-ENOMEM
);
366 int rc
= lprocfs_add_vars(entry
, list
, data
);
368 lprocfs_remove(&entry
);
375 EXPORT_SYMBOL(lprocfs_register
);
377 /* Generic callbacks */
378 int lprocfs_rd_uint(struct seq_file
*m
, void *data
)
380 return seq_printf(m
, "%u\n", *(unsigned int *)data
);
382 EXPORT_SYMBOL(lprocfs_rd_uint
);
384 int lprocfs_wr_uint(struct file
*file
, const char __user
*buffer
,
385 unsigned long count
, void *data
)
388 char dummy
[MAX_STRING_SIZE
+ 1], *end
;
391 dummy
[MAX_STRING_SIZE
] = '\0';
392 if (copy_from_user(dummy
, buffer
, MAX_STRING_SIZE
))
395 tmp
= simple_strtoul(dummy
, &end
, 0);
399 *p
= (unsigned int)tmp
;
402 EXPORT_SYMBOL(lprocfs_wr_uint
);
404 int lprocfs_rd_u64(struct seq_file
*m
, void *data
)
406 return seq_printf(m
, "%llu\n", *(__u64
*)data
);
408 EXPORT_SYMBOL(lprocfs_rd_u64
);
410 int lprocfs_rd_atomic(struct seq_file
*m
, void *data
)
412 atomic_t
*atom
= data
;
413 LASSERT(atom
!= NULL
);
414 return seq_printf(m
, "%d\n", atomic_read(atom
));
416 EXPORT_SYMBOL(lprocfs_rd_atomic
);
418 int lprocfs_wr_atomic(struct file
*file
, const char __user
*buffer
,
419 unsigned long count
, void *data
)
421 atomic_t
*atm
= data
;
425 rc
= lprocfs_write_helper(buffer
, count
, &val
);
432 atomic_set(atm
, val
);
435 EXPORT_SYMBOL(lprocfs_wr_atomic
);
437 int lprocfs_rd_uuid(struct seq_file
*m
, void *data
)
439 struct obd_device
*obd
= data
;
441 LASSERT(obd
!= NULL
);
442 return seq_printf(m
, "%s\n", obd
->obd_uuid
.uuid
);
444 EXPORT_SYMBOL(lprocfs_rd_uuid
);
446 int lprocfs_rd_name(struct seq_file
*m
, void *data
)
448 struct obd_device
*dev
= data
;
450 LASSERT(dev
!= NULL
);
451 return seq_printf(m
, "%s\n", dev
->obd_name
);
453 EXPORT_SYMBOL(lprocfs_rd_name
);
455 int lprocfs_rd_blksize(struct seq_file
*m
, void *data
)
457 struct obd_device
*obd
= data
;
458 struct obd_statfs osfs
;
459 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
460 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
463 rc
= seq_printf(m
, "%u\n", osfs
.os_bsize
);
466 EXPORT_SYMBOL(lprocfs_rd_blksize
);
468 int lprocfs_rd_kbytestotal(struct seq_file
*m
, void *data
)
470 struct obd_device
*obd
= data
;
471 struct obd_statfs osfs
;
472 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
473 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
476 __u32 blk_size
= osfs
.os_bsize
>> 10;
477 __u64 result
= osfs
.os_blocks
;
479 while (blk_size
>>= 1)
482 rc
= seq_printf(m
, "%llu\n", result
);
486 EXPORT_SYMBOL(lprocfs_rd_kbytestotal
);
488 int lprocfs_rd_kbytesfree(struct seq_file
*m
, void *data
)
490 struct obd_device
*obd
= data
;
491 struct obd_statfs osfs
;
492 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
493 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
496 __u32 blk_size
= osfs
.os_bsize
>> 10;
497 __u64 result
= osfs
.os_bfree
;
499 while (blk_size
>>= 1)
502 rc
= seq_printf(m
, "%llu\n", result
);
506 EXPORT_SYMBOL(lprocfs_rd_kbytesfree
);
508 int lprocfs_rd_kbytesavail(struct seq_file
*m
, void *data
)
510 struct obd_device
*obd
= data
;
511 struct obd_statfs osfs
;
512 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
513 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
516 __u32 blk_size
= osfs
.os_bsize
>> 10;
517 __u64 result
= osfs
.os_bavail
;
519 while (blk_size
>>= 1)
522 rc
= seq_printf(m
, "%llu\n", result
);
526 EXPORT_SYMBOL(lprocfs_rd_kbytesavail
);
528 int lprocfs_rd_filestotal(struct seq_file
*m
, void *data
)
530 struct obd_device
*obd
= data
;
531 struct obd_statfs osfs
;
532 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
533 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
536 rc
= seq_printf(m
, "%llu\n", osfs
.os_files
);
540 EXPORT_SYMBOL(lprocfs_rd_filestotal
);
542 int lprocfs_rd_filesfree(struct seq_file
*m
, void *data
)
544 struct obd_device
*obd
= data
;
545 struct obd_statfs osfs
;
546 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
547 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
550 rc
= seq_printf(m
, "%llu\n", osfs
.os_ffree
);
553 EXPORT_SYMBOL(lprocfs_rd_filesfree
);
555 int lprocfs_rd_server_uuid(struct seq_file
*m
, void *data
)
557 struct obd_device
*obd
= data
;
558 struct obd_import
*imp
;
559 char *imp_state_name
= NULL
;
562 LASSERT(obd
!= NULL
);
563 LPROCFS_CLIMP_CHECK(obd
);
564 imp
= obd
->u
.cli
.cl_import
;
565 imp_state_name
= ptlrpc_import_state_name(imp
->imp_state
);
566 rc
= seq_printf(m
, "%s\t%s%s\n", obd2cli_tgt(obd
), imp_state_name
,
567 imp
->imp_deactive
? "\tDEACTIVATED" : "");
569 LPROCFS_CLIMP_EXIT(obd
);
572 EXPORT_SYMBOL(lprocfs_rd_server_uuid
);
574 int lprocfs_rd_conn_uuid(struct seq_file
*m
, void *data
)
576 struct obd_device
*obd
= data
;
577 struct ptlrpc_connection
*conn
;
580 LASSERT(obd
!= NULL
);
582 LPROCFS_CLIMP_CHECK(obd
);
583 conn
= obd
->u
.cli
.cl_import
->imp_connection
;
584 if (conn
&& obd
->u
.cli
.cl_import
)
585 rc
= seq_printf(m
, "%s\n", conn
->c_remote_uuid
.uuid
);
587 rc
= seq_printf(m
, "%s\n", "<none>");
589 LPROCFS_CLIMP_EXIT(obd
);
592 EXPORT_SYMBOL(lprocfs_rd_conn_uuid
);
594 /** add up per-cpu counters */
595 void lprocfs_stats_collect(struct lprocfs_stats
*stats
, int idx
,
596 struct lprocfs_counter
*cnt
)
598 unsigned int num_entry
;
599 struct lprocfs_counter
*percpu_cntr
;
601 unsigned long flags
= 0;
603 memset(cnt
, 0, sizeof(*cnt
));
606 /* set count to 1 to avoid divide-by-zero errs in callers */
611 cnt
->lc_min
= LC_MIN_INIT
;
613 num_entry
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
615 for (i
= 0; i
< num_entry
; i
++) {
616 if (stats
->ls_percpu
[i
] == NULL
)
618 percpu_cntr
= lprocfs_stats_counter_get(stats
, i
, idx
);
620 cnt
->lc_count
+= percpu_cntr
->lc_count
;
621 cnt
->lc_sum
+= percpu_cntr
->lc_sum
;
622 if (percpu_cntr
->lc_min
< cnt
->lc_min
)
623 cnt
->lc_min
= percpu_cntr
->lc_min
;
624 if (percpu_cntr
->lc_max
> cnt
->lc_max
)
625 cnt
->lc_max
= percpu_cntr
->lc_max
;
626 cnt
->lc_sumsquare
+= percpu_cntr
->lc_sumsquare
;
629 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
631 EXPORT_SYMBOL(lprocfs_stats_collect
);
634 * Append a space separated list of current set flags to str.
636 #define flag2str(flag, first) \
638 if (imp->imp_##flag) \
639 seq_printf(m, "%s" #flag, first ? "" : ", "); \
641 static int obd_import_flags2str(struct obd_import
*imp
, struct seq_file
*m
)
645 if (imp
->imp_obd
->obd_no_recov
) {
646 seq_printf(m
, "no_recov");
650 flag2str(invalid
, first
);
652 flag2str(deactive
, first
);
653 flag2str(replayable
, first
);
654 flag2str(pingable
, first
);
659 static void obd_connect_seq_flags2str(struct seq_file
*m
, __u64 flags
, char *sep
)
665 for (i
= 0; obd_connect_names
[i
] != NULL
; i
++, mask
<<= 1) {
667 seq_printf(m
, "%s%s",
668 first
? sep
: "", obd_connect_names
[i
]);
672 if (flags
& ~(mask
- 1))
673 seq_printf(m
, "%sunknown flags %#llx",
674 first
? sep
: "", flags
& ~(mask
- 1));
677 int lprocfs_rd_import(struct seq_file
*m
, void *data
)
679 struct lprocfs_counter ret
;
680 struct lprocfs_counter_header
*header
;
681 struct obd_device
*obd
= (struct obd_device
*)data
;
682 struct obd_import
*imp
;
683 struct obd_import_conn
*conn
;
688 LASSERT(obd
!= NULL
);
689 LPROCFS_CLIMP_CHECK(obd
);
690 imp
= obd
->u
.cli
.cl_import
;
701 ptlrpc_import_state_name(imp
->imp_state
),
702 imp
->imp_connect_data
.ocd_instance
);
703 obd_connect_seq_flags2str(m
, imp
->imp_connect_data
.ocd_connect_flags
, ", ");
707 obd_import_flags2str(imp
, m
);
712 " failover_nids: [");
713 spin_lock(&imp
->imp_lock
);
715 list_for_each_entry(conn
, &imp
->imp_conn_list
, oic_item
) {
716 seq_printf(m
, "%s%s", j
? ", " : "",
717 libcfs_nid2str(conn
->oic_conn
->c_peer
.nid
));
722 " current_connection: %s\n"
723 " connection_attempts: %u\n"
725 " in-progress_invalidations: %u\n",
726 imp
->imp_connection
== NULL
? "<none>" :
727 libcfs_nid2str(imp
->imp_connection
->c_peer
.nid
),
730 atomic_read(&imp
->imp_inval_count
));
731 spin_unlock(&imp
->imp_lock
);
733 if (obd
->obd_svc_stats
== NULL
)
736 header
= &obd
->obd_svc_stats
->ls_cnt_header
[PTLRPC_REQWAIT_CNTR
];
737 lprocfs_stats_collect(obd
->obd_svc_stats
, PTLRPC_REQWAIT_CNTR
, &ret
);
738 if (ret
.lc_count
!= 0) {
739 /* first argument to do_div MUST be __u64 */
740 __u64 sum
= ret
.lc_sum
;
741 do_div(sum
, ret
.lc_count
);
748 " unregistering: %u\n"
750 " avg_waittime: %llu %s\n",
751 atomic_read(&imp
->imp_inflight
),
752 atomic_read(&imp
->imp_unregistering
),
753 atomic_read(&imp
->imp_timeouts
),
754 ret
.lc_sum
, header
->lc_units
);
757 for (j
= 0; j
< IMP_AT_MAX_PORTALS
; j
++) {
758 if (imp
->imp_at
.iat_portal
[j
] == 0)
760 k
= max_t(unsigned int, k
,
761 at_get(&imp
->imp_at
.iat_service_estimate
[j
]));
764 " service_estimates:\n"
765 " services: %u sec\n"
766 " network: %u sec\n",
768 at_get(&imp
->imp_at
.iat_net_latency
));
772 " last_replay: %llu\n"
773 " peer_committed: %llu\n"
774 " last_checked: %llu\n",
775 imp
->imp_last_replay_transno
,
776 imp
->imp_peer_committed_transno
,
777 imp
->imp_last_transno_checked
);
780 for (rw
= 0; rw
<= 1; rw
++) {
781 lprocfs_stats_collect(obd
->obd_svc_stats
,
782 PTLRPC_LAST_CNTR
+ BRW_READ_BYTES
+ rw
,
784 if (ret
.lc_sum
> 0 && ret
.lc_count
> 0) {
785 /* first argument to do_div MUST be __u64 */
786 __u64 sum
= ret
.lc_sum
;
787 do_div(sum
, ret
.lc_count
);
790 " %s_data_averages:\n"
791 " bytes_per_rpc: %llu\n",
792 rw
? "write" : "read",
796 j
= opcode_offset(OST_READ
+ rw
) + EXTRA_MAX_OPCODES
;
797 header
= &obd
->obd_svc_stats
->ls_cnt_header
[j
];
798 lprocfs_stats_collect(obd
->obd_svc_stats
, j
, &ret
);
799 if (ret
.lc_sum
> 0 && ret
.lc_count
!= 0) {
800 /* first argument to do_div MUST be __u64 */
801 __u64 sum
= ret
.lc_sum
;
802 do_div(sum
, ret
.lc_count
);
805 " %s_per_rpc: %llu\n",
806 header
->lc_units
, ret
.lc_sum
);
810 " MB_per_sec: %u.%.02u\n",
811 k
/ j
, (100 * k
/ j
) % 100);
816 LPROCFS_CLIMP_EXIT(obd
);
819 EXPORT_SYMBOL(lprocfs_rd_import
);
821 int lprocfs_rd_state(struct seq_file
*m
, void *data
)
823 struct obd_device
*obd
= (struct obd_device
*)data
;
824 struct obd_import
*imp
;
827 LASSERT(obd
!= NULL
);
828 LPROCFS_CLIMP_CHECK(obd
);
829 imp
= obd
->u
.cli
.cl_import
;
831 seq_printf(m
, "current_state: %s\n",
832 ptlrpc_import_state_name(imp
->imp_state
));
833 seq_printf(m
, "state_history:\n");
834 k
= imp
->imp_state_hist_idx
;
835 for (j
= 0; j
< IMP_STATE_HIST_LEN
; j
++) {
836 struct import_state_hist
*ish
=
837 &imp
->imp_state_hist
[(k
+ j
) % IMP_STATE_HIST_LEN
];
838 if (ish
->ish_state
== 0)
840 seq_printf(m
, " - ["CFS_TIME_T
", %s]\n",
842 ptlrpc_import_state_name(ish
->ish_state
));
845 LPROCFS_CLIMP_EXIT(obd
);
848 EXPORT_SYMBOL(lprocfs_rd_state
);
850 int lprocfs_at_hist_helper(struct seq_file
*m
, struct adaptive_timeout
*at
)
853 for (i
= 0; i
< AT_BINS
; i
++)
854 seq_printf(m
, "%3u ", at
->at_hist
[i
]);
858 EXPORT_SYMBOL(lprocfs_at_hist_helper
);
860 /* See also ptlrpc_lprocfs_rd_timeouts */
861 int lprocfs_rd_timeouts(struct seq_file
*m
, void *data
)
863 struct obd_device
*obd
= (struct obd_device
*)data
;
864 struct obd_import
*imp
;
865 unsigned int cur
, worst
;
870 LASSERT(obd
!= NULL
);
871 LPROCFS_CLIMP_CHECK(obd
);
872 imp
= obd
->u
.cli
.cl_import
;
876 /* Some network health info for kicks */
877 s2dhms(&ts
, now
- imp
->imp_last_reply_time
);
878 seq_printf(m
, "%-10s : %ld, "DHMS_FMT
" ago\n",
879 "last reply", imp
->imp_last_reply_time
, DHMS_VARS(&ts
));
881 cur
= at_get(&imp
->imp_at
.iat_net_latency
);
882 worst
= imp
->imp_at
.iat_net_latency
.at_worst_ever
;
883 worstt
= imp
->imp_at
.iat_net_latency
.at_worst_time
;
884 s2dhms(&ts
, now
- worstt
);
885 seq_printf(m
, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT
" ago) ",
886 "network", cur
, worst
, worstt
, DHMS_VARS(&ts
));
887 lprocfs_at_hist_helper(m
, &imp
->imp_at
.iat_net_latency
);
889 for (i
= 0; i
< IMP_AT_MAX_PORTALS
; i
++) {
890 if (imp
->imp_at
.iat_portal
[i
] == 0)
892 cur
= at_get(&imp
->imp_at
.iat_service_estimate
[i
]);
893 worst
= imp
->imp_at
.iat_service_estimate
[i
].at_worst_ever
;
894 worstt
= imp
->imp_at
.iat_service_estimate
[i
].at_worst_time
;
895 s2dhms(&ts
, now
- worstt
);
896 seq_printf(m
, "portal %-2d : cur %3u worst %3u (at %ld, "
897 DHMS_FMT
" ago) ", imp
->imp_at
.iat_portal
[i
],
898 cur
, worst
, worstt
, DHMS_VARS(&ts
));
899 lprocfs_at_hist_helper(m
, &imp
->imp_at
.iat_service_estimate
[i
]);
902 LPROCFS_CLIMP_EXIT(obd
);
905 EXPORT_SYMBOL(lprocfs_rd_timeouts
);
907 int lprocfs_rd_connect_flags(struct seq_file
*m
, void *data
)
909 struct obd_device
*obd
= data
;
912 LPROCFS_CLIMP_CHECK(obd
);
913 flags
= obd
->u
.cli
.cl_import
->imp_connect_data
.ocd_connect_flags
;
914 seq_printf(m
, "flags=%#llx\n", flags
);
915 obd_connect_seq_flags2str(m
, flags
, "\n");
917 LPROCFS_CLIMP_EXIT(obd
);
920 EXPORT_SYMBOL(lprocfs_rd_connect_flags
);
922 int lprocfs_rd_num_exports(struct seq_file
*m
, void *data
)
924 struct obd_device
*obd
= data
;
926 LASSERT(obd
!= NULL
);
927 return seq_printf(m
, "%u\n", obd
->obd_num_exports
);
929 EXPORT_SYMBOL(lprocfs_rd_num_exports
);
931 int lprocfs_rd_numrefs(struct seq_file
*m
, void *data
)
933 struct obd_type
*class = (struct obd_type
*) data
;
935 LASSERT(class != NULL
);
936 return seq_printf(m
, "%d\n", class->typ_refcnt
);
938 EXPORT_SYMBOL(lprocfs_rd_numrefs
);
940 int lprocfs_obd_setup(struct obd_device
*obd
, struct lprocfs_vars
*list
)
944 LASSERT(obd
!= NULL
);
945 LASSERT(obd
->obd_magic
== OBD_DEVICE_MAGIC
);
946 LASSERT(obd
->obd_type
->typ_procroot
!= NULL
);
948 obd
->obd_proc_entry
= lprocfs_register(obd
->obd_name
,
949 obd
->obd_type
->typ_procroot
,
951 if (IS_ERR(obd
->obd_proc_entry
)) {
952 rc
= PTR_ERR(obd
->obd_proc_entry
);
953 CERROR("error %d setting up lprocfs for %s\n",
955 obd
->obd_proc_entry
= NULL
;
959 EXPORT_SYMBOL(lprocfs_obd_setup
);
961 int lprocfs_obd_cleanup(struct obd_device
*obd
)
965 if (obd
->obd_proc_exports_entry
) {
966 /* Should be no exports left */
967 lprocfs_remove(&obd
->obd_proc_exports_entry
);
968 obd
->obd_proc_exports_entry
= NULL
;
970 if (obd
->obd_proc_entry
) {
971 lprocfs_remove(&obd
->obd_proc_entry
);
972 obd
->obd_proc_entry
= NULL
;
976 EXPORT_SYMBOL(lprocfs_obd_cleanup
);
978 static void lprocfs_free_client_stats(struct nid_stat
*client_stat
)
980 CDEBUG(D_CONFIG
, "stat %p - data %p/%p\n", client_stat
,
981 client_stat
->nid_proc
, client_stat
->nid_stats
);
983 LASSERTF(atomic_read(&client_stat
->nid_exp_ref_count
) == 0,
984 "nid %s:count %d\n", libcfs_nid2str(client_stat
->nid
),
985 atomic_read(&client_stat
->nid_exp_ref_count
));
987 if (client_stat
->nid_proc
)
988 lprocfs_remove(&client_stat
->nid_proc
);
990 if (client_stat
->nid_stats
)
991 lprocfs_free_stats(&client_stat
->nid_stats
);
993 if (client_stat
->nid_ldlm_stats
)
994 lprocfs_free_stats(&client_stat
->nid_ldlm_stats
);
996 OBD_FREE_PTR(client_stat
);
1001 void lprocfs_free_per_client_stats(struct obd_device
*obd
)
1003 struct cfs_hash
*hash
= obd
->obd_nid_stats_hash
;
1004 struct nid_stat
*stat
;
1006 /* we need extra list - because hash_exit called to early */
1007 /* not need locking because all clients is died */
1008 while (!list_empty(&obd
->obd_nid_stats
)) {
1009 stat
= list_entry(obd
->obd_nid_stats
.next
,
1010 struct nid_stat
, nid_list
);
1011 list_del_init(&stat
->nid_list
);
1012 cfs_hash_del(hash
, &stat
->nid
, &stat
->nid_hash
);
1013 lprocfs_free_client_stats(stat
);
1016 EXPORT_SYMBOL(lprocfs_free_per_client_stats
);
1018 int lprocfs_stats_alloc_one(struct lprocfs_stats
*stats
, unsigned int cpuid
)
1020 struct lprocfs_counter
*cntr
;
1021 unsigned int percpusize
;
1023 unsigned long flags
= 0;
1026 LASSERT(stats
->ls_percpu
[cpuid
] == NULL
);
1027 LASSERT((stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
) == 0);
1029 percpusize
= lprocfs_stats_counter_size(stats
);
1030 LIBCFS_ALLOC_ATOMIC(stats
->ls_percpu
[cpuid
], percpusize
);
1031 if (stats
->ls_percpu
[cpuid
] != NULL
) {
1033 if (unlikely(stats
->ls_biggest_alloc_num
<= cpuid
)) {
1034 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
1035 spin_lock_irqsave(&stats
->ls_lock
, flags
);
1037 spin_lock(&stats
->ls_lock
);
1038 if (stats
->ls_biggest_alloc_num
<= cpuid
)
1039 stats
->ls_biggest_alloc_num
= cpuid
+ 1;
1040 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
1041 spin_unlock_irqrestore(&stats
->ls_lock
, flags
);
1043 spin_unlock(&stats
->ls_lock
);
1045 /* initialize the ls_percpu[cpuid] non-zero counter */
1046 for (i
= 0; i
< stats
->ls_num
; ++i
) {
1047 cntr
= lprocfs_stats_counter_get(stats
, cpuid
, i
);
1048 cntr
->lc_min
= LC_MIN_INIT
;
1053 EXPORT_SYMBOL(lprocfs_stats_alloc_one
);
1055 struct lprocfs_stats
*lprocfs_alloc_stats(unsigned int num
,
1056 enum lprocfs_stats_flags flags
)
1058 struct lprocfs_stats
*stats
;
1059 unsigned int num_entry
;
1060 unsigned int percpusize
= 0;
1066 if (lprocfs_no_percpu_stats
!= 0)
1067 flags
|= LPROCFS_STATS_FLAG_NOPERCPU
;
1069 if (flags
& LPROCFS_STATS_FLAG_NOPERCPU
)
1072 num_entry
= num_possible_cpus();
1074 /* alloc percpu pointers for all possible cpu slots */
1075 LIBCFS_ALLOC(stats
, offsetof(typeof(*stats
), ls_percpu
[num_entry
]));
1079 stats
->ls_num
= num
;
1080 stats
->ls_flags
= flags
;
1081 spin_lock_init(&stats
->ls_lock
);
1083 /* alloc num of counter headers */
1084 LIBCFS_ALLOC(stats
->ls_cnt_header
,
1085 stats
->ls_num
* sizeof(struct lprocfs_counter_header
));
1086 if (stats
->ls_cnt_header
== NULL
)
1089 if ((flags
& LPROCFS_STATS_FLAG_NOPERCPU
) != 0) {
1090 /* contains only one set counters */
1091 percpusize
= lprocfs_stats_counter_size(stats
);
1092 LIBCFS_ALLOC_ATOMIC(stats
->ls_percpu
[0], percpusize
);
1093 if (stats
->ls_percpu
[0] == NULL
)
1095 stats
->ls_biggest_alloc_num
= 1;
1096 } else if ((flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0) {
1097 /* alloc all percpu data, currently only obd_memory use this */
1098 for (i
= 0; i
< num_entry
; ++i
)
1099 if (lprocfs_stats_alloc_one(stats
, i
) < 0)
1106 lprocfs_free_stats(&stats
);
1109 EXPORT_SYMBOL(lprocfs_alloc_stats
);
1111 void lprocfs_free_stats(struct lprocfs_stats
**statsh
)
1113 struct lprocfs_stats
*stats
= *statsh
;
1114 unsigned int num_entry
;
1115 unsigned int percpusize
;
1118 if (stats
== NULL
|| stats
->ls_num
== 0)
1122 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
)
1125 num_entry
= num_possible_cpus();
1127 percpusize
= lprocfs_stats_counter_size(stats
);
1128 for (i
= 0; i
< num_entry
; i
++)
1129 if (stats
->ls_percpu
[i
] != NULL
)
1130 LIBCFS_FREE(stats
->ls_percpu
[i
], percpusize
);
1131 if (stats
->ls_cnt_header
!= NULL
)
1132 LIBCFS_FREE(stats
->ls_cnt_header
, stats
->ls_num
*
1133 sizeof(struct lprocfs_counter_header
));
1134 LIBCFS_FREE(stats
, offsetof(typeof(*stats
), ls_percpu
[num_entry
]));
1136 EXPORT_SYMBOL(lprocfs_free_stats
);
1138 void lprocfs_clear_stats(struct lprocfs_stats
*stats
)
1140 struct lprocfs_counter
*percpu_cntr
;
1143 unsigned int num_entry
;
1144 unsigned long flags
= 0;
1146 num_entry
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1148 for (i
= 0; i
< num_entry
; i
++) {
1149 if (stats
->ls_percpu
[i
] == NULL
)
1151 for (j
= 0; j
< stats
->ls_num
; j
++) {
1152 percpu_cntr
= lprocfs_stats_counter_get(stats
, i
, j
);
1153 percpu_cntr
->lc_count
= 0;
1154 percpu_cntr
->lc_min
= LC_MIN_INIT
;
1155 percpu_cntr
->lc_max
= 0;
1156 percpu_cntr
->lc_sumsquare
= 0;
1157 percpu_cntr
->lc_sum
= 0;
1158 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
1159 percpu_cntr
->lc_sum_irq
= 0;
1163 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1165 EXPORT_SYMBOL(lprocfs_clear_stats
);
1167 static ssize_t
lprocfs_stats_seq_write(struct file
*file
,
1168 const char __user
*buf
,
1169 size_t len
, loff_t
*off
)
1171 struct seq_file
*seq
= file
->private_data
;
1172 struct lprocfs_stats
*stats
= seq
->private;
1174 lprocfs_clear_stats(stats
);
1179 static void *lprocfs_stats_seq_start(struct seq_file
*p
, loff_t
*pos
)
1181 struct lprocfs_stats
*stats
= p
->private;
1183 return (*pos
< stats
->ls_num
) ? pos
: NULL
;
1186 static void lprocfs_stats_seq_stop(struct seq_file
*p
, void *v
)
1190 static void *lprocfs_stats_seq_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1193 return lprocfs_stats_seq_start(p
, pos
);
1196 /* seq file export of one lprocfs counter */
1197 static int lprocfs_stats_seq_show(struct seq_file
*p
, void *v
)
1199 struct lprocfs_stats
*stats
= p
->private;
1200 struct lprocfs_counter_header
*hdr
;
1201 struct lprocfs_counter ctr
;
1202 int idx
= *(loff_t
*)v
;
1207 do_gettimeofday(&now
);
1208 rc
= seq_printf(p
, "%-25s %lu.%lu secs.usecs\n",
1209 "snapshot_time", now
.tv_sec
, (unsigned long)now
.tv_usec
);
1213 hdr
= &stats
->ls_cnt_header
[idx
];
1214 lprocfs_stats_collect(stats
, idx
, &ctr
);
1216 if (ctr
.lc_count
== 0)
1219 rc
= seq_printf(p
, "%-25s %lld samples [%s]", hdr
->lc_name
,
1220 ctr
.lc_count
, hdr
->lc_units
);
1225 if ((hdr
->lc_config
& LPROCFS_CNTR_AVGMINMAX
) && (ctr
.lc_count
> 0)) {
1226 rc
= seq_printf(p
, " %lld %lld %lld",
1227 ctr
.lc_min
, ctr
.lc_max
, ctr
.lc_sum
);
1230 if (hdr
->lc_config
& LPROCFS_CNTR_STDDEV
)
1231 rc
= seq_printf(p
, " %lld", ctr
.lc_sumsquare
);
1235 rc
= seq_printf(p
, "\n");
1237 return (rc
< 0) ? rc
: 0;
1240 static const struct seq_operations lprocfs_stats_seq_sops
= {
1241 .start
= lprocfs_stats_seq_start
,
1242 .stop
= lprocfs_stats_seq_stop
,
1243 .next
= lprocfs_stats_seq_next
,
1244 .show
= lprocfs_stats_seq_show
,
1247 static int lprocfs_stats_seq_open(struct inode
*inode
, struct file
*file
)
1249 struct seq_file
*seq
;
1252 rc
= seq_open(file
, &lprocfs_stats_seq_sops
);
1255 seq
= file
->private_data
;
1256 seq
->private = PDE_DATA(inode
);
1260 struct file_operations lprocfs_stats_seq_fops
= {
1261 .owner
= THIS_MODULE
,
1262 .open
= lprocfs_stats_seq_open
,
1264 .write
= lprocfs_stats_seq_write
,
1265 .llseek
= seq_lseek
,
1266 .release
= lprocfs_seq_release
,
1269 int lprocfs_register_stats(struct proc_dir_entry
*root
, const char *name
,
1270 struct lprocfs_stats
*stats
)
1272 struct proc_dir_entry
*entry
;
1273 LASSERT(root
!= NULL
);
1275 entry
= proc_create_data(name
, 0644, root
,
1276 &lprocfs_stats_seq_fops
, stats
);
1282 EXPORT_SYMBOL(lprocfs_register_stats
);
1284 void lprocfs_counter_init(struct lprocfs_stats
*stats
, int index
,
1285 unsigned conf
, const char *name
, const char *units
)
1287 struct lprocfs_counter_header
*header
;
1288 struct lprocfs_counter
*percpu_cntr
;
1289 unsigned long flags
= 0;
1291 unsigned int num_cpu
;
1293 LASSERT(stats
!= NULL
);
1295 header
= &stats
->ls_cnt_header
[index
];
1296 LASSERTF(header
!= NULL
, "Failed to allocate stats header:[%d]%s/%s\n",
1297 index
, name
, units
);
1299 header
->lc_config
= conf
;
1300 header
->lc_name
= name
;
1301 header
->lc_units
= units
;
1303 num_cpu
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1304 for (i
= 0; i
< num_cpu
; ++i
) {
1305 if (stats
->ls_percpu
[i
] == NULL
)
1307 percpu_cntr
= lprocfs_stats_counter_get(stats
, i
, index
);
1308 percpu_cntr
->lc_count
= 0;
1309 percpu_cntr
->lc_min
= LC_MIN_INIT
;
1310 percpu_cntr
->lc_max
= 0;
1311 percpu_cntr
->lc_sumsquare
= 0;
1312 percpu_cntr
->lc_sum
= 0;
1313 if ((stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0)
1314 percpu_cntr
->lc_sum_irq
= 0;
1316 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1318 EXPORT_SYMBOL(lprocfs_counter_init
);
1320 #define LPROCFS_OBD_OP_INIT(base, stats, op) \
1322 unsigned int coffset = base + OBD_COUNTER_OFFSET(op); \
1323 LASSERT(coffset < stats->ls_num); \
1324 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1327 void lprocfs_init_ops_stats(int num_private_stats
, struct lprocfs_stats
*stats
)
1329 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, iocontrol
);
1330 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, get_info
);
1331 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, set_info_async
);
1332 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, attach
);
1333 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, detach
);
1334 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, setup
);
1335 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, precleanup
);
1336 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, cleanup
);
1337 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, process_config
);
1338 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, postrecov
);
1339 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, add_conn
);
1340 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, del_conn
);
1341 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, connect
);
1342 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, reconnect
);
1343 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, disconnect
);
1344 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, fid_init
);
1345 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, fid_fini
);
1346 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, fid_alloc
);
1347 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, statfs
);
1348 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, statfs_async
);
1349 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, packmd
);
1350 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, unpackmd
);
1351 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, preallocate
);
1352 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, create
);
1353 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, destroy
);
1354 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, setattr
);
1355 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, setattr_async
);
1356 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, getattr
);
1357 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, getattr_async
);
1358 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, adjust_kms
);
1359 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, preprw
);
1360 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, commitrw
);
1361 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, find_cbdata
);
1362 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, init_export
);
1363 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, destroy_export
);
1364 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, import_event
);
1365 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, notify
);
1366 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, health_check
);
1367 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, get_uuid
);
1368 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, quotacheck
);
1369 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, quotactl
);
1370 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_new
);
1371 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_rem
);
1372 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_add
);
1373 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_del
);
1374 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, getref
);
1375 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, putref
);
1377 EXPORT_SYMBOL(lprocfs_init_ops_stats
);
1379 int lprocfs_alloc_obd_stats(struct obd_device
*obd
, unsigned num_private_stats
)
1381 struct lprocfs_stats
*stats
;
1382 unsigned int num_stats
;
1385 LASSERT(obd
->obd_stats
== NULL
);
1386 LASSERT(obd
->obd_proc_entry
!= NULL
);
1387 LASSERT(obd
->obd_cntr_base
== 0);
1389 num_stats
= ((int)sizeof(*obd
->obd_type
->typ_dt_ops
) / sizeof(void *)) +
1390 num_private_stats
- 1 /* o_owner */;
1391 stats
= lprocfs_alloc_stats(num_stats
, 0);
1395 lprocfs_init_ops_stats(num_private_stats
, stats
);
1397 for (i
= num_private_stats
; i
< num_stats
; i
++) {
1398 /* If this LBUGs, it is likely that an obd
1399 * operation was added to struct obd_ops in
1400 * <obd.h>, and that the corresponding line item
1401 * LPROCFS_OBD_OP_INIT(.., .., opname)
1402 * is missing from the list above. */
1403 LASSERTF(stats
->ls_cnt_header
[i
].lc_name
!= NULL
,
1404 "Missing obd_stat initializer obd_op operation at offset %d.\n",
1405 i
- num_private_stats
);
1407 rc
= lprocfs_register_stats(obd
->obd_proc_entry
, "stats", stats
);
1409 lprocfs_free_stats(&stats
);
1411 obd
->obd_stats
= stats
;
1412 obd
->obd_cntr_base
= num_private_stats
;
1416 EXPORT_SYMBOL(lprocfs_alloc_obd_stats
);
1418 void lprocfs_free_obd_stats(struct obd_device
*obd
)
1421 lprocfs_free_stats(&obd
->obd_stats
);
1423 EXPORT_SYMBOL(lprocfs_free_obd_stats
);
1425 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1427 unsigned int coffset = base + MD_COUNTER_OFFSET(op); \
1428 LASSERT(coffset < stats->ls_num); \
1429 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1432 void lprocfs_init_mps_stats(int num_private_stats
, struct lprocfs_stats
*stats
)
1434 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getstatus
);
1435 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, null_inode
);
1436 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, find_cbdata
);
1437 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, close
);
1438 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, create
);
1439 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, done_writing
);
1440 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, enqueue
);
1441 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getattr
);
1442 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getattr_name
);
1443 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, intent_lock
);
1444 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, link
);
1445 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, rename
);
1446 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, is_subdir
);
1447 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, setattr
);
1448 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, sync
);
1449 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, readpage
);
1450 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, unlink
);
1451 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, setxattr
);
1452 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getxattr
);
1453 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, init_ea_size
);
1454 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, get_lustre_md
);
1455 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, free_lustre_md
);
1456 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, set_open_replay_data
);
1457 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, clear_open_replay_data
);
1458 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, set_lock_data
);
1459 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, lock_match
);
1460 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, cancel_unused
);
1461 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, renew_capa
);
1462 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, unpack_capa
);
1463 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, get_remote_perm
);
1464 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, intent_getattr_async
);
1465 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, revalidate_lock
);
1467 EXPORT_SYMBOL(lprocfs_init_mps_stats
);
1469 int lprocfs_alloc_md_stats(struct obd_device
*obd
,
1470 unsigned num_private_stats
)
1472 struct lprocfs_stats
*stats
;
1473 unsigned int num_stats
;
1476 LASSERT(obd
->md_stats
== NULL
);
1477 LASSERT(obd
->obd_proc_entry
!= NULL
);
1478 LASSERT(obd
->md_cntr_base
== 0);
1480 num_stats
= 1 + MD_COUNTER_OFFSET(revalidate_lock
) +
1482 stats
= lprocfs_alloc_stats(num_stats
, 0);
1486 lprocfs_init_mps_stats(num_private_stats
, stats
);
1488 for (i
= num_private_stats
; i
< num_stats
; i
++) {
1489 if (stats
->ls_cnt_header
[i
].lc_name
== NULL
) {
1490 CERROR("Missing md_stat initializer md_op 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 stale nid entries");
1612 EXPORT_SYMBOL(lprocfs_nid_stats_clear_read
);
1614 static int lprocfs_nid_stats_clear_write_cb(void *obj
, void *data
)
1616 struct nid_stat
*stat
= obj
;
1618 CDEBUG(D_INFO
, "refcnt %d\n", atomic_read(&stat
->nid_exp_ref_count
));
1619 if (atomic_read(&stat
->nid_exp_ref_count
) == 1) {
1620 /* object has only hash references. */
1621 spin_lock(&stat
->nid_obd
->obd_nid_lock
);
1622 list_move(&stat
->nid_list
, data
);
1623 spin_unlock(&stat
->nid_obd
->obd_nid_lock
);
1626 /* we has reference to object - only clear data*/
1627 if (stat
->nid_stats
)
1628 lprocfs_clear_stats(stat
->nid_stats
);
1633 int lprocfs_nid_stats_clear_write(struct file
*file
, const char *buffer
,
1634 unsigned long count
, void *data
)
1636 struct obd_device
*obd
= (struct obd_device
*)data
;
1637 struct nid_stat
*client_stat
;
1638 LIST_HEAD(free_list
);
1640 cfs_hash_cond_del(obd
->obd_nid_stats_hash
,
1641 lprocfs_nid_stats_clear_write_cb
, &free_list
);
1643 while (!list_empty(&free_list
)) {
1644 client_stat
= list_entry(free_list
.next
, struct nid_stat
,
1646 list_del_init(&client_stat
->nid_list
);
1647 lprocfs_free_client_stats(client_stat
);
1652 EXPORT_SYMBOL(lprocfs_nid_stats_clear_write
);
1654 int lprocfs_exp_setup(struct obd_export
*exp
, lnet_nid_t
*nid
, int *newnid
)
1656 struct nid_stat
*new_stat
, *old_stat
;
1657 struct obd_device
*obd
= NULL
;
1658 struct proc_dir_entry
*entry
;
1659 char *buffer
= NULL
;
1664 if (!exp
|| !exp
->exp_obd
|| !exp
->exp_obd
->obd_proc_exports_entry
||
1665 !exp
->exp_obd
->obd_nid_stats_hash
)
1668 /* not test against zero because eric say:
1669 * You may only test nid against another nid, or LNET_NID_ANY.
1670 * Anything else is nonsense.*/
1671 if (!nid
|| *nid
== LNET_NID_ANY
)
1676 CDEBUG(D_CONFIG
, "using hash %p\n", obd
->obd_nid_stats_hash
);
1678 OBD_ALLOC_PTR(new_stat
);
1679 if (new_stat
== NULL
)
1682 new_stat
->nid
= *nid
;
1683 new_stat
->nid_obd
= exp
->exp_obd
;
1684 /* we need set default refcount to 1 to balance obd_disconnect */
1685 atomic_set(&new_stat
->nid_exp_ref_count
, 1);
1687 old_stat
= cfs_hash_findadd_unique(obd
->obd_nid_stats_hash
,
1688 nid
, &new_stat
->nid_hash
);
1689 CDEBUG(D_INFO
, "Found stats %p for nid %s - ref %d\n",
1690 old_stat
, libcfs_nid2str(*nid
),
1691 atomic_read(&new_stat
->nid_exp_ref_count
));
1693 /* We need to release old stats because lprocfs_exp_cleanup() hasn't
1694 * been and will never be called. */
1695 if (exp
->exp_nid_stats
) {
1696 nidstat_putref(exp
->exp_nid_stats
);
1697 exp
->exp_nid_stats
= NULL
;
1700 /* Return -EALREADY here so that we know that the /proc
1701 * entry already has been created */
1702 if (old_stat
!= new_stat
) {
1703 exp
->exp_nid_stats
= old_stat
;
1707 /* not found - create */
1708 OBD_ALLOC(buffer
, LNET_NIDSTR_SIZE
);
1709 if (buffer
== NULL
) {
1714 memcpy(buffer
, libcfs_nid2str(*nid
), LNET_NIDSTR_SIZE
);
1715 new_stat
->nid_proc
= lprocfs_register(buffer
,
1716 obd
->obd_proc_exports_entry
,
1718 OBD_FREE(buffer
, LNET_NIDSTR_SIZE
);
1720 if (IS_ERR(new_stat
->nid_proc
)) {
1721 CERROR("Error making export directory for nid %s\n",
1722 libcfs_nid2str(*nid
));
1723 rc
= PTR_ERR(new_stat
->nid_proc
);
1724 new_stat
->nid_proc
= NULL
;
1725 goto destroy_new_ns
;
1728 entry
= lprocfs_add_simple(new_stat
->nid_proc
, "uuid",
1729 new_stat
, &lproc_exp_uuid_fops
);
1730 if (IS_ERR(entry
)) {
1731 CWARN("Error adding the NID stats file\n");
1732 rc
= PTR_ERR(entry
);
1733 goto destroy_new_ns
;
1736 entry
= lprocfs_add_simple(new_stat
->nid_proc
, "hash",
1737 new_stat
, &lproc_exp_hash_fops
);
1738 if (IS_ERR(entry
)) {
1739 CWARN("Error adding the hash file\n");
1740 rc
= PTR_ERR(entry
);
1741 goto destroy_new_ns
;
1744 exp
->exp_nid_stats
= new_stat
;
1746 /* protect competitive add to list, not need locking on destroy */
1747 spin_lock(&obd
->obd_nid_lock
);
1748 list_add(&new_stat
->nid_list
, &obd
->obd_nid_stats
);
1749 spin_unlock(&obd
->obd_nid_lock
);
1754 if (new_stat
->nid_proc
!= NULL
)
1755 lprocfs_remove(&new_stat
->nid_proc
);
1756 cfs_hash_del(obd
->obd_nid_stats_hash
, nid
, &new_stat
->nid_hash
);
1759 nidstat_putref(new_stat
);
1760 OBD_FREE_PTR(new_stat
);
1763 EXPORT_SYMBOL(lprocfs_exp_setup
);
1765 int lprocfs_exp_cleanup(struct obd_export
*exp
)
1767 struct nid_stat
*stat
= exp
->exp_nid_stats
;
1769 if (!stat
|| !exp
->exp_obd
)
1772 nidstat_putref(exp
->exp_nid_stats
);
1773 exp
->exp_nid_stats
= NULL
;
1777 EXPORT_SYMBOL(lprocfs_exp_cleanup
);
1779 __s64
lprocfs_read_helper(struct lprocfs_counter
*lc
,
1780 struct lprocfs_counter_header
*header
,
1781 enum lprocfs_stats_flags flags
,
1782 enum lprocfs_fields_flags field
)
1786 if (lc
== NULL
|| header
== NULL
)
1790 case LPROCFS_FIELDS_FLAGS_CONFIG
:
1791 ret
= header
->lc_config
;
1793 case LPROCFS_FIELDS_FLAGS_SUM
:
1795 if ((flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0)
1796 ret
+= lc
->lc_sum_irq
;
1798 case LPROCFS_FIELDS_FLAGS_MIN
:
1801 case LPROCFS_FIELDS_FLAGS_MAX
:
1804 case LPROCFS_FIELDS_FLAGS_AVG
:
1805 ret
= (lc
->lc_max
- lc
->lc_min
) / 2;
1807 case LPROCFS_FIELDS_FLAGS_SUMSQUARE
:
1808 ret
= lc
->lc_sumsquare
;
1810 case LPROCFS_FIELDS_FLAGS_COUNT
:
1819 EXPORT_SYMBOL(lprocfs_read_helper
);
1821 int lprocfs_write_helper(const char __user
*buffer
, unsigned long count
,
1824 return lprocfs_write_frac_helper(buffer
, count
, val
, 1);
1826 EXPORT_SYMBOL(lprocfs_write_helper
);
1828 int lprocfs_seq_read_frac_helper(struct seq_file
*m
, long val
, int mult
)
1830 long decimal_val
, frac_val
;
1832 decimal_val
= val
/ mult
;
1833 seq_printf(m
, "%ld", decimal_val
);
1834 frac_val
= val
% mult
;
1841 /* Three cases: x0, xx, 0x */
1842 if ((frac_val
% 10) != 0)
1843 seq_printf(m
, ".%ld", frac_val
);
1845 seq_printf(m
, ".%ld", frac_val
/ 10);
1848 seq_printf(m
, "\n");
1851 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper
);
1853 int lprocfs_write_u64_helper(const char __user
*buffer
, unsigned long count
,
1856 return lprocfs_write_frac_u64_helper(buffer
, count
, val
, 1);
1858 EXPORT_SYMBOL(lprocfs_write_u64_helper
);
1860 int lprocfs_write_frac_u64_helper(const char *buffer
, unsigned long count
,
1861 __u64
*val
, int mult
)
1863 char kernbuf
[22], *end
, *pbuf
;
1864 __u64 whole
, frac
= 0, units
;
1865 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);
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
++)
1900 switch (tolower(*end
)) {
1912 /* Specified units override the multiplier */
1917 do_div(frac
, frac_d
);
1918 *val
= sign
* (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
);