All of lore.kernel.org
 help / color / mirror / Atom feed
From: "zhangyi (F)" <yi.zhang@huawei.com>
To: linux-unionfs@vger.kernel.org, fstests@vger.kernel.org
Cc: miklos@szeredi.hu, amir73il@gmail.com, eguan@redhat.com,
	darrick.wong@oracle.com, yi.zhang@huawei.com, miaoxie@huawei.com
Subject: [PATCH v2 13/18] fsck.overlay: handle missing case of redirecte directory
Date: Thu, 14 Dec 2017 14:47:42 +0800	[thread overview]
Message-ID: <20171214064747.20999-14-yi.zhang@huawei.com> (raw)
In-Reply-To: <20171214064747.20999-1-yi.zhang@huawei.com>

When we find a valid reidrect dir, the lower redirect target must
be covered by a whiteout or an opaque dir or an other redirect dir.
This patch handle the missing case of another redirect dir. At the
same time, when we remove an invalid redirect xattr, we should also
consider to fix the opaque xattr for this case.

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
---
 check.c | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/check.c b/check.c
index 1e40cac..ca75358 100644
--- a/check.c
+++ b/check.c
@@ -130,6 +130,16 @@ static inline int ovl_remove_redirect(const char *pathname)
 	return remove_xattr(pathname, OVL_REDIRECT_XATTR);
 }
 
