Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 - tidy up debugging



details:   https://anonhg.NetBSD.org/src/rev/6ec8f3e6c7b2
branches:  trunk
changeset: 328389:6ec8f3e6c7b2
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Apr 02 02:14:08 2014 +0000

description:
- tidy up debugging

diffstat:

 sys/arch/x86/x86/x86_autoconf.c |  157 +++++++++++++++++++++------------------
 1 files changed, 86 insertions(+), 71 deletions(-)

diffs (truncated from 306 to 300 lines):

diff -r dbf91b5ce304 -r 6ec8f3e6c7b2 sys/arch/x86/x86/x86_autoconf.c
--- a/sys/arch/x86/x86/x86_autoconf.c   Wed Apr 02 01:22:11 2014 +0000
+++ b/sys/arch/x86/x86/x86_autoconf.c   Wed Apr 02 02:14:08 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_autoconf.c,v 1.68 2013/05/16 19:06:45 christos Exp $       */
+/*     $NetBSD: x86_autoconf.c,v 1.69 2014/04/02 02:14:08 christos Exp $       */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.68 2013/05/16 19:06:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.69 2014/04/02 02:14:08 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -64,6 +64,12 @@
 struct disklist *x86_alldisks;
 int x86_ndisks;
 
+#ifdef DEBUG_GEOM
+#define DPRINTF(a) printf a
+#else
+#define DPRINTF(a)
+#endif
+
 static int
 is_valid_disk(device_t dv)
 {
@@ -124,71 +130,60 @@
                x86_alldisks->dl_biosdisks[i].bi_cyl = big->disk[i].cyl;
                x86_alldisks->dl_biosdisks[i].bi_lbasecs = big->disk[i].totsec;
                x86_alldisks->dl_biosdisks[i].bi_flags = big->disk[i].flags;
-#ifdef GEOM_DEBUG
-#ifdef notyet
-               printf("disk %x: flags %x, interface %x, device %llx\n",
-                      big->disk[i].dev, big->disk[i].flags,
-                      big->disk[i].interface_path, big->disk[i].device_path);
+               DPRINTF(("%s: disk %x: flags %x",
+                   __func__, big->disk[i].dev, big->disk[i].flags));
+#ifdef BIOSDISK_EXTINFO_V3
+               DPRINTF((", interface %x, device %llx",
+                   big->disk[i].interface_path, big->disk[i].device_path));
 #endif
-#endif
+               DPRINTF(("\n"));
        }
 
        /* XXX Code duplication from findroot(). */
        n = -1;
        for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
             dv = deviter_next(&di)) {
-               if (device_class(dv) != DV_DISK)
+               if (!is_valid_disk(dv))
                        continue;
-#ifdef GEOM_DEBUG
-               printf("matchbiosdisks: trying to match (%s) %s\n",
-                   device_xname(dv), device_cfdata(dv)->cf_name);
-#endif
-               if (is_valid_disk(dv)) {
-                       n++;
-                       snprintf(x86_alldisks->dl_nativedisks[n].ni_devname,
-                           sizeof(x86_alldisks->dl_nativedisks[n].ni_devname),
-                           "%s", device_xname(dv));
+               DPRINTF(("%s: trying to match (%s) %s: ", __func__,
+                   device_xname(dv), device_cfdata(dv)->cf_name));
+               n++;
+               snprintf(x86_alldisks->dl_nativedisks[n].ni_devname,
+                   sizeof(x86_alldisks->dl_nativedisks[n].ni_devname),
+                   "%s", device_xname(dv));
+
+               if ((tv = opendisk(dv)) == NULL) {
+                       DPRINTF(("cannot open\n"));
+                       continue;
+               }
 
-                       if ((tv = opendisk(dv)) == NULL)
-                               continue;
+               error = vn_rdwr(UIO_READ, tv, mbr, DEV_BSIZE, 0, UIO_SYSSPACE,
+                   0, NOCRED, NULL, NULL);
+               VOP_CLOSE(tv, FREAD, NOCRED);
+               vput(tv);
+               if (error) {
+                       DPRINTF(("MBR read failure %d\n", error));
+                       continue;
+               }
 
-                       error = vn_rdwr(UIO_READ, tv, mbr, DEV_BSIZE, 0,
-                           UIO_SYSSPACE, 0, NOCRED, NULL, NULL);
-                       VOP_CLOSE(tv, FREAD, NOCRED);
-                       vput(tv);
-                       if (error) {
-#ifdef GEOM_DEBUG
-                               printf("matchbiosdisks: %s: MBR read failure\n",
-                                   device_xname(dv));
-#endif
+               for (ck = i = 0; i < DEV_BSIZE; i++)
+                       ck += mbr[i];
+               for (m = i = 0; i < numbig; i++) {
+                       be = &big->disk[i];
+                       if (be->flags & BI_GEOM_INVALID)
                                continue;
+                       DPRINTF(("matched with %d dev ck %x bios ck %x\n",
+                           i, ck, be->cksum));
+                       if (be->cksum == ck && memcmp(&mbr[MBR_PART_OFFSET],
+                           be->mbrparts, MBR_PART_COUNT
+                           * sizeof(struct mbr_partition)) == 0) {
+                               DPRINTF(("%s: matched BIOS disk %x with %s\n",
+                                   __func__, be->dev, device_xname(dv)));
+                               x86_alldisks->dl_nativedisks[n].
+                                   ni_biosmatches[m++] = i;
                        }
-
-                       for (ck = i = 0; i < DEV_BSIZE; i++)
-                               ck += mbr[i];
-                       for (m = i = 0; i < numbig; i++) {
-                               be = &big->disk[i];
-#ifdef GEOM_DEBUG
-                               printf("match %s with %d "
-                                   "dev ck %x bios ck %x\n", device_xname(dv), i,
-                                   ck, be->cksum);
-#endif
-                               if (be->flags & BI_GEOM_INVALID)
-                                       continue;
-                               if (be->cksum == ck &&
-                                   memcmp(&mbr[MBR_PART_OFFSET], be->mbrparts,
-                                       MBR_PART_COUNT *
-                                         sizeof(struct mbr_partition)) == 0) {
-#ifdef GEOM_DEBUG
-                                       printf("matched BIOS disk %x with %s\n",
-                                           be->dev, device_xname(dv));
-#endif
-                                       x86_alldisks->dl_nativedisks[n].
-                                           ni_biosmatches[m++] = i;
-                               }
-                       }
-                       x86_alldisks->dl_nativedisks[n].ni_nmatches = m;
                }
+               x86_alldisks->dl_nativedisks[n].ni_nmatches = m;
        }
        deviter_release(&di);
 }
@@ -212,11 +207,16 @@
        /*
         * If the boot loader didn't specify the sector, abort.
         */
-       if (biw->matchblk == -1)
-               return (0);
+       if (biw->matchblk == -1) {
+               DPRINTF(("%s: no sector specified for %s\n", __func__,
+                       device_xname(dv)));
+               return 0;
+       }
 
-       if ((tmpvn = opendisk(dv)) == NULL)
+       if ((tmpvn = opendisk(dv)) == NULL) {
+               DPRINTF(("%s: can't open %s\n", __func__, device_xname(dv)));
                return 0;
+       }
 
        MD5Init(&ctx);
        for (blk = biw->matchblk, nblks = biw->matchnblks;
@@ -225,8 +225,9 @@
                    sizeof(bf), blk * DEV_BSIZE, UIO_SYSSPACE,
                    0, NOCRED, NULL, NULL);
                if (error) {
-                       printf("findroot: unable to read block %" PRId64 " "
-                           "of dev %s (%d)\n", blk, device_xname(dv), error);
+                       printf("%s: unable to read block %" PRId64 " "
+                           "of dev %s (%d)\n", __func__,
+                           blk, device_xname(dv), error);
                        goto closeout;
                }
                MD5Update(&ctx, bf, sizeof(bf));
@@ -235,11 +236,12 @@
 
        /* Compare with the provided hash. */
        found = memcmp(biw->matchhash, hash, sizeof(hash)) == 0;
+       DPRINTF(("%s: %s found=%d\n", __func__, device_xname(dv), found));
 
  closeout:
        VOP_CLOSE(tmpvn, FREAD, NOCRED);
        vput(tmpvn);
-       return (found);
+       return found;
 }
 
 /*
@@ -254,19 +256,25 @@
        struct disklabel label;
        int found = 0;
 
-       if (device_is_a(dv, "dk"))
+       if (device_is_a(dv, "dk")) {
+               DPRINTF(("%s: not dk %s\n", __func__, device_xname(dv)));
                return 0;
+       }
 
        /*
         * A disklabel is required here.  The boot loader doesn't refuse
         * to boot from a disk without a label, but this is normally not
         * wanted.
         */
