BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / kern_physio.c
index 61ab1a9..bf6dc96 100644 (file)
-/*     kern_physio.c   4.31    82/08/13        */
-
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/buf.h"
-#include "../h/conf.h"
-#include "../h/proc.h"
-#include "../h/seg.h"
-#include "../h/pte.h"
-#include "../h/vm.h"
-#include "../h/trace.h"
-#include "../h/uio.h"
-
 /*
 /*
- * Swap IO headers -
- * They contain the necessary information for the swap I/O.
- * At any given time, a swap header can be in three
- * different lists. When free it is in the free list, 
- * when allocated and the I/O queued, it is on the swap 
- * device list, and finally, if the operation was a dirty 
- * page push, when the I/O completes, it is inserted 
- * in a list of cleaned pages to be processed by the pageout daemon.
+ * Copyright (c) 1982, 1986, 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ *     from: @(#)kern_physio.c 7.20 (Berkeley) 5/11/91
  */
  */
-struct buf *swbuf;
-short  *swsize;                /* CAN WE JUST USE B_BCOUNT? */
-int    *swpf;
+
+#include "param.h"
+#include "systm.h"
+#include "buf.h"
+#include "conf.h"
+#include "proc.h"
+#include "seg.h"
+#include "trace.h"
+#include "map.h"
+#include "vnode.h"
+#include "specdev.h"
+
+#ifdef HPUXCOMPAT
+#include "user.h"
+#endif
 
 /*
 
 /*
- * swap I/O -
+ * This routine does raw device I/O for a user process.
  *
  *
- * If the flag indicates a dirty page push initiated
- * by the pageout daemon, we map the page into the i th
- * virtual page of process 2 (the daemon itself) where i is
- * the index of the swap header that has been allocated.
- * We simply initialize the header and queue the I/O but
- * do not wait for completion. When the I/O completes,
- * iodone() will link the header to a list of cleaned
- * pages to be processed by the pageout daemon.
+ * If the user has the proper access privileges, the process is
+ * marked 'delayed unlock' and the pages involved in the I/O are
+ * faulted and locked. After the completion of the I/O, the pages
+ * are unlocked.
  */
  */
-swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
-       struct proc *p;
-       swblk_t dblkno;
-       caddr_t addr;
-       int flag, nbytes;
+physio(strat, bp, dev, rw, mincnt, uio)
+       int (*strat)(); 
+       register struct buf *bp;
        dev_t dev;
        dev_t dev;
