Deleted Added
full compact
nfs_clstate.c (207082) nfs_clstate.c (207170)
1/*-
2 * Copyright (c) 2009 Rick Macklem, University of Guelph
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009 Rick Macklem, University of Guelph
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clstate.c 207082 2010-04-22 23:51:01Z rmacklem $");
29__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clstate.c 207170 2010-04-24 22:52:14Z rmacklem $");
30
31/*
32 * These functions implement the client side state handling for NFSv4.
33 * NFSv4 state handling:
34 * - A lockowner is used to determine lock contention, so it
35 * corresponds directly to a Posix pid. (1 to 1 mapping)
36 * - The correct granularity of an OpenOwner is not nearly so
37 * obvious. An OpenOwner does the following:

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

779 clidinusedelay = 120;
780 trystalecnt = 3;
781 do {
782 error = nfsrpc_setclient(VFSTONFS(vnode_mount(vp)),
783 clp, cred, p);
784 if (error == NFSERR_STALECLIENTID ||
785 error == NFSERR_STALEDONTRECOVER ||
786 error == NFSERR_CLIDINUSE) {
30
31/*
32 * These functions implement the client side state handling for NFSv4.
33 * NFSv4 state handling:
34 * - A lockowner is used to determine lock contention, so it
35 * corresponds directly to a Posix pid. (1 to 1 mapping)
36 * - The correct granularity of an OpenOwner is not nearly so
37 * obvious. An OpenOwner does the following:

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

779 clidinusedelay = 120;
780 trystalecnt = 3;
781 do {
782 error = nfsrpc_setclient(VFSTONFS(vnode_mount(vp)),
783 clp, cred, p);
784 if (error == NFSERR_STALECLIENTID ||
785 error == NFSERR_STALEDONTRECOVER ||
786 error == NFSERR_CLIDINUSE) {
787 (void) nfs_catnap(PZERO, "nfs_setcl");
787 (void) nfs_catnap(PZERO, error, "nfs_setcl");
788 }
789 } while (((error == NFSERR_STALECLIENTID ||
790 error == NFSERR_STALEDONTRECOVER) && --trystalecnt > 0) ||
791 (error == NFSERR_CLIDINUSE && --clidinusedelay > 0));
792 if (error) {
793 NFSLOCKCLSTATE();
794 nfsv4_unlock(&clp->nfsc_lock, 0);
795 NFSUNLOCKCLSTATE();

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

2041 /*
2042 * Now, get rid of extra Opens and Delegations.
2043 */
2044 LIST_FOREACH_SAFE(op, &extra_open, nfso_list, nop) {
2045 do {
2046 newnfs_copycred(&op->nfso_cred, tcred);
2047 error = nfscl_tryclose(op, tcred, nmp, p);
2048 if (error == NFSERR_GRACE)
788 }
789 } while (((error == NFSERR_STALECLIENTID ||
790 error == NFSERR_STALEDONTRECOVER) && --trystalecnt > 0) ||
791 (error == NFSERR_CLIDINUSE && --clidinusedelay > 0));
792 if (error) {
793 NFSLOCKCLSTATE();
794 nfsv4_unlock(&clp->nfsc_lock, 0);
795 NFSUNLOCKCLSTATE();

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

2041 /*
2042 * Now, get rid of extra Opens and Delegations.
2043 */
2044 LIST_FOREACH_SAFE(op, &extra_open, nfso_list, nop) {
2045 do {
2046 newnfs_copycred(&op->nfso_cred, tcred);
2047 error = nfscl_tryclose(op, tcred, nmp, p);
2048 if (error == NFSERR_GRACE)
2049 (void) nfs_catnap(PZERO, "nfsexcls");
2049 (void) nfs_catnap(PZERO, error, "nfsexcls");
2050 } while (error == NFSERR_GRACE);
2051 LIST_REMOVE(op, nfso_list);
2052 FREE((caddr_t)op, M_NFSCLOPEN);
2053 }
2054 if (nowp != NULL)
2055 FREE((caddr_t)nowp, M_NFSCLOWNER);
2056
2057 TAILQ_FOREACH_SAFE(dp, &extra_deleg, nfsdl_list, ndp) {
2058 do {
2059 newnfs_copycred(&dp->nfsdl_cred, tcred);
2060 error = nfscl_trydelegreturn(dp, tcred, nmp, p);
2061 if (error == NFSERR_GRACE)
2050 } while (error == NFSERR_GRACE);
2051 LIST_REMOVE(op, nfso_list);
2052 FREE((caddr_t)op, M_NFSCLOPEN);
2053 }
2054 if (nowp != NULL)
2055 FREE((caddr_t)nowp, M_NFSCLOWNER);
2056
2057 TAILQ_FOREACH_SAFE(dp, &extra_deleg, nfsdl_list, ndp) {
2058 do {
2059 newnfs_copycred(&dp->nfsdl_cred, tcred);
2060 error = nfscl_trydelegreturn(dp, tcred, nmp, p);
2061 if (error == NFSERR_GRACE)
2062 (void) nfs_catnap(PZERO, "nfsexdlg");
2062 (void) nfs_catnap(PZERO, error, "nfsexdlg");
2063 } while (error == NFSERR_GRACE);
2064 TAILQ_REMOVE(&extra_deleg, dp, nfsdl_list);
2065 FREE((caddr_t)dp, M_NFSCLDELEG);
2066 }
2067
2068 NFSLOCKCLSTATE();
2069 clp->nfsc_flags &= ~NFSCLFLAGS_RECVRINPROG;
2070 wakeup(&clp->nfsc_flags);

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

3614{
3615 int error;
3616
3617 do {
3618 error = nfsrpc_openrpc(nmp, vp, fhp, fhlen, newfhp, newfhlen,
3619 mode, op, name, namelen, ndpp, reclaim, delegtype, cred, p,
3620 0, 0);
3621 if (error == NFSERR_DELAY)
2063 } while (error == NFSERR_GRACE);
2064 TAILQ_REMOVE(&extra_deleg, dp, nfsdl_list);
2065 FREE((caddr_t)dp, M_NFSCLDELEG);
2066 }
2067
2068 NFSLOCKCLSTATE();
2069 clp->nfsc_flags &= ~NFSCLFLAGS_RECVRINPROG;
2070 wakeup(&clp->nfsc_flags);

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

3614{
3615 int error;
3616
3617 do {
3618 error = nfsrpc_openrpc(nmp, vp, fhp, fhlen, newfhp, newfhlen,
3619 mode, op, name, namelen, ndpp, reclaim, delegtype, cred, p,
3620 0, 0);
3621 if (error == NFSERR_DELAY)
3622 (void) nfs_catnap(PZERO, "nfstryop");
3622 (void) nfs_catnap(PZERO, error, "nfstryop");
3623 } while (error == NFSERR_DELAY);
3624 if (error == EAUTH || error == EACCES) {
3625 /* Try again using system credentials */
3626 newnfs_setroot(cred);
3627 do {
3628 error = nfsrpc_openrpc(nmp, vp, fhp, fhlen, newfhp,
3629 newfhlen, mode, op, name, namelen, ndpp, reclaim,
3630 delegtype, cred, p, 1, 0);
3631 if (error == NFSERR_DELAY)
3623 } while (error == NFSERR_DELAY);
3624 if (error == EAUTH || error == EACCES) {
3625 /* Try again using system credentials */
3626 newnfs_setroot(cred);
3627 do {
3628 error = nfsrpc_openrpc(nmp, vp, fhp, fhlen, newfhp,
3629 newfhlen, mode, op, name, namelen, ndpp, reclaim,
3630 delegtype, cred, p, 1, 0);
3631 if (error == NFSERR_DELAY)
3632 (void) nfs_catnap(PZERO, "nfstryop");
3632 (void) nfs_catnap(PZERO, error, "nfstryop");
3633 } while (error == NFSERR_DELAY);
3634 }
3635 return (error);
3636}
3637
3638/*
3639 * Try a byte range lock. Just loop on nfsrpc_lock() while it returns
3640 * NFSERR_DELAY. Also, retry with system credentials, if the provided

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

3647{
3648 struct nfsrv_descript nfsd, *nd = &nfsd;
3649 int error;
3650
3651 do {
3652 error = nfsrpc_lock(nd, nmp, vp, fhp, fhlen, nlp, newone,
3653 reclaim, off, len, type, cred, p, 0);
3654 if (!error && nd->nd_repstat == NFSERR_DELAY)
3633 } while (error == NFSERR_DELAY);
3634 }
3635 return (error);
3636}
3637
3638/*
3639 * Try a byte range lock. Just loop on nfsrpc_lock() while it returns
3640 * NFSERR_DELAY. Also, retry with system credentials, if the provided

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

3647{
3648 struct nfsrv_descript nfsd, *nd = &nfsd;
3649 int error;
3650
3651 do {
3652 error = nfsrpc_lock(nd, nmp, vp, fhp, fhlen, nlp, newone,
3653 reclaim, off, len, type, cred, p, 0);
3654 if (!error && nd->nd_repstat == NFSERR_DELAY)
3655 (void) nfs_catnap(PZERO, "nfstrylck");
3655 (void) nfs_catnap(PZERO, (int)nd->nd_repstat,
3656 "nfstrylck");
3656 } while (!error && nd->nd_repstat == NFSERR_DELAY);
3657 if (!error)
3658 error = nd->nd_repstat;
3659 if (error == EAUTH || error == EACCES) {
3660 /* Try again using root credentials */
3661 newnfs_setroot(cred);
3662 do {
3663 error = nfsrpc_lock(nd, nmp, vp, fhp, fhlen, nlp,
3664 newone, reclaim, off, len, type, cred, p, 1);
3665 if (!error && nd->nd_repstat == NFSERR_DELAY)
3657 } while (!error && nd->nd_repstat == NFSERR_DELAY);
3658 if (!error)
3659 error = nd->nd_repstat;
3660 if (error == EAUTH || error == EACCES) {
3661 /* Try again using root credentials */
3662 newnfs_setroot(cred);
3663 do {
3664 error = nfsrpc_lock(nd, nmp, vp, fhp, fhlen, nlp,
3665 newone, reclaim, off, len, type, cred, p, 1);
3666 if (!error && nd->nd_repstat == NFSERR_DELAY)
3666 (void) nfs_catnap(PZERO, "nfstrylck");
3667 (void) nfs_catnap(PZERO, (int)nd->nd_repstat,
3668 "nfstrylck");
3667 } while (!error && nd->nd_repstat == NFSERR_DELAY);
3668 if (!error)
3669 error = nd->nd_repstat;
3670 }
3671 return (error);
3672}
3673
3674/*

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

3680nfscl_trydelegreturn(struct nfscldeleg *dp, struct ucred *cred,
3681 struct nfsmount *nmp, NFSPROC_T *p)
3682{
3683 int error;
3684
3685 do {
3686 error = nfsrpc_delegreturn(dp, cred, nmp, p, 0);
3687 if (error == NFSERR_DELAY)
3669 } while (!error && nd->nd_repstat == NFSERR_DELAY);
3670 if (!error)
3671 error = nd->nd_repstat;
3672 }
3673 return (error);
3674}
3675
3676/*

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

3682nfscl_trydelegreturn(struct nfscldeleg *dp, struct ucred *cred,
3683 struct nfsmount *nmp, NFSPROC_T *p)
3684{
3685 int error;
3686
3687 do {
3688 error = nfsrpc_delegreturn(dp, cred, nmp, p, 0);
3689 if (error == NFSERR_DELAY)
3688 (void) nfs_catnap(PZERO, "nfstrydp");
3690 (void) nfs_catnap(PZERO, error, "nfstrydp");
3689 } while (error == NFSERR_DELAY);
3690 if (error == EAUTH || error == EACCES) {
3691 /* Try again using system credentials */
3692 newnfs_setroot(cred);
3693 do {
3694 error = nfsrpc_delegreturn(dp, cred, nmp, p, 1);
3695 if (error == NFSERR_DELAY)
3691 } while (error == NFSERR_DELAY);
3692 if (error == EAUTH || error == EACCES) {
3693 /* Try again using system credentials */
3694 newnfs_setroot(cred);
3695 do {
3696 error = nfsrpc_delegreturn(dp, cred, nmp, p, 1);
3697 if (error == NFSERR_DELAY)
3696 (void) nfs_catnap(PZERO, "nfstrydp");
3698 (void) nfs_catnap(PZERO, error, "nfstrydp");
3697 } while (error == NFSERR_DELAY);
3698 }
3699 return (error);
3700}
3701
3702/*
3703 * Try a close against the server. Just call nfsrpc_closerpc(),
3704 * retrying while NFSERR_DELAY. Also, try system credentials, if the passed in

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

3709 struct nfsmount *nmp, NFSPROC_T *p)
3710{
3711 struct nfsrv_descript nfsd, *nd = &nfsd;
3712 int error;
3713
3714 do {
3715 error = nfsrpc_closerpc(nd, nmp, op, cred, p, 0);
3716 if (error == NFSERR_DELAY)
3699 } while (error == NFSERR_DELAY);
3700 }
3701 return (error);
3702}
3703
3704/*
3705 * Try a close against the server. Just call nfsrpc_closerpc(),
3706 * retrying while NFSERR_DELAY. Also, try system credentials, if the passed in

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

3711 struct nfsmount *nmp, NFSPROC_T *p)
3712{
3713 struct nfsrv_descript nfsd, *nd = &nfsd;
3714 int error;
3715
3716 do {
3717 error = nfsrpc_closerpc(nd, nmp, op, cred, p, 0);
3718 if (error == NFSERR_DELAY)
3717 (void) nfs_catnap(PZERO, "nfstrycl");
3719 (void) nfs_catnap(PZERO, error, "nfstrycl");
3718 } while (error == NFSERR_DELAY);
3719 if (error == EAUTH || error == EACCES) {
3720 /* Try again using system credentials */
3721 newnfs_setroot(cred);
3722 do {
3723 error = nfsrpc_closerpc(nd, nmp, op, cred, p, 1);
3724 if (error == NFSERR_DELAY)
3720 } while (error == NFSERR_DELAY);
3721 if (error == EAUTH || error == EACCES) {
3722 /* Try again using system credentials */
3723 newnfs_setroot(cred);
3724 do {
3725 error = nfsrpc_closerpc(nd, nmp, op, cred, p, 1);
3726 if (error == NFSERR_DELAY)
3725 (void) nfs_catnap(PZERO, "nfstrycl");
3727 (void) nfs_catnap(PZERO, error, "nfstrycl");
3726 } while (error == NFSERR_DELAY);
3727 }
3728 return (error);
3729}
3730
3731/*
3732 * Decide if a delegation on a file permits close without flushing writes
3733 * to the server. This might be a big performance win in some environments.

--- 464 unchanged lines hidden ---
3728 } while (error == NFSERR_DELAY);
3729 }
3730 return (error);
3731}
3732
3733/*
3734 * Decide if a delegation on a file permits close without flushing writes
3735 * to the server. This might be a big performance win in some environments.

--- 464 unchanged lines hidden ---