4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 * Routines for the `clean interface' to cachefs statistics.
37 #include <sys/types.h>
40 #include <sys/fs/cachefs_fs.h>
44 stats_read_stat(stats_cookie_t
*st
)
48 assert(stats_good(st
));
49 assert(st
->st_flags
& ST_BOUND
);
51 if (((stat
= kstat_lookup(st
->st_kstat_cookie
,
52 "cachefs", st
->st_fsid
, "stats")) == NULL
) ||
53 (kstat_read(st
->st_kstat_cookie
, stat
, NULL
) < 0)) {
54 stats_perror(st
, SE_KERNEL
,
55 gettext("Cannot lookup statistics"),
64 stats_hits(stats_cookie_t
*st
)
67 cachefs_stats_t
*stats
;
70 if ((ks
= stats_read_stat(st
)) != NULL
) {
71 stats
= (cachefs_stats_t
*) ks
->ks_data
;
74 stats_perror(st
, SE_KERNEL
,
75 gettext("Cannot read statistics"));
82 stats_misses(stats_cookie_t
*st
)
85 cachefs_stats_t
*stats
;
88 if ((ks
= stats_read_stat(st
)) != NULL
) {
89 stats
= (cachefs_stats_t
*) ks
->ks_data
;
90 rc
= stats
->st_misses
;
92 stats_perror(st
, SE_KERNEL
,
93 gettext("Cannot read statistics"));
100 stats_passes(stats_cookie_t
*st
)
103 cachefs_stats_t
*stats
;
106 if ((ks
= stats_read_stat(st
)) != NULL
) {
107 stats
= (cachefs_stats_t
*) ks
->ks_data
;
108 rc
= stats
->st_passes
;
110 stats_perror(st
, SE_KERNEL
,
111 gettext("Cannot read statistics"));
118 stats_fails(stats_cookie_t
*st
)
121 cachefs_stats_t
*stats
;
124 if ((ks
= stats_read_stat(st
)) != NULL
) {
125 stats
= (cachefs_stats_t
*) ks
->ks_data
;
126 rc
= stats
->st_fails
;
128 stats_perror(st
, SE_KERNEL
,
129 gettext("Cannot read statistics"));
136 stats_modifies(stats_cookie_t
*st
)
139 cachefs_stats_t
*stats
;
142 if ((ks
= stats_read_stat(st
)) != NULL
) {
143 stats
= (cachefs_stats_t
*) ks
->ks_data
;
144 rc
= stats
->st_modifies
;
146 stats_perror(st
, SE_KERNEL
,
147 gettext("Cannot read statistics"));
154 stats_gc_count(stats_cookie_t
*st
)
157 cachefs_stats_t
*stats
;
160 if ((ks
= stats_read_stat(st
)) != NULL
) {
161 stats
= (cachefs_stats_t
*) ks
->ks_data
;
162 rc
= stats
->st_gc_count
;
164 stats_perror(st
, SE_KERNEL
,
165 gettext("Cannot read statistics"));
172 stats_gc_time(stats_cookie_t
*st
)
175 cachefs_stats_t
*stats
;
178 if ((ks
= stats_read_stat(st
)) != NULL
) {
179 stats
= (cachefs_stats_t
*) ks
->ks_data
;
180 rc
= stats
->st_gc_time
;
182 stats_perror(st
, SE_KERNEL
,
183 gettext("Cannot read statistics"));
190 stats_gc_before(stats_cookie_t
*st
)
193 cachefs_stats_t
*stats
;
196 if ((ks
= stats_read_stat(st
)) != NULL
) {
197 stats
= (cachefs_stats_t
*) ks
->ks_data
;
198 rc
= stats
->st_gc_before_atime
;
200 stats_perror(st
, SE_KERNEL
,
201 gettext("Cannot read statistics"));
208 stats_gc_after(stats_cookie_t
*st
)
211 cachefs_stats_t
*stats
;
214 if ((ks
= stats_read_stat(st
)) != NULL
) {
215 stats
= (cachefs_stats_t
*) ks
->ks_data
;
216 rc
= stats
->st_gc_after_atime
;
218 stats_perror(st
, SE_KERNEL
,
219 gettext("Cannot read statistics"));
226 stats_zero_stats(stats_cookie_t
*st
)
228 cachefs_stats_t stats
;
233 assert(stats_good(st
));
234 assert(st
->st_flags
& ST_BOUND
);
236 if ((ks
= stats_read_stat(st
)) == NULL
) {
241 memset(&stats
, '\0', sizeof (stats
));
242 ks
->ks_data
= &stats
;
244 if (kstat_write(st
->st_kstat_cookie
, ks
, NULL
) < 0) {
245 stats_perror(st
, SE_KERNEL
,
246 gettext("Cannot zero statistics"));