aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c77
1 files changed, 32 insertions, 45 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index f09b9085f7d8..87bdb5329c3c 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1612,6 +1612,10 @@ EXPORT_SYMBOL(d_obtain_alias);
1612 * If a dentry was found and moved, then it is returned. Otherwise NULL 1612 * If a dentry was found and moved, then it is returned. Otherwise NULL
1613 * is returned. This matches the expected return value of ->lookup. 1613 * is returned. This matches the expected return value of ->lookup.
1614 * 1614 *
1615 * Cluster filesystems may call this function with a negative, hashed dentry.
1616 * In that case, we know that the inode will be a regular file, and also this
1617 * will only occur during atomic_open. So we need to check for the dentry
1618 * being already hashed only in the final case.
1615 */ 1619 */
1616struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) 1620struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
1617{ 1621{
@@ -1636,8 +1640,11 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
1636 security_d_instantiate(dentry, inode); 1640 security_d_instantiate(dentry, inode);
1637 d_rehash(dentry); 1641 d_rehash(dentry);
1638 } 1642 }
1639 } else 1643 } else {
1640 d_add(dentry, inode); 1644 d_instantiate(dentry, inode);
1645 if (d_unhashed(dentry))
1646 d_rehash(dentry);
1647 }
1641 return new; 1648 return new;
1642} 1649}
1643EXPORT_SYMBOL(d_splice_alias); 1650EXPORT_SYMBOL(d_splice_alias);
@@ -1723,7 +1730,7 @@ EXPORT_SYMBOL(d_add_ci);
1723 * Do the slow-case of the dentry name compare. 1730 * Do the slow-case of the dentry name compare.
1724 * 1731 *
1725 * Unlike the dentry_cmp() function, we need to atomically 1732 * Unlike the dentry_cmp() function, we need to atomically
1726 * load the name, length and inode information, so that the 1733 * load the name and length information, so that the
1727 * filesystem can rely on them, and can use the 'name' and 1734 * filesystem can rely on them, and can use the 'name' and
1728 * 'len' information without worrying about walking off the 1735 * 'len' information without worrying about walking off the
1729 * end of memory etc. 1736 * end of memory etc.
@@ -1741,22 +1748,18 @@ enum slow_d_compare {
1741 1748
1742static noinline enum slow_d_compare slow_dentry_cmp( 1749static noinline enum slow_d_compare slow_dentry_cmp(
1743 const struct dentry *parent, 1750 const struct dentry *parent,
1744 struct inode *inode,
1745 struct dentry *dentry, 1751 struct dentry *dentry,
1746 unsigned int seq, 1752 unsigned int seq,
1747 const struct qstr *name) 1753 const struct qstr *name)
1748{ 1754{
1749 int tlen = dentry->d_name.len; 1755 int tlen = dentry->d_name.len;
1750 const char *tname = dentry->d_name.name; 1756 const char *tname = dentry->d_name.name;
1751 struct inode *i = dentry->d_inode;
1752 1757
1753 if (read_seqcount_retry(&dentry->d_seq, seq)) { 1758 if (read_seqcount_retry(&dentry->d_seq, seq)) {
1754 cpu_relax(); 1759 cpu_relax();
1755 return D_COMP_SEQRETRY; 1760 return D_COMP_SEQRETRY;
1756 } 1761 }
1757 if (parent->d_op->d_compare(parent, inode, 1762 if (parent->d_op->d_compare(parent, dentry, tlen, tname, name))
1758 dentry, i,
1759 tlen, tname, name))
1760 return D_COMP_NOMATCH; 1763 return D_COMP_NOMATCH;
1761 return D_COMP_OK; 1764 return D_COMP_OK;
1762} 1765}
@@ -1766,7 +1769,6 @@ static noinline enum slow_d_compare slow_dentry_cmp(
1766 * @parent: parent dentry 1769 * @parent: parent dentry
1767 * @name: qstr of name we wish to find 1770 * @name: qstr of name we wish to find
1768 * @seqp: returns d_seq value at the point where the dentry was found 1771 * @seqp: returns d_seq value at the point where the dentry was found
1769 * @inode: returns dentry->d_inode when the inode was found valid.
1770 * Returns: dentry, or NULL 1772 * Returns: dentry, or NULL
1771 * 1773 *
1772 * __d_lookup_rcu is the dcache lookup function for rcu-walk name 1774 * __d_lookup_rcu is the dcache lookup function for rcu-walk name
@@ -1793,7 +1795,7 @@ static noinline enum slow_d_compare slow_dentry_cmp(
1793 */ 1795 */
1794struct dentry *__d_lookup_rcu(const struct dentry *parent, 1796struct dentry *__d_lookup_rcu(const struct dentry *parent,
1795 const struct qstr *name, 1797 const struct qstr *name,
1796 unsigned *seqp, struct inode *inode) 1798 unsigned *seqp)
1797{ 1799{
1798 u64 hashlen = name->hash_len; 1800 u64 hashlen = name->hash_len;
1799 const unsigned char *str = name->name; 1801 const unsigned char *str = name->name;
@@ -1827,11 +1829,10 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
1827seqretry: 1829seqretry:
1828 /* 1830 /*
1829 * The dentry sequence count protects us from concurrent 1831 * The dentry sequence count protects us from concurrent
1830 * renames, and thus protects inode, parent and name fields. 1832 * renames, and thus protects parent and name fields.
1831 * 1833 *
1832 * The caller must perform a seqcount check in order 1834 * The caller must perform a seqcount check in order
1833 * to do anything useful with the returned dentry, 1835 * to do anything useful with the returned dentry.
1834 * including using the 'd_inode' pointer.
1835 * 1836 *
1836 * NOTE! We do a "raw" seqcount_begin here. That means that 1837 * NOTE! We do a "raw" seqcount_begin here. That means that
1837 * we don't wait for the sequence count to stabilize if it 1838 * we don't wait for the sequence count to stabilize if it
@@ -1845,12 +1846,12 @@ seqretry:
1845 continue; 1846 continue;
1846 if (d_unhashed(dentry)) 1847 if (d_unhashed(dentry))
1847 continue; 1848 continue;
1848 *seqp = seq;
1849 1849
1850 if (unlikely(parent->d_flags & DCACHE_OP_COMPARE)) { 1850 if (unlikely(parent->d_flags & DCACHE_OP_COMPARE)) {
1851 if (dentry->d_name.hash != hashlen_hash(hashlen)) 1851 if (dentry->d_name.hash != hashlen_hash(hashlen))
1852 continue; 1852 continue;
1853 switch (slow_dentry_cmp(parent, inode, dentry, seq, name)) { 1853 *seqp = seq;
1854 switch (slow_dentry_cmp(parent, dentry, seq, name)) {
1854 case D_COMP_OK: 1855 case D_COMP_OK:
1855 return dentry; 1856 return dentry;
1856 case D_COMP_NOMATCH: 1857 case D_COMP_NOMATCH:
@@ -1862,6 +1863,7 @@ seqretry:
1862 1863
1863 if (dentry->d_name.hash_len != hashlen) 1864 if (dentry->d_name.hash_len != hashlen)
1864 continue; 1865 continue;
1866 *seqp = seq;
1865 if (!dentry_cmp(dentry, str, hashlen_len(hashlen))) 1867 if (!dentry_cmp(dentry, str, hashlen_len(hashlen)))
1866 return dentry; 1868 return dentry;
1867 } 1869 }
@@ -1959,9 +1961,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
1959 if (parent->d_flags & DCACHE_OP_COMPARE) { 1961 if (parent->d_flags & DCACHE_OP_COMPARE) {
1960 int tlen = dentry->d_name.len; 1962 int tlen = dentry->d_name.len;
1961 const char *tname = dentry->d_name.name; 1963 const char *tname = dentry->d_name.name;
1962 if (parent->d_op->d_compare(parent, parent->d_inode, 1964 if (parent->d_op->d_compare(parent, dentry, tlen, tname, name))
1963 dentry, dentry->d_inode,
1964 tlen, tname, name))
1965 goto next; 1965 goto next;
1966 } else { 1966 } else {
1967 if (dentry->d_name.len != len) 1967 if (dentry->d_name.len != len)
@@ -1998,7 +1998,7 @@ struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name)
1998 */ 1998 */
1999 name->hash = full_name_hash(name->name, name->len); 1999 name->hash = full_name_hash(name->name, name->len);
2000 if (dir->d_flags & DCACHE_OP_HASH) { 2000 if (dir->d_flags & DCACHE_OP_HASH) {
2001 int err = dir->d_op->d_hash(dir, dir->d_inode, name); 2001 int err = dir->d_op->d_hash(dir, name);
2002 if (unlikely(err < 0)) 2002 if (unlikely(err < 0))
2003 return ERR_PTR(err); 2003 return ERR_PTR(err);
2004 } 2004 }
@@ -2968,34 +2968,21 @@ rename_retry:
2968 goto again; 2968 goto again;
2969} 2969}
2970 2970
2971/** 2971void d_tmpfile(struct dentry *dentry, struct inode *inode)
2972 * find_inode_number - check for dentry with name
2973 * @dir: directory to check
2974 * @name: Name to find.
2975 *
2976 * Check whether a dentry already exists for the given name,
2977 * and return the inode number if it has an inode. Otherwise
2978 * 0 is returned.
2979 *
2980 * This routine is used to post-process directory listings for
2981 * filesystems using synthetic inode numbers, and is necessary
2982 * to keep getcwd() working.
2983 */
2984
2985ino_t find_inode_number(struct dentry *dir, struct qstr *name)
2986{ 2972{
2987 struct dentry * dentry; 2973 inode_dec_link_count(inode);
2988 ino_t ino = 0; 2974 BUG_ON(dentry->d_name.name != dentry->d_iname ||
2989 2975 !hlist_unhashed(&dentry->d_alias) ||
2990 dentry = d_hash_and_lookup(dir, name); 2976 !d_unlinked(dentry));
2991 if (!IS_ERR_OR_NULL(dentry)) { 2977 spin_lock(&dentry->d_parent->d_lock);
2992 if (dentry->d_inode) 2978 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
2993 ino = dentry->d_inode->i_ino; 2979 dentry->d_name.len = sprintf(dentry->d_iname, "#%llu",
2994 dput(dentry); 2980 (unsigned long long)inode->i_ino);
2995 } 2981 spin_unlock(&dentry->d_lock);
2996 return ino; 2982 spin_unlock(&dentry->d_parent->d_lock);
2983 d_instantiate(dentry, inode);
2997} 2984}
2998EXPORT_SYMBOL(find_inode_number); 2985EXPORT_SYMBOL(d_tmpfile);
2999 2986
3000static __initdata unsigned long dhash_entries; 2987static __initdata unsigned long dhash_entries;
3001static int __init set_dhash_entries(char *str) 2988static int __init set_dhash_entries(char *str)