Make MFS work with the new root filesystem search process.

In order to achieve this, root filesystem mount is moved from
SI_ORDER_FIRST to SI_ORDER_SECOND in the SI_SUB_MOUNT_ROOT sysinit
group.  Now, modules which wish to usurp the default root mount
can use SI_ORDER_FIRST.

A compiled-in or preloaded MFS filesystem will become the root
filesystem unless the vfs.root.mountfrom environment variable refers
to a valid bootable device.  This will normally only be the case when
the kernel and MFS image have been loaded from a disk which has a
valid /etc/fstab file.  In this case, the variable should be manually
overridden in the loader, or the kernel booted with -a.  In either
case "mfs:" should be supplied as the new value.

Also fix a typo in one DFLTROOT case that would not have compiled.
This commit is contained in:
msmith 1999-11-03 11:02:47 +00:00
parent b8f1781068
commit 42a534a64d
3 changed files with 52 additions and 32 deletions

View File

@ -70,7 +70,7 @@ static void gets(char *cp);
char *rootdevnames[2] = {NULL, NULL};
static int setrootbyname(char *name);
SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountroot, NULL);
SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_SECOND, vfs_mountroot, NULL);
/*
* Find and mount the root filesystem
@ -119,8 +119,8 @@ vfs_mountroot(void *junk)
*/
#ifdef ROOTDEVNAME
if (!(boothowto & RB_DFLTROOT))
!vfs_mountroot_try(ROOTDEVNAME))
return;
if (!vfs_mountroot_try(ROOTDEVNAME))
return;
#endif
/*
@ -138,12 +138,12 @@ vfs_mountroot(void *junk)
static int
vfs_mountroot_try(char *mountfrom)
{
struct mount *mp;
struct mount *mp;
char *vfsname, *path;
int error;
char patt[16];
vfsname = path = NULL;
vfsname = path = mp = NULL;
error = EINVAL;
if (mountfrom == NULL)
@ -154,8 +154,9 @@ vfs_mountroot_try(char *mountfrom)
/* parse vfs name and path */
vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK);
path = malloc(MNAMELEN, M_MOUNT, M_WAITOK);
vfsname[0] = path[0] = 0;
sprintf(patt, "%%%d[a-z]:%%%ds", MFSNAMELEN, MNAMELEN);
if (sscanf(mountfrom, patt, vfsname, path) != 2)
if (sscanf(mountfrom, patt, vfsname, path) < 1)
goto done;
/* allocate a root mount */
@ -167,7 +168,7 @@ vfs_mountroot_try(char *mountfrom)
mp->mnt_flag |= MNT_ROOTFS;
/* do our best to set rootdev */
if (setrootbyname(path))
if ((path[0] != 0) && setrootbyname(path))
printf("setrootbyname failed\n");
strcpy(mp->mnt_stat.f_mntfromname, path);
@ -190,7 +191,8 @@ vfs_mountroot_try(char *mountfrom)
/* sanity check system clock against root filesystem timestamp */
inittodr(mp->mnt_time);
}
vfs_unbusy(mp, curproc);
if (mp != NULL)
vfs_unbusy(mp, curproc);
return(error);
}

View File

