coda_vfsops.c revision 1.58.8.2 1 1.58.8.2 pooka /* $NetBSD: coda_vfsops.c,v 1.58.8.2 2007/07/31 21:14:20 pooka Exp $ */
2 1.58.8.2 pooka
3 1.58.8.2 pooka /*
4 1.58.8.2 pooka *
5 1.58.8.2 pooka * Coda: an Experimental Distributed File System
6 1.58.8.2 pooka * Release 3.1
7 1.58.8.2 pooka *
8 1.58.8.2 pooka * Copyright (c) 1987-1998 Carnegie Mellon University
9 1.58.8.2 pooka * All Rights Reserved
10 1.58.8.2 pooka *
11 1.58.8.2 pooka * Permission to use, copy, modify and distribute this software and its
12 1.58.8.2 pooka * documentation is hereby granted, provided that both the copyright
13 1.58.8.2 pooka * notice and this permission notice appear in all copies of the
14 1.58.8.2 pooka * software, derivative works or modified versions, and any portions
15 1.58.8.2 pooka * thereof, and that both notices appear in supporting documentation, and
16 1.58.8.2 pooka * that credit is given to Carnegie Mellon University in all documents
17 1.58.8.2 pooka * and publicity pertaining to direct or indirect use of this code or its
18 1.58.8.2 pooka * derivatives.
19 1.58.8.2 pooka *
20 1.58.8.2 pooka * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
21 1.58.8.2 pooka * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
22 1.58.8.2 pooka * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
23 1.58.8.2 pooka * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
24 1.58.8.2 pooka * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
25 1.58.8.2 pooka * ANY DERIVATIVE WORK.
26 1.58.8.2 pooka *
27 1.58.8.2 pooka * Carnegie Mellon encourages users of this software to return any
28 1.58.8.2 pooka * improvements or extensions that they make, and to grant Carnegie
29 1.58.8.2 pooka * Mellon the rights to redistribute these changes without encumbrance.
30 1.58.8.2 pooka *
31 1.58.8.2 pooka * @(#) cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
32 1.58.8.2 pooka */
33 1.58.8.2 pooka
34 1.58.8.2 pooka /*
35 1.58.8.2 pooka * Mach Operating System
36 1.58.8.2 pooka * Copyright (c) 1989 Carnegie-Mellon University
37 1.58.8.2 pooka * All rights reserved. The CMU software License Agreement specifies
38 1.58.8.2 pooka * the terms and conditions for use and redistribution.
39 1.58.8.2 pooka */
40 1.58.8.2 pooka
41 1.58.8.2 pooka /*
42 1.58.8.2 pooka * This code was written for the Coda file system at Carnegie Mellon
43 1.58.8.2 pooka * University. Contributers include David Steere, James Kistler, and
44 1.58.8.2 pooka * M. Satyanarayanan.
45 1.58.8.2 pooka */
46 1.58.8.2 pooka
47 1.58.8.2 pooka #include <sys/cdefs.h>
48 1.58.8.2 pooka __KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.58.8.2 2007/07/31 21:14:20 pooka Exp $");
49 1.58.8.2 pooka
50 1.58.8.2 pooka #ifdef _LKM
51 1.58.8.2 pooka #define NVCODA 4
52 1.58.8.2 pooka #else
53 1.58.8.2 pooka #include <vcoda.h>
54 1.58.8.2 pooka #endif
55 1.58.8.2 pooka
56 1.58.8.2 pooka #include <sys/param.h>
57 1.58.8.2 pooka #include <sys/systm.h>
58 1.58.8.2 pooka #include <sys/sysctl.h>
59 1.58.8.2 pooka #include <sys/malloc.h>
60 1.58.8.2 pooka #include <sys/conf.h>
61 1.58.8.2 pooka #include <sys/namei.h>
62 1.58.8.2 pooka #include <sys/dirent.h>
63 1.58.8.2 pooka #include <sys/mount.h>
64 1.58.8.2 pooka #include <sys/proc.h>
65 1.58.8.2 pooka #include <sys/select.h>
66 1.58.8.2 pooka #include <sys/kauth.h>
67 1.58.8.2 pooka
68 1.58.8.2 pooka #include <coda/coda.h>
69 1.58.8.2 pooka #include <coda/cnode.h>
70 1.58.8.2 pooka #include <coda/coda_vfsops.h>
71 1.58.8.2 pooka #include <coda/coda_venus.h>
72 1.58.8.2 pooka #include <coda/coda_subr.h>
73 1.58.8.2 pooka #include <coda/coda_opstats.h>
74 1.58.8.2 pooka /* for VN_RDEV */
75 1.58.8.2 pooka #include <miscfs/specfs/specdev.h>
76 1.58.8.2 pooka
77 1.58.8.2 pooka MALLOC_DEFINE(M_CODA, "coda", "Coda file system structures and tables");
78 1.58.8.2 pooka
79 1.58.8.2 pooka int codadebug = 0;
80 1.58.8.2 pooka
81 1.58.8.2 pooka int coda_vfsop_print_entry = 0;
82 1.58.8.2 pooka #define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__))
83 1.58.8.2 pooka
84 1.58.8.2 pooka struct vnode *coda_ctlvp;
85 1.58.8.2 pooka struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
86 1.58.8.2 pooka
87 1.58.8.2 pooka /* structure to keep statistics of internally generated/satisfied calls */
88 1.58.8.2 pooka
89 1.58.8.2 pooka struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
90 1.58.8.2 pooka
91 1.58.8.2 pooka #define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
92 1.58.8.2 pooka #define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
93 1.58.8.2 pooka #define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
94 1.58.8.2 pooka #define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
95 1.58.8.2 pooka
96 1.58.8.2 pooka extern const struct cdevsw vcoda_cdevsw;
97 1.58.8.2 pooka extern const struct vnodeopv_desc coda_vnodeop_opv_desc;
98 1.58.8.2 pooka
99 1.58.8.2 pooka const struct vnodeopv_desc * const coda_vnodeopv_descs[] = {
100 1.58.8.2 pooka &coda_vnodeop_opv_desc,
101 1.58.8.2 pooka NULL,
102 1.58.8.2 pooka };
103 1.58.8.2 pooka
104 1.58.8.2 pooka struct vfsops coda_vfsops = {
105 1.58.8.2 pooka MOUNT_CODA,
106 1.58.8.2 pooka 256, /* This is the pathname, unlike every other fs */
107 1.58.8.2 pooka coda_mount,
108 1.58.8.2 pooka coda_start,
109 1.58.8.2 pooka coda_unmount,
110 1.58.8.2 pooka coda_root,
111 1.58.8.2 pooka coda_quotactl,
112 1.58.8.2 pooka coda_nb_statvfs,
113 1.58.8.2 pooka coda_sync,
114 1.58.8.2 pooka coda_vget,
115 1.58.8.2 pooka (void *)eopnotsupp, /* vfs_fhtovp */
116 1.58.8.2 pooka (void *)eopnotsupp, /* vfs_vptofh */
117 1.58.8.2 pooka coda_init,
118 1.58.8.2 pooka NULL, /* vfs_reinit */
119 1.58.8.2 pooka coda_done,
120 1.58.8.2 pooka (int (*)(void)) eopnotsupp,
121 1.58.8.2 pooka (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
122 1.58.8.2 pooka vfs_stdextattrctl,
123 1.58.8.2 pooka (void *)eopnotsupp, /* vfs_suspendctl */
124 1.58.8.2 pooka coda_vnodeopv_descs,
125 1.58.8.2 pooka 0, /* vfs_refcount */
126 1.58.8.2 pooka { NULL, NULL }, /* vfs_list */
127 1.58.8.2 pooka };
128 1.58.8.2 pooka
129 1.58.8.2 pooka VFS_ATTACH(coda_vfsops);
130 1.58.8.2 pooka
131 1.58.8.2 pooka int
132 1.58.8.2 pooka coda_vfsopstats_init(void)
133 1.58.8.2 pooka {
134 1.58.8.2 pooka int i;
135 1.58.8.2 pooka
136 1.58.8.2 pooka for (i=0;i<CODA_VFSOPS_SIZE;i++) {
137 1.58.8.2 pooka coda_vfsopstats[i].opcode = i;
138 1.58.8.2 pooka coda_vfsopstats[i].entries = 0;
139 1.58.8.2 pooka coda_vfsopstats[i].sat_intrn = 0;
140 1.58.8.2 pooka coda_vfsopstats[i].unsat_intrn = 0;
141 1.58.8.2 pooka coda_vfsopstats[i].gen_intrn = 0;
142 1.58.8.2 pooka }
143 1.58.8.2 pooka
144 1.58.8.2 pooka return 0;
145 1.58.8.2 pooka }
146 1.58.8.2 pooka
147 1.58.8.2 pooka /*
148 1.58.8.2 pooka * cfs mount vfsop
149 1.58.8.2 pooka * Set up mount info record and attach it to vfs struct.
150 1.58.8.2 pooka */
151 1.58.8.2 pooka /*ARGSUSED*/
152 1.58.8.2 pooka int
153 1.58.8.2 pooka coda_mount(struct mount *vfsp, /* Allocated and initialized by mount(2) */
154 1.58.8.2 pooka const char *path, /* path covered: ignored by the fs-layer */
155 1.58.8.2 pooka void *data, /* Need to define a data type for this in netbsd? */
156 1.58.8.2 pooka size_t *data_len,
157 1.58.8.2 pooka struct lwp *l) /* The ever-famous lwp pointer */
158 1.58.8.2 pooka {
159 1.58.8.2 pooka struct nameidata nd;
160 1.58.8.2 pooka struct vnode *dvp;
161 1.58.8.2 pooka struct cnode *cp;
162 1.58.8.2 pooka dev_t dev;
163 1.58.8.2 pooka struct coda_mntinfo *mi;
164 1.58.8.2 pooka struct vnode *rtvp;
165 1.58.8.2 pooka const struct cdevsw *cdev;
166 1.58.8.2 pooka CodaFid rootfid = INVAL_FID;
167 1.58.8.2 pooka CodaFid ctlfid = CTL_FID;
168 1.58.8.2 pooka int error;
169 1.58.8.2 pooka
170 1.58.8.2 pooka if (vfsp->mnt_flag & MNT_GETARGS)
171 1.58.8.2 pooka return EINVAL;
172 1.58.8.2 pooka ENTRY;
173 1.58.8.2 pooka
174 1.58.8.2 pooka coda_vfsopstats_init();
175 1.58.8.2 pooka coda_vnodeopstats_init();
176 1.58.8.2 pooka
177 1.58.8.2 pooka MARK_ENTRY(CODA_MOUNT_STATS);
178 1.58.8.2 pooka if (CODA_MOUNTED(vfsp)) {
179 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
180 1.58.8.2 pooka return(EBUSY);
181 1.58.8.2 pooka }
182 1.58.8.2 pooka
183 1.58.8.2 pooka /* Validate mount device. Similar to getmdev(). */
184 1.58.8.2 pooka
185 1.58.8.2 pooka /*
186 1.58.8.2 pooka * XXX: coda passes the mount device as the entire mount args,
187 1.58.8.2 pooka * All other fs pass a structure contining a pointer.
188 1.58.8.2 pooka * In order to get sys_mount() to do the copyin() we've set a
189 1.58.8.2 pooka * fixed size for the filename buffer.
190 1.58.8.2 pooka */
191 1.58.8.2 pooka NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, data, l);
192 1.58.8.2 pooka error = namei(&nd);
193 1.58.8.2 pooka dvp = nd.ni_vp;
194 1.58.8.2 pooka
195 1.58.8.2 pooka if (error) {
196 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
197 1.58.8.2 pooka return (error);
198 1.58.8.2 pooka }
199 1.58.8.2 pooka if (dvp->v_type != VCHR) {
200 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
201 1.58.8.2 pooka vrele(dvp);
202 1.58.8.2 pooka return(ENXIO);
203 1.58.8.2 pooka }
204 1.58.8.2 pooka dev = dvp->v_specinfo->si_rdev;
205 1.58.8.2 pooka vrele(dvp);
206 1.58.8.2 pooka cdev = cdevsw_lookup(dev);
207 1.58.8.2 pooka if (cdev == NULL) {
208 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
209 1.58.8.2 pooka return(ENXIO);
210 1.58.8.2 pooka }
211 1.58.8.2 pooka
212 1.58.8.2 pooka /*
213 1.58.8.2 pooka * See if the device table matches our expectations.
214 1.58.8.2 pooka */
215 1.58.8.2 pooka if (cdev != &vcoda_cdevsw)
216 1.58.8.2 pooka {
217 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
218 1.58.8.2 pooka return(ENXIO);
219 1.58.8.2 pooka }
220 1.58.8.2 pooka
221 1.58.8.2 pooka if (minor(dev) >= NVCODA || minor(dev) < 0) {
222 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
223 1.58.8.2 pooka return(ENXIO);
224 1.58.8.2 pooka }
225 1.58.8.2 pooka
226 1.58.8.2 pooka /*
227 1.58.8.2 pooka * Initialize the mount record and link it to the vfs struct
228 1.58.8.2 pooka */
229 1.58.8.2 pooka mi = &coda_mnttbl[minor(dev)];
230 1.58.8.2 pooka
231 1.58.8.2 pooka if (!VC_OPEN(&mi->mi_vcomm)) {
232 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
233 1.58.8.2 pooka return(ENODEV);
234 1.58.8.2 pooka }
235 1.58.8.2 pooka
236 1.58.8.2 pooka /* No initialization (here) of mi_vcomm! */
237 1.58.8.2 pooka vfsp->mnt_data = mi;
238 1.58.8.2 pooka vfsp->mnt_stat.f_fsidx.__fsid_val[0] = 0;
239 1.58.8.2 pooka vfsp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CODA);
240 1.58.8.2 pooka vfsp->mnt_stat.f_fsid = vfsp->mnt_stat.f_fsidx.__fsid_val[0];
241 1.58.8.2 pooka vfsp->mnt_stat.f_namemax = MAXNAMLEN;
242 1.58.8.2 pooka mi->mi_vfsp = vfsp;
243 1.58.8.2 pooka
244 1.58.8.2 pooka /*
245 1.58.8.2 pooka * Make a root vnode to placate the Vnode interface, but don't
246 1.58.8.2 pooka * actually make the CODA_ROOT call to venus until the first call
247 1.58.8.2 pooka * to coda_root in case a server is down while venus is starting.
248 1.58.8.2 pooka */
249 1.58.8.2 pooka cp = make_coda_node(&rootfid, vfsp, VDIR);
250 1.58.8.2 pooka rtvp = CTOV(cp);
251 1.58.8.2 pooka rtvp->v_flag |= VROOT;
252 1.58.8.2 pooka
253 1.58.8.2 pooka /* cp = make_coda_node(&ctlfid, vfsp, VCHR);
254 1.58.8.2 pooka The above code seems to cause a loop in the cnode links.
255 1.58.8.2 pooka I don't totally understand when it happens, it is caught
256 1.58.8.2 pooka when closing down the system.
257 1.58.8.2 pooka */
258 1.58.8.2 pooka cp = make_coda_node(&ctlfid, 0, VCHR);
259 1.58.8.2 pooka
260 1.58.8.2 pooka coda_ctlvp = CTOV(cp);
261 1.58.8.2 pooka
262 1.58.8.2 pooka /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
263 1.58.8.2 pooka mi->mi_vfsp = vfsp;
264 1.58.8.2 pooka mi->mi_rootvp = rtvp;
265 1.58.8.2 pooka
266 1.58.8.2 pooka /* set filesystem block size */
267 1.58.8.2 pooka vfsp->mnt_stat.f_bsize = 8192; /* XXX -JJK */
268 1.58.8.2 pooka vfsp->mnt_stat.f_frsize = 8192; /* XXX -JJK */
269 1.58.8.2 pooka
270 1.58.8.2 pooka /* error is currently guaranteed to be zero, but in case some
271 1.58.8.2 pooka code changes... */
272 1.58.8.2 pooka CODADEBUG(1,
273 1.58.8.2 pooka myprintf(("coda_mount returned %d\n",error)););
274 1.58.8.2 pooka if (error)
275 1.58.8.2 pooka MARK_INT_FAIL(CODA_MOUNT_STATS);
276 1.58.8.2 pooka else
277 1.58.8.2 pooka MARK_INT_SAT(CODA_MOUNT_STATS);
278 1.58.8.2 pooka
279 1.58.8.2 pooka return set_statvfs_info("/coda", UIO_SYSSPACE, "CODA", UIO_SYSSPACE,
280 1.58.8.2 pooka vfsp->mnt_op->vfs_name, vfsp, l);
281 1.58.8.2 pooka }
282 1.58.8.2 pooka
283 1.58.8.2 pooka int
284 1.58.8.2 pooka coda_start(struct mount *vfsp, int flags, struct lwp *l)
285 1.58.8.2 pooka {
286 1.58.8.2 pooka ENTRY;
287 1.58.8.2 pooka vftomi(vfsp)->mi_started = 1;
288 1.58.8.2 pooka return (0);
289 1.58.8.2 pooka }
290 1.58.8.2 pooka
291 1.58.8.2 pooka int
292 1.58.8.2 pooka coda_unmount(struct mount *vfsp, int mntflags, struct lwp *l)
293 1.58.8.2 pooka {
294 1.58.8.2 pooka struct coda_mntinfo *mi = vftomi(vfsp);
295 1.58.8.2 pooka int active, error = 0;
296 1.58.8.2 pooka
297 1.58.8.2 pooka ENTRY;
298 1.58.8.2 pooka MARK_ENTRY(CODA_UMOUNT_STATS);
299 1.58.8.2 pooka if (!CODA_MOUNTED(vfsp)) {
300 1.58.8.2 pooka MARK_INT_FAIL(CODA_UMOUNT_STATS);
301 1.58.8.2 pooka return(EINVAL);
302 1.58.8.2 pooka }
303 1.58.8.2 pooka
304 1.58.8.2 pooka if (mi->mi_vfsp == vfsp) { /* We found the victim */
305 1.58.8.2 pooka if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
306 1.58.8.2 pooka return (EBUSY); /* Venus is still running */
307 1.58.8.2 pooka
308 1.58.8.2 pooka #ifdef DEBUG
309 1.58.8.2 pooka printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
310 1.58.8.2 pooka #endif
311 1.58.8.2 pooka mi->mi_started = 0;
312 1.58.8.2 pooka
313 1.58.8.2 pooka vrele(mi->mi_rootvp);
314 1.58.8.2 pooka
315 1.58.8.2 pooka active = coda_kill(vfsp, NOT_DOWNCALL);
316 1.58.8.2 pooka mi->mi_rootvp->v_flag &= ~VROOT;
317 1.58.8.2 pooka error = vflush(mi->mi_vfsp, NULLVP, FORCECLOSE);
318 1.58.8.2 pooka printf("coda_unmount: active = %d, vflush active %d\n", active, error);
319 1.58.8.2 pooka error = 0;
320 1.58.8.2 pooka
321 1.58.8.2 pooka /* I'm going to take this out to allow lookups to go through. I'm
322 1.58.8.2 pooka * not sure it's important anyway. -- DCS 2/2/94
323 1.58.8.2 pooka */
324 1.58.8.2 pooka /* vfsp->VFS_DATA = NULL; */
325 1.58.8.2 pooka
326 1.58.8.2 pooka /* No more vfsp's to hold onto */
327 1.58.8.2 pooka mi->mi_vfsp = NULL;
328 1.58.8.2 pooka mi->mi_rootvp = NULL;
329 1.58.8.2 pooka
330 1.58.8.2 pooka if (error)
331 1.58.8.2 pooka MARK_INT_FAIL(CODA_UMOUNT_STATS);
332 1.58.8.2 pooka else
333 1.58.8.2 pooka MARK_INT_SAT(CODA_UMOUNT_STATS);
334 1.58.8.2 pooka
335 1.58.8.2 pooka return(error);
336 1.58.8.2 pooka }
337 1.58.8.2 pooka return (EINVAL);
338 1.58.8.2 pooka }
339 1.58.8.2 pooka
340 1.58.8.2 pooka /*
341 1.58.8.2 pooka * find root of cfs
342 1.58.8.2 pooka */
343 1.58.8.2 pooka int
344 1.58.8.2 pooka coda_root(struct mount *vfsp, struct vnode **vpp)
345 1.58.8.2 pooka {
346 1.58.8.2 pooka struct coda_mntinfo *mi = vftomi(vfsp);
347 1.58.8.2 pooka int error;
348 1.58.8.2 pooka struct lwp *l = curlwp; /* XXX - bnoble */
349 1.58.8.2 pooka CodaFid VFid;
350 1.58.8.2 pooka static const CodaFid invalfid = INVAL_FID;
351 1.58.8.2 pooka
352 1.58.8.2 pooka ENTRY;
353 1.58.8.2 pooka MARK_ENTRY(CODA_ROOT_STATS);
354 1.58.8.2 pooka
355 1.58.8.2 pooka if (vfsp == mi->mi_vfsp) {
356 1.58.8.2 pooka if (memcmp(&VTOC(mi->mi_rootvp)->c_fid, &invalfid, sizeof(CodaFid)))
357 1.58.8.2 pooka { /* Found valid root. */
358 1.58.8.2 pooka *vpp = mi->mi_rootvp;
359 1.58.8.2 pooka /* On Mach, this is vref. On NetBSD, VOP_LOCK */
360 1.58.8.2 pooka vref(*vpp);
361 1.58.8.2 pooka vn_lock(*vpp, LK_EXCLUSIVE);
362 1.58.8.2 pooka MARK_INT_SAT(CODA_ROOT_STATS);
363 1.58.8.2 pooka return(0);
364 1.58.8.2 pooka }
365 1.58.8.2 pooka }
366 1.58.8.2 pooka
367 1.58.8.2 pooka error = venus_root(vftomi(vfsp), l->l_cred, l->l_proc, &VFid);
368 1.58.8.2 pooka
369 1.58.8.2 pooka if (!error) {
370 1.58.8.2 pooka /*
371 1.58.8.2 pooka * Save the new rootfid in the cnode, and rehash the cnode into the
372 1.58.8.2 pooka * cnode hash with the new fid key.
373 1.58.8.2 pooka */
374 1.58.8.2 pooka coda_unsave(VTOC(mi->mi_rootvp));
375 1.58.8.2 pooka VTOC(mi->mi_rootvp)->c_fid = VFid;
376 1.58.8.2 pooka coda_save(VTOC(mi->mi_rootvp));
377 1.58.8.2 pooka
378 1.58.8.2 pooka *vpp = mi->mi_rootvp;
379 1.58.8.2 pooka vref(*vpp);
380 1.58.8.2 pooka vn_lock(*vpp, LK_EXCLUSIVE);
381 1.58.8.2 pooka MARK_INT_SAT(CODA_ROOT_STATS);
382 1.58.8.2 pooka goto exit;
383 1.58.8.2 pooka } else if (error == ENODEV || error == EINTR) {
384 1.58.8.2 pooka /* Gross hack here! */
385 1.58.8.2 pooka /*
386 1.58.8.2 pooka * If Venus fails to respond to the CODA_ROOT call, coda_call returns
387 1.58.8.2 pooka * ENODEV. Return the uninitialized root vnode to allow vfs
388 1.58.8.2 pooka * operations such as unmount to continue. Without this hack,
389 1.58.8.2 pooka * there is no way to do an unmount if Venus dies before a
390 1.58.8.2 pooka * successful CODA_ROOT call is done. All vnode operations
391 1.58.8.2 pooka * will fail.
392 1.58.8.2 pooka */
393 1.58.8.2 pooka *vpp = mi->mi_rootvp;
394 1.58.8.2 pooka vref(*vpp);
395 1.58.8.2 pooka vn_lock(*vpp, LK_EXCLUSIVE);
396 1.58.8.2 pooka MARK_INT_FAIL(CODA_ROOT_STATS);
397 1.58.8.2 pooka error = 0;
398 1.58.8.2 pooka goto exit;
399 1.58.8.2 pooka } else {
400 1.58.8.2 pooka CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
401 1.58.8.2 pooka MARK_INT_FAIL(CODA_ROOT_STATS);
402 1.58.8.2 pooka
403 1.58.8.2 pooka goto exit;
404 1.58.8.2 pooka }
405 1.58.8.2 pooka exit:
406 1.58.8.2 pooka return(error);
407 1.58.8.2 pooka }
408 1.58.8.2 pooka
409 1.58.8.2 pooka int
410 1.58.8.2 pooka coda_quotactl(struct mount *vfsp, int cmd, uid_t uid,
411 1.58.8.2 pooka void *arg, struct lwp *l)
412 1.58.8.2 pooka {
413 1.58.8.2 pooka ENTRY;
414 1.58.8.2 pooka return (EOPNOTSUPP);
415 1.58.8.2 pooka }
416 1.58.8.2 pooka
417 1.58.8.2 pooka /*
418 1.58.8.2 pooka * Get file system statistics.
419 1.58.8.2 pooka */
420 1.58.8.2 pooka int
421 1.58.8.2 pooka coda_nb_statvfs(struct mount *vfsp, struct statvfs *sbp, struct lwp *l)
422 1.58.8.2 pooka {
423 1.58.8.2 pooka struct coda_statfs fsstat;
424 1.58.8.2 pooka int error;
425 1.58.8.2 pooka
426 1.58.8.2 pooka ENTRY;
427 1.58.8.2 pooka MARK_ENTRY(CODA_STATFS_STATS);
428 1.58.8.2 pooka if (!CODA_MOUNTED(vfsp)) {
429 1.58.8.2 pooka /* MARK_INT_FAIL(CODA_STATFS_STATS); */
430 1.58.8.2 pooka return(EINVAL);
431 1.58.8.2 pooka }
432 1.58.8.2 pooka
433 1.58.8.2 pooka /* XXX - what to do about f_flags, others? --bnoble */
434 1.58.8.2 pooka /* Below This is what AFS does
435 1.58.8.2 pooka #define NB_SFS_SIZ 0x895440
436 1.58.8.2 pooka */
437 1.58.8.2 pooka /* Note: Normal fs's have a bsize of 0x400 == 1024 */
438 1.58.8.2 pooka
439 1.58.8.2 pooka error = venus_statfs(vftomi(vfsp), l->l_cred, l, &fsstat);
440 1.58.8.2 pooka
441 1.58.8.2 pooka if (!error) {
442 1.58.8.2 pooka sbp->f_bsize = 8192; /* XXX */
443 1.58.8.2 pooka sbp->f_frsize = 8192; /* XXX */
444 1.58.8.2 pooka sbp->f_iosize = 8192; /* XXX */
445 1.58.8.2 pooka sbp->f_blocks = fsstat.f_blocks;
446 1.58.8.2 pooka sbp->f_bfree = fsstat.f_bfree;
447 1.58.8.2 pooka sbp->f_bavail = fsstat.f_bavail;
448 1.58.8.2 pooka sbp->f_bresvd = 0;
449 1.58.8.2 pooka sbp->f_files = fsstat.f_files;
450 1.58.8.2 pooka sbp->f_ffree = fsstat.f_ffree;
451 1.58.8.2 pooka sbp->f_favail = fsstat.f_ffree;
452 1.58.8.2 pooka sbp->f_fresvd = 0;
453 1.58.8.2 pooka copy_statvfs_info(sbp, vfsp);
454 1.58.8.2 pooka }
455 1.58.8.2 pooka
456 1.58.8.2 pooka MARK_INT_SAT(CODA_STATFS_STATS);
457 1.58.8.2 pooka return(error);
458 1.58.8.2 pooka }
459 1.58.8.2 pooka
460 1.58.8.2 pooka /*
461 1.58.8.2 pooka * Flush any pending I/O.
462 1.58.8.2 pooka */
463 1.58.8.2 pooka int
464 1.58.8.2 pooka coda_sync(struct mount *vfsp, int waitfor,
465 1.58.8.2 pooka kauth_cred_t cred, struct lwp *l)
466 1.58.8.2 pooka {
467 1.58.8.2 pooka ENTRY;
468 1.58.8.2 pooka MARK_ENTRY(CODA_SYNC_STATS);
469 1.58.8.2 pooka MARK_INT_SAT(CODA_SYNC_STATS);
470 1.58.8.2 pooka return(0);
471 1.58.8.2 pooka }
472 1.58.8.2 pooka
473 1.58.8.2 pooka int
474 1.58.8.2 pooka coda_vget(struct mount *vfsp, ino_t ino,
475 1.58.8.2 pooka struct vnode **vpp)
476 1.58.8.2 pooka {
477 1.58.8.2 pooka ENTRY;
478 1.58.8.2 pooka return (EOPNOTSUPP);
479 1.58.8.2 pooka }
480 1.58.8.2 pooka
481 1.58.8.2 pooka /*
482 1.58.8.2 pooka * fhtovp is now what vget used to be in 4.3-derived systems. For
483 1.58.8.2 pooka * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
484 1.58.8.2 pooka * a type-specific fid.
485 1.58.8.2 pooka */
486 1.58.8.2 pooka int
487 1.58.8.2 pooka coda_fhtovp(struct mount *vfsp, struct fid *fhp, struct mbuf *nam,
488 1.58.8.2 pooka struct vnode **vpp, int *exflagsp,
489 1.58.8.2 pooka kauth_cred_t *creadanonp)
490 1.58.8.2 pooka {
491 1.58.8.2 pooka struct cfid *cfid = (struct cfid *)fhp;
492 1.58.8.2 pooka struct cnode *cp = 0;
493 1.58.8.2 pooka int error;
494 1.58.8.2 pooka struct lwp *l = curlwp; /* XXX -mach */
495 1.58.8.2 pooka CodaFid VFid;
496 1.58.8.2 pooka int vtype;
497 1.58.8.2 pooka
498 1.58.8.2 pooka ENTRY;
499 1.58.8.2 pooka
500 1.58.8.2 pooka MARK_ENTRY(CODA_VGET_STATS);
501 1.58.8.2 pooka /* Check for vget of control object. */
502 1.58.8.2 pooka if (IS_CTL_FID(&cfid->cfid_fid)) {
503 1.58.8.2 pooka *vpp = coda_ctlvp;
504 1.58.8.2 pooka vref(coda_ctlvp);
505 1.58.8.2 pooka MARK_INT_SAT(CODA_VGET_STATS);
506 1.58.8.2 pooka return(0);
507 1.58.8.2 pooka }
508 1.58.8.2 pooka
509 1.58.8.2 pooka error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, l->l_cred, l->l_proc, &VFid, &vtype);
510 1.58.8.2 pooka
511 1.58.8.2 pooka if (error) {
512 1.58.8.2 pooka CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
513 1.58.8.2 pooka *vpp = (struct vnode *)0;
514 1.58.8.2 pooka } else {
515 1.58.8.2 pooka CODADEBUG(CODA_VGET,
516 1.58.8.2 pooka myprintf(("vget: %s type %d result %d\n",
517 1.58.8.2 pooka coda_f2s(&VFid), vtype, error)); )
518 1.58.8.2 pooka
519 1.58.8.2 pooka cp = make_coda_node(&VFid, vfsp, vtype);
520 1.58.8.2 pooka *vpp = CTOV(cp);
521 1.58.8.2 pooka }
522 1.58.8.2 pooka return(error);
523 1.58.8.2 pooka }
524 1.58.8.2 pooka
525 1.58.8.2 pooka int
526 1.58.8.2 pooka coda_vptofh(struct vnode *vnp, struct fid *fidp)
527 1.58.8.2 pooka {
528 1.58.8.2 pooka ENTRY;
529 1.58.8.2 pooka return (EOPNOTSUPP);
530 1.58.8.2 pooka }
531 1.58.8.2 pooka
532 1.58.8.2 pooka void
533 1.58.8.2 pooka coda_init(void)
534 1.58.8.2 pooka {
535 1.58.8.2 pooka ENTRY;
536 1.58.8.2 pooka }
537 1.58.8.2 pooka
538 1.58.8.2 pooka void
539 1.58.8.2 pooka coda_done(void)
540 1.58.8.2 pooka {
541 1.58.8.2 pooka ENTRY;
542 1.58.8.2 pooka }
543 1.58.8.2 pooka
544 1.58.8.2 pooka SYSCTL_SETUP(sysctl_vfs_coda_setup, "sysctl vfs.coda subtree setup")
545 1.58.8.2 pooka {
546 1.58.8.2 pooka sysctl_createv(clog, 0, NULL, NULL,
547 1.58.8.2 pooka CTLFLAG_PERMANENT,
548 1.58.8.2 pooka CTLTYPE_NODE, "vfs", NULL,
549 1.58.8.2 pooka NULL, 0, NULL, 0,
550 1.58.8.2 pooka CTL_VFS, CTL_EOL);
551 1.58.8.2 pooka sysctl_createv(clog, 0, NULL, NULL,
552 1.58.8.2 pooka CTLFLAG_PERMANENT,
553 1.58.8.2 pooka CTLTYPE_NODE, "coda",
554 1.58.8.2 pooka SYSCTL_DESCR("code vfs options"),
555 1.58.8.2 pooka NULL, 0, NULL, 0,
556 1.58.8.2 pooka CTL_VFS, 18, CTL_EOL);
557 1.58.8.2 pooka /*
558 1.58.8.2 pooka * XXX the "18" above could be dynamic, thereby eliminating
559 1.58.8.2 pooka * one more instance of the "number to vfs" mapping problem,
560 1.58.8.2 pooka * but "18" is the order as taken from sys/mount.h
561 1.58.8.2 pooka */
562 1.58.8.2 pooka
563 1.58.8.2 pooka /*
564 1.58.8.2 pooka sysctl_createv(clog, 0, NULL, NULL,
565 1.58.8.2 pooka CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
566 1.58.8.2 pooka CTLTYPE_INT, "clusterread",
567 1.58.8.2 pooka SYSCTL_DESCR( anyone? ),
568 1.58.8.2 pooka NULL, 0, &doclusterread, 0,
569 1.58.8.2 pooka CTL_VFS, 18, FFS_CLUSTERREAD, CTL_EOL);
570 1.58.8.2 pooka */
571 1.58.8.2 pooka }
572 1.58.8.2 pooka
573 1.58.8.2 pooka /*
574 1.58.8.2 pooka * To allow for greater ease of use, some vnodes may be orphaned when
575 1.58.8.2 pooka * Venus dies. Certain operations should still be allowed to go
576 1.58.8.2 pooka * through, but without propagating orphan-ness. So this function will
577 1.58.8.2 pooka * get a new vnode for the file from the current run of Venus.
578 1.58.8.2 pooka */
579 1.58.8.2 pooka
580 1.58.8.2 pooka int
581 1.58.8.2 pooka getNewVnode(struct vnode **vpp)
582 1.58.8.2 pooka {
583 1.58.8.2 pooka struct cfid cfid;
584 1.58.8.2 pooka struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
585 1.58.8.2 pooka
586 1.58.8.2 pooka ENTRY;
587 1.58.8.2 pooka
588 1.58.8.2 pooka cfid.cfid_len = (short)sizeof(CodaFid);
589 1.58.8.2 pooka cfid.cfid_fid = VTOC(*vpp)->c_fid; /* Structure assignment. */
590 1.58.8.2 pooka /* XXX ? */
591 1.58.8.2 pooka
592 1.58.8.2 pooka /* We're guessing that if set, the 1st element on the list is a
593 1.58.8.2 pooka * valid vnode to use. If not, return ENODEV as venus is dead.
594 1.58.8.2 pooka */
595 1.58.8.2 pooka if (mi->mi_vfsp == NULL)
596 1.58.8.2 pooka return ENODEV;
597 1.58.8.2 pooka
598 1.58.8.2 pooka return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
599 1.58.8.2 pooka NULL, NULL);
600 1.58.8.2 pooka }
601 1.58.8.2 pooka
602 1.58.8.2 pooka #include <ufs/ufs/quota.h>
603 1.58.8.2 pooka #include <ufs/ufs/ufsmount.h>
604 1.58.8.2 pooka /* get the mount structure corresponding to a given device. Assume
605 1.58.8.2 pooka * device corresponds to a UFS. Return NULL if no device is found.
606 1.58.8.2 pooka */
607 1.58.8.2 pooka struct mount *devtomp(dev_t dev)
608 1.58.8.2 pooka {
609 1.58.8.2 pooka struct mount *mp, *nmp;
610 1.58.8.2 pooka
611 1.58.8.2 pooka for (mp = mountlist.cqh_first; mp != (void*)&mountlist; mp = nmp) {
612 1.58.8.2 pooka nmp = mp->mnt_list.cqe_next;
613 1.58.8.2 pooka if ((!strcmp(mp->mnt_op->vfs_name, MOUNT_UFS)) &&
614 1.58.8.2 pooka ((VFSTOUFS(mp))->um_dev == (dev_t) dev)) {
615 1.58.8.2 pooka /* mount corresponds to UFS and the device matches one we want */
616 1.58.8.2 pooka return(mp);
617 1.58.8.2 pooka }
618 1.58.8.2 pooka }
619 1.58.8.2 pooka /* mount structure wasn't found */
620 1.58.8.2 pooka return(NULL);
621 1.58.8.2 pooka }
622