Introducing buf_adjcnt() from Bitrig.

It is needed to notify WAPBL that the buffer has size changes.

--
Walter Neto

diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index 9bf9b36..459b4fa 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -1206,6 +1206,14 @@ bcstats_print(
 }
 #endif
 
+void
+buf_adjcnt(struct buf *bp, long ncount)
+{
+       KASSERT(ncount <= bp->b_bufsize);
+       long ocount = bp->b_bcount;
+       bp->b_bcount = ncount;
+}
+
 /* bufcache freelist code below */
 /*
  * Copyright (c) 2014 Ted Unangst <t...@openbsd.org>
diff --git a/sys/sys/buf.h b/sys/sys/buf.h
index 5d71a5f..2336c9a 100644
--- a/sys/sys/buf.h
+++ b/sys/sys/buf.h
@@ -292,6 +292,7 @@ void        brelse(struct buf *);
 void   bufinit(void);
 void   buf_dirty(struct buf *);
 void    buf_undirty(struct buf *);
+void   buf_adjcnt(struct buf *, long);
 int    bwrite(struct buf *);
 struct buf *getblk(struct vnode *, daddr_t, int, int, int);
 struct buf *geteblk(int);
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index 87840a1..42e9a14 100644
--- a/sys/ufs/ffs/ffs_alloc.c
+++ b/sys/ufs/ffs/ffs_alloc.c
@@ -218,7 +218,7 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t 
bpref, int osize,
        if (bpp != NULL) {
                if ((error = bread(ITOV(ip), lbprev, fs->fs_bsize, &bp)) != 0)
                        goto error;
-               bp->b_bcount = osize;
+               buf_adjcnt(bp, osize);
        }
 
        if ((error = ufs_quota_alloc_blocks(ip, btodb(nsize - osize), cred))
@@ -241,7 +241,7 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t 
bpref, int osize,
                        if (nsize > bp->b_bufsize)
                                panic("ffs_realloccg: small buf");
 #endif
-                       bp->b_bcount = nsize;
+                       buf_adjcnt(bp, nsize);
                        bp->b_flags |= B_DONE;
                        memset(bp->b_data + osize, 0, nsize - osize);
                        *bpp = bp;
@@ -313,7 +313,7 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t 
bpref, int osize,
                if (nsize > bp->b_bufsize)
                        panic("ffs_realloccg: small buf 2");
 #endif
-               bp->b_bcount = nsize;
+               buf_adjcnt(bp, nsize);
                bp->b_flags |= B_DONE;
                memset(bp->b_data + osize, 0, nsize - osize);
                *bpp = bp;
diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c
index e4b21cd..f42bfcb 100644
--- a/sys/ufs/ffs/ffs_balloc.c
+++ b/sys/ufs/ffs/ffs_balloc.c
@@ -165,7 +165,7 @@ ffs1_balloc(struct inode *ip, off_t startoffset, int size, 
struct ucred *cred,
                                                brelse(*bpp);
                                                return (error);
                                        }
-                                       (*bpp)->b_bcount = osize;
+                                       buf_adjcnt((*bpp), osize);
                                }
                                return (0);
                        } else {
@@ -535,7 +535,7 @@ ffs2_balloc(struct inode *ip, off_t off, int size, struct 
ucred *cred,
                                                brelse(*bpp);
                                                return (error);
                                        }
-                                       (*bpp)->b_bcount = osize;
+                                       buf_adjcnt((*bpp), osize);
                                }
 
                                return (0);
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c
index 670a23e..6b66f99 100644
--- a/sys/ufs/ffs/ffs_inode.c
+++ b/sys/ufs/ffs/ffs_inode.c
@@ -262,7 +262,7 @@ ffs_truncate(struct inode *oip, off_t length, int flags, 
struct ucred *cred)
                (void) uvm_vnp_uncache(ovp);
                if (ovp->v_type != VDIR)
                        memset(bp->b_data + offset, 0, size - offset);
-               bp->b_bcount = size;
+               buf_adjcnt(bp, size);
                if (aflags & B_SYNC)
                        bwrite(bp);
                else
diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c
index c075f1e..dcbb4ac 100644
--- a/sys/ufs/ffs/ffs_subr.c
+++ b/sys/ufs/ffs/ffs_subr.c
@@ -72,7 +72,7 @@ ffs_bufatoff(struct inode *ip, off_t offset, char **res, 
struct buf **bpp)
                brelse(bp);
                return (error);
        }
-       bp->b_bcount = bsize;
+       buf_adjcnt(bp, bsize);
        if (res)
                *res = (char *)bp->b_data + blkoff(fs, offset);
        *bpp = bp;

Reply via email to