Skip to content

Commit 1a0a397

Browse files
J. Bruce FieldsAl Viro
authored andcommitted
dcache: d_obtain_alias callers don't all want DISCONNECTED
There are a few d_obtain_alias callers that are using it to get the root of a filesystem which may already have an alias somewhere else. This is not the same as the filehandle-lookup case, and none of them actually need DCACHE_DISCONNECTED set. It isn't really a serious problem, but it would really be clearer if we reserved DCACHE_DISCONNECTED for those cases where it's actually needed. In the btrfs case this was causing a spurious printk from nfsd/nfsfh.c:fh_verify when it found an unexpected DCACHE_DISCONNECTED dentry. Josef worked around this by unsetting DCACHE_DISCONNECTED manually in 3a0dfa6 "Btrfs: unset DCACHE_DISCONNECTED when mounting default subvol", and this replaces that workaround. Cc: Josef Bacik <jbacik@fb.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent da093a9 commit 1a0a397

6 files changed

Lines changed: 54 additions & 31 deletions

File tree

‎fs/btrfs/super.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ static struct dentry *get_default_root(struct super_block *sb,
851851
struct btrfs_path *path;
852852
struct btrfs_key location;
853853
struct inode *inode;
854-
struct dentry *dentry;
855854
u64 dir_id;
856855
int new = 0;
857856

@@ -922,13 +921,7 @@ static struct dentry *get_default_root(struct super_block *sb,
922921
return dget(sb->s_root);
923922
}
924923

925-
dentry = d_obtain_alias(inode);
926-
if (!IS_ERR(dentry)) {
927-
spin_lock(&dentry->d_lock);
928-
dentry->d_flags &= ~DCACHE_DISCONNECTED;
929-
spin_unlock(&dentry->d_lock);
930-
}
931-
return dentry;
924+
return d_obtain_root(inode);
932925
}
933926

934927
static int btrfs_fill_super(struct super_block *sb,

‎fs/ceph/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
755755
goto out;
756756
}
757757
} else {
758-
root = d_obtain_alias(inode);
758+
root = d_obtain_root(inode);
759759
}
760760
ceph_init_dentry(root);
761761
dout("open_root_inode success, root dentry is %p\n", root);

‎fs/dcache.c‎

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,25 +1781,7 @@ struct dentry *d_find_any_alias(struct inode *inode)
17811781
}
17821782
EXPORT_SYMBOL(d_find_any_alias);
17831783

1784-
/**
1785-
* d_obtain_alias - find or allocate a dentry for a given inode
1786-
* @inode: inode to allocate the dentry for
1787-
*
1788-
* Obtain a dentry for an inode resulting from NFS filehandle conversion or
1789-
* similar open by handle operations. The returned dentry may be anonymous,
1790-
* or may have a full name (if the inode was already in the cache).
1791-
*
1792-
* When called on a directory inode, we must ensure that the inode only ever
1793-
* has one dentry. If a dentry is found, that is returned instead of
1794-
* allocating a new one.
1795-
*
1796-
* On successful return, the reference to the inode has been transferred
1797-
* to the dentry. In case of an error the reference on the inode is released.
1798-
* To make it easier to use in export operations a %NULL or IS_ERR inode may
1799-
* be passed in and will be the error will be propagate to the return value,
1800-
* with a %NULL @inode replaced by ERR_PTR(-ESTALE).
1801-
*/
1802-
struct dentry *d_obtain_alias(struct inode *inode)
1784+
struct dentry *__d_obtain_alias(struct inode *inode, int disconnected)
18031785
{
18041786
static const struct qstr anonstring = QSTR_INIT("/", 1);
18051787
struct dentry *tmp;
@@ -1830,7 +1812,10 @@ struct dentry *d_obtain_alias(struct inode *inode)
18301812
}
18311813

18321814
/* attach a disconnected dentry */
1833-
add_flags = d_flags_for_inode(inode) | DCACHE_DISCONNECTED;
1815+
add_flags = d_flags_for_inode(inode);
1816+
1817+
if (disconnected)
1818+
add_flags |= DCACHE_DISCONNECTED;
18341819

