Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Refactor setroot, no functional change intended.
details: https://anonhg.NetBSD.org/src/rev/2f5c57f6648c
branches: trunk
changeset: 995773:2f5c57f6648c
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sat Jan 05 09:39:56 2019 +0000
description:
Refactor setroot, no functional change intended.
setroot
- prepare special cases
- loop until root is set
setroot_nfs
- special case for disk boot + NFS root
setroot_ask
- Prompt user
setroot_root
- set root device
setroot_dump
- set dump device
diffstat:
sys/kern/kern_subr.c | 441 ++++++++++++++++++++++++++++----------------------
1 files changed, 249 insertions(+), 192 deletions(-)
diffs (truncated from 560 to 300 lines):
diff -r 0aa0bb3d6ffc -r 2f5c57f6648c sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c Sat Jan 05 09:20:29 2019 +0000
+++ b/sys/kern/kern_subr.c Sat Jan 05 09:39:56 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_subr.c,v 1.220 2018/10/07 11:24:16 mlelstv Exp $ */
+/* $NetBSD: kern_subr.c,v 1.221 2019/01/05 09:39:56 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.220 2018/10/07 11:24:16 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.221 2019/01/05 09:39:56 mlelstv Exp $");
#include "opt_ddb.h"
#include "opt_md.h"
@@ -111,6 +111,12 @@
static device_t parsedisk(char *, int, int, dev_t *);
static const char *getwedgename(const char *, int);
+static void setroot_nfs(device_t);
+static void setroot_ask(device_t, int);
+static void setroot_root(device_t, int);
+static void setroot_dump(device_t, device_t);
+
+
#ifdef TFTPROOT
int tftproot_dhcpboot(device_t);
#endif
@@ -154,6 +160,8 @@
/*
* The device and partition that we booted from.
+ *
+ * This data might be initialized by MD code, but is defined here.
*/
device_t booted_device;
const char *booted_method;
@@ -174,42 +182,6 @@
void
setroot(device_t bootdv, int bootpartition)
{
- device_t dv;
- deviter_t di;
- int len, majdev;
- dev_t nrootdev;
- dev_t ndumpdev = NODEV;
- char buf[128];
- const char *rootdevname;
- const char *dumpdevname;
- device_t rootdv = NULL; /* XXX gcc -Wuninitialized */
- device_t dumpdv = NULL;
- struct ifnet *ifp;
- const char *deffsname;
- struct vfsops *vops;
-
-#ifdef TFTPROOT
- if (tftproot_dhcpboot(bootdv) != 0)
- boothowto |= RB_ASKNAME;
-#endif
-
- /*
- * For root on md0 we have to force the attachment of md0.
- */
- if (md_is_root) {
- int md_major;
- dev_t md_dev;
-
- bootdv = NULL;
- md_major = devsw_name2blk("md", NULL, 0);
- if (md_major >= 0) {
- md_dev = MAKEDISKDEV(md_major, 0, RAW_PART);
- if (bdev_open(md_dev, FREAD, S_IFBLK, curlwp) == 0)
- bootdv = device_find_by_xname("md0");
- }
- if (bootdv == NULL)
- panic("Cannot open \"md0\" (root)");
- }
/*
* Let bootcode augment "rootspec".
@@ -218,27 +190,84 @@
rootspec = bootspec;
/*
- * If NFS is specified as the file system, and we found
- * a DV_DISK boot device (or no boot device at all), then
- * find a reasonable network interface for "rootspec".
+ * force boot device to md0
+ */
+ if (md_is_root)
+ rootspec = "md0";
+
+#ifdef TFTPROOT
+ /*
+ * XXX
+ * if rootspec specifies an interface
+ * sets root_device to that interface
+ * reuses NFS init code to set up network
+ * fetch image into ram disk
+ *
+ * if successful, we change rootspec
+ */
+ if (tftproot_dhcpboot(bootdv) == 0)
+ rootspec = "md0";
+#endif
+
+ /*
+ * quirk for
+ * evbarm/mini2440
+ * hpcarm
+ * hpcmips
+ * hpcsh
+ *
+ * if rootfstype is set to NFS and the
+ * kernel supports NFS and the boot device
+ * is unknown or not a network interface
+ * -> chose the first network interface you find
+ *
+ * hp300 has similar MD code
*/
+ setroot_nfs(bootdv);
+
+ /*
+ * If no bootdv was found by MD code and no
+ * root specified ask the user.
+ */
+ if (rootspec == NULL && bootdv == NULL)
+ boothowto |= RB_ASKNAME;
+
+ /*
+ * loop until a root device is specified
+ */
+ do {
+ if (boothowto & RB_ASKNAME)
+ setroot_ask(bootdv, bootpartition);
+ else
+ setroot_root(bootdv, bootpartition);
+
+ if (root_device == NULL)
+ boothowto |= RB_ASKNAME;
+ } while (root_device == NULL);
+}
+
+/*
+ * If NFS is specified as the file system, and we found
+ * a DV_DISK boot device (or no boot device at all), then
+ * find a reasonable network interface for "rootspec".
+ */
+static void
+setroot_nfs(device_t dv)
+{
+ struct vfsops *vops;
+ struct ifnet *ifp;
+
vops = vfs_getopsbyname(MOUNT_NFS);
if (vops != NULL && strcmp(rootfstype, MOUNT_NFS) == 0 &&
rootspec == NULL &&
- (bootdv == NULL || device_class(bootdv) != DV_IFNET)) {
+ (dv == NULL || device_class(dv) != DV_IFNET)) {
int s = pserialize_read_enter();
IFNET_READER_FOREACH(ifp) {
if ((ifp->if_flags &
(IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
break;
}
- if (ifp == NULL) {
- /*
- * Can't find a suitable interface; ask the
- * user.
- */
- boothowto |= RB_ASKNAME;
- } else {
+ if (ifp != NULL) {
/*
* Have a suitable interface; behave as if
* the user specified this interface.
@@ -249,152 +278,170 @@
}
if (vops != NULL)
vfs_delref(vops);
+}
- /*
- * If wildcarded root and we the boot device wasn't determined,
- * ask the user.
- */
- if (rootspec == NULL && bootdv == NULL)
- boothowto |= RB_ASKNAME;
-
- top:
- if (boothowto & RB_ASKNAME) {
- device_t defdumpdv;
+static void
+setroot_ask(device_t bootdv, int bootpartition)
+{
+ device_t dv, defdumpdv, rootdv, dumpdv;
+ dev_t nrootdev, ndumpdev;
+ struct vfsops *vops;
+ const char *deffsname;
+ int len;
+ char buf[128];
- for (;;) {
- printf("root device");
- if (bootdv != NULL) {
- printf(" (default %s", device_xname(bootdv));
- if (DEV_USES_PARTITIONS(bootdv))
- printf("%c", bootpartition + 'a');
- printf(")");
- }
- printf(": ");
- len = cngetsn(buf, sizeof(buf));
- if (len == 0 && bootdv != NULL) {
- strlcpy(buf, device_xname(bootdv), sizeof(buf));
- len = strlen(buf);
- }
- if (len > 0 && buf[len - 1] == '*') {
- buf[--len] = '\0';
- dv = getdisk(buf, len, 1, &nrootdev, 0);
- if (dv != NULL) {
- rootdv = dv;
- break;
- }
- }
- dv = getdisk(buf, len, bootpartition, &nrootdev, 0);
+ for (;;) {
+ printf("root device");
+ if (bootdv != NULL) {
+ printf(" (default %s", device_xname(bootdv));
+ if (DEV_USES_PARTITIONS(bootdv))
+ printf("%c", bootpartition + 'a');
+ printf(")");
+ }
+ printf(": ");
+ len = cngetsn(buf, sizeof(buf));
+ if (len == 0 && bootdv != NULL) {
+ strlcpy(buf, device_xname(bootdv), sizeof(buf));
+ len = strlen(buf);
+ }
+ if (len > 0 && buf[len - 1] == '*') {
+ buf[--len] = '\0';
+ dv = getdisk(buf, len, 1, &nrootdev, 0);
if (dv != NULL) {
rootdv = dv;
break;
}
}
+ dv = getdisk(buf, len, bootpartition, &nrootdev, 0);
+ if (dv != NULL) {
+ rootdv = dv;
+ break;
+ }
+ }
+ rootdev = nrootdev;
- /*
- * Set up the default dump device. If root is on
- * a network device, there is no default dump
- * device, since we don't support dumps to the
- * network.
- */
- if (DEV_USES_PARTITIONS(rootdv) == 0)
- defdumpdv = NULL;
- else
- defdumpdv = rootdv;
+ /*
+ * Set up the default dump device. If root is on
+ * a network device or a disk without partitions,
+ * there is no default dump device.
+ */
+ if (DEV_USES_PARTITIONS(rootdv) == 0)
+ defdumpdv = NULL;
+ else
+ defdumpdv = rootdv;
- for (;;) {
- printf("dump device");
+ ndumpdev = NODEV;
+ for (;;) {
+ printf("dump device");
+ if (defdumpdv != NULL) {
+ /*
+ * Note, we know it's a disk if we get here.
+ */
+ printf(" (default %sb)", device_xname(defdumpdv));
+ }
+ printf(": ");
+ len = cngetsn(buf, sizeof(buf));
+ if (len == 0) {
if (defdumpdv != NULL) {
- /*
- * Note, we know it's a disk if we get here.
- */
- printf(" (default %sb)", device_xname(defdumpdv));
+ ndumpdev = MAKEDISKDEV(major(nrootdev),
+ DISKUNIT(nrootdev), 1);
}
Home |
Main Index |
Thread Index |
Old Index