attempting to bind() an already bound UNIX domain socket returns EINVAL (kre)
[unix-history] / usr / src / sys / kern / kern_physio.c
index 7375a2a..fd5a092 100644 (file)
@@ -1,18 +1,25 @@
-/*     kern_physio.c   4.37    82/12/17        */
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)kern_physio.c       6.7 (Berkeley) %G%
+ */
 
 #include "../machine/pte.h"
 
 
 #include "../machine/pte.h"
 
-#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/vm.h"
-#include "../h/trace.h"
-#include "../h/uio.h"
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "buf.h"
+#include "conf.h"
+#include "proc.h"
+#include "seg.h"
+#include "vm.h"
+#include "trace.h"
+#include "map.h"
+#include "uio.h"
 
 /*
  * Swap IO headers -
 
 /*
  * Swap IO headers -
@@ -25,8 +32,6 @@
  * in a list of cleaned pages to be processed by the pageout daemon.
  */
 struct buf *swbuf;
  * in a list of cleaned pages to be processed by the pageout daemon.
  */
 struct buf *swbuf;
-short  *swsize;                /* CAN WE JUST USE B_BCOUNT? */
-int    *swpf;
 
 /*
  * swap I/O -
 
 /*
  * swap I/O -
@@ -53,6 +58,7 @@ swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
        int p2dp;
        register struct pte *dpte, *vpte;
        int s;
        int p2dp;
        register struct pte *dpte, *vpte;
        int s;
+       extern swdone();
 
        s = spl6();
        while (bswlist.av_forw == NULL) {
 
        s = spl6();
        while (bswlist.av_forw == NULL) {
@@ -79,7 +85,10 @@ swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
                                panic("swap bad pte");
                        *dpte++ = *vpte++;
                }
                                panic("swap bad pte");
                        *dpte++ = *vpte++;
                }
-               bp->b_un.b_addr = (caddr_t)ctob(p2dp);
+               bp->b_un.b_addr = (caddr_t)ctob(dptov(&proc[2], p2dp));
+               bp->b_flags |= B_CALL;
+               bp->b_iodone = swdone;
+               bp->b_pfcent = pfcent;
        } else
                bp->b_un.b_addr = addr;
        while (nbytes > 0) {
        } else
                bp->b_un.b_addr = addr;
        while (nbytes > 0) {
@@ -88,10 +97,6 @@ swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
                c = bp->b_bcount;
                bp->b_blkno = dblkno;
                bp->b_dev = dev;
                c = bp->b_bcount;
                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
 #ifdef TRACE
                trace(TR_SWAPIO, dev, bp->b_blkno);
 #endif
@@ -106,10 +111,10 @@ swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
                if (bp->b_flags & B_ERROR) {
                        if ((flag & (B_UAREA|B_PAGET)) || rdflg == B_WRITE)
                                panic("hard IO err in swap");
                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);
+                       swkill(p, "swap: read error from swap device");
                }
                nbytes -= c;
                }
                nbytes -= c;
-               dblkno += c / DEV_BSIZE;
+               dblkno += btodb(c);
        }
        s = spl6();
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
        }
        s = spl6();
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_PAGET|B_UAREA|B_DIRTY);
@@ -123,6 +128,27 @@ swap(p, dblkno, addr, nbytes, rdflg, flag, dev, pfcent)
        splx(s);
 }
 
        splx(s);
 }
 
+/*
+ * Put a buffer on the clean list after I/O is done.
+ * Called from biodone.
+ */
+swdone(bp)
+       register struct buf *bp;
+{
+       register int s;
+
+       if (bp->b_flags & B_ERROR)
+               panic("IO err in push");
+       s = spl6();
+       bp->av_forw = bclnlist;
+       cnt.v_pgout++;
+       cnt.v_pgpgout += bp->b_bcount / NBPG;
+       bclnlist = bp;
+       if (bswlist.b_flags & B_WANTED)
+               wakeup((caddr_t)&proc[2]);
+       splx(s);
+}
+
 /*
  * If rout == 0 then killed on swap error, else
  * rout is the name of the routine where we ran out of
 /*
  * If rout == 0 then killed on swap error, else
  * rout is the name of the routine where we ran out of
@@ -132,14 +158,9 @@ swkill(p, rout)
        struct proc *p;
        char *rout;
 {
        struct proc *p;
        char *rout;
 {
-       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);
+       printf("pid %d: %s\n", p->p_pid, rout);
+       uprintf("sorry, pid %d was killed in %s\n", p->p_pid, rout);
        /*
         * To be sure no looping (e.g. in vmsched trying to
         * swap out) mark process locked in core (as though
        /*
         * To be sure no looping (e.g. in vmsched trying to
         * swap out) mark process locked in core (as though
@@ -172,7 +193,7 @@ physio(strat, bp, dev, rw, mincnt, uio)
        unsigned (*mincnt)();
        struct uio *uio;
 {
        unsigned (*mincnt)();
        struct uio *uio;
 {
-       register struct iovec *iov = uio->uio_iov;
+       register struct iovec *iov;
        register int c;
        char *a;
        int s, error = 0;
        register int c;
        char *a;
        int s, error = 0;
@@ -180,6 +201,7 @@ physio(strat, bp, dev, rw, mincnt, uio)
 nextiov:
        if (uio->uio_iovcnt == 0)
                return (0);
 nextiov:
        if (uio->uio_iovcnt == 0)
                return (0);
+       iov = uio->uio_iov;
        if (useracc(iov->iov_base,(u_int)iov->iov_len,rw==B_READ?B_WRITE:B_READ) == NULL)
                return (EFAULT);
        s = spl6();
        if (useracc(iov->iov_base,(u_int)iov->iov_len,rw==B_READ?B_WRITE:B_READ) == NULL)
                return (EFAULT);
        s = spl6();
@@ -194,7 +216,7 @@ nextiov:
        while (iov->iov_len > 0) {
                bp->b_flags = B_BUSY | B_PHYS | rw;
                bp->b_dev = dev;
        while (iov->iov_len > 0) {
                bp->b_flags = B_BUSY | B_PHYS | rw;
                bp->b_dev = dev;
-               bp->b_blkno = uio->uio_offset / DEV_BSIZE;
+               bp->b_blkno = btodb(uio->uio_offset);
                bp->b_bcount = iov->iov_len;
                (*mincnt)(bp);
                c = bp->b_bcount;
                bp->b_bcount = iov->iov_len;
                (*mincnt)(bp);
                c = bp->b_bcount;
@@ -213,7 +235,7 @@ nextiov:
                uio->uio_resid -= c;
                uio->uio_offset += c;
                /* temp kludge for tape drives */
                uio->uio_resid -= c;
                uio->uio_offset += c;
                /* temp kludge for tape drives */
-               if (bp->b_resid || bp->b_flags&B_ERROR)
+               if (bp->b_resid || (bp->b_flags&B_ERROR))
                        break;
        }
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
                        break;
        }
        bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
@@ -226,12 +248,13 @@ nextiov:
        goto nextiov;
 }
 
        goto nextiov;
 }
 
+#define        MAXPHYS (63 * 1024)
+
 unsigned
 minphys(bp)
        struct buf *bp;
 {
 
 unsigned
 minphys(bp)
        struct buf *bp;
 {
 
-       if (bp->b_bcount > 63 * 1024)
-               bp->b_bcount = 63 * 1024;
+       if (bp->b_bcount > MAXPHYS)
+               bp->b_bcount = MAXPHYS;
 }
 }
-