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 09/18] fsck.overlay: add counter of checked objects
Date: Thu, 14 Dec 2017 14:47:38 +0800 [thread overview]
Message-ID: <20171214064747.20999-10-yi.zhang@huawei.com> (raw)
In-Reply-To: <20171214064747.20999-1-yi.zhang@huawei.com>
Count files, sub-directories, whiteouts, opaque directories, redirect
directories (total/invalid/delete/creat) when scaning and fixing
underlying directories of overlayfs. Warn user if any invalid left after
fsck.
Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
---
check.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
lib.c | 5 ++++-
lib.h | 14 ++++++++++++++
3 files changed, 78 insertions(+), 4 deletions(-)
mode change 100755 => 100644 check.c
diff --git a/check.c b/check.c
old mode 100755
new mode 100644
index b26638e..b3a8607
--- a/check.c
+++ b/check.c
@@ -199,6 +199,8 @@ static int ovl_check_whiteout(struct scan_ctx *sctx)
if (!is_whiteout(st))
return 0;
+ sctx->whiteouts[SC_TOTAL]++;
+
/* Is Whiteout in the bottom lower dir ? */
if (sctx->dirtype == OVL_LOWER && sctx->num == lower_num-1)
goto remove;
@@ -216,6 +218,7 @@ static int ovl_check_whiteout(struct scan_ctx *sctx)
goto out;
remove:
+ sctx->whiteouts[SC_INVALID]++;
/* Remove orphan whiteout directly or ask user */
print_info(_("Orphan whiteout: %s "), pathname);
if (!ask_question("Remove", 1))
@@ -227,6 +230,7 @@ remove:
strerror(errno));
return ret;
}
+ sctx->whiteouts[SC_INVALID_DEL]++;
out:
return ret;
}
@@ -252,6 +256,8 @@ static int ovl_check_opaque(struct scan_ctx *sctx)
if (!ovl_is_opaque(pathname))
goto out;
+ sctx->opaques[SC_TOTAL]++;
+
/* Opaque dir in last lower dir ? */
if (sctx->dirtype == OVL_LOWER && sctx->num == lower_num-1)
goto remove;
@@ -278,12 +284,15 @@ static int ovl_check_opaque(struct scan_ctx *sctx)
goto out;
remove:
+ sctx->opaques[SC_INVALID]++;
/* Remove opaque xattr or ask user */
print_info(_("Invalid opaque xattr: %s "), pathname);
if (!ask_question("Remove", 1))
return 0;
ret = ovl_remove_opaque(pathname);
+ if (!ret)
+ sctx->opaques[SC_INVALID_DEL]++;
out:
return ret;
}
@@ -381,6 +390,7 @@ static int ovl_check_redirect(struct scan_ctx *sctx)
return ret;
print_debug(_("Dir %s has redirect %s\n"), pathname, redirect);
+ sctx->redirects[SC_TOTAL]++;
/* Redirect dir in last lower dir ? */
if (sctx->dirtype == OVL_LOWER && sctx->num == lower_num-1)
@@ -401,6 +411,7 @@ static int ovl_check_redirect(struct scan_ctx *sctx)
print_info("origin:%s current:%s last:%s\n",
chk.path, pathname, tmp);
+ sctx->redirects[SC_INVALID]++;
set_st_inconsistency(&status);
}
@@ -418,23 +429,34 @@ static int ovl_check_redirect(struct scan_ctx *sctx)
}
/* Found nothing, create a whiteout */
- ret = ovl_create_whiteout(redirect_rpath);
+ if ((ret = ovl_create_whiteout(redirect_rpath)))
+ goto out;
+
+ 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 */
- ret = ovl_set_opaque(redirect_rpath);
+ if ((ret = ovl_set_opaque(redirect_rpath)))
+ goto out;
+
+ sctx->opaques[SC_CREATE]++;
+ sctx->opaques[SC_TOTAL]++;
}
goto out;
}
remove:
+ sctx->redirects[SC_INVALID]++;
/* Remove redirect xattr or ask user */
print_info(_("Invalid redirect xattr: %s "), pathname);
if (!ask_question("Remove", 1))
goto out;
ret = ovl_remove_redirect(pathname);
+ if (!ret)
+ sctx->redirects[SC_INVALID_DEL]++;
out:
free(redirect);
return ret;
@@ -446,6 +468,40 @@ static struct scan_operations ovl_scan_ops = {
.redirect = ovl_check_redirect,
};
+static void ovl_scan_report(struct scan_ctx *sctx)
+{
+ int i_whiteouts, i_opaques, i_redirects;
+
+ if (flags | FL_VERBOSE) {
+ print_info(_("Scan %d directories, %d files\n"),
+ sctx->directories, sctx->files);
+ print_info(_("Whiteouts: %d/%d/%d/%d [Total/Invalid/Deleted/Create]\n"),
+ sctx->whiteouts[SC_TOTAL], sctx->whiteouts[SC_INVALID],
+ sctx->whiteouts[SC_INVALID_DEL], sctx->whiteouts[SC_CREATE]);
+ print_info(_("Opaque directories: %d/%d/%d/%d [Total/Invalid/Deleted/Create]\n"),
+ sctx->opaques[SC_TOTAL], sctx->opaques[SC_INVALID],
+ sctx->opaques[SC_INVALID_DEL], sctx->opaques[SC_CREATE]);
+ print_info(_("Redirect directories: %d/%d/%d/%d [Total/Invalid/Deleted/Create]\n"),
+ sctx->redirects[SC_TOTAL], sctx->redirects[SC_INVALID],
+ sctx->redirects[SC_INVALID_DEL], sctx->redirects[SC_CREATE]);
+ }
+
+ i_whiteouts = sctx->whiteouts[SC_INVALID] - sctx->whiteouts[SC_INVALID_DEL];
+ i_opaques = sctx->opaques[SC_INVALID] - sctx->opaques[SC_INVALID_DEL];
+ i_redirects = sctx->redirects[SC_INVALID] - sctx->redirects[SC_INVALID_DEL];
+
+ if (i_whiteouts)
+ print_info(_("Invalid whiteouts %d left!\n"), i_whiteouts);
+ else if (i_opaques)
+ print_info(_("Invalid opaque directories %d left!\n"), i_opaques);
+ else if (i_redirects)
+ print_info(_("Invalid redirect directories %d left!\n"), i_redirects);
+ else
+ return;
+
+ set_st_inconsistency(&status);
+}
+
static void ovl_scan_clean(void)
{
/* Clean redirect entry record */
@@ -455,7 +511,7 @@ static void ovl_scan_clean(void)
/* Scan upperdir and each lowerdirs, check and fix inconsistency */
int ovl_scan_fix(void)
{
- struct scan_ctx sctx;
+ struct scan_ctx sctx = {0};
unsigned int i;
int ret = 0;
@@ -489,6 +545,7 @@ int ovl_scan_fix(void)
goto out;
}
out:
+ ovl_scan_report(&sctx);
ovl_scan_clean();
return ret;
}
diff --git a/lib.c b/lib.c
index ecc5d27..7495af5 100644
--- a/lib.c
+++ b/lib.c
@@ -198,7 +198,6 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop)
ftsent->fts_level, ftsent->fts_statp->st_size,
ftsent->fts_path, ftsent->fts_name);
-
/* Fillup base context */
sctx->pathname = ftsent->fts_path;
sctx->pathlen = ftsent->fts_pathlen;
@@ -207,6 +206,9 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop)
sctx->st = ftsent->fts_statp;
switch (ftsent->fts_info) {
+ case FTS_F:
+ sctx->files++;
+ break;
case FTS_DEFAULT:
/* Check whiteouts */
err = __check_entry(sctx, sop->whiteout);
@@ -214,6 +216,7 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop)
break;
case FTS_D:
/* Check opaque and redirect */
+ sctx->directories++;
err = __check_entry(sctx, sop->opaque);
ret = (ret || !err) ? ret : err;
diff --git a/lib.h b/lib.h
index e389ed6..0f0b526 100644
--- a/lib.h
+++ b/lib.h
@@ -38,6 +38,14 @@
#define OVL_OPAQUE_XATTR "trusted.overlay.opaque"
#define OVL_REDIRECT_XATTR "trusted.overlay.redirect"
+enum scan_count_type {
+ SC_TOTAL = 0, /* total check num */
+ SC_INVALID, /* total invalid num */
+ SC_INVALID_DEL, /* deleted invalid num */
+ SC_CREATE, /* create num */
+ SC_MAX,
+};
+
/* Directories scan data struct */
struct scan_ctx {
const char *dirname; /* upper/lower root dir */
@@ -50,6 +58,12 @@ struct scan_ctx {
const char *filename; /* filename */
size_t filelen; /* strlen(filename) */
struct stat *st; /* file stat */
+
+ int files;
+ int directories;
+ int whiteouts[SC_MAX];
+ int redirects[SC_MAX];
+ int opaques[SC_MAX];
};
/* Directories scan callback operations struct */
--
2.9.5
next prev 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 ` zhangyi (F) [this message]
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 ` [PATCH v2 13/18] fsck.overlay: handle missing case of redirecte directory zhangyi (F)
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-10-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox