Deleted Added
full compact
nfs_vnops.c (44679) nfs_vnops.c (46349)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs_vnops.c 8.16 (Berkeley) 5/27/95
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs_vnops.c 8.16 (Berkeley) 5/27/95
37 * $Id: nfs_vnops.c,v 1.123 1999/02/16 10:49:54 dfr Exp $
37 * $Id: nfs_vnops.c,v 1.124 1999/03/12 02:24:58 julian Exp $
38 */
39
40
41/*
42 * vnode op calls for Sun NFS version 2 and 3
43 */
44
45#include "opt_inet.h"

--- 357 unchanged lines hidden (view full) ---

403 auio.uio_segflg = UIO_SYSSPACE;
404 auio.uio_rw = UIO_READ;
405 auio.uio_procp = ap->a_p;
406
407 if (vp->v_type == VREG)
408 error = nfs_readrpc(vp, &auio, ap->a_cred);
409 else if (vp->v_type == VDIR) {
410 char* bp;
38 */
39
40
41/*
42 * vnode op calls for Sun NFS version 2 and 3
43 */
44
45#include "opt_inet.h"

--- 357 unchanged lines hidden (view full) ---

403 auio.uio_segflg = UIO_SYSSPACE;
404 auio.uio_rw = UIO_READ;
405 auio.uio_procp = ap->a_p;
406
407 if (vp->v_type == VREG)
408 error = nfs_readrpc(vp, &auio, ap->a_cred);
409 else if (vp->v_type == VDIR) {
410 char* bp;
411 bp = malloc(NFS_DIRBLKSIZ, M_TEMP, M_WAITOK);
411 bp = malloc(DIRBLKSIZ, M_TEMP, M_WAITOK);
412 aiov.iov_base = bp;
412 aiov.iov_base = bp;
413 aiov.iov_len = auio.uio_resid = NFS_DIRBLKSIZ;
413 aiov.iov_len = auio.uio_resid = DIRBLKSIZ;
414 error = nfs_readdirrpc(vp, &auio, ap->a_cred);
415 free(bp, M_TEMP);
416 } else if (vp->v_type == VLNK)
417 error = nfs_readlinkrpc(vp, &auio, ap->a_cred);
418 else
419 error = EACCES;
420 }
421 return (error);

--- 535 unchanged lines hidden (view full) ---

957 int a_ioflag;
958 struct ucred *a_cred;
959 } */ *ap;
960{
961 register struct vnode *vp = ap->a_vp;
962
963 if (vp->v_type != VREG)
964 return (EPERM);
414 error = nfs_readdirrpc(vp, &auio, ap->a_cred);
415 free(bp, M_TEMP);
416 } else if (vp->v_type == VLNK)
417 error = nfs_readlinkrpc(vp, &auio, ap->a_cred);
418 else
419 error = EACCES;
420 }
421 return (error);

--- 535 unchanged lines hidden (view full) ---

957 int a_ioflag;
958 struct ucred *a_cred;
959 } */ *ap;
960{
961 register struct vnode *vp = ap->a_vp;
962
963 if (vp->v_type != VREG)
964 return (EPERM);
965 return (nfs_bioread(vp, ap->a_uio, ap->a_ioflag, ap->a_cred, 0));
965 return (nfs_bioread(vp, ap->a_uio, ap->a_ioflag, ap->a_cred));
966}
967
968/*
969 * nfs readlink call
970 */
971static int
972nfs_readlink(ap)
973 struct vop_readlink_args /* {
974 struct vnode *a_vp;
975 struct uio *a_uio;
976 struct ucred *a_cred;
977 } */ *ap;
978{
979 register struct vnode *vp = ap->a_vp;
980
981 if (vp->v_type != VLNK)
982 return (EINVAL);
966}
967
968/*
969 * nfs readlink call
970 */
971static int
972nfs_readlink(ap)
973 struct vop_readlink_args /* {
974 struct vnode *a_vp;
975 struct uio *a_uio;
976 struct ucred *a_cred;
977 } */ *ap;
978{
979 register struct vnode *vp = ap->a_vp;
980
981 if (vp->v_type != VLNK)
982 return (EINVAL);
983 return (nfs_bioread(vp, ap->a_uio, 0, ap->a_cred, 0));
983 return (nfs_bioread(vp, ap->a_uio, 0, ap->a_cred));
984}
985
986/*
987 * Do a readlink rpc.
988 * Called by nfs_doio() from below the buffer cache.
989 */
990int
991nfs_readlinkrpc(vp, uiop, cred)

