Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / kern / kern_shutdown.c
index 1f8b307..cea484e 100644 (file)
@@ -37,7 +37,7 @@
  *
  *     @(#)kern_shutdown.c     8.3 (Berkeley) 1/21/94
  * $FreeBSD: src/sys/kern/kern_shutdown.c,v 1.72.2.12 2002/02/21 19:15:10 dillon Exp $
- * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.26 2006/03/07 15:48:11 corecode Exp $
+ * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.36 2006/09/10 01:26:39 dillon Exp $
  */
 
 #include "opt_ddb.h"
@@ -136,12 +136,14 @@ globaldata_t panic_cpu_gd;                /* which cpu took the panic */
 
 static void boot (int) __dead2;
 static void dumpsys (void);
-static int setdumpdev (dev_t dev);
+static int setdumpdev (cdev_t dev);
 static void poweroff_wait (void *, int);
 static void print_uptime (void);
 static void shutdown_halt (void *junk, int howto);
 static void shutdown_panic (void *junk, int howto);
 static void shutdown_reset (void *junk, int howto);
+static int shutdown_busycount1(struct buf *bp, void *info);
+static int shutdown_busycount2(struct buf *bp, void *info);
 
 /* register various local shutdown events */
 static void 
@@ -161,7 +163,7 @@ SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL)
  * The system call that results in a reboot
  */
 int
