Module Name:    src
Committed By:   mlelstv
Date:           Sun Jun 10 17:05:19 UTC 2012

Modified Files:
        src/sys/arch/sparc64/sparc64: autoconf.c
        src/sys/arch/x86/x86: x86_autoconf.c
        src/sys/arch/xen/x86: autoconf.c
        src/sys/dev/dkwedge: dk.c
        src/sys/kern: init_main.c kern_subr.c
        src/sys/sys: device.h disk.h

Log Message:
Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for x86, xen, sparc64.


To generate a diff of this commit:
cvs rdiff -u -r1.186 -r1.187 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/x86/x86/x86_autoconf.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/xen/x86/autoconf.c
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/dkwedge/dk.c
cvs rdiff -u -r1.442 -r1.443 src/sys/kern/init_main.c
cvs rdiff -u -r1.212 -r1.213 src/sys/kern/kern_subr.c
cvs rdiff -u -r1.140 -r1.141 src/sys/sys/device.h
cvs rdiff -u -r1.56 -r1.57 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.186 src/sys/arch/sparc64/sparc64/autoconf.c:1.187
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.186	Mon May 28 19:24:30 2012
+++ src/sys/arch/sparc64/sparc64/autoconf.c	Sun Jun 10 17:05:18 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.186 2012/05/28 19:24:30 martin Exp $ */
+/*	$NetBSD: autoconf.c,v 1.187 2012/06/10 17:05:18 mlelstv Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.186 2012/05/28 19:24:30 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.187 2012/06/10 17:05:18 mlelstv 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.63
--- 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	Sun Jun 10 17:05:18 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.63 2012/06/10 17:05:18 mlelstv 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.63 2012/06/10 17:05:18 mlelstv 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.14
--- src/sys/arch/xen/x86/autoconf.c:1.13	Fri Nov 27 03:23:15 2009
+++ src/sys/arch/xen/x86/autoconf.c	Sun Jun 10 17:05:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.13 2009/11/27 03:23:15 rmind Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.14 2012/06/10 17:05:19 mlelstv 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.14 2012/06/10 17:05:19 mlelstv 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/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.63 src/sys/dev/dkwedge/dk.c:1.64
--- src/sys/dev/dkwedge/dk.c:1.63	Fri Apr 27 18:15:55 2012
+++ src/sys/dev/dkwedge/dk.c	Sun Jun 10 17:05:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.63 2012/04/27 18:15:55 drochner Exp $	*/
+/*	$NetBSD: dk.c,v 1.64 2012/06/10 17:05:19 mlelstv 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.63 2012/04/27 18:15:55 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.64 2012/06/10 17:05:19 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -748,44 +748,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.
  */
@@ -1466,65 +1428,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/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.442 src/sys/kern/init_main.c:1.443
--- src/sys/kern/init_main.c:1.442	Sun Feb 19 21:06:47 2012
+++ src/sys/kern/init_main.c	Sun Jun 10 17:05:18 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.442 2012/02/19 21:06:47 rmind Exp $	*/
+/*	$NetBSD: init_main.c,v 1.443 2012/06/10 17:05:18 mlelstv 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.442 2012/02/19 21:06:47 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.443 2012/06/10 17:05:18 mlelstv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_ipsec.h"
@@ -259,6 +259,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);
@@ -633,7 +634,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. */
@@ -820,6 +821,74 @@ 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);
+		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.213
--- src/sys/kern/kern_subr.c:1.212	Mon Sep 19 23:54:29 2011
+++ src/sys/kern/kern_subr.c	Sun Jun 10 17:05:18 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.213 2012/06/10 17:05:18 mlelstv 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.213 2012/06/10 17:05:18 mlelstv 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.141
--- src/sys/sys/device.h:1.140	Sun Nov 13 22:05:58 2011
+++ src/sys/sys/device.h	Sun Jun 10 17:05:18 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.140 2011/11/13 22:05:58 christos Exp $ */
+/* $NetBSD: device.h,v 1.141 2012/06/10 17:05:18 mlelstv 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.57
--- src/sys/sys/disk.h:1.56	Mon Jan 16 18:47:58 2012
+++ src/sys/sys/disk.h	Sun Jun 10 17:05:18 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: disk.h,v 1.56 2012/01/16 18:47:58 christos Exp $	*/
+/*	$NetBSD: disk.h,v 1.57 2012/06/10 17:05:18 mlelstv 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