18351820
spin_lock(&tmp->d_lock);
18361821
tmp->d_inode = inode;
@@ -1851,8 +1836,52 @@ struct dentry *d_obtain_alias(struct inode *inode)
18511836
iput(inode);
18521837
return res;
18531838
}
1839+
1840+
/**
1841+
* d_obtain_alias - find or allocate a DISCONNECTED dentry for a given inode
1842+
* @inode: inode to allocate the dentry for
1843+
*
1844+
* Obtain a dentry for an inode resulting from NFS filehandle conversion or
1845+
* similar open by handle operations. The returned dentry may be anonymous,
1846+
* or may have a full name (if the inode was already in the cache).
1847+
*
1848+
* When called on a directory inode, we must ensure that the inode only ever
1849+
* has one dentry. If a dentry is found, that is returned instead of
1850+
* allocating a new one.
1851+
*
1852+
* On successful return, the reference to the inode has been transferred
1853+
* to the dentry. In case of an error the reference on the inode is released.
1854+
* To make it easier to use in export operations a %NULL or IS_ERR inode may
1855+
* be passed in and the error will be propagated to the return value,
1856+
* with a %NULL @inode replaced by ERR_PTR(-ESTALE).
1857+
*/
1858+
struct dentry *d_obtain_alias(struct inode *inode)
1859+
{
1860+
return __d_obtain_alias(inode, 1);
1861+
}
18541862
EXPORT_SYMBOL(d_obtain_alias);
18551863

1864+
/**
1865+
* d_obtain_root - find or allocate a dentry for a given inode
1866+
* @inode: inode to allocate the dentry for
1867+
*
1868+
* Obtain an IS_ROOT dentry for the root of a filesystem.
1869+
*
1870+
* We must ensure that directory inodes only ever have one dentry. If a
1871+
* dentry is found, that is returned instead of allocating a new one.
1872+
*
1873+
* On successful return, the reference to the inode has been transferred
1874+
* to the dentry. In case of an error the reference on the inode is
1875+
* released. A %NULL or IS_ERR inode may be passed in and will be the
1876+
* error will be propagate to the return value, with a %NULL @inode
1877+
* replaced by ERR_PTR(-ESTALE).
1878+
*/
1879+
struct dentry *d_obtain_root(struct inode *inode)
1880+
{
1881+
return __d_obtain_alias(inode, 0);
1882+
}
1883+
EXPORT_SYMBOL(d_obtain_root);
1884+
18561885
/**
18571886
* d_add_ci - lookup or allocate new dentry with case-exact name
18581887
* @inode: the inode case-insensitive lookup has found

‎fs/nfs/getroot.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh,
112112
* if the dentry tree reaches them; however if the dentry already
113113
* exists, we'll pick it up at this point and use it as the root
114114
*/
115-
ret = d_obtain_alias(inode);
115+
ret = d_obtain_root(inode);
116116
if (IS_ERR(ret)) {
117117
dprintk("nfs_get_root: get root dentry failed\n");
118118
goto out;

‎fs/nilfs2/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ static int nilfs_get_root_dentry(struct super_block *sb,
942942
iput(inode);
943943
}
944944
} else {
945-
dentry = d_obtain_alias(inode);
945+
dentry = d_obtain_root(inode);
946946
if (IS_ERR(dentry)) {
947947
ret = PTR_ERR(dentry);
948948
goto failed_dentry;

‎include/linux/dcache.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
249249
extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
250250
extern struct dentry *d_find_any_alias(struct inode *inode);
251251
extern struct dentry * d_obtain_alias(struct inode *);
252+
extern struct dentry * d_obtain_root(struct inode *);
252253
extern void shrink_dcache_sb(struct super_block *);
253254
extern void shrink_dcache_parent(struct dentry *);
254255
extern void shrink_dcache_for_umount(struct super_block *);

0 commit comments

Comments
 (0)