BSD 4_4_Lite2 release
[unix-history] / usr / src / sys / nfs / nfs_srvcache.c
index 62e96e4..954987b 100644 (file)
@@ -5,9 +5,35 @@
  * This code is derived from software contributed to Berkeley by
  * Rick Macklem at The University of Guelph.
  *
  * This code is derived from software contributed to Berkeley by
  * Rick Macklem at The University of Guelph.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)nfs_srvcache.c      8.2 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)nfs_srvcache.c      8.3 (Berkeley) 3/30/95
  */
 
 /*
  */
 
 /*
 #endif
 #include <nfs/nfsm_subs.h>
 #include <nfs/rpcv2.h>
 #endif
 #include <nfs/nfsm_subs.h>
 #include <nfs/rpcv2.h>
-#include <nfs/nfsv2.h>
+#include <nfs/nfsproto.h>
 #include <nfs/nfs.h>
 #include <nfs/nfsrvcache.h>
 #include <nfs/nqnfs.h>
 
 #include <nfs/nfs.h>
 #include <nfs/nfsrvcache.h>
 #include <nfs/nqnfs.h>
 
+extern struct nfsstats nfsstats;
+extern int nfsv2_procid[NFS_NPROCS];
 long numnfsrvcache, desirednfsrvcache = NFSRVCACHESIZ;
 
 #define        NFSRCHASH(xid) \
 long numnfsrvcache, desirednfsrvcache = NFSRVCACHESIZ;
 
 #define        NFSRCHASH(xid) \
@@ -62,7 +90,6 @@ int nonidempotent[NFS_NPROCS] = {
        FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
-       FALSE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
@@ -71,6 +98,10 @@ int nonidempotent[NFS_NPROCS] = {
        TRUE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
+       TRUE,
+       FALSE,
+       FALSE,
+       FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
@@ -81,7 +112,7 @@ int nonidempotent[NFS_NPROCS] = {
 };
 
 /* True iff the rpc reply is an nfs status ONLY! */
 };
 
 /* True iff the rpc reply is an nfs status ONLY! */