-       unsigned pfcent;
+       int rw;
+       u_int (*mincnt)();
+       struct uio *uio;
 {
 {
-       register struct buf *bp;
-       register int c;
-       int p2dp;
-       register struct pte *dpte, *vpte;
-       int s;
-
-       s = spl6();
-       while (bswlist.av_forw == NULL) {
-               bswlist.b_flags |= B_WANTED;
-               sleep((caddr_t)&bswlist, PSWP+1);
-       }
-       bp = bswlist.av_forw;
-       bswlist.av_forw = bp->av_forw;
-       splx(s);
 
 
-       bp->b_flags = B_BUSY | B_PHYS | rdflg | flag;
-       if ((bp->b_flags & (B_DIRTY|B_PGIN)) == 0)
-               if (rdflg == B_READ)
-                       sum.v_pswpin += btoc(nbytes);
-               else
-                       sum.v_pswpout += btoc(nbytes);
-       bp->b_proc = p;
-       if (flag & B_DIRTY) {
-               p2dp = ((bp - swbuf) * CLSIZE) * KLMAX;
-               dpte = dptopte(&proc[2], p2dp);
-               vpte = vtopte(p, btop(addr));
-               for (c = 0; c < nbytes; c += NBPG) {
-                       if (vpte->pg_pfnum == 0 || vpte->pg_fod)
-                               panic("swap bad pte");
-                       *dpte++ = *vpte++;
-               }
-               bp->b_un.b_addr = (caddr_t)ctob(p2dp);
-       } else
-               bp->b_un.b_addr = addr;
-       while (nbytes > 0) {
-               c = imin(ctob(120), nbytes);
-               bp->b_bcount = c;
-               bp->b_blkno = dblkno;
-               bp->b_dev = dev;
-               if (flag & B_DIRTY) {
-                       swpf[bp - swbuf] = pfcent;
-                       swsize[bp - swbuf] = nbytes;
-               }
-#ifdef TRACE
-               trace(TR_SWAPIO, dev, bp->b_blkno);
-#endif
-               (*bdevsw[major(dev)].d_strategy)(bp);
-               if (flag & B_DIRTY) {
-                       if (c < nbytes)
-                               panic("big push");
-                       return;
-               }
-               s = spl6();
-               while((bp->b_flags&B_DONE)==0)
-                       sleep((caddr_t)bp, PSWP);
-               splx(s);
-               bp->b_un.b_addr += c;
-               bp->b_flags &= ~B_DONE;
-               if (bp->b_flags & B_ERROR) {
-                       if ((flag & (B_UAREA|B_PAGET)) || rdflg == B_WRITE)
-                               panic("hard IO err in swap");
-                       swkill(p, (char *)0);
-               }
-               nbytes -= c;
-               dblkno += btoc(c);
-       }
-       s = spl6();
-       bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
-       bp->av_forw = bswlist.av_forw;
-       bswlist.av_forw = bp;
-       if (bswlist.b_flags & B_WANTED) {
-               bswlist.b_flags &= ~B_WANTED;
-               wakeup((caddr_t)&bswlist);
-               wakeup((caddr_t)&proc[2]);
-       }
-       splx(s);
+       /*
+        * Body deleted.
+        */
+       return (EIO);
 }
 
 /*
 }
 
 /*
- * If rout == 0 then killed on swap error, else
- * rout is the name of the routine where we ran out of
- * swap space.
+ * Calculate the maximum size of I/O request that can be requested
+ * in a single operation. This limit is necessary to prevent a single
+ * process from being able to lock more than a fixed amount of memory
+ * in the kernel.
  */
  */
-swkill(p, rout)
-       struct proc *p;
-       char *rout;
+u_int
+minphys(bp)
+       struct buf *bp;
 {
 {
-       char *mesg;
 
 
-       printf("pid %d: ", p->p_pid);
-       if (rout)
-               printf(mesg = "killed due to no swap space\n");
-       else
-               printf(mesg = "killed on swap error\n");
-       uprintf("sorry, pid %d was %s", p->p_pid, mesg);
        /*
        /*
-        * To be sure no looping (e.g. in vmsched trying to
-        * swap out) mark process locked in core (as though
-        * done by user) after killing it so noone will try
-        * to swap it out.
+        * Body deleted.
         */
         */
-       psignal(p, SIGKILL);
-       p->p_flag |= SULOCK;
+       return;
 }
 
 /*
 }
 
 /*
- * Raw I/O. The arguments are
- *     The strategy routine for the device
- *     A buffer, which will always be a special buffer
- *       header owned exclusively by the device for this purpose
- *     The device number
- *     Read/write flag
- * Essentially all the work is computing physical addresses and
- * validating them.
- * If the user has the proper access privilidges, the process is
- * marked 'delayed unlock' and the pages involved in the I/O are
- * faulted and locked. After the completion of the I/O, the above pages
- * are unlocked.
+ * Do a read on a device for a user process.
  */
  */
-physio(strat, bp, dev, rw, mincnt, uio)
-       int (*strat)(); 
-       register struct buf *bp;
+rawread(dev, uio)
        dev_t dev;
        dev_t dev;
-       int rw;
-       unsigned (*mincnt)();
        struct uio *uio;
 {
        struct uio *uio;
 {
-       register int c;
-       struct uio auio;
-       register struct iovec *iov;
-       struct iovec aiov;
-       char *a;
-       int s, error = 0;
-
-       if (uio == 0) {
-               uio = &auio;
-               uio->uio_iov = &aiov;
-               uio->uio_iovcnt = 1;
-               uio->uio_offset = u.u_offset;
-               uio->uio_segflg = u.u_segflg;
-               iov = &aiov;
-               iov->iov_base = u.u_base;
-               iov->iov_len = u.u_count;
-               uio->uio_resid = iov->iov_len;
-       } else
-               iov = uio->uio_iov;
-nextiov:
-       if (uio->uio_iovcnt == 0) {
-               u.u_count = uio->uio_resid;
-               return (0);
-       }
-       if (useracc(iov->iov_base,iov->iov_len,rw==B_READ?B_WRITE:B_READ) == NULL) {
-               u.u_count = uio->uio_resid;
-               u.u_error = EFAULT;
-               return (EFAULT);
-       }
-       s = spl6();
-       while (bp->b_flags&B_BUSY) {
-               bp->b_flags |= B_WANTED;
-               sleep((caddr_t)bp, PRIBIO+1);
-       }
-       splx(s);
-       bp->b_error = 0;
-       bp->b_proc = u.u_procp;
-       bp->b_un.b_addr = iov->iov_base;
-       while (iov->iov_len > 0) {
-               bp->b_flags = B_BUSY | B_PHYS | rw;
-               bp->b_dev = dev;
-               bp->b_blkno = uio->uio_offset >> PGSHIFT;
-               bp->b_bcount = iov->iov_len;
-               (*mincnt)(bp);
-               c = bp->b_bcount;
-               u.u_procp->p_flag |= SPHYSIO;
-               vslock(a = bp->b_un.b_addr, c);
-               (*strat)(bp);
-               (void) spl6();
-               while ((bp->b_flags&B_DONE) == 0)
-                       sleep((caddr_t)bp, PRIBIO);
-               vsunlock(a, c, rw);
-               u.u_procp->p_flag &= ~SPHYSIO;
-               if (bp->b_flags&B_WANTED)
-                       wakeup((caddr_t)bp);
-               splx(s);
-               c -= bp->b_resid;
-               bp->b_un.b_addr += c;
-               iov->iov_len -= c;
-               uio->uio_resid -= c;
-               uio->uio_offset += c;
-               if (bp->b_flags&B_ERROR)
-                       break;
-       }
-       bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
-       error = geterror(bp);
-       if (error) {
-               u.u_error = error;
-               u.u_count = uio->uio_resid;
-               return (error);
-       }
-       uio->uio_iov++;
-       uio->uio_iovcnt--;
-       goto nextiov;
+       return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
+           dev, B_READ, minphys, uio));
 }
 
 }
 
-/*ARGSUSED*/
-unsigned
-minphys(bp)
-       struct buf *bp;
+/*
+ * Do a write on a device for a user process.
+ */
+rawwrite(dev, uio)
+       dev_t dev;
+       struct uio *uio;
 {
 {
-
-       if (bp->b_bcount > 63 * 1024)
-               bp->b_bcount = 63 * 1024;
+       return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
+           dev, B_WRITE, minphys, uio));
 }
 }
-