umap_vnops.c revision 1.13 1 1.13 bouyer /* $NetBSD: umap_vnops.c,v 1.13 1999/03/25 13:05:42 bouyer Exp $ */
2 1.2 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1992, 1993
5 1.1 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * This code is derived from software donated to Berkeley by
8 1.1 mycroft * the UCLA Ficus project.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer.
15 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.1 mycroft * documentation and/or other materials provided with the distribution.
18 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.1 mycroft * must display the following acknowledgement:
20 1.1 mycroft * This product includes software developed by the University of
21 1.1 mycroft * California, Berkeley and its contributors.
22 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
23 1.1 mycroft * may be used to endorse or promote products derived from this software
24 1.1 mycroft * without specific prior written permission.
25 1.1 mycroft *
26 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 mycroft * SUCH DAMAGE.
37 1.1 mycroft *
38 1.10 fvdl * @(#)umap_vnops.c 8.6 (Berkeley) 5/22/95
39 1.1 mycroft */
40 1.1 mycroft
41 1.1 mycroft /*
42 1.1 mycroft * Umap Layer
43 1.1 mycroft */
44 1.1 mycroft
45 1.1 mycroft #include <sys/param.h>
46 1.1 mycroft #include <sys/systm.h>
47 1.1 mycroft #include <sys/time.h>
48 1.1 mycroft #include <sys/types.h>
49 1.1 mycroft #include <sys/vnode.h>
50 1.1 mycroft #include <sys/mount.h>
51 1.1 mycroft #include <sys/namei.h>
52 1.1 mycroft #include <sys/malloc.h>
53 1.1 mycroft #include <sys/buf.h>
54 1.1 mycroft #include <miscfs/umapfs/umap.h>
55 1.10 fvdl #include <miscfs/genfs/genfs.h>
56 1.1 mycroft
57 1.1 mycroft
58 1.1 mycroft int umap_bug_bypass = 0; /* for debugging: enables bypass printf'ing */
59 1.1 mycroft
60 1.5 christos int umap_bypass __P((void *));
61 1.5 christos int umap_getattr __P((void *));
62 1.5 christos int umap_inactive __P((void *));
63 1.5 christos int umap_reclaim __P((void *));
64 1.5 christos int umap_print __P((void *));
65 1.5 christos int umap_rename __P((void *));
66 1.5 christos int umap_strategy __P((void *));
67 1.5 christos int umap_bwrite __P((void *));
68 1.10 fvdl int umap_lock __P((void *));
69 1.10 fvdl int umap_unlock __P((void *));
70 1.13 bouyer int umap_open __P((void *));
71 1.12 sommerfe int umap_fsync __P((void *));
72 1.10 fvdl
73 1.10 fvdl extern int null_bypass __P((void *));
74 1.5 christos
75 1.5 christos /*
76 1.5 christos * Global vfs data structures
77 1.5 christos */
78 1.5 christos /*
79 1.5 christos * XXX - strategy, bwrite are hand coded currently. They should
80 1.5 christos * go away with a merged buffer/block cache.
81 1.5 christos *
82 1.5 christos */
83 1.5 christos int (**umap_vnodeop_p) __P((void *));
84 1.5 christos struct vnodeopv_entry_desc umap_vnodeop_entries[] = {
85 1.5 christos { &vop_default_desc, umap_bypass },
86 1.5 christos
87 1.5 christos { &vop_getattr_desc, umap_getattr },
88 1.10 fvdl { &vop_lock_desc, umap_lock },
89 1.10 fvdl { &vop_unlock_desc, umap_unlock },
90 1.12 sommerfe { &vop_fsync_desc, umap_fsync },
91 1.5 christos { &vop_inactive_desc, umap_inactive },
92 1.5 christos { &vop_reclaim_desc, umap_reclaim },
93 1.5 christos { &vop_print_desc, umap_print },
94 1.13 bouyer
95 1.13 bouyer { &vop_open_desc, umap_open }, /* mount option handling */
96 1.13 bouyer
97 1.5 christos { &vop_rename_desc, umap_rename },
98 1.5 christos
99 1.5 christos { &vop_strategy_desc, umap_strategy },
100 1.5 christos { &vop_bwrite_desc, umap_bwrite },
101 1.5 christos
102 1.5 christos { (struct vnodeop_desc*) NULL, (int(*) __P((void *))) NULL }
103 1.5 christos };
104 1.9 thorpej struct vnodeopv_desc umapfs_vnodeop_opv_desc =
105 1.5 christos { &umap_vnodeop_p, umap_vnodeop_entries };
106 1.5 christos
107 1.1 mycroft /*
108 1.1 mycroft * This is the 10-Apr-92 bypass routine.
109 1.1 mycroft * See null_vnops.c:null_bypass for more details.
110 1.1 mycroft */
111 1.1 mycroft int
112 1.5 christos umap_bypass(v)
113 1.5 christos void *v;
114 1.5 christos {
115 1.1 mycroft struct vop_generic_args /* {
116 1.1 mycroft struct vnodeop_desc *a_desc;
117 1.1 mycroft <other random data follows, presumably>
118 1.5 christos } */ *ap = v;
119 1.1 mycroft struct ucred **credpp = 0, *credp = 0;
120 1.5 christos struct ucred *savecredp = 0, *savecompcredp = 0;
121 1.1 mycroft struct ucred *compcredp = 0;
122 1.1 mycroft struct vnode **this_vp_p;
123 1.1 mycroft int error;
124 1.1 mycroft struct vnode *old_vps[VDESC_MAX_VPS];
125 1.1 mycroft struct vnode *vp1 = 0;
126 1.1 mycroft struct vnode **vps_p[VDESC_MAX_VPS];
127 1.1 mycroft struct vnode ***vppp;
128 1.1 mycroft struct vnodeop_desc *descp = ap->a_desc;
129 1.1 mycroft int reles, i;
130 1.1 mycroft struct componentname **compnamepp = 0;
131 1.1 mycroft
132 1.1 mycroft if (umap_bug_bypass)
133 1.8 christos printf("umap_bypass: %s\n", descp->vdesc_name);
134 1.1 mycroft
135 1.1 mycroft #ifdef SAFETY
136 1.1 mycroft /*
137 1.1 mycroft * We require at least one vp.
138 1.1 mycroft */
139 1.1 mycroft if (descp->vdesc_vp_offsets == NULL ||
140 1.1 mycroft descp->vdesc_vp_offsets[0] == VDESC_NO_OFFSET)
141 1.1 mycroft panic ("umap_bypass: no vp's in map.\n");
142 1.1 mycroft #endif
143 1.1 mycroft
144 1.1 mycroft /*
145 1.1 mycroft * Map the vnodes going in.
146 1.1 mycroft * Later, we'll invoke the operation based on
147 1.1 mycroft * the first mapped vnode's operation vector.
148 1.1 mycroft */
149 1.1 mycroft reles = descp->vdesc_flags;
150 1.1 mycroft for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
151 1.1 mycroft if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
152 1.1 mycroft break; /* bail out at end of list */
153 1.1 mycroft vps_p[i] = this_vp_p =
154 1.1 mycroft VOPARG_OFFSETTO(struct vnode**, descp->vdesc_vp_offsets[i], ap);
155 1.1 mycroft
156 1.1 mycroft if (i == 0) {
157 1.1 mycroft vp1 = *vps_p[0];
158 1.1 mycroft }
159 1.1 mycroft
160 1.1 mycroft /*
161 1.1 mycroft * We're not guaranteed that any but the first vnode
162 1.1 mycroft * are of our type. Check for and don't map any
163 1.1 mycroft * that aren't. (Must map first vp or vclean fails.)
164 1.1 mycroft */
165 1.1 mycroft
166 1.11 perseant if (i && ((*this_vp_p)==NULL || (*this_vp_p)->v_op != umap_vnodeop_p)) {
167 1.1 mycroft old_vps[i] = NULL;
168 1.1 mycroft } else {
169 1.1 mycroft old_vps[i] = *this_vp_p;
170 1.1 mycroft *(vps_p[i]) = UMAPVPTOLOWERVP(*this_vp_p);
171 1.1 mycroft if (reles & 1)
172 1.1 mycroft VREF(*this_vp_p);
173 1.1 mycroft }
174 1.1 mycroft
175 1.1 mycroft }
176 1.1 mycroft
177 1.1 mycroft /*
178 1.1 mycroft * Fix the credentials. (That's the purpose of this layer.)
179 1.1 mycroft */
180 1.1 mycroft
181 1.1 mycroft if (descp->vdesc_cred_offset != VDESC_NO_OFFSET) {
182 1.1 mycroft
183 1.1 mycroft credpp = VOPARG_OFFSETTO(struct ucred**,
184 1.1 mycroft descp->vdesc_cred_offset, ap);
185 1.1 mycroft
186 1.1 mycroft /* Save old values */
187 1.1 mycroft
188 1.1 mycroft savecredp = *credpp;
189 1.1 mycroft if (savecredp != NOCRED)
190 1.1 mycroft *credpp = crdup(savecredp);
191 1.1 mycroft credp = *credpp;
192 1.1 mycroft
193 1.1 mycroft if (umap_bug_bypass && credp->cr_uid != 0)
194 1.8 christos printf("umap_bypass: user was %d, group %d\n",
195 1.1 mycroft credp->cr_uid, credp->cr_gid);
196 1.1 mycroft
197 1.1 mycroft /* Map all ids in the credential structure. */
198 1.1 mycroft
199 1.1 mycroft umap_mapids(vp1->v_mount, credp);
200 1.1 mycroft
201 1.1 mycroft if (umap_bug_bypass && credp->cr_uid != 0)
202 1.8 christos printf("umap_bypass: user now %d, group %d\n",
203 1.1 mycroft credp->cr_uid, credp->cr_gid);
204 1.1 mycroft }
205 1.1 mycroft
206 1.1 mycroft /* BSD often keeps a credential in the componentname structure
207 1.1 mycroft * for speed. If there is one, it better get mapped, too.
208 1.1 mycroft */
209 1.1 mycroft
210 1.1 mycroft if (descp->vdesc_componentname_offset != VDESC_NO_OFFSET) {
211 1.1 mycroft
212 1.1 mycroft compnamepp = VOPARG_OFFSETTO(struct componentname**,
213 1.1 mycroft descp->vdesc_componentname_offset, ap);
214 1.1 mycroft
215 1.1 mycroft savecompcredp = (*compnamepp)->cn_cred;
216 1.1 mycroft if (savecompcredp != NOCRED)
217 1.1 mycroft (*compnamepp)->cn_cred = crdup(savecompcredp);
218 1.1 mycroft compcredp = (*compnamepp)->cn_cred;
219 1.1 mycroft
220 1.1 mycroft if (umap_bug_bypass && compcredp->cr_uid != 0)
221 1.8 christos printf("umap_bypass: component credit user was %d, group %d\n",
222 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
223 1.1 mycroft
224 1.1 mycroft /* Map all ids in the credential structure. */
225 1.1 mycroft
226 1.1 mycroft umap_mapids(vp1->v_mount, compcredp);
227 1.1 mycroft
228 1.1 mycroft if (umap_bug_bypass && compcredp->cr_uid != 0)
229 1.8 christos printf("umap_bypass: component credit user now %d, group %d\n",
230 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
231 1.1 mycroft }
232 1.1 mycroft
233 1.1 mycroft /*
234 1.1 mycroft * Call the operation on the lower layer
235 1.1 mycroft * with the modified argument structure.
236 1.1 mycroft */
237 1.1 mycroft error = VCALL(*(vps_p[0]), descp->vdesc_offset, ap);
238 1.1 mycroft
239 1.1 mycroft /*
240 1.1 mycroft * Maintain the illusion of call-by-value
241 1.1 mycroft * by restoring vnodes in the argument structure
242 1.1 mycroft * to their original value.
243 1.1 mycroft */
244 1.1 mycroft reles = descp->vdesc_flags;
245 1.1 mycroft for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
246 1.1 mycroft if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
247 1.1 mycroft break; /* bail out at end of list */
248 1.1 mycroft if (old_vps[i]) {
249 1.1 mycroft *(vps_p[i]) = old_vps[i];
250 1.1 mycroft if (reles & 1)
251 1.1 mycroft vrele(*(vps_p[i]));
252 1.1 mycroft };
253 1.1 mycroft };
254 1.1 mycroft
255 1.1 mycroft /*
256 1.1 mycroft * Map the possible out-going vpp
257 1.1 mycroft * (Assumes that the lower layer always returns
258 1.1 mycroft * a VREF'ed vpp unless it gets an error.)
259 1.1 mycroft */
260 1.1 mycroft if (descp->vdesc_vpp_offset != VDESC_NO_OFFSET &&
261 1.1 mycroft !(descp->vdesc_flags & VDESC_NOMAP_VPP) &&
262 1.1 mycroft !error) {
263 1.1 mycroft if (descp->vdesc_flags & VDESC_VPP_WILLRELE)
264 1.1 mycroft goto out;
265 1.1 mycroft vppp = VOPARG_OFFSETTO(struct vnode***,
266 1.1 mycroft descp->vdesc_vpp_offset, ap);
267 1.1 mycroft error = umap_node_create(old_vps[0]->v_mount, **vppp, *vppp);
268 1.1 mycroft };
269 1.1 mycroft
270 1.1 mycroft out:
271 1.1 mycroft /*
272 1.1 mycroft * Free duplicate cred structure and restore old one.
273 1.1 mycroft */
274 1.1 mycroft if (descp->vdesc_cred_offset != VDESC_NO_OFFSET) {
275 1.1 mycroft if (umap_bug_bypass && credp && credp->cr_uid != 0)
276 1.8 christos printf("umap_bypass: returning-user was %d\n",
277 1.7 christos credp->cr_uid);
278 1.1 mycroft
279 1.1 mycroft if (savecredp != NOCRED) {
280 1.1 mycroft crfree(credp);
281 1.1 mycroft *credpp = savecredp;
282 1.1 mycroft if (umap_bug_bypass && credpp && (*credpp)->cr_uid != 0)
283 1.8 christos printf("umap_bypass: returning-user now %d\n\n",
284 1.1 mycroft savecredp->cr_uid);
285 1.1 mycroft }
286 1.1 mycroft }
287 1.1 mycroft
288 1.1 mycroft if (descp->vdesc_componentname_offset != VDESC_NO_OFFSET) {
289 1.1 mycroft if (umap_bug_bypass && compcredp && compcredp->cr_uid != 0)
290 1.8 christos printf("umap_bypass: returning-component-user was %d\n",
291 1.7 christos compcredp->cr_uid);
292 1.1 mycroft
293 1.1 mycroft if (savecompcredp != NOCRED) {
294 1.1 mycroft crfree(compcredp);
295 1.1 mycroft (*compnamepp)->cn_cred = savecompcredp;
296 1.1 mycroft if (umap_bug_bypass && credpp && (*credpp)->cr_uid != 0)
297 1.8 christos printf("umap_bypass: returning-component-user now %d\n",
298 1.1 mycroft savecompcredp->cr_uid);
299 1.1 mycroft }
300 1.1 mycroft }
301 1.1 mycroft
302 1.1 mycroft return (error);
303 1.1 mycroft }
304 1.1 mycroft
305 1.10 fvdl /*
306 1.10 fvdl * We need to process our own vnode lock and then clear the
307 1.10 fvdl * interlock flag as it applies only to our vnode, not the
308 1.10 fvdl * vnodes below us on the stack.
309 1.10 fvdl */
310 1.10 fvdl int
311 1.10 fvdl umap_lock(v)
312 1.10 fvdl void *v;
313 1.10 fvdl {
314 1.10 fvdl struct vop_lock_args /* {
315 1.10 fvdl struct vnode *a_vp;
316 1.10 fvdl int a_flags;
317 1.10 fvdl struct proc *a_p;
318 1.10 fvdl } */ *ap = v;
319 1.10 fvdl
320 1.10 fvdl genfs_nolock(ap);
321 1.10 fvdl if ((ap->a_flags & LK_TYPE_MASK) == LK_DRAIN)
322 1.10 fvdl return (0);
323 1.10 fvdl ap->a_flags &= ~LK_INTERLOCK;
324 1.10 fvdl return (null_bypass(ap));
325 1.10 fvdl }
326 1.10 fvdl
327 1.10 fvdl /*
328 1.10 fvdl * We need to process our own vnode unlock and then clear the
329 1.10 fvdl * interlock flag as it applies only to our vnode, not the
330 1.10 fvdl * vnodes below us on the stack.
331 1.10 fvdl */
332 1.10 fvdl int
333 1.10 fvdl umap_unlock(v)
334 1.10 fvdl void *v;
335 1.10 fvdl {
336 1.10 fvdl struct vop_unlock_args /* {
337 1.10 fvdl struct vnode *a_vp;
338 1.10 fvdl int a_flags;
339 1.10 fvdl struct proc *a_p;
340 1.10 fvdl } */ *ap = v;
341 1.10 fvdl
342 1.10 fvdl genfs_nounlock(ap);
343 1.10 fvdl ap->a_flags &= ~LK_INTERLOCK;
344 1.10 fvdl return (null_bypass(ap));
345 1.12 sommerfe }
346 1.12 sommerfe
347 1.12 sommerfe /*
348 1.12 sommerfe * If vinvalbuf is calling us, it's a "shallow fsync" -- don't bother
349 1.12 sommerfe * syncing the underlying vnodes, since (a) they'll be fsync'ed when
350 1.12 sommerfe * reclaimed and (b) we could deadlock if they're locked; otherwise,
351 1.12 sommerfe * pass it through to the underlying layer.
352 1.12 sommerfe */
353 1.12 sommerfe
354 1.12 sommerfe int
355 1.12 sommerfe umap_fsync(v)
356 1.12 sommerfe void *v;
357 1.12 sommerfe {
358 1.12 sommerfe struct vop_fsync_args /* {
359 1.12 sommerfe struct vnode *a_vp;
360 1.12 sommerfe struct ucred *a_cred;
361 1.12 sommerfe int a_flags;
362 1.12 sommerfe struct proc *a_p;
363 1.12 sommerfe } */ *ap = v;
364 1.12 sommerfe
365 1.12 sommerfe if (ap->a_flags & FSYNC_RECLAIM)
366 1.12 sommerfe return 0;
367 1.12 sommerfe
368 1.12 sommerfe return (umap_bypass(ap));
369 1.10 fvdl }
370 1.1 mycroft
371 1.1 mycroft /*
372 1.1 mycroft * We handle getattr to change the fsid.
373 1.1 mycroft */
374 1.1 mycroft int
375 1.5 christos umap_getattr(v)
376 1.5 christos void *v;
377 1.5 christos {
378 1.1 mycroft struct vop_getattr_args /* {
379 1.1 mycroft struct vnode *a_vp;
380 1.1 mycroft struct vattr *a_vap;
381 1.1 mycroft struct ucred *a_cred;
382 1.1 mycroft struct proc *a_p;
383 1.5 christos } */ *ap = v;
384 1.1 mycroft uid_t uid;
385 1.1 mycroft gid_t gid;
386 1.1 mycroft int error, tmpid, nentries, gnentries;
387 1.4 cgd u_long (*mapdata)[2];
388 1.4 cgd u_long (*gmapdata)[2];
389 1.1 mycroft struct vnode **vp1p;
390 1.1 mycroft struct vnodeop_desc *descp = ap->a_desc;
391 1.1 mycroft
392 1.5 christos if ((error = umap_bypass(ap)) != 0)
393 1.1 mycroft return (error);
394 1.1 mycroft /* Requires that arguments be restored. */
395 1.1 mycroft ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0];
396 1.1 mycroft
397 1.1 mycroft /*
398 1.1 mycroft * Umap needs to map the uid and gid returned by a stat
399 1.1 mycroft * into the proper values for this site. This involves
400 1.1 mycroft * finding the returned uid in the mapping information,
401 1.1 mycroft * translating it into the uid on the other end,
402 1.1 mycroft * and filling in the proper field in the vattr
403 1.1 mycroft * structure pointed to by ap->a_vap. The group
404 1.1 mycroft * is easier, since currently all groups will be
405 1.1 mycroft * translate to the NULLGROUP.
406 1.1 mycroft */
407 1.1 mycroft
408 1.1 mycroft /* Find entry in map */
409 1.1 mycroft
410 1.1 mycroft uid = ap->a_vap->va_uid;
411 1.1 mycroft gid = ap->a_vap->va_gid;
412 1.1 mycroft if (umap_bug_bypass)
413 1.8 christos printf("umap_getattr: mapped uid = %d, mapped gid = %d\n", uid,
414 1.1 mycroft gid);
415 1.1 mycroft
416 1.1 mycroft vp1p = VOPARG_OFFSETTO(struct vnode**, descp->vdesc_vp_offsets[0], ap);
417 1.1 mycroft nentries = MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_nentries;
418 1.1 mycroft mapdata = (MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_mapdata);
419 1.1 mycroft gnentries = MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_gnentries;
420 1.1 mycroft gmapdata = (MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_gmapdata);
421 1.1 mycroft
422 1.1 mycroft /* Reverse map the uid for the vnode. Since it's a reverse
423 1.1 mycroft map, we can't use umap_mapids() to do it. */
424 1.1 mycroft
425 1.1 mycroft tmpid = umap_reverse_findid(uid, mapdata, nentries);
426 1.1 mycroft
427 1.1 mycroft if (tmpid != -1) {
428 1.1 mycroft ap->a_vap->va_uid = (uid_t) tmpid;
429 1.1 mycroft if (umap_bug_bypass)
430 1.8 christos printf("umap_getattr: original uid = %d\n", uid);
431 1.1 mycroft } else
432 1.1 mycroft ap->a_vap->va_uid = (uid_t) NOBODY;
433 1.1 mycroft
434 1.1 mycroft /* Reverse map the gid for the vnode. */
435 1.1 mycroft
436 1.1 mycroft tmpid = umap_reverse_findid(gid, gmapdata, gnentries);
437 1.1 mycroft
438 1.1 mycroft if (tmpid != -1) {
439 1.1 mycroft ap->a_vap->va_gid = (gid_t) tmpid;
440 1.1 mycroft if (umap_bug_bypass)
441 1.8 christos printf("umap_getattr: original gid = %d\n", gid);
442 1.1 mycroft } else
443 1.1 mycroft ap->a_vap->va_gid = (gid_t) NULLGROUP;
444 1.1 mycroft
445 1.1 mycroft return (0);
446 1.13 bouyer }
447 1.13 bouyer
448 1.13 bouyer /*
449 1.13 bouyer * We must handle open to be able to catch MNT_NODEV and friends.
450 1.13 bouyer */
451 1.13 bouyer int
452 1.13 bouyer umap_open(v)
453 1.13 bouyer void *v;
454 1.13 bouyer {
455 1.13 bouyer struct vop_open_args *ap = v;
456 1.13 bouyer struct vnode *vp = ap->a_vp;
457 1.13 bouyer enum vtype lower_type = UMAPVPTOLOWERVP(vp)->v_type;
458 1.13 bouyer
459 1.13 bouyer
460 1.13 bouyer if (((lower_type == VBLK) || (lower_type == VCHR)) &&
461 1.13 bouyer (vp->v_mount->mnt_flag & MNT_NODEV))
462 1.13 bouyer return ENXIO;
463 1.13 bouyer
464 1.13 bouyer return umap_bypass(ap);
465 1.1 mycroft }
466 1.1 mycroft
467 1.5 christos /*ARGSUSED*/
468 1.1 mycroft int
469 1.5 christos umap_inactive(v)
470 1.5 christos void *v;
471 1.1 mycroft {
472 1.10 fvdl struct vop_inactive_args /* {
473 1.10 fvdl struct vnode *a_vp;
474 1.10 fvdl struct proc *a_p;
475 1.10 fvdl } */ *ap = v;
476 1.1 mycroft /*
477 1.1 mycroft * Do nothing (and _don't_ bypass).
478 1.1 mycroft * Wait to vrele lowervp until reclaim,
479 1.1 mycroft * so that until then our umap_node is in the
480 1.1 mycroft * cache and reusable.
481 1.1 mycroft *
482 1.1 mycroft */
483 1.10 fvdl VOP_UNLOCK(ap->a_vp, 0);
484 1.1 mycroft return (0);
485 1.1 mycroft }
486 1.1 mycroft
487 1.1 mycroft int
488 1.5 christos umap_reclaim(v)
489 1.5 christos void *v;
490 1.5 christos {
491 1.1 mycroft struct vop_reclaim_args /* {
492 1.1 mycroft struct vnode *a_vp;
493 1.5 christos } */ *ap = v;
494 1.1 mycroft struct vnode *vp = ap->a_vp;
495 1.1 mycroft struct umap_node *xp = VTOUMAP(vp);
496 1.1 mycroft struct vnode *lowervp = xp->umap_lowervp;
497 1.1 mycroft
498 1.1 mycroft /* After this assignment, this node will not be re-used. */
499 1.1 mycroft xp->umap_lowervp = NULL;
500 1.3 mycroft LIST_REMOVE(xp, umap_hash);
501 1.1 mycroft FREE(vp->v_data, M_TEMP);
502 1.1 mycroft vp->v_data = NULL;
503 1.1 mycroft vrele(lowervp);
504 1.1 mycroft return (0);
505 1.1 mycroft }
506 1.1 mycroft
507 1.1 mycroft int
508 1.5 christos umap_strategy(v)
509 1.5 christos void *v;
510 1.5 christos {
511 1.1 mycroft struct vop_strategy_args /* {
512 1.1 mycroft struct buf *a_bp;
513 1.5 christos } */ *ap = v;
514 1.1 mycroft struct buf *bp = ap->a_bp;
515 1.1 mycroft int error;
516 1.1 mycroft struct vnode *savedvp;
517 1.1 mycroft
518 1.1 mycroft savedvp = bp->b_vp;
519 1.1 mycroft bp->b_vp = UMAPVPTOLOWERVP(bp->b_vp);
520 1.1 mycroft
521 1.1 mycroft error = VOP_STRATEGY(ap->a_bp);
522 1.1 mycroft
523 1.1 mycroft bp->b_vp = savedvp;
524 1.1 mycroft
525 1.1 mycroft return (error);
526 1.1 mycroft }
527 1.1 mycroft
528 1.1 mycroft int
529 1.5 christos umap_bwrite(v)
530 1.5 christos void *v;
531 1.5 christos {
532 1.1 mycroft struct vop_bwrite_args /* {
533 1.1 mycroft struct buf *a_bp;
534 1.5 christos } */ *ap = v;
535 1.1 mycroft struct buf *bp = ap->a_bp;
536 1.1 mycroft int error;
537 1.1 mycroft struct vnode *savedvp;
538 1.1 mycroft
539 1.1 mycroft savedvp = bp->b_vp;
540 1.1 mycroft bp->b_vp = UMAPVPTOLOWERVP(bp->b_vp);
541 1.1 mycroft
542 1.1 mycroft error = VOP_BWRITE(ap->a_bp);
543 1.1 mycroft
544 1.1 mycroft bp->b_vp = savedvp;
545 1.1 mycroft
546 1.1 mycroft return (error);
547 1.1 mycroft }
548 1.1 mycroft
549 1.1 mycroft
550 1.1 mycroft int
551 1.5 christos umap_print(v)
552 1.5 christos void *v;
553 1.5 christos {
554 1.1 mycroft struct vop_print_args /* {
555 1.1 mycroft struct vnode *a_vp;
556 1.5 christos } */ *ap = v;
557 1.1 mycroft struct vnode *vp = ap->a_vp;
558 1.8 christos printf("\ttag VT_UMAPFS, vp=%p, lowervp=%p\n", vp,
559 1.6 cgd UMAPVPTOLOWERVP(vp));
560 1.1 mycroft return (0);
561 1.1 mycroft }
562 1.1 mycroft
563 1.1 mycroft int
564 1.5 christos umap_rename(v)
565 1.5 christos void *v;
566 1.5 christos {
567 1.1 mycroft struct vop_rename_args /* {
568 1.1 mycroft struct vnode *a_fdvp;
569 1.1 mycroft struct vnode *a_fvp;
570 1.1 mycroft struct componentname *a_fcnp;
571 1.1 mycroft struct vnode *a_tdvp;
572 1.1 mycroft struct vnode *a_tvp;
573 1.1 mycroft struct componentname *a_tcnp;
574 1.5 christos } */ *ap = v;
575 1.1 mycroft int error;
576 1.1 mycroft struct componentname *compnamep;
577 1.1 mycroft struct ucred *compcredp, *savecompcredp;
578 1.1 mycroft struct vnode *vp;
579 1.1 mycroft
580 1.1 mycroft /*
581 1.1 mycroft * Rename is irregular, having two componentname structures.
582 1.1 mycroft * We need to map the cre in the second structure,
583 1.1 mycroft * and then bypass takes care of the rest.
584 1.1 mycroft */
585 1.1 mycroft
586 1.1 mycroft vp = ap->a_fdvp;
587 1.1 mycroft compnamep = ap->a_tcnp;
588 1.1 mycroft compcredp = compnamep->cn_cred;
589 1.1 mycroft
590 1.1 mycroft savecompcredp = compcredp;
591 1.1 mycroft compcredp = compnamep->cn_cred = crdup(savecompcredp);
592 1.1 mycroft
593 1.1 mycroft if (umap_bug_bypass && compcredp->cr_uid != 0)
594 1.8 christos printf("umap_rename: rename component credit user was %d, group %d\n",
595 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
596 1.1 mycroft
597 1.1 mycroft /* Map all ids in the credential structure. */
598 1.1 mycroft
599 1.1 mycroft umap_mapids(vp->v_mount, compcredp);
600 1.1 mycroft
601 1.1 mycroft if (umap_bug_bypass && compcredp->cr_uid != 0)
602 1.8 christos printf("umap_rename: rename component credit user now %d, group %d\n",
603 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
604 1.1 mycroft
605 1.1 mycroft error = umap_bypass(ap);
606 1.1 mycroft
607 1.1 mycroft /* Restore the additional mapped componentname cred structure. */
608 1.1 mycroft
609 1.1 mycroft crfree(compcredp);
610 1.1 mycroft compnamep->cn_cred = savecompcredp;
611 1.1 mycroft
612 1.1 mycroft return error;
613 1.1 mycroft }
614