From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-unionfs@vger.kernel.org
Subject: [PATCH] ovl: create all new directories opaque
Date: Mon, 21 Nov 2016 15:04:05 +0200 [thread overview]
Message-ID: <1479733445-15795-1-git-send-email-amir73il@gmail.com> (raw)
There is really no good reason why not to make all
directories opaque from birth.
The benefit of making directiories opaque on creation
is that lookups can stop short when they reach the
original created directory.
The best case is overlay with N layers, performing
lookup for first level directory, which exists only in upper.
In that case, there will be only one lookup instead of N.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/dir.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index f1794af..cebcec0 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -377,6 +377,8 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
struct dentry *newdentry;
int err;
struct posix_acl *acl, *default_acl;
+ int is_dir = !hardlink && S_ISDIR(stat->mode);
+ int flags = RENAME_EXCHANGE;
if (WARN_ON(!workdir))
return -EROFS;
@@ -403,6 +405,10 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
if (IS_ERR(upper))
goto out_dput;
+ /* mkdir can gets here with no upper whiteout - adjust exchange flag */
+ if (is_dir && d_is_negative(upper))
+ flags = 0;
+
err = ovl_create_real(wdir, newdentry, stat, link, hardlink, true);
if (err)
goto out_dput2;
@@ -434,23 +440,26 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
goto out_cleanup;
}
- if (!hardlink && S_ISDIR(stat->mode)) {
+ if (is_dir) {
err = ovl_set_opaque(newdentry);
if (err)
goto out_cleanup;
- err = ovl_do_rename(wdir, newdentry, udir, upper,
- RENAME_EXCHANGE);
+ err = ovl_do_rename(wdir, newdentry, udir, upper, flags);
if (err)
goto out_cleanup;
- ovl_cleanup(wdir, upper);
+ if (!d_is_negative(upper))
+ ovl_cleanup(wdir, upper);
} else {
err = ovl_do_rename(wdir, newdentry, udir, upper, 0);
if (err)
goto out_cleanup;
}
ovl_instantiate(dentry, inode, newdentry, !!hardlink);
+ /* All directories are created opaque */
+ if (is_dir)
+ ovl_dentry_set_opaque(dentry, true);
newdentry = NULL;
out_dput2:
dput(upper);
@@ -477,6 +486,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
int err;
const struct cred *old_cred;
struct cred *override_cred;
+ int is_dir = !hardlink && S_ISDIR(stat->mode);
err = ovl_copy_up(dentry->d_parent);
if (err)
@@ -500,7 +510,8 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
put_cred(override_creds(override_cred));
put_cred(override_cred);
- if (!ovl_dentry_is_whiteout(dentry))
+ /* Always create new directories opaque */
+ if (!ovl_dentry_is_whiteout(dentry) && !is_dir)
err = ovl_create_upper(dentry, inode, stat, link,
hardlink);
else
@@ -1017,7 +1028,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
err = ovl_set_redirect(old, samedir);
if (err)
goto out_dput;
- } else if (!old_opaque && ovl_lower_positive(new)) {
+ } else if (!old_opaque) {
err = ovl_set_opaque(olddentry);
if (err)
goto out_dput;
@@ -1029,7 +1040,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
err = ovl_set_redirect(new, samedir);
if (err)
goto out_dput;
- } else if (!new_opaque && ovl_lower_positive(old)) {
+ } else if (!new_opaque) {
err = ovl_set_opaque(newdentry);
if (err)
goto out_dput;
--
2.7.4
next reply other threads:[~2016-11-21 13:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-21 13:04 Amir Goldstein [this message]
2016-11-21 13:38 ` [PATCH] ovl: create all new directories opaque Miklos Szeredi
2016-11-21 13:45 ` Amir Goldstein
2016-11-21 14:00 ` Miklos Szeredi
2016-11-21 16:57 ` [PATCH v2] ovl: create directories inside merged parent opaque Amir Goldstein
2016-11-30 11:09 ` Miklos Szeredi
2016-11-30 12:58 ` Amir Goldstein
2016-11-30 14:19 ` Miklos Szeredi
2016-11-30 14:49 ` Amir Goldstein
2016-11-30 15:09 ` Miklos Szeredi
2016-11-30 15:57 ` Amir Goldstein
2016-11-30 16:06 ` Amir Goldstein
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=1479733445-15795-1-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--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