nfs_clbio.c (203119) | nfs_clbio.c (207082) |
---|---|
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 --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95 33 */ 34 35#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 --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clbio.c 203119 2010-01-28 16:17:24Z rmacklem $"); | 36__FBSDID("$FreeBSD: head/sys/fs/nfsclient/nfs_clbio.c 207082 2010-04-22 23:51:01Z rmacklem $"); |
37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bio.h> 41#include <sys/buf.h> 42#include <sys/kernel.h> 43#include <sys/mount.h> 44#include <sys/proc.h> --- 286 unchanged lines hidden (view full) --- 331 uio.uio_rw = UIO_WRITE; 332 uio.uio_td = td; 333 334 if ((ap->a_sync & VM_PAGER_PUT_SYNC) == 0) 335 iomode = NFSWRITE_UNSTABLE; 336 else 337 iomode = NFSWRITE_FILESYNC; 338 | 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bio.h> 41#include <sys/buf.h> 42#include <sys/kernel.h> 43#include <sys/mount.h> 44#include <sys/proc.h> --- 286 unchanged lines hidden (view full) --- 331 uio.uio_rw = UIO_WRITE; 332 uio.uio_td = td; 333 334 if ((ap->a_sync & VM_PAGER_PUT_SYNC) == 0) 335 iomode = NFSWRITE_UNSTABLE; 336 else 337 iomode = NFSWRITE_FILESYNC; 338 |
339 error = ncl_writerpc(vp, &uio, cred, &iomode, &must_commit); | 339 error = ncl_writerpc(vp, &uio, cred, &iomode, &must_commit, 0); |
340 341 pmap_qremove(kva, npages); 342 relpbuf(bp, &ncl_pbuf_freecnt); 343 344 if (!error) { 345 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE; 346 for (i = 0; i < nwritten; i++) { 347 rtvals[i] = VM_PAGER_OK; --- 201 unchanged lines hidden (view full) --- 549 /* 550 * If B_CACHE is not set, we must issue the read. If this 551 * fails, we return an error. 552 */ 553 554 if ((bp->b_flags & B_CACHE) == 0) { 555 bp->b_iocmd = BIO_READ; 556 vfs_busy_pages(bp, 0); | 340 341 pmap_qremove(kva, npages); 342 relpbuf(bp, &ncl_pbuf_freecnt); 343 344 if (!error) { 345 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE; 346 for (i = 0; i < nwritten; i++) { 347 rtvals[i] = VM_PAGER_OK; --- 201 unchanged lines hidden (view full) --- 549 /* 550 * If B_CACHE is not set, we must issue the read. If this 551 * fails, we return an error. 552 */ 553 554 if ((bp->b_flags & B_CACHE) == 0) { 555 bp->b_iocmd = BIO_READ; 556 vfs_busy_pages(bp, 0); |
557 error = ncl_doio(vp, bp, cred, td); | 557 error = ncl_doio(vp, bp, cred, td, 0); |
558 if (error) { 559 brelse(bp); 560 return (error); 561 } 562 } 563 564 /* 565 * on is the offset into the current bp. Figure out how many --- 12 unchanged lines hidden (view full) --- 578 bp = nfs_getcacheblk(vp, (daddr_t)0, NFS_MAXPATHLEN, td); 579 if (!bp) { 580 error = newnfs_sigintr(nmp, td); 581 return (error ? error : EINTR); 582 } 583 if ((bp->b_flags & B_CACHE) == 0) { 584 bp->b_iocmd = BIO_READ; 585 vfs_busy_pages(bp, 0); | 558 if (error) { 559 brelse(bp); 560 return (error); 561 } 562 } 563 564 /* 565 * on is the offset into the current bp. Figure out how many --- 12 unchanged lines hidden (view full) --- 578 bp = nfs_getcacheblk(vp, (daddr_t)0, NFS_MAXPATHLEN, td); 579 if (!bp) { 580 error = newnfs_sigintr(nmp, td); 581 return (error ? error : EINTR); 582 } 583 if ((bp->b_flags & B_CACHE) == 0) { 584 bp->b_iocmd = BIO_READ; 585 vfs_busy_pages(bp, 0); |
586 error = ncl_doio(vp, bp, cred, td); | 586 error = ncl_doio(vp, bp, cred, td, 0); |
587 if (error) { 588 bp->b_ioflags |= BIO_ERROR; 589 brelse(bp); 590 return (error); 591 } 592 } 593 n = min(uio->uio_resid, NFS_MAXPATHLEN - bp->b_resid); 594 on = 0; --- 9 unchanged lines hidden (view full) --- 604 bp = nfs_getcacheblk(vp, lbn, NFS_DIRBLKSIZ, td); 605 if (!bp) { 606 error = newnfs_sigintr(nmp, td); 607 return (error ? error : EINTR); 608 } 609 if ((bp->b_flags & B_CACHE) == 0) { 610 bp->b_iocmd = BIO_READ; 611 vfs_busy_pages(bp, 0); | 587 if (error) { 588 bp->b_ioflags |= BIO_ERROR; 589 brelse(bp); 590 return (error); 591 } 592 } 593 n = min(uio->uio_resid, NFS_MAXPATHLEN - bp->b_resid); 594 on = 0; --- 9 unchanged lines hidden (view full) --- 604 bp = nfs_getcacheblk(vp, lbn, NFS_DIRBLKSIZ, td); 605 if (!bp) { 606 error = newnfs_sigintr(nmp, td); 607 return (error ? error : EINTR); 608 } 609 if ((bp->b_flags & B_CACHE) == 0) { 610 bp->b_iocmd = BIO_READ; 611 vfs_busy_pages(bp, 0); |
612 error = ncl_doio(vp, bp, cred, td); | 612 error = ncl_doio(vp, bp, cred, td, 0); |
613 if (error) { 614 brelse(bp); 615 } 616 while (error == NFSERR_BAD_COOKIE) { 617 ncl_invaldir(vp); 618 error = ncl_vinvalbuf(vp, 0, td, 1); 619 /* 620 * Yuck! The directory has been modified on the --- 12 unchanged lines hidden (view full) --- 633 bp = nfs_getcacheblk(vp, i, NFS_DIRBLKSIZ, td); 634 if (!bp) { 635 error = newnfs_sigintr(nmp, td); 636 return (error ? error : EINTR); 637 } 638 if ((bp->b_flags & B_CACHE) == 0) { 639 bp->b_iocmd = BIO_READ; 640 vfs_busy_pages(bp, 0); | 613 if (error) { 614 brelse(bp); 615 } 616 while (error == NFSERR_BAD_COOKIE) { 617 ncl_invaldir(vp); 618 error = ncl_vinvalbuf(vp, 0, td, 1); 619 /* 620 * Yuck! The directory has been modified on the --- 12 unchanged lines hidden (view full) --- 633 bp = nfs_getcacheblk(vp, i, NFS_DIRBLKSIZ, td); 634 if (!bp) { 635 error = newnfs_sigintr(nmp, td); 636 return (error ? error : EINTR); 637 } 638 if ((bp->b_flags & B_CACHE) == 0) { 639 bp->b_iocmd = BIO_READ; 640 vfs_busy_pages(bp, 0); |
641 error = ncl_doio(vp, bp, cred, td); | 641 error = ncl_doio(vp, bp, cred, td, 0); |
642 /* 643 * no error + B_INVAL == directory EOF, 644 * use the block. 645 */ 646 if (error == 0 && (bp->b_flags & B_INVAL)) 647 break; 648 } 649 /* --- 116 unchanged lines hidden (view full) --- 766 uio.uio_iovcnt = 1; 767 uio.uio_offset = uiop->uio_offset; 768 uio.uio_resid = size; 769 uio.uio_segflg = UIO_USERSPACE; 770 uio.uio_rw = UIO_WRITE; 771 uio.uio_td = td; 772 iomode = NFSWRITE_FILESYNC; 773 error = ncl_writerpc(vp, &uio, cred, &iomode, | 642 /* 643 * no error + B_INVAL == directory EOF, 644 * use the block. 645 */ 646 if (error == 0 && (bp->b_flags & B_INVAL)) 647 break; 648 } 649 /* --- 116 unchanged lines hidden (view full) --- 766 uio.uio_iovcnt = 1; 767 uio.uio_offset = uiop->uio_offset; 768 uio.uio_resid = size; 769 uio.uio_segflg = UIO_USERSPACE; 770 uio.uio_rw = UIO_WRITE; 771 uio.uio_td = td; 772 iomode = NFSWRITE_FILESYNC; 773 error = ncl_writerpc(vp, &uio, cred, &iomode, |
774 &must_commit); | 774 &must_commit, 0); |
775 KASSERT((must_commit == 0), 776 ("ncl_directio_write: Did not commit write")); 777 if (error) 778 return (error); 779 uiop->uio_offset += size; 780 uiop->uio_resid -= size; 781 if (uiop->uio_iov->iov_len <= size) { 782 uiop->uio_iovcnt--; --- 334 unchanged lines hidden (view full) --- 1117 bp->b_flags |= B_CACHE; 1118 bp->b_flags &= ~B_INVAL; 1119 bp->b_ioflags &= ~BIO_ERROR; 1120 } 1121 1122 if ((bp->b_flags & B_CACHE) == 0) { 1123 bp->b_iocmd = BIO_READ; 1124 vfs_busy_pages(bp, 0); | 775 KASSERT((must_commit == 0), 776 ("ncl_directio_write: Did not commit write")); 777 if (error) 778 return (error); 779 uiop->uio_offset += size; 780 uiop->uio_resid -= size; 781 if (uiop->uio_iov->iov_len <= size) { 782 uiop->uio_iovcnt--; --- 334 unchanged lines hidden (view full) --- 1117 bp->b_flags |= B_CACHE; 1118 bp->b_flags &= ~B_INVAL; 1119 bp->b_ioflags &= ~BIO_ERROR; 1120 } 1121 1122 if ((bp->b_flags & B_CACHE) == 0) { 1123 bp->b_iocmd = BIO_READ; 1124 vfs_busy_pages(bp, 0); |
1125 error = ncl_doio(vp, bp, cred, td); | 1125 error = ncl_doio(vp, bp, cred, td, 0); |
1126 if (error) { 1127 brelse(bp); 1128 break; 1129 } 1130 } 1131 if (bp->b_wcred == NOCRED) 1132 bp->b_wcred = crhold(cred); 1133 mtx_lock(&np->n_mtx); --- 384 unchanged lines hidden (view full) --- 1518ncl_doio_directwrite(struct buf *bp) 1519{ 1520 int iomode, must_commit; 1521 struct uio *uiop = (struct uio *)bp->b_caller1; 1522 char *iov_base = uiop->uio_iov->iov_base; 1523 1524 iomode = NFSWRITE_FILESYNC; 1525 uiop->uio_td = NULL; /* NULL since we're in nfsiod */ | 1126 if (error) { 1127 brelse(bp); 1128 break; 1129 } 1130 } 1131 if (bp->b_wcred == NOCRED) 1132 bp->b_wcred = crhold(cred); 1133 mtx_lock(&np->n_mtx); --- 384 unchanged lines hidden (view full) --- 1518ncl_doio_directwrite(struct buf *bp) 1519{ 1520 int iomode, must_commit; 1521 struct uio *uiop = (struct uio *)bp->b_caller1; 1522 char *iov_base = uiop->uio_iov->iov_base; 1523 1524 iomode = NFSWRITE_FILESYNC; 1525 uiop->uio_td = NULL; /* NULL since we're in nfsiod */ |
1526 ncl_writerpc(bp->b_vp, uiop, bp->b_wcred, &iomode, &must_commit); | 1526 ncl_writerpc(bp->b_vp, uiop, bp->b_wcred, &iomode, &must_commit, 0); |
1527 KASSERT((must_commit == 0), ("ncl_doio_directwrite: Did not commit write")); 1528 free(iov_base, M_NFSDIRECTIO); 1529 free(uiop->uio_iov, M_NFSDIRECTIO); 1530 free(uiop, M_NFSDIRECTIO); 1531 if ((bp->b_flags & B_DIRECT) && bp->b_iocmd == BIO_WRITE) { 1532 struct nfsnode *np = VTONFS(bp->b_vp); 1533 mtx_lock(&np->n_mtx); 1534 np->n_directio_asyncwr--; --- 10 unchanged lines hidden (view full) --- 1545 relpbuf(bp, &ncl_pbuf_freecnt); 1546} 1547 1548/* 1549 * Do an I/O operation to/from a cache block. This may be called 1550 * synchronously or from an nfsiod. 1551 */ 1552int | 1527 KASSERT((must_commit == 0), ("ncl_doio_directwrite: Did not commit write")); 1528 free(iov_base, M_NFSDIRECTIO); 1529 free(uiop->uio_iov, M_NFSDIRECTIO); 1530 free(uiop, M_NFSDIRECTIO); 1531 if ((bp->b_flags & B_DIRECT) && bp->b_iocmd == BIO_WRITE) { 1532 struct nfsnode *np = VTONFS(bp->b_vp); 1533 mtx_lock(&np->n_mtx); 1534 np->n_directio_asyncwr--; --- 10 unchanged lines hidden (view full) --- 1545 relpbuf(bp, &ncl_pbuf_freecnt); 1546} 1547 1548/* 1549 * Do an I/O operation to/from a cache block. This may be called 1550 * synchronously or from an nfsiod. 1551 */ 1552int |
1553ncl_doio(struct vnode *vp, struct buf *bp, struct ucred *cr, struct thread *td) | 1553ncl_doio(struct vnode *vp, struct buf *bp, struct ucred *cr, struct thread *td, 1554 int called_from_strategy) |
1554{ 1555 struct uio *uiop; 1556 struct nfsnode *np; 1557 struct nfsmount *nmp; 1558 int error = 0, iomode, must_commit = 0; 1559 struct uio uio; 1560 struct iovec io; 1561 struct proc *p = td ? td->td_proc : NULL; --- 128 unchanged lines hidden (view full) --- 1690 uiop->uio_rw = UIO_WRITE; 1691 NFSINCRGLOBAL(newnfsstats.write_bios); 1692 1693 if ((bp->b_flags & (B_ASYNC | B_NEEDCOMMIT | B_NOCACHE | B_CLUSTER)) == B_ASYNC) 1694 iomode = NFSWRITE_UNSTABLE; 1695 else 1696 iomode = NFSWRITE_FILESYNC; 1697 | 1555{ 1556 struct uio *uiop; 1557 struct nfsnode *np; 1558 struct nfsmount *nmp; 1559 int error = 0, iomode, must_commit = 0; 1560 struct uio uio; 1561 struct iovec io; 1562 struct proc *p = td ? td->td_proc : NULL; --- 128 unchanged lines hidden (view full) --- 1691 uiop->uio_rw = UIO_WRITE; 1692 NFSINCRGLOBAL(newnfsstats.write_bios); 1693 1694 if ((bp->b_flags & (B_ASYNC | B_NEEDCOMMIT | B_NOCACHE | B_CLUSTER)) == B_ASYNC) 1695 iomode = NFSWRITE_UNSTABLE; 1696 else 1697 iomode = NFSWRITE_FILESYNC; 1698 |
1698 error = ncl_writerpc(vp, uiop, cr, &iomode, &must_commit); | 1699 error = ncl_writerpc(vp, uiop, cr, &iomode, &must_commit, 1700 called_from_strategy); |
1699 1700 /* 1701 * When setting B_NEEDCOMMIT also set B_CLUSTEROK to try 1702 * to cluster the buffers needing commit. This will allow 1703 * the system to submit a single commit rpc for the whole 1704 * cluster. We can do this even if the buffer is not 100% 1705 * dirty (relative to the NFS blocksize), so we optimize the 1706 * append-to-file-case. --- 20 unchanged lines hidden (view full) --- 1727 * is not relevant, so the rpc attempt is essentially 1728 * a noop. For the case of a V3 write rpc not being 1729 * committed to stable storage, the block is still 1730 * dirty and requires either a commit rpc or another 1731 * write rpc with iomode == NFSV3WRITE_FILESYNC before 1732 * the block is reused. This is indicated by setting 1733 * the B_DELWRI and B_NEEDCOMMIT flags. 1734 * | 1701 1702 /* 1703 * When setting B_NEEDCOMMIT also set B_CLUSTEROK to try 1704 * to cluster the buffers needing commit. This will allow 1705 * the system to submit a single commit rpc for the whole 1706 * cluster. We can do this even if the buffer is not 100% 1707 * dirty (relative to the NFS blocksize), so we optimize the 1708 * append-to-file-case. --- 20 unchanged lines hidden (view full) --- 1729 * is not relevant, so the rpc attempt is essentially 1730 * a noop. For the case of a V3 write rpc not being 1731 * committed to stable storage, the block is still 1732 * dirty and requires either a commit rpc or another 1733 * write rpc with iomode == NFSV3WRITE_FILESYNC before 1734 * the block is reused. This is indicated by setting 1735 * the B_DELWRI and B_NEEDCOMMIT flags. 1736 * |
1737 * EIO is returned by ncl_writerpc() to indicate a recoverable 1738 * write error and is handled as above, except that 1739 * B_EINTR isn't set. One cause of this is a stale stateid 1740 * error for the RPC that indicates recovery is required, 1741 * when called with called_from_strategy != 0. 1742 * |
|
1735 * If the buffer is marked B_PAGING, it does not reside on 1736 * the vp's paging queues so we cannot call bdirty(). The 1737 * bp in this case is not an NFS cache block so we should 1738 * be safe. XXX 1739 * 1740 * The logic below breaks up errors into recoverable and 1741 * unrecoverable. For the former, we clear B_INVAL|B_NOCACHE 1742 * and keep the buffer around for potential write retries. --- 12 unchanged lines hidden (view full) --- 1755 int s; 1756 1757 s = splbio(); 1758 bp->b_flags &= ~(B_INVAL|B_NOCACHE); 1759 if ((bp->b_flags & B_PAGING) == 0) { 1760 bdirty(bp); 1761 bp->b_flags &= ~B_DONE; 1762 } | 1743 * If the buffer is marked B_PAGING, it does not reside on 1744 * the vp's paging queues so we cannot call bdirty(). The 1745 * bp in this case is not an NFS cache block so we should 1746 * be safe. XXX 1747 * 1748 * The logic below breaks up errors into recoverable and 1749 * unrecoverable. For the former, we clear B_INVAL|B_NOCACHE 1750 * and keep the buffer around for potential write retries. --- 12 unchanged lines hidden (view full) --- 1763 int s; 1764 1765 s = splbio(); 1766 bp->b_flags &= ~(B_INVAL|B_NOCACHE); 1767 if ((bp->b_flags & B_PAGING) == 0) { 1768 bdirty(bp); 1769 bp->b_flags &= ~B_DONE; 1770 } |
1763 if (error && (bp->b_flags & B_ASYNC) == 0) | 1771 if ((error == EINTR || error == ETIMEDOUT) && 1772 (bp->b_flags & B_ASYNC) == 0) |
1764 bp->b_flags |= B_EINTR; 1765 splx(s); 1766 } else { 1767 if (error) { 1768 bp->b_ioflags |= BIO_ERROR; 1769 bp->b_flags |= B_INVAL; 1770 bp->b_error = np->n_error = error; 1771 mtx_lock(&np->n_mtx); --- 68 unchanged lines hidden --- | 1773 bp->b_flags |= B_EINTR; 1774 splx(s); 1775 } else { 1776 if (error) { 1777 bp->b_ioflags |= BIO_ERROR; 1778 bp->b_flags |= B_INVAL; 1779 bp->b_error = np->n_error = error; 1780 mtx_lock(&np->n_mtx); --- 68 unchanged lines hidden --- |