mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-04-22 17:17:44 +07:00
NFSv4: Fix lookup revalidate of regular files
If we're revalidating an existing dentry in order to open a file, we need to ensure that we check the directory has not changed before we optimise away the lookup. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
parent
5ceb9d7fda
commit
c7944ebb9c
77
fs/nfs/dir.c
77
fs/nfs/dir.c
@ -1231,7 +1231,8 @@ nfs_do_lookup_revalidate(struct inode *dir, struct dentry *dentry,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
|
__nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags,
|
||||||
|
int (*reval)(struct inode *, struct dentry *, unsigned int))
|
||||||
{
|
{
|
||||||
struct dentry *parent;
|
struct dentry *parent;
|
||||||
struct inode *dir;
|
struct inode *dir;
|
||||||
@ -1242,17 +1243,22 @@ nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
|
|||||||
dir = d_inode_rcu(parent);
|
dir = d_inode_rcu(parent);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return -ECHILD;
|
return -ECHILD;
|
||||||
ret = nfs_do_lookup_revalidate(dir, dentry, flags);
|
ret = reval(dir, dentry, flags);
|
||||||
if (parent != READ_ONCE(dentry->d_parent))
|
if (parent != READ_ONCE(dentry->d_parent))
|
||||||
return -ECHILD;
|
return -ECHILD;
|
||||||
} else {
|
} else {
|
||||||
parent = dget_parent(dentry);
|
parent = dget_parent(dentry);
|
||||||
ret = nfs_do_lookup_revalidate(d_inode(parent), dentry, flags);
|
ret = reval(d_inode(parent), dentry, flags);
|
||||||
dput(parent);
|
dput(parent);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
|
||||||
|
{
|
||||||
|
return __nfs_lookup_revalidate(dentry, flags, nfs_do_lookup_revalidate);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A weaker form of d_revalidate for revalidating just the d_inode(dentry)
|
* A weaker form of d_revalidate for revalidating just the d_inode(dentry)
|
||||||
* when we don't really care about the dentry name. This is called when a
|
* when we don't really care about the dentry name. This is called when a
|
||||||
@ -1609,62 +1615,55 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nfs_atomic_open);
|
EXPORT_SYMBOL_GPL(nfs_atomic_open);
|
||||||
|
|
||||||
static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
|
static int
|
||||||
|
nfs4_do_lookup_revalidate(struct inode *dir, struct dentry *dentry,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (!(flags & LOOKUP_OPEN) || (flags & LOOKUP_DIRECTORY))
|
if (!(flags & LOOKUP_OPEN) || (flags & LOOKUP_DIRECTORY))
|
||||||
goto no_open;
|
goto full_reval;
|
||||||
if (d_mountpoint(dentry))
|
if (d_mountpoint(dentry))
|
||||||
goto no_open;
|
goto full_reval;
|
||||||
if (NFS_SB(dentry->d_sb)->caps & NFS_CAP_ATOMIC_OPEN_V1)
|
|
||||||
goto no_open;
|
|
||||||
|
|
||||||
inode = d_inode(dentry);
|
inode = d_inode(dentry);
|
||||||
|
|
||||||
/* We can't create new files in nfs_open_revalidate(), so we
|
/* We can't create new files in nfs_open_revalidate(), so we
|
||||||
* optimize away revalidation of negative dentries.
|
* optimize away revalidation of negative dentries.
|
||||||
*/
|
*/
|
||||||
if (inode == NULL) {
|
if (inode == NULL)
|
||||||
struct dentry *parent;
|
goto full_reval;
|
||||||
struct inode *dir;
|
|
||||||
|
|
||||||
if (flags & LOOKUP_RCU) {
|
if (NFS_PROTO(dir)->have_delegation(inode, FMODE_READ))
|
||||||
parent = READ_ONCE(dentry->d_parent);
|
return nfs_lookup_revalidate_delegated(dir, dentry, inode);
|
||||||
dir = d_inode_rcu(parent);
|
|
||||||
if (!dir)
|
|
||||||
return -ECHILD;
|
|
||||||
} else {
|
|
||||||
parent = dget_parent(dentry);
|
|
||||||
dir = d_inode(parent);
|
|
||||||
}
|
|
||||||
if (!nfs_neg_need_reval(dir, dentry, flags))
|
|
||||||
ret = 1;
|
|
||||||
else if (flags & LOOKUP_RCU)
|
|
||||||
ret = -ECHILD;
|
|
||||||
if (!(flags & LOOKUP_RCU))
|
|
||||||
dput(parent);
|
|
||||||
else if (parent != READ_ONCE(dentry->d_parent))
|
|
||||||
return -ECHILD;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NFS only supports OPEN on regular files */
|
/* NFS only supports OPEN on regular files */
|
||||||
if (!S_ISREG(inode->i_mode))
|
if (!S_ISREG(inode->i_mode))
|
||||||
goto no_open;
|
goto full_reval;
|
||||||
|
|
||||||
/* We cannot do exclusive creation on a positive dentry */
|
/* We cannot do exclusive creation on a positive dentry */
|
||||||
if (flags & LOOKUP_EXCL)
|
if (flags & (LOOKUP_EXCL | LOOKUP_REVAL))
|
||||||
goto no_open;
|
goto reval_dentry;
|
||||||
|
|
||||||
|
/* Check if the directory changed */
|
||||||
|
if (!nfs_check_verifier(dir, dentry, flags & LOOKUP_RCU))
|
||||||
|
goto reval_dentry;
|
||||||
|
|
||||||
/* Let f_op->open() actually open (and revalidate) the file */
|
/* Let f_op->open() actually open (and revalidate) the file */
|
||||||
ret = 1;
|
return 1;
|
||||||
|
reval_dentry:
|
||||||
|
if (flags & LOOKUP_RCU)
|
||||||
|
return -ECHILD;
|
||||||
|
return nfs_lookup_revalidate_dentry(dir, dentry, inode);;
|
||||||
|
|
||||||
out:
|
full_reval:
|
||||||
return ret;
|
return nfs_do_lookup_revalidate(dir, dentry, flags);
|
||||||
|
}
|
||||||
|
|
||||||
no_open:
|
static int nfs4_lookup_revalidate(struct dentry *dentry, unsigned int flags)
|
||||||
return nfs_lookup_revalidate(dentry, flags);
|
{
|
||||||
|
return __nfs_lookup_revalidate(dentry, flags,
|
||||||
|
nfs4_do_lookup_revalidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NFSV4 */
|
#endif /* CONFIG_NFSV4 */
|
||||||
|
Loading…
Reference in New Issue
Block a user