From owner-svn-src-head@FreeBSD.ORG Sun May 17 20:26:01 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 22A1F1065674; Sun, 17 May 2009 20:26:01 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 105868FC1A; Sun, 17 May 2009 20:26:01 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4HKQ0ub038806; Sun, 17 May 2009 20:26:00 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4HKQ0ik038803; Sun, 17 May 2009 20:26:00 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <200905172026.n4HKQ0ik038803@svn.freebsd.org> From: Alan Cox Date: Sun, 17 May 2009 20:26:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192260 - in head/sys: kern sys ufs/ffs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 May 2009 20:26:01 -0000 Author: alc Date: Sun May 17 20:26:00 2009 New Revision: 192260 URL: http://svn.freebsd.org/changeset/base/192260 Log: Introduce vfs_bio_set_valid() and use it from ffs_realloccg(). This eliminates the misuse of vfs_bio_clrbuf() by ffs_realloccg(). In collaboration with: tegge Modified: head/sys/kern/vfs_bio.c head/sys/sys/buf.h head/sys/ufs/ffs/ffs_alloc.c Modified: head/sys/kern/vfs_bio.c ============================================================================== --- head/sys/kern/vfs_bio.c Sun May 17 20:16:38 2009 (r192259) +++ head/sys/kern/vfs_bio.c Sun May 17 20:26:00 2009 (r192260) @@ -3625,6 +3625,44 @@ vfs_clean_pages(struct buf *bp) } /* + * vfs_bio_set_valid: + * + * Set the range within the buffer to valid. The range is + * relative to the beginning of the buffer, b_offset. Note that + * b_offset itself may be offset from the beginning of the first + * page. + */ +void +vfs_bio_set_valid(struct buf *bp, int base, int size) +{ + int i, n; + vm_page_t m; + + if (!(bp->b_flags & B_VMIO)) + return; + + /* + * Fixup base to be relative to beginning of first page. + * Set initial n to be the maximum number of bytes in the + * first page that can be validated. + */ + base += (bp->b_offset & PAGE_MASK); + n = PAGE_SIZE - (base & PAGE_MASK); + + VM_OBJECT_LOCK(bp->b_bufobj->bo_object); + for (i = base / PAGE_SIZE; size > 0 && i < bp->b_npages; ++i) { + m = bp->b_pages[i]; + if (n > size) + n = size; + vm_page_set_valid(m, base & PAGE_MASK, n); + base += n; + size -= n; + n = PAGE_SIZE; + } + VM_OBJECT_UNLOCK(bp->b_bufobj->bo_object); +} + +/* * vfs_bio_set_validclean: * * Set the range within the buffer to valid and clean. The range is Modified: head/sys/sys/buf.h ============================================================================== --- head/sys/sys/buf.h Sun May 17 20:16:38 2009 (r192259) +++ head/sys/sys/buf.h Sun May 17 20:26:00 2009 (r192260) @@ -498,6 +498,7 @@ int cluster_read(struct vnode *, u_quad_ struct ucred *, long, int, struct buf **); int cluster_wbuild(struct vnode *, long, daddr_t, int); void cluster_write(struct vnode *, struct buf *, u_quad_t, int); +void vfs_bio_set_valid(struct buf *, int base, int size); void vfs_bio_set_validclean(struct buf *, int base, int size); void vfs_bio_clrbuf(struct buf *); void vfs_busy_pages(struct buf *, int clear_modify); Modified: head/sys/ufs/ffs/ffs_alloc.c ============================================================================== --- head/sys/ufs/ffs/ffs_alloc.c Sun May 17 20:16:38 2009 (r192259) +++ head/sys/ufs/ffs/ffs_alloc.c Sun May 17 20:26:00 2009 (r192260) @@ -326,10 +326,9 @@ retry: ip->i_flag |= IN_CHANGE | IN_UPDATE; allocbuf(bp, nsize); bp->b_flags |= B_DONE; - if ((bp->b_flags & (B_MALLOC | B_VMIO)) != B_VMIO) - bzero((char *)bp->b_data + osize, nsize - osize); - else - vfs_bio_clrbuf(bp); + bzero(bp->b_data + osize, nsize - osize); + if ((bp->b_flags & (B_MALLOC | B_VMIO)) == B_VMIO) + vfs_bio_set_valid(bp, osize, nsize - osize); *bpp = bp; return (0); } @@ -404,10 +403,9 @@ retry: ip->i_flag |= IN_CHANGE | IN_UPDATE; allocbuf(bp, nsize); bp->b_flags |= B_DONE; - if ((bp->b_flags & (B_MALLOC | B_VMIO)) != B_VMIO) - bzero((char *)bp->b_data + osize, nsize - osize); - else - vfs_bio_clrbuf(bp); + bzero(bp->b_data + osize, nsize - osize); + if ((bp->b_flags & (B_MALLOC | B_VMIO)) == B_VMIO) + vfs_bio_set_valid(bp, osize, nsize - osize); *bpp = bp; return (0); }