Deleted Added
full compact
nfs_bio.c (86089) nfs_bio.c (87834)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 23 unchanged lines hidden (view full) ---

32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95
37 */
38
39#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 23 unchanged lines hidden (view full) ---

32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95
37 */
38
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/sys/nfsclient/nfs_bio.c 86089 2001-11-05 18:48:54Z dillon $");
40__FBSDID("$FreeBSD: head/sys/nfsclient/nfs_bio.c 87834 2001-12-14 01:16:57Z dillon $");
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bio.h>
45#include <sys/buf.h>
46#include <sys/kernel.h>
47#include <sys/mount.h>
48#include <sys/proc.h>

--- 152 unchanged lines hidden (view full) ---

201 } else if (size > toff) {
202 /*
203 * Read operation filled a partial page.
204 */
205 m->valid = 0;
206 vm_page_set_validclean(m, 0, size - toff);
207 /* handled by vm_fault now */
208 /* vm_page_zero_invalid(m, TRUE); */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bio.h>
45#include <sys/buf.h>
46#include <sys/kernel.h>
47#include <sys/mount.h>
48#include <sys/proc.h>

--- 152 unchanged lines hidden (view full) ---

201 } else if (size > toff) {
202 /*
203 * Read operation filled a partial page.
204 */
205 m->valid = 0;
206 vm_page_set_validclean(m, 0, size - toff);
207 /* handled by vm_fault now */
208 /* vm_page_zero_invalid(m, TRUE); */
209 } else {
210 /*
211 * Read operation was short. If no error occured
212 * we may have hit a zero-fill section. We simply
213 * leave valid set to 0.
214 */
215 ;
209 }
216 }
210
211 if (i != ap->a_reqpage) {
212 /*
213 * Whether or not to leave the page activated is up in
214 * the air, but we should put the page on a page queue
215 * somewhere (it already is in the object). Result:
216 * It appears that emperical results show that
217 * deactivating pages is best.
218 */

--- 607 unchanged lines hidden (view full) ---

826 */
827 bcount = on + n;
828 if ((off_t)lbn * biosize + bcount < np->n_size) {
829 if ((off_t)(lbn + 1) * biosize < np->n_size)
830 bcount = biosize;
831 else
832 bcount = np->n_size - (off_t)lbn * biosize;
833 }
217 if (i != ap->a_reqpage) {
218 /*
219 * Whether or not to leave the page activated is up in
220 * the air, but we should put the page on a page queue
221 * somewhere (it already is in the object). Result:
222 * It appears that emperical results show that
223 * deactivating pages is best.
224 */

--- 607 unchanged lines hidden (view full) ---

832 */
833 bcount = on + n;
834 if ((off_t)lbn * biosize + bcount < np->n_size) {
835 if ((off_t)(lbn + 1) * biosize < np->n_size)
836 bcount = biosize;
837 else
838 bcount = np->n_size - (off_t)lbn * biosize;
839 }
834
835 bp = nfs_getcacheblk(vp, lbn, bcount, td);
840 bp = nfs_getcacheblk(vp, lbn, bcount, td);
836
837 if (uio->uio_offset + n > np->n_size) {
838 np->n_size = uio->uio_offset + n;
839 np->n_flag |= NMODIFIED;
840 vnode_pager_setsize(vp, np->n_size);
841 }
842 }
843
844 if (!bp) {

--- 449 unchanged lines hidden (view full) ---

1294 if (error) {
1295 bp->b_ioflags |= BIO_ERROR;
1296 bp->b_error = error;
1297 }
1298 } else if (bp->b_iocmd == BIO_READ) {
1299 io.iov_len = uiop->uio_resid = bp->b_bcount;
1300 io.iov_base = bp->b_data;
1301 uiop->uio_rw = UIO_READ;
841 if (uio->uio_offset + n > np->n_size) {
842 np->n_size = uio->uio_offset + n;
843 np->n_flag |= NMODIFIED;
844 vnode_pager_setsize(vp, np->n_size);
845 }
846 }
847
848 if (!bp) {

--- 449 unchanged lines hidden (view full) ---

1298 if (error) {
1299 bp->b_ioflags |= BIO_ERROR;
1300 bp->b_error = error;
1301 }
1302 } else if (bp->b_iocmd == BIO_READ) {
1303 io.iov_len = uiop->uio_resid = bp->b_bcount;
1304 io.iov_base = bp->b_data;
1305 uiop->uio_rw = UIO_READ;
1306
1302 switch (vp->v_type) {
1303 case VREG:
1304 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
1305 nfsstats.read_bios++;
1306 error = nfs_readrpc(vp, uiop, cr);
1307 switch (vp->v_type) {
1308 case VREG:
1309 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
1310 nfsstats.read_bios++;
1311 error = nfs_readrpc(vp, uiop, cr);
1312
1307 if (!error) {
1308 if (uiop->uio_resid) {
1309 /*
1310 * If we had a short read with no error, we must have
1311 * hit a file hole. We should zero-fill the remainder.
1312 * This can also occur if the server hits the file EOF.
1313 *
1314 * Holes used to be able to occur due to pending
1315 * writes, but that is not possible any longer.
1316 */
1317 int nread = bp->b_bcount - uiop->uio_resid;
1313 if (!error) {
1314 if (uiop->uio_resid) {
1315 /*
1316 * If we had a short read with no error, we must have
1317 * hit a file hole. We should zero-fill the remainder.
1318 * This can also occur if the server hits the file EOF.
1319 *
1320 * Holes used to be able to occur due to pending
1321 * writes, but that is not possible any longer.
1322 */
1323 int nread = bp->b_bcount - uiop->uio_resid;
1318 int left = bp->b_bcount - nread;
1324 int left = uiop->uio_resid;
1319
1320 if (left > 0)
1321 bzero((char *)bp->b_data + nread, left);
1322 uiop->uio_resid = 0;
1323 }
1324 }
1325 if (p && (vp->v_flag & VTEXT) &&
1326 (np->n_mtime != np->n_vattr.va_mtime.tv_sec)) {

--- 153 unchanged lines hidden (view full) ---

1480 }
1481 }
1482 bp->b_resid = uiop->uio_resid;
1483 if (must_commit)
1484 nfs_clearcommit(vp->v_mount);
1485 bufdone(bp);
1486 return (error);
1487}
1325
1326 if (left > 0)
1327 bzero((char *)bp->b_data + nread, left);
1328 uiop->uio_resid = 0;
1329 }
1330 }
1331 if (p && (vp->v_flag & VTEXT) &&
1332 (np->n_mtime != np->n_vattr.va_mtime.tv_sec)) {

--- 153 unchanged lines hidden (view full) ---

1486 }
1487 }
1488 bp->b_resid = uiop->uio_resid;
1489 if (must_commit)
1490 nfs_clearcommit(vp->v_mount);
1491 bufdone(bp);
1492 return (error);
1493}
1494
1495/*
1496 * Used to aid in handling ftruncate() operations on the NFS client side.
1497 * Truncation creates a number of special problems for NFS. We have to
1498 * throw away VM pages and buffer cache buffers that are beyond EOF, and
1499 * we have to properly handle VM pages or (potentially dirty) buffers
1500 * that straddle the truncation point.
1501 */
1502
1503int
1504nfs_meta_setsize(struct vnode *vp, struct ucred *cred, struct thread *td, u_quad_t nsize)
1505{
1506 struct nfsnode *np = VTONFS(vp);
1507 u_quad_t tsize = np->n_size;
1508 int biosize = vp->v_mount->mnt_stat.f_iosize;
1509 int error = 0;
1510
1511 np->n_size = nsize;
1512
1513 if (np->n_size < tsize) {
1514 struct buf *bp;
1515 daddr_t lbn;
1516 int bufsize;
1517
1518 /*
1519 * vtruncbuf() doesn't get the buffer overlapping the
1520 * truncation point. We may have a B_DELWRI and/or B_CACHE
1521 * buffer that now needs to be truncated.
1522 */
1523 error = vtruncbuf(vp, cred, td, nsize, biosize);
1524 lbn = nsize / biosize;
1525 bufsize = nsize & (biosize - 1);
1526 bp = nfs_getcacheblk(vp, lbn, bufsize, td);
1527 if (bp->b_dirtyoff > bp->b_bcount)
1528 bp->b_dirtyoff = bp->b_bcount;
1529 if (bp->b_dirtyend > bp->b_bcount)
1530 bp->b_dirtyend = bp->b_bcount;
1531 bp->b_flags |= B_RELBUF; /* don't leave garbage around */
1532 brelse(bp);
1533 } else {
1534 vnode_pager_setsize(vp, nsize);
1535 }
1536 return(error);
1537}
1538