2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed
6 * to Berkeley by John Heidemann of the UCLA Ficus project.
8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * $FreeBSD: src/sys/kern/vfs_default.c,v 1.28.2.7 2003/01/10 18:23:26 bde Exp $
40 * $DragonFly: src/sys/kern/vfs_default.c,v 1.11 2004/08/13 17:51:09 dillon Exp $
43 #include <sys/param.h>
44 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/mount.h>
51 #include <sys/unistd.h>
52 #include <sys/vnode.h>
55 #include <machine/limits.h>
58 #include <vm/vm_object.h>
59 #include <vm/vm_page.h>
60 #include <vm/vm_pager.h>
61 #include <vm/vnode_pager.h>
63 static int vop_nolookup (struct vop_lookup_args *);
64 static int vop_nostrategy (struct vop_strategy_args *);
67 * This vnode table stores what we want to do if the filesystem doesn't
68 * implement a particular VOP.
70 * If there is no specific entry here, we will return EOPNOTSUPP.
74 struct vop_ops *default_vnode_vops;
75 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
76 { &vop_default_desc, vop_eopnotsupp },
77 { &vop_advlock_desc, vop_einval },
78 { &vop_bwrite_desc, (void *) vop_stdbwrite },
79 { &vop_close_desc, vop_null },
80 { &vop_createvobject_desc, (void *) vop_stdcreatevobject },
81 { &vop_destroyvobject_desc, (void *) vop_stddestroyvobject },
82 { &vop_fsync_desc, vop_null },
83 { &vop_getvobject_desc, (void *) vop_stdgetvobject },
84 { &vop_ioctl_desc, vop_enotty },
85 { &vop_islocked_desc, (void *) vop_noislocked },
86 { &vop_lease_desc, vop_null },
87 { &vop_lock_desc, (void *) vop_nolock },
88 { &vop_mmap_desc, vop_einval },
89 { &vop_lookup_desc, (void *) vop_nolookup },
90 { &vop_open_desc, vop_null },
91 { &vop_pathconf_desc, vop_einval },
92 { &vop_poll_desc, (void *) vop_nopoll },
93 { &vop_readlink_desc, vop_einval },
94 { &vop_reallocblks_desc, vop_eopnotsupp },
95 { &vop_revoke_desc, (void *) vop_stdrevoke },
96 { &vop_strategy_desc, (void *) vop_nostrategy },
97 { &vop_unlock_desc, (void *) vop_nounlock },
98 { &vop_getacl_desc, vop_eopnotsupp },
99 { &vop_setacl_desc, vop_eopnotsupp },
100 { &vop_aclcheck_desc, vop_eopnotsupp },
101 { &vop_getextattr_desc, vop_eopnotsupp },
102 { &vop_setextattr_desc, vop_eopnotsupp },
106 static struct vnodeopv_desc default_vnodeop_opv_desc =
107 { &default_vnode_vops, default_vnodeop_entries };
109 VNODEOP_SET(default_vnodeop_opv_desc);
112 vop_eopnotsupp(struct vop_generic_args *ap)
115 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
121 vop_ebadf(struct vop_generic_args *ap)
127 vop_enotty(struct vop_generic_args *ap)
133 vop_einval(struct vop_generic_args *ap)
139 vop_null(struct vop_generic_args *ap)
145 vop_defaultop(struct vop_generic_args *ap)
147 return (VOCALL(default_vnode_vops, ap->a_desc->vdesc_offset, ap));
151 vop_panic(struct vop_generic_args *ap)
154 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
159 struct vop_lookup_args /* {
161 struct vnode **a_vpp;
162 struct componentname *a_cnp;
173 * Strategy routine for VFS devices that have none.
175 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
176 * routine. Typically this is done for a B_READ strategy call. Typically
177 * B_INVAL is assumed to already be clear prior to a write and should not
178 * be cleared manually unless you just made the buffer invalid. B_ERROR
179 * should be cleared either way.
183 vop_nostrategy (struct vop_strategy_args *ap)
185 printf("No strategy for buffer at %p\n", ap->a_bp);
186 vprint("", ap->a_vp);
187 vprint("", ap->a_bp->b_vp);
188 ap->a_bp->b_flags |= B_ERROR;
189 ap->a_bp->b_error = EOPNOTSUPP;
196 struct vop_pathconf_args /* {
203 switch (ap->a_name) {
205 *ap->a_retval = LINK_MAX;
208 *ap->a_retval = MAX_CANON;
211 *ap->a_retval = MAX_INPUT;
214 *ap->a_retval = PIPE_BUF;
216 case _PC_CHOWN_RESTRICTED:
220 *ap->a_retval = _POSIX_VDISABLE;
229 * Standard lock, unlock and islocked functions.
231 * These depend on the lock structure being the first element in the
232 * inode, ie: vp->v_data points to the the lock!
236 struct vop_lock_args /* {
238 lwkt_tokref_t a_vlock;
245 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
246 if (ap->a_flags & LK_INTERLOCK)
247 lwkt_reltoken(ap->a_vlock);
252 return (lockmgr(l, ap->a_flags, ap->a_vlock, ap->a_td));
254 return (debuglockmgr(l, ap->a_flags, ap->a_vlock, ap->a_td,
255 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line));
261 struct vop_unlock_args /* {
263 lwkt_tokref_t a_vlock;
270 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
271 if (ap->a_flags & LK_INTERLOCK)
272 lwkt_reltoken(ap->a_vlock);
276 return (lockmgr(l, ap->a_flags | LK_RELEASE, ap->a_vlock, ap->a_td));
281 struct vop_islocked_args /* {
288 if ((l = (struct lock *)ap->a_vp->v_data) == NULL)
291 return (lockstatus(l, ap->a_td));
295 * Return true for select/poll.
299 struct vop_poll_args /* {
302 struct ucred *a_cred;
307 * Return true for read/write. If the user asked for something
308 * special, return POLLNVAL, so that clients have a way of
309 * determining reliably whether or not the extended
310 * functionality is present without hard-coding knowledge
311 * of specific filesystem implementations.
313 if (ap->a_events & ~POLLSTANDARD)
316 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
320 * Implement poll for local filesystems that support it.
324 struct vop_poll_args /* {
327 struct ucred *a_cred;
331 if (ap->a_events & ~POLLSTANDARD)
332 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
333 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
338 struct vop_bwrite_args *ap;
340 return (bwrite(ap->a_bp));
344 * Stubs to use when there is no locking to be done on the underlying object.
345 * A minimal shared lock is necessary to ensure that the underlying object
346 * is not revoked while an operation is in progress. So, an active shared
347 * count is maintained in an auxillary vnode lock structure.
351 struct vop_lock_args /* {
353 lwkt_tokref_t a_vlock;
359 * This code cannot be used until all the non-locking filesystems
360 * (notably NFS) are converted to properly lock and release nodes.
361 * Also, certain vnode operations change the locking state within
362 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
363 * and symlink). Ideally these operations should not change the
364 * lock state, but should be changed to let the caller of the
365 * function unlock them. Otherwise all intermediate vnode layers
366 * (such as union, umapfs, etc) must catch these functions to do
367 * the necessary locking at their layer. Note that the inactive
368 * and lookup operations also change their lock state, but this
369 * cannot be avoided, so these two operations will always need
370 * to be handled in intermediate layers.
372 struct vnode *vp = ap->a_vp;
373 struct lock *l = (struct lock *)vp->v_data;
374 int vnflags, flags = ap->a_flags;
377 if (ap->a_flags & LK_INTERLOCK)
378 lwkt_reltoken(ap->a_vlock);
381 switch (flags & LK_TYPE_MASK) {
386 #ifdef DEBUG_VFS_LOCKS
388 * Normally, we use shared locks here, but that confuses
389 * the locking assertions.
391 vnflags = LK_EXCLUSIVE;
403 panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK);
405 if (flags & LK_INTERLOCK)
406 vnflags |= LK_INTERLOCK;
408 return (lockmgr(l, vnflags, ap->a_vlock, ap->a_td));
410 return (debuglockmgr(l, vnflags, ap->a_vlock, ap->a_td,
411 "vop_sharedlock", vp->filename, vp->line));
416 * Stubs to use when there is no locking to be done on the underlying object.
417 * A minimal shared lock is necessary to ensure that the underlying object
418 * is not revoked while an operation is in progress. So, an active shared
419 * count is maintained in an auxillary vnode lock structure.
423 struct vop_lock_args /* {
425 lwkt_tokref_t a_vlock;
432 * This code cannot be used until all the non-locking filesystems
433 * (notably NFS) are converted to properly lock and release nodes.
434 * Also, certain vnode operations change the locking state within
435 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
436 * and symlink). Ideally these operations should not change the
437 * lock state, but should be changed to let the caller of the
438 * function unlock them. Otherwise all intermediate vnode layers
439 * (such as union, umapfs, etc) must catch these functions to do
440 * the necessary locking at their layer. Note that the inactive
441 * and lookup operations also change their lock state, but this
442 * cannot be avoided, so these two operations will always need
443 * to be handled in intermediate layers.
445 struct vnode *vp = ap->a_vp;
446 int vnflags, flags = ap->a_flags;
448 switch (flags & LK_TYPE_MASK) {
462 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK);
464 if (flags & LK_INTERLOCK)
465 vnflags |= LK_INTERLOCK;
466 return(lockmgr(vp->v_vnlock, vnflags, ap->a_vlock, ap->a_p));
469 * Since we are not using the lock manager, we must clear
470 * the interlock here.
472 if (ap->a_flags & LK_INTERLOCK)
473 lwkt_reltoken(ap->a_vlock);
479 * Do the inverse of vop_nolock, handling the interlock in a compatible way.
483 struct vop_unlock_args /* {
485 lwkt_tokref_t a_vlock;
490 if (ap->a_flags & LK_INTERLOCK)
491 lwkt_reltoken(ap->a_vlock);
496 * Return whether or not the node is in use.
500 struct vop_islocked_args /* {
509 vop_stdcreatevobject(ap)
510 struct vop_createvobject_args /* {
515 struct vnode *vp = ap->a_vp;
516 struct thread *td = ap->a_td;
521 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
525 if ((object = vp->v_object) == NULL) {
526 if (vp->v_type == VREG || vp->v_type == VDIR) {
527 if ((error = VOP_GETATTR(vp, &vat, td)) != 0)
529 object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
530 } else if (vp->v_rdev && dev_is_good(vp->v_rdev)) {
532 * XXX v_rdev uses NULL/non-NULL instead of NODEV
534 * This simply allocates the biggest object possible
535 * for a disk vnode. This should be fixed, but doesn't
536 * cause any problems (yet).
538 object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
543 * Dereference the reference we just created. This assumes
544 * that the object is associated with the vp.
549 if (object->flags & OBJ_DEAD) {
550 VOP_UNLOCK(vp, NULL, 0, td);
551 tsleep(object, 0, "vodead", 0);
552 vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
557 KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
558 vp->v_flag |= VOBJBUF;
565 vop_stddestroyvobject(ap)
566 struct vop_destroyvobject_args /* {
570 struct vnode *vp = ap->a_vp;
571 vm_object_t obj = vp->v_object;
573 if (vp->v_object == NULL)
576 if (obj->ref_count == 0) {
578 * vclean() may be called twice. The first time
579 * removes the primary reference to the object,
580 * the second time goes one further and is a
581 * special-case to terminate the object.
583 * don't double-terminate the object.
585 if ((obj->flags & OBJ_DEAD) == 0)
586 vm_object_terminate(obj);
589 * Woe to the process that tries to page now :-).
591 vm_pager_deallocate(obj);
597 * Return the underlying VM object. This routine may be called with or
598 * without the vnode interlock held. If called without, the returned
599 * object is not guarenteed to be valid. The syncer typically gets the
600 * object without holding the interlock in order to quickly test whether
601 * it might be dirty before going heavy-weight. vm_object's use zalloc
602 * and thus stable-storage, so this is safe.
605 vop_stdgetvobject(ap)
606 struct vop_getvobject_args /* {
608 struct vm_object **objpp;
611 struct vnode *vp = ap->a_vp;
612 struct vm_object **objpp = ap->a_objpp;
615 *objpp = vp->v_object;
616 return (vp->v_object ? 0 : EINVAL);
621 * used to fill the vfs fucntion table to get reasonable default return values.
624 vfs_stdmount(struct mount *mp, char *path, caddr_t data,
625 struct nameidata *ndp, struct thread *td)
631 vfs_stdunmount(struct mount *mp, int mntflags, struct thread *td)
637 vfs_stdroot(struct mount *mp, struct vnode **vpp)
643 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct thread *td)
649 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
655 vfs_stdstart(struct mount *mp, int flags, struct thread *td)
661 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
662 caddr_t arg, struct thread *td)
668 vfs_stdsync(struct mount *mp, int waitfor, struct thread *td)
674 vfs_stdvget(struct mount *mp, ino_t ino, struct vnode **vpp)
680 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
686 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
687 struct ucred **credanonp)
693 vfs_stdinit(struct vfsconf *vfsp)
699 vfs_stduninit(struct vfsconf *vfsp)
705 vfs_stdextattrctl(struct mount *mp, int cmd, const char *attrname,
706 caddr_t arg, struct thread *td)
711 /* end of vfs default ops */