BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / nfs / nfs_syscalls.c
index d78b006..c6d93c9 100644 (file)
@@ -5,34 +5,46 @@
  * 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.
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  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.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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_syscalls.c      7.18 (Berkeley) 6/28/90
+ * 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_syscalls.c      7.26 (Berkeley) 4/16/91
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "kernel.h"
 #include "file.h"
 #include "stat.h"
 #include "kernel.h"
 #include "file.h"
 #include "stat.h"
+#include "namei.h"
 #include "vnode.h"
 #include "mount.h"
 #include "proc.h"
 #include "vnode.h"
 #include "mount.h"
 #include "proc.h"
-#include "uio.h"
 #include "malloc.h"
 #include "buf.h"
 #include "mbuf.h"
 #include "malloc.h"
 #include "buf.h"
 #include "mbuf.h"
 #include "socketvar.h"
 #include "domain.h"
 #include "protosw.h"
 #include "socketvar.h"
 #include "domain.h"
 #include "protosw.h"
+
 #include "../netinet/in.h"
 #include "../netinet/tcp.h"
 #include "../netinet/in.h"
 #include "../netinet/tcp.h"
+
 #include "nfsv2.h"
 #include "nfs.h"
 #include "nfsrvcache.h"
 #include "nfsv2.h"
 #include "nfs.h"
 #include "nfsrvcache.h"
 extern u_long nfs_prog, nfs_vers;
 extern int (*nfsrv_procs[NFS_NPROCS])();
 extern struct buf nfs_bqueue;
 extern u_long nfs_prog, nfs_vers;
 extern int (*nfsrv_procs[NFS_NPROCS])();
 extern struct buf nfs_bqueue;
-extern int nfs_asyncdaemons;
+extern int nfs_numasync;
 extern struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON];
 extern int nfs_tcpnodelay;
 extern struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON];
 extern int nfs_tcpnodelay;
-struct file *getsock();
+struct mbuf *nfs_compress();
 
 #define        TRUE    1
 #define        FALSE   0
 
 
 #define        TRUE    1
 #define        FALSE   0
 
+static int nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
+static int compressreply[NFS_NPROCS] = {
+       FALSE,
+       TRUE,
+       TRUE,
+       FALSE,
+       TRUE,
+       TRUE,
+       FALSE,
+       FALSE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+       TRUE,
+};
 /*
  * NFS server system calls
  * getfh() lives here too, but maybe should move to kern/vfs_syscalls.c
 /*
  * NFS server system calls
  * getfh() lives here too, but maybe should move to kern/vfs_syscalls.c
@@ -75,20 +110,22 @@ getfh(p, uap, retval)
        } *uap;
        int *retval;
 {
        } *uap;
        int *retval;
 {
-       register struct nameidata *ndp = &u.u_nd;
+       register struct nameidata *ndp;
        register struct vnode *vp;
        fhandle_t fh;
        int error;
        register struct vnode *vp;
        fhandle_t fh;
        int error;
+       struct nameidata nd;
 
        /*
         * Must be super user
         */
 
        /*
         * Must be super user
         */
-       if (error = suser(ndp->ni_cred, &u.u_acflag))
+       if (error = suser(p->p_ucred, &p->p_acflag))
                return (error);
                return (error);
+       ndp = &nd;
        ndp->ni_nameiop = LOOKUP | LOCKLEAF | FOLLOW;
        ndp->ni_segflg = UIO_USERSPACE;
        ndp->ni_dirp = uap->fname;
        ndp->ni_nameiop = LOOKUP | LOCKLEAF | FOLLOW;
        ndp->ni_segflg = UIO_USERSPACE;
        ndp->ni_dirp = uap->fname;
-       if (error = namei(ndp))
+       if (error = namei(ndp, p))
                return (error);
        vp = ndp->ni_vp;
        bzero((caddr_t)&fh, sizeof(fh));
                return (error);
        vp = ndp->ni_vp;
        bzero((caddr_t)&fh, sizeof(fh));
@@ -125,17 +162,16 @@ nfssvc(p, uap, retval)
        struct mbuf msk, mtch;
        struct socket *so;
        caddr_t dpos;
        struct mbuf msk, mtch;
        struct socket *so;
        caddr_t dpos;
-       int procid, repstat, error, cacherep;
+       int procid, repstat, error, cacherep, wascomp;
        u_long retxid;
 
        /*
         * Must be super user
         */
        u_long retxid;
 
        /*
         * Must be super user
         */
-       if (error = suser(u.u_cred, &u.u_acflag))
-               goto bad;
-       fp = getsock(uap->s);
-       if (fp == 0)
-               return;
+       if (error = suser(p->p_ucred, &p->p_acflag))
+               return (error);
+       if (error = getsock(p->p_fd, uap->s, &fp))
+               return (error);
        so = (struct socket *)fp->f_data;
        if (sosendallatonce(so))
                siz = NFS_MAXPACKET;
        so = (struct socket *)fp->f_data;
        if (sosendallatonce(so))
                siz = NFS_MAXPACKET;
@@ -155,7 +191,7 @@ nfssvc(p, uap, retval)
        m_freem(nam);
 
        /* Copy the cred so others don't see changes */
        m_freem(nam);
 
        /* Copy the cred so others don't see changes */
