summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2013-03-19 13:06:11 +0000
committeremaste <emaste@FreeBSD.org>2013-03-19 13:06:11 +0000
commit2ccefecf014b43b06dedf686cbf5b53081d4bf59 (patch)
tree2e258acc65ff04ba13bc1d70952c698edbda9fc9
parentf67d1cc4dd4c25d81b07b6a480e3bb40cdda167e (diff)
downloadFreeBSD-src-2ccefecf014b43b06dedf686cbf5b53081d4bf59.zip
FreeBSD-src-2ccefecf014b43b06dedf686cbf5b53081d4bf59.tar.gz
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@
-rw-r--r--sys/fs/nfsclient/nfs_clbio.c6
-rw-r--r--sys/nfsclient/nfs_bio.c6
2 files changed, 6 insertions, 6 deletions
diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c
index 4a3ef41..21ab8807 100644
--- a/sys/fs/nfsclient/nfs_clbio.c
+++ b/sys/fs/nfsclient/nfs_clbio.c
@@ -484,7 +484,7 @@ ncl_bioread(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred)
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, struct ucred *cred, struct thread *td, u_quad
*/
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;
diff --git a/sys/nfsclient/nfs_bio.c b/sys/nfsclient/nfs_bio.c
index a90afea..b7fe832 100644
--- a/sys/nfsclient/nfs_bio.c
+++ b/sys/nfsclient/nfs_bio.c
@@ -475,7 +475,7 @@ nfs_bioread(struct vnode *vp, struct uio *uio, int ioflag, struct ucred *cred)
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, struct ucred *cred, struct thread *td, u_quad
*/
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;
OpenPOWER on IntegriCloud