-       if (bid->labelsector == -1)
-               return (0);
+       if (bid->labelsector == -1) {
+               DPRINTF(("%s: no label %s\n", __func__, device_xname(dv)));
+               return 0;
+       }
        
-       if ((tmpvn = opendisk(dv)) == NULL)
+       if ((tmpvn = opendisk(dv)) == NULL) {
+               DPRINTF(("%s: can't open %s\n", __func__, device_xname(dv)));
                return 0;
+       }
 
        error = VOP_IOCTL(tmpvn, DIOCGDINFO, &label, FREAD, NOCRED);
        if (error) {
@@ -274,7 +282,7 @@
                 * XXX Can't happen -- open() would have errored out
                 * or faked one up.
                 */
-               printf("findroot: can't get label for dev %s (%d)\n",
+               printf("%s: can't get label for dev %s (%d)\n", __func__,
                    device_xname(dv), error);
                goto closeout;
        }
@@ -285,6 +293,7 @@
            strncmp(label.d_packname, bid->label.packname, 16) == 0)
                found = 1;
 
+       DPRINTF(("%s: %s found=%d\n", __func__, device_xname(dv), found));
  closeout:
        VOP_CLOSE(tmpvn, FREAD, NOCRED);
        vput(tmpvn);
@@ -316,7 +325,7 @@
                 * information cannot be present at the same time, so give
                 * up.
                 */
