Store config(1)'s root filesystem type as a text string rather than

embedding the address of its xxx_mountroot() in swapnetbsd.c.  This
permits booting of kernels with hard-wired filesystem type even if the
filesystem is in a loadable module (ie, not linked into the kernel
image).

Discussed on current-users.  Tested on amd64 and i386 with both hard-
wired and '?' filesystem times, and on both modular and monolithic
kernels.

Thanks to pooka@ for code review and suggestions.

Addresses my PR kern/40167
This commit is contained in:
pgoyette 2008-12-19 17:11:57 +00:00
parent 78284dcaf1
commit 9c68331911
10 changed files with 63 additions and 45 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.91 2008/06/22 16:29:36 tsutsui Exp $ */
/* $NetBSD: autoconf.c,v 1.92 2008/12/19 17:11:57 pgoyette Exp $ */
/*-
* Copyright (c) 1996, 1997, 2002 The NetBSD Foundation, Inc.
@ -136,7 +136,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.91 2008/06/22 16:29:36 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.92 2008/12/19 17:11:57 pgoyette Exp $");
#include "hil.h"
#include "dvbox.h"
@ -380,8 +380,9 @@ cpu_rootconf(void)
* pick the network interface device to use.
*/
if (rootspec == NULL) {
vops = vfs_getopsbyname("nfs");
if (vops != NULL && vops->vfs_mountroot == mountroot) {
vops = vfs_getopsbyname(MOUNT_NFS);
if (vops != NULL && vops->vfs_mountroot != NULL &&
strcmp(rootfstype, MOUNT_NFS) == 0) {
for (dd = LIST_FIRST(&dev_data_list);
dd != NULL; dd = LIST_NEXT(dd, dd_list)) {
if (device_class(dd->dd_dev) == DV_IFNET) {
@ -395,6 +396,8 @@ cpu_rootconf(void)
dv = NULL;
}
}
if (vops != NULL)
vfs_delref(vops);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: hpc_machdep.c,v 1.89 2008/11/30 18:21:34 martin Exp $ */
/* $NetBSD: hpc_machdep.c,v 1.90 2008/12/19 17:11:57 pgoyette Exp $ */
/*
* Copyright (c) 1994-1998 Mark Brinicombe.
@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: hpc_machdep.c,v 1.89 2008/11/30 18:21:34 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: hpc_machdep.c,v 1.90 2008/12/19 17:11:57 pgoyette Exp $");
#include "opt_ddb.h"
#include "opt_pmap_debug.h"
@ -363,8 +363,8 @@ initarm(int argc, char **argv, struct bootinfo *bi)
/* boot device: -b=sd0 etc. */
cp = cp + 2;
#ifdef NFS
if (strcmp(cp, "nfs") == 0)
mountroot = nfs_mountroot;
if (strcmp(cp, MOUNT_NFS) == 0)
rootfstype = MOUNT_NFS;
else
strncpy(boot_file, cp, sizeof(boot_file));
#else /* !NFS */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.99 2008/11/30 18:21:34 martin Exp $ */
/* $NetBSD: machdep.c,v 1.100 2008/12/19 17:11:57 pgoyette Exp $ */
/*-
* Copyright (c) 1999 Shin Takemura, All rights reserved.
@ -108,7 +108,7 @@
*/
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.99 2008/11/30 18:21:34 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.100 2008/12/19 17:11:57 pgoyette Exp $");
#include "opt_vr41xx.h"
#include "opt_tx39xx.h"
@ -418,7 +418,7 @@ mach_init(int argc, char *argv[], struct bootinfo *bi)
/* boot device: -b=sd0 etc. */
#ifdef NFS
if (strcmp(cp+2, "nfs") == 0)
mountroot = nfs_mountroot;
rootfstype = MOUNT_NFS;
else
makebootdev(cp+2);
#else /* NFS */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.65 2008/11/30 18:21:34 martin Exp $ */
/* $NetBSD: machdep.c,v 1.66 2008/12/19 17:11:57 pgoyette Exp $ */
/*-
* Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.65 2008/11/30 18:21:34 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.66 2008/12/19 17:11:57 pgoyette Exp $");
#include "opt_md.h"
#include "opt_ddb.h"
@ -243,7 +243,7 @@ machine_startup(int argc, char *argv[], struct bootinfo *bi)
p = cp + 2;
#ifdef NFS
if (strcmp(p, "nfs") == 0)
mountroot = nfs_mountroot;
rootfstype = MOUNT_NFS;
else
makebootdev(p);
#else /* NFS */

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_subr.c,v 1.196 2008/11/27 21:36:51 christos Exp $ */
/* $NetBSD: kern_subr.c,v 1.197 2008/12/19 17:11:57 pgoyette 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.196 2008/11/27 21:36:51 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.197 2008/12/19 17:11:57 pgoyette Exp $");
#include "opt_ddb.h"
#include "opt_md.h"
@ -785,8 +785,8 @@ setroot(struct device *bootdv, int bootpartition)
* a DV_DISK boot device (or no boot device at all), then
* find a reasonable network interface for "rootspec".
*/
vops = vfs_getopsbyname("nfs");
if (vops != NULL && vops->vfs_mountroot == mountroot &&
vops = vfs_getopsbyname(MOUNT_NFS);
if (vops != NULL && strcmp(rootfstype, MOUNT_NFS) == 0 &&
rootspec == NULL &&
(bootdv == NULL || device_class(bootdv) != DV_IFNET)) {
IFNET_FOREACH(ifp) {
@ -897,12 +897,11 @@ setroot(struct device *bootdv, int bootpartition)
for (vops = LIST_FIRST(&vfs_list); vops != NULL;
vops = LIST_NEXT(vops, vfs_list)) {
if (vops->vfs_mountroot != NULL &&
vops->vfs_mountroot == mountroot)
strcmp(rootfstype, vops->vfs_name) == 0)
break;
}
if (vops == NULL) {
mountroot = NULL;
deffsname = "generic";
} else
deffsname = vops->vfs_name;
@ -910,8 +909,11 @@ setroot(struct device *bootdv, int bootpartition)
for (;;) {
printf("file system (default %s): ", deffsname);
len = cngetsn(buf, sizeof(buf));
if (len == 0)
if (len == 0) {
if (strcmp(deffsname, "generic") == 0)
rootfstype = ROOT_FSTYPE_ANY;
break;
}
if (len == 4 && strcmp(buf, "halt") == 0)
cpu_reboot(RB_HALT, NULL);
else if (len == 6 && strcmp(buf, "reboot") == 0)
@ -922,7 +924,7 @@ setroot(struct device *bootdv, int bootpartition)
}
#endif
else if (len == 7 && strcmp(buf, "generic") == 0) {
mountroot = NULL;
rootfstype = ROOT_FSTYPE_ANY;
break;
}
vops = vfs_getopsbyname(buf);
@ -934,12 +936,20 @@ setroot(struct device *bootdv, int bootpartition)
if (vops->vfs_mountroot != NULL)
printf(" %s", vops->vfs_name);
}
if (vops != NULL)
vfs_delref(vops);
#if defined(DDB)
printf(" ddb");
#endif
printf(" halt reboot\n");
} else {
mountroot = vops->vfs_mountroot;
/*
* XXX If *vops gets freed between here and
* the call to mountroot(), rootfstype will
* point to something unexpected. But in
* this case the system will fail anyway.
*/
rootfstype = vops->vfs_name;
vfs_delref(vops);
break;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_subr.c,v 1.361 2008/12/16 22:35:37 christos Exp $ */
/* $NetBSD: vfs_subr.c,v 1.362 2008/12/19 17:11:57 pgoyette Exp $ */
/*-
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@ -81,7 +81,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.361 2008/12/16 22:35:37 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.362 2008/12/19 17:11:57 pgoyette Exp $");
#include "opt_ddb.h"
#include "opt_compat_netbsd.h"
@ -2345,10 +2345,18 @@ vfs_mountroot(void)
}
/*
* If user specified a file system, use it.
* If user specified a root fs type, use it. Make sure the
* specified type exists and has a mount_root()
*/
if (mountroot != NULL) {
error = (*mountroot)();
if (strcmp(rootfstype, ROOT_FSTYPE_ANY) != 0) {
v = vfs_getopsbyname(rootfstype);
error = EFTYPE;
if (v != NULL) {
if (v->vfs_mountroot != NULL) {
error = (v->vfs_mountroot)();
}
v->vfs_refcount--;
}
goto done;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfsops_stub.c,v 1.3 2008/12/19 00:57:24 pooka Exp $ */
/* $NetBSD: vfsops_stub.c,v 1.4 2008/12/19 17:11:57 pgoyette Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfsops_stub.c,v 1.3 2008/12/19 00:57:24 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfsops_stub.c,v 1.4 2008/12/19 17:11:57 pgoyette Exp $");
#include <sys/param.h>
#include <sys/errno.h>
@ -40,7 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfsops_stub.c,v 1.3 2008/12/19 00:57:24 pooka Exp $"
#include <miscfs/fifofs/fifo.h>
#include <miscfs/syncfs/syncfs.h>
int (*mountroot)(void);
const char *rootfstype;
#define VFSSTUB(name) \
int name(void *arg) {panic("%s: unimplemented vfs stub", __func__);}

View File

@ -1,4 +1,4 @@
/* $NetBSD: systm.h,v 1.231 2008/12/16 22:35:38 christos Exp $ */
/* $NetBSD: systm.h,v 1.232 2008/12/19 17:11:57 pgoyette Exp $ */
/*-
* Copyright (c) 1982, 1988, 1991, 1993
@ -331,7 +331,10 @@ void dopowerhooks(int);
* these to be executed just before (*mountroot)() if the passed device is
* selected as the root device.
*/
extern int (*mountroot)(void);
#define ROOT_FSTYPE_ANY "?"
extern const char *rootfstype;
void *mountroothook_establish(void (*)(struct device *), struct device *);
void mountroothook_disestablish(void *);
void mountroothook_destroy(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mfs_vfsops.c,v 1.99 2008/11/13 11:10:41 ad Exp $ */
/* $NetBSD: mfs_vfsops.c,v 1.100 2008/12/19 17:11:57 pgoyette Exp $ */
/*
* Copyright (c) 1989, 1990, 1993, 1994
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.99 2008/11/13 11:10:41 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.100 2008/12/19 17:11:57 pgoyette Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -253,7 +253,7 @@ mfs_initminiroot(void *base)
if (fs->fs_magic != FS_UFS1_MAGIC || fs->fs_bsize > MAXBSIZE ||
fs->fs_bsize < sizeof(struct fs))
return (0);
mountroot = mfs_mountroot;
rootfstype = MOUNT_MFS;
mfs_rootbase = base;
mfs_rootsize = fs->fs_fsize * fs->fs_size;
rootdev = makedev(255, mfs_minor);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkswap.c,v 1.4 2007/12/12 00:03:34 lukem Exp $ */
/* $NetBSD: mkswap.c,v 1.5 2008/12/19 17:11:57 pgoyette Exp $ */
/*
* Copyright (c) 1992, 1993
@ -133,14 +133,8 @@ mkoneswap(struct config *cf)
/*
* Emit the root file system.
*/
if (cf->cf_fstype == NULL)
strlcpy(specinfo, "NULL", sizeof(specinfo));
else {
snprintf(specinfo, sizeof(specinfo), "%s_mountroot",
cf->cf_fstype);
fprintf(fp, "int %s(void);\n", specinfo);
}
fprintf(fp, "int (*mountroot)(void) = %s;\n", specinfo);
fprintf(fp, "const char *rootfstype = \"%s\";\n",
cf->cf_fstype ? cf->cf_fstype : "?");
fflush(fp);
if (ferror(fp))