summaryrefslogtreecommitdiffstats
path: root/fs/nfs/inode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-01-14 19:08:23 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-14 19:08:23 -0500
commit75f26df6ae6f8787fc6198609c8be17400a69e25 (patch)
tree04d2173357b402ce1ee097ed7e40bcfc2153b937 /fs/nfs/inode.c
parent63f729cb4aa9a224cfd6bb35eab6b4556c29115d (diff)
parent44aab3e09ef947e546ee61c5082c41b86dd15e53 (diff)
Merge tag 'nfs-for-4.5-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
Pull NFS client updates from Trond Myklebust: "Highlights include: Stable fixes: - Fix a regression in the SunRPC socket polling code - Fix the attribute cache revalidation code - Fix race in __update_open_stateid() - Fix an lo->plh_block_lgets imbalance in layoutreturn - Fix an Oopsable typo in ff_mirror_match_fh() Features: - pNFS layout recall performance improvements. - pNFS/flexfiles: Support server-supplied layoutstats sampling period Bugfixes + cleanups: - NFSv4: Don't perform cached access checks before we've OPENed the file - Fix starvation issues with background flushes - Reclaim writes should be flushed as unstable writes if there are already entries in the commit lists - Various bugfixes from Chuck to fix NFS/RDMA send queue ordering problems - Ensure that we propagate fatal layoutget errors back to the application - Fixes for sundry flexfiles layoutstats bugs - Fix files/flexfiles to not cache invalidated layouts in the DS commit buckets" * tag 'nfs-for-4.5-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs: (68 commits) NFS: Fix a compile warning about unused variable in nfs_generic_pg_pgios() NFSv4: Fix a compile warning about no prototype for nfs4_ioctl() NFS: Use wait_on_atomic_t() for unlock after readahead SUNRPC: Fixup socket wait for memory NFSv4.1/pNFS: Cleanup constify struct pnfs_layout_range arguments NFSv4.1/pnfs: Cleanup copying of pnfs_layout_range structures NFSv4.1/pNFS: Cleanup pnfs_mark_matching_lsegs_invalid() NFSv4.1/pNFS: Fix a race in initiate_file_draining() NFSv4.1/pNFS: pnfs_error_mark_layout_for_return() must always return layout NFSv4.1/pNFS: pnfs_mark_matching_lsegs_return() should set the iomode NFSv4.1/pNFS: Use nfs4_stateid_copy for copying stateids NFSv4.1/pNFS: Don't pass stateids by value to pnfs_send_layoutreturn() NFS: Relax requirements in nfs_flush_incompatible NFSv4.1/pNFS: Don't queue up a new commit if the layout segment is invalid NFS: Allow multiple commit requests in flight per file NFS/pNFS: Fix up pNFS write reschedule layering violations and bugs SUNRPC: Fix a missing break in rpc_anyaddr() pNFS/flexfiles: Fix an Oopsable typo in ff_mirror_match_fh() NFS: Fix attribute cache revalidation NFS: Ensure we revalidate attributes before using execute_ok() ...
Diffstat (limited to 'fs/nfs/inode.c')
-rw-r--r--fs/nfs/inode.c78
1 files changed, 57 insertions, 21 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index bdb4dc7b4ecd..c11e855e0e18 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -71,19 +71,25 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
71 return nfs_fileid_to_ino_t(fattr->fileid); 71 return nfs_fileid_to_ino_t(fattr->fileid);
72} 72}
73 73
74/** 74static int nfs_wait_killable(int mode)
75 * nfs_wait_bit_killable - helper for functions that are sleeping on bit locks
76 * @word: long word containing the bit lock
77 */
78int nfs_wait_bit_killable(struct wait_bit_key *key, int mode)
79{ 75{
80 freezable_schedule_unsafe(); 76 freezable_schedule_unsafe();
81 if (signal_pending_state(mode, current)) 77 if (signal_pending_state(mode, current))
82 return -ERESTARTSYS; 78 return -ERESTARTSYS;
83 return 0; 79 return 0;
84} 80}
81
82int nfs_wait_bit_killable(struct wait_bit_key *key, int mode)
83{
84 return nfs_wait_killable(mode);
85}
85EXPORT_SYMBOL_GPL(nfs_wait_bit_killable); 86EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
86 87
88int nfs_wait_atomic_killable(atomic_t *p)
89{
90 return nfs_wait_killable(TASK_KILLABLE);
91}
92
87/** 93/**
88 * nfs_compat_user_ino64 - returns the user-visible inode number 94 * nfs_compat_user_ino64 - returns the user-visible inode number
89 * @fileid: 64-bit fileid 95 * @fileid: 64-bit fileid
@@ -700,7 +706,7 @@ static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
700 l_ctx->lockowner.l_owner = current->files; 706 l_ctx->lockowner.l_owner = current->files;
701 l_ctx->lockowner.l_pid = current->tgid; 707 l_ctx->lockowner.l_pid = current->tgid;
702 INIT_LIST_HEAD(&l_ctx->list); 708 INIT_LIST_HEAD(&l_ctx->list);
703 nfs_iocounter_init(&l_ctx->io_count); 709 atomic_set(&l_ctx->io_count, 0);
704} 710}
705 711
706static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx) 712static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
@@ -913,6 +919,12 @@ void nfs_file_clear_open_context(struct file *filp)
913 if (ctx) { 919 if (ctx) {
914 struct inode *inode = d_inode(ctx->dentry); 920 struct inode *inode = d_inode(ctx->dentry);
915 921
922 /*
923 * We fatal error on write before. Try to writeback
924 * every page again.
925 */
926 if (ctx->error < 0)
927 invalidate_inode_pages2(inode->i_mapping);
916 filp->private_data = NULL; 928 filp->private_data = NULL;
917 spin_lock(&inode->i_lock); 929 spin_lock(&inode->i_lock);
918 list_move_tail(&ctx->list, &NFS_I(inode)->open_files); 930 list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
@@ -1663,6 +1675,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1663 unsigned long invalid = 0; 1675 unsigned long invalid = 0;
1664 unsigned long now = jiffies; 1676 unsigned long now = jiffies;
1665 unsigned long save_cache_validity; 1677 unsigned long save_cache_validity;
1678 bool cache_revalidated = true;
1666 1679
1667 dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n", 1680 dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
1668 __func__, inode->i_sb->s_id, inode->i_ino, 1681 __func__, inode->i_sb->s_id, inode->i_ino,
@@ -1724,22 +1737,28 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1724 nfs_force_lookup_revalidate(inode); 1737 nfs_force_lookup_revalidate(inode);
1725 inode->i_version = fattr->change_attr; 1738 inode->i_version = fattr->change_attr;
1726 } 1739 }
1727 } else 1740 } else {
1728 nfsi->cache_validity |= save_cache_validity; 1741 nfsi->cache_validity |= save_cache_validity;
1742 cache_revalidated = false;
1743 }
1729 1744
1730 if (fattr->valid & NFS_ATTR_FATTR_MTIME) { 1745 if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
1731 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); 1746 memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
1732 } else if (server->caps & NFS_CAP_MTIME) 1747 } else if (server->caps & NFS_CAP_MTIME) {
1733 nfsi->cache_validity |= save_cache_validity & 1748 nfsi->cache_validity |= save_cache_validity &
1734 (NFS_INO_INVALID_ATTR 1749 (NFS_INO_INVALID_ATTR
1735 | NFS_INO_REVAL_FORCED); 1750 | NFS_INO_REVAL_FORCED);
1751 cache_revalidated = false;
1752 }
1736 1753
1737 if (fattr->valid & NFS_ATTR_FATTR_CTIME) { 1754 if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
1738 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); 1755 memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
1739 } else if (server->caps & NFS_CAP_CTIME) 1756 } else if (server->caps & NFS_CAP_CTIME) {
1740 nfsi->cache_validity |= save_cache_validity & 1757 nfsi->cache_validity |= save_cache_validity &
1741 (NFS_INO_INVALID_ATTR 1758 (NFS_INO_INVALID_ATTR
1742 | NFS_INO_REVAL_FORCED); 1759 | NFS_INO_REVAL_FORCED);
1760 cache_revalidated = false;
1761 }
1743 1762
1744 /* Check if our cached file size is stale */ 1763 /* Check if our cached file size is stale */
1745 if (fattr->valid & NFS_ATTR_FATTR_SIZE) { 1764 if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
@@ -1759,19 +1778,23 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1759 (long long)cur_isize, 1778 (long long)cur_isize,
1760 (long long)new_isize); 1779 (long long)new_isize);
1761 } 1780 }
1762 } else 1781 } else {
1763 nfsi->cache_validity |= save_cache_validity & 1782 nfsi->cache_validity |= save_cache_validity &
1764 (NFS_INO_INVALID_ATTR 1783 (NFS_INO_INVALID_ATTR
1765 | NFS_INO_REVAL_PAGECACHE 1784 | NFS_INO_REVAL_PAGECACHE
1766 | NFS_INO_REVAL_FORCED); 1785 | NFS_INO_REVAL_FORCED);
1786 cache_revalidated = false;
1787 }
1767 1788
1768 1789
1769 if (fattr->valid & NFS_ATTR_FATTR_ATIME) 1790 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
1770 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime)); 1791 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
1771 else if (server->caps & NFS_CAP_ATIME) 1792 else if (server->caps & NFS_CAP_ATIME) {
1772 nfsi->cache_validity |= save_cache_validity & 1793 nfsi->cache_validity |= save_cache_validity &
1773 (NFS_INO_INVALID_ATIME 1794 (NFS_INO_INVALID_ATIME
1774 | NFS_INO_REVAL_FORCED); 1795 | NFS_INO_REVAL_FORCED);
1796 cache_revalidated = false;
1797 }
1775 1798
1776 if (fattr->valid & NFS_ATTR_FATTR_MODE) { 1799 if (fattr->valid & NFS_ATTR_FATTR_MODE) {
1777 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { 1800 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
@@ -1780,36 +1803,42 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1780 inode->i_mode = newmode; 1803 inode->i_mode = newmode;
1781 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1804 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1782 } 1805 }
1783 } else if (server->caps & NFS_CAP_MODE) 1806 } else if (server->caps & NFS_CAP_MODE) {
1784 nfsi->cache_validity |= save_cache_validity & 1807 nfsi->cache_validity |= save_cache_validity &
1785 (NFS_INO_INVALID_ATTR 1808 (NFS_INO_INVALID_ATTR
1786 | NFS_INO_INVALID_ACCESS 1809 | NFS_INO_INVALID_ACCESS
1787 | NFS_INO_INVALID_ACL 1810 | NFS_INO_INVALID_ACL
1788 | NFS_INO_REVAL_FORCED); 1811 | NFS_INO_REVAL_FORCED);
1812 cache_revalidated = false;
1813 }
1789 1814
1790 if (fattr->valid & NFS_ATTR_FATTR_OWNER) { 1815 if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
1791 if (!uid_eq(inode->i_uid, fattr->uid)) { 1816 if (!uid_eq(inode->i_uid, fattr->uid)) {
1792 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1817 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1793 inode->i_uid = fattr->uid; 1818 inode->i_uid = fattr->uid;
1794 } 1819 }
1795 } else if (server->caps & NFS_CAP_OWNER) 1820 } else if (server->caps & NFS_CAP_OWNER) {
1796 nfsi->cache_validity |= save_cache_validity & 1821 nfsi->cache_validity |= save_cache_validity &
1797 (NFS_INO_INVALID_ATTR 1822 (NFS_INO_INVALID_ATTR
1798 | NFS_INO_INVALID_ACCESS 1823 | NFS_INO_INVALID_ACCESS
1799 | NFS_INO_INVALID_ACL 1824 | NFS_INO_INVALID_ACL
1800 | NFS_INO_REVAL_FORCED); 1825 | NFS_INO_REVAL_FORCED);
1826 cache_revalidated = false;
1827 }
1801 1828
1802 if (fattr->valid & NFS_ATTR_FATTR_GROUP) { 1829 if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
1803 if (!gid_eq(inode->i_gid, fattr->gid)) { 1830 if (!gid_eq(inode->i_gid, fattr->gid)) {
1804 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; 1831 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
1805 inode->i_gid = fattr->gid; 1832 inode->i_gid = fattr->gid;
1806 } 1833 }
1807 } else if (server->caps & NFS_CAP_OWNER_GROUP) 1834 } else if (server->caps & NFS_CAP_OWNER_GROUP) {
1808 nfsi->cache_validity |= save_cache_validity & 1835 nfsi->cache_validity |= save_cache_validity &
1809 (NFS_INO_INVALID_ATTR 1836 (NFS_INO_INVALID_ATTR
1810 | NFS_INO_INVALID_ACCESS 1837 | NFS_INO_INVALID_ACCESS
1811 | NFS_INO_INVALID_ACL 1838 | NFS_INO_INVALID_ACL
1812 | NFS_INO_REVAL_FORCED); 1839 | NFS_INO_REVAL_FORCED);
1840 cache_revalidated = false;
1841 }
1813 1842
1814 if (fattr->valid & NFS_ATTR_FATTR_NLINK) { 1843 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
1815 if (inode->i_nlink != fattr->nlink) { 1844 if (inode->i_nlink != fattr->nlink) {
@@ -1818,19 +1847,22 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1818 invalid |= NFS_INO_INVALID_DATA; 1847 invalid |= NFS_INO_INVALID_DATA;
1819 set_nlink(inode, fattr->nlink); 1848 set_nlink(inode, fattr->nlink);
1820 } 1849 }
1821 } else if (server->caps & NFS_CAP_NLINK) 1850 } else if (server->caps & NFS_CAP_NLINK) {
1822 nfsi->cache_validity |= save_cache_validity & 1851 nfsi->cache_validity |= save_cache_validity &
1823 (NFS_INO_INVALID_ATTR 1852 (NFS_INO_INVALID_ATTR
1824 | NFS_INO_REVAL_FORCED); 1853 | NFS_INO_REVAL_FORCED);
1854 cache_revalidated = false;
1855 }
1825 1856
1826 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { 1857 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
1827 /* 1858 /*
1828 * report the blocks in 512byte units 1859 * report the blocks in 512byte units
1829 */ 1860 */
1830 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); 1861 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
1831 } 1862 } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
1832 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
1833 inode->i_blocks = fattr->du.nfs2.blocks; 1863 inode->i_blocks = fattr->du.nfs2.blocks;
1864 else
1865 cache_revalidated = false;
1834 1866
1835 /* Update attrtimeo value if we're out of the unstable period */ 1867 /* Update attrtimeo value if we're out of the unstable period */
1836 if (invalid & NFS_INO_INVALID_ATTR) { 1868 if (invalid & NFS_INO_INVALID_ATTR) {
@@ -1840,9 +1872,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1840 /* Set barrier to be more recent than all outstanding updates */ 1872 /* Set barrier to be more recent than all outstanding updates */
1841 nfsi->attr_gencount = nfs_inc_attr_generation_counter(); 1873 nfsi->attr_gencount = nfs_inc_attr_generation_counter();
1842 } else { 1874 } else {
1843 if (!time_in_range_open(now, nfsi->attrtimeo_timestamp, nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) { 1875 if (cache_revalidated) {
1844 if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode)) 1876 if (!time_in_range_open(now, nfsi->attrtimeo_timestamp,
1845 nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode); 1877 nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
1878 nfsi->attrtimeo <<= 1;
1879 if (nfsi->attrtimeo > NFS_MAXATTRTIMEO(inode))
1880 nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
1881 }
1846 nfsi->attrtimeo_timestamp = now; 1882 nfsi->attrtimeo_timestamp = now;
1847 } 1883 }
1848 /* Set the barrier to be more recent than this fattr */ 1884 /* Set the barrier to be more recent than this fattr */
@@ -1851,7 +1887,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1851 } 1887 }
1852 1888
1853 /* Don't declare attrcache up to date if there were no attrs! */ 1889 /* Don't declare attrcache up to date if there were no attrs! */
1854 if (fattr->valid != 0) 1890 if (cache_revalidated)
1855 invalid &= ~NFS_INO_INVALID_ATTR; 1891 invalid &= ~NFS_INO_INVALID_ATTR;
1856 1892
1857 /* Don't invalidate the data if we were to blame */ 1893 /* Don't invalidate the data if we were to blame */