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.9 2004/03/01 06:33:17 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 vop_t **default_vnodeop_p;
75 static struct vnodeopv_entry_desc default_vnodeop_entries[] = {
76 { &vop_default_desc, (vop_t *) vop_eopnotsupp },
77 { &vop_advlock_desc, (vop_t *) vop_einval },
78 { &vop_bwrite_desc, (vop_t *) vop_stdbwrite },
79 { &vop_close_desc, (vop_t *) vop_null },
80 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
81 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
82 { &vop_fsync_desc, (vop_t *) vop_null },
83 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
84 { &vop_ioctl_desc, (vop_t *) vop_enotty },
85 { &vop_islocked_desc, (vop_t *) vop_noislocked },
86 { &vop_lease_desc, (vop_t *) vop_null },
87 { &vop_lock_desc, (vop_t *) vop_nolock },
88 { &vop_mmap_desc, (vop_t *) vop_einval },
89 { &vop_lookup_desc, (vop_t *) vop_nolookup },
90 { &vop_open_desc, (vop_t *) vop_null },
91 { &vop_pathconf_desc, (vop_t *) vop_einval },
92 { &vop_poll_desc, (vop_t *) vop_nopoll },
93 { &vop_readlink_desc, (vop_t *) vop_einval },
94 { &vop_reallocblks_desc, (vop_t *) vop_eopnotsupp },
95 { &vop_revoke_desc, (vop_t *) vop_revoke },
96 { &vop_strategy_desc, (vop_t *) vop_nostrategy },
97 { &vop_unlock_desc, (vop_t *) vop_nounlock },
98 { &vop_getacl_desc, (vop_t *) vop_eopnotsupp },
99 { &vop_setacl_desc, (vop_t *) vop_eopnotsupp },
100 { &vop_aclcheck_desc, (vop_t *) vop_eopnotsupp },
101 { &vop_getextattr_desc, (vop_t *) vop_eopnotsupp },
102 { &vop_setextattr_desc, (vop_t *) vop_eopnotsupp },
106 static struct vnodeopv_desc default_vnodeop_opv_desc =
107 { &default_vnodeop_p, 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);
122 vop_ebadf(struct vop_generic_args *ap)
129 vop_enotty(struct vop_generic_args *ap)
136 vop_einval(struct vop_generic_args *ap)
143 vop_null(struct vop_generic_args *ap)
150 vop_defaultop(struct vop_generic_args *ap)
153 return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap));
157 vop_panic(struct vop_generic_args *ap)
160 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
165 struct vop_lookup_args /* {
167 struct vnode **a_vpp;
168 struct componentname *a_cnp;
179 * Strategy routine for VFS devices that have none.
181 * B_ERROR and B_INVAL must be cleared prior to calling any strategy
182 * routine. Typically this is done for a B_READ strategy call. Typically
183 * B_INVAL is assumed to already be clear prior to a write and should not
184 * be cleared manually unless you just made the buffer invalid. B_ERROR
185 * should be cleared either way.
189 vop_nostrategy (struct vop_strategy_args *ap)
191 printf("No strategy for buffer at %p\n", ap->a_bp);
192 vprint("", ap->a_vp);
193 vprint("", ap->a_bp->b_vp);
194 ap->a_bp->b_flags |= B_ERROR;
195 ap->a_bp->b_error = EOPNOTSUPP;
202 struct vop_pathconf_args /* {
209 switch (ap->a_name) {
211 *ap->a_retval = LINK_MAX;
214 *ap->a_retval = MAX_CANON;
217 *ap->a_retval = MAX_INPUT;
220 *ap->a_retval = PIPE_BUF;
222 case _PC_CHOWN_RESTRICTED:
226 *ap->a_retval = _POSIX_VDISABLE;
235 * Standard lock, unlock and islocked functions.
237 * These depend on the lock structure being the first element in the
238 * inode, ie: vp->v_data points to the the lock!
242 struct vop_lock_args /* {
244 lwkt_tokref_t a_vlock;
251 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
252 if (ap->a_flags & LK_INTERLOCK)
253 lwkt_reltoken(ap->a_vlock);
258 return (lockmgr(l, ap->a_flags, ap->a_vlock, ap->a_td));
260 return (debuglockmgr(l, ap->a_flags, ap->a_vlock, ap->a_td,
261 "vop_stdlock", ap->a_vp->filename, ap->a_vp->line));
267 struct vop_unlock_args /* {
269 lwkt_tokref_t a_vlock;
276 if ((l = (struct lock *)ap->a_vp->v_data) == NULL) {
277 if (ap->a_flags & LK_INTERLOCK)
278 lwkt_reltoken(ap->a_vlock);
282 return (lockmgr(l, ap->a_flags | LK_RELEASE, ap->a_vlock, ap->a_td));
287 struct vop_islocked_args /* {
294 if ((l = (struct lock *)ap->a_vp->v_data) == NULL)
297 return (lockstatus(l, ap->a_td));
301 * Return true for select/poll.
305 struct vop_poll_args /* {
308 struct ucred *a_cred;
313 * Return true for read/write. If the user asked for something
314 * special, return POLLNVAL, so that clients have a way of
315 * determining reliably whether or not the extended
316 * functionality is present without hard-coding knowledge
317 * of specific filesystem implementations.
319 if (ap->a_events & ~POLLSTANDARD)
322 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
326 * Implement poll for local filesystems that support it.
330 struct vop_poll_args /* {
333 struct ucred *a_cred;
337 if (ap->a_events & ~POLLSTANDARD)
338 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
339 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
344 struct vop_bwrite_args *ap;
346 return (bwrite(ap->a_bp));
350 * Stubs to use when there is no locking to be done on the underlying object.
351 * A minimal shared lock is necessary to ensure that the underlying object
352 * is not revoked while an operation is in progress. So, an active shared
353 * count is maintained in an auxillary vnode lock structure.
357 struct vop_lock_args /* {
359 lwkt_tokref_t a_vlock;
365 * This code cannot be used until all the non-locking filesystems
366 * (notably NFS) are converted to properly lock and release nodes.
367 * Also, certain vnode operations change the locking state within
368 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
369 * and symlink). Ideally these operations should not change the
370 * lock state, but should be changed to let the caller of the
371 * function unlock them. Otherwise all intermediate vnode layers
372 * (such as union, umapfs, etc) must catch these functions to do
373 * the necessary locking at their layer. Note that the inactive
374 * and lookup operations also change their lock state, but this
375 * cannot be avoided, so these two operations will always need
376 * to be handled in intermediate layers.
378 struct vnode *vp = ap->a_vp;
379 struct lock *l = (struct lock *)vp->v_data;
380 int vnflags, flags = ap->a_flags;
383 if (ap->a_flags & LK_INTERLOCK)
384 lwkt_reltoken(ap->a_vlock);
387 switch (flags & LK_TYPE_MASK) {
392 #ifdef DEBUG_VFS_LOCKS
394 * Normally, we use shared locks here, but that confuses
395 * the locking assertions.
397 vnflags = LK_EXCLUSIVE;
409 panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK);
411 if (flags & LK_INTERLOCK)
412 vnflags |= LK_INTERLOCK;
414 return (lockmgr(l, vnflags, ap->a_vlock, ap->a_td));
416 return (debuglockmgr(l, vnflags, ap->a_vlock, ap->a_td,
417 "vop_sharedlock", vp->filename, vp->line));
422 * Stubs to use when there is no locking to be done on the underlying object.
423 * A minimal shared lock is necessary to ensure that the underlying object
424 * is not revoked while an operation is in progress. So, an active shared
425 * count is maintained in an auxillary vnode lock structure.
429 struct vop_lock_args /* {
431 lwkt_tokref_t a_vlock;
438 * This code cannot be used until all the non-locking filesystems
439 * (notably NFS) are converted to properly lock and release nodes.
440 * Also, certain vnode operations change the locking state within
441 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
442 * and symlink). Ideally these operations should not change the
443 * lock state, but should be changed to let the caller of the
444 * function unlock them. Otherwise all intermediate vnode layers
445 * (such as union, umapfs, etc) must catch these functions to do
446 * the necessary locking at their layer. Note that the inactive
447 * and lookup operations also change their lock state, but this
448 * cannot be avoided, so these two operations will always need
449 * to be handled in intermediate layers.
451 struct vnode *vp = ap->a_vp;
452 int vnflags, flags = ap->a_flags;
454 switch (flags & LK_TYPE_MASK) {
468 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK);
470 if (flags & LK_INTERLOCK)
471 vnflags |= LK_INTERLOCK;
472 return(lockmgr(vp->v_vnlock, vnflags, ap->a_vlock, ap->a_p));
475 * Since we are not using the lock manager, we must clear
476 * the interlock here.
478 if (ap->a_flags & LK_INTERLOCK)
479 lwkt_reltoken(ap->a_vlock);
485 * Do the inverse of vop_nolock, handling the interlock in a compatible way.
489 struct vop_unlock_args /* {
491 lwkt_tokref_t a_vlock;
496 if (ap->a_flags & LK_INTERLOCK)
497 lwkt_reltoken(ap->a_vlock);
502 * Return whether or not the node is in use.
506 struct vop_islocked_args /* {
515 vop_stdcreatevobject(ap)
516 struct vop_createvobject_args /* {
521 struct vnode *vp = ap->a_vp;
522 struct thread *td = ap->a_td;
527 if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE)
531 if ((object = vp->v_object) == NULL) {
532 if (vp->v_type == VREG || vp->v_type == VDIR) {
533 if ((error = VOP_GETATTR(vp, &vat, td)) != 0)
535 object = vnode_pager_alloc(vp, vat.va_size, 0, 0);
536 } else if (dev_dport(vp->v_rdev) != NULL) {
538 * This simply allocates the biggest object possible
539 * for a disk vnode. This should be fixed, but doesn't
540 * cause any problems (yet).
542 object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0);
547 * Dereference the reference we just created. This assumes
548 * that the object is associated with the vp.
553 if (object->flags & OBJ_DEAD) {
554 VOP_UNLOCK(vp, NULL, 0, td);
555 tsleep(object, 0, "vodead", 0);
556 vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
561 KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object"));
562 vp->v_flag |= VOBJBUF;
569 vop_stddestroyvobject(ap)
570 struct vop_destroyvobject_args /* {
574 struct vnode *vp = ap->a_vp;
575 vm_object_t obj = vp->v_object;
577 if (vp->v_object == NULL)
580 if (obj->ref_count == 0) {
582 * vclean() may be called twice. The first time
583 * removes the primary reference to the object,
584 * the second time goes one further and is a
585 * special-case to terminate the object.
587 * don't double-terminate the object.
589 if ((obj->flags & OBJ_DEAD) == 0)
590 vm_object_terminate(obj);
593 * Woe to the process that tries to page now :-).
595 vm_pager_deallocate(obj);
601 * Return the underlying VM object. This routine may be called with or
602 * without the vnode interlock held. If called without, the returned
603 * object is not guarenteed to be valid. The syncer typically gets the
604 * object without holding the interlock in order to quickly test whether
605 * it might be dirty before going heavy-weight. vm_object's use zalloc
606 * and thus stable-storage, so this is safe.
609 vop_stdgetvobject(ap)
610 struct vop_getvobject_args /* {
612 struct vm_object **objpp;
615 struct vnode *vp = ap->a_vp;
616 struct vm_object **objpp = ap->a_objpp;
619 *objpp = vp->v_object;
620 return (vp->v_object ? 0 : EINVAL);
625 * used to fill the vfs fucntion table to get reasonable default return values.
628 vfs_stdmount(struct mount *mp, char *path, caddr_t data,
629 struct nameidata *ndp, struct thread *td)
635 vfs_stdunmount(struct mount *mp, int mntflags, struct thread *td)
641 vfs_stdroot(struct mount *mp, struct vnode **vpp)
647 vfs_stdstatfs(struct mount *mp, struct statfs *sbp, struct thread *td)
653 vfs_stdvptofh(struct vnode *vp, struct fid *fhp)
659 vfs_stdstart(struct mount *mp, int flags, struct thread *td)
665 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid,
666 caddr_t arg, struct thread *td)
672 vfs_stdsync(struct mount *mp, int waitfor, struct thread *td)
678 vfs_stdvget(struct mount *mp, ino_t ino, struct vnode **vpp)
684 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
690 vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
691 struct ucred **credanonp)
697 vfs_stdinit(struct vfsconf *vfsp)
703 vfs_stduninit(struct vfsconf *vfsp)
709 vfs_stdextattrctl(struct mount *mp, int cmd, const char *attrname,
710 caddr_t arg, struct thread *td)
715 /* end of vfs default ops */