--- 988 unchanged lines hidden (view full) ---

1980 return (0);
1981 }
1982 }
1983
1984 /*
1985 * Call nfs_bioread() to do the real work.
1986 */
1987 tresid = uio->uio_resid;
984}
985
986/*
987 * Do a readlink rpc.
988 * Called by nfs_doio() from below the buffer cache.
989 */
990int
991nfs_readlinkrpc(vp, uiop, cred)

--- 988 unchanged lines hidden (view full) ---

1980 return (0);
1981 }
1982 }
1983
1984 /*
1985 * Call nfs_bioread() to do the real work.
1986 */
1987 tresid = uio->uio_resid;
1988 error = nfs_bioread(vp, uio, 0, ap->a_cred, 0);
1988 error = nfs_bioread(vp, uio, 0, ap->a_cred);
1989
1990 if (!error && uio->uio_resid == tresid)
1991 nfsstats.direofcache_misses++;
1992 return (error);
1993}
1994
1995/*
1996 * Readdir rpc call.
1997 * Called from below the buffer cache by nfs_doio().
1998 */
1999int
2000nfs_readdirrpc(vp, uiop, cred)
2001 struct vnode *vp;
2002 register struct uio *uiop;
2003 struct ucred *cred;
2004
2005{
2006 register int len, left;
1989
1990 if (!error && uio->uio_resid == tresid)
1991 nfsstats.direofcache_misses++;
1992 return (error);
1993}
1994
1995/*
1996 * Readdir rpc call.
1997 * Called from below the buffer cache by nfs_doio().
1998 */
1999int
2000nfs_readdirrpc(vp, uiop, cred)
2001 struct vnode *vp;
2002 register struct uio *uiop;
2003 struct ucred *cred;
2004
2005{
2006 register int len, left;
2007 register struct dirent *dp;
2007 register struct dirent *dp = NULL;
2008 register u_int32_t *tl;
2009 register caddr_t cp;
2010 register int32_t t1, t2;
2011 register nfsuint64 *cookiep;
2012 caddr_t bpos, dpos, cp2;
2013 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
2014 nfsuint64 cookie;
2015 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2016 struct nfsnode *dnp = VTONFS(vp);
2017 u_quad_t fileno;
2018 int error = 0, tlen, more_dirs = 1, blksiz = 0, bigenough = 1;
2019 int attrflag;
2020 int v3 = NFS_ISV3(vp);
2021
2008 register u_int32_t *tl;
2009 register caddr_t cp;
2010 register int32_t t1, t2;
2011 register nfsuint64 *cookiep;
2012 caddr_t bpos, dpos, cp2;
2013 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
2014 nfsuint64 cookie;
2015 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2016 struct nfsnode *dnp = VTONFS(vp);
2017 u_quad_t fileno;
2018 int error = 0, tlen, more_dirs = 1, blksiz = 0, bigenough = 1;
2019 int attrflag;
2020 int v3 = NFS_ISV3(vp);
2021
2022#ifndef nolint
2023 dp = (struct dirent *)0;
2024#endif
2025#ifndef DIAGNOSTIC
2022#ifndef DIAGNOSTIC
2026 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (NFS_DIRBLKSIZ - 1)) ||
2027 (uiop->uio_resid & (NFS_DIRBLKSIZ - 1)))
2023 if (uiop->uio_iovcnt != 1 || (uiop->uio_offset & (DIRBLKSIZ - 1)) ||
2024 (uiop->uio_resid & (DIRBLKSIZ - 1)))
2028 panic("nfs readdirrpc bad uio");
2029#endif
2030
2031 /*
2032 * If there is no cookie, assume directory was stale.
2033 */
2034 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
2035 if (cookiep)

--- 340 unchanged lines hidden (view full) ---

2376 */
2377 if (!more_dirs) {
2378 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2379 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2380 }
2381 m_freem(mrep);
2382 }
2383 /*
2025 panic("nfs readdirrpc bad uio");
2026#endif
2027
2028 /*
2029 * If there is no cookie, assume directory was stale.
2030 */
2031 cookiep = nfs_getcookie(dnp, uiop->uio_offset, 0);
2032 if (cookiep)