-reboot(struct reboot_args *uap)
+sys_reboot(struct reboot_args *uap)
 {
        struct thread *td = curthread;
        int error;
@@ -185,7 +187,7 @@ shutdown_nice(int howto)
        
        /* Send a signal to init(8) and have it shutdown the world */
        if (initproc != NULL) {
-               psignal(initproc, SIGINT);
+               ksignal(initproc, SIGINT);
        } else {
                /* No init(8) running, so simply reboot */
                boot(RB_NOSYNC);
@@ -264,13 +266,12 @@ boot(int howto)
         * Now sync filesystems
         */
        if (!cold && (howto & RB_NOSYNC) == 0 && waittime < 0) {
-               struct buf *bp;
                int iter, nbusy, pbusy;
 
                waittime = 0;
                printf("\nsyncing disks... ");
 
-               sync(NULL);     /* YYY was sync(&proc0, NULL). why proc0 ? */
+               sys_sync(NULL); /* YYY was sync(&proc0, NULL). why proc0 ? */
 
                /*
                 * With soft updates, some buffers that are
@@ -278,17 +279,7 @@ boot(int howto)
                 * buffers are written.
                 */
                for (iter = pbusy = 0; iter < 20; iter++) {
-                       nbusy = 0;
-                       for (bp = &buf[nbuf]; --bp >= buf; ) {
-                               if ((bp->b_flags & B_INVAL) == 0 &&
-                                   BUF_REFCNT(bp) > 0) {
-                                       nbusy++;
-                               } else if ((bp->b_flags & (B_DELWRI | B_INVAL))
-                                               == B_DELWRI) {
-                                       /* bawrite(bp);*/
-                                       nbusy++;
-                               }
-                       }
+                       nbusy = scan_all_buffers(shutdown_busycount1, NULL);
                        if (nbusy == 0)
                                break;
                        printf("%d ", nbusy);
@@ -302,7 +293,7 @@ boot(int howto)
                         */
                        if (iter > 5 && bioops.io_sync)
                                (*bioops.io_sync)(NULL);
-                       sync(NULL); /* YYY was sync(&proc0, NULL). why proc0 ? */
+                       sys_sync(NULL); /* YYY was sync(&proc0, NULL). why proc0 ? */
                        tsleep(boot, 0, "shutdn", hz * iter / 20 + 1);
                }
                printf("\n");
@@ -310,28 +301,7 @@ boot(int howto)
                 * Count only busy local buffers to prevent forcing 
                 * a fsck if we're just a client of a wedged NFS server
                 */
-               nbusy = 0;
-               for (bp = &buf[nbuf]; --bp >= buf; ) {
-                       if (((bp->b_flags&B_INVAL) == 0 && BUF_REFCNT(bp)) ||
-                           ((bp->b_flags & (B_DELWRI|B_INVAL)) == B_DELWRI)) {
-                               /*
-                                * Only count buffers undergoing write I/O
-                                * on the related vnode.
-                                */
-                               if (bp->b_vp == NULL || 
-                                   bp->b_vp->v_track_write.bk_active == 0) {
-                                       continue;
-                               }
-                               nbusy++;
-#if defined(SHOW_BUSYBUFS) || defined(DIAGNOSTIC)
-                               printf(
-                           "%p %d: dev:?, flags:%08lx, blkno:%ld, lblkno:%ld\n",
-                                   bp, nbusy,
-                                   bp->b_flags, (long)bp->b_bio1.bio_blkno,
-                                   (long)bp->b_lblkno);
-#endif
-                       }
-               }
+               nbusy = scan_all_buffers(shutdown_busycount2, NULL);
                if (nbusy) {
                        /*
                         * Failed to sync all blocks. Indicate this and don't
@@ -371,6 +341,41 @@ boot(int howto)
        /* NOTREACHED */
 }
 
+static int
+shutdown_busycount1(struct buf *bp, void *info)
+{
+       if ((bp->b_flags & B_INVAL) == 0 && BUF_REFCNT(bp) > 0)
+               return(1);
+       if ((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI)
+               return (1);
+       return (0);
+}
+
+static int
+shutdown_busycount2(struct buf *bp, void *info)
+{
+       if (((bp->b_flags & B_INVAL) == 0 && BUF_REFCNT(bp)) ||
+           ((bp->b_flags & (B_DELWRI|B_INVAL)) == B_DELWRI)) {
+               /*
+                * Only count buffers undergoing write I/O
+                * on the related vnode.
+                */
+               if (bp->b_vp == NULL || 
+                   bp->b_vp->v_track_write.bk_active == 0) {
+                       return (0);
+               }
+#if defined(SHOW_BUSYBUFS) || defined(DIAGNOSTIC)
+               printf(
+           "%p dev:?, flags:%08x, loffset:%lld, doffset:%lld\n",
+                   bp, 
+                   bp->b_flags, bp->b_loffset,
+                   bp->b_bio2.bio_offset);
+#endif
+               return(1);
+       }
+       return(0);
+}
+
 /*
  * If the shutdown was a clean halt, behave accordingly.
  */
@@ -456,12 +461,12 @@ SYSCTL_INT(_machdep, OID_AUTO, do_dump, CTLFLAG_RW, &dodump, 0,
 
 static int
 setdumpdev(dev)
-       dev_t dev;
+       cdev_t dev;
 {
        int psize;
        long newdumplo;
 
-       if (dev == NODEV) {
+       if (dev == NOCDEV) {
                dumpdev = dev;
                return (0);
        }
@@ -487,17 +492,17 @@ dump_conf(dummy)
        void *dummy;
 {
        char *path;
-       dev_t dev;
+       cdev_t dev;
 
-       path = malloc(MNAMELEN, M_TEMP, M_WAITOK);
+       path = kmalloc(MNAMELEN, M_TEMP, M_WAITOK);
        if (TUNABLE_STR_FETCH("dumpdev", path, MNAMELEN) != 0) {
-               dev = getdiskbyname(path);
-               if (dev != NODEV)
+               dev = kgetdiskbyname(path);
+               if (dev != NOCDEV)
                        dumpdev = dev;
        }
-       free(path, M_TEMP);
+       kfree(path, M_TEMP);
        if (setdumpdev(dumpdev) != 0)
-               dumpdev = NODEV;
+               dumpdev = NOCDEV;
 }
 
 SYSINIT(dump_conf, SI_SUB_DUMP_CONF, SI_ORDER_FIRST, dump_conf, NULL)
@@ -516,7 +521,7 @@ sysctl_kern_dumpdev(SYSCTL_HANDLER_ARGS)
 }
 
 SYSCTL_PROC(_kern, KERN_DUMPDEV, dumpdev, CTLTYPE_OPAQUE|CTLFLAG_RW,
-       0, sizeof dumpdev, sysctl_kern_dumpdev, "T,dev_t", "");
+       0, sizeof dumpdev, sysctl_kern_dumpdev, "T,cdev_t", "");
 
 /*
  * Doadump comes here after turning off memory management and
@@ -536,7 +541,7 @@ dumpsys(void)
        }
        if (!dodump)
                return;
-       if (dumpdev == NODEV)
+       if (dumpdev == NOCDEV)
                return;
        dumpsize = Maxmem;
        printf("\ndumping to dev %s, offset %ld\n", devtoname(dumpdev), dumplo);