vfs_subr.c (30354) | vfs_subr.c (30743) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 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 36 * SUCH DAMAGE. 37 * 38 * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 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 36 * SUCH DAMAGE. 37 * 38 * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 |
39 * $Id: vfs_subr.c,v 1.109 1997/10/11 18:31:26 phk Exp $ | 39 * $Id: vfs_subr.c,v 1.110 1997/10/12 20:24:26 phk Exp $ |
40 */ 41 42/* 43 * External virtual filesystem routines 44 */ 45#include "opt_ddb.h" 46#include "opt_devfs.h" 47 --- 814 unchanged lines hidden (view full) --- 862 if (flags & LK_TYPE_MASK) { 863 if (error = vn_lock(vp, flags | LK_INTERLOCK, p)) 864 vrele(vp); 865 return (error); 866 } 867 simple_unlock(&vp->v_interlock); 868 return (0); 869} | 40 */ 41 42/* 43 * External virtual filesystem routines 44 */ 45#include "opt_ddb.h" 46#include "opt_devfs.h" 47 --- 814 unchanged lines hidden (view full) --- 862 if (flags & LK_TYPE_MASK) { 863 if (error = vn_lock(vp, flags | LK_INTERLOCK, p)) 864 vrele(vp); 865 return (error); 866 } 867 simple_unlock(&vp->v_interlock); 868 return (0); 869} |
870 871/* 872 * Stubs to use when there is no locking to be done on the underlying object. 873 * A minimal shared lock is necessary to ensure that the underlying object 874 * is not revoked while an operation is in progress. So, an active shared 875 * count is maintained in an auxillary vnode lock structure. 876 */ 877int 878vop_sharedlock(ap) 879 struct vop_lock_args /* { 880 struct vnode *a_vp; 881 int a_flags; 882 struct proc *a_p; 883 } */ *ap; 884{ 885 /* 886 * This code cannot be used until all the non-locking filesystems 887 * (notably NFS) are converted to properly lock and release nodes. 888 * Also, certain vnode operations change the locking state within 889 * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 890 * and symlink). Ideally these operations should not change the 891 * lock state, but should be changed to let the caller of the 892 * function unlock them. Otherwise all intermediate vnode layers 893 * (such as union, umapfs, etc) must catch these functions to do 894 * the necessary locking at their layer. Note that the inactive 895 * and lookup operations also change their lock state, but this 896 * cannot be avoided, so these two operations will always need 897 * to be handled in intermediate layers. 898 */ 899 struct vnode *vp = ap->a_vp; 900 int vnflags, flags = ap->a_flags; 901 902 if (vp->v_vnlock == NULL) { 903 if ((flags & LK_TYPE_MASK) == LK_DRAIN) 904 return (0); 905 MALLOC(vp->v_vnlock, struct lock *, sizeof(struct lock), 906 M_VNODE, M_WAITOK); 907 lockinit(vp->v_vnlock, PVFS, "vnlock", 0, 0); 908 } 909 switch (flags & LK_TYPE_MASK) { 910 case LK_DRAIN: 911 vnflags = LK_DRAIN; 912 break; 913 case LK_EXCLUSIVE: 914#ifdef DEBUG_VFS_LOCKS 915 /* 916 * Normally, we use shared locks here, but that confuses 917 * the locking assertions. 918 */ 919 vnflags = LK_EXCLUSIVE; 920 break; 921#endif 922 case LK_SHARED: 923 vnflags = LK_SHARED; 924 break; 925 case LK_UPGRADE: 926 case LK_EXCLUPGRADE: 927 case LK_DOWNGRADE: 928 return (0); 929 case LK_RELEASE: 930 default: 931 panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 932 } 933 if (flags & LK_INTERLOCK) 934 vnflags |= LK_INTERLOCK; 935 return(lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p)); 936} 937 938/* 939 * Stubs to use when there is no locking to be done on the underlying object. 940 * A minimal shared lock is necessary to ensure that the underlying object 941 * is not revoked while an operation is in progress. So, an active shared 942 * count is maintained in an auxillary vnode lock structure. 943 */ 944int 945vop_nolock(ap) 946 struct vop_lock_args /* { 947 struct vnode *a_vp; 948 int a_flags; 949 struct proc *a_p; 950 } */ *ap; 951{ 952#ifdef notyet 953 /* 954 * This code cannot be used until all the non-locking filesystems 955 * (notably NFS) are converted to properly lock and release nodes. 956 * Also, certain vnode operations change the locking state within 957 * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 958 * and symlink). Ideally these operations should not change the 959 * lock state, but should be changed to let the caller of the 960 * function unlock them. Otherwise all intermediate vnode layers 961 * (such as union, umapfs, etc) must catch these functions to do 962 * the necessary locking at their layer. Note that the inactive 963 * and lookup operations also change their lock state, but this 964 * cannot be avoided, so these two operations will always need 965 * to be handled in intermediate layers. 966 */ 967 struct vnode *vp = ap->a_vp; 968 int vnflags, flags = ap->a_flags; 969 970 if (vp->v_vnlock == NULL) { 971 if ((flags & LK_TYPE_MASK) == LK_DRAIN) 972 return (0); 973 MALLOC(vp->v_vnlock, struct lock *, sizeof(struct lock), 974 M_VNODE, M_WAITOK); 975 lockinit(vp->v_vnlock, PVFS, "vnlock", 0, 0); 976 } 977 switch (flags & LK_TYPE_MASK) { 978 case LK_DRAIN: 979 vnflags = LK_DRAIN; 980 break; 981 case LK_EXCLUSIVE: 982 case LK_SHARED: 983 vnflags = LK_SHARED; 984 break; 985 case LK_UPGRADE: 986 case LK_EXCLUPGRADE: 987 case LK_DOWNGRADE: 988 return (0); 989 case LK_RELEASE: 990 default: 991 panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 992 } 993 if (flags & LK_INTERLOCK) 994 vnflags |= LK_INTERLOCK; 995 return(lockmgr(vp->v_vnlock, vnflags, &vp->v_interlock, ap->a_p)); 996#else /* for now */ 997 /* 998 * Since we are not using the lock manager, we must clear 999 * the interlock here. 1000 */ 1001 if (ap->a_flags & LK_INTERLOCK) { 1002 simple_unlock(&ap->a_vp->v_interlock); 1003 } 1004 return (0); 1005#endif 1006} 1007 1008/* 1009 * Do the inverse of vop_nolock, handling the interlock in a compatible way. 1010 */ 1011int 1012vop_nounlock(ap) 1013 struct vop_unlock_args /* { 1014 struct vnode *a_vp; 1015 int a_flags; 1016 struct proc *a_p; 1017 } */ *ap; 1018{ 1019 struct vnode *vp = ap->a_vp; 1020 1021 if (vp->v_vnlock == NULL) { 1022 if (ap->a_flags & LK_INTERLOCK) 1023 simple_unlock(&ap->a_vp->v_interlock); 1024 return (0); 1025 } 1026 return (lockmgr(vp->v_vnlock, LK_RELEASE | ap->a_flags, 1027 &ap->a_vp->v_interlock, ap->a_p)); 1028} 1029 1030/* 1031 * Return whether or not the node is in use. 1032 */ 1033int 1034vop_noislocked(ap) 1035 struct vop_islocked_args /* { 1036 struct vnode *a_vp; 1037 } */ *ap; 1038{ 1039 struct vnode *vp = ap->a_vp; 1040 1041 if (vp->v_vnlock == NULL) 1042 return (0); 1043 return (lockstatus(vp->v_vnlock)); 1044} 1045 | |
1046/* #ifdef DIAGNOSTIC */ 1047/* 1048 * Vnode reference, just increment the count 1049 */ 1050void 1051vref(vp) 1052 struct vnode *vp; 1053{ --- 581 unchanged lines hidden (view full) --- 1635 vgone(vq); 1636 goto loop; 1637 } 1638 count += vq->v_usecount; 1639 } 1640 simple_unlock(&spechash_slock); 1641 return (count); 1642} | 870/* #ifdef DIAGNOSTIC */ 871/* 872 * Vnode reference, just increment the count 873 */ 874void 875vref(vp) 876 struct vnode *vp; 877{ --- 581 unchanged lines hidden (view full) --- 1459 vgone(vq); 1460 goto loop; 1461 } 1462 count += vq->v_usecount; 1463 } 1464 simple_unlock(&spechash_slock); 1465 return (count); 1466} |
1643 | |
1644/* | 1467/* |
1645 * Return true for select/poll. 1646 */ 1647int 1648vop_nopoll(ap) 1649 struct vop_poll_args /* { 1650 struct vnode *a_vp; 1651 int a_events; 1652 struct ucred *a_cred; 1653 struct proc *a_p; 1654 } */ *ap; 1655{ 1656 1657 /* 1658 * Just return what we were asked for. 1659 */ 1660 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 1661} 1662 1663/* | |
1664 * Print out a description of a vnode. 1665 */ 1666static char *typename[] = 1667{"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"}; 1668 1669void 1670vprint(label, vp) 1671 char *label; --- 635 unchanged lines hidden --- | 1468 * Print out a description of a vnode. 1469 */ 1470static char *typename[] = 1471{"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"}; 1472 1473void 1474vprint(label, vp) 1475 char *label; --- 635 unchanged lines hidden --- |