Move rootfs-related init from init_main() to vfs_mountroot().

Reduces code re-written in rump.
This commit is contained in:
pooka 2009-11-27 16:43:51 +00:00
parent 0ff76018d0
commit 8102fe7341
4 changed files with 40 additions and 46 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.410 2009/11/15 02:37:13 elad Exp $ */
/* $NetBSD: init_main.c,v 1.411 2009/11/27 16:43:51 pooka 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.410 2009/11/15 02:37:13 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.411 2009/11/27 16:43:51 pooka Exp $");
#include "opt_ddb.h"
#include "opt_ipsec.h"
@ -253,7 +253,6 @@ struct timeval50 boottime50;
extern struct proc proc0;
extern struct lwp lwp0;
extern struct cwdinfo cwdi0;
extern time_t rootfstime;
#ifndef curlwp
@ -632,30 +631,6 @@ main(void)
*/
inittodr(rootfstime);
CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
CIRCLEQ_FIRST(&mountlist)->mnt_op->vfs_refcount++;
/*
* Get the vnode for '/'. Set filedesc0.fd_fd.fd_cdir to
* reference it.
*/
error = VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode);
if (error)
panic("cannot find root vnode, error=%d", error);
cwdi0.cwdi_cdir = rootvnode;
VREF(cwdi0.cwdi_cdir);
VOP_UNLOCK(rootvnode, 0);
cwdi0.cwdi_rdir = NULL;
/*
* Now that root is mounted, we can fixup initproc's CWD
* info. All other processes are kthreads, which merely
* share proc0's CWD info.
*/
initproc->p_cwdi->cwdi_cdir = rootvnode;
VREF(initproc->p_cwdi->cwdi_cdir);
initproc->p_cwdi->cwdi_rdir = NULL;
/*
* Now can look at time, having had a chance to verify the time
* from the file system. Reset l->l_rtime as it may have been

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_subr.c,v 1.390 2009/11/26 20:52:19 pooka Exp $ */
/* $NetBSD: vfs_subr.c,v 1.391 2009/11/27 16:43:51 pooka Exp $ */
/*-
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.390 2009/11/26 20:52:19 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.391 2009/11/27 16:43:51 pooka Exp $");
#include "opt_ddb.h"
#include "opt_compat_netbsd.h"
@ -2567,6 +2567,33 @@ done:
VOP_CLOSE(rootvp, FREAD, FSCRED);
vrele(rootvp);
}
if (error == 0) {
extern struct cwdinfo cwdi0;
CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
CIRCLEQ_FIRST(&mountlist)->mnt_op->vfs_refcount++;
/*
* Get the vnode for '/'. Set cwdi0.cwdi_cdir to
* reference it.
*/
error = VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode);
if (error)
panic("cannot find root vnode, error=%d", error);
cwdi0.cwdi_cdir = rootvnode;
VREF(cwdi0.cwdi_cdir);
VOP_UNLOCK(rootvnode, 0);
cwdi0.cwdi_rdir = NULL;
/*
* Now that root is mounted, we can fixup initproc's CWD
* info. All other processes are kthreads, which merely
* share proc0's CWD info.
*/
initproc->p_cwdi->cwdi_cdir = rootvnode;
VREF(initproc->p_cwdi->cwdi_cdir);
initproc->p_cwdi->cwdi_rdir = NULL;
}
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump_vfs.c,v 1.36 2009/11/26 21:04:42 pooka Exp $ */
/* $NetBSD: rump_vfs.c,v 1.37 2009/11/27 16:43:51 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.36 2009/11/26 21:04:42 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.37 2009/11/27 16:43:51 pooka Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@ -113,6 +113,11 @@ rump_vfs_init2()
rootfstype = ROOT_FSTYPE_ANY;
root_device = RUMP_VFSROOTDEV;
/* bootstrap cwdi (rest done in vfs_mountroot() */
rw_init(&cwdi0.cwdi_lock);
proc0.p_cwdi = &cwdi0;
proc0.p_cwdi = cwdinit();
/*
* XXX: make sure rumpfs is attached. The opposite can
* happen e.g. on Linux where the dynlinker doesn't work
@ -122,20 +127,10 @@ rump_vfs_init2()
vfs_attach(&rumpfs_vfsops);
vfs_mountroot();
VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode);
rump_proc_vfs_init = pvfs_init;
rump_proc_vfs_release = pvfs_rele;
/* bootstrap cwdi */
rw_init(&cwdi0.cwdi_lock);
cwdi0.cwdi_cdir = rootvnode;
vref(cwdi0.cwdi_cdir);
proc0.p_cwdi = &cwdi0;
proc0.p_cwdi = cwdinit();
VOP_UNLOCK(rootvnode, 0);
if (rump_threads) {
if ((rv = kthread_create(PRI_IOFLUSH, KTHREAD_MPSAFE, NULL,
sched_sync, NULL, NULL, "ioflush")) != 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpfs.c,v 1.30 2009/11/26 20:58:51 pooka Exp $ */
/* $NetBSD: rumpfs.c,v 1.31 2009/11/27 16:43:51 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.30 2009/11/26 20:58:51 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.31 2009/11/27 16:43:51 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -875,9 +875,6 @@ rumpfs_mountroot()
mp->mnt_data = rfsmp;
VOP_UNLOCK(rfsmp->rfsmp_rvp, 0);
mp->mnt_flag |= MNT_ROOTFS;
rumpfs_vfsops.vfs_refcount++;
mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mutex_exit(&mountlist_lock);