Kill handrolled buffercache and use vfs_bio from the kernel. This is

mostly to get the flag jungle in sync with the kernel.
This commit is contained in:
pooka 2007-08-14 13:54:14 +00:00
parent 3340382aec
commit 243a4686b8
13 changed files with 121 additions and 257 deletions

View File

@ -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 <bsd.own.mk>
@ -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

View File

@ -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 <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/buf.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/queue.h>
#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__);
}

View File

@ -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 <machine/cpu.h>
#include <machine/stdarg.h>
#include <uvm/uvm_map.h>
#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

View File

@ -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",

View File

@ -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;
}

View File

@ -0,0 +1 @@
/* $NetBSD: fs_ffs.h,v 1.1 2007/08/14 13:54:15 pooka Exp $ */

View File

@ -0,0 +1 @@
/* $NetBSD: opt_bufcache.h,v 1.1 2007/08/14 13:54:15 pooka Exp $ */

View File

@ -0,0 +1 @@
/* $NetBSD: opt_softdep.h,v 1.1 2007/08/14 13:54:15 pooka Exp $ */

View File

@ -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 *);

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}