use new queue.h data structures
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 23 Aug 1994 01:20:11 +0000 (17:20 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Tue, 23 Aug 1994 01:20:11 +0000 (17:20 -0800)
SCCS-vsn: sys/kern/init_main.c 8.10
SCCS-vsn: sys/kern/kern_sysctl.c 8.5
SCCS-vsn: sys/kern/tty.c 8.12
SCCS-vsn: sys/kern/kern_sig.c 8.10
SCCS-vsn: sys/kern/kern_ktrace.c 8.3
SCCS-vsn: sys/kern/kern_resource.c 8.6
SCCS-vsn: sys/kern/kern_exit.c 8.8
SCCS-vsn: sys/kern/uipc_usrreq.c 8.5
SCCS-vsn: sys/kern/kern_proc.c 8.5
SCCS-vsn: sys/kern/kern_synch.c 8.7
SCCS-vsn: sys/kern/vfs_cache.c 8.3
SCCS-vsn: sys/kern/kern_fork.c 8.7
SCCS-vsn: sys/kern/kern_descrip.c 8.7

13 files changed:
usr/src/sys/kern/init_main.c
usr/src/sys/kern/kern_descrip.c
usr/src/sys/kern/kern_exit.c
usr/src/sys/kern/kern_fork.c
usr/src/sys/kern/kern_ktrace.c
usr/src/sys/kern/kern_proc.c
usr/src/sys/kern/kern_resource.c
usr/src/sys/kern/kern_sig.c
usr/src/sys/kern/kern_synch.c
usr/src/sys/kern/kern_sysctl.c
usr/src/sys/kern/tty.c
usr/src/sys/kern/uipc_usrreq.c
usr/src/sys/kern/vfs_cache.c

index e6fb607..525f3f7 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)init_main.c 8.9 (Berkeley) %G%
+ *     @(#)init_main.c 8.10 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -102,14 +102,20 @@ main(framep)
        kmeminit();
        cpu_startup();
 
        kmeminit();
        cpu_startup();
 
+       /*
+        * Initialize process and pgrp structures.
+        */
+       procinit();
+
        /*
         * Create process 0 (the swapper).
         */
        /*
         * Create process 0 (the swapper).
         */
-       allproc = (volatile struct proc *)p;
-       p->p_prev = (struct proc **)&allproc;
+       LIST_INSERT_HEAD(&allproc, p, p_list);
        p->p_pgrp = &pgrp0;
        p->p_pgrp = &pgrp0;
-       pgrphash[0] = &pgrp0;
-       pgrp0.pg_mem = p;
+       LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
+       LIST_INIT(&pgrp0.pg_members);
+       LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
+
        pgrp0.pg_session = &session0;
        session0.s_count = 1;
        session0.s_leader = p;
        pgrp0.pg_session = &session0;
        session0.s_count = 1;
        session0.s_leader = p;
@@ -164,10 +170,8 @@ main(framep)
        p->p_sigacts = &p->p_addr->u_sigacts;
 
        /*
        p->p_sigacts = &p->p_addr->u_sigacts;
 
        /*
-        * Initialize per uid information structure and charge
-        * root for one process.
+        * Charge root for one process.
         */
         */
-       usrinfoinit();
        (void)chgproccnt(0, 1);
 
        rqinit();
        (void)chgproccnt(0, 1);
 
        rqinit();
index d4cfa73..1a31016 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_descrip.c      8.6 (Berkeley) %G%
+ *     @(#)kern_descrip.c      8.7 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -32,8 +32,8 @@
 /*
  * Descriptor management.
  */
 /*
  * Descriptor management.
  */
-struct file *filehead; /* head of list of open files */
-int nfiles;            /* actual number of open files */
+struct filelist filehead;      /* head of list of open files */
+int nfiles;                    /* actual number of open files */
 
 /*
  * System calls on descriptors.
 
 /*
  * System calls on descriptors.
@@ -545,7 +545,7 @@ falloc(p, resultfp, resultfd)
        struct file **resultfp;
        int *resultfd;
 {
        struct file **resultfp;
        int *resultfd;
 {
-       register struct file *fp, *fq, **fpp;
+       register struct file *fp, *fq;
        int error, i;
 
        if (error = fdalloc(p, 0, &i))
        int error, i;
 
        if (error = fdalloc(p, 0, &i))
@@ -563,16 +563,12 @@ falloc(p, resultfp, resultfd)
        nfiles++;
        MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK);
        bzero(fp, sizeof(struct file));
        nfiles++;
        MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK);
        bzero(fp, sizeof(struct file));
-       if (fq = p->p_fd->fd_ofiles[0])
-               fpp = &fq->f_filef;
-       else
-               fpp = &filehead;
+       if (fq = p->p_fd->fd_ofiles[0]) {
+               LIST_INSERT_AFTER(fq, fp, f_list);
+       } else {
+               LIST_INSERT_HEAD(&filehead, fp, f_list);
+       }
        p->p_fd->fd_ofiles[i] = fp;
        p->p_fd->fd_ofiles[i] = fp;
-       if (fq = *fpp)
-               fq->f_fileb = &fp->f_filef;
-       fp->f_filef = fq;
-       fp->f_fileb = fpp;
-       *fpp = fp;
        fp->f_count = 1;
        fp->f_cred = p->p_ucred;
        crhold(fp->f_cred);
        fp->f_count = 1;
        fp->f_cred = p->p_ucred;
        crhold(fp->f_cred);
@@ -591,13 +587,9 @@ ffree(fp)
 {
        register struct file *fq;
 
 {
        register struct file *fq;
 
-       if (fq = fp->f_filef)
-               fq->f_fileb = fp->f_fileb;
-       *fp->f_fileb = fq;
+       LIST_REMOVE(fp, f_list);
        crfree(fp->f_cred);
 #ifdef DIAGNOSTIC
        crfree(fp->f_cred);
 #ifdef DIAGNOSTIC
-       fp->f_filef = NULL;
-       fp->f_fileb = NULL;
        fp->f_count = 0;
 #endif
        nfiles--;
        fp->f_count = 0;
 #endif
        nfiles--;
index 90ad991..d9f7032 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_exit.c 8.7 (Berkeley) %G%
+ *     @(#)kern_exit.c 8.8 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -165,34 +165,19 @@ exit1(p, rv)
         * Remove proc from allproc queue and pidhash chain.
         * Place onto zombproc.  Unlink from parent's child list.
         */
         * Remove proc from allproc queue and pidhash chain.
         * Place onto zombproc.  Unlink from parent's child list.
         */
-       if (*p->p_prev = p->p_next)
-               p->p_next->p_prev = p->p_prev;
-       if (p->p_next = zombproc)
-               p->p_next->p_prev = &p->p_next;
-       p->p_prev = &zombproc;
-       zombproc = p;
+       LIST_REMOVE(p, p_list);
+       LIST_INSERT_HEAD(&zombproc, p, p_list);
        p->p_stat = SZOMB;
 
        p->p_stat = SZOMB;
 
-       for (pp = &pidhash[PIDHASH(p->p_pid)]; *pp; pp = &(*pp)->p_hash)
-               if (*pp == p) {
-                       *pp = p->p_hash;
-                       goto done;
-               }
-       panic("exit");
-done:
+       LIST_REMOVE(p, p_hash);
 
 
-       if (p->p_cptr)          /* only need this if any child is S_ZOMB */
+       q = p->p_children.lh_first;
+       if (q)          /* only need this if any child is S_ZOMB */
                wakeup((caddr_t) initproc);
                wakeup((caddr_t) initproc);
-       for (q = p->p_cptr; q != NULL; q = nq) {
-               nq = q->p_osptr;
-               if (nq != NULL)
-                       nq->p_ysptr = NULL;
-               if (initproc->p_cptr)
-                       initproc->p_cptr->p_ysptr = q;
-               q->p_osptr = initproc->p_cptr;
-               q->p_ysptr = NULL;
-               initproc->p_cptr = q;
-
+       for (; q != 0; q = nq) {
+               nq = q->p_sibling.le_next;
+               LIST_REMOVE(q, p_sibling);
+               LIST_INSERT_HEAD(&initproc->p_children, q, p_sibling);
                q->p_pptr = initproc;
                /*
                 * Traced processes are killed
                q->p_pptr = initproc;
                /*
                 * Traced processes are killed
@@ -203,7 +188,6 @@ done:
                        psignal(q, SIGKILL);
                }
        }
                        psignal(q, SIGKILL);
                }
        }
-       p->p_cptr = NULL;
 
        /*
         * Save exit status and final rusage info, adding in child rusage
 
        /*
         * Save exit status and final rusage info, adding in child rusage
@@ -322,7 +306,7 @@ wait1(q, uap, retval)
 #endif
 loop:
        nfound = 0;
 #endif
 loop:
        nfound = 0;
-       for (p = q->p_cptr; p; p = p->p_osptr) {
+       for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
                if (uap->pid != WAIT_ANY &&
                    p->p_pid != uap->pid && p->p_pgid != -uap->pid)
                        continue;
                if (uap->pid != WAIT_ANY &&
                    p->p_pid != uap->pid && p->p_pgid != -uap->pid)
                        continue;
@@ -382,14 +366,8 @@ loop:
                         * Unlink it from its process group and free it.
                         */
                        leavepgrp(p);
                         * Unlink it from its process group and free it.
                         */
                        leavepgrp(p);
-                       if (*p->p_prev = p->p_next)     /* off zombproc */
-                               p->p_next->p_prev = p->p_prev;
-                       if (q = p->p_ysptr)
-                               q->p_osptr = p->p_osptr;
-                       if (q = p->p_osptr)
-                               q->p_ysptr = p->p_ysptr;
-                       if ((q = p->p_pptr)->p_cptr == p)
-                               q->p_cptr = p->p_osptr;
+                       LIST_REMOVE(p, p_list); /* off zombproc */
+                       LIST_REMOVE(p, p_sibling);
 
                        /*
                         * Give machine-dependent layer a chance
 
                        /*
                         * Give machine-dependent layer a chance
@@ -439,28 +417,11 @@ proc_reparent(child, parent)
        register struct proc *child;
        register struct proc *parent;
 {
        register struct proc *child;
        register struct proc *parent;
 {
-       register struct proc *o;
-       register struct proc *y;
 
        if (child->p_pptr == parent)
                return;
 
 
        if (child->p_pptr == parent)
                return;
 
-       /* fix up the child linkage for the old parent */
-       o = child->p_osptr;
-       y = child->p_ysptr;
-       if (y)
-               y->p_osptr = o;
-       if (o)
-               o->p_ysptr = y;
-       if (child->p_pptr->p_cptr == child)
-               child->p_pptr->p_cptr = o;
-
-       /* fix up child linkage for new parent */
-       o = parent->p_cptr;
-       if (o)
-               o->p_ysptr = child;
-       child->p_osptr = o;
-       child->p_ysptr = NULL;
-       parent->p_cptr = child;
+       LIST_REMOVE(child, p_sibling);
+       LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
        child->p_pptr = parent;
 }
        child->p_pptr = parent;
 }
index 724f982..af3252a 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_fork.c 8.6 (Berkeley) %G%
+ *     @(#)kern_fork.c 8.7 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -110,9 +110,9 @@ retry:
                 * is in use.  Remember the lowest pid that's greater
                 * than nextpid, so we can avoid checking for a while.
                 */
                 * is in use.  Remember the lowest pid that's greater
                 * than nextpid, so we can avoid checking for a while.
                 */
-               p2 = (struct proc *)allproc;
+               p2 = allproc.lh_first;
 again:
 again:
-               for (; p2 != NULL; p2 = p2->p_next) {
+               for (; p2 != 0; p2 = p2->p_list.le_next) {
                        while (p2->p_pid == nextpid ||
                            p2->p_pgrp->pg_id == nextpid) {
                                nextpid++;
                        while (p2->p_pid == nextpid ||
                            p2->p_pgrp->pg_id == nextpid) {
                                nextpid++;
@@ -127,43 +127,19 @@ again:
                }
                if (!doingzomb) {
                        doingzomb = 1;
                }
                if (!doingzomb) {
                        doingzomb = 1;
-                       p2 = zombproc;
+                       p2 = zombproc.lh_first;
                        goto again;
                }
        }
 
 
                        goto again;
                }
        }
 
 
-       /*
-        * Link onto allproc (this should probably be delayed).
-        * Heavy use of volatile here to prevent the compiler from
-        * rearranging code.  Yes, it *is* terribly ugly, but at least
-        * it works.
-        */
        nprocs++;
        p2 = newproc;
        nprocs++;
        p2 = newproc;
-#define        Vp2 ((volatile struct proc *)p2)
-       Vp2->p_stat = SIDL;                     /* protect against others */
-       Vp2->p_pid = nextpid;
-       /*
-        * This is really:
-        *      p2->p_next = allproc;
-        *      allproc->p_prev = &p2->p_next;
-        *      p2->p_prev = &allproc;
-        *      allproc = p2;
-        * The assignment via allproc is legal since it is never NULL.
-        */
-       *(volatile struct proc **)&Vp2->p_next = allproc;
-       *(volatile struct proc ***)&allproc->p_prev =
-           (volatile struct proc **)&Vp2->p_next;
-       *(volatile struct proc ***)&Vp2->p_prev = &allproc;
-       allproc = Vp2;
-#undef Vp2
+       p2->p_stat = SIDL;                      /* protect against others */
+       p2->p_pid = nextpid;
+       LIST_INSERT_HEAD(&allproc, p2, p_list);
        p2->p_forw = p2->p_back = NULL;         /* shouldn't be necessary */
        p2->p_forw = p2->p_back = NULL;         /* shouldn't be necessary */
-
-       /* Insert on the hash chain. */
-       hash = &pidhash[PIDHASH(p2->p_pid)];
-       p2->p_hash = *hash;
-       *hash = p2;
+       LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
 
        /*
         * Make a proc table entry for the new process.
 
        /*
         * Make a proc table entry for the new process.
@@ -212,13 +188,11 @@ again:
                p2->p_flag |= P_CONTROLT;
        if (isvfork)
                p2->p_flag |= P_PPWAIT;
                p2->p_flag |= P_CONTROLT;
        if (isvfork)
                p2->p_flag |= P_PPWAIT;
-       p2->p_pgrpnxt = p1->p_pgrpnxt;
-       p1->p_pgrpnxt = p2;
+       LIST_INSERT_AFTER(p1, p2, p_pglist);
        p2->p_pptr = p1;
        p2->p_pptr = p1;
-       p2->p_osptr = p1->p_cptr;
-       if (p1->p_cptr)
-               p1->p_cptr->p_ysptr = p2;
-       p1->p_cptr = p2;
+       LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
+       LIST_INIT(&p2->p_children);
+
 #ifdef KTRACE
        /*
         * Copy traceflag and tracefile if enabled.
 #ifdef KTRACE
        /*
         * Copy traceflag and tracefile if enabled.
index 43e9c39..e701e6a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_ktrace.c       8.2 (Berkeley) %G%
+ *     @(#)kern_ktrace.c       8.3 (Berkeley) %G%
  */
 
 #ifdef KTRACE
  */
 
 #ifdef KTRACE
@@ -233,7 +233,7 @@ ktrace(curp, uap, retval)
         * Clear all uses of the tracefile
         */
        if (ops == KTROP_CLEARFILE) {
         * Clear all uses of the tracefile
         */
        if (ops == KTROP_CLEARFILE) {
-               for (p = (struct proc *)allproc; p != NULL; p = p->p_next) {
+               for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
                        if (p->p_tracep == vp) {
                                if (ktrcanset(curp, p)) {
                                        p->p_tracep = NULL;
                        if (p->p_tracep == vp) {
                                if (ktrcanset(curp, p)) {
                                        p->p_tracep = NULL;
@@ -265,7 +265,7 @@ ktrace(curp, uap, retval)
                        error = ESRCH;
                        goto done;
                }
                        error = ESRCH;
                        goto done;
                }
-               for (p = pg->pg_mem; p != NULL; p = p->p_pgrpnxt)
+               for (p = pg->pg_members.lh_first; p != 0; p = p->p_pglist.le_next)
                        if (descend)
                                ret |= ktrsetchildren(curp, p, ops, facs, vp);
                        else 
                        if (descend)
                                ret |= ktrsetchildren(curp, p, ops, facs, vp);
                        else 
@@ -347,20 +347,16 @@ ktrsetchildren(curp, top, ops, facs, vp)
                 * otherwise do any siblings, and if done with this level,
                 * follow back up the tree (but not past top).
                 */
                 * otherwise do any siblings, and if done with this level,
                 * follow back up the tree (but not past top).
                 */
-               if (p->p_cptr)
-                       p = p->p_cptr;
-               else if (p == top)
-                       return (ret);
-               else if (p->p_osptr)
-                       p = p->p_osptr;
+               if (p->p_children.lh_first)
+                       p = p->p_children.lh_first;
                else for (;;) {
                else for (;;) {
-                       p = p->p_pptr;
                        if (p == top)
                                return (ret);
                        if (p == top)
                                return (ret);
-                       if (p->p_osptr) {
-                               p = p->p_osptr;
+                       if (p->p_sibling.le_next) {
+                               p = p->p_sibling.le_next;
                                break;
                        }
                                break;
                        }
+                       p = p->p_pptr;
                }
        }
        /*NOTREACHED*/
                }
        }
        /*NOTREACHED*/
@@ -402,7 +398,7 @@ ktrwrite(vp, kth)
         */
        log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n",
            error);
         */
        log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n",
            error);
-       for (p = (struct proc *)allproc; p != NULL; p = p->p_next) {
+       for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
                if (p->p_tracep == vp) {
                        p->p_tracep = NULL;
                        p->p_traceflag = 0;
                if (p->p_tracep == vp) {
                        p->p_tracep = NULL;
                        p->p_traceflag = 0;
index c5e8975..8c27ddf 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_proc.c 8.4 (Berkeley) %G%
+ *     @(#)kern_proc.c 8.5 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
  * Structure associated with user cacheing.
  */
 struct uidinfo {
  * Structure associated with user cacheing.
  */
 struct uidinfo {
-       struct  uidinfo *ui_next;
-       struct  uidinfo **ui_prev;
+       LIST_ENTRY(uidinfo) ui_hash;
        uid_t   ui_uid;
        long    ui_proccnt;
        uid_t   ui_uid;
        long    ui_proccnt;
-} **uihashtbl;
-u_long uihash;         /* size of hash table - 1 */
-#define        UIHASH(uid)     ((uid) & uihash)
+};
+#define        UIHASH(uid)     (&uihashtbl[(uid) & uihash])
+LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
+u_long uihash;         /* size of hash table - 1 */
 
 /*
 
 /*
- * Allocate a hash table.
+ * Other process lists
  */
  */
-usrinfoinit()
+struct pidhashhead *pidhashtbl;
+u_long pidhash;
+struct pgrphashhead *pgrphashtbl;
+u_long pgrphash;
+struct proclist allproc;
+struct proclist zombproc;
+
+/*
+ * Initialize global process hashing structures.
+ */
+procinit()
 {
 
 {
 
+       LIST_INIT(&allproc);
+       LIST_INIT(&zombproc);
+       pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
+       pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash);
        uihashtbl = hashinit(maxproc / 16, M_PROC, &uihash);
 }
 
        uihashtbl = hashinit(maxproc / 16, M_PROC, &uihash);
 }
 
@@ -53,10 +67,11 @@ chgproccnt(uid, diff)
        uid_t   uid;
        int     diff;
 {
        uid_t   uid;
        int     diff;
 {
-       register struct uidinfo **uipp, *uip, *uiq;
+       register struct uidinfo *uip;
+       register struct uihashhead *uipp;
 
 
-       uipp = &uihashtbl[UIHASH(uid)];
-       for (uip = *uipp; uip; uip = uip->ui_next)
+       uipp = UIHASH(uid);
+       for (uip = uipp->lh_first; uip != 0; uip = uip->ui_hash.le_next)
                if (uip->ui_uid == uid)
                        break;
        if (uip) {
                if (uip->ui_uid == uid)
                        break;
        if (uip) {
@@ -65,9 +80,7 @@ chgproccnt(uid, diff)
                        return (uip->ui_proccnt);
                if (uip->ui_proccnt < 0)
                        panic("chgproccnt: procs < 0");
                        return (uip->ui_proccnt);
                if (uip->ui_proccnt < 0)
                        panic("chgproccnt: procs < 0");
-               if (uiq = uip->ui_next)
-                       uiq->ui_prev = uip->ui_prev;
-               *uip->ui_prev = uiq;
+               LIST_REMOVE(uip, ui_hash);
                FREE(uip, M_PROC);
                return (0);
        }
                FREE(uip, M_PROC);
                return (0);
        }
@@ -77,11 +90,7 @@ chgproccnt(uid, diff)
                panic("chgproccnt: lost user");
        }
        MALLOC(uip, struct uidinfo *, sizeof(*uip), M_PROC, M_WAITOK);
                panic("chgproccnt: lost user");
        }
        MALLOC(uip, struct uidinfo *, sizeof(*uip), M_PROC, M_WAITOK);
-       if (uiq = *uipp)
-               uiq->ui_prev = &uip->ui_next;
-       uip->ui_next = uiq;
-       uip->ui_prev = uipp;
-       *uipp = uip;
+       LIST_INSERT_HEAD(uipp, uip, ui_hash);
        uip->ui_uid = uid;
        uip->ui_proccnt = diff;
        return (diff);
        uip->ui_uid = uid;
        uip->ui_proccnt = diff;
        return (diff);
@@ -109,7 +118,7 @@ pfind(pid)
 {
        register struct proc *p;
 
 {
        register struct proc *p;
 
-       for (p = pidhash[PIDHASH(pid)]; p != NULL; p = p->p_hash)
+       for (p = PIDHASH(pid)->lh_first; p != 0; p = p->p_hash.le_next)
                if (p->p_pid == pid)
                        return (p);
        return (NULL);
                if (p->p_pid == pid)
                        return (p);
        return (NULL);
@@ -124,8 +133,8 @@ pgfind(pgid)
 {
        register struct pgrp *pgrp;
 
 {
        register struct pgrp *pgrp;
 
-       for (pgrp = pgrphash[PIDHASH(pgid)];
-           pgrp != NULL; pgrp = pgrp->pg_hforw)
+       for (pgrp = PGRPHASH(pgid)->lh_first; pgrp != 0;
+            pgrp = pgrp->pg_hash.le_next)
                if (pgrp->pg_id == pgid)
                        return (pgrp);
        return (NULL);
                if (pgrp->pg_id == pgid)
                        return (pgrp);
        return (NULL);
@@ -140,7 +149,6 @@ enterpgrp(p, pgid, mksess)
        int mksess;
 {
        register struct pgrp *pgrp = pgfind(pgid);
        int mksess;
 {
        register struct pgrp *pgrp = pgfind(pgid);
-       register struct proc **pp;
        int n;
 
 #ifdef DIAGNOSTIC
        int n;
 
 #ifdef DIAGNOSTIC
@@ -160,7 +168,7 @@ enterpgrp(p, pgid, mksess)
                        panic("enterpgrp: new pgrp and pid != pgid");
 #endif
                MALLOC(pgrp, struct pgrp *, sizeof(struct pgrp), M_PGRP,
                        panic("enterpgrp: new pgrp and pid != pgid");
 #endif
                MALLOC(pgrp, struct pgrp *, sizeof(struct pgrp), M_PGRP,
-                      M_WAITOK);
+                   M_WAITOK);
                if ((np = pfind(savepid)) == NULL || np != p)
                        return (ESRCH);
                if (mksess) {
                if ((np = pfind(savepid)) == NULL || np != p)
                        return (ESRCH);
                if (mksess) {
@@ -170,7 +178,7 @@ enterpgrp(p, pgid, mksess)
                         * new session
                         */
                        MALLOC(sess, struct session *, sizeof(struct session),
                         * new session
                         */
                        MALLOC(sess, struct session *, sizeof(struct session),
-                               M_SESSION, M_WAITOK);
+                           M_SESSION, M_WAITOK);
                        sess->s_leader = p;
                        sess->s_count = 1;
                        sess->s_ttyvp = NULL;
                        sess->s_leader = p;
                        sess->s_count = 1;
                        sess->s_ttyvp = NULL;
@@ -188,10 +196,9 @@ enterpgrp(p, pgid, mksess)
                        pgrp->pg_session->s_count++;
                }
                pgrp->pg_id = pgid;
                        pgrp->pg_session->s_count++;
                }
                pgrp->pg_id = pgid;
-               pgrp->pg_hforw = pgrphash[n = PIDHASH(pgid)];
-               pgrphash[n] = pgrp;
+               LIST_INIT(&pgrp->pg_members);
+               LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
                pgrp->pg_jobc = 0;
                pgrp->pg_jobc = 0;
-               pgrp->pg_mem = NULL;
        } else if (pgrp == p->p_pgrp)
                return (0);
 
        } else if (pgrp == p->p_pgrp)
                return (0);
 
@@ -203,30 +210,11 @@ enterpgrp(p, pgid, mksess)
        fixjobc(p, pgrp, 1);
        fixjobc(p, p->p_pgrp, 0);
 
        fixjobc(p, pgrp, 1);
        fixjobc(p, p->p_pgrp, 0);
 
-       /*
-        * unlink p from old process group
-        */
-       for (pp = &p->p_pgrp->pg_mem; *pp; pp = &(*pp)->p_pgrpnxt) {
-               if (*pp == p) {
-                       *pp = p->p_pgrpnxt;
-                       break;
-               }
-       }
-#ifdef DIAGNOSTIC
-       if (pp == NULL)
-               panic("enterpgrp: can't find p on old pgrp");
-#endif
-       /*
-        * delete old if empty
-        */
-       if (p->p_pgrp->pg_mem == 0)
+       LIST_REMOVE(p, p_pglist);
+       if (p->p_pgrp->pg_members.lh_first == 0)
                pgdelete(p->p_pgrp);
                pgdelete(p->p_pgrp);
-       /*
-        * link into new one
-        */
        p->p_pgrp = pgrp;
        p->p_pgrp = pgrp;
-       p->p_pgrpnxt = pgrp->pg_mem;
-       pgrp->pg_mem = p;
+       LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
        return (0);
 }
 
        return (0);
 }
 
@@ -236,19 +224,9 @@ enterpgrp(p, pgid, mksess)
 leavepgrp(p)
        register struct proc *p;
 {
 leavepgrp(p)
        register struct proc *p;
 {
-       register struct proc **pp = &p->p_pgrp->pg_mem;
 
 
-       for (; *pp; pp = &(*pp)->p_pgrpnxt) {
-               if (*pp == p) {
-                       *pp = p->p_pgrpnxt;
-                       break;
-               }
-       }
-#ifdef DIAGNOSTIC
-       if (pp == NULL)
-               panic("leavepgrp: can't find p in pgrp");
-#endif
-       if (!p->p_pgrp->pg_mem)
+       LIST_REMOVE(p, p_pglist);
+       if (p->p_pgrp->pg_members.lh_first == 0)
                pgdelete(p->p_pgrp);
        p->p_pgrp = 0;
        return (0);
                pgdelete(p->p_pgrp);
        p->p_pgrp = 0;
        return (0);
@@ -260,21 +238,11 @@ leavepgrp(p)
 pgdelete(pgrp)
        register struct pgrp *pgrp;
 {
 pgdelete(pgrp)
        register struct pgrp *pgrp;
 {
-       register struct pgrp **pgp = &pgrphash[PIDHASH(pgrp->pg_id)];
 
        if (pgrp->pg_session->s_ttyp != NULL && 
            pgrp->pg_session->s_ttyp->t_pgrp == pgrp)
                pgrp->pg_session->s_ttyp->t_pgrp = NULL;
 
        if (pgrp->pg_session->s_ttyp != NULL && 
            pgrp->pg_session->s_ttyp->t_pgrp == pgrp)
                pgrp->pg_session->s_ttyp->t_pgrp = NULL;
-       for (; *pgp; pgp = &(*pgp)->pg_hforw) {
-               if (*pgp == pgrp) {
-                       *pgp = pgrp->pg_hforw;
-                       break;
-               }
-       }
-#ifdef DIAGNOSTIC
-       if (pgp == NULL)
-               panic("pgdelete: can't find pgrp on hash chain");
-#endif
+       LIST_REMOVE(pgrp, pg_hash);
        if (--pgrp->pg_session->s_count == 0)
                FREE(pgrp->pg_session, M_SESSION);
        FREE(pgrp, M_PGRP);
        if (--pgrp->pg_session->s_count == 0)
                FREE(pgrp->pg_session, M_SESSION);
        FREE(pgrp, M_PGRP);
@@ -316,7 +284,7 @@ fixjobc(p, pgrp, entering)
         * their process groups; if so, adjust counts for children's
         * process groups.
         */
         * their process groups; if so, adjust counts for children's
         * process groups.
         */
-       for (p = p->p_cptr; p; p = p->p_osptr)
+       for (p = p->p_children.lh_first; p != 0; p = p->p_sibling.le_next)
                if ((hispgrp = p->p_pgrp) != pgrp &&
                    hispgrp->pg_session == mysession &&
                    p->p_stat != SZOMB)
                if ((hispgrp = p->p_pgrp) != pgrp &&
                    hispgrp->pg_session == mysession &&
                    p->p_stat != SZOMB)
@@ -337,9 +305,10 @@ orphanpg(pg)
 {
        register struct proc *p;
 
 {
        register struct proc *p;
 
-       for (p = pg->pg_mem; p; p = p->p_pgrpnxt) {
+       for (p = pg->pg_members.lh_first; p != 0; p = p->p_pglist.le_next) {
                if (p->p_stat == SSTOP) {
                if (p->p_stat == SSTOP) {
-                       for (p = pg->pg_mem; p; p = p->p_pgrpnxt) {
+                       for (p = pg->pg_members.lh_first; p != 0;
+                           p = p->p_pglist.le_next) {
                                psignal(p, SIGHUP);
                                psignal(p, SIGCONT);
                        }
                                psignal(p, SIGHUP);
                                psignal(p, SIGCONT);
                        }
@@ -348,28 +317,28 @@ orphanpg(pg)
        }
 }
 
        }
 }
 
-#ifdef debug
-/* DEBUG */
+#ifdef DEBUG
 pgrpdump()
 {
        register struct pgrp *pgrp;
        register struct proc *p;
        register i;
 
 pgrpdump()
 {
        register struct pgrp *pgrp;
        register struct proc *p;
        register i;
 
-       for (i=0; i<PIDHSZ; i++) {
-               if (pgrphash[i]) {
-                 printf("\tindx %d\n", i);
-                 for (pgrp=pgrphash[i]; pgrp; pgrp=pgrp->pg_hforw) {
-                   printf("\tpgrp %x, pgid %d, sess %x, sesscnt %d, mem %x\n",
-                       pgrp, pgrp->pg_id, pgrp->pg_session,
-                       pgrp->pg_session->s_count, pgrp->pg_mem);
-                   for (p=pgrp->pg_mem; p; p=p->p_pgrpnxt) {
-                       printf("\t\tpid %d addr %x pgrp %x\n", 
-                               p->p_pid, p, p->p_pgrp);
-                   }
-                 }
-
+       for (i = 0; i <= pgrphash; i++) {
+               if (pgrp = pgrphashtbl[i].lh_first) {
+                       printf("\tindx %d\n", i);
+                       for (; pgrp != 0; pgrp = pgrp->pg_hash.le_next) {
+                               printf("\tpgrp %x, pgid %d, sess %x, sesscnt %d, mem %x\n",
+                                   pgrp, pgrp->pg_id, pgrp->pg_session,
+                                   pgrp->pg_session->s_count,
+                                   pgrp->pg_members.lh_first);
+                               for (p = pgrp->pg_members.lh_first; p != 0;
+                                   p = p->p_pglist.le_next) {
+                                       printf("\t\tpid %d addr %x pgrp %x\n", 
+                                           p->p_pid, p, p->p_pgrp);
+                               }
+                       }
                }
        }
 }
                }
        }
 }
-#endif /* debug */
+#endif /* DEBUG */
index 9fff730..1ac71be 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_resource.c     8.5 (Berkeley) %G%
+ *     @(#)kern_resource.c     8.6 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -56,21 +56,19 @@ getpriority(curp, uap, retval)
                        pg = curp->p_pgrp;
                else if ((pg = pgfind(uap->who)) == NULL)
                        break;
                        pg = curp->p_pgrp;
                else if ((pg = pgfind(uap->who)) == NULL)
                        break;
-               for (p = pg->pg_mem; p != NULL; p = p->p_pgrpnxt) {
+               for (p = pg->pg_members.lh_first; p != 0;
+                    p = p->p_pglist.le_next)
                        if (p->p_nice < low)
                                low = p->p_nice;
                        if (p->p_nice < low)
                                low = p->p_nice;
-               }
                break;
        }
 
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = curp->p_ucred->cr_uid;
                break;
        }
 
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = curp->p_ucred->cr_uid;
-               for (p = (struct proc *)allproc; p != NULL; p = p->p_next) {
-                       if (p->p_ucred->cr_uid == uap->who &&
-                           p->p_nice < low)
+               for (p = allproc.lh_first; p != 0; p = p->p_list.le_next)
+                       if (p->p_ucred->cr_uid == uap->who && p->p_nice < low)
                                low = p->p_nice;
                                low = p->p_nice;
-               }
                break;
 
        default:
                break;
 
        default:
@@ -116,7 +114,7 @@ setpriority(curp, uap, retval)
                        pg = curp->p_pgrp;
                else if ((pg = pgfind(uap->who)) == NULL)
                        break;
                        pg = curp->p_pgrp;
                else if ((pg = pgfind(uap->who)) == NULL)
                        break;
-               for (p = pg->pg_mem; p != NULL; p = p->p_pgrpnxt) {
+               for (p = pg->pg_members.lh_first; p != 0; p = p->p_pglist.le_next) {
                        error = donice(curp, p, uap->prio);
                        found++;
                }
                        error = donice(curp, p, uap->prio);
                        found++;
                }
@@ -126,7 +124,7 @@ setpriority(curp, uap, retval)
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = curp->p_ucred->cr_uid;
        case PRIO_USER:
                if (uap->who == 0)
                        uap->who = curp->p_ucred->cr_uid;
-               for (p = (struct proc *)allproc; p != NULL; p = p->p_next)
+               for (p = allproc.lh_first; p != 0; p = p->p_list.le_next)
                        if (p->p_ucred->cr_uid == uap->who) {
                                error = donice(curp, p, uap->prio);
                                found++;
                        if (p->p_ucred->cr_uid == uap->who) {
                                error = donice(curp, p, uap->prio);
                                found++;
index 7f28505..18a2bd6 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_sig.c  8.9 (Berkeley) %G%
+ *     @(#)kern_sig.c  8.10 (Berkeley) %G%
  */
 
 #define        SIGPROP         /* include signal properties table */
  */
 
 #define        SIGPROP         /* include signal properties table */
@@ -525,7 +525,7 @@ killpg1(cp, signum, pgid, all)
                /* 
                 * broadcast 
                 */
                /* 
                 * broadcast 
                 */
-               for (p = (struct proc *)allproc; p != NULL; p = p->p_next) {
+               for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
                        if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || 
                            p == cp || !CANSIGNAL(cp, pc, p, signum))
                                continue;
                        if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || 
                            p == cp || !CANSIGNAL(cp, pc, p, signum))
                                continue;
@@ -544,7 +544,8 @@ killpg1(cp, signum, pgid, all)
                        if (pgrp == NULL)
                                return (ESRCH);
                }
                        if (pgrp == NULL)
                                return (ESRCH);
                }
-               for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
+               for (p = pgrp->pg_members.lh_first; p != 0;
+                    p = p->p_pglist.le_next) {
                        if (p->p_pid <= 1 || p->p_flag & P_SYSTEM ||
                            p->p_stat == SZOMB ||
                            !CANSIGNAL(cp, pc, p, signum))
                        if (p->p_pid <= 1 || p->p_flag & P_SYSTEM ||
                            p->p_stat == SZOMB ||
                            !CANSIGNAL(cp, pc, p, signum))
@@ -582,7 +583,8 @@ pgsignal(pgrp, signum, checkctty)
        register struct proc *p;
 
        if (pgrp)
        register struct proc *p;
 
        if (pgrp)
-               for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt)
+               for (p = pgrp->pg_members.lh_first; p != 0;
+                    p = p->p_pglist.le_next)
                        if (checkctty == 0 || p->p_flag & P_CONTROLT)
                                psignal(p, signum);
 }
                        if (checkctty == 0 || p->p_flag & P_CONTROLT)
                                psignal(p, signum);
 }
index 0315547..bdf5338 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_synch.c        8.6 (Berkeley) %G%
+ *     @(#)kern_synch.c        8.7 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -141,7 +141,7 @@ schedcpu(arg)
        register unsigned int newcpu;
 
        wakeup((caddr_t)&lbolt);
        register unsigned int newcpu;
 
        wakeup((caddr_t)&lbolt);
-       for (p = (struct proc *)allproc; p != NULL; p = p->p_next) {
+       for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
                /*
                 * Increment time in/out of memory and sleep time
                 * (if sleeping).  We ignore overflow; with 16-bit int's
                /*
                 * Increment time in/out of memory and sleep time
                 * (if sleeping).  We ignore overflow; with 16-bit int's
index 6734531..d49d6a9 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_sysctl.c       8.4 (Berkeley) %G%
+ *     @(#)kern_sysctl.c       8.5 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -508,7 +508,7 @@ sysctl_file(where, sizep)
        /*
         * followed by an array of file structures
         */
        /*
         * followed by an array of file structures
         */
-       for (fp = filehead; fp != NULL; fp = fp->f_filef) {
+       for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next) {
                if (buflen < sizeof(struct file)) {
                        *sizep = where - start;
                        return (ENOMEM);
                if (buflen < sizeof(struct file)) {
                        *sizep = where - start;
                        return (ENOMEM);
@@ -543,10 +543,10 @@ sysctl_doproc(name, namelen, where, sizep)
 
        if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
                return (EINVAL);
 
        if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
                return (EINVAL);
-       p = (struct proc *)allproc;
+       p = allproc.lh_first;
        doingzomb = 0;
 again:
        doingzomb = 0;
 again:
-       for (; p != NULL; p = p->p_next) {
+       for (; p != 0; p = p->p_list.le_next) {
                /*
                 * Skip embryonic processes.
                 */
                /*
                 * Skip embryonic processes.
                 */
@@ -601,7 +601,7 @@ again:
                needed += sizeof(struct kinfo_proc);
        }
        if (doingzomb == 0) {
                needed += sizeof(struct kinfo_proc);
        }
        if (doingzomb == 0) {
-               p = zombproc;
+               p = zombproc.lh_first;
                doingzomb++;
                goto again;
        }
                doingzomb++;
                goto again;
        }
index e4264b9..e772764 100644 (file)
@@ -9,7 +9,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)tty.c       8.11 (Berkeley) %G%
+ *     @(#)tty.c       8.12 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -1609,11 +1609,11 @@ ttyinfo(tp)
                ttyprintf(tp, "not a controlling terminal\n");
        else if (tp->t_pgrp == NULL)
                ttyprintf(tp, "no foreground process group\n");
                ttyprintf(tp, "not a controlling terminal\n");
        else if (tp->t_pgrp == NULL)
                ttyprintf(tp, "no foreground process group\n");
-       else if ((p = tp->t_pgrp->pg_mem) == NULL)
+       else if ((p = tp->t_pgrp->pg_members.lh_first) == 0)
                ttyprintf(tp, "empty foreground process group\n");
        else {
                /* Pick interesting process. */
                ttyprintf(tp, "empty foreground process group\n");
        else {
                /* Pick interesting process. */
-               for (pick = NULL; p != NULL; p = p->p_pgrpnxt)
+               for (pick = NULL; p != 0; p = p->p_pglist.le_next)
                        if (proc_compare(pick, p))
                                pick = p;
 
                        if (proc_compare(pick, p))
                                pick = p;
 
index 26221f3..4ca6d9d 100644 (file)
@@ -2,7 +2,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)uipc_usrreq.c       8.4 (Berkeley) %G%
+ *     @(#)uipc_usrreq.c       8.5 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -638,10 +638,10 @@ unp_gc()
                return;
        unp_gcing = 1;
        unp_defer = 0;
                return;
        unp_gcing = 1;
        unp_defer = 0;
-       for (fp = filehead; fp; fp = fp->f_filef)
+       for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next)
                fp->f_flag &= ~(FMARK|FDEFER);
        do {
                fp->f_flag &= ~(FMARK|FDEFER);
        do {
-               for (fp = filehead; fp; fp = fp->f_filef) {
+               for (fp = filehead.lh_first; fp != 0; fp = fp->f_list.le_next) {
                        if (fp->f_count == 0)
                                continue;
                        if (fp->f_flag & FDEFER) {
                        if (fp->f_count == 0)
                                continue;
                        if (fp->f_flag & FDEFER) {
@@ -719,8 +719,9 @@ unp_gc()
         * 91/09/19, bsy@cs.cmu.edu
         */
        extra_ref = malloc(nfiles * sizeof(struct file *), M_FILE, M_WAITOK);
         * 91/09/19, bsy@cs.cmu.edu
         */
        extra_ref = malloc(nfiles * sizeof(struct file *), M_FILE, M_WAITOK);
-       for (nunref = 0, fp = filehead, fpp = extra_ref; fp; fp = nextfp) {
-               nextfp = fp->f_filef;
+       for (nunref = 0, fp = filehead.lh_first, fpp = extra_ref; fp != 0;
+           fp = nextfp) {
+               nextfp = fp->f_list.le_next;
                if (fp->f_count == 0)
                        continue;
                if (fp->f_count == fp->f_msgcount && !(fp->f_flag & FMARK)) {
                if (fp->f_count == 0)
                        continue;
                if (fp->f_count == fp->f_msgcount && !(fp->f_flag & FMARK)) {
index c652c7a..6e50b8b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_cache.c 8.2 (Berkeley) %G%
+ *     @(#)vfs_cache.c 8.3 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
 /*
  * Structures associated with name cacheing.
  */
 /*
  * Structures associated with name cacheing.
  */
-struct namecache **nchashtbl;
+LIST_HEAD(nchashhead, namecache) *nchashtbl;
 u_long nchash;                         /* size of hash table - 1 */
 long   numcache;                       /* number of cache entries allocated */
 u_long nchash;                         /* size of hash table - 1 */
 long   numcache;                       /* number of cache entries allocated */
-struct namecache *nchhead, **nchtail;  /* LRU chain pointers */
+TAILQ_HEAD(, namecache) nclruhead;             /* LRU chain */
 struct nchstats nchstats;              /* cache effectiveness statistics */
 
 int doingcache = 1;                    /* 1 => enable the cache */
 struct nchstats nchstats;              /* cache effectiveness statistics */
 
 int doingcache = 1;                    /* 1 => enable the cache */
@@ -65,7 +65,8 @@ cache_lookup(dvp, vpp, cnp)
        struct vnode **vpp;
        struct componentname *cnp;
 {
        struct vnode **vpp;
        struct componentname *cnp;
 {
-       register struct namecache *ncp, *ncq, **ncpp;
+       register struct namecache *ncp;
+       register struct nchashhead *ncpp;
 
        if (!doingcache) {
                cnp->cn_flags &= ~MAKEENTRY;
 
        if (!doingcache) {
                cnp->cn_flags &= ~MAKEENTRY;
@@ -77,18 +78,18 @@ cache_lookup(dvp, vpp, cnp)
                return (0);
        }
        ncpp = &nchashtbl[cnp->cn_hash & nchash];
                return (0);
        }
        ncpp = &nchashtbl[cnp->cn_hash & nchash];
-       for (ncp = *ncpp; ncp; ncp = ncp->nc_forw) {
+       for (ncp = ncpp->lh_first; ncp != 0; ncp = ncp->nc_hash.le_next) {
                if (ncp->nc_dvp == dvp &&
                    ncp->nc_dvpid == dvp->v_id &&
                    ncp->nc_nlen == cnp->cn_namelen &&
                    !bcmp(ncp->nc_name, cnp->cn_nameptr, (u_int)ncp->nc_nlen))
                        break;
        }
                if (ncp->nc_dvp == dvp &&
                    ncp->nc_dvpid == dvp->v_id &&
                    ncp->nc_nlen == cnp->cn_namelen &&
                    !bcmp(ncp->nc_name, cnp->cn_nameptr, (u_int)ncp->nc_nlen))
                        break;
        }
-       if (ncp == NULL) {
+       if (ncp == 0) {
                nchstats.ncs_miss++;
                return (0);
        }
                nchstats.ncs_miss++;
                return (0);
        }
-       if (!(cnp->cn_flags & MAKEENTRY)) {
+       if ((cnp->cn_flags & MAKEENTRY) == 0) {
                nchstats.ncs_badhits++;
        } else if (ncp->nc_vp == NULL) {
                if (cnp->cn_nameiop != CREATE) {
                nchstats.ncs_badhits++;
        } else if (ncp->nc_vp == NULL) {
                if (cnp->cn_nameiop != CREATE) {
@@ -97,15 +98,9 @@ cache_lookup(dvp, vpp, cnp)
                         * Move this slot to end of LRU chain,
                         * if not already there.
                         */
                         * Move this slot to end of LRU chain,
                         * if not already there.
                         */
-                       if (ncp->nc_nxt) {
-                               /* remove from LRU chain */
-                               *ncp->nc_prev = ncp->nc_nxt;
-                               ncp->nc_nxt->nc_prev = ncp->nc_prev;
-                               /* and replace at end of it */
-                               ncp->nc_nxt = NULL;
-                               ncp->nc_prev = nchtail;
-                               *nchtail = ncp;
-                               nchtail = &ncp->nc_nxt;
+                       if (ncp->nc_lru.tqe_next != 0) {
+                               TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
+                               TAILQ_INSERT_TAIL(&nclruhead, ncp, nc_lru);
                        }
                        return (ENOENT);
                }
                        }
                        return (ENOENT);
                }
@@ -116,15 +111,9 @@ cache_lookup(dvp, vpp, cnp)
                /*
                 * move this slot to end of LRU chain, if not already there
                 */
                /*
                 * move this slot to end of LRU chain, if not already there
                 */
-               if (ncp->nc_nxt) {
-                       /* remove from LRU chain */
-                       *ncp->nc_prev = ncp->nc_nxt;
-                       ncp->nc_nxt->nc_prev = ncp->nc_prev;
-                       /* and replace at end of it */
-                       ncp->nc_nxt = NULL;
-                       ncp->nc_prev = nchtail;
-                       *nchtail = ncp;
-                       nchtail = &ncp->nc_nxt;
+               if (ncp->nc_lru.tqe_next != 0) {
+                       TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
+                       TAILQ_INSERT_TAIL(&nclruhead, ncp, nc_lru);
                }
                *vpp = ncp->nc_vp;
                return (-1);
                }
                *vpp = ncp->nc_vp;
                return (-1);
@@ -135,27 +124,10 @@ cache_lookup(dvp, vpp, cnp)
         * the cache entry is invalid, or otherwise don't
         * want cache entry to exist.
         */
         * the cache entry is invalid, or otherwise don't
         * want cache entry to exist.
         */
-       /* remove from LRU chain */
-       if (ncq = ncp->nc_nxt)
-               ncq->nc_prev = ncp->nc_prev;
-       else
-               nchtail = ncp->nc_prev;
-       *ncp->nc_prev = ncq;
-       /* remove from hash chain */
-       if (ncq = ncp->nc_forw)
-               ncq->nc_back = ncp->nc_back;
-       *ncp->nc_back = ncq;
-       /* and make a dummy hash chain */
-       ncp->nc_forw = NULL;
-       ncp->nc_back = NULL;
-       /* insert at head of LRU list (first to grab) */
-       if (ncq = nchhead)
-               ncq->nc_prev = &ncp->nc_nxt;
-       else
-               nchtail = &ncp->nc_nxt;
-       nchhead = ncp;
-       ncp->nc_nxt = ncq;
-       ncp->nc_prev = &nchhead;
+       TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
+       LIST_REMOVE(ncp, nc_hash);
+       ncp->nc_hash.le_prev = 0;
+       TAILQ_INSERT_HEAD(&nclruhead, ncp, nc_lru);
        return (0);
 }
 
        return (0);
 }
 
@@ -167,7 +139,8 @@ cache_enter(dvp, vp, cnp)
        struct vnode *vp;
        struct componentname *cnp;
 {
        struct vnode *vp;
        struct componentname *cnp;
 {
-       register struct namecache *ncp, *ncq, **ncpp;
+       register struct namecache *ncp;
+       register struct nchashhead *ncpp;
 
 #ifdef DIAGNOSTIC
        if (cnp->cn_namelen > NCHNAMLEN)
 
 #ifdef DIAGNOSTIC
        if (cnp->cn_namelen > NCHNAMLEN)
@@ -183,20 +156,11 @@ cache_enter(dvp, vp, cnp)
                        malloc((u_long)sizeof *ncp, M_CACHE, M_WAITOK);
                bzero((char *)ncp, sizeof *ncp);
                numcache++;
                        malloc((u_long)sizeof *ncp, M_CACHE, M_WAITOK);
                bzero((char *)ncp, sizeof *ncp);
                numcache++;
-       } else if (ncp = nchhead) {
-               /* remove from lru chain */
-               if (ncq = ncp->nc_nxt)
-                       ncq->nc_prev = ncp->nc_prev;
-               else
-                       nchtail = ncp->nc_prev;
-               *ncp->nc_prev = ncq;
-               /* remove from old hash chain, if on one */
-               if (ncp->nc_back) {
-                       if (ncq = ncp->nc_forw)
-                               ncq->nc_back = ncp->nc_back;
-                       *ncp->nc_back = ncq;
-                       ncp->nc_forw = NULL;
-                       ncp->nc_back = NULL;
+       } else if (ncp = nclruhead.tqh_first) {
+               TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
+               if (ncp->nc_hash.le_prev != 0) {
+                       LIST_REMOVE(ncp, nc_hash);
+                       ncp->nc_hash.le_prev = 0;
                }
        } else
                return;
                }
        } else
                return;
@@ -211,18 +175,9 @@ cache_enter(dvp, vp, cnp)
        ncp->nc_dvpid = dvp->v_id;
        ncp->nc_nlen = cnp->cn_namelen;
        bcopy(cnp->cn_nameptr, ncp->nc_name, (unsigned)ncp->nc_nlen);
        ncp->nc_dvpid = dvp->v_id;
        ncp->nc_nlen = cnp->cn_namelen;
        bcopy(cnp->cn_nameptr, ncp->nc_name, (unsigned)ncp->nc_nlen);
-       /* link at end of lru chain */
-       ncp->nc_nxt = NULL;
-       ncp->nc_prev = nchtail;
-       *nchtail = ncp;
-       nchtail = &ncp->nc_nxt;
-       /* and insert on hash chain */
+       TAILQ_INSERT_TAIL(&nclruhead, ncp, nc_lru);
        ncpp = &nchashtbl[cnp->cn_hash & nchash];
        ncpp = &nchashtbl[cnp->cn_hash & nchash];
-       if (ncq = *ncpp)
-               ncq->nc_back = &ncp->nc_forw;
-       ncp->nc_forw = ncq;
-       ncp->nc_back = ncpp;
-       *ncpp = ncp;
+       LIST_INSERT_HEAD(ncpp, ncp, nc_hash);
 }
 
 /*
 }
 
 /*
@@ -231,7 +186,7 @@ cache_enter(dvp, vp, cnp)
 nchinit()
 {
 
 nchinit()
 {
 
-       nchtail = &nchhead;
+       TAILQ_INIT(&nclruhead);
        nchashtbl = hashinit(desiredvnodes, M_CACHE, &nchash);
 }
 
        nchashtbl = hashinit(desiredvnodes, M_CACHE, &nchash);
 }
 
@@ -242,13 +197,14 @@ nchinit()
 cache_purge(vp)
        struct vnode *vp;
 {
 cache_purge(vp)
        struct vnode *vp;
 {
-       struct namecache *ncp, **ncpp;
+       struct namecache *ncp;
+       struct nchashhead *ncpp;
 
        vp->v_id = ++nextvnodeid;
        if (nextvnodeid != 0)
                return;
        for (ncpp = &nchashtbl[nchash]; ncpp >= nchashtbl; ncpp--) {
 
        vp->v_id = ++nextvnodeid;
        if (nextvnodeid != 0)
                return;
        for (ncpp = &nchashtbl[nchash]; ncpp >= nchashtbl; ncpp--) {
-               for (ncp = *ncpp; ncp; ncp = ncp->nc_forw) {
+               for (ncp = ncpp->lh_first; ncp != 0; ncp = ncp->nc_hash.le_next) {
                        ncp->nc_vpid = 0;
                        ncp->nc_dvpid = 0;
                }
                        ncp->nc_vpid = 0;
                        ncp->nc_dvpid = 0;
                }
@@ -269,36 +225,21 @@ cache_purgevfs(mp)
 {
        register struct namecache *ncp, *nxtcp;
 
 {
        register struct namecache *ncp, *nxtcp;
 
-       for (ncp = nchhead; ncp; ncp = nxtcp) {
+       for (ncp = nclruhead.tqh_first; ncp != 0; ncp = nxtcp) {
                if (ncp->nc_dvp == NULL || ncp->nc_dvp->v_mount != mp) {
                if (ncp->nc_dvp == NULL || ncp->nc_dvp->v_mount != mp) {
-                       nxtcp = ncp->nc_nxt;
+                       nxtcp = ncp->nc_lru.tqe_next;
                        continue;
                }
                /* free the resources we had */
                ncp->nc_vp = NULL;
                ncp->nc_dvp = NULL;
                        continue;
                }
                /* free the resources we had */
                ncp->nc_vp = NULL;
                ncp->nc_dvp = NULL;
-               /* remove from old hash chain, if on one */
-               if (ncp->nc_back) {
-                       if (nxtcp = ncp->nc_forw)
-                               nxtcp->nc_back = ncp->nc_back;
-                       *ncp->nc_back = nxtcp;
-                       ncp->nc_forw = NULL;
-                       ncp->nc_back = NULL;
+               TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
+               if (ncp->nc_hash.le_prev != 0) {
+                       LIST_REMOVE(ncp, nc_hash);
+                       ncp->nc_hash.le_prev = 0;
                }
                }
-               /* delete this entry from LRU chain */
-               if (nxtcp = ncp->nc_nxt)
-                       nxtcp->nc_prev = ncp->nc_prev;
-               else
-                       nchtail = ncp->nc_prev;
-               *ncp->nc_prev = nxtcp;
                /* cause rescan of list, it may have altered */
                /* cause rescan of list, it may have altered */
-               /* also put the now-free entry at head of LRU */
-               if (nxtcp = nchhead)
-                       nxtcp->nc_prev = &ncp->nc_nxt;
-               else
-                       nchtail = &ncp->nc_nxt;
-               nchhead = ncp;
-               ncp->nc_nxt = nxtcp;
-               ncp->nc_prev = &nchhead;
+               nxtcp = nclruhead.tqh_first;
+               TAILQ_INSERT_HEAD(&nclruhead, ncp, nc_lru);
        }
 }
        }
 }