-       cr = u.u_cred = crcopy(u.u_cred);
+       cr = p->p_ucred = crcopy(p->p_ucred);
 
        /*
         * Set protocol specific options { for now TCP only } and
 
        /*
         * Set protocol specific options { for now TCP only } and
@@ -187,7 +223,7 @@ nfssvc(p, uap, retval)
        for (;;) {
                if (error = nfs_getreq(so, nfs_prog, nfs_vers, NFS_NPROCS-1,
                   &nam, &mrep, &md, &dpos, &retxid, &procid, cr,
        for (;;) {
                if (error = nfs_getreq(so, nfs_prog, nfs_vers, NFS_NPROCS-1,
                   &nam, &mrep, &md, &dpos, &retxid, &procid, cr,
-                  &msk, &mtch)) {
+                  &msk, &mtch, &wascomp)) {
                        if (nam)
                                m_freem(nam);
                        if (error == EPIPE || error == EINTR ||
                        if (nam)
                                m_freem(nam);
                        if (error == EPIPE || error == EINTR ||
@@ -206,7 +242,7 @@ nfssvc(p, uap, retval)
                switch (cacherep) {
                case RC_DOIT:
                        if (error = (*(nfsrv_procs[procid]))(mrep, md, dpos,
                switch (cacherep) {
                case RC_DOIT:
                        if (error = (*(nfsrv_procs[procid]))(mrep, md, dpos,
-                               cr, retxid, &mreq, &repstat)) {
+                               cr, retxid, &mreq, &repstat, p)) {
                                nfsstats.srv_errs++;
                                if (nam) {
                                        nfsrv_updatecache(nam, retxid, procid,
                                nfsstats.srv_errs++;
                                if (nam) {
                                        nfsrv_updatecache(nam, retxid, procid,
@@ -233,6 +269,10 @@ nfssvc(p, uap, retval)
                        }
                        mreq->m_pkthdr.len = siz;
                        mreq->m_pkthdr.rcvif = (struct ifnet *)0;
                        }
                        mreq->m_pkthdr.len = siz;
                        mreq->m_pkthdr.rcvif = (struct ifnet *)0;
+                       if (wascomp && compressreply[procid]) {
+                               mreq = nfs_compress(mreq);
+                               siz = mreq->m_pkthdr.len;
+                       }
                        /*
                         * For non-atomic protocols, prepend a Sun RPC
                         * Record Mark.
                        /*
                         * For non-atomic protocols, prepend a Sun RPC
                         * Record Mark.
@@ -276,39 +316,53 @@ async_daemon(p, uap, retval)
        int *retval;
 {
        register struct buf *bp, *dp;
        int *retval;
 {
        register struct buf *bp, *dp;
+       register int i, myiod;
        int error;
        int error;
-       int myiod;
 
        /*
         * Must be super user
         */
 
        /*
         * Must be super user
         */
-       if (error = suser(u.u_cred, &u.u_acflag))
+       if (error = suser(p->p_ucred, &p->p_acflag))
                return (error);
        /*
         * Assign my position or return error if too many already running
         */
                return (error);
        /*
         * Assign my position or return error if too many already running
         */
-       if (nfs_asyncdaemons > NFS_MAXASYNCDAEMON)
+       myiod = -1;
+       for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
+               if (nfs_asyncdaemon[i] == 0) {
+                       nfs_asyncdaemon[i]++;
+                       myiod = i;
+                       break;
+               }
+       if (myiod == -1)
                return (EBUSY);
                return (EBUSY);
-       myiod = nfs_asyncdaemons++;
+       nfs_numasync++;
        dp = &nfs_bqueue;
        /*
         * Just loop around doin our stuff until SIGKILL
         */
        for (;;) {
        dp = &nfs_bqueue;
        /*
         * Just loop around doin our stuff until SIGKILL
         */
        for (;;) {
-               while (dp->b_actf == NULL) {
+               while (dp->b_actf == NULL && error == 0) {
                        nfs_iodwant[myiod] = p;
                        nfs_iodwant[myiod] = p;
-                       if (error = tsleep((caddr_t)&nfs_iodwant[myiod],
-                               PWAIT | PCATCH, "nfsidl", 0))
-                               return (error);
+                       error = tsleep((caddr_t)&nfs_iodwant[myiod],
+                               PWAIT | PCATCH, "nfsidl", 0);
+                       nfs_iodwant[myiod] = (struct proc *)0;
+               }
+               while (dp->b_actf != NULL) {
+                       /* Take one off the end of the list */
+                       bp = dp->b_actl;
+                       if (bp->b_actl == dp) {
+                               dp->b_actf = dp->b_actl = (struct buf *)0;
+                       } else {
+                               dp->b_actl = bp->b_actl;
+                               bp->b_actl->b_actf = dp;
+                       }
+                       (void) nfs_doio(bp);
                }
                }
-               /* Take one off the end of the list */
-               bp = dp->b_actl;
-               if (bp->b_actl == dp) {
-                       dp->b_actf = dp->b_actl = (struct buf *)0;
-               } else {
-                       dp->b_actl = bp->b_actl;
-                       bp->b_actl->b_actf = dp;
+               if (error) {
+                       nfs_asyncdaemon[myiod] = 0;
+                       nfs_numasync--;
+                       return (error);
                }
                }
-               (void) nfs_doio(bp);
        }
 }
        }
 }