-static int repliesstatus[NFS_NPROCS] = {
+static int nfsv2_repstat[NFS_NPROCS] = {
        FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
        FALSE,
@@ -100,16 +131,12 @@ static int repliesstatus[NFS_NPROCS] = {
        TRUE,
        FALSE,
        FALSE,
        TRUE,
        FALSE,
        FALSE,
-       FALSE,
-       FALSE,
-       FALSE,
-       FALSE,
-       TRUE,
 };
 
 /*
  * Initialize the server request cache list
  */
 };
 
 /*
  * Initialize the server request cache list
  */
+void
 nfsrv_initcache()
 {
 
 nfsrv_initcache()
 {
 
@@ -131,9 +158,10 @@ nfsrv_initcache()
  *   return DOIT
  * Update/add new request at end of lru list
  */
  *   return DOIT
  * Update/add new request at end of lru list
  */
-nfsrv_getcache(nam, nd, repp)
-       struct mbuf *nam;
-       register struct nfsd *nd;
+int
+nfsrv_getcache(nd, slp, repp)
+       register struct nfsrv_descript *nd;
+       struct nfssvc_sock *slp;
        struct mbuf **repp;
 {
        register struct nfsrvcache *rp;
        struct mbuf **repp;
 {
        register struct nfsrvcache *rp;
@@ -142,13 +170,17 @@ nfsrv_getcache(nam, nd, repp)
        caddr_t bpos;
        int ret;
 
        caddr_t bpos;
        int ret;
 
-       if (nd->nd_nqlflag != NQL_NOVAL)
+       /*
+        * Don't cache recent requests for reliable transport protocols.
+        * (Maybe we should for the case of a reconnect, but..)
+        */
+       if (!nd->nd_nam2)
                return (RC_DOIT);
 loop:
        for (rp = NFSRCHASH(nd->nd_retxid)->lh_first; rp != 0;
            rp = rp->rc_hash.le_next) {
            if (nd->nd_retxid == rp->rc_xid && nd->nd_procnum == rp->rc_proc &&
                return (RC_DOIT);
 loop:
        for (rp = NFSRCHASH(nd->nd_retxid)->lh_first; rp != 0;
            rp = rp->rc_hash.le_next) {
            if (nd->nd_retxid == rp->rc_xid && nd->nd_procnum == rp->rc_proc &&
-               netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nam)) {
+               netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nd->nd_nam)) {
                        if ((rp->rc_flag & RC_LOCKED) != 0) {
                                rp->rc_flag |= RC_WANTED;
                                (void) tsleep((caddr_t)rp, PZERO-1, "nfsrc", 0);
                        if ((rp->rc_flag & RC_LOCKED) != 0) {
                                rp->rc_flag |= RC_WANTED;
                                (void) tsleep((caddr_t)rp, PZERO-1, "nfsrc", 0);
@@ -167,7 +199,7 @@ loop:
                                ret = RC_DROPIT;
                        } else if (rp->rc_flag & RC_REPSTATUS) {
                                nfsstats.srvcache_nonidemdonehits++;
                                ret = RC_DROPIT;
                        } else if (rp->rc_flag & RC_REPSTATUS) {
                                nfsstats.srvcache_nonidemdonehits++;
-                               nfs_rephead(0, nd, rp->rc_status,
+                               nfs_rephead(0, nd, slp, rp->rc_status,
                                   0, (u_quad_t *)0, repp, &mb, &bpos);
                                ret = RC_REPLY;
                        } else if (rp->rc_flag & RC_REPMBUF) {
                                   0, (u_quad_t *)0, repp, &mb, &bpos);
                                ret = RC_REPLY;
                        } else if (rp->rc_flag & RC_REPMBUF) {
@@ -214,7 +246,7 @@ loop:
        TAILQ_INSERT_TAIL(&nfsrvlruhead, rp, rc_lru);
        rp->rc_state = RC_INPROG;
        rp->rc_xid = nd->nd_retxid;
        TAILQ_INSERT_TAIL(&nfsrvlruhead, rp, rc_lru);
        rp->rc_state = RC_INPROG;
        rp->rc_xid = nd->nd_retxid;
-       saddr = mtod(nam, struct sockaddr_in *);
+       saddr = mtod(nd->nd_nam, struct sockaddr_in *);
        switch (saddr->sin_family) {
        case AF_INET:
                rp->rc_flag |= RC_INETADDR;
        switch (saddr->sin_family) {
        case AF_INET:
                rp->rc_flag |= RC_INETADDR;
@@ -223,7 +255,7 @@ loop:
        case AF_ISO:
        default:
                rp->rc_flag |= RC_NAM;
        case AF_ISO:
        default:
                rp->rc_flag |= RC_NAM;
-               rp->rc_nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
+               rp->rc_nam = m_copym(nd->nd_nam, 0, M_COPYALL, M_WAIT);
                break;
        };
        rp->rc_proc = nd->nd_procnum;
                break;
        };
        rp->rc_proc = nd->nd_procnum;
@@ -240,21 +272,20 @@ loop:
  * Update a request cache entry after the rpc has been done
  */
 void
  * Update a request cache entry after the rpc has been done
  */
 void
-nfsrv_updatecache(nam, nd, repvalid, repmbuf)
-       struct mbuf *nam;
-       register struct nfsd *nd;
+nfsrv_updatecache(nd, repvalid, repmbuf)
+       register struct nfsrv_descript *nd;
        int repvalid;
        struct mbuf *repmbuf;
 {
        register struct nfsrvcache *rp;
 
        int repvalid;
        struct mbuf *repmbuf;
 {
        register struct nfsrvcache *rp;
 
-       if (nd->nd_nqlflag != NQL_NOVAL)
+       if (!nd->nd_nam2)
                return;
 loop:
        for (rp = NFSRCHASH(nd->nd_retxid)->lh_first; rp != 0;
            rp = rp->rc_hash.le_next) {
            if (nd->nd_retxid == rp->rc_xid && nd->nd_procnum == rp->rc_proc &&
                return;
 loop:
        for (rp = NFSRCHASH(nd->nd_retxid)->lh_first; rp != 0;
            rp = rp->rc_hash.le_next) {
            if (nd->nd_retxid == rp->rc_xid && nd->nd_procnum == rp->rc_proc &&
-               netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nam)) {
+               netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nd->nd_nam)) {
                        if ((rp->rc_flag & RC_LOCKED) != 0) {
                                rp->rc_flag |= RC_WANTED;
                                (void) tsleep((caddr_t)rp, PZERO-1, "nfsrc", 0);
                        if ((rp->rc_flag & RC_LOCKED) != 0) {
                                rp->rc_flag |= RC_WANTED;
                                (void) tsleep((caddr_t)rp, PZERO-1, "nfsrc", 0);
@@ -267,7 +298,8 @@ loop:
                         * the reply for non-idempotent rpc's.
                         */
                        if (repvalid && nonidempotent[nd->nd_procnum]) {
                         * the reply for non-idempotent rpc's.
                         */
                        if (repvalid && nonidempotent[nd->nd_procnum]) {
-                               if (repliesstatus[nd->nd_procnum]) {
+                               if ((nd->nd_flag & ND_NFSV3) == 0 &&
+                                 nfsv2_repstat[nfsv2_procid[nd->nd_procnum]]) {
                                        rp->rc_status = nd->nd_repstat;
                                        rp->rc_flag |= RC_REPSTATUS;
                                } else {
                                        rp->rc_status = nd->nd_repstat;
                                        rp->rc_flag |= RC_REPSTATUS;
                                } else {