Module Name:    src
Committed By:   riz
Date:           Thu Jul  5 18:12:49 UTC 2012

Modified Files:
        src/sys/arch/sparc64/sparc64 [netbsd-6]: autoconf.c
        src/sys/arch/x86/x86 [netbsd-6]: x86_autoconf.c
        src/sys/arch/xen/x86 [netbsd-6]: autoconf.c
        src/sys/arch/zaurus/zaurus [netbsd-6]: autoconf.c
        src/sys/dev [netbsd-6]: vnd.c
        src/sys/dev/dkwedge [netbsd-6]: dk.c dkwedge_bsdlabel.c
        src/sys/kern [netbsd-6]: init_main.c kern_subr.c
        src/sys/sys [netbsd-6]: device.h disk.h

Log Message:
Pull up following revision(s) (requested by mlelstv in ticket #402):
        sys/dev/vnd.c: revision 1.221
        sys/kern/init_main.c: revision 1.443
        sys/kern/init_main.c: revision 1.444
        sys/dev/dkwedge/dk.c: revision 1.64
        sys/arch/x86/x86/x86_autoconf.c: revision 1.63
        sys/arch/sparc64/sparc64/autoconf.c: revision 1.187
        sys/sys/device.h: revision 1.141
        sys/dev/dkwedge/dkwedge_bsdlabel.c: revision 1.17
        sys/kern/kern_subr.c: revision 1.213
        sys/arch/zaurus/zaurus/autoconf.c: revision 1.11
        sys/arch/xen/x86/autoconf.c: revision 1.14
        sys/sys/disk.h: revision 1.57
Use the label's packname to create wedge names instead of the classic
device names. Fall back to classic device names when the label has an
empty name or the default name 'fictitious'.
autodiscover wedges
Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for x86, xen, sparc64.
Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for zaurus.
Do not try to find the wedge we booted from if opendisk(booted_device)
failed.


To generate a diff of this commit:
cvs rdiff -u -r1.185.2.1 -r1.185.2.2 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.62 -r1.62.8.1 src/sys/arch/x86/x86/x86_autoconf.c
cvs rdiff -u -r1.13 -r1.13.18.1 src/sys/arch/xen/x86/autoconf.c
cvs rdiff -u -r1.10 -r1.10.10.1 src/sys/arch/zaurus/zaurus/autoconf.c
cvs rdiff -u -r1.219.8.1 -r1.219.8.2 src/sys/dev/vnd.c
cvs rdiff -u -r1.62 -r1.62.8.1 src/sys/dev/dkwedge/dk.c
cvs rdiff -u -r1.16 -r1.16.18.1 src/sys/dev/dkwedge/dkwedge_bsdlabel.c
cvs rdiff -u -r1.441 -r1.441.2.1 src/sys/kern/init_main.c
cvs rdiff -u -r1.212 -r1.212.8.1 src/sys/kern/kern_subr.c
cvs rdiff -u -r1.140 -r1.140.6.1 src/sys/sys/device.h
cvs rdiff -u -r1.56 -r1.56.2.1 src/sys/sys/disk.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc64/sparc64/autoconf.c
diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.185.2.1 src/sys/arch/sparc64/sparc64/autoconf.c:1.185.2.2
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.185.2.1	Tue Jun  5 16:22:24 2012
+++ src/sys/arch/sparc64/sparc64/autoconf.c	Thu Jul  5 18:12:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.185.2.1 2012/06/05 16:22:24 jdc Exp $ */
+/*	$NetBSD: autoconf.c,v 1.185.2.2 2012/07/05 18:12:48 riz Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.185.2.1 2012/06/05 16:22:24 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.185.2.2 2012/07/05 18:12:48 riz Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -508,10 +508,7 @@ cpu_rootconf(void)
 		return;
 	}
 
-	if (config_handle_wedges(booted_device, booted_partition) == 0)
-		setroot(booted_wedge, 0);
-	else
-		setroot(booted_device, booted_partition);
+	setroot(booted_device, booted_partition);
 }
 
 char *

Index: src/sys/arch/x86/x86/x86_autoconf.c
diff -u src/sys/arch/x86/x86/x86_autoconf.c:1.62 src/sys/arch/x86/x86/x86_autoconf.c:1.62.8.1
--- src/sys/arch/x86/x86/x86_autoconf.c:1.62	Tue Oct 18 23:43:36 2011
+++ src/sys/arch/x86/x86/x86_autoconf.c	Thu Jul  5 18:12:47 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_autoconf.c,v 1.62 2011/10/18 23:43:36 dyoung Exp $	*/
+/*	$NetBSD: x86_autoconf.c,v 1.62.8.1 2012/07/05 18:12:47 riz 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.62 2011/10/18 23:43:36 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.62.8.1 2012/07/05 18:12:47 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -64,15 +64,6 @@ __KERNEL_RCSID(0, "$NetBSD: x86_autoconf
 struct disklist *x86_alldisks;
 int x86_ndisks;
 
-static void
-handle_wedges(device_t dv, int par)
-{
-	if (config_handle_wedges(dv, par) == 0)
-		return;
-	booted_device = dv;
-	booted_partition = par;
-}
-
 static int
 is_valid_disk(device_t dv)
 {
@@ -344,7 +335,9 @@ findroot(void)
 
 			if (strncmp(cd->cf_name, biv->devname, len) == 0 &&
 			    biv->devname[len] - '0' == device_unit(dv)) {
-				handle_wedges(dv, biv->devname[len + 1] - 'a');
+				booted_device = dv;
+				booted_partition = biv->devname[len + 1] - 'a';
+				booted_nblks = 0;
 				break;
 			}
 		}
@@ -388,11 +381,14 @@ findroot(void)
 				    device_xname(dv));
 				continue;
 			}
-			dkwedge_set_bootwedge(dv, biw->startblk, biw->nblks);
+			booted_device = dv;
+			booted_partition = 0;
+			booted_nblks = biw->nblks;
+			booted_startblk = biw->startblk;
 		}
 		deviter_release(&di);
 
-		if (booted_wedge)
+		if (booted_nblks)
 			return;
 	}
 
@@ -445,7 +441,9 @@ findroot(void)
 				    device_xname(dv));
 				continue;
 			}
-			handle_wedges(dv, bid->partition);
+			booted_device = dv;
+			booted_partition = bid->partition;
+			booted_nblks = 0;
 		}
 		deviter_release(&di);
 
@@ -477,6 +475,7 @@ findroot(void)
 				    device_is_a(dv, "cd")) {
 					booted_device = dv;
 					booted_partition = 0;
+					booted_nblks = 0;
 					break;
 				}
 			}
@@ -492,16 +491,9 @@ cpu_rootconf(void)
 	findroot();
 	matchbiosdisks();
 
-	if (booted_wedge) {
-		KASSERT(booted_device != NULL);
-		aprint_normal("boot device: %s (%s)\n",
-		    device_xname(booted_wedge), device_xname(booted_device));
-		setroot(booted_wedge, 0);
-	} else {
-		aprint_normal("boot device: %s\n",
-		    booted_device ? device_xname(booted_device) : "<unknown>");
-		setroot(booted_device, booted_partition);
-	}
+	aprint_normal("boot device: %s\n",
+	    booted_device ? device_xname(booted_device) : "<unknown>");
+	setroot(booted_device, booted_partition);
 }
 
 void

Index: src/sys/arch/xen/x86/autoconf.c
diff -u src/sys/arch/xen/x86/autoconf.c:1.13 src/sys/arch/xen/x86/autoconf.c:1.13.18.1
--- src/sys/arch/xen/x86/autoconf.c:1.13	Fri Nov 27 03:23:15 2009
+++ src/sys/arch/xen/x86/autoconf.c	Thu Jul  5 18:12:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.13 2009/11/27 03:23:15 rmind Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.13.18.1 2012/07/05 18:12:49 riz Exp $	*/
 /*	NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp 	*/
 
 /*-
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.13 2009/11/27 03:23:15 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.13.18.1 2012/07/05 18:12:49 riz Exp $");
 
 #include "opt_xen.h"
 #include "opt_compat_oldboot.h"
@@ -88,7 +88,6 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v
 
 static void findroot(void);
 static int is_valid_disk(device_t);
-static void handle_wedges(device_t, int);
 
 struct disklist *x86_alldisks;
 int x86_ndisks;
@@ -155,16 +154,9 @@ cpu_rootconf(void)
 {
 	findroot();
 
-	if (booted_wedge) {
-		KASSERT(booted_device != NULL);
-		printf("boot device: %s (%s)\n",
-		    device_xname(booted_wedge), device_xname(booted_device));
-		setroot(booted_wedge, 0);
-	} else {
-		printf("boot device: %s\n",
-		    booted_device ? device_xname(booted_device) : "<unknown>");
-		setroot(booted_device, booted_partition);
-	}
+	printf("boot device: %s\n",
+	    booted_device ? device_xname(booted_device) : "<unknown>");
+	setroot(booted_device, booted_partition);
 }
 
 
@@ -199,7 +191,7 @@ findroot(void)
 			continue;
 
 		if (is_disk && xcp.xcp_bootdev[0] == 0) {
-			handle_wedges(dv, 0);
+			booted_device = dv;
 			break;
 		}
 
@@ -354,15 +346,6 @@ found:
 	booted_device = dev;
 }
 
-static void
-handle_wedges(device_t dv, int par)
-{
-	if (config_handle_wedges(dv, par) == 0)
-		return;
-	booted_device = dv;
-	booted_partition = par;
-}
-
 static int
 is_valid_disk(device_t dv)
 {

Index: src/sys/arch/zaurus/zaurus/autoconf.c
diff -u src/sys/arch/zaurus/zaurus/autoconf.c:1.10 src/sys/arch/zaurus/zaurus/autoconf.c:1.10.10.1
--- src/sys/arch/zaurus/zaurus/autoconf.c:1.10	Thu May  5 08:46:12 2011
+++ src/sys/arch/zaurus/zaurus/autoconf.c	Thu Jul  5 18:12:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.10 2011/05/05 08:46:12 nonaka Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.10.10.1 2012/07/05 18:12:49 riz Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.10 2011/05/05 08:46:12 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.10.10.1 2012/07/05 18:12:49 riz Exp $");
 
 #include "opt_md.h"
 
@@ -48,7 +48,6 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v
 #include <machine/bootinfo.h>
 #include <machine/config_hook.h>
 
-static void handle_wedges(device_t dv, int par);
 static int is_valid_disk(device_t dv);
 static int match_bootdisk(device_t dv, struct btinfo_bootdisk *bid);
 static void findroot(void);
@@ -69,17 +68,6 @@ cpu_configure(void)
 	spl0();
 }
 
-static void
-handle_wedges(device_t dv, int par)
-{
-
-	if (config_handle_wedges(dv, par) == 0)
-		return;
-
-	booted_device = dv;
-	booted_partition = par;
-}
-
 static int
 is_valid_disk(device_t dv)
 {
@@ -168,7 +156,8 @@ findroot(void)
 
 			if (strncmp(cd->cf_name, biv->devname, len) == 0 &&
 			    biv->devname[len] - '0' == cd->cf_unit) {
-				handle_wedges(dv, biv->devname[len + 1] - 'a');
+				booted_device = dv;
+				booted_partition = biv->devname[len + 1] - 'a';
 				break;
 			}
 		}
@@ -205,7 +194,8 @@ findroot(void)
 				    device_xname(dv));
 				continue;
 			}
-			handle_wedges(dv, bid->partition);
+			booted_device = dv;
+			booted_partition = bid->partition;
 		}
 		deviter_release(&di);
 

Index: src/sys/dev/vnd.c
diff -u src/sys/dev/vnd.c:1.219.8.1 src/sys/dev/vnd.c:1.219.8.2
--- src/sys/dev/vnd.c:1.219.8.1	Fri Apr  6 17:44:21 2012
+++ src/sys/dev/vnd.c	Thu Jul  5 18:12:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnd.c,v 1.219.8.1 2012/04/06 17:44:21 riz Exp $	*/
+/*	$NetBSD: vnd.c,v 1.219.8.2 2012/07/05 18:12:46 riz Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.219.8.1 2012/04/06 17:44:21 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.219.8.2 2012/07/05 18:12:46 riz Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -332,15 +332,31 @@ vndopen(dev_t dev, int flags, int mode, 
 	part = DISKPART(dev);
 	pmask = (1 << part);
 
-	/*
-	 * If we're initialized, check to see if there are any other
-	 * open partitions.  If not, then it's safe to update the
-	 * in-core disklabel.  Only read the disklabel if it is
-	 * not already valid.
-	 */
-	if ((sc->sc_flags & (VNF_INITED|VNF_VLABEL)) == VNF_INITED &&
-	    sc->sc_dkdev.dk_openmask == 0)
-		vndgetdisklabel(dev, sc);
+	if (sc->sc_dkdev.dk_nwedges != 0 && part != RAW_PART) {
+		error = EBUSY;
+		goto done;
+	}
+
+	if (sc->sc_flags & VNF_INITED) {
+		if ((sc->sc_dkdev.dk_openmask & ~(1<<RAW_PART)) != 0) {
+			/*
+			 * If any non-raw partition is open, but the disk
+			 * has been invalidated, disallow further opens.
+			 */
+			if ((sc->sc_flags & VNF_VLABEL) == 0) {
+				error = EIO;
+				goto done;
+			}
+		} else {
+			/*
+			 * Load the partition info if not already loaded.
+			 */
+			if ((sc->sc_flags & VNF_VLABEL) == 0) {
+				sc->sc_flags |= VNF_VLABEL;
+				vndgetdisklabel(dev, sc);
+			}
+		}
+	}
 
 	/* Check that the partitions exists. */
 	if (part != RAW_PART) {
@@ -968,6 +984,9 @@ vnddoclear(struct vnd_softc *vnd, int pm
 		return EBUSY;
 	}
 
+	/* Delete all of our wedges */
+	dkwedge_delall(&vnd->sc_dkdev);
+
 	/*
 	 * XXX vndclear() might call vndclose() implicitly;
 	 * release lock to avoid recursion
@@ -1320,12 +1339,13 @@ vndioctl(dev_t dev, u_long cmd, void *da
 		pool_init(&vnd->sc_vxpool, sizeof(struct vndxfer), 0,
 		    0, 0, "vndxpl", NULL, IPL_BIO);
 
-		/* Try and read the disklabel. */
-		vndgetdisklabel(dev, vnd);
-
 		vndunlock(vnd);
 
 		pathbuf_destroy(pb);
+
+		/* Discover wedges on this disk */
+		dkwedge_discover(&vnd->sc_dkdev);
+
 		break;
 
 close_and_exit:
@@ -1827,9 +1847,6 @@ vndgetdisklabel(dev_t dev, struct vnd_so
 		lp->d_npartitions = MAXPARTITIONS;
 		lp->d_checksum = dkcksum(lp);
 	}
-
-	/* In-core label now valid. */
-	sc->sc_flags |= VNF_VLABEL;
 }
 
 /*

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.62 src/sys/dev/dkwedge/dk.c:1.62.8.1
--- src/sys/dev/dkwedge/dk.c:1.62	Sat Jul 30 12:08:36 2011
+++ src/sys/dev/dkwedge/dk.c	Thu Jul  5 18:12:47 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.62 2011/07/30 12:08:36 jmcneill Exp $	*/
+/*	$NetBSD: dk.c,v 1.62.8.1 2012/07/05 18:12:47 riz Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.62 2011/07/30 12:08:36 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.62.8.1 2012/07/05 18:12:47 riz Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -747,44 +747,6 @@ dkwedge_print_wnames(void)
 }
 
 /*
- * dkwedge_set_bootwedge
- *
- *	Set the booted_wedge global based on the specified parent name
- *	and offset/length.
- */
-void
-dkwedge_set_bootwedge(device_t parent, daddr_t startblk, uint64_t nblks)
-{
-	struct dkwedge_softc *sc;
-	int i;
-
-	rw_enter(&dkwedges_lock, RW_WRITER);
-	for (i = 0; i < ndkwedges; i++) {
-		if ((sc = dkwedges[i]) == NULL)
-			continue;
-		if (strcmp(sc->sc_parent->dk_name, device_xname(parent)) == 0 &&
-		    sc->sc_offset == startblk &&
-		    sc->sc_size == nblks) {
-			if (booted_wedge) {
-				printf("WARNING: double match for boot wedge "
-				    "(%s, %s)\n",
-				    device_xname(booted_wedge),
-				    device_xname(sc->sc_dev));
-				continue;
-			}
-			booted_device = parent;
-			booted_wedge = sc->sc_dev;
-			booted_partition = 0;
-		}
-	}
-	/*
-	 * XXX What if we don't find one?  Should we create a special
-	 * XXX root wedge?
-	 */
-	rw_exit(&dkwedges_lock);
-}
-
-/*
  * We need a dummy object to stuff into the dkwedge discovery method link
  * set to ensure that there is always at least one object in the set.
  */
@@ -1465,65 +1427,38 @@ out:
  * config glue
  */
 
-int
-config_handle_wedges(struct device *dv, int par)
+/*
+ * dkwedge_find_partition
+ *
+ *	Find wedge corresponding to the specified parent name
+ *	and offset/length.
+ */
+device_t
+dkwedge_find_partition(device_t parent, daddr_t startblk, uint64_t nblks)
 {
-	struct dkwedge_list wl;
-	struct dkwedge_info *wi;
-	struct vnode *vn;
-	char diskname[16];
-	int i, error;
-
-	if ((vn = opendisk(dv)) == NULL)
-		return -1;
-
-	wl.dkwl_bufsize = sizeof(*wi) * 16;
-	wl.dkwl_buf = wi = malloc(wl.dkwl_bufsize, M_TEMP, M_WAITOK);
-
-	error = VOP_IOCTL(vn, DIOCLWEDGES, &wl, FREAD, NOCRED);
-	VOP_CLOSE(vn, FREAD, NOCRED);
-	vput(vn);
-	if (error) {
-#ifdef DEBUG_WEDGE
-		printf("%s: List wedges returned %d\n",
-		    device_xname(dv), error);
-#endif
-		free(wi, M_TEMP);
-		return -1;
-	}
-
-#ifdef DEBUG_WEDGE
-	printf("%s: Returned %u(%u) wedges\n", device_xname(dv),
-	    wl.dkwl_nwedges, wl.dkwl_ncopied);
-#endif
-	snprintf(diskname, sizeof(diskname), "%s%c", device_xname(dv),
-	    par + 'a');
-
-	for (i = 0; i < wl.dkwl_ncopied; i++) {
-#ifdef DEBUG_WEDGE
-		printf("%s: Looking for %s in %s\n", 
-		    device_xname(dv), diskname, wi[i].dkw_wname);
-#endif
-		if (strcmp(wi[i].dkw_wname, diskname) == 0)
-			break;
-	}
+	struct dkwedge_softc *sc;
+	int i;
+	device_t wedge = NULL;
 
-	if (i == wl.dkwl_ncopied) {
-#ifdef DEBUG_WEDGE
-		printf("%s: Cannot find wedge with parent %s\n",
-		    device_xname(dv), diskname);
-#endif
-		free(wi, M_TEMP);
-		return -1;
+	rw_enter(&dkwedges_lock, RW_READER);
+	for (i = 0; i < ndkwedges; i++) {
+		if ((sc = dkwedges[i]) == NULL)
+			continue;
+		if (strcmp(sc->sc_parent->dk_name, device_xname(parent)) == 0 &&
+		    sc->sc_offset == startblk &&
+		    sc->sc_size == nblks) {
+			if (wedge) {
+				printf("WARNING: double match for boot wedge "
+				    "(%s, %s)\n",
+				    device_xname(wedge),
+				    device_xname(sc->sc_dev));
+				continue;
+			}
+			wedge = sc->sc_dev;
+		}
 	}
+	rw_exit(&dkwedges_lock);
 
-#ifdef DEBUG_WEDGE
-	printf("%s: Setting boot wedge %s (%s) at %llu %llu\n", 
-		device_xname(dv), wi[i].dkw_devname, wi[i].dkw_wname,
-		(unsigned long long)wi[i].dkw_offset,
-		(unsigned long long)wi[i].dkw_size);
-#endif
-	dkwedge_set_bootwedge(dv, wi[i].dkw_offset, wi[i].dkw_size);
-	free(wi, M_TEMP);
-	return 0;
+	return wedge;
 }
+

Index: src/sys/dev/dkwedge/dkwedge_bsdlabel.c
diff -u src/sys/dev/dkwedge/dkwedge_bsdlabel.c:1.16 src/sys/dev/dkwedge/dkwedge_bsdlabel.c:1.16.18.1
--- src/sys/dev/dkwedge/dkwedge_bsdlabel.c:1.16	Sat Dec  5 16:29:14 2009
+++ src/sys/dev/dkwedge/dkwedge_bsdlabel.c	Thu Jul  5 18:12:47 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: dkwedge_bsdlabel.c,v 1.16 2009/12/05 16:29:14 pooka Exp $	*/
+/*	$NetBSD: dkwedge_bsdlabel.c,v 1.16.18.1 2012/07/05 18:12:47 riz Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dkwedge_bsdlabel.c,v 1.16 2009/12/05 16:29:14 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dkwedge_bsdlabel.c,v 1.16.18.1 2012/07/05 18:12:47 riz Exp $");
 
 #include <sys/param.h>
 #ifdef _KERNEL
@@ -248,11 +248,20 @@ addwedges(const mbr_args_t *a, const str
 		dkw.dkw_size = p->p_size;
 
 		/*
-		 * These get historical disk naming style
+		 * If the label defines a name, append the partition
+		 * letter and use it as the wedge name.
+		 * Otherwise use historical disk naming style
 		 * wedge names.
 		 */
-		snprintf((char *)&dkw.dkw_wname, sizeof(dkw.dkw_wname),
-		    "%s%c", a->pdk->dk_name, 'a' + i);
+		if (lp->d_packname[0] &&
+		    strcmp(lp->d_packname,"fictitious") != 0) {
+			snprintf((char *)&dkw.dkw_wname, sizeof(dkw.dkw_wname),
+		    		"%.*s/%c", (int)sizeof(dkw.dkw_wname)-3,
+				lp->d_packname, 'a' + i);
+		} else {
+			snprintf((char *)&dkw.dkw_wname, sizeof(dkw.dkw_wname),
+			    "%s%c", a->pdk->dk_name, 'a' + i);
+		}
 
 		error = dkwedge_add(&dkw);
 		if (error == EEXIST)

Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.441 src/sys/kern/init_main.c:1.441.2.1
--- src/sys/kern/init_main.c:1.441	Thu Feb  2 19:43:07 2012
+++ src/sys/kern/init_main.c	Thu Jul  5 18:12:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.441 2012/02/02 19:43:07 tls Exp $	*/
+/*	$NetBSD: init_main.c,v 1.441.2.1 2012/07/05 18:12:46 riz Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.441 2012/02/02 19:43:07 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.441.2.1 2012/07/05 18:12:46 riz Exp $");
 
 #include "opt_ddb.h"
 #include "opt_ipsec.h"
@@ -263,6 +263,7 @@ int	start_init_exec;		/* semaphore for s
 
 cprng_strong_t	*kern_cprng;
 
+static void rootconf(void);
 static void check_console(struct lwp *l);
 static void start_init(void *);
 static void configure(void);
@@ -640,7 +641,7 @@ main(void)
 	 * Now that autoconfiguration has completed, we can determine
 	 * the root and dump devices.
 	 */
-	cpu_rootconf();
+	rootconf();
 	cpu_dumpconf();
 
 	/* Mount the root file system. */
@@ -827,6 +828,78 @@ configure3(void)
 }
 
 static void
+rootconf_handle_wedges(void)
+{
+	struct partinfo dpart;
+	struct partition *p;
+	struct vnode *vp;
+	daddr_t startblk;
+	uint64_t nblks;
+	device_t dev; 
+	int error;
+
+	if (booted_nblks) {
+		/*
+		 * bootloader passed geometry
+		 */
+		dev      = booted_device;
+		startblk = booted_startblk;
+		nblks    = booted_nblks;
+
+		/*
+		 * keep booted_device and booted_partition
+		 * in case the kernel doesn't identify a wedge
+		 */
+	} else {
+		/*
+		 * bootloader passed partition number
+		 *
+		 * We cannot ask the partition device directly when it is
+		 * covered by a wedge. Instead we look up the geometry in
+		 * the disklabel.
+		 */
+		vp = opendisk(booted_device);
+
+		if (vp == NULL)
+			return;
+
+		error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED);
+		VOP_CLOSE(vp, FREAD, NOCRED);
+		vput(vp);
+		if (error)
+			return;
+
+		KASSERT(booted_partition >= 0
+			&& booted_partition < MAXPARTITIONS);
+
+		p = &dpart.disklab->d_partitions[booted_partition];
+
+		dev      = booted_device;
+		startblk = p->p_offset;
+		nblks    = p->p_size;
+	}
+
+	dev = dkwedge_find_partition(dev, startblk, nblks);
+	if (dev != NULL) {
+		booted_device = dev;
+		booted_partition = 0;
+	}
+}
+
+static void
+rootconf(void)
+{
+	cpu_rootconf();
+
+	if (booted_device == NULL)
+		return;
+
+	rootconf_handle_wedges();
+
+	setroot(booted_device, booted_partition);
+}
+
+static void
 check_console(struct lwp *l)
 {
 	struct vnode *vp;

Index: src/sys/kern/kern_subr.c
diff -u src/sys/kern/kern_subr.c:1.212 src/sys/kern/kern_subr.c:1.212.8.1
--- src/sys/kern/kern_subr.c:1.212	Mon Sep 19 23:54:29 2011
+++ src/sys/kern/kern_subr.c	Thu Jul  5 18:12:47 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_subr.c,v 1.212 2011/09/19 23:54:29 christos Exp $	*/
+/*	$NetBSD: kern_subr.c,v 1.212.8.1 2012/07/05 18:12:47 riz Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.212 2011/09/19 23:54:29 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.212.8.1 2012/07/05 18:12:47 riz Exp $");
 
 #include "opt_ddb.h"
 #include "opt_md.h"
@@ -158,12 +158,12 @@ int md_is_root = 0;
 #endif
 
 /*
- * The device and wedge that we booted from.  If booted_wedge is NULL,
- * the we might consult booted_partition.
+ * The device and partition that we booted from.
  */
 device_t booted_device;
-device_t booted_wedge;
 int booted_partition;
+daddr_t booted_startblk;
+uint64_t booted_nblks;
 
 /*
  * Use partition letters if it's a disk class but not a wedge.

Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.140 src/sys/sys/device.h:1.140.6.1
--- src/sys/sys/device.h:1.140	Sun Nov 13 22:05:58 2011
+++ src/sys/sys/device.h	Thu Jul  5 18:12:48 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.140 2011/11/13 22:05:58 christos Exp $ */
+/* $NetBSD: device.h,v 1.140.6.1 2012/07/05 18:12:48 riz Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -423,14 +423,14 @@ struct pdevinit {
 extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */
 extern struct cftablelist allcftables;	/* list of all cfdata tables */
 extern device_t booted_device;		/* the device we booted from */
-extern device_t booted_wedge;		/* the wedge on that device */
-extern int booted_partition;		/* or the partition on that device */
+extern int booted_partition;		/* the partition on that device */
+extern daddr_t booted_startblk;		/* or the start of a wedge */
+extern uint64_t booted_nblks;		/* and the size of that wedge */
 
 struct vnode *opendisk(struct device *);
 int getdisksize(struct vnode *, uint64_t *, unsigned *);
 struct dkwedge_info;
 int getdiskinfo(struct vnode *, struct dkwedge_info *);
-int config_handle_wedges(struct device *, int);
 
 void	config_init(void);
 int	config_init_component(struct cfdriver *const*,

Index: src/sys/sys/disk.h
diff -u src/sys/sys/disk.h:1.56 src/sys/sys/disk.h:1.56.2.1
--- src/sys/sys/disk.h:1.56	Mon Jan 16 18:47:58 2012
+++ src/sys/sys/disk.h	Thu Jul  5 18:12:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: disk.h,v 1.56 2012/01/16 18:47:58 christos Exp $	*/
+/*	$NetBSD: disk.h,v 1.56.2.1 2012/07/05 18:12:48 riz Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
@@ -530,10 +530,10 @@ int	dkwedge_del(struct dkwedge_info *);
 void	dkwedge_delall(struct disk *);
 int	dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *);
 void	dkwedge_discover(struct disk *);
-void	dkwedge_set_bootwedge(device_t, daddr_t, uint64_t);
 int	dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t);
 device_t dkwedge_find_by_wname(const char *);
 void	dkwedge_print_wnames(void);
+device_t dkwedge_find_partition(device_t, daddr_t, uint64_t);
 #endif
 
 #endif /* _SYS_DISK_H_ */

Reply via email to