6253 F_GETLK doesn't always return lock owner
[illumos-gate.git] / usr / src / cmd / fs.d / cachefs / common / stats_stats.c
blobc1b3fe4cdfad7a150e643ba86ee818f5fc480c50
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 * stats_stats.c
33 * Routines for the `clean interface' to cachefs statistics.
36 #include <libintl.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <assert.h>
40 #include <sys/fs/cachefs_fs.h>
41 #include "stats.h"
43 static kstat_t *
44 stats_read_stat(stats_cookie_t *st)
46 kstat_t *stat;
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"),
56 st->st_fsid);
57 goto out;
59 out:
60 return (stat);
63 u_int
64 stats_hits(stats_cookie_t *st)
66 kstat_t *ks;
67 cachefs_stats_t *stats;
68 u_int rc = 0;
70 if ((ks = stats_read_stat(st)) != NULL) {
71 stats = (cachefs_stats_t *) ks->ks_data;
72 rc = stats->st_hits;
73 } else {
74 stats_perror(st, SE_KERNEL,
75 gettext("Cannot read statistics"));
78 return (rc);
81 u_int
82 stats_misses(stats_cookie_t *st)
84 kstat_t *ks;
85 cachefs_stats_t *stats;
86 u_int rc = 0;
88 if ((ks = stats_read_stat(st)) != NULL) {
89 stats = (cachefs_stats_t *) ks->ks_data;
90 rc = stats->st_misses;
91 } else {
92 stats_perror(st, SE_KERNEL,
93 gettext("Cannot read statistics"));
96 return (rc);
99 u_int
100 stats_passes(stats_cookie_t *st)
102 kstat_t *ks;
103 cachefs_stats_t *stats;
104 u_int rc = 0;
106 if ((ks = stats_read_stat(st)) != NULL) {
107 stats = (cachefs_stats_t *) ks->ks_data;
108 rc = stats->st_passes;
109 } else {
110 stats_perror(st, SE_KERNEL,
111 gettext("Cannot read statistics"));
114 return (rc);
117 u_int
118 stats_fails(stats_cookie_t *st)
120 kstat_t *ks;
121 cachefs_stats_t *stats;
122 u_int rc = 0;
124 if ((ks = stats_read_stat(st)) != NULL) {
125 stats = (cachefs_stats_t *) ks->ks_data;
126 rc = stats->st_fails;
127 } else {
128 stats_perror(st, SE_KERNEL,
129 gettext("Cannot read statistics"));
132 return (rc);
135 u_int
136 stats_modifies(stats_cookie_t *st)
138 kstat_t *ks;
139 cachefs_stats_t *stats;
140 u_int rc = 0;
142 if ((ks = stats_read_stat(st)) != NULL) {
143 stats = (cachefs_stats_t *) ks->ks_data;
144 rc = stats->st_modifies;
145 } else {
146 stats_perror(st, SE_KERNEL,
147 gettext("Cannot read statistics"));
150 return (rc);
153 u_int
154 stats_gc_count(stats_cookie_t *st)
156 kstat_t *ks;
157 cachefs_stats_t *stats;
158 u_int rc = 0;
160 if ((ks = stats_read_stat(st)) != NULL) {
161 stats = (cachefs_stats_t *) ks->ks_data;
162 rc = stats->st_gc_count;
163 } else {
164 stats_perror(st, SE_KERNEL,
165 gettext("Cannot read statistics"));
168 return (rc);
171 time_t
172 stats_gc_time(stats_cookie_t *st)
174 kstat_t *ks;
175 cachefs_stats_t *stats;
176 time_t rc = 0;
178 if ((ks = stats_read_stat(st)) != NULL) {
179 stats = (cachefs_stats_t *) ks->ks_data;
180 rc = stats->st_gc_time;
181 } else {
182 stats_perror(st, SE_KERNEL,
183 gettext("Cannot read statistics"));
186 return (rc);
189 time_t
190 stats_gc_before(stats_cookie_t *st)
192 kstat_t *ks;
193 cachefs_stats_t *stats;
194 time_t rc = 0;
196 if ((ks = stats_read_stat(st)) != NULL) {
197 stats = (cachefs_stats_t *) ks->ks_data;
198 rc = stats->st_gc_before_atime;
199 } else {
200 stats_perror(st, SE_KERNEL,
201 gettext("Cannot read statistics"));
204 return (rc);
207 time_t
208 stats_gc_after(stats_cookie_t *st)
210 kstat_t *ks;
211 cachefs_stats_t *stats;
212 time_t rc = 0;
214 if ((ks = stats_read_stat(st)) != NULL) {
215 stats = (cachefs_stats_t *) ks->ks_data;
216 rc = stats->st_gc_after_atime;
217 } else {
218 stats_perror(st, SE_KERNEL,
219 gettext("Cannot read statistics"));
222 return (rc);
226 stats_zero_stats(stats_cookie_t *st)
228 cachefs_stats_t stats;
229 kstat_t *ks;
230 int rc = 0;
231 void *memset();
233 assert(stats_good(st));
234 assert(st->st_flags & ST_BOUND);
236 if ((ks = stats_read_stat(st)) == NULL) {
237 rc = -1;
238 goto out;
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"));
247 rc = -1;
248 goto out;
251 out:
252 return (rc);