Deleted Added
full compact
nfs_clvnops.c (203303) nfs_clvnops.c (207082)
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

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

28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * from nfs_vnops.c 8.16 (Berkeley) 5/27/95
33 */
34
35#include <sys/cdefs.h>
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

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

28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * from nfs_vnops.c 8.16 (Berkeley) 5/27/95
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clvnops.c 203303 2010-01-31 19:12:24Z rmacklem $");
36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clvnops.c 207082 2010-04-22 23:51:01Z rmacklem $");
37
38/*
39 * vnode op calls for Sun NFS version 2, 3 and 4
40 */
41
42#include "opt_inet.h"
43
44#include <sys/param.h>

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

665 *
666 * We cannot clear the NMODIFIED bit in np->n_flag due to
667 * potential races with other processes, and certainly
668 * cannot clear it if we don't commit.
669 * These races occur when there is no longer the old
670 * traditional vnode locking implemented for Vnode Ops.
671 */
672 int cm = newnfs_commit_on_close ? 1 : 0;
37
38/*
39 * vnode op calls for Sun NFS version 2, 3 and 4
40 */
41
42#include "opt_inet.h"
43
44#include <sys/param.h>

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

665 *
666 * We cannot clear the NMODIFIED bit in np->n_flag due to
667 * potential races with other processes, and certainly
668 * cannot clear it if we don't commit.
669 * These races occur when there is no longer the old
670 * traditional vnode locking implemented for Vnode Ops.
671 */
672 int cm = newnfs_commit_on_close ? 1 : 0;
673 error = ncl_flush(vp, MNT_WAIT, cred, ap->a_td, cm);
673 error = ncl_flush(vp, MNT_WAIT, cred, ap->a_td, cm, 0);
674 /* np->n_flag &= ~NMODIFIED; */
675 } else if (NFS_ISV4(vp)) {
676 if (nfscl_mustflush(vp)) {
677 int cm = newnfs_commit_on_close ? 1 : 0;
678 error = ncl_flush(vp, MNT_WAIT, cred, ap->a_td,
674 /* np->n_flag &= ~NMODIFIED; */
675 } else if (NFS_ISV4(vp)) {
676 if (nfscl_mustflush(vp)) {
677 int cm = newnfs_commit_on_close ? 1 : 0;
678 error = ncl_flush(vp, MNT_WAIT, cred, ap->a_td,
679 cm);
679 cm, 0);
680 /*
681 * as above w.r.t races when clearing
682 * NMODIFIED.
683 * np->n_flag &= ~NMODIFIED;
684 */
685 }
686 } else
687 error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);

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

1301 return (error);
1302}
1303
1304/*
1305 * nfs write call
1306 */
1307int
1308ncl_writerpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
680 /*
681 * as above w.r.t races when clearing
682 * NMODIFIED.
683 * np->n_flag &= ~NMODIFIED;
684 */
685 }
686 } else
687 error = ncl_vinvalbuf(vp, V_SAVE, ap->a_td, 1);

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