-               printf("findroot: netboot interface not found.\n");
+               printf("%s: netboot interface not found.\n", __func__);
                return;
        }
 
@@ -341,6 +350,8 @@
                                break;
                        }
                }
+               DPRINTF(("%s: BTINFO_ROOTDEVICE %s\n", __func__,
+                   booted_device ? device_xname(booted_device) : "not found"));
                deviter_release(&di);
                if (dv != NULL)
                        return;
@@ -360,9 +371,6 @@
                for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
                     dv != NULL;
                     dv = deviter_next(&di)) {
-                       if (device_class(dv) != DV_DISK)
-                               continue;
-
                        if (is_valid_disk(dv)) {
                                /*
                                 * Don't trust BIOS device numbers, try
@@ -391,6 +399,8 @@
                }
                deviter_release(&di);
 
+               DPRINTF(("%s: BTINFO_BOOTWEDGE %s\n", __func__,
+                   booted_device ? device_xname(booted_device) : "not found"));
                if (booted_nblks)
                        return;
        }
@@ -406,10 +416,10 @@
                for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
                     dv != NULL;
                     dv = deviter_next(&di)) {
-                       if (device_class(dv) != DV_DISK)
                                continue;
 
-                       if (device_is_a(dv, "fd")) {
+                       if (device_is_a(dv, "fd") &&
+                           device_class(dv) == DV_DISK) {
                                /*
                                 * Assume the configured unit number matches
                                 * the BIOS device number.  (This is the old
@@ -450,6 +460,8 @@
                }
                deviter_release(&di);
 
+               DPRINTF(("%s: BTINFO_BOOTDISK %s\n", __func__,
+                   booted_device ? device_xname(booted_device) : "not found"));
                if (booted_device)
                        return;
 
@@ -489,6 +501,9 @@
                                }
                        }
                        deviter_release(&di);



Home | Main Index | Thread Index | Old Index