Module Name: src Committed By: pooka Date: Thu Nov 26 20:58:51 UTC 2009
Modified Files: src/sys/rump/librump/rumpkern: emul.c rump.c rump_private.h src/sys/rump/librump/rumpvfs: Makefile.rumpvfs rump_vfs.c rump_vfs_private.h rumpfs.c Log Message: For rumpfs, do mountroot instead of the bunch of homegrown hacks currently there. Still needs a little massage to get the kernel interfaces right and avoid copypaste especially from main(). Also, move it a bit more into the direction of a real file system (finally!) by giving it a vfsops. Most ops are still unimplemented, though. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/sys/rump/librump/rumpkern/emul.c cvs rdiff -u -r1.139 -r1.140 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r1.35 -r1.36 src/sys/rump/librump/rumpkern/rump_private.h cvs rdiff -u -r1.19 -r1.20 src/sys/rump/librump/rumpvfs/Makefile.rumpvfs cvs rdiff -u -r1.34 -r1.35 src/sys/rump/librump/rumpvfs/rump_vfs.c cvs rdiff -u -r1.7 -r1.8 src/sys/rump/librump/rumpvfs/rump_vfs_private.h cvs rdiff -u -r1.29 -r1.30 src/sys/rump/librump/rumpvfs/rumpfs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/rump/librump/rumpkern/emul.c diff -u src/sys/rump/librump/rumpkern/emul.c:1.109 src/sys/rump/librump/rumpkern/emul.c:1.110 --- src/sys/rump/librump/rumpkern/emul.c:1.109 Wed Nov 4 19:21:51 2009 +++ src/sys/rump/librump/rumpkern/emul.c Thu Nov 26 20:58:51 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: emul.c,v 1.109 2009/11/04 19:21:51 pooka Exp $ */ +/* $NetBSD: emul.c,v 1.110 2009/11/26 20:58:51 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.109 2009/11/04 19:21:51 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.110 2009/11/26 20:58:51 pooka Exp $"); #include <sys/param.h> #include <sys/null.h> @@ -67,7 +67,6 @@ kmutex_t *proc_lock; struct lwp lwp0; struct vnode *rootvp; -struct device *root_device; dev_t rootdev; int physmem = 256*256; /* 256 * 1024*1024 / 4k, PAGE_SIZE not always set */ int doing_shutdown; @@ -124,10 +123,10 @@ device_class(device_t dev) { - if (dev != root_device) + if (dev != RUMP_VFSROOTDEV) panic("%s: dev != root_device not supported", __func__); - return DV_DISK; + return DV_VIRTUAL; } void Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.139 src/sys/rump/librump/rumpkern/rump.c:1.140 --- src/sys/rump/librump/rumpkern/rump.c:1.139 Thu Nov 26 17:36:22 2009 +++ src/sys/rump/librump/rumpkern/rump.c Thu Nov 26 20:58:51 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.139 2009/11/26 17:36:22 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.140 2009/11/26 20:58:51 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.139 2009/11/26 17:36:22 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.140 2009/11/26 20:58:51 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -123,6 +123,7 @@ int rump__unavailable() {return EOPNOTSUPP;} __weak_alias(rump_net_init,rump__unavailable); __weak_alias(rump_vfs_init,rump__unavailable); +__weak_alias(rump_vfs_init2,rump__unavailable); __weak_alias(rump_dev_init,rump__unavailable); __weak_alias(rump_vfs_fini,rump__unavailable); @@ -300,6 +301,11 @@ sysctl_finalize(); + rumpuser_dl_module_bootstrap(rump_module_init, rump_kernelfsym_load); + + /* mount rootfs, etcetc. */ + rump_vfs_init2(); + rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error); hostnamelen = strlen(hostname); @@ -312,7 +318,6 @@ vmem_rehash_start(); #endif - rumpuser_dl_module_bootstrap(rump_module_init, rump_kernelfsym_load); rump_unschedule(); return 0; Index: src/sys/rump/librump/rumpkern/rump_private.h diff -u src/sys/rump/librump/rumpkern/rump_private.h:1.35 src/sys/rump/librump/rumpkern/rump_private.h:1.36 --- src/sys/rump/librump/rumpkern/rump_private.h:1.35 Mon Nov 9 19:17:42 2009 +++ src/sys/rump/librump/rumpkern/rump_private.h Thu Nov 26 20:58:51 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_private.h,v 1.35 2009/11/09 19:17:42 pooka Exp $ */ +/* $NetBSD: rump_private.h,v 1.36 2009/11/26 20:58:51 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -54,6 +54,7 @@ #define UIO_VMSPACE_SYS (&rump_vmspace) #define RUMP_LMUTEX_MAGIC ((kmutex_t *)0x101) +#define RUMP_VFSROOTDEV ((struct device *)-11) extern int rump_threads; Index: src/sys/rump/librump/rumpvfs/Makefile.rumpvfs diff -u src/sys/rump/librump/rumpvfs/Makefile.rumpvfs:1.19 src/sys/rump/librump/rumpvfs/Makefile.rumpvfs:1.20 --- src/sys/rump/librump/rumpvfs/Makefile.rumpvfs:1.19 Thu Nov 26 07:30:24 2009 +++ src/sys/rump/librump/rumpvfs/Makefile.rumpvfs Thu Nov 26 20:58:51 2009 @@ -1,11 +1,11 @@ -# $NetBSD: Makefile.rumpvfs,v 1.19 2009/11/26 07:30:24 pooka Exp $ +# $NetBSD: Makefile.rumpvfs,v 1.20 2009/11/26 20:58:51 pooka Exp $ # .include "${RUMPTOP}/Makefile.rump" LIB= rumpvfs -.PATH: ${RUMPTOP}/librump/rumpvfs \ +.PATH: ${RUMPTOP}/librump/rumpvfs ${RUMPTOP}/librump \ ${RUMPTOP}/../kern \ ${RUMPTOP}/../miscfs/genfs ${RUMPTOP}/../miscfs/syncfs \ ${RUMPTOP}/../miscfs/specfs ${RUMPTOP}/../miscfs/deadfs \ @@ -17,7 +17,7 @@ # SRCS= rump_vfs.c devnodes.c rumpblk.c rumpfs.c vm_vfs.c -SRCS+= fstrans_stub.c vfsops_stub.c +SRCS+= fstrans_stub.c vfsops_stub.c rump_module.c SRCS+= rumpvfs_if_wrappers.c Index: src/sys/rump/librump/rumpvfs/rump_vfs.c diff -u src/sys/rump/librump/rumpvfs/rump_vfs.c:1.34 src/sys/rump/librump/rumpvfs/rump_vfs.c:1.35 --- src/sys/rump/librump/rumpvfs/rump_vfs.c:1.34 Thu Nov 19 14:44:58 2009 +++ src/sys/rump/librump/rumpvfs/rump_vfs.c Thu Nov 26 20:58:51 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_vfs.c,v 1.34 2009/11/19 14:44:58 pooka Exp $ */ +/* $NetBSD: rump_vfs.c,v 1.35 2009/11/26 20:58: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.34 2009/11/19 14:44:58 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.35 2009/11/26 20:58:51 pooka Exp $"); #include <sys/param.h> #include <sys/buf.h> @@ -102,7 +102,17 @@ rumpuser_biothread, rump_biodone, NULL, "rmpabio")) != 0) panic("syncer thread create failed: %d", rv); } - rumpfs_init(); +} + +void +rump_vfs_init2() +{ + int rv; + + rootfstype = ROOT_FSTYPE_ANY; + root_device = RUMP_VFSROOTDEV; + vfs_mountroot(); + VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode); rump_proc_vfs_init = pvfs_init; rump_proc_vfs_release = pvfs_rele; @@ -114,6 +124,8 @@ 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) Index: src/sys/rump/librump/rumpvfs/rump_vfs_private.h diff -u src/sys/rump/librump/rumpvfs/rump_vfs_private.h:1.7 src/sys/rump/librump/rumpvfs/rump_vfs_private.h:1.8 --- src/sys/rump/librump/rumpvfs/rump_vfs_private.h:1.7 Wed Oct 14 17:29:20 2009 +++ src/sys/rump/librump/rumpvfs/rump_vfs_private.h Thu Nov 26 20:58:51 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_vfs_private.h,v 1.7 2009/10/14 17:29:20 pooka Exp $ */ +/* $NetBSD: rump_vfs_private.h,v 1.8 2009/11/26 20:58:51 pooka Exp $ */ /* * Copyright (c) 2008 Antti Kantee. All Rights Reserved. @@ -31,6 +31,7 @@ #include <sys/types.h> void rump_vfs_init(void); +void rump_vfs_init2(void); void rump_vfs_fini(void); void rumpfs_init(void); Index: src/sys/rump/librump/rumpvfs/rumpfs.c diff -u src/sys/rump/librump/rumpvfs/rumpfs.c:1.29 src/sys/rump/librump/rumpvfs/rumpfs.c:1.30 --- src/sys/rump/librump/rumpvfs/rumpfs.c:1.29 Wed Oct 14 18:18:53 2009 +++ src/sys/rump/librump/rumpvfs/rumpfs.c Thu Nov 26 20:58:51 2009 @@ -1,9 +1,7 @@ -/* $NetBSD: rumpfs.c,v 1.29 2009/10/14 18:18:53 pooka Exp $ */ +/* $NetBSD: rumpfs.c,v 1.30 2009/11/26 20:58:51 pooka Exp $ */ /* - * Copyright (c) 2007 Antti Kantee. All Rights Reserved. - * - * Development of this software was supported by Google Summer of Code. + * Copyright (c) 2009 Antti Kantee. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.29 2009/10/14 18:18:53 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.30 2009/11/26 20:58:51 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -37,6 +35,7 @@ #include <sys/fcntl.h> #include <sys/kauth.h> #include <sys/malloc.h> +#include <sys/module.h> #include <sys/mount.h> #include <sys/namei.h> #include <sys/lock.h> @@ -140,6 +139,10 @@ #define rn_offset rn_u.reg.offset #define rn_dir rn_u.dir +struct rumpfs_mount { + struct vnode *rfsmp_rvp; +}; + static struct rumpfs_node *makeprivate(enum vtype, dev_t, off_t); /* @@ -310,7 +313,6 @@ * rumpfs */ -static struct mount rump_mnt; static int lastino = 1; static kmutex_t reclock; @@ -365,7 +367,7 @@ } static int -makevnode(struct rumpfs_node *rn, struct vnode **vpp) +makevnode(struct mount *mp, struct rumpfs_node *rn, struct vnode **vpp) { struct vnode *vp; int (**vpops)(void *); @@ -384,7 +386,7 @@ && va->va_type != VSOCK) return EOPNOTSUPP; - rv = getnewvnode(VT_RUMP, &rump_mnt, vpops, &vp); + rv = getnewvnode(VT_RUMP, mp, vpops, &vp); if (rv) return rv; @@ -476,7 +478,7 @@ goto getvnode; *vpp = vp; } else { - rv = makevnode(rn, vpp); + rv = makevnode(dvp->v_mount, rn, vpp); rn->rn_vp = *vpp; mutex_exit(&reclock); if (rv) @@ -518,7 +520,7 @@ rn = makeprivate(VDIR, NODEV, DEV_BSIZE); mutex_enter(&reclock); - rv = makevnode(rn, vpp); + rv = makevnode(dvp->v_mount, rn, vpp); mutex_exit(&reclock); if (rv) goto out; @@ -554,7 +556,7 @@ rn = makeprivate(va->va_type, va->va_rdev, DEV_BSIZE); mutex_enter(&reclock); - rv = makevnode(rn, vpp); + rv = makevnode(dvp->v_mount, rn, vpp); mutex_exit(&reclock); if (rv) goto out; @@ -595,7 +597,7 @@ } rn = makeprivate(VSOCK, NODEV, DEV_BSIZE); mutex_enter(&reclock); - rv = makevnode(rn, vpp); + rv = makevnode(dvp->v_mount, rn, vpp); mutex_exit(&reclock); if (rv) goto out; @@ -770,30 +772,133 @@ return VOCALL(opvec, ap->a_desc->vdesc_offset, v); } +/* + * Begin vfs-level stuff + */ + +VFS_PROTOS(rumpfs); +struct vfsops rumpfs_vfsops = { + .vfs_name = MOUNT_RUMPFS, + .vfs_min_mount_data = 0, + .vfs_mount = rumpfs_mount, + .vfs_start = (void *)nullop, + .vfs_unmount = rumpfs_unmount, + .vfs_root = rumpfs_root, + .vfs_quotactl = (void *)eopnotsupp, + .vfs_sync = (void *)nullop, + .vfs_vget = rumpfs_vget, + .vfs_fhtovp = (void *)eopnotsupp, + .vfs_vptofh = (void *)eopnotsupp, + .vfs_init = rumpfs_init, + .vfs_reinit = NULL, + .vfs_done = rumpfs_done, + .vfs_mountroot = rumpfs_mountroot, + .vfs_snapshot = (void *)eopnotsupp, + .vfs_extattrctl = (void *)eopnotsupp, + .vfs_suspendctl = (void *)eopnotsupp, + .vfs_opv_descs = rump_opv_descs, + /* vfs_refcount */ + /* vfs_list */ +}; + +int +rumpfs_mount(struct mount *mp, const char *mntpath, void *arg, size_t *alen) +{ + + return EOPNOTSUPP; +} + +int +rumpfs_unmount(struct mount *mp, int flags) +{ + + return EOPNOTSUPP; /* ;) */ +} + +int +rumpfs_root(struct mount *mp, struct vnode **vpp) +{ + struct rumpfs_mount *rfsmp = mp->mnt_data; + + vget(rfsmp->rfsmp_rvp, LK_EXCLUSIVE | LK_RETRY); + *vpp = rfsmp->rfsmp_rvp; + return 0; +} + +int +rumpfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp) +{ + + return EOPNOTSUPP; +} + void -rumpfs_init(void) +rumpfs_init() { - struct rumpfs_node *rn; - int rv; CTASSERT(RUMP_ETFS_SIZE_ENDOFF == RUMPBLK_SIZENOTSET); mutex_init(&reclock, MUTEX_DEFAULT, IPL_NONE); mutex_init(&etfs_lock, MUTEX_DEFAULT, IPL_NONE); +} + +void +rumpfs_done() +{ + + mutex_destroy(&reclock); + mutex_destroy(&etfs_lock); +} - /* XXX: init properly instead of this crap */ - rump_mnt.mnt_refcnt = 1; - rump_mnt.mnt_flag = MNT_ROOTFS; - rw_init(&rump_mnt.mnt_unmounting); - TAILQ_INIT(&rump_mnt.mnt_vnodelist); +int +rumpfs_mountroot() +{ + struct mount *mp; + struct rumpfs_mount *rfsmp; + struct rumpfs_node *rn; + int error; + + if ((error = vfs_rootmountalloc(MOUNT_RUMPFS, "rootdev", &mp)) != 0) { + vrele(rootvp); + return error; + } + + rfsmp = kmem_alloc(sizeof(*rfsmp), KM_SLEEP); - vfs_opv_init(rump_opv_descs); rn = makeprivate(VDIR, NODEV, DEV_BSIZE); mutex_enter(&reclock); - rv = makevnode(rn, &rootvnode); + error = makevnode(mp, rn, &rfsmp->rfsmp_rvp); mutex_exit(&reclock); - if (rv) - panic("could not create root vnode: %d", rv); - rootvnode->v_vflag |= VV_ROOT; - VOP_UNLOCK(rootvnode, 0); + rfsmp->rfsmp_rvp->v_vflag |= VV_ROOT; + if (error) + panic("could not create root vnode: %d", error); + 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); + + vfs_unbusy(mp, false, NULL); + + return 0; +} + +MODULE(MODULE_CLASS_VFS, rumpfs, NULL); + +static int +rumpfs_modcmd(modcmd_t cmd, void *arg) +{ + + switch (cmd) { + case MODULE_CMD_INIT: + return vfs_attach(&rumpfs_vfsops); + case MODULE_CMD_FINI: + return vfs_detach(&rumpfs_vfsops); + default: + return ENOTTY; + } }