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 (c) 1994-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Methods of the cfsd_cache class.
39 #include <sys/utsname.h>
41 #include <mdbug/mdbug.h>
42 #include <sys/fs/cachefs_fs.h>
43 #include <sys/fs/cachefs_dlog.h>
44 #include <sys/fs/cachefs_ioctl.h>
46 #include "cfsd_kmod.h"
47 #include "cfsd_maptbl.h"
48 #include "cfsd_logfile.h"
49 #include "cfsd_fscache.h"
50 #include "cfsd_cache.h"
53 * -----------------------------------------------------------------
63 cfsd_cache_create(void)
65 cfsd_cache_object_t
*cache_object_p
;
68 dbug_enter("cfsd_cache_create");
70 cache_object_p
= cfsd_calloc(sizeof (cfsd_cache_object_t
));
71 strlcpy(cache_object_p
->i_cachedir
, gettext("unknown"),
72 sizeof (cache_object_p
->i_cachedir
));
73 cache_object_p
->i_refcnt
= 0;
74 cache_object_p
->i_nextfscacheid
= 0;
75 cache_object_p
->i_cacheid
= 0;
76 cache_object_p
->i_modify
= 1;
77 cache_object_p
->i_fscachelist
= NULL
;
78 cache_object_p
->i_fscachecount
= 0;
80 /* initialize the locking mutex */
81 xx
= mutex_init(&cache_object_p
->i_lock
, USYNC_THREAD
, NULL
);
84 dbug_leave("cfsd_cache_create");
85 return (cache_object_p
);
89 * -----------------------------------------------------------------
100 cfsd_cache_destroy(cfsd_cache_object_t
*cache_object_p
)
103 cfsd_fscache_object_t
*fscache_object_p
;
104 cfsd_fscache_object_t
*tmp_fscache_object_p
;
107 dbug_enter("cfsd_cache_destroy");
109 /* get rid of any fscache objects */
110 fscache_object_p
= cache_object_p
->i_fscachelist
;
112 while (fscache_object_p
!= NULL
) {
113 tmp_fscache_object_p
= fscache_object_p
->i_next
;
114 cfsd_fscache_destroy(fscache_object_p
);
115 fscache_object_p
= tmp_fscache_object_p
;
118 /* destroy the locking mutex */
119 xx
= mutex_destroy(&cache_object_p
->i_lock
);
120 dbug_assert(xx
== 0);
121 cfsd_free(cache_object_p
);
122 dbug_leave("cfsd_cache_destroy");
126 * -----------------------------------------------------------------
130 * Performs setup for the cache.
140 cache_setup(cfsd_cache_object_t
*cache_object_p
, const char *cachedirp
,
144 /* XXX either need to prevent multiple calls to this or */
149 dbug_enter("cache_setup");
151 if ((stat64(cachedirp
, &sinfo
) == -1) ||
152 (!S_ISDIR(sinfo
.st_mode
)) ||
153 (*cachedirp
!= '/')) {
154 dbug_print(("info", "%s is not a cache directory", cachedirp
));
157 strlcpy(cache_object_p
->i_cachedir
, cachedirp
,
158 sizeof (cache_object_p
->i_cachedir
));
162 cache_object_p
->i_cacheid
= cacheid
;
163 cache_object_p
->i_modify
++;
165 dbug_leave("cache_setup");
170 * -----------------------------------------------------------------
180 cache_lock(cfsd_cache_object_t
*cache_object_p
)
182 dbug_enter("cache_lock");
184 mutex_lock(&cache_object_p
->i_lock
);
185 dbug_leave("cache_lock");
189 * -----------------------------------------------------------------
199 cache_unlock(cfsd_cache_object_t
*cache_object_p
)
201 dbug_enter("cache_unlock");
203 mutex_unlock(&cache_object_p
->i_lock
);
204 dbug_leave("cache_unlock");
207 * -----------------------------------------------------------------
208 * cache_fscachelist_at
218 cfsd_fscache_object_t
*
219 cache_fscachelist_at(cfsd_cache_object_t
*cache_object_p
, size_t index
)
221 cfsd_fscache_object_t
*fscache_object_p
;
224 dbug_enter("cache_fscachelist_at");
226 /* find the correct cache object */
227 fscache_object_p
= cache_object_p
->i_fscachelist
;
229 while ((fscache_object_p
!= NULL
) && (i
++ < index
)) {
230 fscache_object_p
= fscache_object_p
->i_next
;
233 dbug_leave("cache_fscachelist_at");
234 return (fscache_object_p
);
238 * -----------------------------------------------------------------
239 * cache_fscachelist_add
250 cache_fscachelist_add(cfsd_cache_object_t
*cache_object_p
,
251 cfsd_fscache_object_t
*fscache_object_p
)
253 dbug_enter("cache_fscachelist_add");
255 dbug_precond(fscache_object_p
);
257 fscache_object_p
->i_next
= cache_object_p
->i_fscachelist
;
258 cache_object_p
->i_fscachelist
= fscache_object_p
;
259 cache_object_p
->i_modify
++;
260 cache_object_p
->i_fscachecount
++;
261 dbug_leave("cache_fscachelist_add");
265 * -----------------------------------------------------------------
266 * cache_fscachelist_find
277 cfsd_fscache_object_t
*
278 cache_fscachelist_find(cfsd_cache_object_t
*cache_object_p
,
281 cfsd_fscache_object_t
*fscache_object_p
;
283 dbug_enter("cache_fscachelist_find");
287 /* see if the fscache exists */
288 fscache_object_p
= cache_object_p
->i_fscachelist
;
290 while ((fscache_object_p
!= NULL
) &&
291 strcmp(namep
, fscache_object_p
->i_name
)) {
292 fscache_object_p
= fscache_object_p
->i_next
;
295 dbug_leave("cache_fscachelist_find");
296 return (fscache_object_p
);