@ -70,7 +70,7 @@ static void gets(char *cp);
char *rootdevnames[2] = {NULL, NULL};
static int setrootbyname(char *name);
SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountroot, NULL);
SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_SECOND, vfs_mountroot, NULL);
/*
* Find and mount the root filesystem
@ -119,8 +119,8 @@ vfs_mountroot(void *junk)
*/
#ifdef ROOTDEVNAME
if (!(boothowto & RB_DFLTROOT))
!vfs_mountroot_try(ROOTDEVNAME))
return;
if (!vfs_mountroot_try(ROOTDEVNAME))
return;
#endif
/*
@ -138,12 +138,12 @@ vfs_mountroot(void *junk)
static int
vfs_mountroot_try(char *mountfrom)
{
struct mount *mp;
struct mount *mp;
char *vfsname, *path;
int error;
char patt[16];
vfsname = path = NULL;
vfsname = path = mp = NULL;
error = EINVAL;
if (mountfrom == NULL)
@ -154,8 +154,9 @@ vfs_mountroot_try(char *mountfrom)
/* parse vfs name and path */
vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK);
path = malloc(MNAMELEN, M_MOUNT, M_WAITOK);
vfsname[0] = path[0] = 0;
sprintf(patt, "%%%d[a-z]:%%%ds", MFSNAMELEN, MNAMELEN);
if (sscanf(mountfrom, patt, vfsname, path) != 2)
if (sscanf(mountfrom, patt, vfsname, path) < 1)
goto done;
/* allocate a root mount */
@ -167,7 +168,7 @@ vfs_mountroot_try(char *mountfrom)
mp->mnt_flag |= MNT_ROOTFS;
/* do our best to set rootdev */
if (setrootbyname(path))
if ((path[0] != 0) && setrootbyname(path))
printf("setrootbyname failed\n");
strcpy(mp->mnt_stat.f_mntfromname, path);
@ -190,7 +191,8 @@ vfs_mountroot_try(char *mountfrom)
/* sanity check system clock against root filesystem timestamp */
inittodr(mp->mnt_time);
}
vfs_unbusy(mp, curproc);
if (mp != NULL)
vfs_unbusy(mp, curproc);
return(error);
}

View File

@ -78,6 +78,7 @@ static int mfs_start __P((struct mount *mp, int flags, struct proc *p));
static int mfs_statfs __P((struct mount *mp, struct statfs *sbp,
struct proc *p));
static int mfs_init __P((struct vfsconf *));
static void mfs_takeroot __P((void *));
static struct cdevsw mfs_cdevsw = {
/* open */ noopen,
@ -228,8 +229,14 @@ mfs_mount(mp, path, data, ndp, p)
mfs_rootbase = base;
mfs_rootsize = fs->fs_fsize * fs->fs_size;
printf("rootfs is %ld Kbyte compiled in MFS\n",
mfs_rootsize/1024);
/* remake rootdev, since vfs_mountroot will have it wrong */
rootdev = make_dev(&mfs_cdevsw, mfs_minor,
0, 0, 0, "MFS%d", mfs_minor);
rootdev->si_bsize_phys = DEV_BSIZE;
rootdev->si_iosize_max = DFLTPHYS;
mfs_minor++;
if ((err = bdevvp(rootdev, &rootvp))) {
printf("mfs_mount: can't find rootvp\n");
return (err);
@ -486,19 +493,28 @@ mfs_init(vfsp)
{
cdevsw_add(&mfs_cdevsw);
#ifdef MFS_ROOT
if (bootverbose)
printf("Considering MFS root f/s.\n");
if (mfs_getimage()) {
mountrootfsname = "mfs";
rootdev = make_dev(&mfs_cdevsw, mfs_minor,
0, 0, 0, "MFS%d", mfs_minor);
/* It is not clear that these will get initialized otherwise */
rootdev->si_bsize_phys = DEV_BSIZE;
rootdev->si_iosize_max = DFLTPHYS;
mfs_minor++;
} else if (bootverbose)
printf("No MFS image available as root f/s.\n");
#endif
return (0);
}
#ifdef MFS_ROOT
/*
* Just before root is mounted, check to see if we are a candidate
* to supply it. If we have an image available, override the guessed
* defaults.
*/
static void
mfs_takeroot(junk)
void *junk;
{
if (bootverbose)
printf("Considering MFS root f/s...");
if (mfs_getimage()) {
rootdevnames[0] = "mfs:";
printf("preloaded filesystem found.\n");
} else if (bootverbose) {
printf("not found.\n");
}
}
SYSINIT(mfs_root, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, mfs_takeroot, NULL);
#endif