From owner-svn-src-head@FreeBSD.ORG Tue Mar 19 13:06:12 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id BC406E0; Tue, 19 Mar 2013 13:06:12 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 8B81B1A0; Tue, 19 Mar 2013 13:06:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r2JD6Ca9091015; Tue, 19 Mar 2013 13:06:12 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r2JD6CHj091013; Tue, 19 Mar 2013 13:06:12 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201303191306.r2JD6CHj091013@svn.freebsd.org> From: Ed Maste Date: Tue, 19 Mar 2013 13:06:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r248500 - in head/sys: fs/nfsclient nfsclient X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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: Tue, 19 Mar 2013 13:06:12 -0000 Author: emaste Date: Tue Mar 19 13:06:11 2013 New Revision: 248500 URL: http://svnweb.freebsd.org/changeset/base/248500 Log: Fix remainder calculation when biosize is not a power of 2 In common configurations biosize is a power of two, but is not required to be so. Thanks to markj@ for spotting an additional case beyond my original patch. Reviewed by: rmacklem@ Modified: head/sys/fs/nfsclient/nfs_clbio.c head/sys/nfsclient/nfs_bio.c Modified: head/sys/fs/nfsclient/nfs_clbio.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clbio.c Tue Mar 19 12:52:13 2013 (r248499) +++ head/sys/fs/nfsclient/nfs_clbio.c Tue Mar 19 13:06:11 2013 (r248500) @@ -484,7 +484,7 @@ ncl_bioread(struct vnode *vp, struct uio case VREG: NFSINCRGLOBAL(newnfsstats.biocache_reads); lbn = uio->uio_offset / biosize; - on = uio->uio_offset & (biosize - 1); + on = uio->uio_offset - (lbn * biosize); /* * Start the read ahead(s), as required. @@ -1029,7 +1029,7 @@ flush_and_restart: do { NFSINCRGLOBAL(newnfsstats.biocache_writes); lbn = uio->uio_offset / biosize; - on = uio->uio_offset & (biosize-1); + on = uio->uio_offset - (lbn * biosize); n = MIN((unsigned)(biosize - on), uio->uio_resid); again: /* @@ -1847,7 +1847,7 @@ ncl_meta_setsize(struct vnode *vp, struc */ error = vtruncbuf(vp, cred, nsize, biosize); lbn = nsize / biosize; - bufsize = nsize & (biosize - 1); + bufsize = nsize - (lbn * biosize); bp = nfs_getcacheblk(vp, lbn, bufsize, td); if (!bp) return EINTR; Modified: head/sys/nfsclient/nfs_bio.c ============================================================================== --- head/sys/nfsclient/nfs_bio.c Tue Mar 19 12:52:13 2013 (r248499) +++ head/sys/nfsclient/nfs_bio.c Tue Mar 19 13:06:11 2013 (r248500) @@ -475,7 +475,7 @@ nfs_bioread(struct vnode *vp, struct uio case VREG: nfsstats.biocache_reads++; lbn = uio->uio_offset / biosize; - on = uio->uio_offset & (biosize - 1); + on = uio->uio_offset - (lbn * biosize); /* * Start the read ahead(s), as required. @@ -1011,7 +1011,7 @@ flush_and_restart: do { nfsstats.biocache_writes++; lbn = uio->uio_offset / biosize; - on = uio->uio_offset & (biosize-1); + on = uio->uio_offset - (lbn * biosize); n = MIN((unsigned)(biosize - on), uio->uio_resid); again: /* @@ -1781,7 +1781,7 @@ nfs_meta_setsize(struct vnode *vp, struc */ error = vtruncbuf(vp, cred, nsize, biosize); lbn = nsize / biosize; - bufsize = nsize & (biosize - 1); + bufsize = nsize - (lbn * biosize); bp = nfs_getcacheblk(vp, lbn, bufsize, td); if (!bp) return EINTR;