dcache: extrace and use d_unlinked()
d_unlinked() will be used in middle-term to ban checkpointing when opened but unlinked file is detected, and in long term, to detect such situation and special case on it. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
8c85e12512
commit
f3da392e9f
|
@ -1910,7 +1910,7 @@ char *__d_path(const struct path *path, struct path *root,
|
||||||
|
|
||||||
spin_lock(&vfsmount_lock);
|
spin_lock(&vfsmount_lock);
|
||||||
prepend(&end, &buflen, "\0", 1);
|
prepend(&end, &buflen, "\0", 1);
|
||||||
if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
|
if (d_unlinked(dentry) &&
|
||||||
(prepend(&end, &buflen, " (deleted)", 10) != 0))
|
(prepend(&end, &buflen, " (deleted)", 10) != 0))
|
||||||
goto Elong;
|
goto Elong;
|
||||||
|
|
||||||
|
@ -2035,7 +2035,7 @@ char *dentry_path(struct dentry *dentry, char *buf, int buflen)
|
||||||
|
|
||||||
spin_lock(&dcache_lock);
|
spin_lock(&dcache_lock);
|
||||||
prepend(&end, &buflen, "\0", 1);
|
prepend(&end, &buflen, "\0", 1);
|
||||||
if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
|
if (d_unlinked(dentry) &&
|
||||||
(prepend(&end, &buflen, "//deleted", 9) != 0))
|
(prepend(&end, &buflen, "//deleted", 9) != 0))
|
||||||
goto Elong;
|
goto Elong;
|
||||||
if (buflen < 1)
|
if (buflen < 1)
|
||||||
|
@ -2097,9 +2097,8 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
|
||||||
read_unlock(¤t->fs->lock);
|
read_unlock(¤t->fs->lock);
|
||||||
|
|
||||||
error = -ENOENT;
|
error = -ENOENT;
|
||||||
/* Has the current directory has been unlinked? */
|
|
||||||
spin_lock(&dcache_lock);
|
spin_lock(&dcache_lock);
|
||||||
if (IS_ROOT(pwd.dentry) || !d_unhashed(pwd.dentry)) {
|
if (!d_unlinked(pwd.dentry)) {
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
struct path tmp = root;
|
struct path tmp = root;
|
||||||
char * cwd;
|
char * cwd;
|
||||||
|
|
|
@ -1384,7 +1384,7 @@ static int graft_tree(struct vfsmount *mnt, struct path *path)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
if (IS_ROOT(path->dentry) || !d_unhashed(path->dentry))
|
if (!d_unlinked(path->dentry))
|
||||||
err = attach_recursive_mnt(mnt, path, NULL);
|
err = attach_recursive_mnt(mnt, path, NULL);
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&path->dentry->d_inode->i_mutex);
|
mutex_unlock(&path->dentry->d_inode->i_mutex);
|
||||||
|
@ -1566,7 +1566,7 @@ static int do_move_mount(struct path *path, char *old_name)
|
||||||
if (IS_DEADDIR(path->dentry->d_inode))
|
if (IS_DEADDIR(path->dentry->d_inode))
|
||||||
goto out1;
|
goto out1;
|
||||||
|
|
||||||
if (!IS_ROOT(path->dentry) && d_unhashed(path->dentry))
|
if (d_unlinked(path->dentry))
|
||||||
goto out1;
|
goto out1;
|
||||||
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
|
@ -2129,9 +2129,9 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
|
||||||
error = -ENOENT;
|
error = -ENOENT;
|
||||||
if (IS_DEADDIR(new.dentry->d_inode))
|
if (IS_DEADDIR(new.dentry->d_inode))
|
||||||
goto out2;
|
goto out2;
|
||||||
if (d_unhashed(new.dentry) && !IS_ROOT(new.dentry))
|
if (d_unlinked(new.dentry))
|
||||||
goto out2;
|
goto out2;
|
||||||
if (d_unhashed(old.dentry) && !IS_ROOT(old.dentry))
|
if (d_unlinked(old.dentry))
|
||||||
goto out2;
|
goto out2;
|
||||||
error = -EBUSY;
|
error = -EBUSY;
|
||||||
if (new.mnt == root.mnt ||
|
if (new.mnt == root.mnt ||
|
||||||
|
|
|
@ -353,6 +353,11 @@ static inline int d_unhashed(struct dentry *dentry)
|
||||||
return (dentry->d_flags & DCACHE_UNHASHED);
|
return (dentry->d_flags & DCACHE_UNHASHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int d_unlinked(struct dentry *dentry)
|
||||||
|
{
|
||||||
|
return d_unhashed(dentry) && !IS_ROOT(dentry);
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct dentry *dget_parent(struct dentry *dentry)
|
static inline struct dentry *dget_parent(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
struct dentry *ret;
|
struct dentry *ret;
|
||||||
|
|
Loading…
Reference in New Issue