coda_vnops.c revision 1.50.4.1 1 1.1 rvb /*
2 1.3 rvb coda_create/vn_open
3 1.2 rvb remove/unlink
4 1.2 rvb link
5 1.2 rvb mkdir
6 1.2 rvb rmdir
7 1.2 rvb symlink
8 1.1 rvb */
9 1.50.4.1 ad /* $NetBSD: coda_vnops.c,v 1.50.4.1 2007/01/12 01:04:02 ad Exp $ */
10 1.1 rvb
11 1.2 rvb /*
12 1.40 perry *
13 1.2 rvb * Coda: an Experimental Distributed File System
14 1.2 rvb * Release 3.1
15 1.40 perry *
16 1.2 rvb * Copyright (c) 1987-1998 Carnegie Mellon University
17 1.2 rvb * All Rights Reserved
18 1.40 perry *
19 1.2 rvb * Permission to use, copy, modify and distribute this software and its
20 1.2 rvb * documentation is hereby granted, provided that both the copyright
21 1.2 rvb * notice and this permission notice appear in all copies of the
22 1.2 rvb * software, derivative works or modified versions, and any portions
23 1.2 rvb * thereof, and that both notices appear in supporting documentation, and
24 1.2 rvb * that credit is given to Carnegie Mellon University in all documents
25 1.2 rvb * and publicity pertaining to direct or indirect use of this code or its
26 1.2 rvb * derivatives.
27 1.40 perry *
28 1.2 rvb * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
29 1.2 rvb * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
30 1.2 rvb * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
31 1.2 rvb * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
32 1.2 rvb * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
33 1.2 rvb * ANY DERIVATIVE WORK.
34 1.40 perry *
35 1.2 rvb * Carnegie Mellon encourages users of this software to return any
36 1.2 rvb * improvements or extensions that they make, and to grant Carnegie
37 1.2 rvb * Mellon the rights to redistribute these changes without encumbrance.
38 1.40 perry *
39 1.40 perry * @(#) coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
40 1.2 rvb */
41 1.1 rvb
42 1.40 perry /*
43 1.1 rvb * Mach Operating System
44 1.1 rvb * Copyright (c) 1990 Carnegie-Mellon University
45 1.1 rvb * Copyright (c) 1989 Carnegie-Mellon University
46 1.1 rvb * All rights reserved. The CMU software License Agreement specifies
47 1.1 rvb * the terms and conditions for use and redistribution.
48 1.1 rvb */
49 1.1 rvb
50 1.1 rvb /*
51 1.1 rvb * This code was written for the Coda file system at Carnegie Mellon
52 1.1 rvb * University. Contributers include David Steere, James Kistler, and
53 1.40 perry * M. Satyanarayanan.
54 1.1 rvb */
55 1.27 lukem
56 1.27 lukem #include <sys/cdefs.h>
57 1.50.4.1 ad __KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.50.4.1 2007/01/12 01:04:02 ad Exp $");
58 1.1 rvb
59 1.1 rvb #include <sys/param.h>
60 1.1 rvb #include <sys/systm.h>
61 1.1 rvb #include <sys/malloc.h>
62 1.1 rvb #include <sys/errno.h>
63 1.1 rvb #include <sys/acct.h>
64 1.1 rvb #include <sys/file.h>
65 1.1 rvb #include <sys/uio.h>
66 1.1 rvb #include <sys/namei.h>
67 1.1 rvb #include <sys/ioctl.h>
68 1.1 rvb #include <sys/mount.h>
69 1.1 rvb #include <sys/proc.h>
70 1.1 rvb #include <sys/select.h>
71 1.1 rvb #include <sys/user.h>
72 1.49 elad #include <sys/kauth.h>
73 1.49 elad
74 1.1 rvb #include <miscfs/genfs/genfs.h>
75 1.1 rvb
76 1.4 rvb #include <coda/coda.h>
77 1.4 rvb #include <coda/cnode.h>
78 1.4 rvb #include <coda/coda_vnops.h>
79 1.4 rvb #include <coda/coda_venus.h>
80 1.4 rvb #include <coda/coda_opstats.h>
81 1.4 rvb #include <coda/coda_subr.h>
82 1.4 rvb #include <coda/coda_namecache.h>
83 1.4 rvb #include <coda/coda_pioctl.h>
84 1.1 rvb
85 1.40 perry /*
86 1.1 rvb * These flags select various performance enhancements.
87 1.1 rvb */
88 1.3 rvb int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
89 1.3 rvb int coda_symlink_cache = 1; /* Set to cache symbolic link information */
90 1.3 rvb int coda_access_cache = 1; /* Set to handle some access checks directly */
91 1.1 rvb
92 1.1 rvb /* structure to keep track of vfs calls */
93 1.1 rvb
94 1.3 rvb struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
95 1.1 rvb
96 1.3 rvb #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
97 1.3 rvb #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
98 1.3 rvb #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
99 1.3 rvb #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
100 1.1 rvb
101 1.1 rvb /* What we are delaying for in printf */
102 1.3 rvb int coda_printf_delay = 0; /* in microseconds */
103 1.3 rvb int coda_vnop_print_entry = 0;
104 1.3 rvb static int coda_lockdebug = 0;
105 1.1 rvb
106 1.1 rvb /* Definition of the vfs operation vector */
107 1.1 rvb
108 1.1 rvb /*
109 1.1 rvb * Some NetBSD details:
110 1.40 perry *
111 1.3 rvb * coda_start is called at the end of the mount syscall.
112 1.3 rvb * coda_init is called at boot time.
113 1.1 rvb */
114 1.1 rvb
115 1.28 perry #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
116 1.1 rvb
117 1.1 rvb /* Definition of the vnode operation vector */
118 1.1 rvb
119 1.23 jdolecek const struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
120 1.3 rvb { &vop_default_desc, coda_vop_error },
121 1.3 rvb { &vop_lookup_desc, coda_lookup }, /* lookup */
122 1.3 rvb { &vop_create_desc, coda_create }, /* create */
123 1.5 rvb { &vop_mknod_desc, coda_vop_error }, /* mknod */
124 1.3 rvb { &vop_open_desc, coda_open }, /* open */
125 1.3 rvb { &vop_close_desc, coda_close }, /* close */
126 1.3 rvb { &vop_access_desc, coda_access }, /* access */
127 1.5 rvb { &vop_getattr_desc, coda_getattr }, /* getattr */
128 1.5 rvb { &vop_setattr_desc, coda_setattr }, /* setattr */
129 1.3 rvb { &vop_read_desc, coda_read }, /* read */
130 1.3 rvb { &vop_write_desc, coda_write }, /* write */
131 1.11 wrstuden { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
132 1.3 rvb { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
133 1.3 rvb /* 1.3 { &vop_select_desc, coda_select }, select */
134 1.24 chs { &vop_mmap_desc, genfs_mmap }, /* mmap */
135 1.3 rvb { &vop_fsync_desc, coda_fsync }, /* fsync */
136 1.3 rvb { &vop_remove_desc, coda_remove }, /* remove */
137 1.3 rvb { &vop_link_desc, coda_link }, /* link */
138 1.3 rvb { &vop_rename_desc, coda_rename }, /* rename */
139 1.3 rvb { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
140 1.3 rvb { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
141 1.5 rvb { &vop_symlink_desc, coda_symlink }, /* symlink */
142 1.5 rvb { &vop_readdir_desc, coda_readdir }, /* readdir */
143 1.3 rvb { &vop_readlink_desc, coda_readlink }, /* readlink */
144 1.5 rvb { &vop_abortop_desc, coda_abortop }, /* abortop */
145 1.3 rvb { &vop_inactive_desc, coda_inactive }, /* inactive */
146 1.5 rvb { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
147 1.3 rvb { &vop_lock_desc, coda_lock }, /* lock */
148 1.3 rvb { &vop_unlock_desc, coda_unlock }, /* unlock */
149 1.3 rvb { &vop_bmap_desc, coda_bmap }, /* bmap */
150 1.3 rvb { &vop_strategy_desc, coda_strategy }, /* strategy */
151 1.5 rvb { &vop_print_desc, coda_vop_error }, /* print */
152 1.3 rvb { &vop_islocked_desc, coda_islocked }, /* islocked */
153 1.3 rvb { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
154 1.5 rvb { &vop_advlock_desc, coda_vop_nop }, /* advlock */
155 1.3 rvb { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
156 1.3 rvb { &vop_lease_desc, coda_vop_nop }, /* lease */
157 1.1 rvb { &vop_seek_desc, genfs_seek }, /* seek */
158 1.5 rvb { &vop_poll_desc, genfs_poll }, /* poll */
159 1.25 chs { &vop_getpages_desc, coda_getpages }, /* getpages */
160 1.25 chs { &vop_putpages_desc, coda_putpages }, /* putpages */
161 1.24 chs { NULL, NULL }
162 1.1 rvb };
163 1.1 rvb
164 1.40 perry const struct vnodeopv_desc coda_vnodeop_opv_desc =
165 1.3 rvb { &coda_vnodeop_p, coda_vnodeop_entries };
166 1.1 rvb
167 1.1 rvb /* Definitions of NetBSD vnodeop interfaces */
168 1.1 rvb
169 1.1 rvb /* A generic panic: we were called with something we didn't define yet */
170 1.1 rvb int
171 1.3 rvb coda_vop_error(void *anon) {
172 1.1 rvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
173 1.1 rvb
174 1.9 rvb myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
175 1.1 rvb (*desc)->vdesc_name));
176 1.9 rvb /*
177 1.3 rvb panic("coda_nbsd_vop_error");
178 1.1 rvb return 0;
179 1.9 rvb */
180 1.9 rvb return EIO;
181 1.1 rvb }
182 1.1 rvb
183 1.1 rvb /* A generic do-nothing. For lease_check, advlock */
184 1.1 rvb int
185 1.3 rvb coda_vop_nop(void *anon) {
186 1.1 rvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
187 1.1 rvb
188 1.3 rvb if (codadebug) {
189 1.1 rvb myprintf(("Vnode operation %s called, but unsupported\n",
190 1.1 rvb (*desc)->vdesc_name));
191 1.40 perry }
192 1.1 rvb return (0);
193 1.1 rvb }
194 1.1 rvb
195 1.1 rvb int
196 1.3 rvb coda_vnodeopstats_init(void)
197 1.1 rvb {
198 1.17 augustss int i;
199 1.40 perry
200 1.3 rvb for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
201 1.3 rvb coda_vnodeopstats[i].opcode = i;
202 1.3 rvb coda_vnodeopstats[i].entries = 0;
203 1.3 rvb coda_vnodeopstats[i].sat_intrn = 0;
204 1.3 rvb coda_vnodeopstats[i].unsat_intrn = 0;
205 1.3 rvb coda_vnodeopstats[i].gen_intrn = 0;
206 1.1 rvb }
207 1.40 perry
208 1.1 rvb return 0;
209 1.1 rvb }
210 1.40 perry
211 1.40 perry /*
212 1.3 rvb * coda_open calls Venus to return the device, inode pair of the cache
213 1.3 rvb * file holding the data. Using iget, coda_open finds the vnode of the
214 1.1 rvb * cache file, and then opens it.
215 1.1 rvb */
216 1.1 rvb int
217 1.43 xtraeme coda_open(void *v)
218 1.1 rvb {
219 1.40 perry /*
220 1.1 rvb * NetBSD can pass the O_EXCL flag in mode, even though the check
221 1.1 rvb * has already happened. Venus defensively assumes that if open
222 1.1 rvb * is passed the EXCL, it must be a bug. We strip the flag here.
223 1.1 rvb */
224 1.1 rvb /* true args */
225 1.1 rvb struct vop_open_args *ap = v;
226 1.17 augustss struct vnode **vpp = &(ap->a_vp);
227 1.1 rvb struct cnode *cp = VTOC(*vpp);
228 1.1 rvb int flag = ap->a_mode & (~O_EXCL);
229 1.49 elad kauth_cred_t cred = ap->a_cred;
230 1.45 christos struct lwp *l = ap->a_l;
231 1.1 rvb /* locals */
232 1.1 rvb int error;
233 1.1 rvb struct vnode *vp;
234 1.1 rvb dev_t dev;
235 1.1 rvb ino_t inode;
236 1.1 rvb
237 1.3 rvb MARK_ENTRY(CODA_OPEN_STATS);
238 1.1 rvb
239 1.1 rvb /* Check for open of control file. */
240 1.1 rvb if (IS_CTL_VP(*vpp)) {
241 1.1 rvb /* XXX */
242 1.40 perry /* if (WRITABLE(flag)) */
243 1.1 rvb if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
244 1.3 rvb MARK_INT_FAIL(CODA_OPEN_STATS);
245 1.1 rvb return(EACCES);
246 1.1 rvb }
247 1.3 rvb MARK_INT_SAT(CODA_OPEN_STATS);
248 1.1 rvb return(0);
249 1.1 rvb }
250 1.1 rvb
251 1.45 christos error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, l, &dev, &inode);
252 1.1 rvb if (error)
253 1.1 rvb return (error);
254 1.1 rvb if (!error) {
255 1.42 christos CODADEBUG( CODA_OPEN,myprintf(("open: dev %d inode %llu result %d\n",
256 1.42 christos dev, (unsigned long long)inode, error)); )
257 1.1 rvb }
258 1.1 rvb
259 1.1 rvb /* Translate the <device, inode> pair for the cache file into
260 1.1 rvb an inode pointer. */
261 1.35 thorpej error = coda_grab_vnode(dev, inode, &vp);
262 1.1 rvb if (error)
263 1.1 rvb return (error);
264 1.1 rvb
265 1.1 rvb /* We get the vnode back locked in both Mach and NetBSD. Needs unlocked */
266 1.2 rvb VOP_UNLOCK(vp, 0);
267 1.1 rvb /* Keep a reference until the close comes in. */
268 1.40 perry vref(*vpp);
269 1.1 rvb
270 1.1 rvb /* Save the vnode pointer for the cache file. */
271 1.1 rvb if (cp->c_ovp == NULL) {
272 1.1 rvb cp->c_ovp = vp;
273 1.1 rvb } else {
274 1.1 rvb if (cp->c_ovp != vp)
275 1.3 rvb panic("coda_open: cp->c_ovp != ITOV(ip)");
276 1.1 rvb }
277 1.1 rvb cp->c_ocount++;
278 1.1 rvb
279 1.1 rvb /* Flush the attribute cached if writing the file. */
280 1.1 rvb if (flag & FWRITE) {
281 1.1 rvb cp->c_owrite++;
282 1.1 rvb cp->c_flags &= ~C_VATTR;
283 1.1 rvb }
284 1.1 rvb
285 1.1 rvb /* Save the <device, inode> pair for the cache file to speed
286 1.1 rvb up subsequent page_read's. */
287 1.1 rvb cp->c_device = dev;
288 1.1 rvb cp->c_inode = inode;
289 1.1 rvb
290 1.1 rvb /* Open the cache file. */
291 1.45 christos error = VOP_OPEN(vp, flag, cred, l);
292 1.1 rvb return(error);
293 1.1 rvb }
294 1.1 rvb
295 1.1 rvb /*
296 1.1 rvb * Close the cache file used for I/O and notify Venus.
297 1.1 rvb */
298 1.1 rvb int
299 1.43 xtraeme coda_close(void *v)
300 1.1 rvb {
301 1.1 rvb /* true args */
302 1.1 rvb struct vop_close_args *ap = v;
303 1.1 rvb struct vnode *vp = ap->a_vp;
304 1.1 rvb struct cnode *cp = VTOC(vp);
305 1.1 rvb int flag = ap->a_fflag;
306 1.49 elad kauth_cred_t cred = ap->a_cred;
307 1.45 christos struct lwp *l = ap->a_l;
308 1.1 rvb /* locals */
309 1.1 rvb int error;
310 1.1 rvb
311 1.3 rvb MARK_ENTRY(CODA_CLOSE_STATS);
312 1.1 rvb
313 1.1 rvb /* Check for close of control file. */
314 1.1 rvb if (IS_CTL_VP(vp)) {
315 1.3 rvb MARK_INT_SAT(CODA_CLOSE_STATS);
316 1.1 rvb return(0);
317 1.1 rvb }
318 1.1 rvb
319 1.1 rvb if (IS_UNMOUNTING(cp)) {
320 1.1 rvb if (cp->c_ovp) {
321 1.7 rvb #ifdef CODA_VERBOSE
322 1.3 rvb printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
323 1.1 rvb vp->v_usecount, cp->c_ovp, vp, cp);
324 1.5 rvb #endif
325 1.8 rvb #ifdef hmm
326 1.1 rvb vgone(cp->c_ovp);
327 1.8 rvb #else
328 1.14 wrstuden vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY);
329 1.45 christos VOP_CLOSE(cp->c_ovp, flag, cred, l); /* Do errors matter here? */
330 1.14 wrstuden vput(cp->c_ovp);
331 1.8 rvb #endif
332 1.1 rvb } else {
333 1.7 rvb #ifdef CODA_VERBOSE
334 1.3 rvb printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
335 1.5 rvb #endif
336 1.1 rvb }
337 1.1 rvb return ENODEV;
338 1.1 rvb } else {
339 1.14 wrstuden vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY);
340 1.45 christos VOP_CLOSE(cp->c_ovp, flag, cred, l); /* Do errors matter here? */
341 1.14 wrstuden vput(cp->c_ovp);
342 1.1 rvb }
343 1.1 rvb
344 1.1 rvb if (--cp->c_ocount == 0)
345 1.1 rvb cp->c_ovp = NULL;
346 1.1 rvb
347 1.1 rvb if (flag & FWRITE) /* file was opened for write */
348 1.1 rvb --cp->c_owrite;
349 1.1 rvb
350 1.45 christos error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, l);
351 1.1 rvb vrele(CTOV(cp));
352 1.1 rvb
353 1.3 rvb CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
354 1.1 rvb return(error);
355 1.1 rvb }
356 1.1 rvb
357 1.1 rvb int
358 1.43 xtraeme coda_read(void *v)
359 1.1 rvb {
360 1.1 rvb struct vop_read_args *ap = v;
361 1.1 rvb
362 1.1 rvb ENTRY;
363 1.3 rvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
364 1.47 yamt ap->a_ioflag, ap->a_cred, curlwp));
365 1.1 rvb }
366 1.1 rvb
367 1.1 rvb int
368 1.43 xtraeme coda_write(void *v)
369 1.1 rvb {
370 1.1 rvb struct vop_write_args *ap = v;
371 1.1 rvb
372 1.1 rvb ENTRY;
373 1.3 rvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
374 1.47 yamt ap->a_ioflag, ap->a_cred, curlwp));
375 1.1 rvb }
376 1.1 rvb
377 1.1 rvb int
378 1.43 xtraeme coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
379 1.49 elad kauth_cred_t cred, struct lwp *l)
380 1.40 perry {
381 1.1 rvb /* upcall decl */
382 1.1 rvb /* NOTE: container file operation!!! */
383 1.1 rvb /* locals */
384 1.1 rvb struct cnode *cp = VTOC(vp);
385 1.1 rvb struct vnode *cfvp = cp->c_ovp;
386 1.45 christos struct proc *p = l->l_proc;
387 1.1 rvb int opened_internally = 0;
388 1.1 rvb int error = 0;
389 1.1 rvb
390 1.3 rvb MARK_ENTRY(CODA_RDWR_STATS);
391 1.1 rvb
392 1.47 yamt CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %lu, %lld)\n", rw,
393 1.12 matt uiop->uio_iov->iov_base,
394 1.40 perry (unsigned long) uiop->uio_resid,
395 1.47 yamt (long long) uiop->uio_offset)); )
396 1.40 perry
397 1.1 rvb /* Check for rdwr of control object. */
398 1.1 rvb if (IS_CTL_VP(vp)) {
399 1.3 rvb MARK_INT_FAIL(CODA_RDWR_STATS);
400 1.1 rvb return(EINVAL);
401 1.1 rvb }
402 1.1 rvb
403 1.1 rvb /* Redirect the request to UFS. */
404 1.1 rvb
405 1.40 perry /*
406 1.1 rvb * If file is not already open this must be a page
407 1.1 rvb * {read,write} request. Iget the cache file's inode
408 1.1 rvb * pointer if we still have its <device, inode> pair.
409 1.1 rvb * Otherwise, we must do an internal open to derive the
410 1.40 perry * pair.
411 1.1 rvb */
412 1.1 rvb if (cfvp == NULL) {
413 1.40 perry /*
414 1.1 rvb * If we're dumping core, do the internal open. Otherwise
415 1.1 rvb * venus won't have the correct size of the core when
416 1.1 rvb * it's completely written.
417 1.1 rvb */
418 1.40 perry if (cp->c_inode != 0 && !(p && (p->p_acflag & ACORE))) {
419 1.35 thorpej error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
420 1.1 rvb if (error) {
421 1.3 rvb MARK_INT_FAIL(CODA_RDWR_STATS);
422 1.1 rvb return(error);
423 1.1 rvb }
424 1.40 perry /*
425 1.1 rvb * We get the vnode back locked in both Mach and
426 1.40 perry * NetBSD. Needs unlocked
427 1.1 rvb */
428 1.2 rvb VOP_UNLOCK(cfvp, 0);
429 1.1 rvb }
430 1.1 rvb else {
431 1.1 rvb opened_internally = 1;
432 1.3 rvb MARK_INT_GEN(CODA_OPEN_STATS);
433 1.40 perry error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
434 1.45 christos cred, l);
435 1.18 phil #ifdef CODA_VERBOSE
436 1.3 rvb printf("coda_rdwr: Internally Opening %p\n", vp);
437 1.18 phil #endif
438 1.1 rvb if (error) {
439 1.3 rvb MARK_INT_FAIL(CODA_RDWR_STATS);
440 1.1 rvb return(error);
441 1.1 rvb }
442 1.1 rvb cfvp = cp->c_ovp;
443 1.1 rvb }
444 1.1 rvb }
445 1.1 rvb
446 1.1 rvb /* Have UFS handle the call. */
447 1.37 drochner CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = %s, refcnt = %d\n",
448 1.37 drochner coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); )
449 1.1 rvb
450 1.1 rvb if (rw == UIO_READ) {
451 1.1 rvb error = VOP_READ(cfvp, uiop, ioflag, cred);
452 1.1 rvb } else {
453 1.1 rvb error = VOP_WRITE(cfvp, uiop, ioflag, cred);
454 1.1 rvb }
455 1.1 rvb
456 1.1 rvb if (error)
457 1.3 rvb MARK_INT_FAIL(CODA_RDWR_STATS);
458 1.1 rvb else
459 1.3 rvb MARK_INT_SAT(CODA_RDWR_STATS);
460 1.1 rvb
461 1.1 rvb /* Do an internal close if necessary. */
462 1.1 rvb if (opened_internally) {
463 1.3 rvb MARK_INT_GEN(CODA_CLOSE_STATS);
464 1.45 christos (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, l);
465 1.1 rvb }
466 1.1 rvb
467 1.1 rvb /* Invalidate cached attributes if writing. */
468 1.1 rvb if (rw == UIO_WRITE)
469 1.1 rvb cp->c_flags &= ~C_VATTR;
470 1.1 rvb return(error);
471 1.1 rvb }
472 1.1 rvb
473 1.1 rvb int
474 1.43 xtraeme coda_ioctl(void *v)
475 1.1 rvb {
476 1.1 rvb /* true args */
477 1.1 rvb struct vop_ioctl_args *ap = v;
478 1.1 rvb struct vnode *vp = ap->a_vp;
479 1.1 rvb int com = ap->a_command;
480 1.1 rvb caddr_t data = ap->a_data;
481 1.1 rvb int flag = ap->a_fflag;
482 1.49 elad kauth_cred_t cred = ap->a_cred;
483 1.45 christos struct lwp *l = ap->a_l;
484 1.1 rvb /* locals */
485 1.1 rvb int error;
486 1.1 rvb struct vnode *tvp;
487 1.1 rvb struct nameidata ndp;
488 1.1 rvb struct PioctlData *iap = (struct PioctlData *)data;
489 1.1 rvb
490 1.3 rvb MARK_ENTRY(CODA_IOCTL_STATS);
491 1.1 rvb
492 1.3 rvb CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
493 1.40 perry
494 1.1 rvb /* Don't check for operation on a dying object, for ctlvp it
495 1.1 rvb shouldn't matter */
496 1.40 perry
497 1.1 rvb /* Must be control object to succeed. */
498 1.1 rvb if (!IS_CTL_VP(vp)) {
499 1.3 rvb MARK_INT_FAIL(CODA_IOCTL_STATS);
500 1.3 rvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
501 1.1 rvb return (EOPNOTSUPP);
502 1.1 rvb }
503 1.1 rvb /* Look up the pathname. */
504 1.1 rvb
505 1.1 rvb /* Should we use the name cache here? It would get it from
506 1.1 rvb lookupname sooner or later anyway, right? */
507 1.1 rvb
508 1.41 christos NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE,
509 1.45 christos iap->path, l);
510 1.1 rvb error = namei(&ndp);
511 1.1 rvb tvp = ndp.ni_vp;
512 1.1 rvb
513 1.1 rvb if (error) {
514 1.3 rvb MARK_INT_FAIL(CODA_IOCTL_STATS);
515 1.3 rvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
516 1.1 rvb error));)
517 1.1 rvb return(error);
518 1.1 rvb }
519 1.1 rvb
520 1.40 perry /*
521 1.1 rvb * Make sure this is a coda style cnode, but it may be a
522 1.40 perry * different vfsp
523 1.1 rvb */
524 1.1 rvb /* XXX: this totally violates the comment about vtagtype in vnode.h */
525 1.3 rvb if (tvp->v_tag != VT_CODA) {
526 1.1 rvb vrele(tvp);
527 1.3 rvb MARK_INT_FAIL(CODA_IOCTL_STATS);
528 1.40 perry CODADEBUG(CODA_IOCTL,
529 1.40 perry myprintf(("coda_ioctl error: %s not a coda object\n",
530 1.1 rvb iap->path));)
531 1.1 rvb return(EINVAL);
532 1.1 rvb }
533 1.1 rvb
534 1.1 rvb if (iap->vi.in_size > VC_MAXDATASIZE) {
535 1.1 rvb vrele(tvp);
536 1.1 rvb return(EINVAL);
537 1.1 rvb }
538 1.45 christos error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, l);
539 1.1 rvb
540 1.1 rvb if (error)
541 1.3 rvb MARK_INT_FAIL(CODA_IOCTL_STATS);
542 1.1 rvb else
543 1.3 rvb CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
544 1.1 rvb
545 1.1 rvb vrele(tvp);
546 1.1 rvb return(error);
547 1.1 rvb }
548 1.1 rvb
549 1.1 rvb /*
550 1.1 rvb * To reduce the cost of a user-level venus;we cache attributes in
551 1.1 rvb * the kernel. Each cnode has storage allocated for an attribute. If
552 1.1 rvb * c_vattr is valid, return a reference to it. Otherwise, get the
553 1.1 rvb * attributes from venus and store them in the cnode. There is some
554 1.1 rvb * question if this method is a security leak. But I think that in
555 1.1 rvb * order to make this call, the user must have done a lookup and
556 1.40 perry * opened the file, and therefore should already have access.
557 1.1 rvb */
558 1.1 rvb int
559 1.43 xtraeme coda_getattr(void *v)
560 1.1 rvb {
561 1.1 rvb /* true args */
562 1.1 rvb struct vop_getattr_args *ap = v;
563 1.1 rvb struct vnode *vp = ap->a_vp;
564 1.1 rvb struct cnode *cp = VTOC(vp);
565 1.1 rvb struct vattr *vap = ap->a_vap;
566 1.49 elad kauth_cred_t cred = ap->a_cred;
567 1.45 christos struct lwp *l = ap->a_l;
568 1.1 rvb /* locals */
569 1.1 rvb int error;
570 1.1 rvb
571 1.3 rvb MARK_ENTRY(CODA_GETATTR_STATS);
572 1.1 rvb
573 1.1 rvb /* Check for getattr of control object. */
574 1.1 rvb if (IS_CTL_VP(vp)) {
575 1.3 rvb MARK_INT_FAIL(CODA_GETATTR_STATS);
576 1.1 rvb return(ENOENT);
577 1.1 rvb }
578 1.1 rvb
579 1.1 rvb /* Check to see if the attributes have already been cached */
580 1.40 perry if (VALID_VATTR(cp)) {
581 1.37 drochner CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: %s\n",
582 1.37 drochner coda_f2s(&cp->c_fid)));});
583 1.3 rvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
584 1.1 rvb print_vattr(&cp->c_vattr); );
585 1.40 perry
586 1.1 rvb *vap = cp->c_vattr;
587 1.3 rvb MARK_INT_SAT(CODA_GETATTR_STATS);
588 1.1 rvb return(0);
589 1.1 rvb }
590 1.1 rvb
591 1.45 christos error = venus_getattr(vtomi(vp), &cp->c_fid, cred, l, vap);
592 1.1 rvb
593 1.1 rvb if (!error) {
594 1.37 drochner CODADEBUG(CODA_GETATTR, myprintf(("getattr miss %s: result %d\n",
595 1.37 drochner coda_f2s(&cp->c_fid), error)); )
596 1.40 perry
597 1.3 rvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
598 1.1 rvb print_vattr(vap); );
599 1.40 perry
600 1.40 perry /* If not open for write, store attributes in cnode */
601 1.40 perry if ((cp->c_owrite == 0) && (coda_attr_cache)) {
602 1.1 rvb cp->c_vattr = *vap;
603 1.40 perry cp->c_flags |= C_VATTR;
604 1.1 rvb }
605 1.40 perry
606 1.1 rvb }
607 1.1 rvb return(error);
608 1.1 rvb }
609 1.1 rvb
610 1.1 rvb int
611 1.43 xtraeme coda_setattr(void *v)
612 1.1 rvb {
613 1.1 rvb /* true args */
614 1.1 rvb struct vop_setattr_args *ap = v;
615 1.17 augustss struct vnode *vp = ap->a_vp;
616 1.1 rvb struct cnode *cp = VTOC(vp);
617 1.17 augustss struct vattr *vap = ap->a_vap;
618 1.49 elad kauth_cred_t cred = ap->a_cred;
619 1.45 christos struct lwp *l = ap->a_l;
620 1.1 rvb /* locals */
621 1.1 rvb int error;
622 1.1 rvb
623 1.3 rvb MARK_ENTRY(CODA_SETATTR_STATS);
624 1.1 rvb
625 1.1 rvb /* Check for setattr of control object. */
626 1.1 rvb if (IS_CTL_VP(vp)) {
627 1.3 rvb MARK_INT_FAIL(CODA_SETATTR_STATS);
628 1.1 rvb return(ENOENT);
629 1.1 rvb }
630 1.1 rvb
631 1.3 rvb if (codadebug & CODADBGMSK(CODA_SETATTR)) {
632 1.1 rvb print_vattr(vap);
633 1.1 rvb }
634 1.45 christos error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, l);
635 1.1 rvb
636 1.1 rvb if (!error)
637 1.1 rvb cp->c_flags &= ~C_VATTR;
638 1.1 rvb
639 1.3 rvb CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
640 1.1 rvb return(error);
641 1.1 rvb }
642 1.1 rvb
643 1.1 rvb int
644 1.43 xtraeme coda_access(void *v)
645 1.1 rvb {
646 1.1 rvb /* true args */
647 1.1 rvb struct vop_access_args *ap = v;
648 1.1 rvb struct vnode *vp = ap->a_vp;
649 1.1 rvb struct cnode *cp = VTOC(vp);
650 1.1 rvb int mode = ap->a_mode;
651 1.49 elad kauth_cred_t cred = ap->a_cred;
652 1.45 christos struct lwp *l = ap->a_l;
653 1.1 rvb /* locals */
654 1.1 rvb int error;
655 1.1 rvb
656 1.3 rvb MARK_ENTRY(CODA_ACCESS_STATS);
657 1.1 rvb
658 1.1 rvb /* Check for access of control object. Only read access is
659 1.1 rvb allowed on it. */
660 1.1 rvb if (IS_CTL_VP(vp)) {
661 1.1 rvb /* bogus hack - all will be marked as successes */
662 1.3 rvb MARK_INT_SAT(CODA_ACCESS_STATS);
663 1.40 perry return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
664 1.1 rvb ? 0 : EACCES);
665 1.1 rvb }
666 1.1 rvb
667 1.1 rvb /*
668 1.40 perry * if the file is a directory, and we are checking exec (eg lookup)
669 1.40 perry * access, and the file is in the namecache, then the user must have
670 1.1 rvb * lookup access to it.
671 1.1 rvb */
672 1.3 rvb if (coda_access_cache) {
673 1.1 rvb if ((vp->v_type == VDIR) && (mode & VEXEC)) {
674 1.3 rvb if (coda_nc_lookup(cp, ".", 1, cred)) {
675 1.3 rvb MARK_INT_SAT(CODA_ACCESS_STATS);
676 1.1 rvb return(0); /* it was in the cache */
677 1.1 rvb }
678 1.1 rvb }
679 1.1 rvb }
680 1.1 rvb
681 1.45 christos error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, l);
682 1.1 rvb
683 1.1 rvb return(error);
684 1.1 rvb }
685 1.1 rvb
686 1.1 rvb /*
687 1.3 rvb * CODA abort op, called after namei() when a CREATE/DELETE isn't actually
688 1.3 rvb * done. If a buffer has been saved in anticipation of a coda_create or
689 1.3 rvb * a coda_remove, delete it.
690 1.1 rvb */
691 1.1 rvb /* ARGSUSED */
692 1.1 rvb int
693 1.43 xtraeme coda_abortop(void *v)
694 1.1 rvb {
695 1.1 rvb /* true args */
696 1.1 rvb struct vop_abortop_args /* {
697 1.1 rvb struct vnode *a_dvp;
698 1.1 rvb struct componentname *a_cnp;
699 1.1 rvb } */ *ap = v;
700 1.1 rvb /* upcall decl */
701 1.1 rvb /* locals */
702 1.1 rvb
703 1.1 rvb if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
704 1.20 thorpej PNBUF_PUT(ap->a_cnp->cn_pnbuf);
705 1.1 rvb return (0);
706 1.1 rvb }
707 1.1 rvb
708 1.1 rvb int
709 1.43 xtraeme coda_readlink(void *v)
710 1.1 rvb {
711 1.1 rvb /* true args */
712 1.1 rvb struct vop_readlink_args *ap = v;
713 1.1 rvb struct vnode *vp = ap->a_vp;
714 1.1 rvb struct cnode *cp = VTOC(vp);
715 1.1 rvb struct uio *uiop = ap->a_uio;
716 1.49 elad kauth_cred_t cred = ap->a_cred;
717 1.1 rvb /* locals */
718 1.47 yamt struct lwp *l = curlwp;
719 1.1 rvb int error;
720 1.1 rvb char *str;
721 1.1 rvb int len;
722 1.1 rvb
723 1.3 rvb MARK_ENTRY(CODA_READLINK_STATS);
724 1.1 rvb
725 1.1 rvb /* Check for readlink of control object. */
726 1.1 rvb if (IS_CTL_VP(vp)) {
727 1.3 rvb MARK_INT_FAIL(CODA_READLINK_STATS);
728 1.1 rvb return(ENOENT);
729 1.1 rvb }
730 1.1 rvb
731 1.3 rvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
732 1.1 rvb uiop->uio_rw = UIO_READ;
733 1.1 rvb error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
734 1.1 rvb if (error)
735 1.3 rvb MARK_INT_FAIL(CODA_READLINK_STATS);
736 1.1 rvb else
737 1.3 rvb MARK_INT_SAT(CODA_READLINK_STATS);
738 1.1 rvb return(error);
739 1.1 rvb }
740 1.1 rvb
741 1.45 christos error = venus_readlink(vtomi(vp), &cp->c_fid, cred, l, &str, &len);
742 1.1 rvb
743 1.1 rvb if (!error) {
744 1.1 rvb uiop->uio_rw = UIO_READ;
745 1.1 rvb error = uiomove(str, len, uiop);
746 1.1 rvb
747 1.3 rvb if (coda_symlink_cache) {
748 1.1 rvb cp->c_symlink = str;
749 1.1 rvb cp->c_symlen = len;
750 1.1 rvb cp->c_flags |= C_SYMLINK;
751 1.1 rvb } else
752 1.3 rvb CODA_FREE(str, len);
753 1.1 rvb }
754 1.1 rvb
755 1.3 rvb CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
756 1.1 rvb return(error);
757 1.1 rvb }
758 1.1 rvb
759 1.1 rvb int
760 1.43 xtraeme coda_fsync(void *v)
761 1.1 rvb {
762 1.1 rvb /* true args */
763 1.1 rvb struct vop_fsync_args *ap = v;
764 1.1 rvb struct vnode *vp = ap->a_vp;
765 1.1 rvb struct cnode *cp = VTOC(vp);
766 1.49 elad kauth_cred_t cred = ap->a_cred;
767 1.45 christos struct lwp *l = ap->a_l;
768 1.1 rvb /* locals */
769 1.1 rvb struct vnode *convp = cp->c_ovp;
770 1.1 rvb int error;
771 1.40 perry
772 1.3 rvb MARK_ENTRY(CODA_FSYNC_STATS);
773 1.1 rvb
774 1.1 rvb /* Check for fsync on an unmounting object */
775 1.1 rvb /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
776 1.1 rvb * after an unmount has been initiated. This is a Bad Thing,
777 1.1 rvb * which we have to avoid. Not a legitimate failure for stats.
778 1.1 rvb */
779 1.1 rvb if (IS_UNMOUNTING(cp)) {
780 1.1 rvb return(ENODEV);
781 1.1 rvb }
782 1.1 rvb
783 1.1 rvb /* Check for fsync of control object. */
784 1.1 rvb if (IS_CTL_VP(vp)) {
785 1.3 rvb MARK_INT_SAT(CODA_FSYNC_STATS);
786 1.1 rvb return(0);
787 1.1 rvb }
788 1.1 rvb
789 1.1 rvb if (convp)
790 1.45 christos VOP_FSYNC(convp, cred, MNT_WAIT, 0, 0, l);
791 1.1 rvb
792 1.1 rvb /*
793 1.1 rvb * We can expect fsync on any vnode at all if venus is pruging it.
794 1.1 rvb * Venus can't very well answer the fsync request, now can it?
795 1.1 rvb * Hopefully, it won't have to, because hopefully, venus preserves
796 1.1 rvb * the (possibly untrue) invariant that it never purges an open
797 1.1 rvb * vnode. Hopefully.
798 1.1 rvb */
799 1.1 rvb if (cp->c_flags & C_PURGING) {
800 1.1 rvb return(0);
801 1.1 rvb }
802 1.1 rvb
803 1.45 christos error = venus_fsync(vtomi(vp), &cp->c_fid, cred, l);
804 1.1 rvb
805 1.3 rvb CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
806 1.1 rvb return(error);
807 1.1 rvb }
808 1.1 rvb
809 1.1 rvb int
810 1.43 xtraeme coda_inactive(void *v)
811 1.1 rvb {
812 1.1 rvb /* XXX - at the moment, inactive doesn't look at cred, and doesn't
813 1.1 rvb have a proc pointer. Oops. */
814 1.1 rvb /* true args */
815 1.1 rvb struct vop_inactive_args *ap = v;
816 1.1 rvb struct vnode *vp = ap->a_vp;
817 1.1 rvb struct cnode *cp = VTOC(vp);
818 1.49 elad kauth_cred_t cred __attribute__((unused)) = NULL;
819 1.45 christos struct lwp *l __attribute__((unused)) = curlwp;
820 1.1 rvb /* upcall decl */
821 1.1 rvb /* locals */
822 1.1 rvb
823 1.1 rvb /* We don't need to send inactive to venus - DCS */
824 1.3 rvb MARK_ENTRY(CODA_INACTIVE_STATS);
825 1.1 rvb
826 1.1 rvb if (IS_CTL_VP(vp)) {
827 1.3 rvb MARK_INT_SAT(CODA_INACTIVE_STATS);
828 1.1 rvb return 0;
829 1.1 rvb }
830 1.1 rvb
831 1.37 drochner CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %s, vfsp %p\n",
832 1.37 drochner coda_f2s(&cp->c_fid), vp->v_mount));)
833 1.1 rvb
834 1.1 rvb /* If an array has been allocated to hold the symlink, deallocate it */
835 1.3 rvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
836 1.1 rvb if (cp->c_symlink == NULL)
837 1.3 rvb panic("coda_inactive: null symlink pointer in cnode");
838 1.40 perry
839 1.3 rvb CODA_FREE(cp->c_symlink, cp->c_symlen);
840 1.1 rvb cp->c_flags &= ~C_SYMLINK;
841 1.1 rvb cp->c_symlen = 0;
842 1.1 rvb }
843 1.1 rvb
844 1.1 rvb /* Remove it from the table so it can't be found. */
845 1.3 rvb coda_unsave(cp);
846 1.31 soren if (vp->v_mount->mnt_data == NULL) {
847 1.1 rvb myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
848 1.32 provos panic("badness in coda_inactive");
849 1.1 rvb }
850 1.1 rvb
851 1.1 rvb if (IS_UNMOUNTING(cp)) {
852 1.1 rvb #ifdef DEBUG
853 1.22 chs printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
854 1.1 rvb if (cp->c_ovp != NULL)
855 1.22 chs printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
856 1.1 rvb vp->v_usecount, vp, cp);
857 1.1 rvb #endif
858 1.10 wrstuden lockmgr(&vp->v_lock, LK_RELEASE, &vp->v_interlock);
859 1.1 rvb } else {
860 1.5 rvb #ifdef OLD_DIAGNOSTIC
861 1.1 rvb if (CTOV(cp)->v_usecount) {
862 1.3 rvb panic("coda_inactive: nonzero reference count");
863 1.1 rvb }
864 1.1 rvb if (cp->c_ovp != NULL) {
865 1.3 rvb panic("coda_inactive: cp->ovp != NULL");
866 1.1 rvb }
867 1.1 rvb #endif
868 1.2 rvb VOP_UNLOCK(vp, 0);
869 1.1 rvb vgone(vp);
870 1.1 rvb }
871 1.1 rvb
872 1.3 rvb MARK_INT_SAT(CODA_INACTIVE_STATS);
873 1.1 rvb return(0);
874 1.1 rvb }
875 1.1 rvb
876 1.1 rvb /*
877 1.1 rvb * Remote file system operations having to do with directory manipulation.
878 1.1 rvb */
879 1.1 rvb
880 1.40 perry /*
881 1.1 rvb * It appears that in NetBSD, lookup is supposed to return the vnode locked
882 1.1 rvb */
883 1.1 rvb int
884 1.43 xtraeme coda_lookup(void *v)
885 1.1 rvb {
886 1.1 rvb /* true args */
887 1.1 rvb struct vop_lookup_args *ap = v;
888 1.1 rvb struct vnode *dvp = ap->a_dvp;
889 1.1 rvb struct cnode *dcp = VTOC(dvp);
890 1.1 rvb struct vnode **vpp = ap->a_vpp;
891 1.40 perry /*
892 1.1 rvb * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
893 1.1 rvb * of the string to xlate, and that we must try to get at least
894 1.1 rvb * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
895 1.40 perry * could be wrong.
896 1.1 rvb */
897 1.1 rvb struct componentname *cnp = ap->a_cnp;
898 1.49 elad kauth_cred_t cred = cnp->cn_cred;
899 1.45 christos struct lwp *l = cnp->cn_lwp;
900 1.1 rvb /* locals */
901 1.1 rvb struct cnode *cp;
902 1.1 rvb const char *nm = cnp->cn_nameptr;
903 1.1 rvb int len = cnp->cn_namelen;
904 1.37 drochner CodaFid VFid;
905 1.1 rvb int vtype;
906 1.1 rvb int error = 0;
907 1.1 rvb
908 1.3 rvb MARK_ENTRY(CODA_LOOKUP_STATS);
909 1.1 rvb
910 1.37 drochner CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %s\n",
911 1.37 drochner nm, coda_f2s(&dcp->c_fid))););
912 1.1 rvb
913 1.1 rvb /* Check for lookup of control object. */
914 1.1 rvb if (IS_CTL_NAME(dvp, nm, len)) {
915 1.3 rvb *vpp = coda_ctlvp;
916 1.1 rvb vref(*vpp);
917 1.3 rvb MARK_INT_SAT(CODA_LOOKUP_STATS);
918 1.1 rvb goto exit;
919 1.1 rvb }
920 1.1 rvb
921 1.3 rvb if (len+1 > CODA_MAXNAMLEN) {
922 1.3 rvb MARK_INT_FAIL(CODA_LOOKUP_STATS);
923 1.37 drochner CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %s (%s)\n",
924 1.37 drochner coda_f2s(&dcp->c_fid), nm)););
925 1.1 rvb *vpp = (struct vnode *)0;
926 1.1 rvb error = EINVAL;
927 1.1 rvb goto exit;
928 1.1 rvb }
929 1.1 rvb /* First try to look the file up in the cfs name cache */
930 1.1 rvb /* lock the parent vnode? */
931 1.3 rvb cp = coda_nc_lookup(dcp, nm, len, cred);
932 1.1 rvb if (cp) {
933 1.1 rvb *vpp = CTOV(cp);
934 1.1 rvb vref(*vpp);
935 1.40 perry CODADEBUG(CODA_LOOKUP,
936 1.1 rvb myprintf(("lookup result %d vpp %p\n",error,*vpp));)
937 1.1 rvb } else {
938 1.40 perry
939 1.1 rvb /* The name wasn't cached, so we need to contact Venus */
940 1.45 christos error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, l, &VFid, &vtype);
941 1.40 perry
942 1.1 rvb if (error) {
943 1.3 rvb MARK_INT_FAIL(CODA_LOOKUP_STATS);
944 1.37 drochner CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %s (%s)%d\n",
945 1.37 drochner coda_f2s(&dcp->c_fid), nm, error));)
946 1.1 rvb *vpp = (struct vnode *)0;
947 1.1 rvb } else {
948 1.3 rvb MARK_INT_SAT(CODA_LOOKUP_STATS);
949 1.40 perry CODADEBUG(CODA_LOOKUP,
950 1.37 drochner myprintf(("lookup: %s type %o result %d\n",
951 1.37 drochner coda_f2s(&VFid), vtype, error)); )
952 1.40 perry
953 1.3 rvb cp = make_coda_node(&VFid, dvp->v_mount, vtype);
954 1.1 rvb *vpp = CTOV(cp);
955 1.40 perry
956 1.1 rvb /* enter the new vnode in the Name Cache only if the top bit isn't set */
957 1.1 rvb /* And don't enter a new vnode for an invalid one! */
958 1.3 rvb if (!(vtype & CODA_NOCACHE))
959 1.3 rvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
960 1.1 rvb }
961 1.1 rvb }
962 1.1 rvb
963 1.1 rvb exit:
964 1.40 perry /*
965 1.1 rvb * If we are creating, and this was the last name to be looked up,
966 1.1 rvb * and the error was ENOENT, then there really shouldn't be an
967 1.1 rvb * error and we can make the leaf NULL and return success. Since
968 1.1 rvb * this is supposed to work under Mach as well as NetBSD, we're
969 1.1 rvb * leaving this fn wrapped. We also must tell lookup/namei that
970 1.1 rvb * we need to save the last component of the name. (Create will
971 1.1 rvb * have to free the name buffer later...lucky us...)
972 1.1 rvb */
973 1.1 rvb if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
974 1.1 rvb && (cnp->cn_flags & ISLASTCN)
975 1.1 rvb && (error == ENOENT))
976 1.1 rvb {
977 1.1 rvb error = EJUSTRETURN;
978 1.1 rvb cnp->cn_flags |= SAVENAME;
979 1.1 rvb *ap->a_vpp = NULL;
980 1.1 rvb }
981 1.1 rvb
982 1.40 perry /*
983 1.1 rvb * If we are removing, and we are at the last element, and we
984 1.1 rvb * found it, then we need to keep the name around so that the
985 1.1 rvb * removal will go ahead as planned. Unfortunately, this will
986 1.1 rvb * probably also lock the to-be-removed vnode, which may or may
987 1.1 rvb * not be a good idea. I'll have to look at the bits of
988 1.3 rvb * coda_remove to make sure. We'll only save the name if we did in
989 1.3 rvb * fact find the name, otherwise coda_remove won't have a chance
990 1.40 perry * to free the pathname.
991 1.1 rvb */
992 1.1 rvb if ((cnp->cn_nameiop == DELETE)
993 1.1 rvb && (cnp->cn_flags & ISLASTCN)
994 1.1 rvb && !error)
995 1.1 rvb {
996 1.1 rvb cnp->cn_flags |= SAVENAME;
997 1.1 rvb }
998 1.1 rvb
999 1.40 perry /*
1000 1.50.4.1 ad * If the lookup went well, we need to lock the child.
1001 1.1 rvb */
1002 1.1 rvb if (!error || (error == EJUSTRETURN)) {
1003 1.50.4.1 ad /* The parent is locked, and may be the same as the child */
1004 1.50.4.1 ad if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1005 1.50.4.1 ad /* Different, go ahead and lock it. */
1006 1.50.4.1 ad vn_lock(*ap->a_vpp, LK_EXCLUSIVE|LK_RETRY);
1007 1.1 rvb }
1008 1.1 rvb } else {
1009 1.1 rvb /* If the lookup failed, we need to ensure that the leaf is NULL */
1010 1.1 rvb /* Don't change any locking? */
1011 1.1 rvb *ap->a_vpp = NULL;
1012 1.1 rvb }
1013 1.1 rvb return(error);
1014 1.1 rvb }
1015 1.1 rvb
1016 1.1 rvb /*ARGSUSED*/
1017 1.1 rvb int
1018 1.43 xtraeme coda_create(void *v)
1019 1.1 rvb {
1020 1.1 rvb /* true args */
1021 1.1 rvb struct vop_create_args *ap = v;
1022 1.1 rvb struct vnode *dvp = ap->a_dvp;
1023 1.1 rvb struct cnode *dcp = VTOC(dvp);
1024 1.1 rvb struct vattr *va = ap->a_vap;
1025 1.1 rvb int exclusive = 1;
1026 1.1 rvb int mode = ap->a_vap->va_mode;
1027 1.1 rvb struct vnode **vpp = ap->a_vpp;
1028 1.1 rvb struct componentname *cnp = ap->a_cnp;
1029 1.49 elad kauth_cred_t cred = cnp->cn_cred;
1030 1.45 christos struct lwp *l = cnp->cn_lwp;
1031 1.1 rvb /* locals */
1032 1.1 rvb int error;
1033 1.1 rvb struct cnode *cp;
1034 1.1 rvb const char *nm = cnp->cn_nameptr;
1035 1.1 rvb int len = cnp->cn_namelen;
1036 1.37 drochner CodaFid VFid;
1037 1.1 rvb struct vattr attr;
1038 1.1 rvb
1039 1.3 rvb MARK_ENTRY(CODA_CREATE_STATS);
1040 1.1 rvb
1041 1.1 rvb /* All creates are exclusive XXX */
1042 1.1 rvb /* I'm assuming the 'mode' argument is the file mode bits XXX */
1043 1.1 rvb
1044 1.1 rvb /* Check for create of control object. */
1045 1.1 rvb if (IS_CTL_NAME(dvp, nm, len)) {
1046 1.1 rvb *vpp = (struct vnode *)0;
1047 1.3 rvb MARK_INT_FAIL(CODA_CREATE_STATS);
1048 1.1 rvb return(EACCES);
1049 1.1 rvb }
1050 1.1 rvb
1051 1.45 christos error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, l, &VFid, &attr);
1052 1.1 rvb
1053 1.1 rvb if (!error) {
1054 1.40 perry
1055 1.1 rvb /* If this is an exclusive create, panic if the file already exists. */
1056 1.1 rvb /* Venus should have detected the file and reported EEXIST. */
1057 1.1 rvb
1058 1.1 rvb if ((exclusive == 1) &&
1059 1.3 rvb (coda_find(&VFid) != NULL))
1060 1.1 rvb panic("cnode existed for newly created file!");
1061 1.40 perry
1062 1.3 rvb cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1063 1.1 rvb *vpp = CTOV(cp);
1064 1.40 perry
1065 1.1 rvb /* Update va to reflect the new attributes. */
1066 1.1 rvb (*va) = attr;
1067 1.40 perry
1068 1.1 rvb /* Update the attribute cache and mark it as valid */
1069 1.3 rvb if (coda_attr_cache) {
1070 1.1 rvb VTOC(*vpp)->c_vattr = attr;
1071 1.40 perry VTOC(*vpp)->c_flags |= C_VATTR;
1072 1.1 rvb }
1073 1.1 rvb
1074 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1075 1.1 rvb VTOC(dvp)->c_flags &= ~C_VATTR;
1076 1.40 perry
1077 1.1 rvb /* enter the new vnode in the Name Cache */
1078 1.3 rvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1079 1.40 perry
1080 1.40 perry CODADEBUG(CODA_CREATE,
1081 1.37 drochner myprintf(("create: %s, result %d\n",
1082 1.37 drochner coda_f2s(&VFid), error)); )
1083 1.1 rvb } else {
1084 1.1 rvb *vpp = (struct vnode *)0;
1085 1.3 rvb CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1086 1.1 rvb }
1087 1.1 rvb
1088 1.1 rvb /* Locking strategy. */
1089 1.1 rvb /*
1090 1.1 rvb * In NetBSD, all creates must explicitly vput their dvp's. We'll
1091 1.1 rvb * go ahead and use the LOCKLEAF flag of the cnp argument.
1092 1.1 rvb * However, I'm pretty sure that create must return the leaf
1093 1.1 rvb * locked; so there is a DIAGNOSTIC check to ensure that this is
1094 1.1 rvb * true.
1095 1.1 rvb */
1096 1.1 rvb vput(dvp);
1097 1.1 rvb if (!error) {
1098 1.1 rvb if (cnp->cn_flags & LOCKLEAF) {
1099 1.2 rvb if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1100 1.3 rvb printf("coda_create: ");
1101 1.1 rvb panic("unlocked parent but couldn't lock child");
1102 1.1 rvb }
1103 1.1 rvb }
1104 1.7 rvb #ifdef OLD_DIAGNOSTIC
1105 1.1 rvb else {
1106 1.3 rvb printf("coda_create: LOCKLEAF not set!\n");
1107 1.1 rvb }
1108 1.5 rvb #endif
1109 1.1 rvb }
1110 1.1 rvb /* Have to free the previously saved name */
1111 1.40 perry /*
1112 1.1 rvb * This condition is stolen from ufs_makeinode. I have no idea
1113 1.1 rvb * why it's here, but what the hey...
1114 1.1 rvb */
1115 1.1 rvb if ((cnp->cn_flags & SAVESTART) == 0) {
1116 1.20 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1117 1.1 rvb }
1118 1.1 rvb return(error);
1119 1.1 rvb }
1120 1.1 rvb
1121 1.1 rvb int
1122 1.43 xtraeme coda_remove(void *v)
1123 1.1 rvb {
1124 1.1 rvb /* true args */
1125 1.1 rvb struct vop_remove_args *ap = v;
1126 1.1 rvb struct vnode *dvp = ap->a_dvp;
1127 1.1 rvb struct cnode *cp = VTOC(dvp);
1128 1.1 rvb struct componentname *cnp = ap->a_cnp;
1129 1.49 elad kauth_cred_t cred = cnp->cn_cred;
1130 1.45 christos struct lwp *l = cnp->cn_lwp;
1131 1.1 rvb /* locals */
1132 1.1 rvb int error;
1133 1.1 rvb const char *nm = cnp->cn_nameptr;
1134 1.1 rvb int len = cnp->cn_namelen;
1135 1.1 rvb struct cnode *tp;
1136 1.1 rvb
1137 1.3 rvb MARK_ENTRY(CODA_REMOVE_STATS);
1138 1.1 rvb
1139 1.37 drochner CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %s\n",
1140 1.37 drochner nm, coda_f2s(&cp->c_fid))););
1141 1.1 rvb
1142 1.3 rvb /* Remove the file's entry from the CODA Name Cache */
1143 1.1 rvb /* We're being conservative here, it might be that this person
1144 1.1 rvb * doesn't really have sufficient access to delete the file
1145 1.1 rvb * but we feel zapping the entry won't really hurt anyone -- dcs
1146 1.1 rvb */
1147 1.1 rvb /* I'm gonna go out on a limb here. If a file and a hardlink to it
1148 1.1 rvb * exist, and one is removed, the link count on the other will be
1149 1.1 rvb * off by 1. We could either invalidate the attrs if cached, or
1150 1.1 rvb * fix them. I'll try to fix them. DCS 11/8/94
1151 1.1 rvb */
1152 1.3 rvb tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1153 1.1 rvb if (tp) {
1154 1.1 rvb if (VALID_VATTR(tp)) { /* If attrs are cached */
1155 1.1 rvb if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1156 1.1 rvb tp->c_vattr.va_nlink--;
1157 1.1 rvb }
1158 1.1 rvb }
1159 1.40 perry
1160 1.40 perry coda_nc_zapfile(VTOC(dvp), nm, len);
1161 1.1 rvb /* No need to flush it if it doesn't exist! */
1162 1.1 rvb }
1163 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1164 1.1 rvb VTOC(dvp)->c_flags &= ~C_VATTR;
1165 1.1 rvb
1166 1.1 rvb /* Check for remove of control object. */
1167 1.1 rvb if (IS_CTL_NAME(dvp, nm, len)) {
1168 1.3 rvb MARK_INT_FAIL(CODA_REMOVE_STATS);
1169 1.1 rvb return(ENOENT);
1170 1.1 rvb }
1171 1.1 rvb
1172 1.45 christos error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, l);
1173 1.1 rvb
1174 1.3 rvb CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1175 1.1 rvb
1176 1.40 perry /*
1177 1.1 rvb * Regardless of what happens, we have to unconditionally drop
1178 1.1 rvb * locks/refs on parent and child. (I hope). This is based on
1179 1.1 rvb * what ufs_remove seems to be doing.
1180 1.1 rvb */
1181 1.1 rvb if (dvp == ap->a_vp) {
1182 1.1 rvb vrele(ap->a_vp);
1183 1.1 rvb } else {
1184 1.1 rvb vput(ap->a_vp);
1185 1.1 rvb }
1186 1.1 rvb vput(dvp);
1187 1.1 rvb
1188 1.1 rvb if ((cnp->cn_flags & SAVESTART) == 0) {
1189 1.20 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1190 1.1 rvb }
1191 1.1 rvb return(error);
1192 1.1 rvb }
1193 1.1 rvb
1194 1.1 rvb int
1195 1.43 xtraeme coda_link(void *v)
1196 1.1 rvb {
1197 1.1 rvb /* true args */
1198 1.1 rvb struct vop_link_args *ap = v;
1199 1.1 rvb struct vnode *vp = ap->a_vp;
1200 1.1 rvb struct cnode *cp = VTOC(vp);
1201 1.1 rvb struct vnode *tdvp = ap->a_dvp;
1202 1.1 rvb struct cnode *tdcp = VTOC(tdvp);
1203 1.1 rvb struct componentname *cnp = ap->a_cnp;
1204 1.49 elad kauth_cred_t cred = cnp->cn_cred;
1205 1.45 christos struct lwp *l = cnp->cn_lwp;
1206 1.1 rvb /* locals */
1207 1.1 rvb int error;
1208 1.1 rvb const char *nm = cnp->cn_nameptr;
1209 1.1 rvb int len = cnp->cn_namelen;
1210 1.1 rvb
1211 1.3 rvb MARK_ENTRY(CODA_LINK_STATS);
1212 1.1 rvb
1213 1.3 rvb if (codadebug & CODADBGMSK(CODA_LINK)) {
1214 1.1 rvb
1215 1.37 drochner myprintf(("nb_link: vp fid: %s\n",
1216 1.37 drochner coda_f2s(&cp->c_fid)));
1217 1.37 drochner myprintf(("nb_link: tdvp fid: %s)\n",
1218 1.37 drochner coda_f2s(&tdcp->c_fid)));
1219 1.40 perry
1220 1.1 rvb }
1221 1.3 rvb if (codadebug & CODADBGMSK(CODA_LINK)) {
1222 1.37 drochner myprintf(("link: vp fid: %s\n",
1223 1.37 drochner coda_f2s(&cp->c_fid)));
1224 1.37 drochner myprintf(("link: tdvp fid: %s\n",
1225 1.37 drochner coda_f2s(&tdcp->c_fid)));
1226 1.1 rvb
1227 1.1 rvb }
1228 1.1 rvb
1229 1.1 rvb /* Check for link to/from control object. */
1230 1.1 rvb if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1231 1.3 rvb MARK_INT_FAIL(CODA_LINK_STATS);
1232 1.1 rvb return(EACCES);
1233 1.1 rvb }
1234 1.1 rvb
1235 1.1 rvb /*
1236 1.1 rvb * According to the ufs_link operation here's the locking situation:
1237 1.1 rvb * We enter with the thing called "dvp" (the directory) locked.
1238 1.1 rvb * We must unconditionally drop locks on "dvp"
1239 1.1 rvb *
1240 1.1 rvb * We enter with the thing called "vp" (the linked-to) unlocked,
1241 1.1 rvb * but ref'd (?)
1242 1.3 rvb * We seem to need to lock it before calling coda_link, and
1243 1.1 rvb * unconditionally unlock it after.
1244 1.1 rvb */
1245 1.1 rvb
1246 1.2 rvb if ((ap->a_vp != tdvp) && (error = vn_lock(ap->a_vp, LK_EXCLUSIVE))) {
1247 1.1 rvb goto exit;
1248 1.1 rvb }
1249 1.40 perry
1250 1.45 christos error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, l);
1251 1.1 rvb
1252 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1253 1.1 rvb VTOC(tdvp)->c_flags &= ~C_VATTR;
1254 1.1 rvb VTOC(vp)->c_flags &= ~C_VATTR;
1255 1.1 rvb
1256 1.3 rvb CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1257 1.1 rvb
1258 1.1 rvb exit:
1259 1.1 rvb
1260 1.1 rvb if (ap->a_vp != tdvp) {
1261 1.2 rvb VOP_UNLOCK(ap->a_vp, 0);
1262 1.1 rvb }
1263 1.1 rvb vput(tdvp);
1264 1.1 rvb
1265 1.1 rvb /* Drop the name buffer if we don't need to SAVESTART */
1266 1.1 rvb if ((cnp->cn_flags & SAVESTART) == 0) {
1267 1.20 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1268 1.1 rvb }
1269 1.1 rvb return(error);
1270 1.1 rvb }
1271 1.1 rvb
1272 1.1 rvb int
1273 1.43 xtraeme coda_rename(void *v)
1274 1.1 rvb {
1275 1.1 rvb /* true args */
1276 1.1 rvb struct vop_rename_args *ap = v;
1277 1.1 rvb struct vnode *odvp = ap->a_fdvp;
1278 1.1 rvb struct cnode *odcp = VTOC(odvp);
1279 1.1 rvb struct componentname *fcnp = ap->a_fcnp;
1280 1.1 rvb struct vnode *ndvp = ap->a_tdvp;
1281 1.1 rvb struct cnode *ndcp = VTOC(ndvp);
1282 1.1 rvb struct componentname *tcnp = ap->a_tcnp;
1283 1.49 elad kauth_cred_t cred = fcnp->cn_cred;
1284 1.45 christos struct lwp *l = fcnp->cn_lwp;
1285 1.1 rvb /* true args */
1286 1.1 rvb int error;
1287 1.1 rvb const char *fnm = fcnp->cn_nameptr;
1288 1.1 rvb int flen = fcnp->cn_namelen;
1289 1.1 rvb const char *tnm = tcnp->cn_nameptr;
1290 1.1 rvb int tlen = tcnp->cn_namelen;
1291 1.1 rvb
1292 1.3 rvb MARK_ENTRY(CODA_RENAME_STATS);
1293 1.1 rvb
1294 1.1 rvb /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1295 1.1 rvb This could be Bad. XXX */
1296 1.5 rvb #ifdef OLD_DIAGNOSTIC
1297 1.1 rvb if ((fcnp->cn_cred != tcnp->cn_cred)
1298 1.45 christos || (fcnp->cn_lwp != tcnp->cn_lwp))
1299 1.1 rvb {
1300 1.3 rvb panic("coda_rename: component names don't agree");
1301 1.1 rvb }
1302 1.5 rvb #endif
1303 1.1 rvb
1304 1.40 perry /* Check for rename involving control object. */
1305 1.1 rvb if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1306 1.3 rvb MARK_INT_FAIL(CODA_RENAME_STATS);
1307 1.1 rvb return(EACCES);
1308 1.1 rvb }
1309 1.1 rvb
1310 1.1 rvb /* Problem with moving directories -- need to flush entry for .. */
1311 1.1 rvb if (odvp != ndvp) {
1312 1.3 rvb struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1313 1.1 rvb if (ovcp) {
1314 1.1 rvb struct vnode *ovp = CTOV(ovcp);
1315 1.1 rvb if ((ovp) &&
1316 1.1 rvb (ovp->v_type == VDIR)) /* If it's a directory */
1317 1.3 rvb coda_nc_zapfile(VTOC(ovp),"..", 2);
1318 1.1 rvb }
1319 1.1 rvb }
1320 1.1 rvb
1321 1.1 rvb /* Remove the entries for both source and target files */
1322 1.3 rvb coda_nc_zapfile(VTOC(odvp), fnm, flen);
1323 1.3 rvb coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1324 1.1 rvb
1325 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1326 1.1 rvb VTOC(odvp)->c_flags &= ~C_VATTR;
1327 1.1 rvb VTOC(ndvp)->c_flags &= ~C_VATTR;
1328 1.1 rvb
1329 1.3 rvb if (flen+1 > CODA_MAXNAMLEN) {
1330 1.3 rvb MARK_INT_FAIL(CODA_RENAME_STATS);
1331 1.1 rvb error = EINVAL;
1332 1.1 rvb goto exit;
1333 1.1 rvb }
1334 1.1 rvb
1335 1.3 rvb if (tlen+1 > CODA_MAXNAMLEN) {
1336 1.3 rvb MARK_INT_FAIL(CODA_RENAME_STATS);
1337 1.1 rvb error = EINVAL;
1338 1.1 rvb goto exit;
1339 1.1 rvb }
1340 1.1 rvb
1341 1.45 christos error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, l);
1342 1.1 rvb
1343 1.1 rvb exit:
1344 1.3 rvb CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1345 1.1 rvb /* XXX - do we need to call cache pureg on the moved vnode? */
1346 1.1 rvb cache_purge(ap->a_fvp);
1347 1.1 rvb
1348 1.1 rvb /* It seems to be incumbent on us to drop locks on all four vnodes */
1349 1.1 rvb /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1350 1.1 rvb
1351 1.1 rvb vrele(ap->a_fvp);
1352 1.1 rvb vrele(odvp);
1353 1.1 rvb
1354 1.1 rvb if (ap->a_tvp) {
1355 1.1 rvb if (ap->a_tvp == ndvp) {
1356 1.1 rvb vrele(ap->a_tvp);
1357 1.1 rvb } else {
1358 1.1 rvb vput(ap->a_tvp);
1359 1.1 rvb }
1360 1.1 rvb }
1361 1.1 rvb
1362 1.1 rvb vput(ndvp);
1363 1.1 rvb return(error);
1364 1.1 rvb }
1365 1.1 rvb
1366 1.1 rvb int
1367 1.43 xtraeme coda_mkdir(void *v)
1368 1.1 rvb {
1369 1.1 rvb /* true args */
1370 1.1 rvb struct vop_mkdir_args *ap = v;
1371 1.1 rvb struct vnode *dvp = ap->a_dvp;
1372 1.40 perry struct cnode *dcp = VTOC(dvp);
1373 1.1 rvb struct componentname *cnp = ap->a_cnp;
1374 1.17 augustss struct vattr *va = ap->a_vap;
1375 1.1 rvb struct vnode **vpp = ap->a_vpp;
1376 1.49 elad kauth_cred_t cred = cnp->cn_cred;
1377 1.45 christos struct lwp *l = cnp->cn_lwp;
1378 1.1 rvb /* locals */
1379 1.1 rvb int error;
1380 1.1 rvb const char *nm = cnp->cn_nameptr;
1381 1.1 rvb int len = cnp->cn_namelen;
1382 1.1 rvb struct cnode *cp;
1383 1.37 drochner CodaFid VFid;
1384 1.1 rvb struct vattr ova;
1385 1.1 rvb
1386 1.3 rvb MARK_ENTRY(CODA_MKDIR_STATS);
1387 1.1 rvb
1388 1.1 rvb /* Check for mkdir of target object. */
1389 1.1 rvb if (IS_CTL_NAME(dvp, nm, len)) {
1390 1.1 rvb *vpp = (struct vnode *)0;
1391 1.3 rvb MARK_INT_FAIL(CODA_MKDIR_STATS);
1392 1.1 rvb return(EACCES);
1393 1.1 rvb }
1394 1.1 rvb
1395 1.3 rvb if (len+1 > CODA_MAXNAMLEN) {
1396 1.1 rvb *vpp = (struct vnode *)0;
1397 1.3 rvb MARK_INT_FAIL(CODA_MKDIR_STATS);
1398 1.1 rvb return(EACCES);
1399 1.1 rvb }
1400 1.1 rvb
1401 1.45 christos error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, l, &VFid, &ova);
1402 1.1 rvb
1403 1.1 rvb if (!error) {
1404 1.3 rvb if (coda_find(&VFid) != NULL)
1405 1.1 rvb panic("cnode existed for newly created directory!");
1406 1.40 perry
1407 1.40 perry
1408 1.3 rvb cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1409 1.1 rvb *vpp = CTOV(cp);
1410 1.40 perry
1411 1.1 rvb /* enter the new vnode in the Name Cache */
1412 1.3 rvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1413 1.1 rvb
1414 1.1 rvb /* as a side effect, enter "." and ".." for the directory */
1415 1.3 rvb coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1416 1.3 rvb coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1417 1.1 rvb
1418 1.3 rvb if (coda_attr_cache) {
1419 1.1 rvb VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1420 1.1 rvb VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1421 1.1 rvb }
1422 1.1 rvb
1423 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1424 1.1 rvb VTOC(dvp)->c_flags &= ~C_VATTR;
1425 1.40 perry
1426 1.37 drochner CODADEBUG( CODA_MKDIR, myprintf(("mkdir: %s result %d\n",
1427 1.37 drochner coda_f2s(&VFid), error)); )
1428 1.1 rvb } else {
1429 1.1 rvb *vpp = (struct vnode *)0;
1430 1.3 rvb CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1431 1.1 rvb }
1432 1.1 rvb
1433 1.1 rvb /*
1434 1.1 rvb * Currently, all mkdirs explicitly vput their dvp's.
1435 1.1 rvb * It also appears that we *must* lock the vpp, since
1436 1.1 rvb * lockleaf isn't set, but someone down the road is going
1437 1.1 rvb * to try to unlock the new directory.
1438 1.1 rvb */
1439 1.1 rvb vput(dvp);
1440 1.1 rvb if (!error) {
1441 1.2 rvb if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1442 1.3 rvb panic("coda_mkdir: couldn't lock child");
1443 1.1 rvb }
1444 1.1 rvb }
1445 1.1 rvb
1446 1.1 rvb /* Have to free the previously saved name */
1447 1.40 perry /*
1448 1.1 rvb * ufs_mkdir doesn't check for SAVESTART before freeing the
1449 1.1 rvb * pathname buffer, but ufs_create does. For the moment, I'll
1450 1.1 rvb * follow their lead, but this seems like it is probably
1451 1.40 perry * incorrect.
1452 1.1 rvb */
1453 1.20 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1454 1.1 rvb return(error);
1455 1.1 rvb }
1456 1.1 rvb
1457 1.1 rvb int
1458 1.43 xtraeme coda_rmdir(void *v)
1459 1.1 rvb {
1460 1.1 rvb /* true args */
1461 1.1 rvb struct vop_rmdir_args *ap = v;
1462 1.1 rvb struct vnode *dvp = ap->a_dvp;
1463 1.1 rvb struct cnode *dcp = VTOC(dvp);
1464 1.1 rvb struct componentname *cnp = ap->a_cnp;
1465 1.49 elad kauth_cred_t cred = cnp->cn_cred;
1466 1.45 christos struct lwp *l = cnp->cn_lwp;
1467 1.1 rvb /* true args */
1468 1.1 rvb int error;
1469 1.1 rvb const char *nm = cnp->cn_nameptr;
1470 1.1 rvb int len = cnp->cn_namelen;
1471 1.1 rvb struct cnode *cp;
1472 1.40 perry
1473 1.3 rvb MARK_ENTRY(CODA_RMDIR_STATS);
1474 1.1 rvb
1475 1.1 rvb /* Check for rmdir of control object. */
1476 1.1 rvb if (IS_CTL_NAME(dvp, nm, len)) {
1477 1.3 rvb MARK_INT_FAIL(CODA_RMDIR_STATS);
1478 1.1 rvb return(ENOENT);
1479 1.1 rvb }
1480 1.1 rvb
1481 1.1 rvb /* We're being conservative here, it might be that this person
1482 1.1 rvb * doesn't really have sufficient access to delete the file
1483 1.1 rvb * but we feel zapping the entry won't really hurt anyone -- dcs
1484 1.1 rvb */
1485 1.1 rvb /*
1486 1.1 rvb * As a side effect of the rmdir, remove any entries for children of
1487 1.1 rvb * the directory, especially "." and "..".
1488 1.1 rvb */
1489 1.3 rvb cp = coda_nc_lookup(dcp, nm, len, cred);
1490 1.3 rvb if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1491 1.1 rvb
1492 1.3 rvb /* Remove the file's entry from the CODA Name Cache */
1493 1.3 rvb coda_nc_zapfile(dcp, nm, len);
1494 1.1 rvb
1495 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1496 1.1 rvb dcp->c_flags &= ~C_VATTR;
1497 1.1 rvb
1498 1.45 christos error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, l);
1499 1.1 rvb
1500 1.3 rvb CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1501 1.1 rvb
1502 1.1 rvb /*
1503 1.40 perry * regardless of what happens, we need to drop locks/refs on the
1504 1.40 perry * parent and child. I think.
1505 1.1 rvb */
1506 1.1 rvb if (dvp == ap->a_vp) {
1507 1.1 rvb vrele(ap->a_vp);
1508 1.1 rvb } else {
1509 1.1 rvb vput(ap->a_vp);
1510 1.1 rvb }
1511 1.1 rvb vput(dvp);
1512 1.1 rvb
1513 1.1 rvb if ((cnp->cn_flags & SAVESTART) == 0) {
1514 1.20 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1515 1.1 rvb }
1516 1.1 rvb return(error);
1517 1.1 rvb }
1518 1.1 rvb
1519 1.1 rvb int
1520 1.43 xtraeme coda_symlink(void *v)
1521 1.1 rvb {
1522 1.1 rvb /* true args */
1523 1.1 rvb struct vop_symlink_args *ap = v;
1524 1.1 rvb struct vnode *tdvp = ap->a_dvp;
1525 1.40 perry struct cnode *tdcp = VTOC(tdvp);
1526 1.1 rvb struct componentname *cnp = ap->a_cnp;
1527 1.1 rvb struct vattr *tva = ap->a_vap;
1528 1.1 rvb char *path = ap->a_target;
1529 1.49 elad kauth_cred_t cred = cnp->cn_cred;
1530 1.45 christos struct lwp *l = cnp->cn_lwp;
1531 1.1 rvb /* locals */
1532 1.1 rvb int error;
1533 1.39 petrov u_long saved_cn_flags;
1534 1.40 perry /*
1535 1.3 rvb * XXX I'm assuming the following things about coda_symlink's
1536 1.40 perry * arguments:
1537 1.1 rvb * t(foo) is the new name/parent/etc being created.
1538 1.40 perry * lname is the contents of the new symlink.
1539 1.1 rvb */
1540 1.2 rvb const char *nm = cnp->cn_nameptr;
1541 1.1 rvb int len = cnp->cn_namelen;
1542 1.1 rvb int plen = strlen(path);
1543 1.1 rvb
1544 1.1 rvb /* XXX What about the vpp argument? Do we need it? */
1545 1.40 perry /*
1546 1.1 rvb * Here's the strategy for the moment: perform the symlink, then
1547 1.1 rvb * do a lookup to grab the resulting vnode. I know this requires
1548 1.1 rvb * two communications with Venus for a new sybolic link, but
1549 1.1 rvb * that's the way the ball bounces. I don't yet want to change
1550 1.1 rvb * the way the Mach symlink works. When Mach support is
1551 1.1 rvb * deprecated, we should change symlink so that the common case
1552 1.1 rvb * returns the resultant vnode in a vpp argument.
1553 1.1 rvb */
1554 1.1 rvb
1555 1.3 rvb MARK_ENTRY(CODA_SYMLINK_STATS);
1556 1.1 rvb
1557 1.1 rvb /* Check for symlink of control object. */
1558 1.1 rvb if (IS_CTL_NAME(tdvp, nm, len)) {
1559 1.3 rvb MARK_INT_FAIL(CODA_SYMLINK_STATS);
1560 1.1 rvb return(EACCES);
1561 1.1 rvb }
1562 1.1 rvb
1563 1.3 rvb if (plen+1 > CODA_MAXPATHLEN) {
1564 1.3 rvb MARK_INT_FAIL(CODA_SYMLINK_STATS);
1565 1.1 rvb return(EINVAL);
1566 1.1 rvb }
1567 1.1 rvb
1568 1.3 rvb if (len+1 > CODA_MAXNAMLEN) {
1569 1.3 rvb MARK_INT_FAIL(CODA_SYMLINK_STATS);
1570 1.1 rvb error = EINVAL;
1571 1.1 rvb goto exit;
1572 1.1 rvb }
1573 1.1 rvb
1574 1.45 christos error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, l);
1575 1.1 rvb
1576 1.1 rvb /* Invalidate the parent's attr cache, the modification time has changed */
1577 1.1 rvb tdcp->c_flags &= ~C_VATTR;
1578 1.1 rvb
1579 1.39 petrov if (!error) {
1580 1.39 petrov /*
1581 1.39 petrov * VOP_SYMLINK is not defined to pay attention to cnp->cn_flags;
1582 1.39 petrov * these are defined only for VOP_LOOKUP. We desire to reuse
1583 1.39 petrov * cnp for a VOP_LOOKUP operation, and must be sure to not pass
1584 1.39 petrov * stray flags passed to us. Such stray flags can occur because
1585 1.39 petrov * sys_symlink makes a namei call and then reuses the
1586 1.39 petrov * componentname structure.
1587 1.39 petrov */
1588 1.39 petrov /*
1589 1.39 petrov * XXX Arguably we should create our own componentname structure
1590 1.39 petrov * and not reuse the one that was passed in.
1591 1.39 petrov */
1592 1.39 petrov saved_cn_flags = cnp->cn_flags;
1593 1.39 petrov cnp->cn_flags &= ~(MODMASK | OPMASK);
1594 1.39 petrov cnp->cn_flags |= LOOKUP;
1595 1.39 petrov error = VOP_LOOKUP(tdvp, ap->a_vpp, cnp);
1596 1.39 petrov cnp->cn_flags = saved_cn_flags;
1597 1.39 petrov /* Either an error occurs, or ap->a_vpp is locked. */
1598 1.1 rvb }
1599 1.50.4.1 ad /* unlock and deference parent */
1600 1.50.4.1 ad vput(tdvp);
1601 1.1 rvb
1602 1.40 perry exit:
1603 1.3 rvb CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1604 1.1 rvb return(error);
1605 1.1 rvb }
1606 1.1 rvb
1607 1.1 rvb /*
1608 1.1 rvb * Read directory entries.
1609 1.1 rvb */
1610 1.1 rvb int
1611 1.43 xtraeme coda_readdir(void *v)
1612 1.1 rvb {
1613 1.1 rvb /* true args */
1614 1.1 rvb struct vop_readdir_args *ap = v;
1615 1.1 rvb struct vnode *vp = ap->a_vp;
1616 1.1 rvb struct cnode *cp = VTOC(vp);
1617 1.17 augustss struct uio *uiop = ap->a_uio;
1618 1.49 elad kauth_cred_t cred = ap->a_cred;
1619 1.1 rvb int *eofflag = ap->a_eofflag;
1620 1.1 rvb off_t **cookies = ap->a_cookies;
1621 1.1 rvb int *ncookies = ap->a_ncookies;
1622 1.1 rvb /* upcall decl */
1623 1.1 rvb /* locals */
1624 1.47 yamt struct lwp *l = curlwp;
1625 1.1 rvb int error = 0;
1626 1.1 rvb
1627 1.3 rvb MARK_ENTRY(CODA_READDIR_STATS);
1628 1.1 rvb
1629 1.47 yamt CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %lu, %lld)\n", uiop->uio_iov->iov_base, (unsigned long) uiop->uio_resid, (long long) uiop->uio_offset)); )
1630 1.40 perry
1631 1.1 rvb /* Check for readdir of control object. */
1632 1.1 rvb if (IS_CTL_VP(vp)) {
1633 1.3 rvb MARK_INT_FAIL(CODA_READDIR_STATS);
1634 1.1 rvb return(ENOENT);
1635 1.1 rvb }
1636 1.1 rvb
1637 1.2 rvb {
1638 1.1 rvb /* Redirect the request to UFS. */
1639 1.40 perry
1640 1.1 rvb /* If directory is not already open do an "internal open" on it. */
1641 1.1 rvb int opened_internally = 0;
1642 1.1 rvb if (cp->c_ovp == NULL) {
1643 1.1 rvb opened_internally = 1;
1644 1.3 rvb MARK_INT_GEN(CODA_OPEN_STATS);
1645 1.45 christos error = VOP_OPEN(vp, FREAD, cred, l);
1646 1.18 phil #ifdef CODA_VERBOSE
1647 1.3 rvb printf("coda_readdir: Internally Opening %p\n", vp);
1648 1.18 phil #endif
1649 1.1 rvb if (error) return(error);
1650 1.48 christos } else
1651 1.48 christos vp = cp->c_ovp;
1652 1.40 perry
1653 1.1 rvb /* Have UFS handle the call. */
1654 1.37 drochner CODADEBUG(CODA_READDIR, myprintf((
1655 1.37 drochner "indirect readdir: fid = %s, refcnt = %d\n",
1656 1.37 drochner coda_f2s(&cp->c_fid), vp->v_usecount)); )
1657 1.48 christos error = VOP_READDIR(vp, uiop, cred, eofflag, cookies, ncookies);
1658 1.1 rvb if (error)
1659 1.3 rvb MARK_INT_FAIL(CODA_READDIR_STATS);
1660 1.1 rvb else
1661 1.3 rvb MARK_INT_SAT(CODA_READDIR_STATS);
1662 1.40 perry
1663 1.40 perry /* Do an "internal close" if necessary. */
1664 1.1 rvb if (opened_internally) {
1665 1.3 rvb MARK_INT_GEN(CODA_CLOSE_STATS);
1666 1.45 christos (void)VOP_CLOSE(vp, FREAD, cred, l);
1667 1.1 rvb }
1668 1.1 rvb }
1669 1.1 rvb
1670 1.1 rvb return(error);
1671 1.1 rvb }
1672 1.1 rvb
1673 1.1 rvb /*
1674 1.1 rvb * Convert from file system blocks to device blocks
1675 1.1 rvb */
1676 1.1 rvb int
1677 1.43 xtraeme coda_bmap(void *v)
1678 1.1 rvb {
1679 1.1 rvb /* XXX on the global proc */
1680 1.1 rvb /* true args */
1681 1.1 rvb struct vop_bmap_args *ap = v;
1682 1.1 rvb struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1683 1.1 rvb daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1684 1.1 rvb struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1685 1.1 rvb daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1686 1.45 christos struct lwp *l __attribute__((unused)) = curlwp;
1687 1.1 rvb /* upcall decl */
1688 1.1 rvb /* locals */
1689 1.1 rvb
1690 1.1 rvb *vpp = (struct vnode *)0;
1691 1.3 rvb myprintf(("coda_bmap called!\n"));
1692 1.1 rvb return(EINVAL);
1693 1.1 rvb }
1694 1.1 rvb
1695 1.1 rvb /*
1696 1.1 rvb * I don't think the following two things are used anywhere, so I've
1697 1.40 perry * commented them out
1698 1.40 perry *
1699 1.40 perry * struct buf *async_bufhead;
1700 1.1 rvb * int async_daemon_count;
1701 1.1 rvb */
1702 1.1 rvb int
1703 1.43 xtraeme coda_strategy(void *v)
1704 1.1 rvb {
1705 1.1 rvb /* true args */
1706 1.1 rvb struct vop_strategy_args *ap = v;
1707 1.17 augustss struct buf *bp __attribute__((unused)) = ap->a_bp;
1708 1.45 christos struct lwp *l __attribute__((unused)) = curlwp;
1709 1.1 rvb /* upcall decl */
1710 1.1 rvb /* locals */
1711 1.1 rvb
1712 1.3 rvb myprintf(("coda_strategy called! "));
1713 1.1 rvb return(EINVAL);
1714 1.1 rvb }
1715 1.1 rvb
1716 1.1 rvb int
1717 1.43 xtraeme coda_reclaim(void *v)
1718 1.1 rvb {
1719 1.1 rvb /* true args */
1720 1.1 rvb struct vop_reclaim_args *ap = v;
1721 1.1 rvb struct vnode *vp = ap->a_vp;
1722 1.1 rvb struct cnode *cp = VTOC(vp);
1723 1.1 rvb /* upcall decl */
1724 1.1 rvb /* locals */
1725 1.1 rvb
1726 1.1 rvb /*
1727 1.1 rvb * Forced unmount/flush will let vnodes with non zero use be destroyed!
1728 1.1 rvb */
1729 1.1 rvb ENTRY;
1730 1.1 rvb
1731 1.1 rvb if (IS_UNMOUNTING(cp)) {
1732 1.1 rvb #ifdef DEBUG
1733 1.1 rvb if (VTOC(vp)->c_ovp) {
1734 1.1 rvb if (IS_UNMOUNTING(cp))
1735 1.3 rvb printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1736 1.1 rvb }
1737 1.1 rvb #endif
1738 1.1 rvb } else {
1739 1.5 rvb #ifdef OLD_DIAGNOSTIC
1740 1.40 perry if (vp->v_usecount != 0)
1741 1.5 rvb print("coda_reclaim: pushing active %p\n", vp);
1742 1.1 rvb if (VTOC(vp)->c_ovp) {
1743 1.3 rvb panic("coda_reclaim: c_ovp not void");
1744 1.2 rvb }
1745 1.5 rvb #endif
1746 1.1 rvb }
1747 1.1 rvb cache_purge(vp);
1748 1.3 rvb coda_free(VTOC(vp));
1749 1.29 perry SET_VTOC(vp) = NULL;
1750 1.1 rvb return (0);
1751 1.1 rvb }
1752 1.1 rvb
1753 1.1 rvb int
1754 1.43 xtraeme coda_lock(void *v)
1755 1.1 rvb {
1756 1.1 rvb /* true args */
1757 1.1 rvb struct vop_lock_args *ap = v;
1758 1.1 rvb struct vnode *vp = ap->a_vp;
1759 1.1 rvb struct cnode *cp = VTOC(vp);
1760 1.1 rvb /* upcall decl */
1761 1.1 rvb /* locals */
1762 1.1 rvb
1763 1.1 rvb ENTRY;
1764 1.1 rvb
1765 1.3 rvb if (coda_lockdebug) {
1766 1.37 drochner myprintf(("Attempting lock on %s\n",
1767 1.37 drochner coda_f2s(&cp->c_fid)));
1768 1.1 rvb }
1769 1.1 rvb
1770 1.10 wrstuden return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
1771 1.1 rvb }
1772 1.1 rvb
1773 1.1 rvb int
1774 1.43 xtraeme coda_unlock(void *v)
1775 1.1 rvb {
1776 1.1 rvb /* true args */
1777 1.1 rvb struct vop_unlock_args *ap = v;
1778 1.1 rvb struct vnode *vp = ap->a_vp;
1779 1.1 rvb struct cnode *cp = VTOC(vp);
1780 1.1 rvb /* upcall decl */
1781 1.1 rvb /* locals */
1782 1.1 rvb
1783 1.1 rvb ENTRY;
1784 1.3 rvb if (coda_lockdebug) {
1785 1.37 drochner myprintf(("Attempting unlock on %s\n",
1786 1.37 drochner coda_f2s(&cp->c_fid)));
1787 1.1 rvb }
1788 1.1 rvb
1789 1.10 wrstuden return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock));
1790 1.1 rvb }
1791 1.1 rvb
1792 1.1 rvb int
1793 1.43 xtraeme coda_islocked(void *v)
1794 1.1 rvb {
1795 1.1 rvb /* true args */
1796 1.1 rvb struct vop_islocked_args *ap = v;
1797 1.1 rvb ENTRY;
1798 1.1 rvb
1799 1.10 wrstuden return (lockstatus(&ap->a_vp->v_lock));
1800 1.1 rvb }
1801 1.1 rvb
1802 1.1 rvb /* How one looks up a vnode given a device/inode pair: */
1803 1.1 rvb int
1804 1.35 thorpej coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1805 1.1 rvb {
1806 1.1 rvb /* This is like VFS_VGET() or igetinode()! */
1807 1.1 rvb int error;
1808 1.1 rvb struct mount *mp;
1809 1.1 rvb
1810 1.1 rvb if (!(mp = devtomp(dev))) {
1811 1.3 rvb myprintf(("coda_grab_vnode: devtomp(%d) returns NULL\n", dev));
1812 1.1 rvb return(ENXIO);
1813 1.1 rvb }
1814 1.1 rvb
1815 1.1 rvb /* XXX - ensure that nonzero-return means failure */
1816 1.45 christos error = VFS_VGET(mp, ino, vpp);
1817 1.1 rvb if (error) {
1818 1.42 christos myprintf(("coda_grab_vnode: iget/vget(%d, %llu) returns %p, err %d\n",
1819 1.42 christos dev, (unsigned long long)ino, *vpp, error));
1820 1.1 rvb return(ENOENT);
1821 1.1 rvb }
1822 1.1 rvb return(0);
1823 1.1 rvb }
1824 1.1 rvb
1825 1.1 rvb void
1826 1.43 xtraeme print_vattr(struct vattr *attr)
1827 1.1 rvb {
1828 1.41 christos const char *typestr;
1829 1.1 rvb
1830 1.1 rvb switch (attr->va_type) {
1831 1.1 rvb case VNON:
1832 1.1 rvb typestr = "VNON";
1833 1.1 rvb break;
1834 1.1 rvb case VREG:
1835 1.1 rvb typestr = "VREG";
1836 1.1 rvb break;
1837 1.1 rvb case VDIR:
1838 1.1 rvb typestr = "VDIR";
1839 1.1 rvb break;
1840 1.1 rvb case VBLK:
1841 1.1 rvb typestr = "VBLK";
1842 1.1 rvb break;
1843 1.1 rvb case VCHR:
1844 1.1 rvb typestr = "VCHR";
1845 1.1 rvb break;
1846 1.1 rvb case VLNK:
1847 1.1 rvb typestr = "VLNK";
1848 1.1 rvb break;
1849 1.1 rvb case VSOCK:
1850 1.1 rvb typestr = "VSCK";
1851 1.1 rvb break;
1852 1.1 rvb case VFIFO:
1853 1.1 rvb typestr = "VFFO";
1854 1.1 rvb break;
1855 1.1 rvb case VBAD:
1856 1.1 rvb typestr = "VBAD";
1857 1.1 rvb break;
1858 1.1 rvb default:
1859 1.1 rvb typestr = "????";
1860 1.1 rvb break;
1861 1.1 rvb }
1862 1.1 rvb
1863 1.1 rvb
1864 1.1 rvb myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1865 1.1 rvb typestr, (int)attr->va_mode, (int)attr->va_uid,
1866 1.1 rvb (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1867 1.1 rvb
1868 1.1 rvb myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1869 1.40 perry (int)attr->va_fileid, (int)attr->va_nlink,
1870 1.1 rvb (int)attr->va_size,
1871 1.1 rvb (int)attr->va_blocksize,(int)attr->va_bytes));
1872 1.1 rvb myprintf((" gen %ld flags %ld vaflags %d\n",
1873 1.1 rvb attr->va_gen, attr->va_flags, attr->va_vaflags));
1874 1.1 rvb myprintf((" atime sec %d nsec %d\n",
1875 1.1 rvb (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1876 1.1 rvb myprintf((" mtime sec %d nsec %d\n",
1877 1.1 rvb (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1878 1.1 rvb myprintf((" ctime sec %d nsec %d\n",
1879 1.1 rvb (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1880 1.1 rvb }
1881 1.1 rvb
1882 1.1 rvb /* How to print a ucred */
1883 1.1 rvb void
1884 1.49 elad print_cred(kauth_cred_t cred)
1885 1.1 rvb {
1886 1.1 rvb
1887 1.49 elad uint16_t ngroups;
1888 1.1 rvb int i;
1889 1.1 rvb
1890 1.49 elad myprintf(("ref %d\tuid %d\n", kauth_cred_getrefcnt(cred),
1891 1.49 elad kauth_cred_geteuid(cred)));
1892 1.1 rvb
1893 1.49 elad ngroups = kauth_cred_ngroups(cred);
1894 1.49 elad for (i=0; i < ngroups; i++)
1895 1.49 elad myprintf(("\tgroup %d: (%d)\n", i, kauth_cred_group(cred, i)));
1896 1.1 rvb myprintf(("\n"));
1897 1.1 rvb
1898 1.1 rvb }
1899 1.1 rvb
1900 1.1 rvb /*
1901 1.1 rvb * Return a vnode for the given fid.
1902 1.1 rvb * If no cnode exists for this fid create one and put it
1903 1.37 drochner * in a table hashed by coda_f2i(). If the cnode for
1904 1.1 rvb * this fid is already in the table return it (ref count is
1905 1.3 rvb * incremented by coda_find. The cnode will be flushed from the
1906 1.3 rvb * table when coda_inactive calls coda_unsave.
1907 1.1 rvb */
1908 1.1 rvb struct cnode *
1909 1.43 xtraeme make_coda_node(CodaFid *fid, struct mount *vfsp, short type)
1910 1.1 rvb {
1911 1.1 rvb struct cnode *cp;
1912 1.1 rvb int err;
1913 1.1 rvb
1914 1.3 rvb if ((cp = coda_find(fid)) == NULL) {
1915 1.1 rvb struct vnode *vp;
1916 1.40 perry
1917 1.3 rvb cp = coda_alloc();
1918 1.1 rvb cp->c_fid = *fid;
1919 1.40 perry
1920 1.40 perry err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
1921 1.40 perry if (err) {
1922 1.40 perry panic("coda: getnewvnode returned error %d", err);
1923 1.40 perry }
1924 1.40 perry vp->v_data = cp;
1925 1.40 perry vp->v_type = type;
1926 1.40 perry cp->c_vnode = vp;
1927 1.3 rvb coda_save(cp);
1928 1.40 perry
1929 1.1 rvb } else {
1930 1.1 rvb vref(CTOV(cp));
1931 1.1 rvb }
1932 1.1 rvb
1933 1.1 rvb return cp;
1934 1.25 chs }
1935 1.25 chs
1936 1.25 chs int
1937 1.43 xtraeme coda_getpages(void *v)
1938 1.25 chs {
1939 1.25 chs struct vop_getpages_args /* {
1940 1.25 chs struct vnode *a_vp;
1941 1.25 chs voff_t a_offset;
1942 1.25 chs struct vm_page **a_m;
1943 1.25 chs int *a_count;
1944 1.25 chs int a_centeridx;
1945 1.25 chs vm_prot_t a_access_type;
1946 1.25 chs int a_advice;
1947 1.25 chs int a_flags;
1948 1.25 chs } */ *ap = v;
1949 1.25 chs struct vnode *vp = ap->a_vp;
1950 1.25 chs struct cnode *cp = VTOC(vp);
1951 1.45 christos struct lwp *l = curlwp;
1952 1.50 ad kauth_cred_t cred = l->l_cred;
1953 1.25 chs int error;
1954 1.25 chs
1955 1.25 chs /* Check for control object. */
1956 1.25 chs if (IS_CTL_VP(vp)) {
1957 1.25 chs return(EINVAL);
1958 1.25 chs }
1959 1.25 chs
1960 1.45 christos error = VOP_OPEN(vp, FREAD, cred, l);
1961 1.25 chs if (error) {
1962 1.25 chs return error;
1963 1.25 chs }
1964 1.25 chs ap->a_vp = cp->c_ovp;
1965 1.25 chs error = VOCALL(ap->a_vp->v_op, VOFFSET(vop_getpages), ap);
1966 1.45 christos (void) VOP_CLOSE(vp, FREAD, cred, l);
1967 1.25 chs return error;
1968 1.25 chs }
1969 1.25 chs
1970 1.25 chs int
1971 1.43 xtraeme coda_putpages(void *v)
1972 1.25 chs {
1973 1.25 chs struct vop_putpages_args /* {
1974 1.25 chs struct vnode *a_vp;
1975 1.25 chs voff_t a_offlo;
1976 1.25 chs voff_t a_offhi;
1977 1.25 chs int a_flags;
1978 1.25 chs } */ *ap = v;
1979 1.25 chs struct vnode *vp = ap->a_vp;
1980 1.30 chs
1981 1.30 chs simple_unlock(&vp->v_interlock);
1982 1.25 chs
1983 1.25 chs /* Check for control object. */
1984 1.25 chs if (IS_CTL_VP(vp)) {
1985 1.25 chs return(EINVAL);
1986 1.25 chs }
1987 1.25 chs
1988 1.25 chs /*
1989 1.25 chs * XXX
1990 1.25 chs * we'd like to do something useful here for msync(),
1991 1.25 chs * but that turns out to be hard.
1992 1.25 chs */
1993 1.25 chs
1994 1.25 chs return 0;
1995 1.1 rvb }
1996