--- 340 unchanged lines hidden (view full) ---

2373 */
2374 if (!more_dirs) {
2375 nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
2376 more_dirs = (fxdr_unsigned(int, *tl) == 0);
2377 }
2378 m_freem(mrep);
2379 }
2380 /*
2384 * Fill last record, iff any, out to a multiple of NFS_DIRBLKSIZ
2381 * Fill last record, iff any, out to a multiple of DIRBLKSIZ
2385 * by increasing d_reclen for the last record.
2386 */
2387 if (blksiz > 0) {
2388 left = DIRBLKSIZ - blksiz;
2389 dp->d_reclen += left;
2390 uiop->uio_iov->iov_base += left;
2391 uiop->uio_iov->iov_len -= left;
2392 uiop->uio_offset += left;

--- 630 unchanged lines hidden (view full) ---

3023 * NOTE: B_DONE may or may not be set in a_bp on call.
3024 */
3025static int
3026nfs_bwrite(ap)
3027 struct vop_bwrite_args /* {
3028 struct vnode *a_bp;
3029 } */ *ap;
3030{
2382 * by increasing d_reclen for the last record.
2383 */
2384 if (blksiz > 0) {
2385 left = DIRBLKSIZ - blksiz;
2386 dp->d_reclen += left;
2387 uiop->uio_iov->iov_base += left;
2388 uiop->uio_iov->iov_len -= left;
2389 uiop->uio_offset += left;

--- 630 unchanged lines hidden (view full) ---

3020 * NOTE: B_DONE may or may not be set in a_bp on call.
3021 */
3022static int
3023nfs_bwrite(ap)
3024 struct vop_bwrite_args /* {
3025 struct vnode *a_bp;
3026 } */ *ap;
3027{
3031
3032 return (nfs_writebp(ap->a_bp, 1));
3033}
3034
3035/*
3036 * This is a clone of vn_bwrite(), except that B_WRITEINPROG isn't set unless
3028 return (nfs_writebp(ap->a_bp, 1));
3029}
3030
3031/*
3032 * This is a clone of vn_bwrite(), except that B_WRITEINPROG isn't set unless
3037 * the force flag is one and it also handles the B_NEEDCOMMIT flag.
3033 * the force flag is one and it also handles the B_NEEDCOMMIT flag. We set
3034 * B_CACHE if this is a VMIO buffer.
3038 */
3039int
3040nfs_writebp(bp, force)
3041 register struct buf *bp;
3042 int force;
3043{
3044 int s;
3045 int oldflags = bp->b_flags;
3046 int retv = 1;
3047 off_t off;
3048
3049 if(!(bp->b_flags & B_BUSY))
3050 panic("bwrite: buffer is not busy???");
3051
3035 */
3036int
3037nfs_writebp(bp, force)
3038 register struct buf *bp;
3039 int force;
3040{
3041 int s;
3042 int oldflags = bp->b_flags;
3043 int retv = 1;
3044 off_t off;
3045
3046 if(!(bp->b_flags & B_BUSY))
3047 panic("bwrite: buffer is not busy???");
3048
3052 if (bp->b_flags & B_INVAL)
3053 bp->b_flags |= B_NOCACHE;
3049 if (bp->b_flags & B_INVAL) {
3050 brelse(bp);
3051 return(0);
3052 }
3054
3053
3054 bp->b_flags |= B_CACHE;
3055
3055 /*
3056 /*
3056 * XXX we bundirty() the bp here. Shouldn't we do it later after
3057 * the I/O has completed??
3057 * Undirty the bp. We will redirty it later if the I/O fails.
3058 */
3059
3060 s = splbio();
3061 bundirty(bp);
3062 bp->b_flags &= ~(B_READ|B_DONE|B_ERROR);
3063
3064 bp->b_vp->v_numoutput++;
3065 curproc->p_stats->p_ru.ru_oublock++;

--- 270 unchanged lines hidden ---
3058 */
3059
3060 s = splbio();
3061 bundirty(bp);
3062 bp->b_flags &= ~(B_READ|B_DONE|B_ERROR);
3063
3064 bp->b_vp->v_numoutput++;
3065 curproc->p_stats->p_ru.ru_oublock++;

--- 270 unchanged lines hidden ---