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 for the cfsd_all class.
40 #include <sys/utsname.h>
41 #include <sys/param.h>
42 #include <sys/mnttab.h>
43 #include <sys/vfstab.h>
44 #include <mdbug/mdbug.h>
45 #include <sys/fs/cachefs_fs.h>
46 #include <sys/fs/cachefs_dlog.h>
47 #include <sys/fs/cachefs_ioctl.h>
49 #include "cfsd_kmod.h"
50 #include "cfsd_maptbl.h"
51 #include "cfsd_logfile.h"
52 #include "cfsd_fscache.h"
53 #include "cfsd_cache.h"
57 * ------------------------------------------------------------
69 /* get the host name */
71 cfsd_all_object_t
*all_object_p
;
73 char buffer
[MAXPATHLEN
];
75 dbug_enter("cfsd_all_create");
78 (cfsd_all_object_t
*)cfsd_calloc(sizeof (cfsd_all_object_t
));
82 dbug_print(("error", "cannot get host name"));
83 strlcpy(all_object_p
->i_machname
, gettext("unknown"),
84 sizeof (all_object_p
->i_machname
));
86 strlcpy(all_object_p
->i_machname
, info
.nodename
,
87 sizeof (all_object_p
->i_machname
));
90 /* initialize the locking mutex */
91 xx
= mutex_init(&all_object_p
->i_lock
, USYNC_THREAD
, NULL
);
94 all_object_p
->i_nextcacheid
= 0;
95 all_object_p
->i_modify
= 1;
96 all_object_p
->i_cachelist
= NULL
;
97 all_object_p
->i_cachecount
= 0;
99 /* all_object_p->i_hoardp = NULL; */
101 snprintf(buffer
, sizeof (buffer
), gettext("host name is \"%s\""),
102 all_object_p
->i_machname
);
103 dbug_print(("info", buffer
));
104 dbug_leave("cfsd_all_create");
105 return (all_object_p
);
109 * ------------------------------------------------------------
118 cfsd_all_destroy(cfsd_all_object_t
*all_object_p
)
120 cfsd_cache_object_t
*cache_object_p
;
121 cfsd_cache_object_t
*tmp_cache_object_p
;
124 dbug_enter("cfsd_all_destroy");
126 /* dbug_assert(all_object_p->i_hoardp == NULL); */
128 /* get rid of any cache objects */
129 cache_object_p
= all_object_p
->i_cachelist
;
131 while (cache_object_p
!= NULL
) {
132 tmp_cache_object_p
= cache_object_p
->i_next
;
133 cfsd_cache_destroy(cache_object_p
);
134 cache_object_p
= tmp_cache_object_p
;
137 /* destroy the locking mutex */
138 xx
= mutex_destroy(&all_object_p
->i_lock
);
139 dbug_assert(xx
== 0);
140 cfsd_free(all_object_p
);
141 dbug_leave("cfsd_all_destroy");
145 * ------------------------------------------------------------
154 all_lock(cfsd_all_object_t
*all_object_p
)
156 dbug_enter("all_lock");
158 mutex_lock(&all_object_p
->i_lock
);
159 dbug_leave("all_lock");
163 * ------------------------------------------------------------
172 all_unlock(cfsd_all_object_t
*all_object_p
)
174 dbug_enter("all_unlock");
176 mutex_unlock(&all_object_p
->i_lock
);
177 dbug_leave("all_unlock");
181 * ------------------------------------------------------------
191 cfsd_cache_object_t
*
192 all_cachelist_at(cfsd_all_object_t
*all_object_p
, size_t index
)
194 cfsd_cache_object_t
*cache_object_p
;
197 dbug_enter("all_cachelist_at");
199 /* find the correct cache object */
200 cache_object_p
= all_object_p
->i_cachelist
;
202 while ((cache_object_p
!= NULL
) && (i
++ < index
)) {
203 cache_object_p
= cache_object_p
->i_next
;
206 dbug_leave("all_cachelist_at");
207 return (cache_object_p
);
211 * ------------------------------------------------------------
222 all_cachelist_add(cfsd_all_object_t
*all_object_p
,
223 cfsd_cache_object_t
*cache_object_p
)
225 dbug_enter("all_cachelist_add");
227 dbug_precond(cache_object_p
);
229 cache_object_p
->i_next
= all_object_p
->i_cachelist
;
230 all_object_p
->i_cachelist
= cache_object_p
;
231 all_object_p
->i_modify
++;
232 all_object_p
->i_cachecount
++;
233 dbug_leave("all_cachelist_add");
237 * ------------------------------------------------------------
248 cfsd_cache_object_t
*
249 all_cachelist_find(cfsd_all_object_t
*all_object_p
, const char *namep
)
251 cfsd_cache_object_t
*cache_object_p
;
253 dbug_enter("all_cachelist_find");
257 /* find the correct cache object */
258 cache_object_p
= all_object_p
->i_cachelist
;
260 while ((cache_object_p
!= NULL
) &&
261 strcmp(namep
, cache_object_p
->i_cachedir
)) {
262 cache_object_p
= cache_object_p
->i_next
;
265 dbug_leave("all_cachelist_find");
266 return (cache_object_p
);
270 * ------------------------------------------------------------
271 * all_cachefstab_update
279 all_cachefstab_update(cfsd_all_object_t
*all_object_p
)
281 cfsd_cache_object_t
*cache_object_p
;
284 dbug_enter("all_cachefstab_update");
286 fout
= fopen(CACHEFSTAB
, "w");
288 dbug_print(("error", "cannot write %s", CACHEFSTAB
));
290 cache_object_p
= all_object_p
->i_cachelist
;
292 while (cache_object_p
!= NULL
) {
293 dbug_assert(cache_object_p
);
294 fprintf(fout
, "%s\n", cache_object_p
->i_cachedir
);
295 cache_object_p
= cache_object_p
->i_next
;
298 dbug_print(("error", "cannot close %s error %d",
301 dbug_leave("all_cachefstab_update");