public inbox for linux-unionfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: linux-unionfs@vger.kernel.org
Cc: miklos@szeredi.hu, amir73il@gmail.com, vgoyal@redhat.com
Subject: [PATCH v10 13/18] ovl: Check metacopy attributes on a chain of origin
Date: Mon, 22 Jan 2018 13:39:59 -0500	[thread overview]
Message-ID: <20180122184004.26026-14-vgoyal@redhat.com> (raw)
In-Reply-To: <20180122184004.26026-1-vgoyal@redhat.com>

So far our check for metacopy is simple. That is we check for presence
of OVL_XATTR_METACOPY only on upper inode. But with the possibility of
metacopy inode being present on lower layer also, we should check it
on the whole origin chain and keep track of which lower dentries are
metacopy.

So this patch adds enahnces ovl_check_metacopy() so that it checks
for metacopy not only on dentry being passed, but also travels through
the chain of origins for that dentry and checks metacopy xattr.

We also need to remember metacopy state of each dentry/inode so that
we don't have to look it up all the time. Hence I added a field
"metacopy" in "struct ovl_path" and set this when a particular dentry
is metacopy only. This only applies to lower dentries as we keep
ovl_path only for lower dentries. Upper dentry continues to rely on
ovl inode flag OVL_UPPERDATA to figure out if upper is metacopy
only inode or not.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 fs/overlayfs/namei.c     | 45 ++++++++++++++++++++++++++++++++++++++++-----
 fs/overlayfs/ovl_entry.h |  1 +
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index 99f896e7bcf2..f6f0d97bd0ca 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -47,11 +47,36 @@ static int ovl_check_metacopy_xattr(struct dentry *dentry)
 	return res;
 }
 
+static int ovl_check_origin_metacopy(struct ovl_path *stackp, unsigned int ctr)
+{
+	int i, metacopy;
+
+	if (!ctr)
+		return 0;
+
+	for (i = 0; i < ctr; i++) {
+		metacopy = ovl_check_metacopy_xattr(stackp[i].dentry);
+		if (metacopy <= 0)
+			return metacopy;
+		stackp[i].metacopy = true;
+	}
+
+	if (stackp[i - 1].metacopy) {
+		/*
+		 * Last origin should not have metacopy set. It should be
+		 * the source of metacopy. Something is wrong.
+		 */
+		return -EIO;
+	}
+
+	return 0;
+}
+
 /* err < 0, 0 if upper does not have metacopy, 1 if metacopy found */
 static int ovl_check_metacopy(struct ovl_fs *ofs, struct dentry *dentry,
-			      unsigned int ctr)
+			      struct ovl_path *stackp, unsigned int ctr)
 {
-	int metacopy;
+	int metacopy, err;
 
 	metacopy = ovl_check_metacopy_xattr(dentry);
 	if (metacopy <= 0 )
@@ -75,6 +100,9 @@ static int ovl_check_metacopy(struct ovl_fs *ofs, struct dentry *dentry,
 		return -EPERM;
 	}
 
+	err = ovl_check_origin_metacopy(stackp, ctr);
+	if (err)
+		return err;
 	return metacopy;
 }
 
@@ -348,8 +376,6 @@ static int ovl_check_origin(struct dentry *dentry,
 	bool mem_allocated = false;
 	struct ovl_path *origin_stack;
 
-	BUG_ON(*ctrp);
-
 	if (!*stackp) {
 		origin_stack = kmalloc(sizeof(struct ovl_path) * nr_path, GFP_KERNEL);
 		if (!origin_stack)
@@ -721,7 +747,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
 			if (err)
 				goto out_put_upper;
 
-			err = ovl_check_metacopy(ofs, upperdentry, ctr);
+			err = ovl_check_metacopy(ofs, upperdentry, stack, ctr);
 			metacopy = err;
 			if (err < 0)
 				goto out_put_upper;
@@ -818,6 +844,15 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
 			goto out_put;
 
 		ctr += nr_origins;
+
+		err = ovl_check_metacopy(ofs, stack[0].dentry, &stack[1],
+					 nr_origins);
+		metacopy = err;
+		if (err < 0)
+			goto out_put;
+
+		if (metacopy)
+			stack[0].metacopy = true;
 	}
 
 	oe = ovl_alloc_entry(ctr);
diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
index 92a4db0bd18c..a8cfdae4df89 100644
--- a/fs/overlayfs/ovl_entry.h
+++ b/fs/overlayfs/ovl_entry.h
@@ -28,6 +28,7 @@ struct ovl_layer {
 struct ovl_path {
 	struct ovl_layer *layer;
 	struct dentry *dentry;
+	bool metacopy;
 };
 
 /* private information held for overlayfs's superblock */
-- 
2.13.6

  parent reply	other threads:[~2018-01-22 18:40 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 18:39 [PATCH v10 00/18] overlayfs: Delayed copy up of data Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 01/18] ovl: Do not look for OVL_XATTR_NLINK if index is not there Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 02/18] ovl: disable redirect_dir and index when no xattr support Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 03/18] ovl: Create origin xattr on copy up for all files Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 04/18] ovl: Provide a mount option metacopy=on/off for metadata copyup Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 05/18] ovl: During copy up, first copy up metadata and then data Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 06/18] ovl: Move the copy up helpers to copy_up.c Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 07/18] ovl: Add mechanism to create a chain of origin dentries Vivek Goyal
2018-01-22 19:34   ` Amir Goldstein
2018-01-22 19:46     ` Amir Goldstein
2018-01-23 13:45       ` Vivek Goyal
2018-01-23 13:47         ` Amir Goldstein
2018-01-23 14:13           ` Vivek Goyal
2018-01-30 19:33           ` Vivek Goyal
2018-01-30 20:03             ` Amir Goldstein
2018-01-30 20:05               ` Amir Goldstein
2018-01-30 20:15                 ` Vivek Goyal
2018-01-30 21:01                   ` Amir Goldstein
2018-01-30 20:06               ` Vivek Goyal
2018-01-23 13:40     ` Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 08/18] ovl: Copy up only metadata during copy up where it makes sense Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 09/18] ovl: Add helper ovl_already_copied_up() Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 10/18] ovl: A new xattr OVL_XATTR_METACOPY for file on upper Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 11/18] ovl: Set OVL_UPPERDATA flag during ovl_lookup() Vivek Goyal
2018-01-22 18:39 ` [PATCH v10 12/18] ovl: Setup origin chain for lower regular files Vivek Goyal
2018-01-22 18:39 ` Vivek Goyal [this message]
2018-01-22 18:40 ` [PATCH v10 14/18] ovl: Do not mark a non dir as _OVL_PATH_MERGE in ovl_path_type() Vivek Goyal
2018-01-22 18:40 ` [PATCH v10 15/18] ovl: Copy up meta inode data from lowest data inode Vivek Goyal
2018-01-22 18:40 ` [PATCH v10 16/18] ovl: Fix ovl_getattr() to get number of blocks from lower Vivek Goyal
2018-01-22 18:40 ` [PATCH v10 17/18] ovl: Do not expose metacopy only upper dentry from d_real() Vivek Goyal
2018-01-22 18:40 ` [PATCH v10 18/18] ovl: Enable metadata only feature Vivek Goyal
2018-01-24  9:05 ` [PATCH v10 00/18] overlayfs: Delayed copy up of data Miklos Szeredi
2018-01-27 16:38   ` 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=20180122184004.26026-14-vgoyal@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=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