Commit dc0755cd authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs pile 2 (of many) from Al Viro:
 "Mostly Miklos' series this time"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  constify dcache.c inlined helpers where possible
  fuse: drop dentry on failed revalidate
  fuse: clean up return in fuse_dentry_revalidate()
  fuse: use d_materialise_unique()
  sysfs: use check_submounts_and_drop()
  nfs: use check_submounts_and_drop()
  gfs2: use check_submounts_and_drop()
  afs: use check_submounts_and_drop()
  vfs: check unlinked ancestors before mount
  vfs: check submounts and drop atomically
  vfs: add d_walk()
  vfs: restructure d_genocide()
parents c7c4591d f0d3b3de
......@@ -685,16 +685,12 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags)
spin_unlock(&dentry->d_lock);
out_bad:
if (dentry->d_inode) {
/* don't unhash if we have submounts */
if (have_submounts(dentry))
goto out_skip;
}
/* don't unhash if we have submounts */
if (check_submounts_and_drop(dentry) != 0)
goto out_skip;
_debug("dropping dentry %s/%s",
parent->d_name.name, dentry->d_name.name);
shrink_dcache_parent(dentry);
d_drop(dentry);
dput(parent);
key_put(key);
......
This diff is collapsed.
......@@ -182,10 +182,11 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
struct inode *inode;
struct dentry *parent;
struct fuse_conn *fc;
int ret;
inode = ACCESS_ONCE(entry->d_inode);
if (inode && is_bad_inode(inode))
return 0;
goto invalid;
else if (fuse_dentry_time(entry) < get_jiffies_64()) {
int err;
struct fuse_entry_out outarg;
......@@ -195,20 +196,23 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
/* For negative dentries, always do a fresh lookup */
if (!inode)
return 0;
goto invalid;
ret = -ECHILD;
if (flags & LOOKUP_RCU)
return -ECHILD;
goto out;
fc = get_fuse_conn(inode);
req = fuse_get_req_nopages(fc);
ret = PTR_ERR(req);
if (IS_ERR(req))
return 0;
goto out;
forget = fuse_alloc_forget();
if (!forget) {
fuse_put_request(fc, req);
return 0;
ret = -ENOMEM;
goto out;
}
attr_version = fuse_get_attr_version(fc);
......@@ -227,7 +231,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
struct fuse_inode *fi = get_fuse_inode(inode);
if (outarg.nodeid != get_node_id(inode)) {
fuse_queue_forget(fc, forget, outarg.nodeid, 1);
return 0;
goto invalid;
}
spin_lock(&fc->lock);
fi->nlookup++;
......@@ -235,7 +239,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
}
kfree(forget);
if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
return 0;
goto invalid;
fuse_change_attributes(inode, &outarg.attr,
entry_attr_timeout(&outarg),
......@@ -249,7 +253,15 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
dput(parent);
}
}
return 1;
ret = 1;
out:
return ret;
invalid:
ret = 0;
if (check_submounts_and_drop(entry) != 0)
ret = 1;
goto out;
}
static int invalid_nodeid(u64 nodeid)
......@@ -267,26 +279,6 @@ int fuse_valid_type(int m)
S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
}
/*
* Add a directory inode to a dentry, ensuring that no other dentry
* refers to this inode. Called with fc->inst_mutex.
*/
static struct dentry *fuse_d_add_directory(struct dentry *entry,
struct inode *inode)
{
struct dentry *alias = d_find_alias(inode);
if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
/* This tries to shrink the subtree below alias */
fuse_invalidate_entry(alias);
dput(alias);
if (!hlist_empty(&inode->i_dentry))
return ERR_PTR(-EBUSY);
} else {
dput(alias);
}
return d_splice_alias(inode, entry);
}
int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
struct fuse_entry_out *outarg, struct inode **inode)
{
......@@ -345,6 +337,24 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
return err;
}
static struct dentry *fuse_materialise_dentry(struct dentry *dentry,
struct inode *inode)
{
struct dentry *newent;
if (inode && S_ISDIR(inode->i_mode)) {
struct fuse_conn *fc = get_fuse_conn(inode);
mutex_lock(&fc->inst_mutex);
newent = d_materialise_unique(dentry, inode);
mutex_unlock(&fc->inst_mutex);
} else {
newent = d_materialise_unique(dentry, inode);
}
return newent;
}
static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
unsigned int flags)
{
......@@ -352,7 +362,6 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
struct fuse_entry_out outarg;
struct inode *inode;
struct dentry *newent;
struct fuse_conn *fc = get_fuse_conn(dir);
bool outarg_valid = true;
err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
......@@ -368,16 +377,10 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
if (inode && get_node_id(inode) == FUSE_ROOT_ID)
goto out_iput;
if (inode && S_ISDIR(inode->i_mode)) {
mutex_lock(&fc->inst_mutex);
newent = fuse_d_add_directory(entry, inode);
mutex_unlock(&fc->inst_mutex);
err = PTR_ERR(newent);
if (IS_ERR(newent))
goto out_iput;
} else {
newent = d_splice_alias(inode, entry);
}
newent = fuse_materialise_dentry(entry, inode);
err = PTR_ERR(newent);
if (IS_ERR(newent))
goto out_err;
entry = newent ? newent : entry;
if (outarg_valid)
......@@ -1275,18 +1278,10 @@ static int fuse_direntplus_link(struct file *file,
if (!inode)
goto out;
if (S_ISDIR(inode->i_mode)) {
mutex_lock(&fc->inst_mutex);
alias = fuse_d_add_directory(dentry, inode);
mutex_unlock(&fc->inst_mutex);
err = PTR_ERR(alias);
if (IS_ERR(alias)) {
iput(inode);
goto out;
}
} else {
alias = d_splice_alias(inode, dentry);
}
alias = fuse_materialise_dentry(dentry, inode);
err = PTR_ERR(alias);
if (IS_ERR(alias))
goto out;
if (alias) {
dput(dentry);
......
......@@ -93,12 +93,9 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
if (!had_lock)
gfs2_glock_dq_uninit(&d_gh);
invalid:
if (inode && S_ISDIR(inode->i_mode)) {
if (have_submounts(dentry))
goto valid;
shrink_dcache_parent(dentry);
}
d_drop(dentry);
if (check_submounts_and_drop(dentry) != 0)
goto valid;
dput(parent);
return 0;
......
......@@ -126,6 +126,7 @@ extern int invalidate_inodes(struct super_block *, bool);
* dcache.c
*/
extern struct dentry *__d_alloc(struct super_block *, const struct qstr *);
extern int d_set_mounted(struct dentry *dentry);
/*
* read_write.c
......
......@@ -611,6 +611,7 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry)
{
struct list_head *chain = mountpoint_hashtable + hash(NULL, dentry);
struct mountpoint *mp;
int ret;
list_for_each_entry(mp, chain, m_hash) {
if (mp->m_dentry == dentry) {
......@@ -626,14 +627,12 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry)
if (!mp)
return ERR_PTR(-ENOMEM);
spin_lock(&dentry->d_lock);
if (d_unlinked(dentry)) {
spin_unlock(&dentry->d_lock);
ret = d_set_mounted(dentry);
if (ret) {
kfree(mp);
return ERR_PTR(-ENOENT);
return ERR_PTR(ret);
}
dentry->d_flags |= DCACHE_MOUNTED;
spin_unlock(&dentry->d_lock);
mp->m_dentry = dentry;
mp->m_count = 1;
list_add(&mp->m_hash, chain);
......
......@@ -1135,14 +1135,13 @@ static int nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
if (inode && S_ISDIR(inode->i_mode)) {
/* Purge readdir caches. */
nfs_zap_caches(inode);
/* If we have submounts, don't unhash ! */
if (have_submounts(dentry))
goto out_valid;
if (dentry->d_flags & DCACHE_DISCONNECTED)
goto out_valid;
shrink_dcache_parent(dentry);
}
d_drop(dentry);
/* If we have submounts, don't unhash ! */
if (check_submounts_and_drop(dentry) != 0)
goto out_valid;
dput(parent);
dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
__func__, dentry->d_parent->d_name.name,
......
......@@ -297,7 +297,6 @@ static int sysfs_dentry_delete(const struct dentry *dentry)
static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
{
struct sysfs_dirent *sd;
int is_dir;
int type;
if (flags & LOOKUP_RCU)
......@@ -341,18 +340,15 @@ static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
* is performed at its new name the dentry will be readded
* to the dcache hashes.
*/
is_dir = (sysfs_type(sd) == SYSFS_DIR);
mutex_unlock(&sysfs_mutex);
if (is_dir) {
/* If we have submounts we must allow the vfs caches
* to lie about the state of the filesystem to prevent
* leaks and other nasty things.
*/
if (have_submounts(dentry))
goto out_valid;
shrink_dcache_parent(dentry);
}
d_drop(dentry);
/* If we have submounts we must allow the vfs caches
* to lie about the state of the filesystem to prevent
* leaks and other nasty things.
*/
if (check_submounts_and_drop(dentry) != 0)
goto out_valid;
return 0;
}
......
......@@ -212,7 +212,7 @@ struct dentry_operations {
extern seqlock_t rename_lock;
static inline int dname_external(struct dentry *dentry)
static inline int dname_external(const struct dentry *dentry)
{
return dentry->d_name.name != dentry->d_iname;
}
......@@ -253,6 +253,7 @@ extern void d_prune_aliases(struct inode *);
/* test whether we have any submounts in a subdir tree */
extern int have_submounts(struct dentry *);
extern int check_submounts_and_drop(struct dentry *);
/*
* This adds the entry to the hash queues.
......@@ -357,17 +358,17 @@ extern struct dentry *dget_parent(struct dentry *dentry);
* Returns true if the dentry passed is not currently hashed.
*/
static inline int d_unhashed(struct dentry *dentry)
static inline int d_unhashed(const struct dentry *dentry)
{
return hlist_bl_unhashed(&dentry->d_hash);
}
static inline int d_unlinked(struct dentry *dentry)
static inline int d_unlinked(const struct dentry *dentry)
{
return d_unhashed(dentry) && !IS_ROOT(dentry);
}
static inline int cant_mount(struct dentry *dentry)
static inline int cant_mount(const struct dentry *dentry)
{
return (dentry->d_flags & DCACHE_CANT_MOUNT);
}
......@@ -381,12 +382,12 @@ static inline void dont_mount(struct dentry *dentry)
extern void dput(struct dentry *);
static inline bool d_managed(struct dentry *dentry)
static inline bool d_managed(const struct dentry *dentry)
{
return dentry->d_flags & DCACHE_MANAGED_DENTRY;
}
static inline bool d_mountpoint(struct dentry *dentry)
static inline bool d_mountpoint(const struct dentry *dentry)
{
return dentry->d_flags & DCACHE_MOUNTED;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment