From 243a4686b8e482f18a001d6e40ceedd10c76ed5e Mon Sep 17 00:00:00 2001 From: pooka Date: Tue, 14 Aug 2007 13:54:14 +0000 Subject: [PATCH] Kill handrolled buffercache and use vfs_bio from the kernel. This is mostly to get the flag jungle in sync with the kernel. --- sys/rump/librump/rumpkern/Makefile | 12 +- sys/rump/librump/rumpkern/buffercache.c | 201 ------------------- sys/rump/librump/rumpkern/emul.c | 12 +- sys/rump/librump/rumpkern/genfs.c | 12 +- sys/rump/librump/rumpkern/misc_stub.c | 9 +- sys/rump/librump/rumpkern/opt/fs_ffs.h | 1 + sys/rump/librump/rumpkern/opt/opt_bufcache.h | 1 + sys/rump/librump/rumpkern/opt/opt_softdep.h | 1 + sys/rump/librump/rumpkern/pool.c | 16 +- sys/rump/librump/rumpkern/rump.c | 3 +- sys/rump/librump/rumpkern/specfs.c | 25 ++- sys/rump/librump/rumpkern/vfs.c | 52 ++--- sys/rump/librump/rumpkern/vm.c | 33 ++- 13 files changed, 121 insertions(+), 257 deletions(-) delete mode 100644 sys/rump/librump/rumpkern/buffercache.c create mode 100644 sys/rump/librump/rumpkern/opt/fs_ffs.h create mode 100644 sys/rump/librump/rumpkern/opt/opt_bufcache.h create mode 100644 sys/rump/librump/rumpkern/opt/opt_softdep.h diff --git a/sys/rump/librump/rumpkern/Makefile b/sys/rump/librump/rumpkern/Makefile index cfd83c480209..efe52b68b206 100644 --- a/sys/rump/librump/rumpkern/Makefile +++ b/sys/rump/librump/rumpkern/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2007/08/14 13:24:34 pooka Exp $ +# $NetBSD: Makefile,v 1.9 2007/08/14 13:54:14 pooka Exp $ # .include @@ -7,10 +7,11 @@ LIB= rump .PATH: ${NETBSDSRCDIR}/sys/kern ${NETBSDSRCDIR}/sys/lib/libkern \ - ${NETBSDSRCDIR}/sys/conf ${NETBSDSRCDIR}/sys/dev + ${NETBSDSRCDIR}/sys/conf ${NETBSDSRCDIR}/sys/dev \ + ${NETBSDSRCDIR}/sys/miscfs/syncfs # implements something -SRCS= rump.c buffercache.c emul.c vfs.c genfs.c vm.c pool.c specfs.c +SRCS= rump.c emul.c vfs.c genfs.c vm.c pool.c specfs.c # just stubs SRCS+= fstrans_stub.c kauth_stub.c lock_stub.c misc_stub.c \ @@ -18,8 +19,9 @@ SRCS+= fstrans_stub.c kauth_stub.c lock_stub.c misc_stub.c \ # sys/kern SRCS+= clock_subr.c param.c subr_hash.c subr_prf_bitmask.c \ - subr_specificdata.c subr_time.c subr_xxx.c vfs_init.c \ - vfs_cache.c vfs_subr2.c vnode_if.c param.c vfs_vnops.c + subr_specificdata.c subr_time.c subr_xxx.c sync_subr.c \ + vfs_bio.c vfs_cache.c vfs_vnops.c vfs_init.c vfs_subr2.c \ + vnode_if.c param.c # src/lib/libkern SRCS+= __assert.c scanc.c skpc.c diff --git a/sys/rump/librump/rumpkern/buffercache.c b/sys/rump/librump/rumpkern/buffercache.c deleted file mode 100644 index ae06aacdae6d..000000000000 --- a/sys/rump/librump/rumpkern/buffercache.c +++ /dev/null @@ -1,201 +0,0 @@ -/* $NetBSD: buffercache.c,v 1.3 2007/08/09 09:11:57 pooka Exp $ */ - -/* - * Copyright (c) 2007 Antti Kantee. All Rights Reserved. - * - * Development of this software was supported by Google Summer of Code. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rumpuser.h" - -#define BQUEUES 3 -struct bqueue { - TAILQ_HEAD(,buf) bq_queue; - uint64_t bq_bytes; -} bufqueues[BQUEUES]; - -int -bread(struct vnode *vp, daddr_t blkno, int size, struct kauth_cred *cred, - struct buf **bpp) -{ - struct buf *bp; - - bp = getblk(vp, blkno, size, 0, 0); - bp->b_flags = B_READ; - VOP_STRATEGY(vp, bp); - bp->b_flags = B_BUSY; - - *bpp = bp; - return 0; -} - -int -breadn(struct vnode *vp, daddr_t blkno, int size, daddr_t *rablks, - int *rasizes, int nrablks, struct kauth_cred *cred, struct buf **bpp) -{ - - return bread(vp, blkno, size, cred, bpp); -} - -int -bwrite(struct buf *bp) -{ - - bp->b_flags &= ~B_READ; - VOP_STRATEGY(bp->b_vp, bp); - brelse(bp); - - return 0; -} - -void -bawrite(struct buf *bp) -{ - - bwrite(bp); -} - -void -bdwrite(struct buf *bp) -{ - - bwrite(bp); -} - -void -brelse(struct buf *bp) -{ - - rumpuser_free(bp->b_data); - rumpuser_free(bp); -} - -struct buf * -getblk(struct vnode *vp, daddr_t blkno, int size, int slpflag, int slptimeo) -{ - struct buf *bp; - - bp = rumpuser_malloc(sizeof(struct buf), 0); - memset(bp, 0x55, sizeof(struct buf)); - bp->b_data = rumpuser_malloc(size, 0); - bp->b_blkno = bp->b_lblkno = blkno; - bp->b_bcount = bp->b_bufsize = size; - bp->b_vp = vp; - - return bp; -} - -struct buf * -incore(struct vnode *vp, daddr_t blkno) -{ - - return NULL; -} - -void -allocbuf(struct buf *bp, int size, int preserve) -{ - - bp->b_bcount = bp->b_bufsize = size; - bp->b_data = rumpuser_realloc(bp->b_data, size, 0); -} - -void -biodone(struct buf *bp) -{ - - /* nada */ -} - -/* everything is always instantly done */ -int -biowait(struct buf *bp) -{ - - return 0; -} - -struct buf * -getiobuf() -{ - - return rumpuser_malloc(sizeof(struct buf), 0); -} - -struct buf * -getiobuf_nowait() -{ - - return rumpuser_malloc(sizeof(struct buf), 1); -} - -void -putiobuf(struct buf *bp) -{ - - rumpuser_free(bp); -} - -void -bgetvp(struct vnode *vp, struct buf *bp) -{ - - if (bp->b_vp) - panic("%s: vp already set", __func__); - - bp->b_vp = vp; -} - -void -bremfree(struct buf *bp) -{ - - return; -} - -void -brelvp(struct buf *bp) -{ - - if (bp->b_vp == NULL) - panic("%s: vp not set", __func__); - - bp->b_vp = NULL; -} - -void -reassignbuf(struct buf *bp, struct vnode *vp) -{ - - panic("%s: not implemented", __func__); -} diff --git a/sys/rump/librump/rumpkern/emul.c b/sys/rump/librump/rumpkern/emul.c index f15c42b6cb14..c2888b3f4caa 100644 --- a/sys/rump/librump/rumpkern/emul.c +++ b/sys/rump/librump/rumpkern/emul.c @@ -1,4 +1,4 @@ -/* $NetBSD: emul.c,v 1.7 2007/08/13 13:51:39 pooka Exp $ */ +/* $NetBSD: emul.c,v 1.8 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -44,6 +44,8 @@ #include #include +#include + #include "rump.h" #include "rumpuser.h" @@ -55,6 +57,8 @@ struct lwp lwp0; struct vnode *rootvp; struct device *root_device; dev_t rootdev; +struct vm_map *kernel_map; +int physmem; MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount struct"); MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure"); @@ -277,11 +281,11 @@ bdev_strategy(struct buf *bp) panic("%s: not supported", __func__); } -void -vn_syncer_remove_from_worklist(struct vnode *vp) +int +bdev_type(dev_t dev) { - /* nada */ + return D_DISK; } int diff --git a/sys/rump/librump/rumpkern/genfs.c b/sys/rump/librump/rumpkern/genfs.c index b4c354516467..87c678957b6e 100644 --- a/sys/rump/librump/rumpkern/genfs.c +++ b/sys/rump/librump/rumpkern/genfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: genfs.c,v 1.13 2007/08/13 13:51:39 pooka Exp $ */ +/* $NetBSD: genfs.c,v 1.14 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -192,11 +192,13 @@ genfs_getpages(void *v) continue; } + memset(&buf, 0, sizeof(buf)); buf.b_data = tmpbuf + bufoff; buf.b_bcount = xfersize; buf.b_blkno = bn; buf.b_lblkno = 0; buf.b_flags = B_READ; + buf.b_vp = vp; VOP_STRATEGY(devvp, &buf); if (buf.b_error) @@ -265,8 +267,6 @@ genfs_do_putpages(struct vnode *vp, off_t startoff, off_t endoff, int flags, int bshift = vp->v_mount->mnt_fs_bshift; int bsize = 1 << bshift; - GOP_SIZE(vp, vp->v_writesize, &eof, 0); - restart: /* check if all pages are clean */ smallest = -1; @@ -287,6 +287,8 @@ genfs_do_putpages(struct vnode *vp, off_t startoff, off_t endoff, int flags, return 0; } + GOP_SIZE(vp, vp->v_writesize, &eof, 0); + /* we need to flush */ for (curoff = smallest; curoff < eof; curoff += PAGE_SIZE) { if (curoff - smallest >= MAXPHYS) @@ -306,6 +308,8 @@ genfs_do_putpages(struct vnode *vp, off_t startoff, off_t endoff, int flags, daddr_t bn, lbn; int run, error; + memset(&buf, 0, sizeof(buf)); + lbn = (smallest + bufoff) >> bshift; error = VOP_BMAP(vp, lbn, &devvp, &bn, &run); if (error) @@ -332,7 +336,9 @@ genfs_do_putpages(struct vnode *vp, off_t startoff, off_t endoff, int flags, buf.b_blkno = bn + (((smallest+bufoff)&(bsize-1))>>DEV_BSHIFT); buf.b_data = databuf + bufoff; buf.b_flags = B_WRITE; + buf.b_vp = vp; + vp->v_numoutput++; VOP_STRATEGY(devvp, &buf); if (buf.b_error) panic("%s: VOP_STRATEGY lazy bum %d", diff --git a/sys/rump/librump/rumpkern/misc_stub.c b/sys/rump/librump/rumpkern/misc_stub.c index 46dc85f7829e..b0034519818d 100644 --- a/sys/rump/librump/rumpkern/misc_stub.c +++ b/sys/rump/librump/rumpkern/misc_stub.c @@ -1,4 +1,4 @@ -/* $NetBSD: misc_stub.c,v 1.2 2007/08/09 08:56:45 pooka Exp $ */ +/* $NetBSD: misc_stub.c,v 1.3 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -71,3 +71,10 @@ sysctl_lookup(SYSCTLFN_ARGS) return ENOSYS; } + +int +sysctl_query(SYSCTLFN_ARGS) +{ + + return ENOSYS; +} diff --git a/sys/rump/librump/rumpkern/opt/fs_ffs.h b/sys/rump/librump/rumpkern/opt/fs_ffs.h new file mode 100644 index 000000000000..7f65af5c65db --- /dev/null +++ b/sys/rump/librump/rumpkern/opt/fs_ffs.h @@ -0,0 +1 @@ +/* $NetBSD: fs_ffs.h,v 1.1 2007/08/14 13:54:15 pooka Exp $ */ diff --git a/sys/rump/librump/rumpkern/opt/opt_bufcache.h b/sys/rump/librump/rumpkern/opt/opt_bufcache.h new file mode 100644 index 000000000000..c51dfe0639f5 --- /dev/null +++ b/sys/rump/librump/rumpkern/opt/opt_bufcache.h @@ -0,0 +1 @@ +/* $NetBSD: opt_bufcache.h,v 1.1 2007/08/14 13:54:15 pooka Exp $ */ diff --git a/sys/rump/librump/rumpkern/opt/opt_softdep.h b/sys/rump/librump/rumpkern/opt/opt_softdep.h new file mode 100644 index 000000000000..9ab04d3fd167 --- /dev/null +++ b/sys/rump/librump/rumpkern/opt/opt_softdep.h @@ -0,0 +1 @@ +/* $NetBSD: opt_softdep.h,v 1.1 2007/08/14 13:54:15 pooka Exp $ */ diff --git a/sys/rump/librump/rumpkern/pool.c b/sys/rump/librump/rumpkern/pool.c index beacc3ad4fb1..05df2ece1ddc 100644 --- a/sys/rump/librump/rumpkern/pool.c +++ b/sys/rump/librump/rumpkern/pool.c @@ -1,4 +1,4 @@ -/* $NetBSD: pool.c,v 1.1 2007/08/05 22:28:09 pooka Exp $ */ +/* $NetBSD: pool.c,v 1.2 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -109,6 +109,20 @@ pool_put(struct pool *pp, void *item) rumpuser_free(item); } +void +pool_sethiwat(struct pool *pp, int n) +{ + + return; +} + +void +pool_setlowat(struct pool *pp, int n) +{ + + return; +} + /* XXX: for tmpfs, shouldn't be here */ void *pool_page_alloc_nointr(struct pool *, int); void pool_page_free_nointr(struct pool *, void *); diff --git a/sys/rump/librump/rumpkern/rump.c b/sys/rump/librump/rumpkern/rump.c index c92424e65870..4d8b55cf066d 100644 --- a/sys/rump/librump/rumpkern/rump.c +++ b/sys/rump/librump/rumpkern/rump.c @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.4 2007/08/08 14:09:07 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.5 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -75,6 +75,7 @@ rump_init() rump_proc.p_limit = &rump_limits; vfsinit(); + bufinit(); rumpuser_gethostname(hostname, MAXHOSTNAMELEN, &error); hostnamelen = strlen(hostname); diff --git a/sys/rump/librump/rumpkern/specfs.c b/sys/rump/librump/rumpkern/specfs.c index cf96e5e02c99..0825b143252d 100644 --- a/sys/rump/librump/rumpkern/specfs.c +++ b/sys/rump/librump/rumpkern/specfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: specfs.c,v 1.4 2007/08/14 13:24:07 pooka Exp $ */ +/* $NetBSD: specfs.c,v 1.5 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -46,17 +46,20 @@ static int rump_specopen(void *); static int rump_specioctl(void *); static int rump_specclose(void *); static int rump_specfsync(void *); +static int rump_specputpages(void *); static int rump_specstrategy(void *); int (**spec_vnodeop_p)(void *); const struct vnodeopv_entry_desc rumpspec_vnodeop_entries[] = { { &vop_default_desc, vn_default_error }, + { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ { &vop_lock_desc, genfs_lock }, /* lock */ { &vop_unlock_desc, genfs_unlock }, /* unlock */ { &vop_open_desc, rump_specopen }, /* open */ { &vop_close_desc, rump_specclose }, /* close */ { &vop_ioctl_desc, rump_specioctl }, /* ioctl */ { &vop_fsync_desc, rump_specfsync }, /* fsync */ + { &vop_putpages_desc, rump_specputpages }, /* putpages */ { &vop_strategy_desc, rump_specstrategy }, /* strategy */ { NULL, NULL } }; @@ -149,6 +152,25 @@ rump_specclose(void *v) int rump_specfsync(void *v) +{ + struct vop_fsync_args /* { + struct vnode *a_vp; + kauth_cred_t a_cred; + int a_flags; + off_t a_offlo; + off_t a_offhi; + struct lwp *a_l; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + + assert(vp->v_type == VBLK); + vflushbuf(vp, 1); + + return 0; +} + +int +rump_specputpages(void *v) { return 0; @@ -187,6 +209,7 @@ rump_specstrategy(void *v) bp->b_error = error; else bp->b_resid = bp->b_bcount - rv; + biodone(bp); return error; } diff --git a/sys/rump/librump/rumpkern/vfs.c b/sys/rump/librump/rumpkern/vfs.c index 76b474e0406b..277b5f8fa47c 100644 --- a/sys/rump/librump/rumpkern/vfs.c +++ b/sys/rump/librump/rumpkern/vfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs.c,v 1.9 2007/08/13 13:51:39 pooka Exp $ */ +/* $NetBSD: vfs.c,v 1.10 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -156,6 +156,18 @@ vgone(struct vnode *vp) } +void +vholdl(struct vnode *vp) +{ + +} + +void +holdrelel(struct vnode *vp) +{ + +} + int vrecycle(struct vnode *vp, struct simplelock *inter_lkp, struct lwp *l) { @@ -170,37 +182,6 @@ vrecycle(struct vnode *vp, struct simplelock *inter_lkp, struct lwp *l) return 0; } -int -vinvalbuf(struct vnode *vp, int flags, kauth_cred_t cred, struct lwp *l, - int slpflag, int slptimeo) -{ - - return 0; -} - -int -vtruncbuf(struct vnode *vp, daddr_t lbn, int splflag, int slptimeo) -{ - - return 0; -} - -void -vflushbuf(struct vnode *vp, int sync) -{ - - (void) VOP_PUTPAGES(vp, 0, 0, - PGO_CLEANIT | PGO_ALLPAGES | sync ? PGO_SYNCIO : 0); -} - -int -vn_bwrite(void *v) -{ - struct vop_bwrite_args *ap = v; - - return bwrite(ap->a_bp); -} - int vcount(struct vnode *vp) { @@ -396,10 +377,3 @@ vfs_mountedon(struct vnode *vp) return 0; } - -void -vn_initialize_syncerd() -{ - - return; -} diff --git a/sys/rump/librump/rumpkern/vm.c b/sys/rump/librump/rumpkern/vm.c index ee9da8368c6e..af606df6c831 100644 --- a/sys/rump/librump/rumpkern/vm.c +++ b/sys/rump/librump/rumpkern/vm.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm.c,v 1.11 2007/08/13 13:51:39 pooka Exp $ */ +/* $NetBSD: vm.c,v 1.12 2007/08/14 13:54:15 pooka Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -467,3 +467,34 @@ kmem_free(void *p, size_t size) rumpuser_free(p); } + +/* + * UVM km + */ + +vaddr_t +uvm_km_alloc(struct vm_map *map, vsize_t size, vsize_t align, uvm_flag_t flags) +{ + void *rv; + + rv = rumpuser_malloc(size, flags & (UVM_KMF_CANFAIL | UVM_KMF_NOWAIT)); + if (rv && flags & UVM_KMF_ZERO) + memset(rv, 0, size); + + return (vaddr_t)rv; +} + +void +uvm_km_free(struct vm_map *map, vaddr_t vaddr, vsize_t size, uvm_flag_t flags) +{ + + rumpuser_free((void *)vaddr); +} + +struct vm_map * +uvm_km_suballoc(struct vm_map *map, vaddr_t *minaddr, vaddr_t *maxaddr, + vsize_t size, int pageable, bool fixed, struct vm_map_kernel *submap) +{ + + return (struct vm_map *)417416; +}