aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/dir.c')
-rw-r--r--fs/nfs/dir.c161
1 files changed, 88 insertions, 73 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index a7bb5c694aa3..29539ceeb745 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -53,7 +53,7 @@ static int nfs_link(struct dentry *, struct inode *, struct dentry *);
53static int nfs_mknod(struct inode *, struct dentry *, int, dev_t); 53static int nfs_mknod(struct inode *, struct dentry *, int, dev_t);
54static int nfs_rename(struct inode *, struct dentry *, 54static int nfs_rename(struct inode *, struct dentry *,
55 struct inode *, struct dentry *); 55 struct inode *, struct dentry *);
56static int nfs_fsync_dir(struct file *, struct dentry *, int); 56static int nfs_fsync_dir(struct file *, int);
57static loff_t nfs_llseek_dir(struct file *, loff_t, int); 57static loff_t nfs_llseek_dir(struct file *, loff_t, int);
58 58
59const struct file_operations nfs_dir_operations = { 59const struct file_operations nfs_dir_operations = {
@@ -530,9 +530,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
530 nfs_readdir_descriptor_t my_desc, 530 nfs_readdir_descriptor_t my_desc,
531 *desc = &my_desc; 531 *desc = &my_desc;
532 struct nfs_entry my_entry; 532 struct nfs_entry my_entry;
533 struct nfs_fh fh; 533 int res = -ENOMEM;
534 struct nfs_fattr fattr;
535 long res;
536 534
537 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n", 535 dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
538 dentry->d_parent->d_name.name, dentry->d_name.name, 536 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -554,9 +552,11 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
554 552
555 my_entry.cookie = my_entry.prev_cookie = 0; 553 my_entry.cookie = my_entry.prev_cookie = 0;
556 my_entry.eof = 0; 554 my_entry.eof = 0;
557 my_entry.fh = &fh; 555 my_entry.fh = nfs_alloc_fhandle();
558 my_entry.fattr = &fattr; 556 my_entry.fattr = nfs_alloc_fattr();
559 nfs_fattr_init(&fattr); 557 if (my_entry.fh == NULL || my_entry.fattr == NULL)
558 goto out_alloc_failed;
559
560 desc->entry = &my_entry; 560 desc->entry = &my_entry;
561 561
562 nfs_block_sillyrename(dentry); 562 nfs_block_sillyrename(dentry);
@@ -598,7 +598,10 @@ out:
598 nfs_unblock_sillyrename(dentry); 598 nfs_unblock_sillyrename(dentry);
599 if (res > 0) 599 if (res > 0)
600 res = 0; 600 res = 0;
601 dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n", 601out_alloc_failed:
602 nfs_free_fattr(my_entry.fattr);
603 nfs_free_fhandle(my_entry.fh);
604 dfprintk(FILE, "NFS: readdir(%s/%s) returns %d\n",
602 dentry->d_parent->d_name.name, dentry->d_name.name, 605 dentry->d_parent->d_name.name, dentry->d_name.name,
603 res); 606 res);
604 return res; 607 return res;
@@ -638,8 +641,10 @@ out:
638 * All directory operations under NFS are synchronous, so fsync() 641 * All directory operations under NFS are synchronous, so fsync()
639 * is a dummy operation. 642 * is a dummy operation.
640 */ 643 */
641static int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync) 644static int nfs_fsync_dir(struct file *filp, int datasync)
642{ 645{
646 struct dentry *dentry = filp->f_path.dentry;
647
643 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n", 648 dfprintk(FILE, "NFS: fsync dir(%s/%s) datasync %d\n",
644 dentry->d_parent->d_name.name, dentry->d_name.name, 649 dentry->d_parent->d_name.name, dentry->d_name.name,
645 datasync); 650 datasync);
@@ -776,9 +781,9 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
776 struct inode *dir; 781 struct inode *dir;
777 struct inode *inode; 782 struct inode *inode;
778 struct dentry *parent; 783 struct dentry *parent;
784 struct nfs_fh *fhandle = NULL;
785 struct nfs_fattr *fattr = NULL;
779 int error; 786 int error;
780 struct nfs_fh fhandle;
781 struct nfs_fattr fattr;
782 787
783 parent = dget_parent(dentry); 788 parent = dget_parent(dentry);
784 dir = parent->d_inode; 789 dir = parent->d_inode;
@@ -811,14 +816,22 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
811 if (NFS_STALE(inode)) 816 if (NFS_STALE(inode))
812 goto out_bad; 817 goto out_bad;
813 818
814 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr); 819 error = -ENOMEM;
820 fhandle = nfs_alloc_fhandle();
821 fattr = nfs_alloc_fattr();
822 if (fhandle == NULL || fattr == NULL)
823 goto out_error;
824
825 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
815 if (error) 826 if (error)
816 goto out_bad; 827 goto out_bad;
817 if (nfs_compare_fh(NFS_FH(inode), &fhandle)) 828 if (nfs_compare_fh(NFS_FH(inode), fhandle))
818 goto out_bad; 829 goto out_bad;
819 if ((error = nfs_refresh_inode(inode, &fattr)) != 0) 830 if ((error = nfs_refresh_inode(inode, fattr)) != 0)
820 goto out_bad; 831 goto out_bad;
821 832
833 nfs_free_fattr(fattr);
834 nfs_free_fhandle(fhandle);
822out_set_verifier: 835out_set_verifier:
823 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 836 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
824 out_valid: 837 out_valid:
@@ -842,11 +855,21 @@ out_zap_parent:
842 shrink_dcache_parent(dentry); 855 shrink_dcache_parent(dentry);
843 } 856 }
844 d_drop(dentry); 857 d_drop(dentry);
858 nfs_free_fattr(fattr);
859 nfs_free_fhandle(fhandle);
845 dput(parent); 860 dput(parent);
846 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n", 861 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
847 __func__, dentry->d_parent->d_name.name, 862 __func__, dentry->d_parent->d_name.name,
848 dentry->d_name.name); 863 dentry->d_name.name);
849 return 0; 864 return 0;
865out_error:
866 nfs_free_fattr(fattr);
867 nfs_free_fhandle(fhandle);
868 dput(parent);
869 dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) lookup returned error %d\n",
870 __func__, dentry->d_parent->d_name.name,
871 dentry->d_name.name, error);
872 return error;
850} 873}
851 874
852/* 875/*
@@ -911,9 +934,9 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
911 struct dentry *res; 934 struct dentry *res;
912 struct dentry *parent; 935 struct dentry *parent;
913 struct inode *inode = NULL; 936 struct inode *inode = NULL;
937 struct nfs_fh *fhandle = NULL;
938 struct nfs_fattr *fattr = NULL;
914 int error; 939 int error;
915 struct nfs_fh fhandle;
916 struct nfs_fattr fattr;
917 940
918 dfprintk(VFS, "NFS: lookup(%s/%s)\n", 941 dfprintk(VFS, "NFS: lookup(%s/%s)\n",
919 dentry->d_parent->d_name.name, dentry->d_name.name); 942 dentry->d_parent->d_name.name, dentry->d_name.name);
@@ -923,7 +946,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
923 if (dentry->d_name.len > NFS_SERVER(dir)->namelen) 946 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
924 goto out; 947 goto out;
925 948
926 res = ERR_PTR(-ENOMEM);
927 dentry->d_op = NFS_PROTO(dir)->dentry_ops; 949 dentry->d_op = NFS_PROTO(dir)->dentry_ops;
928 950
929 /* 951 /*
@@ -936,17 +958,23 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
936 goto out; 958 goto out;
937 } 959 }
938 960
961 res = ERR_PTR(-ENOMEM);
962 fhandle = nfs_alloc_fhandle();
963 fattr = nfs_alloc_fattr();
964 if (fhandle == NULL || fattr == NULL)
965 goto out;
966
939 parent = dentry->d_parent; 967 parent = dentry->d_parent;
940 /* Protect against concurrent sillydeletes */ 968 /* Protect against concurrent sillydeletes */
941 nfs_block_sillyrename(parent); 969 nfs_block_sillyrename(parent);
942 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr); 970 error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
943 if (error == -ENOENT) 971 if (error == -ENOENT)
944 goto no_entry; 972 goto no_entry;
945 if (error < 0) { 973 if (error < 0) {
946 res = ERR_PTR(error); 974 res = ERR_PTR(error);
947 goto out_unblock_sillyrename; 975 goto out_unblock_sillyrename;
948 } 976 }
949 inode = nfs_fhget(dentry->d_sb, &fhandle, &fattr); 977 inode = nfs_fhget(dentry->d_sb, fhandle, fattr);
950 res = (struct dentry *)inode; 978 res = (struct dentry *)inode;
951 if (IS_ERR(res)) 979 if (IS_ERR(res))
952 goto out_unblock_sillyrename; 980 goto out_unblock_sillyrename;
@@ -962,6 +990,8 @@ no_entry:
962out_unblock_sillyrename: 990out_unblock_sillyrename:
963 nfs_unblock_sillyrename(parent); 991 nfs_unblock_sillyrename(parent);
964out: 992out:
993 nfs_free_fattr(fattr);
994 nfs_free_fhandle(fhandle);
965 return res; 995 return res;
966} 996}
967 997
@@ -1622,16 +1652,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1622 } 1652 }
1623 } 1653 }
1624 1654
1625 /*
1626 * ... prune child dentries and writebacks if needed.
1627 */
1628 if (atomic_read(&old_dentry->d_count) > 1) {
1629 if (S_ISREG(old_inode->i_mode))
1630 nfs_wb_all(old_inode);
1631 shrink_dcache_parent(old_dentry);
1632 }
1633 nfs_inode_return_delegation(old_inode); 1655 nfs_inode_return_delegation(old_inode);
1634
1635 if (new_inode != NULL) 1656 if (new_inode != NULL)
1636 nfs_inode_return_delegation(new_inode); 1657 nfs_inode_return_delegation(new_inode);
1637 1658
@@ -1669,28 +1690,33 @@ static void nfs_access_free_entry(struct nfs_access_entry *entry)
1669 smp_mb__after_atomic_dec(); 1690 smp_mb__after_atomic_dec();
1670} 1691}
1671 1692
1672int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask) 1693static void nfs_access_free_list(struct list_head *head)
1694{
1695 struct nfs_access_entry *cache;
1696
1697 while (!list_empty(head)) {
1698 cache = list_entry(head->next, struct nfs_access_entry, lru);
1699 list_del(&cache->lru);
1700 nfs_access_free_entry(cache);
1701 }
1702}
1703
1704int nfs_access_cache_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
1673{ 1705{
1674 LIST_HEAD(head); 1706 LIST_HEAD(head);
1675 struct nfs_inode *nfsi; 1707 struct nfs_inode *nfsi;
1676 struct nfs_access_entry *cache; 1708 struct nfs_access_entry *cache;
1677 1709
1678restart: 1710 if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
1711 return (nr_to_scan == 0) ? 0 : -1;
1712
1679 spin_lock(&nfs_access_lru_lock); 1713 spin_lock(&nfs_access_lru_lock);
1680 list_for_each_entry(nfsi, &nfs_access_lru_list, access_cache_inode_lru) { 1714 list_for_each_entry(nfsi, &nfs_access_lru_list, access_cache_inode_lru) {
1681 struct rw_semaphore *s_umount;
1682 struct inode *inode; 1715 struct inode *inode;
1683 1716
1684 if (nr_to_scan-- == 0) 1717 if (nr_to_scan-- == 0)
1685 break; 1718 break;
1686 s_umount = &nfsi->vfs_inode.i_sb->s_umount; 1719 inode = &nfsi->vfs_inode;
1687 if (!down_read_trylock(s_umount))
1688 continue;
1689 inode = igrab(&nfsi->vfs_inode);
1690 if (inode == NULL) {
1691 up_read(s_umount);
1692 continue;
1693 }
1694 spin_lock(&inode->i_lock); 1720 spin_lock(&inode->i_lock);
1695 if (list_empty(&nfsi->access_cache_entry_lru)) 1721 if (list_empty(&nfsi->access_cache_entry_lru))
1696 goto remove_lru_entry; 1722 goto remove_lru_entry;
@@ -1704,61 +1730,48 @@ restart:
1704 else { 1730 else {
1705remove_lru_entry: 1731remove_lru_entry:
1706 list_del_init(&nfsi->access_cache_inode_lru); 1732 list_del_init(&nfsi->access_cache_inode_lru);
1733 smp_mb__before_clear_bit();
1707 clear_bit(NFS_INO_ACL_LRU_SET, &nfsi->flags); 1734 clear_bit(NFS_INO_ACL_LRU_SET, &nfsi->flags);
1735 smp_mb__after_clear_bit();
1708 } 1736 }
1709 spin_unlock(&inode->i_lock); 1737 spin_unlock(&inode->i_lock);
1710 spin_unlock(&nfs_access_lru_lock);
1711 iput(inode);
1712 up_read(s_umount);
1713 goto restart;
1714 } 1738 }
1715 spin_unlock(&nfs_access_lru_lock); 1739 spin_unlock(&nfs_access_lru_lock);
1716 while (!list_empty(&head)) { 1740 nfs_access_free_list(&head);
1717 cache = list_entry(head.next, struct nfs_access_entry, lru);
1718 list_del(&cache->lru);
1719 nfs_access_free_entry(cache);
1720 }
1721 return (atomic_long_read(&nfs_access_nr_entries) / 100) * sysctl_vfs_cache_pressure; 1741 return (atomic_long_read(&nfs_access_nr_entries) / 100) * sysctl_vfs_cache_pressure;
1722} 1742}
1723 1743
1724static void __nfs_access_zap_cache(struct inode *inode) 1744static void __nfs_access_zap_cache(struct nfs_inode *nfsi, struct list_head *head)
1725{ 1745{
1726 struct nfs_inode *nfsi = NFS_I(inode);
1727 struct rb_root *root_node = &nfsi->access_cache; 1746 struct rb_root *root_node = &nfsi->access_cache;
1728 struct rb_node *n, *dispose = NULL; 1747 struct rb_node *n;
1729 struct nfs_access_entry *entry; 1748 struct nfs_access_entry *entry;
1730 1749
1731 /* Unhook entries from the cache */ 1750 /* Unhook entries from the cache */
1732 while ((n = rb_first(root_node)) != NULL) { 1751 while ((n = rb_first(root_node)) != NULL) {
1733 entry = rb_entry(n, struct nfs_access_entry, rb_node); 1752 entry = rb_entry(n, struct nfs_access_entry, rb_node);
1734 rb_erase(n, root_node); 1753 rb_erase(n, root_node);
1735 list_del(&entry->lru); 1754 list_move(&entry->lru, head);
1736 n->rb_left = dispose;
1737 dispose = n;
1738 } 1755 }
1739 nfsi->cache_validity &= ~NFS_INO_INVALID_ACCESS; 1756 nfsi->cache_validity &= ~NFS_INO_INVALID_ACCESS;
1740 spin_unlock(&inode->i_lock);
1741
1742 /* Now kill them all! */
1743 while (dispose != NULL) {
1744 n = dispose;
1745 dispose = n->rb_left;
1746 nfs_access_free_entry(rb_entry(n, struct nfs_access_entry, rb_node));
1747 }
1748} 1757}
1749 1758
1750void nfs_access_zap_cache(struct inode *inode) 1759void nfs_access_zap_cache(struct inode *inode)
1751{ 1760{
1761 LIST_HEAD(head);
1762
1763 if (test_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags) == 0)
1764 return;
1752 /* Remove from global LRU init */ 1765 /* Remove from global LRU init */
1753 if (test_and_clear_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) { 1766 spin_lock(&nfs_access_lru_lock);
1754 spin_lock(&nfs_access_lru_lock); 1767 if (test_and_clear_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags))
1755 list_del_init(&NFS_I(inode)->access_cache_inode_lru); 1768 list_del_init(&NFS_I(inode)->access_cache_inode_lru);
1756 spin_unlock(&nfs_access_lru_lock);
1757 }
1758 1769
1759 spin_lock(&inode->i_lock); 1770 spin_lock(&inode->i_lock);
1760 /* This will release the spinlock */ 1771 __nfs_access_zap_cache(NFS_I(inode), &head);
1761 __nfs_access_zap_cache(inode); 1772 spin_unlock(&inode->i_lock);
1773 spin_unlock(&nfs_access_lru_lock);
1774 nfs_access_free_list(&head);
1762} 1775}
1763 1776
1764static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, struct rpc_cred *cred) 1777static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, struct rpc_cred *cred)
@@ -1809,8 +1822,8 @@ out_stale:
1809 nfs_access_free_entry(cache); 1822 nfs_access_free_entry(cache);
1810 return -ENOENT; 1823 return -ENOENT;
1811out_zap: 1824out_zap:
1812 /* This will release the spinlock */ 1825 spin_unlock(&inode->i_lock);
1813 __nfs_access_zap_cache(inode); 1826 nfs_access_zap_cache(inode);
1814 return -ENOENT; 1827 return -ENOENT;
1815} 1828}
1816 1829
@@ -1865,9 +1878,11 @@ static void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *s
1865 smp_mb__after_atomic_inc(); 1878 smp_mb__after_atomic_inc();
1866 1879
1867 /* Add inode to global LRU list */ 1880 /* Add inode to global LRU list */
1868 if (!test_and_set_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) { 1881 if (!test_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) {
1869 spin_lock(&nfs_access_lru_lock); 1882 spin_lock(&nfs_access_lru_lock);
1870 list_add_tail(&NFS_I(inode)->access_cache_inode_lru, &nfs_access_lru_list); 1883 if (!test_and_set_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags))
1884 list_add_tail(&NFS_I(inode)->access_cache_inode_lru,
1885 &nfs_access_lru_list);
1871 spin_unlock(&nfs_access_lru_lock); 1886 spin_unlock(&nfs_access_lru_lock);
1872 } 1887 }
1873} 1888}
@@ -1929,7 +1944,7 @@ int nfs_permission(struct inode *inode, int mask)
1929 if ((mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == 0) 1944 if ((mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == 0)
1930 goto out; 1945 goto out;
1931 /* Is this sys_access() ? */ 1946 /* Is this sys_access() ? */
1932 if (mask & MAY_ACCESS) 1947 if (mask & (MAY_ACCESS | MAY_CHDIR))
1933 goto force_lookup; 1948 goto force_lookup;
1934 1949
1935 switch (inode->i_mode & S_IFMT) { 1950 switch (inode->i_mode & S_IFMT) {