+/* Just check exists */
+static inline bool ovl_is_redirect(const char *pathname)
+{
+	bool exist = false;
+	ssize_t ret;
+
+	ret = get_xattr(pathname, OVL_REDIRECT_XATTR, NULL, &exist);
+	return ret ? false : exist;
+}
+
 static inline int ovl_create_whiteout(const char *pathname)
 {
 	int ret;
@@ -380,7 +390,11 @@ static void ovl_redirect_free(void)
  *    If more than one in the same layer, there must be some inconsistency
  *    but not sure which one is invalid, just warn in 'auto' mode and remove
  *    the duplicate one in 'yes' mode.
- * 3) Check and fix the missing whiteout or opaque in redierct parent dir.
+ * 3) Check and fix the missing whiteout or opaque in redierct parent directory
+ *    if there is no another redirected upper directory covering the redirect
+ *    lower target.
+ * When a redirect xattr is removed, and the lower layers have directory with
+ * same name, add opaque to cover it.
  */
 static int ovl_check_redirect(struct scan_ctx *sctx)
 {
@@ -402,8 +416,10 @@ static int ovl_check_redirect(struct scan_ctx *sctx)
 	sctx->redirects[SC_TOTAL]++;
 
 	/* Redirect dir in last lower dir ? */
-	if (sctx->dirtype == OVL_LOWER && sctx->num == lower_num-1)
+	if (sctx->dirtype == OVL_LOWER && sctx->num == lower_num-1) {
+		start = lower_num;
 		goto remove;
+	}
 
 	/* Scan lower directories to check redirect dir exist or not */
 	start = (sctx->dirtype == OVL_LOWER) ? sctx->num + 1 : 0;
@@ -448,8 +464,15 @@ static int ovl_check_redirect(struct scan_ctx *sctx)
 			sctx->whiteouts[SC_CREATE]++;
 			sctx->whiteouts[SC_TOTAL]++;
 
-		} else if (is_dir(&rst) && !ovl_is_opaque(redirect_rpath)) {
-			/* Found a directory but not opaqued, fix opaque xattr */
+		} else if (is_dir(&rst) && !ovl_is_opaque(redirect_rpath) &&
+			   !ovl_is_redirect(redirect_rpath)) {
+			/*
+			 * Found a directory but not opaqued and not
+			 * redirected, fix the opaque xattr. Note that we
+			 * don't check redirect validity here, the opaque
+			 * will be fixed if it's invalid when we remove it
+			 * later.
+			 */
 			if ((ret = ovl_set_opaque(redirect_rpath)))
 				goto out;
 
@@ -467,9 +490,18 @@ remove:
 	if (!ovl_ask_invalid("Invalid redirect xattr", pathname, 1))
 		goto out;
 remove_d:
-	ret = ovl_remove_redirect(pathname);
-	if (!ret)
-		sctx->redirects[SC_INVALID_DEL]++;
+	if ((ret = ovl_remove_redirect(pathname)))
+		goto out;
+
+	sctx->redirects[SC_INVALID_DEL]++;
+
+	/* If lower directory exist, create opaque xattr to cover it */
+	if (start < lower_num) {
+		if ((ret = ovl_check_lower(pathname, start, &chk, false)))
+			goto out;
+		if (chk.exist && is_dir(&chk.st))
+			ret = ovl_set_opaque(pathname);
+	}
 out:
 	free(redirect);
 	return ret;
-- 
2.9.5

  parent reply	other threads:[~2017-12-14  6:42 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-14  6:47 [PATCH v2 00/18] overlay: implement fsck.overlay utility zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 01/18] overlay: implement fsck utility zhangyi (F)
2017-12-14 14:13   ` Miklos Szeredi
2017-12-14 14:33     ` Amir Goldstein
2017-12-14 14:47       ` Miklos Szeredi
2017-12-14 15:03         ` Amir Goldstein
2017-12-14 15:10           ` Miklos Szeredi
2017-12-14 15:18             ` Amir Goldstein
2017-12-14 15:48               ` Miklos Szeredi
2017-12-14 16:03                 ` Vivek Goyal
2017-12-14 16:29                 ` Amir Goldstein
2017-12-15 14:18                   ` Miklos Szeredi
2017-12-15 14:44                     ` Amir Goldstein
2017-12-15 16:06                       ` Miklos Szeredi
2017-12-15 16:14                         ` Miklos Szeredi
2017-12-15 15:16                     ` Vivek Goyal
2017-12-15 16:17                       ` Miklos Szeredi
2017-12-14 15:21       ` Vivek Goyal
2017-12-14 15:43         ` Amir Goldstein
2017-12-14 16:12           ` Vivek Goyal
2017-12-15  4:18       ` zhangyi (F)
2017-12-15  3:35     ` zhangyi (F)
2017-12-15  7:45       ` Amir Goldstein
2017-12-15  9:13         ` zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 02/18] fsck.overlay: fix uninitialized variable zhangyi (F)
2017-12-14  9:15   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 03/18] fsck.overlay: add -n -p and -y options zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 04/18] fsck.overlay: add path package and split helper zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 05/18] fsck.overlay: convert path parse to use helper function zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 06/18] fsck.overlay: open lowerdirs in advance zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 07/18] fsck.overlay: check lowers use relative path zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 08/18] fsck.overlay: fix spelling mistakes zhangyi (F)
2017-12-14  9:13   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 09/18] fsck.overlay: add counter of checked objects zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 10/18] fsck.overlay: fix verbose flag zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 11/18] fsck.overlay: add ovl_ask_invalid helper zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 12/18] fsck.overlay: remove duplicate redirect xattr in yes mode zhangyi (F)
2017-12-14  6:47 ` zhangyi (F) [this message]
2017-12-14  6:47 ` [PATCH v2 14/18] fsck.overlay: correct copyright and License zhangyi (F)
2017-12-14  9:09   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 15/18] fsck.overlay: fix word mistake zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 16/18] fsck.overlay: remove test cases zhangyi (F)
2017-12-14  9:11   ` Amir Goldstein
2017-12-14  6:47 ` [PATCH v2 17/18] fsck.overlay: not enforce overlayfs is offline in 'no changes' mode zhangyi (F)
2017-12-14  6:47 ` [PATCH v2 18/18] fsck.overlay: use relative path when checking lowers zhangyi (F)
2017-12-14  9:27 ` [PATCH v2 00/18] overlay: implement fsck.overlay utility Amir Goldstein
2017-12-14 10:43   ` zhangyi (F)

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=20171214064747.20999-14-yi.zhang@huawei.com \
    --to=yi.zhang@huawei.com \
    --cc=amir73il@gmail.com \
    --cc=darrick.wong@oracle.com \
    --cc=eguan@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.