1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 1994-2002 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * RPC service routines.
31*7c478bd9Sstevel@tonic-gate */
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <string.h>
36*7c478bd9Sstevel@tonic-gate #include <errno.h>
37*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
38*7c478bd9Sstevel@tonic-gate #include <rpc/pmap_clnt.h> /* for pmap_unset */
39*7c478bd9Sstevel@tonic-gate #include <string.h> /* strcmp */
40*7c478bd9Sstevel@tonic-gate #include <signal.h>
41*7c478bd9Sstevel@tonic-gate #include <unistd.h> /* setsid */
42*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
44*7c478bd9Sstevel@tonic-gate #include <time.h>
45*7c478bd9Sstevel@tonic-gate #include <memory.h>
46*7c478bd9Sstevel@tonic-gate #include <stropts.h>
47*7c478bd9Sstevel@tonic-gate #include <netconfig.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/resource.h> /* rlimit */
49*7c478bd9Sstevel@tonic-gate #include <thread.h>
50*7c478bd9Sstevel@tonic-gate #include <synch.h>
51*7c478bd9Sstevel@tonic-gate #include <mdbug/mdbug.h>
52*7c478bd9Sstevel@tonic-gate #include <common/cachefsd.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_dlog.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_ioctl.h>
56*7c478bd9Sstevel@tonic-gate #include "cfsd.h"
57*7c478bd9Sstevel@tonic-gate #include "cfsd_kmod.h"
58*7c478bd9Sstevel@tonic-gate #include "cfsd_maptbl.h"
59*7c478bd9Sstevel@tonic-gate #include "cfsd_logfile.h"
60*7c478bd9Sstevel@tonic-gate #include "cfsd_fscache.h"
61*7c478bd9Sstevel@tonic-gate #include "cfsd_cache.h"
62*7c478bd9Sstevel@tonic-gate #include "cfsd_all.h"
63*7c478bd9Sstevel@tonic-gate #include "cfsd_subr.h"
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate /* declared in cfsd_main.c */
66*7c478bd9Sstevel@tonic-gate extern cfsd_all_object_t *all_object_p;
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate * cachefsd_null_1_svc
70*7c478bd9Sstevel@tonic-gate *
71*7c478bd9Sstevel@tonic-gate * Description:
72*7c478bd9Sstevel@tonic-gate * Routine to process NULLPROC command, see /usr/include/rpc/clnt.h.
73*7c478bd9Sstevel@tonic-gate * Arguments:
74*7c478bd9Sstevel@tonic-gate * inp should be NULL
75*7c478bd9Sstevel@tonic-gate * outp should be NULL
76*7c478bd9Sstevel@tonic-gate * reqp svc_req info
77*7c478bd9Sstevel@tonic-gate * Returns:
78*7c478bd9Sstevel@tonic-gate * Always returns 1, e.g. returns success result.
79*7c478bd9Sstevel@tonic-gate * Preconditions:
80*7c478bd9Sstevel@tonic-gate * precond(reqp)
81*7c478bd9Sstevel@tonic-gate */
82*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_null_1_svc(void * inp,void * outp,struct svc_req * reqp)83*7c478bd9Sstevel@tonic-gate cachefsd_null_1_svc(void *inp, void *outp, struct svc_req *reqp)
84*7c478bd9Sstevel@tonic-gate {
85*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_null_1_svc");
86*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate dbug_assert(inp == NULL);
89*7c478bd9Sstevel@tonic-gate dbug_assert(outp == NULL);
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_null_1_svc");
92*7c478bd9Sstevel@tonic-gate return (1);
93*7c478bd9Sstevel@tonic-gate }
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate /*
96*7c478bd9Sstevel@tonic-gate * cachefsd_caches_1_svc
97*7c478bd9Sstevel@tonic-gate *
98*7c478bd9Sstevel@tonic-gate * Description:
99*7c478bd9Sstevel@tonic-gate * Returns list of caches on the system.
100*7c478bd9Sstevel@tonic-gate * Arguments:
101*7c478bd9Sstevel@tonic-gate * inp should be NULL
102*7c478bd9Sstevel@tonic-gate * outp should point to return object
103*7c478bd9Sstevel@tonic-gate * reqp svc_req info
104*7c478bd9Sstevel@tonic-gate * Returns:
105*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an error occurs.
106*7c478bd9Sstevel@tonic-gate * Preconditions:
107*7c478bd9Sstevel@tonic-gate * precond(reqp)
108*7c478bd9Sstevel@tonic-gate */
109*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_caches_1_svc(void * inp,cachefsd_caches_return * outp,struct svc_req * reqp)110*7c478bd9Sstevel@tonic-gate cachefsd_caches_1_svc(void *inp,
111*7c478bd9Sstevel@tonic-gate cachefsd_caches_return *outp,
112*7c478bd9Sstevel@tonic-gate struct svc_req *reqp)
113*7c478bd9Sstevel@tonic-gate {
114*7c478bd9Sstevel@tonic-gate size_t cnt;
115*7c478bd9Sstevel@tonic-gate size_t index;
116*7c478bd9Sstevel@tonic-gate cfsd_cache_object_t *cache_object_p;
117*7c478bd9Sstevel@tonic-gate cachefsd_caches_id *headp, *idp;
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_caches_1_svc");
120*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate dbug_assert(inp == NULL);
123*7c478bd9Sstevel@tonic-gate dbug_assert(outp);
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate if (inp || (outp == NULL)) {
126*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_caches_1_svc");
127*7c478bd9Sstevel@tonic-gate return (0);
128*7c478bd9Sstevel@tonic-gate }
129*7c478bd9Sstevel@tonic-gate all_lock(all_object_p);
130*7c478bd9Sstevel@tonic-gate headp = NULL;
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate /* if there are any caches */
133*7c478bd9Sstevel@tonic-gate cnt = all_object_p->i_cachecount;
134*7c478bd9Sstevel@tonic-gate if (cnt) {
135*7c478bd9Sstevel@tonic-gate /* allocate space for each cache information */
136*7c478bd9Sstevel@tonic-gate headp = idp = cfsd_calloc(sizeof (cachefsd_caches_id) * cnt);
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate /* for each cache */
139*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++, idp++) {
140*7c478bd9Sstevel@tonic-gate /* get the cache */
141*7c478bd9Sstevel@tonic-gate cache_object_p = all_cachelist_at(all_object_p, index);
142*7c478bd9Sstevel@tonic-gate dbug_assert(cache_object_p);
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate /* get the cache id and name */
145*7c478bd9Sstevel@tonic-gate idp->cci_cacheid = cache_object_p->i_cacheid;
146*7c478bd9Sstevel@tonic-gate idp->cci_name = subr_strdup(cache_object_p->i_cachedir);
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate }
149*7c478bd9Sstevel@tonic-gate
150*7c478bd9Sstevel@tonic-gate /* fill in the return object */
151*7c478bd9Sstevel@tonic-gate outp->ccr_modify = all_object_p->i_modify;
152*7c478bd9Sstevel@tonic-gate outp->ccr_ids.ccr_ids_len = cnt;
153*7c478bd9Sstevel@tonic-gate outp->ccr_ids.ccr_ids_val = headp;
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate all_unlock(all_object_p);
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_caches_1_svc");
158*7c478bd9Sstevel@tonic-gate return (1);
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate /*
162*7c478bd9Sstevel@tonic-gate * cachefsd_cache_status_1_svc
163*7c478bd9Sstevel@tonic-gate *
164*7c478bd9Sstevel@tonic-gate * Description:
165*7c478bd9Sstevel@tonic-gate * Returns status about a particular cache.
166*7c478bd9Sstevel@tonic-gate * Arguments:
167*7c478bd9Sstevel@tonic-gate * inp should be ptr to cache id
168*7c478bd9Sstevel@tonic-gate * outp should be ptr to place to put cache status
169*7c478bd9Sstevel@tonic-gate * reqp svc_req info
170*7c478bd9Sstevel@tonic-gate * Returns:
171*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an error occurs.
172*7c478bd9Sstevel@tonic-gate * Preconditions:
173*7c478bd9Sstevel@tonic-gate * precond(reqp)
174*7c478bd9Sstevel@tonic-gate */
175*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_cache_status_1_svc(int * inp,struct cachefsd_cache_status * outp,struct svc_req * reqp)176*7c478bd9Sstevel@tonic-gate cachefsd_cache_status_1_svc(int *inp, struct cachefsd_cache_status *outp,
177*7c478bd9Sstevel@tonic-gate struct svc_req *reqp)
178*7c478bd9Sstevel@tonic-gate {
179*7c478bd9Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p = NULL;
180*7c478bd9Sstevel@tonic-gate size_t cnt, index;
181*7c478bd9Sstevel@tonic-gate cfsd_cache_object_t *cache_object_p;
182*7c478bd9Sstevel@tonic-gate cfsd_kmod_object_t *kmod_object_p;
183*7c478bd9Sstevel@tonic-gate cachefsio_getstats_t gs;
184*7c478bd9Sstevel@tonic-gate int xx;
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_cache_status_1_svc");
187*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate dbug_assert(inp);
190*7c478bd9Sstevel@tonic-gate dbug_assert(outp);
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate if ((inp == NULL) || (outp == NULL)) {
193*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_cache_status_1_svc");
194*7c478bd9Sstevel@tonic-gate return (0);
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate memset(outp, 0, sizeof (*outp));
197*7c478bd9Sstevel@tonic-gate
198*7c478bd9Sstevel@tonic-gate /* find the requested cache */
199*7c478bd9Sstevel@tonic-gate all_lock(all_object_p);
200*7c478bd9Sstevel@tonic-gate cnt = all_object_p->i_cachecount;
201*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++) {
202*7c478bd9Sstevel@tonic-gate /* get the cache */
203*7c478bd9Sstevel@tonic-gate cache_object_p = all_cachelist_at(all_object_p, index);
204*7c478bd9Sstevel@tonic-gate dbug_assert(cache_object_p);
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate /* if a match */
207*7c478bd9Sstevel@tonic-gate if (cache_object_p->i_cacheid == *inp) {
208*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
209*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt++;
210*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
211*7c478bd9Sstevel@tonic-gate break;
212*7c478bd9Sstevel@tonic-gate }
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate all_unlock(all_object_p);
215*7c478bd9Sstevel@tonic-gate
216*7c478bd9Sstevel@tonic-gate /* if no match */
217*7c478bd9Sstevel@tonic-gate if (index >= cnt) {
218*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_cache_status_1_svc");
219*7c478bd9Sstevel@tonic-gate return (1);
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate /* find a mounted file system in the cache */
222*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
223*7c478bd9Sstevel@tonic-gate cnt = cache_object_p->i_fscachecount;
224*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++) {
225*7c478bd9Sstevel@tonic-gate /* get the fscache */
226*7c478bd9Sstevel@tonic-gate fscache_object_p = cache_fscachelist_at(cache_object_p, index);
227*7c478bd9Sstevel@tonic-gate dbug_assert(fscache_object_p);
228*7c478bd9Sstevel@tonic-gate
229*7c478bd9Sstevel@tonic-gate /* mounted */
230*7c478bd9Sstevel@tonic-gate if (fscache_object_p->i_mounted) {
231*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
232*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt++;
233*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
234*7c478bd9Sstevel@tonic-gate break;
235*7c478bd9Sstevel@tonic-gate }
236*7c478bd9Sstevel@tonic-gate fscache_object_p = NULL;
237*7c478bd9Sstevel@tonic-gate }
238*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
239*7c478bd9Sstevel@tonic-gate
240*7c478bd9Sstevel@tonic-gate outp->ccs_size = 0;
241*7c478bd9Sstevel@tonic-gate outp->ccs_lrusize = 0;
242*7c478bd9Sstevel@tonic-gate outp->ccs_packsize = 0;
243*7c478bd9Sstevel@tonic-gate outp->ccs_freesize = 0;
244*7c478bd9Sstevel@tonic-gate outp->ccs_lrutime = 0;
245*7c478bd9Sstevel@tonic-gate
246*7c478bd9Sstevel@tonic-gate kmod_object_p = cfsd_kmod_create();
247*7c478bd9Sstevel@tonic-gate if (fscache_object_p) {
248*7c478bd9Sstevel@tonic-gate xx = kmod_setup(kmod_object_p, fscache_object_p->i_mntpt);
249*7c478bd9Sstevel@tonic-gate if (xx != 0) {
250*7c478bd9Sstevel@tonic-gate dbug_print(("err",
251*7c478bd9Sstevel@tonic-gate "setup of kmod interface failed %d", xx));
252*7c478bd9Sstevel@tonic-gate } else if ((xx = kmod_getstats(kmod_object_p, &gs)) != 0) {
253*7c478bd9Sstevel@tonic-gate dbug_print(("err", "getstat failed %d", xx));
254*7c478bd9Sstevel@tonic-gate } else {
255*7c478bd9Sstevel@tonic-gate outp->ccs_size = gs.gs_total;
256*7c478bd9Sstevel@tonic-gate outp->ccs_lrusize = gs.gs_gc + gs.gs_active;
257*7c478bd9Sstevel@tonic-gate outp->ccs_packsize = gs.gs_packed;
258*7c478bd9Sstevel@tonic-gate outp->ccs_freesize = gs.gs_free;
259*7c478bd9Sstevel@tonic-gate outp->ccs_lrutime = gs.gs_gctime;
260*7c478bd9Sstevel@tonic-gate
261*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
262*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt--;
263*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate cfsd_kmod_destroy(kmod_object_p);
267*7c478bd9Sstevel@tonic-gate
268*7c478bd9Sstevel@tonic-gate outp->ccs_id = cache_object_p->i_cacheid;
269*7c478bd9Sstevel@tonic-gate outp->ccs_name = subr_strdup(cache_object_p->i_cachedir);
270*7c478bd9Sstevel@tonic-gate outp->ccs_modify = cache_object_p->i_modify;
271*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
272*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt--;
273*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
274*7c478bd9Sstevel@tonic-gate
275*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_cache_status_1_svc");
276*7c478bd9Sstevel@tonic-gate return (1);
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate
279*7c478bd9Sstevel@tonic-gate /*
280*7c478bd9Sstevel@tonic-gate * cachefsd_mounts_1_svc
281*7c478bd9Sstevel@tonic-gate *
282*7c478bd9Sstevel@tonic-gate * Description:
283*7c478bd9Sstevel@tonic-gate * Returns the list of file systems that are in the cache.
284*7c478bd9Sstevel@tonic-gate * Arguments:
285*7c478bd9Sstevel@tonic-gate * inp should be ptr to cache id
286*7c478bd9Sstevel@tonic-gate * outp should be ptr to place to put mounts
287*7c478bd9Sstevel@tonic-gate * reqp svc_req info
288*7c478bd9Sstevel@tonic-gate * Returns:
289*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an internal error occurs.
290*7c478bd9Sstevel@tonic-gate * Preconditions:
291*7c478bd9Sstevel@tonic-gate * precond(reqp)
292*7c478bd9Sstevel@tonic-gate */
293*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_mounts_1_svc(int * inp,struct cachefsd_mount_returns * outp,struct svc_req * reqp)294*7c478bd9Sstevel@tonic-gate cachefsd_mounts_1_svc(int *inp, struct cachefsd_mount_returns *outp,
295*7c478bd9Sstevel@tonic-gate struct svc_req *reqp)
296*7c478bd9Sstevel@tonic-gate {
297*7c478bd9Sstevel@tonic-gate size_t cnt, index;
298*7c478bd9Sstevel@tonic-gate cfsd_cache_object_t *cache_object_p;
299*7c478bd9Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p;
300*7c478bd9Sstevel@tonic-gate struct cachefsd_mount *headp, *idp;
301*7c478bd9Sstevel@tonic-gate
302*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_mounts_1_svc");
303*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
304*7c478bd9Sstevel@tonic-gate
305*7c478bd9Sstevel@tonic-gate dbug_assert(inp);
306*7c478bd9Sstevel@tonic-gate dbug_assert(outp);
307*7c478bd9Sstevel@tonic-gate if ((inp == NULL) || (outp == NULL)) {
308*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mounts_1_svc");
309*7c478bd9Sstevel@tonic-gate return (0);
310*7c478bd9Sstevel@tonic-gate }
311*7c478bd9Sstevel@tonic-gate memset(outp, 0, sizeof (*outp));
312*7c478bd9Sstevel@tonic-gate
313*7c478bd9Sstevel@tonic-gate /* find the requested cache */
314*7c478bd9Sstevel@tonic-gate all_lock(all_object_p);
315*7c478bd9Sstevel@tonic-gate cnt = all_object_p->i_cachecount;
316*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++) {
317*7c478bd9Sstevel@tonic-gate /* get the cache */
318*7c478bd9Sstevel@tonic-gate cache_object_p = all_cachelist_at(all_object_p, index);
319*7c478bd9Sstevel@tonic-gate dbug_assert(cache_object_p);
320*7c478bd9Sstevel@tonic-gate
321*7c478bd9Sstevel@tonic-gate /* if a match */
322*7c478bd9Sstevel@tonic-gate if (cache_object_p->i_cacheid == *inp) {
323*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
324*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt++;
325*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
326*7c478bd9Sstevel@tonic-gate break;
327*7c478bd9Sstevel@tonic-gate }
328*7c478bd9Sstevel@tonic-gate }
329*7c478bd9Sstevel@tonic-gate all_unlock(all_object_p);
330*7c478bd9Sstevel@tonic-gate
331*7c478bd9Sstevel@tonic-gate /* if no match was found */
332*7c478bd9Sstevel@tonic-gate if (index >= cnt) {
333*7c478bd9Sstevel@tonic-gate outp->cmr_error = ENOENT;
334*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mounts_1_svc");
335*7c478bd9Sstevel@tonic-gate return (1);
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate
338*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
339*7c478bd9Sstevel@tonic-gate headp = NULL;
340*7c478bd9Sstevel@tonic-gate
341*7c478bd9Sstevel@tonic-gate /* if there are any fscaches */
342*7c478bd9Sstevel@tonic-gate cnt = cache_object_p->i_fscachecount;
343*7c478bd9Sstevel@tonic-gate if (cnt) {
344*7c478bd9Sstevel@tonic-gate /* allocate space for each fscache information */
345*7c478bd9Sstevel@tonic-gate headp = idp = cfsd_calloc(sizeof (cachefsd_mount) * cnt);
346*7c478bd9Sstevel@tonic-gate /* for each fscache */
347*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++, idp++) {
348*7c478bd9Sstevel@tonic-gate /* get the fscache */
349*7c478bd9Sstevel@tonic-gate fscache_object_p =
350*7c478bd9Sstevel@tonic-gate cache_fscachelist_at(cache_object_p, index);
351*7c478bd9Sstevel@tonic-gate dbug_assert(fscache_object_p);
352*7c478bd9Sstevel@tonic-gate
353*7c478bd9Sstevel@tonic-gate /* get the fscache id and name */
354*7c478bd9Sstevel@tonic-gate idp->cm_fsid = fscache_object_p->i_fscacheid;
355*7c478bd9Sstevel@tonic-gate idp->cm_name = subr_strdup(fscache_object_p->i_name);
356*7c478bd9Sstevel@tonic-gate }
357*7c478bd9Sstevel@tonic-gate }
358*7c478bd9Sstevel@tonic-gate
359*7c478bd9Sstevel@tonic-gate /* fill in the return object */
360*7c478bd9Sstevel@tonic-gate outp->cmr_modify = cache_object_p->i_modify;
361*7c478bd9Sstevel@tonic-gate outp->cmr_error = 0;
362*7c478bd9Sstevel@tonic-gate outp->cmr_names.cmr_names_len = cnt;
363*7c478bd9Sstevel@tonic-gate outp->cmr_names.cmr_names_val = headp;
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt--;
366*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
367*7c478bd9Sstevel@tonic-gate
368*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mounts_1_svc");
369*7c478bd9Sstevel@tonic-gate return (1);
370*7c478bd9Sstevel@tonic-gate }
371*7c478bd9Sstevel@tonic-gate
372*7c478bd9Sstevel@tonic-gate /*
373*7c478bd9Sstevel@tonic-gate * cachefsd_mount_stat_1_svc
374*7c478bd9Sstevel@tonic-gate *
375*7c478bd9Sstevel@tonic-gate * Description:
376*7c478bd9Sstevel@tonic-gate * Returns status information about a single file system
377*7c478bd9Sstevel@tonic-gate * in the cache.
378*7c478bd9Sstevel@tonic-gate * Arguments:
379*7c478bd9Sstevel@tonic-gate * inp should be which file system to get info for
380*7c478bd9Sstevel@tonic-gate * outp should be place to put mount info
381*7c478bd9Sstevel@tonic-gate * reqp svc_req info
382*7c478bd9Sstevel@tonic-gate * Returns:
383*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an error occurs.
384*7c478bd9Sstevel@tonic-gate * Preconditions:
385*7c478bd9Sstevel@tonic-gate * precond(reqp)
386*7c478bd9Sstevel@tonic-gate */
387*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_mount_stat_1_svc(struct cachefsd_mount_stat_args * inp,struct cachefsd_mount_stat * outp,struct svc_req * reqp)388*7c478bd9Sstevel@tonic-gate cachefsd_mount_stat_1_svc(struct cachefsd_mount_stat_args *inp,
389*7c478bd9Sstevel@tonic-gate struct cachefsd_mount_stat *outp, struct svc_req *reqp)
390*7c478bd9Sstevel@tonic-gate {
391*7c478bd9Sstevel@tonic-gate size_t cnt, index;
392*7c478bd9Sstevel@tonic-gate cfsd_cache_object_t *cache_object_p;
393*7c478bd9Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p;
394*7c478bd9Sstevel@tonic-gate char namebuf[MAXPATHLEN];
395*7c478bd9Sstevel@tonic-gate struct stat sinfo;
396*7c478bd9Sstevel@tonic-gate
397*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_mount_stat_1_svc");
398*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
399*7c478bd9Sstevel@tonic-gate
400*7c478bd9Sstevel@tonic-gate dbug_assert(inp);
401*7c478bd9Sstevel@tonic-gate dbug_assert(outp);
402*7c478bd9Sstevel@tonic-gate if ((inp == NULL) || (outp == NULL)) {
403*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mount_stat_1_svc");
404*7c478bd9Sstevel@tonic-gate return (0);
405*7c478bd9Sstevel@tonic-gate }
406*7c478bd9Sstevel@tonic-gate memset(outp, 0, sizeof (*outp));
407*7c478bd9Sstevel@tonic-gate
408*7c478bd9Sstevel@tonic-gate /* find the requested cache */
409*7c478bd9Sstevel@tonic-gate all_lock(all_object_p);
410*7c478bd9Sstevel@tonic-gate cnt = all_object_p->i_cachecount;
411*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++) {
412*7c478bd9Sstevel@tonic-gate /* get the cache */
413*7c478bd9Sstevel@tonic-gate cache_object_p = all_cachelist_at(all_object_p, index);
414*7c478bd9Sstevel@tonic-gate dbug_assert(cache_object_p);
415*7c478bd9Sstevel@tonic-gate
416*7c478bd9Sstevel@tonic-gate /* if a match */
417*7c478bd9Sstevel@tonic-gate if (cache_object_p->i_cacheid == inp->cma_cacheid) {
418*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
419*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt++;
420*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
421*7c478bd9Sstevel@tonic-gate break;
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate }
424*7c478bd9Sstevel@tonic-gate all_unlock(all_object_p);
425*7c478bd9Sstevel@tonic-gate
426*7c478bd9Sstevel@tonic-gate /* if no match was found */
427*7c478bd9Sstevel@tonic-gate if (index >= cnt) {
428*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mount_stat_1_svc");
429*7c478bd9Sstevel@tonic-gate return (1);
430*7c478bd9Sstevel@tonic-gate }
431*7c478bd9Sstevel@tonic-gate
432*7c478bd9Sstevel@tonic-gate /* find the requested fscache */
433*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
434*7c478bd9Sstevel@tonic-gate cnt = cache_object_p->i_fscachecount;
435*7c478bd9Sstevel@tonic-gate for (index = 0; index < cnt; index++) {
436*7c478bd9Sstevel@tonic-gate /* get the fscache */
437*7c478bd9Sstevel@tonic-gate fscache_object_p = cache_fscachelist_at(cache_object_p, index);
438*7c478bd9Sstevel@tonic-gate dbug_assert(fscache_object_p);
439*7c478bd9Sstevel@tonic-gate
440*7c478bd9Sstevel@tonic-gate /* if a match */
441*7c478bd9Sstevel@tonic-gate if (fscache_object_p->i_fscacheid == inp->cma_fsid) {
442*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
443*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt++;
444*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
445*7c478bd9Sstevel@tonic-gate break;
446*7c478bd9Sstevel@tonic-gate }
447*7c478bd9Sstevel@tonic-gate }
448*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
449*7c478bd9Sstevel@tonic-gate
450*7c478bd9Sstevel@tonic-gate /* if no match was found */
451*7c478bd9Sstevel@tonic-gate if (index >= cnt) {
452*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
453*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt--;
454*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
455*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mount_stat_1_svc");
456*7c478bd9Sstevel@tonic-gate return (1);
457*7c478bd9Sstevel@tonic-gate }
458*7c478bd9Sstevel@tonic-gate
459*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
460*7c478bd9Sstevel@tonic-gate
461*7c478bd9Sstevel@tonic-gate /* see if there are changes to roll to the server */
462*7c478bd9Sstevel@tonic-gate if ((fscache_object_p->i_connected == 0) &&
463*7c478bd9Sstevel@tonic-gate (fscache_object_p->i_changes == 0)) {
464*7c478bd9Sstevel@tonic-gate snprintf(namebuf, sizeof (namebuf), "%s/%s/%s",
465*7c478bd9Sstevel@tonic-gate cache_object_p->i_cachedir, fscache_object_p->i_name,
466*7c478bd9Sstevel@tonic-gate CACHEFS_DLOG_FILE);
467*7c478bd9Sstevel@tonic-gate if (stat(namebuf, &sinfo) == 0) {
468*7c478bd9Sstevel@tonic-gate fscache_changes(fscache_object_p, 1);
469*7c478bd9Sstevel@tonic-gate }
470*7c478bd9Sstevel@tonic-gate }
471*7c478bd9Sstevel@tonic-gate
472*7c478bd9Sstevel@tonic-gate /* fill in the return object */
473*7c478bd9Sstevel@tonic-gate outp->cms_cacheid = cache_object_p->i_cacheid;
474*7c478bd9Sstevel@tonic-gate outp->cms_fsid = fscache_object_p->i_fscacheid;
475*7c478bd9Sstevel@tonic-gate outp->cms_name = subr_strdup(fscache_object_p->i_name);
476*7c478bd9Sstevel@tonic-gate outp->cms_backfs = subr_strdup(fscache_object_p->i_backfs);
477*7c478bd9Sstevel@tonic-gate outp->cms_mountpt = subr_strdup(fscache_object_p->i_mntpt);
478*7c478bd9Sstevel@tonic-gate outp->cms_backfstype = subr_strdup(fscache_object_p->i_backfstype);
479*7c478bd9Sstevel@tonic-gate outp->cms_writemode = NULL;
480*7c478bd9Sstevel@tonic-gate outp->cms_options = subr_strdup(fscache_object_p->i_cfsopt);
481*7c478bd9Sstevel@tonic-gate outp->cms_mounted = fscache_object_p->i_mounted;
482*7c478bd9Sstevel@tonic-gate outp->cms_connected = fscache_object_p->i_connected;
483*7c478bd9Sstevel@tonic-gate outp->cms_reconcile = fscache_object_p->i_reconcile;
484*7c478bd9Sstevel@tonic-gate outp->cms_changes = fscache_object_p->i_changes;
485*7c478bd9Sstevel@tonic-gate outp->cms_time_state = fscache_object_p->i_time_state;
486*7c478bd9Sstevel@tonic-gate outp->cms_mnttime = fscache_object_p->i_time_mnt;
487*7c478bd9Sstevel@tonic-gate outp->cms_modify = fscache_object_p->i_modify;
488*7c478bd9Sstevel@tonic-gate
489*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt--;
490*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
491*7c478bd9Sstevel@tonic-gate
492*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
493*7c478bd9Sstevel@tonic-gate cache_object_p->i_refcnt--;
494*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
495*7c478bd9Sstevel@tonic-gate
496*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_mount_stat_1_svc");
497*7c478bd9Sstevel@tonic-gate return (1);
498*7c478bd9Sstevel@tonic-gate }
499*7c478bd9Sstevel@tonic-gate
500*7c478bd9Sstevel@tonic-gate /*
501*7c478bd9Sstevel@tonic-gate * cachefsd_fs_mounted_1_svc
502*7c478bd9Sstevel@tonic-gate *
503*7c478bd9Sstevel@tonic-gate * Description:
504*7c478bd9Sstevel@tonic-gate * Sent by the mount command to indicate a new file system
505*7c478bd9Sstevel@tonic-gate * has been mounted
506*7c478bd9Sstevel@tonic-gate * Arguments:
507*7c478bd9Sstevel@tonic-gate * inp ptr to mount information
508*7c478bd9Sstevel@tonic-gate * outp should be null
509*7c478bd9Sstevel@tonic-gate * reqp svc_req info
510*7c478bd9Sstevel@tonic-gate * Returns:
511*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an internal error occurs.
512*7c478bd9Sstevel@tonic-gate * Preconditions:
513*7c478bd9Sstevel@tonic-gate * precond(inp)
514*7c478bd9Sstevel@tonic-gate */
515*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_fs_mounted_1_svc(struct cachefsd_fs_mounted * inp,void * outp,struct svc_req * reqp)516*7c478bd9Sstevel@tonic-gate cachefsd_fs_mounted_1_svc(struct cachefsd_fs_mounted *inp, void *outp,
517*7c478bd9Sstevel@tonic-gate struct svc_req *reqp)
518*7c478bd9Sstevel@tonic-gate {
519*7c478bd9Sstevel@tonic-gate int error = 0;
520*7c478bd9Sstevel@tonic-gate
521*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_fs_mounted_1_svc");
522*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
523*7c478bd9Sstevel@tonic-gate
524*7c478bd9Sstevel@tonic-gate dbug_assert(inp);
525*7c478bd9Sstevel@tonic-gate dbug_assert(outp == NULL);
526*7c478bd9Sstevel@tonic-gate if ((inp == NULL) || outp) {
527*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_fs_mounted_1_svc");
528*7c478bd9Sstevel@tonic-gate return (0);
529*7c478bd9Sstevel@tonic-gate }
530*7c478bd9Sstevel@tonic-gate
531*7c478bd9Sstevel@tonic-gate if (inp->mt_cachedir == NULL) {
532*7c478bd9Sstevel@tonic-gate dbug_print(("error", "cachedir is null"));
533*7c478bd9Sstevel@tonic-gate error = 1;
534*7c478bd9Sstevel@tonic-gate }
535*7c478bd9Sstevel@tonic-gate if (inp->mt_cacheid == NULL) {
536*7c478bd9Sstevel@tonic-gate dbug_print(("error", "cacheid is null"));
537*7c478bd9Sstevel@tonic-gate error = 1;
538*7c478bd9Sstevel@tonic-gate }
539*7c478bd9Sstevel@tonic-gate
540*7c478bd9Sstevel@tonic-gate if (error == 0) {
541*7c478bd9Sstevel@tonic-gate dbug_print(("info", "Mounted in %s file system %s",
542*7c478bd9Sstevel@tonic-gate inp->mt_cachedir, inp->mt_cacheid));
543*7c478bd9Sstevel@tonic-gate subr_add_mount(all_object_p, inp->mt_cachedir, inp->mt_cacheid);
544*7c478bd9Sstevel@tonic-gate }
545*7c478bd9Sstevel@tonic-gate
546*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_fs_mounted_1_svc");
547*7c478bd9Sstevel@tonic-gate return (1);
548*7c478bd9Sstevel@tonic-gate }
549*7c478bd9Sstevel@tonic-gate
550*7c478bd9Sstevel@tonic-gate /*
551*7c478bd9Sstevel@tonic-gate * cachefsd_fs_unmounted_1_svc
552*7c478bd9Sstevel@tonic-gate *
553*7c478bd9Sstevel@tonic-gate * Description:
554*7c478bd9Sstevel@tonic-gate * Arguments:
555*7c478bd9Sstevel@tonic-gate * inp
556*7c478bd9Sstevel@tonic-gate * outp
557*7c478bd9Sstevel@tonic-gate * reqp
558*7c478bd9Sstevel@tonic-gate * Returns:
559*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an internal error occurs.
560*7c478bd9Sstevel@tonic-gate * Preconditions:
561*7c478bd9Sstevel@tonic-gate * precond(inp)
562*7c478bd9Sstevel@tonic-gate * precond(outp == NULL)
563*7c478bd9Sstevel@tonic-gate * precond(reqp)
564*7c478bd9Sstevel@tonic-gate */
565*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_fs_unmounted_1_svc(struct cachefsd_fs_unmounted * inp,int * outp,struct svc_req * reqp)566*7c478bd9Sstevel@tonic-gate cachefsd_fs_unmounted_1_svc(struct cachefsd_fs_unmounted *inp, int *outp,
567*7c478bd9Sstevel@tonic-gate struct svc_req *reqp)
568*7c478bd9Sstevel@tonic-gate {
569*7c478bd9Sstevel@tonic-gate size_t cnt1, cnt2, index1, index2;
570*7c478bd9Sstevel@tonic-gate cfsd_cache_object_t *cache_object_p;
571*7c478bd9Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p = NULL;
572*7c478bd9Sstevel@tonic-gate int found = 0;
573*7c478bd9Sstevel@tonic-gate int flag = 0;
574*7c478bd9Sstevel@tonic-gate
575*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_fs_unmounted_1_svc");
576*7c478bd9Sstevel@tonic-gate
577*7c478bd9Sstevel@tonic-gate dbug_precond(inp);
578*7c478bd9Sstevel@tonic-gate dbug_precond(outp);
579*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
580*7c478bd9Sstevel@tonic-gate
581*7c478bd9Sstevel@tonic-gate if ((inp == NULL) || (outp == NULL)) {
582*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_fs_unmounted_1_svc");
583*7c478bd9Sstevel@tonic-gate return (0);
584*7c478bd9Sstevel@tonic-gate }
585*7c478bd9Sstevel@tonic-gate memset(outp, 0, sizeof (*outp));
586*7c478bd9Sstevel@tonic-gate
587*7c478bd9Sstevel@tonic-gate if (inp->mntpt == NULL) {
588*7c478bd9Sstevel@tonic-gate dbug_print(("error", "mntpt is null"));
589*7c478bd9Sstevel@tonic-gate *outp = EIO;
590*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_fs_unmounted_1_svc");
591*7c478bd9Sstevel@tonic-gate return (1);
592*7c478bd9Sstevel@tonic-gate }
593*7c478bd9Sstevel@tonic-gate
594*7c478bd9Sstevel@tonic-gate /* for each cache */
595*7c478bd9Sstevel@tonic-gate all_lock(all_object_p);
596*7c478bd9Sstevel@tonic-gate cnt1 = all_object_p->i_cachecount;
597*7c478bd9Sstevel@tonic-gate for (index1 = 0; index1 < cnt1; index1++) {
598*7c478bd9Sstevel@tonic-gate /* get the cache */
599*7c478bd9Sstevel@tonic-gate cache_object_p = all_cachelist_at(all_object_p, index1);
600*7c478bd9Sstevel@tonic-gate dbug_assert(cache_object_p);
601*7c478bd9Sstevel@tonic-gate
602*7c478bd9Sstevel@tonic-gate /* for each file system in this cache */
603*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
604*7c478bd9Sstevel@tonic-gate cnt2 = cache_object_p->i_fscachecount;
605*7c478bd9Sstevel@tonic-gate for (index2 = 0; index2 < cnt2; index2++) {
606*7c478bd9Sstevel@tonic-gate /* get the fscache */
607*7c478bd9Sstevel@tonic-gate fscache_object_p =
608*7c478bd9Sstevel@tonic-gate cache_fscachelist_at(cache_object_p, index2);
609*7c478bd9Sstevel@tonic-gate dbug_assert(fscache_object_p);
610*7c478bd9Sstevel@tonic-gate
611*7c478bd9Sstevel@tonic-gate /* skip if not mounted */
612*7c478bd9Sstevel@tonic-gate if (fscache_object_p->i_mounted == 0)
613*7c478bd9Sstevel@tonic-gate continue;
614*7c478bd9Sstevel@tonic-gate
615*7c478bd9Sstevel@tonic-gate /* if a match */
616*7c478bd9Sstevel@tonic-gate if (strcmp(fscache_object_p->i_mntpt,
617*7c478bd9Sstevel@tonic-gate inp->mntpt) == 0) {
618*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
619*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt++;
620*7c478bd9Sstevel@tonic-gate flag = inp->flag;
621*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
622*7c478bd9Sstevel@tonic-gate found = 1;
623*7c478bd9Sstevel@tonic-gate break;
624*7c478bd9Sstevel@tonic-gate }
625*7c478bd9Sstevel@tonic-gate }
626*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
627*7c478bd9Sstevel@tonic-gate if (found)
628*7c478bd9Sstevel@tonic-gate break;
629*7c478bd9Sstevel@tonic-gate fscache_object_p = NULL;
630*7c478bd9Sstevel@tonic-gate }
631*7c478bd9Sstevel@tonic-gate all_unlock(all_object_p);
632*7c478bd9Sstevel@tonic-gate
633*7c478bd9Sstevel@tonic-gate /* if no match */
634*7c478bd9Sstevel@tonic-gate if (fscache_object_p == NULL) {
635*7c478bd9Sstevel@tonic-gate *outp = EIO;
636*7c478bd9Sstevel@tonic-gate } else {
637*7c478bd9Sstevel@tonic-gate *outp = fscache_unmount(fscache_object_p, flag);
638*7c478bd9Sstevel@tonic-gate
639*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
640*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt--;
641*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
642*7c478bd9Sstevel@tonic-gate }
643*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_fs_unmounted_1_svc");
644*7c478bd9Sstevel@tonic-gate return (1);
645*7c478bd9Sstevel@tonic-gate }
646*7c478bd9Sstevel@tonic-gate
647*7c478bd9Sstevel@tonic-gate /*
648*7c478bd9Sstevel@tonic-gate * cachefsd_disconnection_1_svc
649*7c478bd9Sstevel@tonic-gate *
650*7c478bd9Sstevel@tonic-gate * Description:
651*7c478bd9Sstevel@tonic-gate * Arguments:
652*7c478bd9Sstevel@tonic-gate * inp
653*7c478bd9Sstevel@tonic-gate * outp
654*7c478bd9Sstevel@tonic-gate * reqp
655*7c478bd9Sstevel@tonic-gate * Returns:
656*7c478bd9Sstevel@tonic-gate * Returns 1 for success 0 if an internal error occurs.
657*7c478bd9Sstevel@tonic-gate * Preconditions:
658*7c478bd9Sstevel@tonic-gate * precond(inp)
659*7c478bd9Sstevel@tonic-gate * precond(outp)
660*7c478bd9Sstevel@tonic-gate * precond(reqp)
661*7c478bd9Sstevel@tonic-gate */
662*7c478bd9Sstevel@tonic-gate bool_t
cachefsd_disconnection_1_svc(struct cachefsd_disconnection_args * inp,int * outp,struct svc_req * reqp)663*7c478bd9Sstevel@tonic-gate cachefsd_disconnection_1_svc(struct cachefsd_disconnection_args *inp, int *outp,
664*7c478bd9Sstevel@tonic-gate struct svc_req *reqp)
665*7c478bd9Sstevel@tonic-gate {
666*7c478bd9Sstevel@tonic-gate size_t cnt1, cnt2, index1, index2;
667*7c478bd9Sstevel@tonic-gate cfsd_cache_object_t *cache_object_p;
668*7c478bd9Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p = NULL;
669*7c478bd9Sstevel@tonic-gate int found = 0;
670*7c478bd9Sstevel@tonic-gate
671*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsd_disconnection_1_svc");
672*7c478bd9Sstevel@tonic-gate
673*7c478bd9Sstevel@tonic-gate dbug_precond(inp);
674*7c478bd9Sstevel@tonic-gate dbug_precond(outp);
675*7c478bd9Sstevel@tonic-gate dbug_precond(reqp);
676*7c478bd9Sstevel@tonic-gate
677*7c478bd9Sstevel@tonic-gate if ((inp == NULL) || (outp == NULL)) {
678*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_disconnection_1_svc");
679*7c478bd9Sstevel@tonic-gate return (0);
680*7c478bd9Sstevel@tonic-gate }
681*7c478bd9Sstevel@tonic-gate memset(outp, 0, sizeof (*outp));
682*7c478bd9Sstevel@tonic-gate
683*7c478bd9Sstevel@tonic-gate /* for each cache */
684*7c478bd9Sstevel@tonic-gate all_lock(all_object_p);
685*7c478bd9Sstevel@tonic-gate cnt1 = all_object_p->i_cachecount;
686*7c478bd9Sstevel@tonic-gate for (index1 = 0; index1 < cnt1; index1++) {
687*7c478bd9Sstevel@tonic-gate /* get the cache */
688*7c478bd9Sstevel@tonic-gate cache_object_p = all_cachelist_at(all_object_p, index1);
689*7c478bd9Sstevel@tonic-gate dbug_assert(cache_object_p);
690*7c478bd9Sstevel@tonic-gate
691*7c478bd9Sstevel@tonic-gate /* for each file system in this cache */
692*7c478bd9Sstevel@tonic-gate cache_lock(cache_object_p);
693*7c478bd9Sstevel@tonic-gate cnt2 = cache_object_p->i_fscachecount;
694*7c478bd9Sstevel@tonic-gate for (index2 = 0; index2 < cnt2; index2++) {
695*7c478bd9Sstevel@tonic-gate /* get the fscache */
696*7c478bd9Sstevel@tonic-gate fscache_object_p =
697*7c478bd9Sstevel@tonic-gate cache_fscachelist_at(cache_object_p, index2);
698*7c478bd9Sstevel@tonic-gate dbug_assert(fscache_object_p);
699*7c478bd9Sstevel@tonic-gate
700*7c478bd9Sstevel@tonic-gate /* if a match */
701*7c478bd9Sstevel@tonic-gate if (strcmp(fscache_object_p->i_mntpt, inp->cda_mntpt)
702*7c478bd9Sstevel@tonic-gate == 0) {
703*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
704*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt++;
705*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
706*7c478bd9Sstevel@tonic-gate found = 1;
707*7c478bd9Sstevel@tonic-gate break;
708*7c478bd9Sstevel@tonic-gate }
709*7c478bd9Sstevel@tonic-gate }
710*7c478bd9Sstevel@tonic-gate cache_unlock(cache_object_p);
711*7c478bd9Sstevel@tonic-gate if (found)
712*7c478bd9Sstevel@tonic-gate break;
713*7c478bd9Sstevel@tonic-gate fscache_object_p = NULL;
714*7c478bd9Sstevel@tonic-gate }
715*7c478bd9Sstevel@tonic-gate all_unlock(all_object_p);
716*7c478bd9Sstevel@tonic-gate
717*7c478bd9Sstevel@tonic-gate /* if no match */
718*7c478bd9Sstevel@tonic-gate if (fscache_object_p == NULL) {
719*7c478bd9Sstevel@tonic-gate *outp = 3;
720*7c478bd9Sstevel@tonic-gate } else {
721*7c478bd9Sstevel@tonic-gate *outp = fscache_simdisconnect(fscache_object_p,
722*7c478bd9Sstevel@tonic-gate inp->cda_disconnect);
723*7c478bd9Sstevel@tonic-gate
724*7c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
725*7c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt--;
726*7c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
727*7c478bd9Sstevel@tonic-gate }
728*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsd_disconnection_1_svc");
729*7c478bd9Sstevel@tonic-gate return (1);
730*7c478bd9Sstevel@tonic-gate }
731*7c478bd9Sstevel@tonic-gate
732*7c478bd9Sstevel@tonic-gate /*
733*7c478bd9Sstevel@tonic-gate * cachefsdprog_1_freeresult
734*7c478bd9Sstevel@tonic-gate *
735*7c478bd9Sstevel@tonic-gate * Description:
736*7c478bd9Sstevel@tonic-gate * Arguments:
737*7c478bd9Sstevel@tonic-gate * transp
738*7c478bd9Sstevel@tonic-gate * xdr_result
739*7c478bd9Sstevel@tonic-gate * resultp
740*7c478bd9Sstevel@tonic-gate * Returns:
741*7c478bd9Sstevel@tonic-gate * Returns ...
742*7c478bd9Sstevel@tonic-gate * Preconditions:
743*7c478bd9Sstevel@tonic-gate * precond(transp)
744*7c478bd9Sstevel@tonic-gate */
745*7c478bd9Sstevel@tonic-gate int
cachefsdprog_1_freeresult(SVCXPRT * transp,xdrproc_t xdr_result,caddr_t resultp)746*7c478bd9Sstevel@tonic-gate cachefsdprog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result,
747*7c478bd9Sstevel@tonic-gate caddr_t resultp)
748*7c478bd9Sstevel@tonic-gate {
749*7c478bd9Sstevel@tonic-gate dbug_enter("cachefsdprog_1_freeresult");
750*7c478bd9Sstevel@tonic-gate
751*7c478bd9Sstevel@tonic-gate dbug_precond(transp);
752*7c478bd9Sstevel@tonic-gate
753*7c478bd9Sstevel@tonic-gate (void) xdr_free(xdr_result, resultp);
754*7c478bd9Sstevel@tonic-gate dbug_leave("cachefsdprog_1_freeresult");
755*7c478bd9Sstevel@tonic-gate return (1);
756*7c478bd9Sstevel@tonic-gate }
757