vfs_subr.c (100207) | vfs_subr.c (100344) |
---|---|
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 * $FreeBSD: head/sys/kern/vfs_subr.c 100207 2002-07-17 02:03:19Z mckusick $ | 39 * $FreeBSD: head/sys/kern/vfs_subr.c 100344 2002-07-19 07:29:39Z mckusick $ |
40 */ 41 42/* 43 * External virtual filesystem routines 44 */ 45#include "opt_ddb.h" 46 47#include <sys/param.h> --- 23 unchanged lines hidden (view full) --- 71#include <vm/uma.h> 72 73static MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure"); 74 75static void addalias(struct vnode *vp, dev_t nvp_rdev); 76static void insmntque(struct vnode *vp, struct mount *mp); 77static void vclean(struct vnode *vp, int flags, struct thread *td); 78static void vlruvp(struct vnode *vp); | 40 */ 41 42/* 43 * External virtual filesystem routines 44 */ 45#include "opt_ddb.h" 46 47#include <sys/param.h> --- 23 unchanged lines hidden (view full) --- 71#include <vm/uma.h> 72 73static MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure"); 74 75static void addalias(struct vnode *vp, dev_t nvp_rdev); 76static void insmntque(struct vnode *vp, struct mount *mp); 77static void vclean(struct vnode *vp, int flags, struct thread *td); 78static void vlruvp(struct vnode *vp); |
79static int flushbuflist(struct buf *blist, int flags, struct vnode *vp, 80 int slpflag, int slptimeo, int *errorp); |
|
79 80/* 81 * Number of vnodes in existence. Increased whenever getnewvnode() 82 * allocates a new vnode, never decreased. 83 */ 84static unsigned long numvnodes; 85 86SYSCTL_LONG(_vfs, OID_AUTO, numvnodes, CTLFLAG_RD, &numvnodes, 0, ""); --- 806 unchanged lines hidden (view full) --- 893} 894 895/* 896 * Flush out and invalidate all buffers associated with a vnode. 897 * Called with the underlying object locked. 898 */ 899int 900vinvalbuf(vp, flags, cred, td, slpflag, slptimeo) | 81 82/* 83 * Number of vnodes in existence. Increased whenever getnewvnode() 84 * allocates a new vnode, never decreased. 85 */ 86static unsigned long numvnodes; 87 88SYSCTL_LONG(_vfs, OID_AUTO, numvnodes, CTLFLAG_RD, &numvnodes, 0, ""); --- 806 unchanged lines hidden (view full) --- 895} 896 897/* 898 * Flush out and invalidate all buffers associated with a vnode. 899 * Called with the underlying object locked. 900 */ 901int 902vinvalbuf(vp, flags, cred, td, slpflag, slptimeo) |
901 register struct vnode *vp; | 903 struct vnode *vp; |
902 int flags; 903 struct ucred *cred; 904 struct thread *td; 905 int slpflag, slptimeo; 906{ | 904 int flags; 905 struct ucred *cred; 906 struct thread *td; 907 int slpflag, slptimeo; 908{ |
907 register struct buf *bp; 908 struct buf *nbp, *blist; | 909 struct buf *blist; |
909 int s, error; 910 vm_object_t object; 911 912 GIANT_REQUIRED; 913 914 if (flags & V_SAVE) { 915 s = splbio(); 916 while (vp->v_numoutput) { --- 12 unchanged lines hidden (view full) --- 929 s = splbio(); 930 if (vp->v_numoutput > 0 || 931 !TAILQ_EMPTY(&vp->v_dirtyblkhd)) 932 panic("vinvalbuf: dirty bufs"); 933 } 934 splx(s); 935 } 936 s = splbio(); | 910 int s, error; 911 vm_object_t object; 912 913 GIANT_REQUIRED; 914 915 if (flags & V_SAVE) { 916 s = splbio(); 917 while (vp->v_numoutput) { --- 12 unchanged lines hidden (view full) --- 930 s = splbio(); 931 if (vp->v_numoutput > 0 || 932 !TAILQ_EMPTY(&vp->v_dirtyblkhd)) 933 panic("vinvalbuf: dirty bufs"); 934 } 935 splx(s); 936 } 937 s = splbio(); |
937 for (;;) { 938 blist = TAILQ_FIRST(&vp->v_cleanblkhd); 939 if (!blist) 940 blist = TAILQ_FIRST(&vp->v_dirtyblkhd); 941 if (!blist) 942 break; 943 944 for (bp = blist; bp; bp = nbp) { 945 nbp = TAILQ_NEXT(bp, b_vnbufs); 946 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) { 947 error = BUF_TIMELOCK(bp, 948 LK_EXCLUSIVE | LK_SLEEPFAIL, 949 "vinvalbuf", slpflag, slptimeo); 950 if (error == ENOLCK) 951 break; 952 splx(s); 953 return (error); 954 } 955 /* 956 * XXX Since there are no node locks for NFS, I 957 * believe there is a slight chance that a delayed 958 * write will occur while sleeping just above, so 959 * check for it. Note that vfs_bio_awrite expects 960 * buffers to reside on a queue, while BUF_WRITE and 961 * brelse do not. 962 */ 963 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) && 964 (flags & V_SAVE)) { 965 966 if (bp->b_vp == vp) { 967 if (bp->b_flags & B_CLUSTEROK) { 968 BUF_UNLOCK(bp); 969 vfs_bio_awrite(bp); 970 } else { 971 bremfree(bp); 972 bp->b_flags |= B_ASYNC; 973 BUF_WRITE(bp); 974 } 975 } else { 976 bremfree(bp); 977 (void) BUF_WRITE(bp); 978 } | 938 for (error = 0;;) { 939 if ((blist = TAILQ_FIRST(&vp->v_cleanblkhd)) != 0 && 940 flushbuflist(blist, flags, vp, slpflag, slptimeo, &error)) { 941 if (error) |
979 break; | 942 break; |
980 } 981 bremfree(bp); 982 bp->b_flags |= (B_INVAL | B_NOCACHE | B_RELBUF); 983 bp->b_flags &= ~B_ASYNC; 984 brelse(bp); | 943 continue; |
985 } | 944 } |
945 if ((blist = TAILQ_FIRST(&vp->v_dirtyblkhd)) != 0 && 946 flushbuflist(blist, flags, vp, slpflag, slptimeo, &error)) { 947 if (error) 948 break; 949 continue; 950 } 951 break; |
|
986 } | 952 } |
953 if (error) { 954 splx(s); 955 return (error); 956 } |
|
987 988 /* 989 * Wait for I/O to complete. XXX needs cleaning up. The vnode can 990 * have write I/O in-progress but if there is a VM object then the 991 * VM object can also have read-I/O in-progress. 992 */ 993 do { 994 while (vp->v_numoutput > 0) { --- 13 unchanged lines hidden (view full) --- 1008 */ 1009 mtx_lock(&vp->v_interlock); 1010 if (VOP_GETVOBJECT(vp, &object) == 0) { 1011 vm_object_page_remove(object, 0, 0, 1012 (flags & V_SAVE) ? TRUE : FALSE); 1013 } 1014 mtx_unlock(&vp->v_interlock); 1015 | 957 958 /* 959 * Wait for I/O to complete. XXX needs cleaning up. The vnode can 960 * have write I/O in-progress but if there is a VM object then the 961 * VM object can also have read-I/O in-progress. 962 */ 963 do { 964 while (vp->v_numoutput > 0) { --- 13 unchanged lines hidden (view full) --- 978 */ 979 mtx_lock(&vp->v_interlock); 980 if (VOP_GETVOBJECT(vp, &object) == 0) { 981 vm_object_page_remove(object, 0, 0, 982 (flags & V_SAVE) ? TRUE : FALSE); 983 } 984 mtx_unlock(&vp->v_interlock); 985 |
1016 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd) || !TAILQ_EMPTY(&vp->v_cleanblkhd)) | 986 if ((flags & (V_ALT | V_NORMAL)) == 0 && 987 (!TAILQ_EMPTY(&vp->v_dirtyblkhd) || 988 !TAILQ_EMPTY(&vp->v_cleanblkhd))) |
1017 panic("vinvalbuf: flush failed"); 1018 return (0); 1019} 1020 1021/* | 989 panic("vinvalbuf: flush failed"); 990 return (0); 991} 992 993/* |
994 * Flush out buffers on the specified list. 995 */ 996static int 997flushbuflist(blist, flags, vp, slpflag, slptimeo, errorp) 998 struct buf *blist; 999 int flags; 1000 struct vnode *vp; 1001 int slpflag, slptimeo; 1002 int *errorp; 1003{ 1004 struct buf *bp, *nbp; 1005 int found, error; 1006 1007 for (found = 0, bp = blist; bp; bp = nbp) { 1008 nbp = TAILQ_NEXT(bp, b_vnbufs); 1009 if (((flags & V_NORMAL) && (bp->b_xflags & BX_ALTDATA)) || 1010 ((flags & V_ALT) && (bp->b_xflags & BX_ALTDATA) == 0)) 1011 continue; 1012 found += 1; 1013 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) { 1014 error = BUF_TIMELOCK(bp, 1015 LK_EXCLUSIVE | LK_SLEEPFAIL, 1016 "flushbuf", slpflag, slptimeo); 1017 if (error != ENOLCK) 1018 *errorp = error; 1019 return (found); 1020 } 1021 /* 1022 * XXX Since there are no node locks for NFS, I 1023 * believe there is a slight chance that a delayed 1024 * write will occur while sleeping just above, so 1025 * check for it. Note that vfs_bio_awrite expects 1026 * buffers to reside on a queue, while BUF_WRITE and 1027 * brelse do not. 1028 */ 1029 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) && 1030 (flags & V_SAVE)) { 1031 1032 if (bp->b_vp == vp) { 1033 if (bp->b_flags & B_CLUSTEROK) { 1034 BUF_UNLOCK(bp); 1035 vfs_bio_awrite(bp); 1036 } else { 1037 bremfree(bp); 1038 bp->b_flags |= B_ASYNC; 1039 BUF_WRITE(bp); 1040 } 1041 } else { 1042 bremfree(bp); 1043 (void) BUF_WRITE(bp); 1044 } 1045 return (found); 1046 } 1047 bremfree(bp); 1048 bp->b_flags |= (B_INVAL | B_NOCACHE | B_RELBUF); 1049 bp->b_flags &= ~B_ASYNC; 1050 brelse(bp); 1051 } 1052 return (found); 1053} 1054 1055/* |
|
1022 * Truncate a file's buffer and pages to a specified length. This 1023 * is in lieu of the old vinvalbuf mechanism, which performed unneeded 1024 * sync activity. 1025 */ 1026int 1027vtruncbuf(vp, cred, td, length, blksize) 1028 register struct vnode *vp; 1029 struct ucred *cred; --- 2277 unchanged lines hidden --- | 1056 * Truncate a file's buffer and pages to a specified length. This 1057 * is in lieu of the old vinvalbuf mechanism, which performed unneeded 1058 * sync activity. 1059 */ 1060int 1061vtruncbuf(vp, cred, td, length, blksize) 1062 register struct vnode *vp; 1063 struct ucred *cred; --- 2277 unchanged lines hidden --- |