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 <obd_class.h>
45 #include <lprocfs_status.h>
46 #include <lustre/lustre_idl.h>
47 #include <linux/seq_file.h>
51 static int lprocfs_no_percpu_stats
= 0;
52 CFS_MODULE_PARM(lprocfs_no_percpu_stats
, "i", int, 0644,
53 "Do not alloc percpu data for lprocfs stats");
55 #define MAX_STRING_SIZE 128
57 int lprocfs_single_release(struct inode
*inode
, struct file
*file
)
59 return single_release(inode
, file
);
61 EXPORT_SYMBOL(lprocfs_single_release
);
63 int lprocfs_seq_release(struct inode
*inode
, struct file
*file
)
65 return seq_release(inode
, file
);
67 EXPORT_SYMBOL(lprocfs_seq_release
);
69 /* lprocfs API calls */
71 proc_dir_entry_t
*lprocfs_add_simple(struct proc_dir_entry
*root
,
72 char *name
, void *data
,
73 struct file_operations
*fops
)
75 proc_dir_entry_t
*proc
;
78 if (root
== NULL
|| name
== NULL
|| fops
== NULL
)
79 return ERR_PTR(-EINVAL
);
85 proc
= proc_create_data(name
, mode
, root
, fops
, data
);
87 CERROR("LprocFS: No memory to create /proc entry %s", name
);
88 return ERR_PTR(-ENOMEM
);
92 EXPORT_SYMBOL(lprocfs_add_simple
);
94 struct proc_dir_entry
*lprocfs_add_symlink(const char *name
,
95 struct proc_dir_entry
*parent
, const char *format
, ...)
97 struct proc_dir_entry
*entry
;
101 if (parent
== NULL
|| format
== NULL
)
104 OBD_ALLOC_WAIT(dest
, MAX_STRING_SIZE
+ 1);
108 va_start(ap
, format
);
109 vsnprintf(dest
, MAX_STRING_SIZE
, format
, ap
);
112 entry
= proc_symlink(name
, parent
, dest
);
114 CERROR("LprocFS: Could not create symbolic link from %s to %s",
117 OBD_FREE(dest
, MAX_STRING_SIZE
+ 1);
120 EXPORT_SYMBOL(lprocfs_add_symlink
);
122 static struct file_operations lprocfs_generic_fops
= { };
127 * \param root [in] The parent proc entry on which new entry will be added.
128 * \param list [in] Array of proc entries to be added.
129 * \param data [in] The argument to be passed when entries read/write routines
130 * are called through /proc file.
132 * \retval 0 on success
135 int lprocfs_add_vars(struct proc_dir_entry
*root
, struct lprocfs_vars
*list
,
138 if (root
== NULL
|| list
== NULL
)
141 while (list
->name
!= NULL
) {
142 struct proc_dir_entry
*proc
;
145 if (list
->proc_mode
!= 0000) {
146 mode
= list
->proc_mode
;
147 } else if (list
->fops
) {
148 if (list
->fops
->read
)
150 if (list
->fops
->write
)
153 proc
= proc_create_data(list
->name
, mode
, root
,
154 list
->fops
?: &lprocfs_generic_fops
,
162 EXPORT_SYMBOL(lprocfs_add_vars
);
164 void lprocfs_remove(struct proc_dir_entry
**rooth
)
169 EXPORT_SYMBOL(lprocfs_remove
);
171 void lprocfs_remove_proc_entry(const char *name
, struct proc_dir_entry
*parent
)
173 LASSERT(parent
!= NULL
);
174 remove_proc_entry(name
, parent
);
176 EXPORT_SYMBOL(lprocfs_remove_proc_entry
);
178 struct proc_dir_entry
*lprocfs_register(const char *name
,
179 struct proc_dir_entry
*parent
,
180 struct lprocfs_vars
*list
, void *data
)
182 struct proc_dir_entry
*newchild
;
184 newchild
= proc_mkdir(name
, parent
);
185 if (newchild
!= NULL
&& list
!= NULL
) {
186 int rc
= lprocfs_add_vars(newchild
, list
, data
);
188 lprocfs_remove(&newchild
);
194 EXPORT_SYMBOL(lprocfs_register
);
196 /* Generic callbacks */
197 int lprocfs_rd_uint(struct seq_file
*m
, void *data
)
199 return seq_printf(m
, "%u\n", *(unsigned int *)data
);
201 EXPORT_SYMBOL(lprocfs_rd_uint
);
203 int lprocfs_wr_uint(struct file
*file
, const char __user
*buffer
,
204 unsigned long count
, void *data
)
207 char dummy
[MAX_STRING_SIZE
+ 1], *end
;
210 dummy
[MAX_STRING_SIZE
] = '\0';
211 if (copy_from_user(dummy
, buffer
, MAX_STRING_SIZE
))
214 tmp
= simple_strtoul(dummy
, &end
, 0);
218 *p
= (unsigned int)tmp
;
221 EXPORT_SYMBOL(lprocfs_wr_uint
);
223 int lprocfs_rd_u64(struct seq_file
*m
, void *data
)
225 return seq_printf(m
, LPU64
"\n", *(__u64
*)data
);
227 EXPORT_SYMBOL(lprocfs_rd_u64
);
229 int lprocfs_rd_atomic(struct seq_file
*m
, void *data
)
231 atomic_t
*atom
= data
;
232 LASSERT(atom
!= NULL
);
233 return seq_printf(m
, "%d\n", atomic_read(atom
));
235 EXPORT_SYMBOL(lprocfs_rd_atomic
);
237 int lprocfs_wr_atomic(struct file
*file
, const char __user
*buffer
,
238 unsigned long count
, void *data
)
240 atomic_t
*atm
= data
;
244 rc
= lprocfs_write_helper(buffer
, count
, &val
);
251 atomic_set(atm
, val
);
254 EXPORT_SYMBOL(lprocfs_wr_atomic
);
256 int lprocfs_rd_uuid(struct seq_file
*m
, void *data
)
258 struct obd_device
*obd
= data
;
260 LASSERT(obd
!= NULL
);
261 return seq_printf(m
, "%s\n", obd
->obd_uuid
.uuid
);
263 EXPORT_SYMBOL(lprocfs_rd_uuid
);
265 int lprocfs_rd_name(struct seq_file
*m
, void *data
)
267 struct obd_device
*dev
= data
;
269 LASSERT(dev
!= NULL
);
270 return seq_printf(m
, "%s\n", dev
->obd_name
);
272 EXPORT_SYMBOL(lprocfs_rd_name
);
274 int lprocfs_rd_blksize(struct seq_file
*m
, void *data
)
276 struct obd_device
*obd
= data
;
277 struct obd_statfs osfs
;
278 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
279 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
282 rc
= seq_printf(m
, "%u\n", osfs
.os_bsize
);
285 EXPORT_SYMBOL(lprocfs_rd_blksize
);
287 int lprocfs_rd_kbytestotal(struct seq_file
*m
, void *data
)
289 struct obd_device
*obd
= data
;
290 struct obd_statfs osfs
;
291 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
292 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
295 __u32 blk_size
= osfs
.os_bsize
>> 10;
296 __u64 result
= osfs
.os_blocks
;
298 while (blk_size
>>= 1)
301 rc
= seq_printf(m
, LPU64
"\n", result
);
305 EXPORT_SYMBOL(lprocfs_rd_kbytestotal
);
307 int lprocfs_rd_kbytesfree(struct seq_file
*m
, void *data
)
309 struct obd_device
*obd
= data
;
310 struct obd_statfs osfs
;
311 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
312 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
315 __u32 blk_size
= osfs
.os_bsize
>> 10;
316 __u64 result
= osfs
.os_bfree
;
318 while (blk_size
>>= 1)
321 rc
= seq_printf(m
, LPU64
"\n", result
);
325 EXPORT_SYMBOL(lprocfs_rd_kbytesfree
);
327 int lprocfs_rd_kbytesavail(struct seq_file
*m
, void *data
)
329 struct obd_device
*obd
= data
;
330 struct obd_statfs osfs
;
331 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
332 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
335 __u32 blk_size
= osfs
.os_bsize
>> 10;
336 __u64 result
= osfs
.os_bavail
;
338 while (blk_size
>>= 1)
341 rc
= seq_printf(m
, LPU64
"\n", result
);
345 EXPORT_SYMBOL(lprocfs_rd_kbytesavail
);
347 int lprocfs_rd_filestotal(struct seq_file
*m
, void *data
)
349 struct obd_device
*obd
= data
;
350 struct obd_statfs osfs
;
351 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
352 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
355 rc
= seq_printf(m
, LPU64
"\n", osfs
.os_files
);
359 EXPORT_SYMBOL(lprocfs_rd_filestotal
);
361 int lprocfs_rd_filesfree(struct seq_file
*m
, void *data
)
363 struct obd_device
*obd
= data
;
364 struct obd_statfs osfs
;
365 int rc
= obd_statfs(NULL
, obd
->obd_self_export
, &osfs
,
366 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
369 rc
= seq_printf(m
, LPU64
"\n", osfs
.os_ffree
);
372 EXPORT_SYMBOL(lprocfs_rd_filesfree
);
374 int lprocfs_rd_server_uuid(struct seq_file
*m
, void *data
)
376 struct obd_device
*obd
= data
;
377 struct obd_import
*imp
;
378 char *imp_state_name
= NULL
;
381 LASSERT(obd
!= NULL
);
382 LPROCFS_CLIMP_CHECK(obd
);
383 imp
= obd
->u
.cli
.cl_import
;
384 imp_state_name
= ptlrpc_import_state_name(imp
->imp_state
);
385 rc
= seq_printf(m
, "%s\t%s%s\n", obd2cli_tgt(obd
), imp_state_name
,
386 imp
->imp_deactive
? "\tDEACTIVATED" : "");
388 LPROCFS_CLIMP_EXIT(obd
);
391 EXPORT_SYMBOL(lprocfs_rd_server_uuid
);
393 int lprocfs_rd_conn_uuid(struct seq_file
*m
, void *data
)
395 struct obd_device
*obd
= data
;
396 struct ptlrpc_connection
*conn
;
399 LASSERT(obd
!= NULL
);
401 LPROCFS_CLIMP_CHECK(obd
);
402 conn
= obd
->u
.cli
.cl_import
->imp_connection
;
403 if (conn
&& obd
->u
.cli
.cl_import
)
404 rc
= seq_printf(m
, "%s\n", conn
->c_remote_uuid
.uuid
);
406 rc
= seq_printf(m
, "%s\n", "<none>");
408 LPROCFS_CLIMP_EXIT(obd
);
411 EXPORT_SYMBOL(lprocfs_rd_conn_uuid
);
413 /** add up per-cpu counters */
414 void lprocfs_stats_collect(struct lprocfs_stats
*stats
, int idx
,
415 struct lprocfs_counter
*cnt
)
417 unsigned int num_entry
;
418 struct lprocfs_counter
*percpu_cntr
;
419 struct lprocfs_counter_header
*cntr_header
;
421 unsigned long flags
= 0;
423 memset(cnt
, 0, sizeof(*cnt
));
426 /* set count to 1 to avoid divide-by-zero errs in callers */
431 cnt
->lc_min
= LC_MIN_INIT
;
433 num_entry
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
435 for (i
= 0; i
< num_entry
; i
++) {
436 if (stats
->ls_percpu
[i
] == NULL
)
438 cntr_header
= &stats
->ls_cnt_header
[idx
];
439 percpu_cntr
= lprocfs_stats_counter_get(stats
, i
, idx
);
441 cnt
->lc_count
+= percpu_cntr
->lc_count
;
442 cnt
->lc_sum
+= percpu_cntr
->lc_sum
;
443 if (percpu_cntr
->lc_min
< cnt
->lc_min
)
444 cnt
->lc_min
= percpu_cntr
->lc_min
;
445 if (percpu_cntr
->lc_max
> cnt
->lc_max
)
446 cnt
->lc_max
= percpu_cntr
->lc_max
;
447 cnt
->lc_sumsquare
+= percpu_cntr
->lc_sumsquare
;
450 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
452 EXPORT_SYMBOL(lprocfs_stats_collect
);
455 * Append a space separated list of current set flags to str.
457 #define flag2str(flag, first) \
459 if (imp->imp_##flag) \
460 seq_printf(m, "%s" #flag, first ? "" : ", "); \
462 static int obd_import_flags2str(struct obd_import
*imp
, struct seq_file
*m
)
466 if (imp
->imp_obd
->obd_no_recov
) {
467 seq_printf(m
, "no_recov");
471 flag2str(invalid
, first
);
473 flag2str(deactive
, first
);
474 flag2str(replayable
, first
);
475 flag2str(pingable
, first
);
480 static const char *obd_connect_names
[] = {
494 "join_file(obsolete)",
498 "remote_client_by_force",
507 "mds_mds_connection",
510 "alt_checksum_algorithm",
536 static void obd_connect_seq_flags2str(struct seq_file
*m
, __u64 flags
, char *sep
)
542 for (i
= 0; obd_connect_names
[i
] != NULL
; i
++, mask
<<= 1) {
544 seq_printf(m
, "%s%s",
545 first
? sep
: "", obd_connect_names
[i
]);
549 if (flags
& ~(mask
- 1))
550 seq_printf(m
, "%sunknown flags "LPX64
,
551 first
? sep
: "", flags
& ~(mask
- 1));
554 int obd_connect_flags2str(char *page
, int count
, __u64 flags
, char *sep
)
559 for (i
= 0; obd_connect_names
[i
] != NULL
; i
++, mask
<<= 1) {
561 ret
+= snprintf(page
+ ret
, count
- ret
, "%s%s",
562 ret
? sep
: "", obd_connect_names
[i
]);
564 if (flags
& ~(mask
- 1))
565 ret
+= snprintf(page
+ ret
, count
- ret
,
566 "%sunknown flags "LPX64
,
567 ret
? sep
: "", flags
& ~(mask
- 1));
570 EXPORT_SYMBOL(obd_connect_flags2str
);
572 int lprocfs_rd_import(struct seq_file
*m
, void *data
)
574 struct lprocfs_counter ret
;
575 struct lprocfs_counter_header
*header
;
576 struct obd_device
*obd
= (struct obd_device
*)data
;
577 struct obd_import
*imp
;
578 struct obd_import_conn
*conn
;
583 LASSERT(obd
!= NULL
);
584 LPROCFS_CLIMP_CHECK(obd
);
585 imp
= obd
->u
.cli
.cl_import
;
596 ptlrpc_import_state_name(imp
->imp_state
),
597 imp
->imp_connect_data
.ocd_instance
);
598 obd_connect_seq_flags2str(m
, imp
->imp_connect_data
.ocd_connect_flags
, ", ");
602 obd_import_flags2str(imp
, m
);
607 " failover_nids: [");
608 spin_lock(&imp
->imp_lock
);
610 list_for_each_entry(conn
, &imp
->imp_conn_list
, oic_item
) {
611 seq_printf(m
, "%s%s", j
? ", " : "",
612 libcfs_nid2str(conn
->oic_conn
->c_peer
.nid
));
617 " current_connection: %s\n"
618 " connection_attempts: %u\n"
620 " in-progress_invalidations: %u\n",
621 imp
->imp_connection
== NULL
? "<none>" :
622 libcfs_nid2str(imp
->imp_connection
->c_peer
.nid
),
625 atomic_read(&imp
->imp_inval_count
));
626 spin_unlock(&imp
->imp_lock
);
628 if (obd
->obd_svc_stats
== NULL
)
631 header
= &obd
->obd_svc_stats
->ls_cnt_header
[PTLRPC_REQWAIT_CNTR
];
632 lprocfs_stats_collect(obd
->obd_svc_stats
, PTLRPC_REQWAIT_CNTR
, &ret
);
633 if (ret
.lc_count
!= 0) {
634 /* first argument to do_div MUST be __u64 */
635 __u64 sum
= ret
.lc_sum
;
636 do_div(sum
, ret
.lc_count
);
643 " unregistering: %u\n"
645 " avg_waittime: "LPU64
" %s\n",
646 atomic_read(&imp
->imp_inflight
),
647 atomic_read(&imp
->imp_unregistering
),
648 atomic_read(&imp
->imp_timeouts
),
649 ret
.lc_sum
, header
->lc_units
);
652 for(j
= 0; j
< IMP_AT_MAX_PORTALS
; j
++) {
653 if (imp
->imp_at
.iat_portal
[j
] == 0)
655 k
= max_t(unsigned int, k
,
656 at_get(&imp
->imp_at
.iat_service_estimate
[j
]));
659 " service_estimates:\n"
660 " services: %u sec\n"
661 " network: %u sec\n",
663 at_get(&imp
->imp_at
.iat_net_latency
));
667 " last_replay: "LPU64
"\n"
668 " peer_committed: "LPU64
"\n"
669 " last_checked: "LPU64
"\n",
670 imp
->imp_last_replay_transno
,
671 imp
->imp_peer_committed_transno
,
672 imp
->imp_last_transno_checked
);
675 for (rw
= 0; rw
<= 1; rw
++) {
676 lprocfs_stats_collect(obd
->obd_svc_stats
,
677 PTLRPC_LAST_CNTR
+ BRW_READ_BYTES
+ rw
,
679 if (ret
.lc_sum
> 0 && ret
.lc_count
> 0) {
680 /* first argument to do_div MUST be __u64 */
681 __u64 sum
= ret
.lc_sum
;
682 do_div(sum
, ret
.lc_count
);
685 " %s_data_averages:\n"
686 " bytes_per_rpc: "LPU64
"\n",
687 rw
? "write" : "read",
691 j
= opcode_offset(OST_READ
+ rw
) + EXTRA_MAX_OPCODES
;
692 header
= &obd
->obd_svc_stats
->ls_cnt_header
[j
];
693 lprocfs_stats_collect(obd
->obd_svc_stats
, j
, &ret
);
694 if (ret
.lc_sum
> 0 && ret
.lc_count
!= 0) {
695 /* first argument to do_div MUST be __u64 */
696 __u64 sum
= ret
.lc_sum
;
697 do_div(sum
, ret
.lc_count
);
700 " %s_per_rpc: "LPU64
"\n",
701 header
->lc_units
, ret
.lc_sum
);
705 " MB_per_sec: %u.%.02u\n",
706 k
/ j
, (100 * k
/ j
) % 100);
711 LPROCFS_CLIMP_EXIT(obd
);
714 EXPORT_SYMBOL(lprocfs_rd_import
);
716 int lprocfs_rd_state(struct seq_file
*m
, void *data
)
718 struct obd_device
*obd
= (struct obd_device
*)data
;
719 struct obd_import
*imp
;
722 LASSERT(obd
!= NULL
);
723 LPROCFS_CLIMP_CHECK(obd
);
724 imp
= obd
->u
.cli
.cl_import
;
726 seq_printf(m
, "current_state: %s\n",
727 ptlrpc_import_state_name(imp
->imp_state
));
728 seq_printf(m
, "state_history:\n");
729 k
= imp
->imp_state_hist_idx
;
730 for (j
= 0; j
< IMP_STATE_HIST_LEN
; j
++) {
731 struct import_state_hist
*ish
=
732 &imp
->imp_state_hist
[(k
+ j
) % IMP_STATE_HIST_LEN
];
733 if (ish
->ish_state
== 0)
735 seq_printf(m
, " - ["CFS_TIME_T
", %s]\n",
737 ptlrpc_import_state_name(ish
->ish_state
));
740 LPROCFS_CLIMP_EXIT(obd
);
743 EXPORT_SYMBOL(lprocfs_rd_state
);
745 int lprocfs_at_hist_helper(struct seq_file
*m
, struct adaptive_timeout
*at
)
748 for (i
= 0; i
< AT_BINS
; i
++)
749 seq_printf(m
, "%3u ", at
->at_hist
[i
]);
753 EXPORT_SYMBOL(lprocfs_at_hist_helper
);
755 /* See also ptlrpc_lprocfs_rd_timeouts */
756 int lprocfs_rd_timeouts(struct seq_file
*m
, void *data
)
758 struct obd_device
*obd
= (struct obd_device
*)data
;
759 struct obd_import
*imp
;
760 unsigned int cur
, worst
;
765 LASSERT(obd
!= NULL
);
766 LPROCFS_CLIMP_CHECK(obd
);
767 imp
= obd
->u
.cli
.cl_import
;
769 now
= cfs_time_current_sec();
771 /* Some network health info for kicks */
772 s2dhms(&ts
, now
- imp
->imp_last_reply_time
);
773 seq_printf(m
, "%-10s : %ld, "DHMS_FMT
" ago\n",
774 "last reply", imp
->imp_last_reply_time
, DHMS_VARS(&ts
));
776 cur
= at_get(&imp
->imp_at
.iat_net_latency
);
777 worst
= imp
->imp_at
.iat_net_latency
.at_worst_ever
;
778 worstt
= imp
->imp_at
.iat_net_latency
.at_worst_time
;
779 s2dhms(&ts
, now
- worstt
);
780 seq_printf(m
, "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT
" ago) ",
781 "network", cur
, worst
, worstt
, DHMS_VARS(&ts
));
782 lprocfs_at_hist_helper(m
, &imp
->imp_at
.iat_net_latency
);
784 for(i
= 0; i
< IMP_AT_MAX_PORTALS
; i
++) {
785 if (imp
->imp_at
.iat_portal
[i
] == 0)
787 cur
= at_get(&imp
->imp_at
.iat_service_estimate
[i
]);
788 worst
= imp
->imp_at
.iat_service_estimate
[i
].at_worst_ever
;
789 worstt
= imp
->imp_at
.iat_service_estimate
[i
].at_worst_time
;
790 s2dhms(&ts
, now
- worstt
);
791 seq_printf(m
, "portal %-2d : cur %3u worst %3u (at %ld, "
792 DHMS_FMT
" ago) ", imp
->imp_at
.iat_portal
[i
],
793 cur
, worst
, worstt
, DHMS_VARS(&ts
));
794 lprocfs_at_hist_helper(m
, &imp
->imp_at
.iat_service_estimate
[i
]);
797 LPROCFS_CLIMP_EXIT(obd
);
800 EXPORT_SYMBOL(lprocfs_rd_timeouts
);
802 int lprocfs_rd_connect_flags(struct seq_file
*m
, void *data
)
804 struct obd_device
*obd
= data
;
807 LPROCFS_CLIMP_CHECK(obd
);
808 flags
= obd
->u
.cli
.cl_import
->imp_connect_data
.ocd_connect_flags
;
809 seq_printf(m
, "flags="LPX64
"\n", flags
);
810 obd_connect_seq_flags2str(m
, flags
, "\n");
812 LPROCFS_CLIMP_EXIT(obd
);
815 EXPORT_SYMBOL(lprocfs_rd_connect_flags
);
817 int lprocfs_rd_num_exports(struct seq_file
*m
, void *data
)
819 struct obd_device
*obd
= data
;
821 LASSERT(obd
!= NULL
);
822 return seq_printf(m
, "%u\n", obd
->obd_num_exports
);
824 EXPORT_SYMBOL(lprocfs_rd_num_exports
);
826 int lprocfs_rd_numrefs(struct seq_file
*m
, void *data
)
828 struct obd_type
*class = (struct obd_type
*) data
;
830 LASSERT(class != NULL
);
831 return seq_printf(m
, "%d\n", class->typ_refcnt
);
833 EXPORT_SYMBOL(lprocfs_rd_numrefs
);
835 int lprocfs_obd_setup(struct obd_device
*obd
, struct lprocfs_vars
*list
)
839 LASSERT(obd
!= NULL
);
840 LASSERT(obd
->obd_magic
== OBD_DEVICE_MAGIC
);
841 LASSERT(obd
->obd_type
->typ_procroot
!= NULL
);
843 obd
->obd_proc_entry
= lprocfs_register(obd
->obd_name
,
844 obd
->obd_type
->typ_procroot
,
846 if (IS_ERR(obd
->obd_proc_entry
)) {
847 rc
= PTR_ERR(obd
->obd_proc_entry
);
848 CERROR("error %d setting up lprocfs for %s\n",rc
,obd
->obd_name
);
849 obd
->obd_proc_entry
= NULL
;
853 EXPORT_SYMBOL(lprocfs_obd_setup
);
855 int lprocfs_obd_cleanup(struct obd_device
*obd
)
859 if (obd
->obd_proc_exports_entry
) {
860 /* Should be no exports left */
861 lprocfs_remove(&obd
->obd_proc_exports_entry
);
862 obd
->obd_proc_exports_entry
= NULL
;
864 if (obd
->obd_proc_entry
) {
865 lprocfs_remove(&obd
->obd_proc_entry
);
866 obd
->obd_proc_entry
= NULL
;
870 EXPORT_SYMBOL(lprocfs_obd_cleanup
);
872 static void lprocfs_free_client_stats(struct nid_stat
*client_stat
)
874 CDEBUG(D_CONFIG
, "stat %p - data %p/%p\n", client_stat
,
875 client_stat
->nid_proc
, client_stat
->nid_stats
);
877 LASSERTF(atomic_read(&client_stat
->nid_exp_ref_count
) == 0,
878 "nid %s:count %d\n", libcfs_nid2str(client_stat
->nid
),
879 atomic_read(&client_stat
->nid_exp_ref_count
));
881 if (client_stat
->nid_proc
)
882 lprocfs_remove(&client_stat
->nid_proc
);
884 if (client_stat
->nid_stats
)
885 lprocfs_free_stats(&client_stat
->nid_stats
);
887 if (client_stat
->nid_ldlm_stats
)
888 lprocfs_free_stats(&client_stat
->nid_ldlm_stats
);
890 OBD_FREE_PTR(client_stat
);
895 void lprocfs_free_per_client_stats(struct obd_device
*obd
)
897 cfs_hash_t
*hash
= obd
->obd_nid_stats_hash
;
898 struct nid_stat
*stat
;
901 /* we need extra list - because hash_exit called to early */
902 /* not need locking because all clients is died */
903 while (!list_empty(&obd
->obd_nid_stats
)) {
904 stat
= list_entry(obd
->obd_nid_stats
.next
,
905 struct nid_stat
, nid_list
);
906 list_del_init(&stat
->nid_list
);
907 cfs_hash_del(hash
, &stat
->nid
, &stat
->nid_hash
);
908 lprocfs_free_client_stats(stat
);
912 EXPORT_SYMBOL(lprocfs_free_per_client_stats
);
914 struct lprocfs_stats
*lprocfs_alloc_stats(unsigned int num
,
915 enum lprocfs_stats_flags flags
)
917 struct lprocfs_stats
*stats
;
918 unsigned int num_entry
;
919 unsigned int percpusize
= 0;
925 if (lprocfs_no_percpu_stats
!= 0)
926 flags
|= LPROCFS_STATS_FLAG_NOPERCPU
;
928 if (flags
& LPROCFS_STATS_FLAG_NOPERCPU
)
931 num_entry
= num_possible_cpus();
933 /* alloc percpu pointers for all possible cpu slots */
934 LIBCFS_ALLOC(stats
, offsetof(typeof(*stats
), ls_percpu
[num_entry
]));
939 stats
->ls_flags
= flags
;
940 spin_lock_init(&stats
->ls_lock
);
942 /* alloc num of counter headers */
943 LIBCFS_ALLOC(stats
->ls_cnt_header
,
944 stats
->ls_num
* sizeof(struct lprocfs_counter_header
));
945 if (stats
->ls_cnt_header
== NULL
)
948 if ((flags
& LPROCFS_STATS_FLAG_NOPERCPU
) != 0) {
949 /* contains only one set counters */
950 percpusize
= lprocfs_stats_counter_size(stats
);
951 LIBCFS_ALLOC_ATOMIC(stats
->ls_percpu
[0], percpusize
);
952 if (stats
->ls_percpu
[0] == NULL
)
954 stats
->ls_biggest_alloc_num
= 1;
955 } else if ((flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0) {
956 /* alloc all percpu data, currently only obd_memory use this */
957 for (i
= 0; i
< num_entry
; ++i
)
958 if (lprocfs_stats_alloc_one(stats
, i
) < 0)
965 lprocfs_free_stats(&stats
);
968 EXPORT_SYMBOL(lprocfs_alloc_stats
);
970 void lprocfs_free_stats(struct lprocfs_stats
**statsh
)
972 struct lprocfs_stats
*stats
= *statsh
;
973 unsigned int num_entry
;
974 unsigned int percpusize
;
977 if (stats
== NULL
|| stats
->ls_num
== 0)
981 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
)
984 num_entry
= num_possible_cpus();
986 percpusize
= lprocfs_stats_counter_size(stats
);
987 for (i
= 0; i
< num_entry
; i
++)
988 if (stats
->ls_percpu
[i
] != NULL
)
989 LIBCFS_FREE(stats
->ls_percpu
[i
], percpusize
);
990 if (stats
->ls_cnt_header
!= NULL
)
991 LIBCFS_FREE(stats
->ls_cnt_header
, stats
->ls_num
*
992 sizeof(struct lprocfs_counter_header
));
993 LIBCFS_FREE(stats
, offsetof(typeof(*stats
), ls_percpu
[num_entry
]));
995 EXPORT_SYMBOL(lprocfs_free_stats
);
997 void lprocfs_clear_stats(struct lprocfs_stats
*stats
)
999 struct lprocfs_counter
*percpu_cntr
;
1000 struct lprocfs_counter_header
*header
;
1003 unsigned int num_entry
;
1004 unsigned long flags
= 0;
1006 num_entry
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1008 for (i
= 0; i
< num_entry
; i
++) {
1009 if (stats
->ls_percpu
[i
] == NULL
)
1011 for (j
= 0; j
< stats
->ls_num
; j
++) {
1012 header
= &stats
->ls_cnt_header
[j
];
1013 percpu_cntr
= lprocfs_stats_counter_get(stats
, i
, j
);
1014 percpu_cntr
->lc_count
= 0;
1015 percpu_cntr
->lc_min
= LC_MIN_INIT
;
1016 percpu_cntr
->lc_max
= 0;
1017 percpu_cntr
->lc_sumsquare
= 0;
1018 percpu_cntr
->lc_sum
= 0;
1019 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
1020 percpu_cntr
->lc_sum_irq
= 0;
1024 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1026 EXPORT_SYMBOL(lprocfs_clear_stats
);
1028 static ssize_t
lprocfs_stats_seq_write(struct file
*file
,
1029 const char __user
*buf
,
1030 size_t len
, loff_t
*off
)
1032 struct seq_file
*seq
= file
->private_data
;
1033 struct lprocfs_stats
*stats
= seq
->private;
1035 lprocfs_clear_stats(stats
);
1040 static void *lprocfs_stats_seq_start(struct seq_file
*p
, loff_t
*pos
)
1042 struct lprocfs_stats
*stats
= p
->private;
1044 return (*pos
< stats
->ls_num
) ? pos
: NULL
;
1047 static void lprocfs_stats_seq_stop(struct seq_file
*p
, void *v
)
1051 static void *lprocfs_stats_seq_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
1054 return lprocfs_stats_seq_start(p
, pos
);
1057 /* seq file export of one lprocfs counter */
1058 static int lprocfs_stats_seq_show(struct seq_file
*p
, void *v
)
1060 struct lprocfs_stats
*stats
= p
->private;
1061 struct lprocfs_counter_header
*hdr
;
1062 struct lprocfs_counter ctr
;
1063 int idx
= *(loff_t
*)v
;
1068 do_gettimeofday(&now
);
1069 rc
= seq_printf(p
, "%-25s %lu.%lu secs.usecs\n",
1070 "snapshot_time", now
.tv_sec
, now
.tv_usec
);
1074 hdr
= &stats
->ls_cnt_header
[idx
];
1075 lprocfs_stats_collect(stats
, idx
, &ctr
);
1077 if (ctr
.lc_count
== 0)
1080 rc
= seq_printf(p
, "%-25s "LPD64
" samples [%s]", hdr
->lc_name
,
1081 ctr
.lc_count
, hdr
->lc_units
);
1086 if ((hdr
->lc_config
& LPROCFS_CNTR_AVGMINMAX
) && (ctr
.lc_count
> 0)) {
1087 rc
= seq_printf(p
, " "LPD64
" "LPD64
" "LPD64
,
1088 ctr
.lc_min
, ctr
.lc_max
, ctr
.lc_sum
);
1091 if (hdr
->lc_config
& LPROCFS_CNTR_STDDEV
)
1092 rc
= seq_printf(p
, " "LPD64
, ctr
.lc_sumsquare
);
1096 rc
= seq_printf(p
, "\n");
1098 return (rc
< 0) ? rc
: 0;
1101 struct seq_operations lprocfs_stats_seq_sops
= {
1102 .start
= lprocfs_stats_seq_start
,
1103 .stop
= lprocfs_stats_seq_stop
,
1104 .next
= lprocfs_stats_seq_next
,
1105 .show
= lprocfs_stats_seq_show
,
1108 static int lprocfs_stats_seq_open(struct inode
*inode
, struct file
*file
)
1110 struct seq_file
*seq
;
1113 rc
= seq_open(file
, &lprocfs_stats_seq_sops
);
1116 seq
= file
->private_data
;
1117 seq
->private = PDE_DATA(inode
);
1121 struct file_operations lprocfs_stats_seq_fops
= {
1122 .owner
= THIS_MODULE
,
1123 .open
= lprocfs_stats_seq_open
,
1125 .write
= lprocfs_stats_seq_write
,
1126 .llseek
= seq_lseek
,
1127 .release
= lprocfs_seq_release
,
1130 int lprocfs_register_stats(struct proc_dir_entry
*root
, const char *name
,
1131 struct lprocfs_stats
*stats
)
1133 struct proc_dir_entry
*entry
;
1134 LASSERT(root
!= NULL
);
1136 entry
= proc_create_data(name
, 0644, root
,
1137 &lprocfs_stats_seq_fops
, stats
);
1143 EXPORT_SYMBOL(lprocfs_register_stats
);
1145 void lprocfs_counter_init(struct lprocfs_stats
*stats
, int index
,
1146 unsigned conf
, const char *name
, const char *units
)
1148 struct lprocfs_counter_header
*header
;
1149 struct lprocfs_counter
*percpu_cntr
;
1150 unsigned long flags
= 0;
1152 unsigned int num_cpu
;
1154 LASSERT(stats
!= NULL
);
1156 header
= &stats
->ls_cnt_header
[index
];
1157 LASSERTF(header
!= NULL
, "Failed to allocate stats header:[%d]%s/%s\n",
1158 index
, name
, units
);
1160 header
->lc_config
= conf
;
1161 header
->lc_name
= name
;
1162 header
->lc_units
= units
;
1164 num_cpu
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1165 for (i
= 0; i
< num_cpu
; ++i
) {
1166 if (stats
->ls_percpu
[i
] == NULL
)
1168 percpu_cntr
= lprocfs_stats_counter_get(stats
, i
, index
);
1169 percpu_cntr
->lc_count
= 0;
1170 percpu_cntr
->lc_min
= LC_MIN_INIT
;
1171 percpu_cntr
->lc_max
= 0;
1172 percpu_cntr
->lc_sumsquare
= 0;
1173 percpu_cntr
->lc_sum
= 0;
1174 if ((stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0)
1175 percpu_cntr
->lc_sum_irq
= 0;
1177 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
1179 EXPORT_SYMBOL(lprocfs_counter_init
);
1181 #define LPROCFS_OBD_OP_INIT(base, stats, op) \
1183 unsigned int coffset = base + OBD_COUNTER_OFFSET(op); \
1184 LASSERT(coffset < stats->ls_num); \
1185 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1188 void lprocfs_init_ops_stats(int num_private_stats
, struct lprocfs_stats
*stats
)
1190 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, iocontrol
);
1191 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, get_info
);
1192 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, set_info_async
);
1193 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, attach
);
1194 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, detach
);
1195 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, setup
);
1196 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, precleanup
);
1197 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, cleanup
);
1198 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, process_config
);
1199 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, postrecov
);
1200 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, add_conn
);
1201 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, del_conn
);
1202 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, connect
);
1203 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, reconnect
);
1204 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, disconnect
);
1205 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, fid_init
);
1206 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, fid_fini
);
1207 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, fid_alloc
);
1208 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, statfs
);
1209 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, statfs_async
);
1210 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, packmd
);
1211 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, unpackmd
);
1212 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, preallocate
);
1213 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, precreate
);
1214 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, create
);
1215 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, create_async
);
1216 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, destroy
);
1217 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, setattr
);
1218 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, setattr_async
);
1219 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, getattr
);
1220 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, getattr_async
);
1221 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, brw
);
1222 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, merge_lvb
);
1223 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, adjust_kms
);
1224 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, punch
);
1225 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, sync
);
1226 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, migrate
);
1227 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, copy
);
1228 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, iterate
);
1229 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, preprw
);
1230 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, commitrw
);
1231 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, enqueue
);
1232 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, change_cbdata
);
1233 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, find_cbdata
);
1234 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, cancel
);
1235 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, cancel_unused
);
1236 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, init_export
);
1237 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, destroy_export
);
1238 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, extent_calc
);
1239 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, llog_init
);
1240 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, llog_connect
);
1241 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, llog_finish
);
1242 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pin
);
1243 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, unpin
);
1244 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, import_event
);
1245 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, notify
);
1246 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, health_check
);
1247 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, get_uuid
);
1248 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, quotacheck
);
1249 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, quotactl
);
1250 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, ping
);
1251 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_new
);
1252 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_rem
);
1253 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_add
);
1254 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, pool_del
);
1255 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, getref
);
1256 LPROCFS_OBD_OP_INIT(num_private_stats
, stats
, putref
);
1258 EXPORT_SYMBOL(lprocfs_init_ops_stats
);
1260 int lprocfs_alloc_obd_stats(struct obd_device
*obd
, unsigned num_private_stats
)
1262 struct lprocfs_stats
*stats
;
1263 unsigned int num_stats
;
1266 LASSERT(obd
->obd_stats
== NULL
);
1267 LASSERT(obd
->obd_proc_entry
!= NULL
);
1268 LASSERT(obd
->obd_cntr_base
== 0);
1270 num_stats
= ((int)sizeof(*obd
->obd_type
->typ_dt_ops
) / sizeof(void *)) +
1271 num_private_stats
- 1 /* o_owner */;
1272 stats
= lprocfs_alloc_stats(num_stats
, 0);
1276 lprocfs_init_ops_stats(num_private_stats
, stats
);
1278 for (i
= num_private_stats
; i
< num_stats
; i
++) {
1279 /* If this LBUGs, it is likely that an obd
1280 * operation was added to struct obd_ops in
1281 * <obd.h>, and that the corresponding line item
1282 * LPROCFS_OBD_OP_INIT(.., .., opname)
1283 * is missing from the list above. */
1284 LASSERTF(stats
->ls_cnt_header
[i
].lc_name
!= NULL
,
1285 "Missing obd_stat initializer obd_op "
1286 "operation at offset %d.\n", i
- num_private_stats
);
1288 rc
= lprocfs_register_stats(obd
->obd_proc_entry
, "stats", stats
);
1290 lprocfs_free_stats(&stats
);
1292 obd
->obd_stats
= stats
;
1293 obd
->obd_cntr_base
= num_private_stats
;
1297 EXPORT_SYMBOL(lprocfs_alloc_obd_stats
);
1299 void lprocfs_free_obd_stats(struct obd_device
*obd
)
1302 lprocfs_free_stats(&obd
->obd_stats
);
1304 EXPORT_SYMBOL(lprocfs_free_obd_stats
);
1306 #define LPROCFS_MD_OP_INIT(base, stats, op) \
1308 unsigned int coffset = base + MD_COUNTER_OFFSET(op); \
1309 LASSERT(coffset < stats->ls_num); \
1310 lprocfs_counter_init(stats, coffset, 0, #op, "reqs"); \
1313 void lprocfs_init_mps_stats(int num_private_stats
, struct lprocfs_stats
*stats
)
1315 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getstatus
);
1316 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, null_inode
);
1317 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, find_cbdata
);
1318 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, close
);
1319 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, create
);
1320 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, done_writing
);
1321 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, enqueue
);
1322 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getattr
);
1323 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getattr_name
);
1324 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, intent_lock
);
1325 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, link
);
1326 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, rename
);
1327 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, is_subdir
);
1328 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, setattr
);
1329 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, sync
);
1330 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, readpage
);
1331 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, unlink
);
1332 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, setxattr
);
1333 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, getxattr
);
1334 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, init_ea_size
);
1335 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, get_lustre_md
);
1336 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, free_lustre_md
);
1337 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, set_open_replay_data
);
1338 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, clear_open_replay_data
);
1339 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, set_lock_data
);
1340 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, lock_match
);
1341 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, cancel_unused
);
1342 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, renew_capa
);
1343 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, unpack_capa
);
1344 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, get_remote_perm
);
1345 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, intent_getattr_async
);
1346 LPROCFS_MD_OP_INIT(num_private_stats
, stats
, revalidate_lock
);
1348 EXPORT_SYMBOL(lprocfs_init_mps_stats
);
1350 int lprocfs_alloc_md_stats(struct obd_device
*obd
,
1351 unsigned num_private_stats
)
1353 struct lprocfs_stats
*stats
;
1354 unsigned int num_stats
;
1357 LASSERT(obd
->md_stats
== NULL
);
1358 LASSERT(obd
->obd_proc_entry
!= NULL
);
1359 LASSERT(obd
->md_cntr_base
== 0);
1361 num_stats
= 1 + MD_COUNTER_OFFSET(revalidate_lock
) +
1363 stats
= lprocfs_alloc_stats(num_stats
, 0);
1367 lprocfs_init_mps_stats(num_private_stats
, stats
);
1369 for (i
= num_private_stats
; i
< num_stats
; i
++) {
1370 if (stats
->ls_cnt_header
[i
].lc_name
== NULL
) {
1371 CERROR("Missing md_stat initializer md_op "
1372 "operation at offset %d. Aborting.\n",
1373 i
- num_private_stats
);
1377 rc
= lprocfs_register_stats(obd
->obd_proc_entry
, "md_stats", stats
);
1379 lprocfs_free_stats(&stats
);
1381 obd
->md_stats
= stats
;
1382 obd
->md_cntr_base
= num_private_stats
;
1386 EXPORT_SYMBOL(lprocfs_alloc_md_stats
);
1388 void lprocfs_free_md_stats(struct obd_device
*obd
)
1390 struct lprocfs_stats
*stats
= obd
->md_stats
;
1392 if (stats
!= NULL
) {
1393 obd
->md_stats
= NULL
;
1394 obd
->md_cntr_base
= 0;
1395 lprocfs_free_stats(&stats
);
1398 EXPORT_SYMBOL(lprocfs_free_md_stats
);
1400 void lprocfs_init_ldlm_stats(struct lprocfs_stats
*ldlm_stats
)
1402 lprocfs_counter_init(ldlm_stats
,
1403 LDLM_ENQUEUE
- LDLM_FIRST_OPC
,
1404 0, "ldlm_enqueue", "reqs");
1405 lprocfs_counter_init(ldlm_stats
,
1406 LDLM_CONVERT
- LDLM_FIRST_OPC
,
1407 0, "ldlm_convert", "reqs");
1408 lprocfs_counter_init(ldlm_stats
,
1409 LDLM_CANCEL
- LDLM_FIRST_OPC
,
1410 0, "ldlm_cancel", "reqs");
1411 lprocfs_counter_init(ldlm_stats
,
1412 LDLM_BL_CALLBACK
- LDLM_FIRST_OPC
,
1413 0, "ldlm_bl_callback", "reqs");
1414 lprocfs_counter_init(ldlm_stats
,
1415 LDLM_CP_CALLBACK
- LDLM_FIRST_OPC
,
1416 0, "ldlm_cp_callback", "reqs");
1417 lprocfs_counter_init(ldlm_stats
,
1418 LDLM_GL_CALLBACK
- LDLM_FIRST_OPC
,
1419 0, "ldlm_gl_callback", "reqs");
1421 EXPORT_SYMBOL(lprocfs_init_ldlm_stats
);
1423 int lprocfs_exp_print_uuid(cfs_hash_t
*hs
, cfs_hash_bd_t
*bd
,
1424 struct hlist_node
*hnode
, void *data
)
1427 struct obd_export
*exp
= cfs_hash_object(hs
, hnode
);
1428 struct seq_file
*m
= (struct seq_file
*)data
;
1430 if (exp
->exp_nid_stats
)
1431 seq_printf(m
, "%s\n", obd_uuid2str(&exp
->exp_client_uuid
));
1437 lproc_exp_uuid_seq_show(struct seq_file
*m
, void *unused
)
1439 struct nid_stat
*stats
= (struct nid_stat
*)m
->private;
1440 struct obd_device
*obd
= stats
->nid_obd
;
1442 cfs_hash_for_each_key(obd
->obd_nid_hash
, &stats
->nid
,
1443 lprocfs_exp_print_uuid
, m
);
1447 LPROC_SEQ_FOPS_RO(lproc_exp_uuid
);
1449 struct exp_hash_cb_data
{
1454 int lprocfs_exp_print_hash(cfs_hash_t
*hs
, cfs_hash_bd_t
*bd
,
1455 struct hlist_node
*hnode
, void *cb_data
)
1458 struct exp_hash_cb_data
*data
= (struct exp_hash_cb_data
*)cb_data
;
1459 struct obd_export
*exp
= cfs_hash_object(hs
, hnode
);
1461 if (exp
->exp_lock_hash
!= NULL
) {
1463 cfs_hash_debug_header(data
->m
);
1464 data
->first
= false;
1466 cfs_hash_debug_str(hs
, data
->m
);
1473 lproc_exp_hash_seq_show(struct seq_file
*m
, void *unused
)
1475 struct nid_stat
*stats
= (struct nid_stat
*)m
->private;
1476 struct obd_device
*obd
= stats
->nid_obd
;
1477 struct exp_hash_cb_data cb_data
= {m
, true};
1479 cfs_hash_for_each_key(obd
->obd_nid_hash
, &stats
->nid
,
1480 lprocfs_exp_print_hash
, &cb_data
);
1484 LPROC_SEQ_FOPS_RO(lproc_exp_hash
);
1486 int lprocfs_nid_stats_clear_read(struct seq_file
*m
, void *data
)
1488 return seq_printf(m
, "%s\n",
1489 "Write into this file to clear all nid stats and "
1490 "stale nid entries");
1492 EXPORT_SYMBOL(lprocfs_nid_stats_clear_read
);
1494 static int lprocfs_nid_stats_clear_write_cb(void *obj
, void *data
)
1496 struct nid_stat
*stat
= obj
;
1499 CDEBUG(D_INFO
,"refcnt %d\n", atomic_read(&stat
->nid_exp_ref_count
));
1500 if (atomic_read(&stat
->nid_exp_ref_count
) == 1) {
1501 /* object has only hash references. */
1502 spin_lock(&stat
->nid_obd
->obd_nid_lock
);
1503 list_move(&stat
->nid_list
, data
);
1504 spin_unlock(&stat
->nid_obd
->obd_nid_lock
);
1507 /* we has reference to object - only clear data*/
1508 if (stat
->nid_stats
)
1509 lprocfs_clear_stats(stat
->nid_stats
);
1514 int lprocfs_nid_stats_clear_write(struct file
*file
, const char *buffer
,
1515 unsigned long count
, void *data
)
1517 struct obd_device
*obd
= (struct obd_device
*)data
;
1518 struct nid_stat
*client_stat
;
1519 LIST_HEAD(free_list
);
1521 cfs_hash_cond_del(obd
->obd_nid_stats_hash
,
1522 lprocfs_nid_stats_clear_write_cb
, &free_list
);
1524 while (!list_empty(&free_list
)) {
1525 client_stat
= list_entry(free_list
.next
, struct nid_stat
,
1527 list_del_init(&client_stat
->nid_list
);
1528 lprocfs_free_client_stats(client_stat
);
1533 EXPORT_SYMBOL(lprocfs_nid_stats_clear_write
);
1535 int lprocfs_exp_setup(struct obd_export
*exp
, lnet_nid_t
*nid
, int *newnid
)
1537 struct nid_stat
*new_stat
, *old_stat
;
1538 struct obd_device
*obd
= NULL
;
1539 proc_dir_entry_t
*entry
;
1540 char *buffer
= NULL
;
1546 if (!exp
|| !exp
->exp_obd
|| !exp
->exp_obd
->obd_proc_exports_entry
||
1547 !exp
->exp_obd
->obd_nid_stats_hash
)
1550 /* not test against zero because eric say:
1551 * You may only test nid against another nid, or LNET_NID_ANY.
1552 * Anything else is nonsense.*/
1553 if (!nid
|| *nid
== LNET_NID_ANY
)
1558 CDEBUG(D_CONFIG
, "using hash %p\n", obd
->obd_nid_stats_hash
);
1560 OBD_ALLOC_PTR(new_stat
);
1561 if (new_stat
== NULL
)
1564 new_stat
->nid
= *nid
;
1565 new_stat
->nid_obd
= exp
->exp_obd
;
1566 /* we need set default refcount to 1 to balance obd_disconnect */
1567 atomic_set(&new_stat
->nid_exp_ref_count
, 1);
1569 old_stat
= cfs_hash_findadd_unique(obd
->obd_nid_stats_hash
,
1570 nid
, &new_stat
->nid_hash
);
1571 CDEBUG(D_INFO
, "Found stats %p for nid %s - ref %d\n",
1572 old_stat
, libcfs_nid2str(*nid
),
1573 atomic_read(&new_stat
->nid_exp_ref_count
));
1575 /* We need to release old stats because lprocfs_exp_cleanup() hasn't
1576 * been and will never be called. */
1577 if (exp
->exp_nid_stats
) {
1578 nidstat_putref(exp
->exp_nid_stats
);
1579 exp
->exp_nid_stats
= NULL
;
1582 /* Return -EALREADY here so that we know that the /proc
1583 * entry already has been created */
1584 if (old_stat
!= new_stat
) {
1585 exp
->exp_nid_stats
= old_stat
;
1586 GOTO(destroy_new
, rc
= -EALREADY
);
1588 /* not found - create */
1589 OBD_ALLOC(buffer
, LNET_NIDSTR_SIZE
);
1591 GOTO(destroy_new
, rc
= -ENOMEM
);
1593 memcpy(buffer
, libcfs_nid2str(*nid
), LNET_NIDSTR_SIZE
);
1594 new_stat
->nid_proc
= lprocfs_register(buffer
,
1595 obd
->obd_proc_exports_entry
,
1597 OBD_FREE(buffer
, LNET_NIDSTR_SIZE
);
1599 if (new_stat
->nid_proc
== NULL
) {
1600 CERROR("Error making export directory for nid %s\n",
1601 libcfs_nid2str(*nid
));
1602 GOTO(destroy_new_ns
, rc
= -ENOMEM
);
1605 entry
= lprocfs_add_simple(new_stat
->nid_proc
, "uuid",
1606 new_stat
, &lproc_exp_uuid_fops
);
1607 if (IS_ERR(entry
)) {
1608 CWARN("Error adding the NID stats file\n");
1609 rc
= PTR_ERR(entry
);
1610 GOTO(destroy_new_ns
, rc
);
1613 entry
= lprocfs_add_simple(new_stat
->nid_proc
, "hash",
1614 new_stat
, &lproc_exp_hash_fops
);
1615 if (IS_ERR(entry
)) {
1616 CWARN("Error adding the hash file\n");
1617 rc
= PTR_ERR(entry
);
1618 GOTO(destroy_new_ns
, rc
);
1621 exp
->exp_nid_stats
= new_stat
;
1623 /* protect competitive add to list, not need locking on destroy */
1624 spin_lock(&obd
->obd_nid_lock
);
1625 list_add(&new_stat
->nid_list
, &obd
->obd_nid_stats
);
1626 spin_unlock(&obd
->obd_nid_lock
);
1631 if (new_stat
->nid_proc
!= NULL
)
1632 lprocfs_remove(&new_stat
->nid_proc
);
1633 cfs_hash_del(obd
->obd_nid_stats_hash
, nid
, &new_stat
->nid_hash
);
1636 nidstat_putref(new_stat
);
1637 OBD_FREE_PTR(new_stat
);
1640 EXPORT_SYMBOL(lprocfs_exp_setup
);
1642 int lprocfs_exp_cleanup(struct obd_export
*exp
)
1644 struct nid_stat
*stat
= exp
->exp_nid_stats
;
1646 if(!stat
|| !exp
->exp_obd
)
1649 nidstat_putref(exp
->exp_nid_stats
);
1650 exp
->exp_nid_stats
= NULL
;
1654 EXPORT_SYMBOL(lprocfs_exp_cleanup
);
1656 int lprocfs_write_helper(const char *buffer
, unsigned long count
,
1659 return lprocfs_write_frac_helper(buffer
, count
, val
, 1);
1661 EXPORT_SYMBOL(lprocfs_write_helper
);
1663 int lprocfs_write_frac_helper(const char *buffer
, unsigned long count
,
1666 char kernbuf
[20], *end
, *pbuf
;
1668 if (count
> (sizeof(kernbuf
) - 1))
1671 if (copy_from_user(kernbuf
, buffer
, count
))
1674 kernbuf
[count
] = '\0';
1681 *val
= (int)simple_strtoul(pbuf
, &end
, 10) * mult
;
1685 if (end
!= NULL
&& *end
== '.') {
1686 int temp_val
, pow
= 1;
1690 if (strlen(pbuf
) > 5)
1691 pbuf
[5] = '\0'; /*only allow 5bits fractional*/
1693 temp_val
= (int)simple_strtoul(pbuf
, &end
, 10) * mult
;
1696 for (i
= 0; i
< (end
- pbuf
); i
++)
1699 *val
+= temp_val
/ pow
;
1704 EXPORT_SYMBOL(lprocfs_write_frac_helper
);
1706 int lprocfs_read_frac_helper(char *buffer
, unsigned long count
, long val
,
1709 long decimal_val
, frac_val
;
1715 decimal_val
= val
/ mult
;
1716 prtn
= snprintf(buffer
, count
, "%ld", decimal_val
);
1717 frac_val
= val
% mult
;
1719 if (prtn
< (count
- 4) && frac_val
> 0) {
1721 int i
, temp_mult
= 1, frac_bits
= 0;
1723 temp_frac
= frac_val
* 10;
1724 buffer
[prtn
++] = '.';
1725 while (frac_bits
< 2 && (temp_frac
/ mult
) < 1 ) {
1726 /* only reserved 2 bits fraction */
1727 buffer
[prtn
++] ='0';
1732 * Need to think these cases :
1733 * 1. #echo x.00 > /proc/xxx output result : x
1734 * 2. #echo x.0x > /proc/xxx output result : x.0x
1735 * 3. #echo x.x0 > /proc/xxx output result : x.x
1736 * 4. #echo x.xx > /proc/xxx output result : x.xx
1737 * Only reserved 2 bits fraction.
1739 for (i
= 0; i
< (5 - prtn
); i
++)
1742 frac_bits
= min((int)count
- prtn
, 3 - frac_bits
);
1743 prtn
+= snprintf(buffer
+ prtn
, frac_bits
, "%ld",
1744 frac_val
* temp_mult
/ mult
);
1747 while(buffer
[prtn
] < '1' || buffer
[prtn
] > '9') {
1749 if (buffer
[prtn
] == '.') {
1756 buffer
[prtn
++] ='\n';
1759 EXPORT_SYMBOL(lprocfs_read_frac_helper
);
1761 int lprocfs_seq_read_frac_helper(struct seq_file
*m
, long val
, int mult
)
1763 long decimal_val
, frac_val
;
1765 decimal_val
= val
/ mult
;
1766 seq_printf(m
, "%ld", decimal_val
);
1767 frac_val
= val
% mult
;
1774 /* Three cases: x0, xx, 0x */
1775 if ((frac_val
% 10) != 0)
1776 seq_printf(m
, ".%ld", frac_val
);
1778 seq_printf(m
, ".%ld", frac_val
/ 10);
1781 seq_printf(m
, "\n");
1784 EXPORT_SYMBOL(lprocfs_seq_read_frac_helper
);
1786 int lprocfs_write_u64_helper(const char *buffer
, unsigned long count
,__u64
*val
)
1788 return lprocfs_write_frac_u64_helper(buffer
, count
, val
, 1);
1790 EXPORT_SYMBOL(lprocfs_write_u64_helper
);
1792 int lprocfs_write_frac_u64_helper(const char *buffer
, unsigned long count
,
1793 __u64
*val
, int mult
)
1795 char kernbuf
[22], *end
, *pbuf
;
1796 __u64 whole
, frac
= 0, units
;
1797 unsigned frac_d
= 1;
1799 if (count
> (sizeof(kernbuf
) - 1))
1802 if (copy_from_user(kernbuf
, buffer
, count
))
1805 kernbuf
[count
] = '\0';
1812 whole
= simple_strtoull(pbuf
, &end
, 10);
1816 if (end
!= NULL
&& *end
== '.') {
1820 /* need to limit frac_d to a __u32 */
1821 if (strlen(pbuf
) > 10)
1824 frac
= simple_strtoull(pbuf
, &end
, 10);
1825 /* count decimal places */
1826 for (i
= 0; i
< (end
- pbuf
); i
++)
1843 /* Specified units override the multiplier */
1845 mult
= mult
< 0 ? -units
: units
;
1848 do_div(frac
, frac_d
);
1849 *val
= whole
* mult
+ frac
;
1852 EXPORT_SYMBOL(lprocfs_write_frac_u64_helper
);
1854 static char *lprocfs_strnstr(const char *s1
, const char *s2
, size_t len
)
1863 if (!memcmp(s1
, s2
, l2
))
1871 * Find the string \a name in the input \a buffer, and return a pointer to the
1872 * value immediately following \a name, reducing \a count appropriately.
1873 * If \a name is not found the original \a buffer is returned.
1875 char *lprocfs_find_named_value(const char *buffer
, const char *name
,
1876 unsigned long *count
)
1879 size_t buflen
= *count
;
1881 /* there is no strnstr() in rhel5 and ubuntu kernels */
1882 val
= lprocfs_strnstr(buffer
, name
, buflen
);
1884 return (char *)buffer
;
1886 val
+= strlen(name
); /* skip prefix */
1887 while (val
< buffer
+ buflen
&& isspace(*val
)) /* skip separator */
1891 while (val
< buffer
+ buflen
&& isalnum(*val
)) {
1896 return val
- *count
;
1898 EXPORT_SYMBOL(lprocfs_find_named_value
);
1900 int lprocfs_seq_create(proc_dir_entry_t
*parent
,
1903 const struct file_operations
*seq_fops
,
1906 struct proc_dir_entry
*entry
;
1909 /* Disallow secretly (un)writable entries. */
1910 LASSERT((seq_fops
->write
== NULL
) == ((mode
& 0222) == 0));
1911 entry
= proc_create_data(name
, mode
, parent
, seq_fops
, data
);
1918 EXPORT_SYMBOL(lprocfs_seq_create
);
1920 int lprocfs_obd_seq_create(struct obd_device
*dev
,
1923 const struct file_operations
*seq_fops
,
1926 return (lprocfs_seq_create(dev
->obd_proc_entry
, name
,
1927 mode
, seq_fops
, data
));
1929 EXPORT_SYMBOL(lprocfs_obd_seq_create
);
1931 void lprocfs_oh_tally(struct obd_histogram
*oh
, unsigned int value
)
1933 if (value
>= OBD_HIST_MAX
)
1934 value
= OBD_HIST_MAX
- 1;
1936 spin_lock(&oh
->oh_lock
);
1937 oh
->oh_buckets
[value
]++;
1938 spin_unlock(&oh
->oh_lock
);
1940 EXPORT_SYMBOL(lprocfs_oh_tally
);
1942 void lprocfs_oh_tally_log2(struct obd_histogram
*oh
, unsigned int value
)
1946 for (val
= 0; ((1 << val
) < value
) && (val
<= OBD_HIST_MAX
); val
++)
1949 lprocfs_oh_tally(oh
, val
);
1951 EXPORT_SYMBOL(lprocfs_oh_tally_log2
);
1953 unsigned long lprocfs_oh_sum(struct obd_histogram
*oh
)
1955 unsigned long ret
= 0;
1958 for (i
= 0; i
< OBD_HIST_MAX
; i
++)
1959 ret
+= oh
->oh_buckets
[i
];
1962 EXPORT_SYMBOL(lprocfs_oh_sum
);
1964 void lprocfs_oh_clear(struct obd_histogram
*oh
)
1966 spin_lock(&oh
->oh_lock
);
1967 memset(oh
->oh_buckets
, 0, sizeof(oh
->oh_buckets
));
1968 spin_unlock(&oh
->oh_lock
);
1970 EXPORT_SYMBOL(lprocfs_oh_clear
);
1972 int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file
*m
, void *data
)
1974 struct obd_device
*dev
= data
;
1975 struct client_obd
*cli
= &dev
->u
.cli
;
1978 client_obd_list_lock(&cli
->cl_loi_list_lock
);
1979 rc
= seq_printf(m
, "%d\n", cli
->cl_max_pages_per_rpc
);
1980 client_obd_list_unlock(&cli
->cl_loi_list_lock
);
1983 EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc
);