Linux Overlay Filesystem development
 help / color / mirror / Atom feed
* [PATCH] ovl: create all new directories opaque
@ 2016-11-21 13:04 Amir Goldstein
  2016-11-21 13:38 ` Miklos Szeredi
  0 siblings, 1 reply; 12+ messages in thread
From: Amir Goldstein @ 2016-11-21 13:04 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-unionfs

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-11-30 16:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-21 13:04 [PATCH] ovl: create all new directories opaque Amir Goldstein
2016-11-21 13:38 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox