- unify ffs_blkatoff and lfs_blkatoff.

- remove ufs_ops::uo_blkatoff.
- add directory read-ahead code.  (disabled for now.)
This commit is contained in:
yamt 2006-01-14 17:41:16 +00:00
parent e39c6d8223
commit 03f80508d6
10 changed files with 85 additions and 92 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_extern.h,v 1.50 2005/12/27 04:06:46 chs Exp $ */
/* $NetBSD: ffs_extern.h,v 1.51 2006/01/14 17:41:16 yamt Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -119,7 +119,6 @@ int ffs_truncate(struct vnode *, off_t, int, struct ucred *, struct lwp *);
/* ffs_subr.c */
void ffs_load_inode(struct buf *, struct inode *, struct fs *, ino_t);
int ffs_blkatoff(struct vnode *, off_t, char **, struct buf **);
int ffs_freefile(struct fs *, struct vnode *, ino_t, int);
void ffs_fragacct(struct fs *, int, int32_t[], int, int);
int ffs_isblock(struct fs *, u_char *, int32_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_subr.c,v 1.40 2005/12/27 04:06:46 chs Exp $ */
/* $NetBSD: ffs_subr.c,v 1.41 2006/01/14 17:41:16 yamt Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -36,7 +36,7 @@
#endif
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.40 2005/12/27 04:06:46 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.41 2006/01/14 17:41:16 yamt Exp $");
#include <sys/param.h>
@ -66,37 +66,6 @@ void panic(const char *, ...)
#include <ufs/ffs/ffs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
/*
* Return buffer with the contents of block "offset" from the beginning of
* directory "ip". If "res" is non-zero, fill it in with a pointer to the
* remaining space in the directory.
*/
int
ffs_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp)
{
struct inode *ip;
struct fs *fs;
struct buf *bp;
daddr_t lbn;
int bsize, error;
ip = VTOI(vp);
fs = ip->i_fs;
lbn = lblkno(fs, offset);
bsize = blksize(fs, ip, lbn);
*bpp = NULL;
if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
brelse(bp);
return (error);
}
if (res)
*res = (char *)bp->b_data + blkoff(fs, offset);
*bpp = bp;
return (0);
}
/*
* Load up the contents of an inode and copy the appropriate pieces
* to the incore copy.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_vfsops.c,v 1.178 2005/12/23 23:20:00 rpaulo Exp $ */
/* $NetBSD: ffs_vfsops.c,v 1.179 2006/01/14 17:41:16 yamt Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1994
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.178 2005/12/23 23:20:00 rpaulo Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.179 2006/01/14 17:41:16 yamt Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -125,7 +125,6 @@ static const struct ufs_ops ffs_ufsops = {
.uo_valloc = ffs_valloc,
.uo_vfree = ffs_vfree,
.uo_balloc = ffs_balloc,
.uo_blkatoff = ffs_blkatoff,
};
POOL_INIT(ffs_inode_pool, sizeof(struct inode), 0, 0, 0, "ffsinopl",

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_extern.h,v 1.74 2006/01/06 09:27:55 yamt Exp $ */
/* $NetBSD: lfs_extern.h,v 1.75 2006/01/14 17:41:17 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -205,7 +205,6 @@ void lfs_vunref(struct vnode *);
void lfs_vunref_head(struct vnode *);
/* lfs_subr.c */
int lfs_blkatoff(struct vnode *, off_t, char **, struct buf **);
void lfs_setup_resblks(struct lfs *);
void lfs_pad_check(unsigned char *, int, char *, int);
void lfs_free_resblks(struct lfs *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_subr.c,v 1.55 2005/12/11 12:25:26 christos Exp $ */
/* $NetBSD: lfs_subr.c,v 1.56 2006/01/14 17:41:17 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.55 2005/12/11 12:25:26 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.56 2006/01/14 17:41:17 yamt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -84,36 +84,6 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.55 2005/12/11 12:25:26 christos Exp $
#include <uvm/uvm.h>
/*
* Return buffer with the contents of block "offset" from the beginning of
* directory "ip". If "res" is non-zero, fill it in with a pointer to the
* remaining space in the directory.
*/
int
lfs_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp)
{
struct lfs *fs;
struct inode *ip;
struct buf *bp;
daddr_t lbn;
int bsize, error;
ip = VTOI(vp);
fs = ip->i_lfs;
lbn = lblkno(fs, offset);
bsize = blksize(fs, ip, lbn);
*bpp = NULL;
if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
brelse(bp);
return (error);
}
if (res)
*res = (char *)bp->b_data + blkoff(fs, offset);
*bpp = bp;
return (0);
}
#ifdef DEBUG
const char *lfs_res_names[LFS_NB_COUNT] = {
"summary",

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vfsops.c,v 1.191 2006/01/04 10:13:06 yamt Exp $ */
/* $NetBSD: lfs_vfsops.c,v 1.192 2006/01/14 17:41:17 yamt Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.191 2006/01/04 10:13:06 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.192 2006/01/14 17:41:17 yamt Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -174,7 +174,6 @@ static const struct ufs_ops lfs_ufsops = {
.uo_valloc = lfs_valloc,
.uo_vfree = lfs_vfree,
.uo_balloc = lfs_balloc,
.uo_blkatoff = lfs_blkatoff,
};
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_dirhash.c,v 1.9 2006/01/14 09:09:39 yamt Exp $ */
/* $NetBSD: ufs_dirhash.c,v 1.10 2006/01/14 17:41:18 yamt Exp $ */
/*
* Copyright (c) 2001, 2002 Ian Dowse. All rights reserved.
@ -202,7 +202,7 @@ ufsdirhash_build(struct inode *ip)
if ((pos & bmask) == 0) {
if (bp != NULL)
brelse(bp);
if (UFS_BLKATOFF(vp, (off_t)pos, NULL, &bp) != 0)
if (ufs_blkatoff(vp, (off_t)pos, NULL, &bp) != 0)
goto fail;
}
@ -397,7 +397,7 @@ restart:
if (bp != NULL)
brelse(bp);
blkoff = offset & ~bmask;
if (UFS_BLKATOFF(vp, (off_t)blkoff, NULL, &bp) != 0)
if (ufs_blkatoff(vp, (off_t)blkoff, NULL, &bp) != 0)
return (EJUSTRETURN);
}
dp = (struct direct *)(bp->b_data + (offset & bmask));
@ -506,7 +506,7 @@ ufsdirhash_findfree(struct inode *ip, int slotneeded, int *slotsize)
dh->dh_blkfree[dirblock] >= howmany(slotneeded, DIRALIGN));
DIRHASH_UNLOCK(dh);
pos = dirblock * dirblksiz;
error = UFS_BLKATOFF(ip->i_vnode, (off_t)pos, (void *)&dp, &bp);
error = ufs_blkatoff(ip->i_vnode, (off_t)pos, (void *)&dp, &bp);
if (error)
return (-1);
/* Find the first entry with free space. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_extern.h,v 1.47 2005/12/11 12:25:28 christos Exp $ */
/* $NetBSD: ufs_extern.h,v 1.48 2006/01/14 17:41:18 yamt Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -130,6 +130,7 @@ int ufs_dirremove(struct vnode *, struct inode *, int, int);
int ufs_dirrewrite(struct inode *, struct inode *, ino_t, int, int, int);
int ufs_dirempty(struct inode *, ino_t, struct ucred *);
int ufs_checkpath(struct inode *, struct inode *, struct ucred *);
int ufs_blkatoff(struct vnode *, off_t, char **, struct buf **);
/* ufs_quota.c */
int getinoquota(struct inode *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_lookup.c,v 1.72 2006/01/14 09:09:02 yamt Exp $ */
/* $NetBSD: ufs_lookup.c,v 1.73 2006/01/14 17:41:18 yamt Exp $ */
/*
* Copyright (c) 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.72 2006/01/14 09:09:02 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.73 2006/01/14 17:41:18 yamt Exp $");
#ifdef _KERNEL_OPT
#include "opt_ffs.h"
@ -244,7 +244,7 @@ ufs_lookup(void *v)
} else {
dp->i_offset = dp->i_diroff;
if ((entryoffsetinblock = dp->i_offset & bmask) &&
(error = UFS_BLKATOFF(vdp, (off_t)dp->i_offset, NULL, &bp)))
(error = ufs_blkatoff(vdp, (off_t)dp->i_offset, NULL, &bp)))
return (error);
numdirpasses = 2;
nchstats.ncs_2passes++;
@ -263,7 +263,7 @@ searchloop:
if ((dp->i_offset & bmask) == 0) {
if (bp != NULL)
brelse(bp);
error = UFS_BLKATOFF(vdp, (off_t)dp->i_offset, NULL,
error = ufs_blkatoff(vdp, (off_t)dp->i_offset, NULL,
&bp);
if (error)
return (error);
@ -895,7 +895,7 @@ ufs_direnter(struct vnode *dvp, struct vnode *tvp, struct direct *dirp,
/*
* Get the block containing the space for the new directory entry.
*/
error = UFS_BLKATOFF(dvp, (off_t)dp->i_offset, &dirbuf, &bp);
error = ufs_blkatoff(dvp, (off_t)dp->i_offset, &dirbuf, &bp);
if (error) {
if (DOINGSOFTDEP(dvp) && newdirbp != NULL)
bdwrite(newdirbp);
@ -1054,7 +1054,7 @@ ufs_dirremove(struct vnode *dvp, struct inode *ip, int flags, int isrmdir)
/*
* Whiteout entry: set d_ino to WINO.
*/
error = UFS_BLKATOFF(dvp, (off_t)dp->i_offset, (void *)&ep,
error = ufs_blkatoff(dvp, (off_t)dp->i_offset, (void *)&ep,
&bp);
if (error)
return (error);
@ -1063,7 +1063,7 @@ ufs_dirremove(struct vnode *dvp, struct inode *ip, int flags, int isrmdir)
goto out;
}
if ((error = UFS_BLKATOFF(dvp,
if ((error = ufs_blkatoff(dvp,
(off_t)(dp->i_offset - dp->i_count), (void *)&ep, &bp)) != 0)
return (error);
@ -1143,7 +1143,7 @@ ufs_dirrewrite(struct inode *dp, struct inode *oip, ino_t newinum, int newtype,
struct vnode *vdp = ITOV(dp);
int error;
error = UFS_BLKATOFF(vdp, (off_t)dp->i_offset, (void *)&ep, &bp);
error = ufs_blkatoff(vdp, (off_t)dp->i_offset, (void *)&ep, &bp);
if (error)
return (error);
ep->d_ino = ufs_rw32(newinum, UFS_MPNEEDSWAP(dp->i_ump));
@ -1311,3 +1311,63 @@ out:
vput(vp);
return (error);
}
#define UFS_DIRRABLKS 0
int ufs_dirrablks = UFS_DIRRABLKS;
/*
* ufs_blkatoff: Return buffer with the contents of block "offset" from
* the beginning of directory "vp". If "res" is non-zero, fill it in with
* a pointer to the remaining space in the directory.
*/
int
ufs_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp)
{
struct inode *ip;
struct buf *bp;
daddr_t lbn;
int error;
const int dirrablks = ufs_dirrablks;
daddr_t blks[1 + dirrablks];
int blksizes[1 + dirrablks];
int run;
struct mount *mp = vp->v_mount;
const int bshift = mp->mnt_fs_bshift;
const int bsize = 1 << bshift;
off_t eof;
ip = VTOI(vp);
KASSERT(vp->v_size == ip->i_size);
GOP_SIZE(vp, vp->v_size, &eof, GOP_SIZE_READ);
lbn = offset >> bshift;
for (run = 0; run <= dirrablks;) {
const off_t curoff = lbn << bshift;
const int size = MIN(eof - curoff, bsize);
if (size == 0) {
break;
}
KASSERT(curoff < eof);
blks[run] = lbn;
blksizes[run] = size;
lbn++;
run++;
if (size != bsize) {
break;
}
}
KASSERT(run >= 1);
error = breadn(vp, blks[0], blksizes[0], &blks[1], &blksizes[1],
run - 1, NOCRED, &bp);
if (error != 0) {
brelse(bp);
*bpp = NULL;
return error;
}
if (res) {
*res = (char *)bp->b_data + (offset & (bsize - 1));
}
*bpp = bp;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufsmount.h,v 1.25 2005/12/11 12:25:28 christos Exp $ */
/* $NetBSD: ufsmount.h,v 1.26 2006/01/14 17:41:19 yamt Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -117,7 +117,6 @@ struct ufs_ops {
int (*uo_vfree)(struct vnode *, ino_t, int);
int (*uo_balloc)(struct vnode *, off_t, int, struct ucred *, int,
struct buf **);
int (*uo_blkatoff)(struct vnode *, off_t, char **, struct buf **);
};
#define UFS_OPS(vp) (VFSTOUFS((vp)->v_mount)->um_ops)
@ -134,8 +133,6 @@ struct ufs_ops {
(*UFS_OPS(vp)->uo_vfree)((vp), (ino), (mode))
#define UFS_BALLOC(vp, off, size, cr, flags, bpp) \
(*UFS_OPS(vp)->uo_balloc)((vp), (off), (size), (cr), (flags), (bpp))
#define UFS_BLKATOFF(vp, off, res, bpp) \
(*UFS_OPS(vp)->uo_blkatoff)((vp), (off), (res), (bpp))
/* UFS-specific flags */
#define UFS_NEEDSWAP 0x01 /* filesystem metadata need byte-swapping */