1301 return (error);
1302}
1303
1304/*
1305 * nfs write call
1306 */
1307int
1308ncl_writerpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
1309 int *iomode, int *must_commit)
1309 int *iomode, int *must_commit, int called_from_strategy)
1310{
1311 struct nfsvattr nfsva;
1312 int error = 0, attrflag, ret;
1313 u_char verf[NFSX_VERF];
1314 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1315
1316 *must_commit = 0;
1317 error = nfsrpc_write(vp, uiop, iomode, verf, cred,
1310{
1311 struct nfsvattr nfsva;
1312 int error = 0, attrflag, ret;
1313 u_char verf[NFSX_VERF];
1314 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
1315
1316 *must_commit = 0;
1317 error = nfsrpc_write(vp, uiop, iomode, verf, cred,
1318 uiop->uio_td, &nfsva, &attrflag, NULL);
1318 uiop->uio_td, &nfsva, &attrflag, NULL, called_from_strategy);
1319 NFSLOCKMNT(nmp);
1320 if (!error && NFSHASWRITEVERF(nmp) &&
1321 NFSBCMP(verf, nmp->nm_verf, NFSX_VERF)) {
1322 *must_commit = 1;
1323 NFSBCOPY(verf, nmp->nm_verf, NFSX_VERF);
1324 }
1325 NFSUNLOCKMNT(nmp);
1326 if (attrflag) {

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

2468
2469 /*
2470 * If the op is asynchronous and an i/o daemon is waiting
2471 * queue the request, wake it up and wait for completion
2472 * otherwise just do it ourselves.
2473 */
2474 if ((bp->b_flags & B_ASYNC) == 0 ||
2475 ncl_asyncio(VFSTONFS(ap->a_vp->v_mount), bp, NOCRED, curthread))
1319 NFSLOCKMNT(nmp);
1320 if (!error && NFSHASWRITEVERF(nmp) &&
1321 NFSBCMP(verf, nmp->nm_verf, NFSX_VERF)) {
1322 *must_commit = 1;
1323 NFSBCOPY(verf, nmp->nm_verf, NFSX_VERF);
1324 }
1325 NFSUNLOCKMNT(nmp);
1326 if (attrflag) {

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

2468
2469 /*
2470 * If the op is asynchronous and an i/o daemon is waiting
2471 * queue the request, wake it up and wait for completion
2472 * otherwise just do it ourselves.
2473 */
2474 if ((bp->b_flags & B_ASYNC) == 0 ||
2475 ncl_asyncio(VFSTONFS(ap->a_vp->v_mount), bp, NOCRED, curthread))
2476 (void)ncl_doio(ap->a_vp, bp, cr, curthread);
2476 (void) ncl_doio(ap->a_vp, bp, cr, curthread, 1);
2477 return (0);
2478}
2479
2480/*
2481 * fsync vnode op. Just call ncl_flush() with commit == 1.
2482 */
2483/* ARGSUSED */
2484static int
2485nfs_fsync(struct vop_fsync_args *ap)
2486{
2477 return (0);
2478}
2479
2480/*
2481 * fsync vnode op. Just call ncl_flush() with commit == 1.
2482 */
2483/* ARGSUSED */
2484static int
2485nfs_fsync(struct vop_fsync_args *ap)
2486{
2487 return (ncl_flush(ap->a_vp, ap->a_waitfor, NULL, ap->a_td, 1));
2487 return (ncl_flush(ap->a_vp, ap->a_waitfor, NULL, ap->a_td, 1, 0));
2488}
2489
2490/*
2491 * Flush all the blocks associated with a vnode.
2492 * Walk through the buffer pool and push any dirty pages
2493 * associated with the vnode.
2488}
2489
2490/*
2491 * Flush all the blocks associated with a vnode.
2492 * Walk through the buffer pool and push any dirty pages
2493 * associated with the vnode.
2494 * If the called_from_renewthread argument is TRUE, it has been called
2495 * from the NFSv4 renew thread and, as such, cannot block indefinitely
2496 * waiting for a buffer write to complete.
2494 */
2495int
2496ncl_flush(struct vnode *vp, int waitfor, struct ucred *cred, struct thread *td,
2497 */
2498int
2499ncl_flush(struct vnode *vp, int waitfor, struct ucred *cred, struct thread *td,
2497 int commit)
2500 int commit, int called_from_renewthread)
2498{
2499 struct nfsnode *np = VTONFS(vp);
2500 struct buf *bp;
2501 int i;
2502 struct buf *nbp;
2503 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2504 int error = 0, slptimeo = 0, slpflag = 0, retv, bvecpos;
2505 int passone = 1, trycnt = 0;
2506 u_quad_t off, endoff, toff;
2507 struct ucred* wcred = NULL;
2508 struct buf **bvec = NULL;
2509 struct bufobj *bo;
2510#ifndef NFS_COMMITBVECSIZ
2511#define NFS_COMMITBVECSIZ 20
2512#endif
2513 struct buf *bvec_on_stack[NFS_COMMITBVECSIZ];
2514 int bvecsize = 0, bveccount;
2515
2501{
2502 struct nfsnode *np = VTONFS(vp);
2503 struct buf *bp;
2504 int i;
2505 struct buf *nbp;
2506 struct nfsmount *nmp = VFSTONFS(vp->v_mount);
2507 int error = 0, slptimeo = 0, slpflag = 0, retv, bvecpos;
2508 int passone = 1, trycnt = 0;
2509 u_quad_t off, endoff, toff;
2510 struct ucred* wcred = NULL;
2511 struct buf **bvec = NULL;
2512 struct bufobj *bo;
2513#ifndef NFS_COMMITBVECSIZ
2514#define NFS_COMMITBVECSIZ 20
2515#endif
2516 struct buf *bvec_on_stack[NFS_COMMITBVECSIZ];
2517 int bvecsize = 0, bveccount;
2518
2519 if (called_from_renewthread != 0)
2520 slptimeo = hz;
2516 if (nmp->nm_flag & NFSMNT_INT)
2517 slpflag = NFS_PCATCH;
2518 if (!commit)
2519 passone = 0;
2520 bo = &vp->v_bufobj;
2521 /*
2522 * A b_flags == (B_DELWRI | B_NEEDCOMMIT) block has been written to the
2523 * server, but has not been committed to stable storage on the server

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

2703 if (error == 0) {
2704 BUF_UNLOCK(bp);
2705 goto loop;
2706 }
2707 if (error == ENOLCK) {
2708 error = 0;
2709 goto loop;
2710 }
2521 if (nmp->nm_flag & NFSMNT_INT)
2522 slpflag = NFS_PCATCH;
2523 if (!commit)
2524 passone = 0;
2525 bo = &vp->v_bufobj;
2526 /*
2527 * A b_flags == (B_DELWRI | B_NEEDCOMMIT) block has been written to the
2528 * server, but has not been committed to stable storage on the server

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

2708 if (error == 0) {
2709 BUF_UNLOCK(bp);
2710 goto loop;
2711 }
2712 if (error == ENOLCK) {
2713 error = 0;
2714 goto loop;
2715 }
2716 if (called_from_renewthread != 0) {
2717 /*
2718 * Return EIO so the flush will be retried
2719 * later.
2720 */
2721 error = EIO;
2722 goto done;
2723 }
2711 if (newnfs_sigintr(nmp, td)) {
2712 error = EINTR;
2713 goto done;
2714 }
2715 if (slpflag & PCATCH) {
2716 slpflag = 0;
2717 slptimeo = 2 * hz;
2718 }

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

2742 BO_UNLOCK(bo);
2743 goto again;
2744 }
2745 if (waitfor == MNT_WAIT) {
2746 while (bo->bo_numoutput) {
2747 error = bufobj_wwait(bo, slpflag, slptimeo);
2748 if (error) {
2749 BO_UNLOCK(bo);
2724 if (newnfs_sigintr(nmp, td)) {
2725 error = EINTR;
2726 goto done;
2727 }
2728 if (slpflag & PCATCH) {
2729 slpflag = 0;
2730 slptimeo = 2 * hz;
2731 }

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

2755 BO_UNLOCK(bo);
2756 goto again;
2757 }
2758 if (waitfor == MNT_WAIT) {
2759 while (bo->bo_numoutput) {
2760 error = bufobj_wwait(bo, slpflag, slptimeo);
2761 if (error) {
2762 BO_UNLOCK(bo);
2763 if (called_from_renewthread != 0) {
2764 /*
2765 * Return EIO so that the flush will be
2766 * retried later.
2767 */
2768 error = EIO;
2769 goto done;
2770 }
2750 error = newnfs_sigintr(nmp, td);
2751 if (error)
2752 goto done;
2753 if (slpflag & PCATCH) {
2754 slpflag = 0;
2755 slptimeo = 2 * hz;
2756 }
2757 BO_LOCK(bo);

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

2833
2834 /*
2835 * If this is unlocking a write locked region, flush and
2836 * commit them before unlocking. This is required by
2837 * RFC3530 Sec. 9.3.2.
2838 */
2839 if (ap->a_op == F_UNLCK &&
2840 nfscl_checkwritelocked(vp, ap->a_fl, cred, td))
2771 error = newnfs_sigintr(nmp, td);
2772 if (error)
2773 goto done;
2774 if (slpflag & PCATCH) {
2775 slpflag = 0;
2776 slptimeo = 2 * hz;
2777 }
2778 BO_LOCK(bo);

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

2854
2855 /*
2856 * If this is unlocking a write locked region, flush and
2857 * commit them before unlocking. This is required by
2858 * RFC3530 Sec. 9.3.2.
2859 */
2860 if (ap->a_op == F_UNLCK &&
2861 nfscl_checkwritelocked(vp, ap->a_fl, cred, td))
2841 (void) ncl_flush(vp, MNT_WAIT, cred, td, 1);
2862 (void) ncl_flush(vp, MNT_WAIT, cred, td, 1, 0);
2842
2843 /*
2844 * Loop around doing the lock op, while a blocking lock
2845 * must wait for the lock op to succeed.
2846 */
2847 do {
2848 ret = nfsrpc_advlock(vp, np->n_size, ap->a_op,
2849 ap->a_fl, 0, cred, td);

--- 369 unchanged lines hidden ---
2863
2864 /*
2865 * Loop around doing the lock op, while a blocking lock
2866 * must wait for the lock op to succeed.
2867 */
2868 do {
2869 ret = nfsrpc_advlock(vp, np->n_size, ap->a_op,
2870 ap->a_fl, 0, cred, td);

--- 369 unchanged lines hidden ---