summaryrefslogtreecommitdiff
path: root/sys/ufs/ffs
diff options
context:
space:
mode:
authorPedro Martelletto <pedro@cvs.openbsd.org>2007-05-26 20:26:52 +0000
committerPedro Martelletto <pedro@cvs.openbsd.org>2007-05-26 20:26:52 +0000
commit196f5066228d908cbac060396a1aba557efe1ef3 (patch)
tree5c48aa4f82af6d902afe35afb642c3d4225a1a07 /sys/ufs/ffs
parent6e18a0b85a66c596fb041fbf27229487f6661bbf (diff)
Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.
Diffstat (limited to 'sys/ufs/ffs')
-rw-r--r--sys/ufs/ffs/ffs_alloc.c27
-rw-r--r--sys/ufs/ffs/ffs_balloc.c20
-rw-r--r--sys/ufs/ffs/ffs_inode.c4
-rw-r--r--sys/ufs/ffs/ffs_softdep.c10
-rw-r--r--sys/ufs/ffs/ffs_subr.c10
-rw-r--r--sys/ufs/ffs/ffs_vnops.c11
6 files changed, 47 insertions, 35 deletions
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index fb36da6df60..7e361d55289 100644
--- a/sys/ufs/ffs/ffs_alloc.c
+++ b/sys/ufs/ffs/ffs_alloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_alloc.c,v 1.72 2007/04/29 17:58:09 deraadt Exp $ */
+/* $OpenBSD: ffs_alloc.c,v 1.73 2007/05/26 20:26:51 pedro Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */
/*
@@ -211,9 +211,12 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bpref, int osize,
/*
* Allocate the extra space in the buffer.
*/
- if (bpp != NULL &&
- (error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp)) != 0)
- goto error;
+ if (bpp != NULL) {
+ if ((error = bread(ITOV(ip), lbprev, fs->fs_bsize,
+ NOCRED, &bp)) != 0)
+ goto error;
+ bp->b_bcount = osize;
+ }
if ((error = ufs_quota_alloc_blocks(ip, btodb(nsize - osize), cred))
!= 0)
@@ -231,9 +234,13 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bpref, int osize,
if (bpp != NULL) {
if (bp->b_blkno != fsbtodb(fs, bno))
panic("ffs_realloccg: bad blockno");
- allocbuf(bp, nsize);
+#ifdef DIAGNOSTIC
+ if (nsize > bp->b_bufsize)
+ panic("ffs_realloccg: small buf");
+#endif
+ bp->b_bcount = nsize;
bp->b_flags |= B_DONE;
- bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
+ bzero(bp->b_data + osize, (u_int)nsize - osize);
*bpp = bp;
}
if (blknop != NULL) {
@@ -300,9 +307,13 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bpref, int osize,
ip->i_flag |= IN_CHANGE | IN_UPDATE;
if (bpp != NULL) {
bp->b_blkno = fsbtodb(fs, bno);
- allocbuf(bp, nsize);
+#ifdef DIAGNOSTIC
+ if (nsize > bp->b_bufsize)
+ panic("ffs_realloccg: small buf 2");
+#endif
+ bp->b_bcount = nsize;
bp->b_flags |= B_DONE;
- bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
+ bzero(bp->b_data + osize, (u_int)nsize - osize);
*bpp = bp;
}
if (blknop != NULL) {
diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c
index 2bba9412313..c4d0e1af4f0 100644
--- a/sys/ufs/ffs/ffs_balloc.c
+++ b/sys/ufs/ffs/ffs_balloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_balloc.c,v 1.31 2007/01/17 20:47:13 sturm Exp $ */
+/* $OpenBSD: ffs_balloc.c,v 1.32 2007/05/26 20:26:51 pedro Exp $ */
/* $NetBSD: ffs_balloc.c,v 1.3 1996/02/09 22:22:21 christos Exp $ */
/*
@@ -164,12 +164,13 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred,
* Just read the block (if requested).
*/
if (bpp != NULL) {
- error = bread(vp, lbn, osize, NOCRED,
- bpp);
+ error = bread(vp, lbn, fs->fs_bsize,
+ NOCRED, bpp);
if (error) {
brelse(*bpp);
return (error);
}
+ (*bpp)->b_bcount = osize;
}
return (0);
} else {
@@ -204,7 +205,9 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, struct ucred *cred,
if (error)
return (error);
if (bpp != NULL) {
- *bpp = getblk(vp, lbn, nsize, 0, 0);
+ *bpp = getblk(vp, lbn, fs->fs_bsize, 0, 0);
+ if (nsize < fs->fs_bsize)
+ (*bpp)->b_bcount = nsize;
(*bpp)->b_blkno = fsbtodb(fs, newb);
if (flags & B_CLRBUF)
clrbuf(*bpp);
@@ -534,12 +537,13 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred,
* big as we want. Just read it, if requested.
*/
if (bpp != NULL) {
- error = bread(vp, lbn, osize, NOCRED,
- bpp);
+ error = bread(vp, lbn, fs->fs_bsize,
+ NOCRED, bpp);
if (error) {
brelse(*bpp);
return (error);
}
+ (*bpp)->b_bcount = osize;
}
return (0);
@@ -576,7 +580,9 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct ucred *cred,
return (error);
if (bpp != NULL) {
- bp = getblk(vp, lbn, nsize, 0, 0);
+ bp = getblk(vp, lbn, fs->fs_bsize, 0, 0);
+ if (nsize < fs->fs_bsize)
+ bp->b_bcount = nsize;
bp->b_blkno = fsbtodb(fs, newb);
if (flags & B_CLRBUF)
clrbuf(bp);
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c
index 5777ac10ce9..6d0371158cb 100644
--- a/sys/ufs/ffs/ffs_inode.c
+++ b/sys/ufs/ffs/ffs_inode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_inode.c,v 1.46 2006/09/20 22:54:29 pedro Exp $ */
+/* $OpenBSD: ffs_inode.c,v 1.47 2007/05/26 20:26:51 pedro Exp $ */
/* $NetBSD: ffs_inode.c,v 1.10 1996/05/11 18:27:19 mycroft Exp $ */
/*
@@ -296,7 +296,7 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred)
if (ovp->v_type != VDIR)
bzero((char *)bp->b_data + offset,
(u_int)(size - offset));
- allocbuf(bp, size);
+ bp->b_bcount = size;
if (aflags & B_SYNC)
bwrite(bp);
else
diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c
index 46fb3e75982..dc3f798e830 100644
--- a/sys/ufs/ffs/ffs_softdep.c
+++ b/sys/ufs/ffs/ffs_softdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_softdep.c,v 1.86 2007/04/15 10:48:35 pedro Exp $ */
+/* $OpenBSD: ffs_softdep.c,v 1.87 2007/05/26 20:26:51 pedro Exp $ */
/*
* Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved.
@@ -4655,11 +4655,11 @@ softdep_fsync(vp)
/*
* Flush directory page containing the inode's name.
*/
- error = bread(pvp, lbn, blksize(fs, pip, lbn), p->p_ucred,
- &bp);
- if (error == 0)
+ error = bread(pvp, lbn, fs->fs_bsize, p->p_ucred, &bp);
+ if (error == 0) {
+ bp->b_bcount = blksize(fs, pip, lbn);
error = bwrite(bp);
- else
+ } else
brelse(bp);
vput(pvp);
if (error != 0)
diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c
index 3a6d55d89bd..68236370737 100644
--- a/sys/ufs/ffs/ffs_subr.c
+++ b/sys/ufs/ffs/ffs_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_subr.c,v 1.19 2007/01/06 23:30:42 tedu Exp $ */
+/* $OpenBSD: ffs_subr.c,v 1.20 2007/05/26 20:26:51 pedro Exp $ */
/* $NetBSD: ffs_subr.c,v 1.6 1996/03/17 02:16:23 christos Exp $ */
/*
@@ -68,10 +68,11 @@ ffs_bufatoff(struct inode *ip, off_t offset, char **res, struct buf **bpp)
bsize = blksize(fs, ip, lbn);
*bpp = NULL;
- if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
+ if ((error = bread(vp, lbn, fs->fs_bsize, NOCRED, &bp)) != 0) {
brelse(bp);
return (error);
}
+ bp->b_bcount = bsize;
if (res)
*res = (char *)bp->b_data + blkoff(fs, offset);
*bpp = bp;
@@ -122,14 +123,13 @@ ffs_fragacct(struct fs *fs, int fragmap, int32_t fraglist[], int cnt)
void
ffs_checkoverlap(struct buf *bp, struct inode *ip)
{
- struct buf *ebp, *ep;
daddr_t start, last;
struct vnode *vp;
+ struct buf *ep;
- ebp = &buf[nbuf];
start = bp->b_blkno;
last = start + btodb(bp->b_bcount) - 1;
- for (ep = buf; ep < ebp; ep++) {
+ LIST_FOREACH(ep, &bufhead, b_list) {
if (ep == bp || (ep->b_flags & B_INVAL) ||
ep->b_vp == NULLVP)
continue;
diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index 7cb8ca1f6a7..1cf7a53c974 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_vnops.c,v 1.43 2007/04/13 17:09:22 thib Exp $ */
+/* $OpenBSD: ffs_vnops.c,v 1.44 2007/05/26 20:26:51 pedro Exp $ */
/* $NetBSD: ffs_vnops.c,v 1.7 1996/05/11 18:27:24 mycroft Exp $ */
/*
@@ -214,7 +214,7 @@ ffs_read(void *v)
break;
lbn = lblkno(fs, uio->uio_offset);
nextlbn = lbn + 1;
- size = blksize(fs, ip, lbn);
+ size = fs->fs_bsize; /* WAS blksize(fs, ip, lbn); */
blkoffset = blkoff(fs, uio->uio_offset);
xfersize = fs->fs_bsize - blkoffset;
if (uio->uio_resid < xfersize)
@@ -224,13 +224,8 @@ ffs_read(void *v)
if (lblktosize(fs, nextlbn) >= DIP(ip, size))
error = bread(vp, lbn, size, NOCRED, &bp);
- else if (doclusterread)
- error = cluster_read(vp, &ip->i_ci,
- DIP(ip, size), lbn, size, NOCRED, &bp);
else if (lbn - 1 == ip->i_ci.ci_lastr) {
- int nextsize = blksize(fs, ip, nextlbn);
- error = breadn(vp, lbn,
- size, &nextlbn, &nextsize, 1, NOCRED, &bp);
+ error = bread_cluster(vp, lbn, size, &bp);
} else
error = bread(vp, lbn, size, NOCRED, &bp);