From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Guillem Jover <guillem@debian.org>,
Raphael Hertzog <hertzog@debian.org>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH] ovl: check for emptiness of redirect dir
Date: Wed, 26 Oct 2016 12:34:06 +0300 [thread overview]
Message-ID: <1477474446-13429-1-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1477380887-21333-1-git-send-email-mszeredi@redhat.com>
Before introducing redirect_dir feature, the condition
!ovl_lower_positive(dentry) for a directory, implied that
it is a pure upper directory, which may be removed if empty.
Now that directory can be redirect, it is possible that
upper does not cover any lower (i.e. !ovl_lower_positive(dentry)),
but the directory is a merge (with redirected path) and maybe
non empty.
Check for this case in ovl_remove_upper().
This change fixes the following test case from rename-pop-dir.py
of unionmount-testsuite:
"""Remove dir and rename old name"""
d = ctx.non_empty_dir()
d2 = ctx.no_dir()
ctx.rmdir(d, err=ENOTEMPTY)
ctx.rename(d, d2)
ctx.rmdir(d, err=ENOENT)
ctx.rmdir(d2, err=ENOTEMPTY)
./run --ov rename-pop-dir
/mnt/a/no_dir103: Expected error (Directory not empty) was not produced
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/dir.c | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 065e021..d750ed9 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -672,9 +672,18 @@ static int ovl_remove_upper(struct dentry *dentry, bool is_dir)
{
struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent);
struct inode *dir = upperdir->d_inode;
- struct dentry *upper;
+ struct dentry *upper = NULL;
+ struct dentry *opaquedir = NULL;
int err;
+ /* Redirect dir can be !ovl_lower_positive && OVL_TYPE_MERGE */
+ if (is_dir && ovl_dentry_is_redirect(dentry)) {
+ opaquedir = ovl_check_empty_and_clear(dentry);
+ err = PTR_ERR(opaquedir);
+ if (IS_ERR(opaquedir))
+ return err;
+ }
+
inode_lock_nested(dir, I_MUTEX_PARENT);
upper = lookup_one_len(dentry->d_name.name, upperdir,
dentry->d_name.len);
@@ -683,14 +692,15 @@ static int ovl_remove_upper(struct dentry *dentry, bool is_dir)
goto out_unlock;
err = -ESTALE;
- if (upper == ovl_dentry_upper(dentry)) {
- if (is_dir)
- err = vfs_rmdir(dir, upper);
- else
- err = vfs_unlink(dir, upper, NULL);
- ovl_dentry_version_inc(dentry->d_parent);
- }
- dput(upper);
+ if ((opaquedir && upper != opaquedir) ||
+ upper != ovl_dentry_upper(dentry))
+ goto out_dput_upper;
+
+ if (is_dir)
+ err = vfs_rmdir(dir, upper);
+ else
+ err = vfs_unlink(dir, upper, NULL);
+ ovl_dentry_version_inc(dentry->d_parent);
/*
* Keeping this dentry hashed would mean having to release
@@ -700,8 +710,11 @@ static int ovl_remove_upper(struct dentry *dentry, bool is_dir)
*/
if (!err)
d_drop(dentry);
+out_dput_upper:
+ dput(upper);
out_unlock:
inode_unlock(dir);
+ dput(opaquedir);
return err;
}
--
2.7.4
next prev parent reply other threads:[~2016-10-26 9:34 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-25 7:34 [PATCH 0/3] overlayfs: allow moving directory trees Miklos Szeredi
2016-10-25 7:34 ` [PATCH 1/3] ovl: check fs features Miklos Szeredi
2016-10-25 11:24 ` Amir Goldstein
2016-11-05 20:40 ` Amir Goldstein
2016-10-25 7:34 ` [PATCH 2/3] vfs: export vfs_path_lookup() Miklos Szeredi
2016-10-25 7:34 ` [PATCH 3/3] ovl: redirect on rename-dir Miklos Szeredi
2016-10-25 11:57 ` Raphael Hertzog
2016-10-26 11:12 ` Miklos Szeredi
2016-10-28 12:56 ` Raphael Hertzog
2016-10-28 12:59 ` Miklos Szeredi
2016-11-06 19:14 ` Konstantin Khlebnikov
2016-11-07 8:07 ` Miklos Szeredi
2016-11-07 9:58 ` Konstantin Khlebnikov
2016-11-07 10:04 ` Miklos Szeredi
2016-11-07 10:08 ` Konstantin Khlebnikov
2016-11-07 13:38 ` Amir Goldstein
2016-11-10 22:56 ` Amir Goldstein
2016-11-11 9:46 ` Konstantin Khlebnikov
2016-11-11 10:06 ` Miklos Szeredi
2016-11-11 12:42 ` Amir Goldstein
2016-11-13 9:11 ` Amir Goldstein
2016-11-07 11:03 ` Raphael Hertzog
2016-11-07 11:31 ` Konstantin Khlebnikov
2016-11-07 13:42 ` Raphael Hertzog
2016-11-10 22:39 ` Miklos Szeredi
2016-11-11 9:41 ` Konstantin Khlebnikov
2016-11-13 10:00 ` Amir Goldstein
2016-11-14 16:25 ` Amir Goldstein
2016-11-16 22:00 ` Miklos Szeredi
2016-11-18 15:37 ` Amir Goldstein
2016-11-20 11:39 ` Amir Goldstein
2016-11-21 9:54 ` Miklos Szeredi
2016-11-21 10:13 ` Amir Goldstein
2016-11-21 10:16 ` Miklos Szeredi
2016-11-22 13:42 ` Amir Goldstein
2016-10-25 12:49 ` Amir Goldstein
2016-10-26 11:26 ` Miklos Szeredi
2016-10-26 12:11 ` Amir Goldstein
2016-10-26 12:51 ` Miklos Szeredi
2016-10-26 19:56 ` Amir Goldstein
2016-10-30 22:00 ` Amir Goldstein
2016-10-31 14:59 ` Miklos Szeredi
2016-10-31 15:02 ` Amir Goldstein
2016-10-28 16:15 ` Al Viro
2016-11-03 15:50 ` Miklos Szeredi
2016-11-04 9:29 ` Amir Goldstein
2016-11-04 13:48 ` Miklos Szeredi
2016-10-25 20:25 ` [PATCH 0/3] overlayfs: allow moving directory trees Amir Goldstein
2016-10-26 9:37 ` Amir Goldstein
2016-10-26 9:34 ` Amir Goldstein [this message]
2016-10-26 10:45 ` [PATCH] ovl: check for emptiness of redirect dir Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477474446-13429-1-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=guillem@debian.org \
--cc=hertzog@debian.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).