overlay: implement fsck.overlay utility
v4 cover overlay: implement fsck.overlay utility
Hi All,
Here is the forth version of fsck.overlay. Most of comments from last three iterations have been handled. Now, this tool have three basic features (see README for detail, include TODO list):
1. Check and fix orphan whiteouts,
2. Check and fix invalid/duplicate redirect directories,
3. Check and fix missing impure xattrs.
This incubation tool will post to github repository[1] directly. Any suggestion is helpful if you review the source code or find bugs/improvements when you use/test this tool.
Thanks,
Yi.
[1] https://github.com/hisilicon/overlayfs-progs
Changes since v3:
- Use existing library for path manipulation and separate self-implemented manipulation helpers. (Comment from Amir)
- Use fstatat() with relative path instead of lstat() with absolute path when traverse layers and lookup target. (Amir)
- Split check routines into two pass, the first pass check redirect dir to confirm directory structure, the second pass check whiteouts and impure xattr.
- Change list to linux kernel style.
- Fix duplicate redirect xattr check, correct questions and default actions, and handle cases of duplicate redirect xattr in different layers. (Amir)
- Fix impure xattr comments and invalid error message. (Amir & Vivek)
----------------
Changes since v2(v1):
- Add "-n -p -y" options. (Comment from Amir and Darrick)
- Change underlying dirs input to '-o' option like mount(8). (Miklos)
- Remove invalid opaque check. (Miklos)
- Correct redirect xattr check. (Amir and Miklos)
- Fix lower target lookup, handle the missing case of opaque and redirect parent.
- Add impure xattr check. (Amir)
zhangyi (F) (5):
overlay: implement fsck utility fsck.overlay: correct redirect xattr check fsck.overlay: add origin count fsck.overlay: add merge and redirect subdir count fsck.overlay: add impure xattr check
PATCH v4 1/5 overlay: implement fsck utility
fsck.overlay
============
fsck.overlay is used to check and optionally repair underlying directories of overlay-filesystem.
Check the following points:
Whiteouts
---------
A whiteout is a character device with 0/0 device number. It is used to record the removed files or directories, When a whiteout is found in a directory, there should be at least one directory or file with the same name in any of the corresponding lower layers. If not exist, the whiteout will be treated as orphan whiteout and remove.
Redirect directories
--------------------
An redirect directory is a directory with "trusted.overlay.redirect" xattr valued to the path of the original location from the root of the overlay. It is only used when renaming a directory and "redirect dir" feature is enabled.
If an redirect directory is found, the following must be met:
1) The directory path pointed by redirect xattr should exist in one of lower layers.
2) The origin directory should be redirected only once, which means there is only one redirect xattr point to this origin directory in all layers.
3) A whiteout or an opaque directory with the same name to origin should exist in the same directory as the redirect directory.
If not, 1) The redirect xattr is invalid and need to remove 2) One of the redirect xattr is redundant but not sure which one is, ask user or warn in auto mode 3) Create a whiteout device or set opaque xattr to an existing directory if the parent directory was meregd or remove xattr if not.
Usage
=====
1. Ensure overlay filesystem is not mounted based on directories which need to check.
2. Run fsck.overlay program:
Usage:
fsck.overlay [-o lowerdir=<lowers>,upperdir=<upper>,workdir=<work>] \
[-pnyvhV] Options:
-o, specify underlying directories of overlayfs
multiple lower dirs use ':' as separator
-p, automatic repair (no questions) -n, make no changes to the filesystem -y, assume "yes" to all questions -v, --verbose print more messages of overlayfs -h, --help display this usage of overlayfs -V, --version display version information
Example:
fsck.overlay -o lowerdir=lower,upperdir=upper,workdir=work
3. Exit value:
0 No errors 1 Filesystem errors corrected 2 System should be rebooted 4 Filesystem errors left uncorrected 8 Operational error 16 Usage or syntax error 32 Checking canceled by user request 128 Shared-library error
--- Makefile | 21 ++ README.md | 87 ++++++++ check.c | 718 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ check.h | 25 +++ common.c | 119 +++++++++++ common.h | 53 +++++ config.h | 40 ++++ fsck.c | 305 ++++++++++++++++++++++++++ lib.c | 249 ++++++++++++++++++++++ lib.h | 102 +++++++++ list.h | 114 ++++++++++ mount.c | 370 ++++++++++++++++++++++++++++++++ mount.h | 34 +++ path.c | 78 +++++++ path.h | 24 +++ 15 files changed, 2339 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 check.c create mode 100644 check.h create mode 100644 common.c create mode 100644 common.h create mode 100644 config.h create mode 100644 fsck.c create mode 100644 lib.c create mode 100644 lib.h create mode 100644 list.h create mode 100644 mount.c create mode 100644 mount.h create mode 100644 path.c create mode 100644 path.h
Makefile new file +21 -0
@@ -0,0 +1,21 @@ +CFLAGS = -Wall -g +LFLAGS = -lm +CC = gcc + +all: overlay + +objects = fsck.o common.o lib.o check.o mount.o path.o + +overlay: $(objects) + $(CC) $(LFLAGS) $(objects) -o fsck.overlay + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + rm -f *.o fsck.overlay + rm -rf bin + +install: all + mkdir bin + cp fsck.overlay bin
README.md new file +87 -0
87 lines not on this page · raw message
check.c new file +718 -0
718 lines not on this page · raw message
check.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (c) 2017 Huawei. All Rights Reserved. +* Author: zhangyi (F) <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef OVL_WHITECHECK_H +#define OVL_WHITECHECK_H + +/* Scan upperdir and each lowerdirs, check and fix inconsistency */ +int ovl_scan_fix (void ); + +#endif /* OVL_WHITECHECK_H */
common.c new file +119 -0
119 lines not on this page · raw message
common.h new file +53 -0
53 lines not on this page · raw message
config.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (c) 2017 Huawei. All Rights Reserved. +* Author: zhangyi (F) <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef OVL_CONFIG_H +#define OVL_CONFIG_H + +/* program version */ +#define PACKAGE_VERSION "v0.1.0" + +/* overlay max lower stacks (the same to kernel overlayfs driver) */ +#define OVL_MAX_STACK 500 + +/* File with mounted filesystems */ +#define MOUNT_TAB "/proc/mounts" + +/* Name of overlay filesystem type */ +#define OVERLAY_NAME "overlay" +#define OVERLAY_NAME_OLD "overlayfs" + +/* Mount options */ +#define OPT_LOWERDIR "lowerdir=" +#define OPT_UPPERDIR "upperdir=" +#define OPT_WORKDIR "workdir=" + +#endif
fsck.c new file +305 -0
305 lines not on this page · raw message
lib.c new file +249 -0
249 lines not on this page · raw message
lib.h new file +102 -0
102 lines not on this page · raw message
list.h new file +114 -0
114 lines not on this page · raw message
mount.c new file +370 -0
370 lines not on this page · raw message
mount.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (c) 2017 Huawei. All Rights Reserved. +* Author: zhangyi (F) <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef OVL_MOUNT_H +#define OVL_MOUNT_H + +struct ovl_config { +char *lowerdir; +char *upperdir; +char *workdir; +}; + +void ovl_parse_opt (char *opt,struct ovl_config *config); +void ovl_free_opt (struct ovl_config *config); +int ovl_get_dirs (struct ovl_config *config,char ***lowerdir, +int *lowernum,char **upperdir,char **workdir); +int ovl_check_mount (bool *mounted); + +#endif /* OVL_MOUNT_H */
path.c new file +78 -0
78 lines not on this page · raw message
path.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2017 Huawei. All Rights Reserved. +* Author: zhangyi (F) <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef OVL_PATH_H +#define OVL_PATH_H + +char *joinname (const char *path,const char *name); +char *basename2 (const char *path,const char *dir); + +#endif /* OVL_PATH_H */
Signature · 1 line
2.9.5
PATCH v4 2/5 fsck.overlay: correct redirect xattr check
In reply to zhangyi (F)When we found a valid redirect xattr and the lower origin targed was covered by a directory, it could be 1) an another redirect directory, or 2) an opaque directory created after rename in overlayfs or 3) a general directory created in the underlying directory when overlay is offline. Currently, we only handled case 2, this patch cover the other two cases.
--- README.md | 27 ++++++---- check.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 159 insertions(+), 47 deletions(-)
README.md +18 -9
@@ -25,15 +25,24 @@ If an redirect directory is found, the following must be met: 1) The directory path pointed by redirect xattr should exist in one of lower layers. -2) The origin directory should be redirected only once, which means there is - only one redirect xattr point to this origin directory in all layers. -3) A whiteout or an opaque directory with the same name to origin should exist - in the same directory as the redirect directory. - -If not, 1) The redirect xattr is invalid and need to remove 2) One of the -redirect xattr is redundant but not sure which one is, ask user or warn in -auto mode 3) Create a whiteout device or set opaque xattr to an existing -directory if the parent directory was meregd or remove xattr if not. +2) There must be something with the same name to the rename origin in upper + layer covering the lower target, could be a whiteout or a generic file, + could be an opaque directory or another redirect direcotry but not a merge + directory. +3) The origin directory should be redirected by only once, which means this + origin directory should be redirected by an unique directory in all layers. + +If not, +1) The redirect xattr is invalid and should remove. +2) If nothing covering the redirect origin target, fix the missing whiteout. + If the redirect origin is covered by a generic directory, it becomes a + subcase of duplicate redirect directory (redirect direcotry duplicate with + an existing merge directory). Not sure the origin is a merge directory or + a redirected directory, so there are two options can fix this inconsistency: + a) remove the redirect xattr fsck found, or b) set opaque to the covering + directory. Ask user by default or warn in auto mode. +3) Record redirect xattrs but not sure which one is invalid, ask user by + default and warn in auto mode. Usage =====
check.c +141 -38
234 lines not on this page · raw message
Signature · 1 line
2.9.5
PATCH v4 3/5 fsck.overlay: add origin count
In reply to zhangyi (F)Count origin targets in a directory in scan pass two, will be use for impure xattr check.
--- check.c | 22 ++++++++++++++++++++++ lib.c | 19 +++++++++++++++++++ lib.h | 9 ++++++++- 3 files changed, 49 insertions(+), 1 deletion(-)
check.c +22 -0
@@ -180,6 +180,13 @@ static inline bool ovl_is_redirect(int dirfd, const char *pathname)return exist; } +static inline bool ovl_is_origin (int dirfd,const char *pathname) +{ +bool exist = false; +get_xattr (dirfd, pathname,OVL_ORIGIN_XATTR ,NULL , &exist); +return exist; +} +static inline int ovl_ask_action (const char *description,const char *pathname,int dirtype,int stack,const char *question,int action)
@@ -701,6 +708,20 @@ out:return ret; } +static int ovl_count_origin (struct scan_ctx *sctx) +{ +struct scan_dir_data *parent = sctx->dirdata; + +if (!parent) +return 0 ; + +if (ovl_is_origin (sctx->dirfd, sctx->pathname)) + parent->origins++; + +return 0 ; +} + +/* * Scan Pass: * -Pass one: Iterate through all directories, and check validity
@@ -723,6 +744,7 @@ static struct scan_operations ovl_scan_ops[OVL_SCAN_PASS][2] = { { [OVL_UPPER] = { .whiteout = ovl_check_whiteout, + .origin = ovl_count_origin, }, [OVL_LOWER] = { .whiteout = ovl_check_whiteout,
lib.c +19 -0
@@ -219,6 +219,11 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop)switch (ftsent->fts_info) {case FTS_F : sctx->files++; + +/* Check origin xattr */ + ret =scan_check_entry (sop->origin, sctx); +if (ret) + goto out;break ;case FTS_DEFAULT :/* Check whiteouts */
@@ -233,6 +238,20 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop) ret =scan_check_entry (sop->redirect, sctx);if (ret) goto out; + +/* Check origin xattr */ + ret =scan_check_entry (sop->origin, sctx); +if (ret) + goto out; + +/* Save current dir data and create new one for subdir */ + ftsent->fts_pointer = sctx->dirdata; + sctx->dirdata =smalloc (sizeof (struct scan_dir_data )); +break ; +case FTS_DP : +/* Restore parent's dir data */ +free (sctx->dirdata); + sctx->dirdata = ftsent->fts_pointer;break ;case FTS_NS :case FTS_DNR :
lib.h +8 -1
@@ -54,9 +54,14 @@/* Xattr */ #define OVL_OPAQUE_XATTR "trusted.overlay.opaque"#define OVL_REDIRECT_XATTR "trusted.overlay.redirect" +#define OVL_ORIGIN_XATTR "trusted.overlay.origin" -/* Directories scan data struct */ +/* Directories scan data structs */ +struct scan_dir_data { +int origins;/* origin number in this directory (no iterate) */ +}; +struct scan_ctx {const char *dirname;/* overlay base dir */ int dirfd;/* dir descriptor */
@@ -73,12 +78,14 @@ struct scan_ctx {const char *pathname;/* path relative to overlay root */ const char *filename;/* filename */ struct stat *st;/* file stat */ +struct scan_dir_data *dirdata;/* parent dir data of current (could be null) */ };/* Directories scan callback operations struct */ struct scan_operations {int (*whiteout)(struct scan_ctx *);int (*redirect)(struct scan_ctx *); +int (*origin)(struct scan_ctx *); };static inline void set_inconsistency (int *status)
Signature · 1 line
2.9.5
PATCH v4 4/5 fsck.overlay: add merge and redirect subdir count
In reply to zhangyi (F)Count merge and redirect subdir in a directory in scan pass two, will be use for impure xattr check.
--- check.c | 33 +++++++++++++++++++++++++++++++++ lib.c | 4 ++++ lib.h | 3 +++ 3 files changed, 40 insertions(+)
check.c +33 -0
@@ -721,6 +721,38 @@ static int ovl_count_origin(struct scan_ctx *sctx)return 0 ; } +static inline bool ovl_is_merge (int dirfd,const char *pathname, +int dirtype,int stack) +{ +struct ovl_lookup_data od = {0 }; + +if (ovl_is_opaque (dirfd, pathname)) +return false; +if (ovl_lookup_lower (pathname, dirtype, stack, &od)) +return false; +if (od.exist &&is_dir (&od.st)) +return true; + +return false; +} + +/* Count merge dir and redirect dir in a specified directory */ +static int ovl_count_unreal (struct scan_ctx *sctx) +{ +struct scan_dir_data *parent = sctx->dirdata; + +if (!parent) +return 0 ; + +if (ovl_is_redirect (sctx->dirfd, sctx->pathname)) + parent->redirects++; +if (!ovl_is_origin (sctx->dirfd, sctx->pathname) && +ovl_is_merge (sctx->dirfd, sctx->pathname, + sctx->dirtype, sctx->stack)) + parent->mergedirs++; + +return 0 ; +}/* * Scan Pass:
@@ -745,6 +777,7 @@ static struct scan_operations ovl_scan_ops[OVL_SCAN_PASS][2] = { [OVL_UPPER] = { .whiteout = ovl_check_whiteout, .origin = ovl_count_origin, + .unreal = ovl_count_unreal, }, [OVL_LOWER] = { .whiteout = ovl_check_whiteout,
lib.c +4 -0
@@ -244,6 +244,10 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop)if (ret) goto out; + ret =scan_check_entry (sop->unreal, sctx); +if (ret) + goto out; +/* Save current dir data and create new one for subdir */ ftsent->fts_pointer = sctx->dirdata; sctx->dirdata =smalloc (sizeof (struct scan_dir_data ));
lib.h +3 -0
@@ -60,6 +60,8 @@/* Directories scan data structs */ struct scan_dir_data {int origins;/* origin number in this directory (no iterate) */ +int mergedirs;/* merge subdir number in this directory (no iterate) */ +int redirects;/* redirect subdir number in this directory (no iterate) */ };struct scan_ctx {
@@ -86,6 +88,7 @@ struct scan_operations {int (*whiteout)(struct scan_ctx *);int (*redirect)(struct scan_ctx *);int (*origin)(struct scan_ctx *); +int (*unreal)(struct scan_ctx *); };static inline void set_inconsistency (int *status)
Signature · 1 line
2.9.5
Re: [PATCH v4 4/5] fsck.overlay: add merge and redirect subdir count
Quoted 25 lines · zhangyi (F)
Count merge and redirect subdir in a directory in scan pass two, will be use for impure xattr check.
Signed-off-by zhangyi (F) <[email protected]>--- check.c | 33 +++++++++++++++++++++++++++++++++ lib.c | 4 ++++ lib.h | 3 +++ 3 files changed, 40 insertions(+)check.c +7
-0@@ -721,6 +721,38 @@ static int ovl_count_origin(struct scan_ctx *sctx)return 0 ; } +static inline bool ovl_is_merge (int dirfd,const char *pathname, +int dirtype,int stack) +{ +struct ovl_lookup_data od = {0 }; + +if (ovl_is_opaque (dirfd, pathname)) +return false;
check.c static int ovl_count_origin(struct scan_ctx *sctx) · line 740
Quoted 10 lines
check.c +10
-0+if (ovl_lookup_lower (pathname, dirtype, stack, &od)) +return false; +if (od.exist &&is_dir (&od.st)) +return true; + +return false; +} + +/* Count merge dir and redirect dir in a specified directory */ +static int ovl_count_unreal (struct scan_ctx *sctx)
I am amused by this name :)
FYI, the legacy term used for a directory that is NOT a merge directory is "pure", such as "pure upper" or "pure lower".
Confusingly, the "impure dir" term is not exactly the opposite of the legacy "pure dir" term, but really is a shortcut for "dir that contains non pure entries".
We could have called the xattr "impurities", but we (I) didn't.
So, basically, merge and redirect dir are "impurities", which make the parent dir "impure".
See for example:
void ovl_dentry_version_inc(struct dentry *dentry, bool impurity)
'impurity' refers to merge/redirect children of parent, kind of like this scan function, so I propose either:ovl_count_impurities()
ORovl_count_impure()
I realize that there is overlap in the term with ovl_count_origin(), which also counts impurities, but still..
Quoted 65 lines
check.c +16
-0+{ +struct scan_dir_data *parent = sctx->dirdata; + +if (!parent) +return 0 ; + +if (ovl_is_redirect (sctx->dirfd, sctx->pathname)) + parent->redirects++; +if (!ovl_is_origin (sctx->dirfd, sctx->pathname) && +ovl_is_merge (sctx->dirfd, sctx->pathname, + sctx->dirtype, sctx->stack)) + parent->mergedirs++; + +return 0 ; +}/* * Scan Pass: @@ -745,6 +777,7 @@ static struct scan_operations ovl_scan_ops[OVL_SCAN_PASS][2] = { [OVL_UPPER] = { .whiteout = ovl_check_whiteout, .origin = ovl_count_origin, + .unreal = ovl_count_unreal, }, [OVL_LOWER] = { .whiteout = ovl_check_whiteout,lib.c +4
-0@@ -244,6 +244,10 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop)if (ret) goto out; + ret =scan_check_entry (sop->unreal, sctx); +if (ret) + goto out; +/* Save current dir data and create new one for subdir */ ftsent->fts_pointer = sctx->dirdata; sctx->dirdata =smalloc (sizeof (struct scan_dir_data ));lib.h +3
-1@@ -60,6 +60,8 @@/* Directories scan data structs */ struct scan_dir_data {int origins;/* origin number in this directory (no iterate) */ +int mergedirs;/* merge subdir number in this directory (no iterate) */ +int redirects;/* redirect subdir number in this directory (no iterate) */ };struct scan_ctx {@@ -86,6 +88,7 @@ struct scan_operations {int (*whiteout)(struct scan_ctx *);int (*redirect)(struct scan_ctx *);int (*origin)(struct scan_ctx *); +int (*unreal)(struct scan_ctx *); };static inline void set_inconsistency (int *status) --2.9.5
Re: [PATCH v4 4/5] fsck.overlay: add merge and redirect subdir count
On 2018/1/18 15:13, Amir Goldstein Wrote:
Quoted 16 lines · zhangyi (F)
check.c static int ovl_count_origin(struct scan_ctx *sctx) · line 740
Quoted 2 lines
check.c +2
-0+/* Count merge dir and redirect dir in a specified directory */ +static int ovl_count_unreal (struct scan_ctx *sctx)I am amused by this name :)
FYI, the legacy term used for a directory that is NOT a merge directory is "pure", such as "pure upper" or "pure lower".Confusingly, the "impure dir" term is not exactly the opposite of the legacy "pure dir" term, but really is a shortcut for "dir that contains non pure entries".
We could have called the xattr "impurities", but we (I) didn't.So, basically, merge and redirect dir are "impurities", which make the parent dir "impure".
Quoted 9 lines
See for example:
voidovl_dentry_version_inc(struct dentry *dentry, bool impurity)'impurity' refers to merge/redirect children of parent, kind of like this scan function, so I propose either:
ovl_count_impurities()
ORovl_count_impure()
Ha, I've thouht it for a long time, but still cannot find a proper word. Because I think 'impure' may confuse with the meaning of directory with impure xattr. Now, the 'impurities' looks great, thanks! :)
Quoted 2 lines
I realize that there is overlap in the term with
ovl_count_origin(), which also counts impurities, but still..
Right, origin target is also a kind of impurities, I will improve this.
Thanks,
Yi.
PATCH v4 5/5 fsck.overlay: add impure xattr check
In reply to zhangyi (F)An impure directory is a directory with "trusted.overlay.impure" xattr valued 'y', which indicate that this directory may contain copied up targets from lower layers.
If a target copy-up from lower to upper layer, it's 'd_ino' (see getdents(2)) will change from lower's 'd_ino' to upper's (a new inode will be created in upper layer). So the impure xattr should be set to the parent directory to prompt overlay filesystem to get and return the origin 'd_ino', thus ensuring the consistentcy of 'd_ino'.
There are three situations of setting impure xattr in overlay filesystem:
1) Copy-up lower target in a directory.
2) Link an origin target (already copied up, have origin xattr) into a directory.
3) Rename an origin target (include merge subdirectories) into a new directory.
So, the impure xattr should be set if a direcotry contains origin targets or redirect/merge subdirectories. If not, fix the impure xattr.
--- README.md | 22 ++++++++++++++++++ check.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- lib.c | 5 ++++ lib.h | 3 +++ 4 files changed, 102 insertions(+), 6 deletions(-)
README.md +22 -0
@@ -44,6 +44,28 @@ If not, 3) Record redirect xattrs but not sure which one is invalid, ask user by default and warn in auto mode. +Impure directories +------------------ + +An impure directory is a directory with "trusted.overlay.impure" xattr valued +'y', which indicate that this directory may contain copied up targets from lower +layers. +If a target copy-up from lower to upper layer, it's 'd_ino' (see getdents(2)) +will change from lower's 'd_ino' to upper's (a new inode will be created in +upper layer). So the impure xattr should be set to the parent directory to +prompt overlay filesystem to get and return the origin 'd_ino', thus ensuring +the consistentcy of 'd_ino'. + +There are three situations of setting impure xattr in overlay filesystem: +1) Copy-up lower target in a directory. +2) Link an origin target (already copied up, have origin xattr) into a + directory. +3) Rename an origin target (include merge subdirectories) into a new + directory. + +So, the impure xattr should be set if a direcotry contains origin targets or +redirect/merge subdirectories. If not, fix the impure xattr. + Usage =====
check.c +72 -6
128 lines not on this page · raw message
lib.c +5 -0
@@ -253,6 +253,11 @@ int scan_dir(struct scan_ctx *sctx, struct scan_operations *sop) sctx->dirdata =smalloc (sizeof (struct scan_dir_data ));break ;case FTS_DP : +/* Check impure xattr */ + ret =scan_check_entry (sop->impure, sctx); +if (ret) + goto out; +/* Restore parent's dir data */ free (sctx->dirdata); sctx->dirdata = ftsent->fts_pointer;
lib.h +3 -0
@@ -55,6 +55,7 @@#define OVL_OPAQUE_XATTR "trusted.overlay.opaque"#define OVL_REDIRECT_XATTR "trusted.overlay.redirect"#define OVL_ORIGIN_XATTR "trusted.overlay.origin" +#define OVL_IMPURE_XATTR "trusted.overlay.impure"/* Directories scan data structs */
@@ -76,6 +77,7 @@ struct scan_ctx {int i_whiteouts;/* invalid whiteouts */ int t_redirects;/* total redirect dirs */ int i_redirects;/* invalid redirect dirs */ +int m_impure;/* missing inpure dirs */ const char *pathname;/* path relative to overlay root */ const char *filename;/* filename */
@@ -89,6 +91,7 @@ struct scan_operations {int (*redirect)(struct scan_ctx *);int (*origin)(struct scan_ctx *);int (*unreal)(struct scan_ctx *); +int (*impure)(struct scan_ctx *); };static inline void set_inconsistency (int *status)
Signature · 1 line
2.9.5
Quoted 9 lines · zhangyi (F)
Hi All,
Here is the forth version of fsck.overlay. Most of comments from last three iterations have been handled. Now, this tool have three basic features (see README for detail, include TODO list):
1. Check and fix orphan whiteouts,
2. Check and fix invalid/duplicate redirect directories,
3. Check and fix missing impure xattrs.
Quoted 8 lines
This incubation tool will post to github repository[1] directly. Any suggestion is helpful if you review the source code or find bugs/improvements when you use/test this tool.
Thanks,
Yi.
Very nice work!
I find your code very pleasant to read.
I did not go through it all to check functional correctness. Just have some minor high level comments.
In general, many functions could use a comment and more files could use a header comment.
Quoted 4 lines
Changes since v3:
- Use existing library for path manipulation and separate self-implemented manipulation helpers. (Comment from Amir)
Specifically, in what way in basename2() different than basename()? and what is a the semantics of joinname()?
There are thing better documented above the functions, especially for general utility functions.
Quoted 5 lines
- Use
fstatat()with relative path instead oflstat()with absolute path when traverse layers and lookup target. (Amir)
- Split check routines into two pass, the first pass check redirect dir to confirm directory structure, the second pass check whiteouts and impure xattr.
This could be an opportunity to start splitting check.c which is getting bigger to pass1.c pass2.c or to check_whiteout.c check_redirect.c. I leave it up to you to decide when and how to split.
Quoted 1 line
- Change list to linux kernel style.
This is a good example of code copied/derived from kernel code that is placed in a dedicated file with header comment to state this fact.
You should do the same with other functions that are copied from kernel and place them in a dedicated file with header comment. There are 2 such helpers in mount.c and at least one constant in config.h.
Quoted 24 lines
- Fix duplicate redirect xattr check, correct questions and default actions, and handle cases of duplicate redirect xattr in different layers. (Amir)
- Fix impure xattr comments and invalid error message. (Amir & Vivek)----------------
Changes since v2(v1):
- Add "-n -p -y" options. (Comment from Amir and Darrick)
- Change underlying dirs input to '-o' option like mount(8). (Miklos)
- Remove invalid opaque check. (Miklos)
- Correct redirect xattr check. (Amir and Miklos)
- Fix lower target lookup, handle the missing case of opaque and redirect parent.
- Add impure xattr check. (Amir)zhangyi (F) (5):
overlay: implement fsck utility fsck.overlay: correct redirect xattr check fsck.overlay: add origin count fsck.overlay: add merge and redirect subdir count fsck.overlay: add impure xattr check
On 2018/1/18 15:34, Amir Goldstein Wrote:
Quoted 17 lines · zhangyi (F)
Quoted 16 lines
Hi All,
Here is the forth version of fsck.overlay. Most of comments from last three iterations have been handled. Now, this tool have three basic features (see README for detail, include TODO list):
1. Check and fix orphan whiteouts,
2. Check and fix invalid/duplicate redirect directories,
3. Check and fix missing impure xattrs.This incubation tool will post to github repository[1] directly. Any suggestion is helpful if you review the source code or find bugs/improvements when you use/test this tool.
Thanks,
Yi.
Quoted 6 lines
Quoted 1 line
Very nice work!
I find your code very pleasant to read.
I did not go through it all to check functional correctness. Just have some minor high level comments.
Thanks for your approval and comments.
Quoted 3 lines
In general, many functions could use a comment and more files could use a header comment.
Will do.
Quoted 10 lines
Quoted 4 lines
Changes since v3:
- Use existing library for path manipulation and separate self-implemented manipulation helpers. (Comment from Amir)Specifically, in what way in
basename2()different thanbasename()? and what is a the semantics ofjoinname()?
There are thing better documented above the functions, especially for general utility functions.
Will do.
Quoted 11 lines
Quoted 6 lines
- Use
fstatat()with relative path instead oflstat()with absolute path when traverse layers and lookup target. (Amir)
- Split check routines into two pass, the first pass check redirect dir to confirm directory structure, the second pass check whiteouts and impure xattr.This could be an opportunity to start splitting
check.cwhich is getting bigger topass1.cpass2.cor tocheck_whiteout.ccheck_redirect.c. I leave it up to you to decide when and how to split.
Yes, I realize that fsck.ext4 have passN.c to handle each pass, I will think how to split it.
Quoted 11 lines
Quoted 1 line
- Change list to linux kernel style.
This is a good example of code copied/derived from kernel code that is placed in a dedicated file with header comment to state this fact.
You should do the same with other functions that are copied from kernel and place them in a dedicated file with header comment. There are 2 such helpers in
mount.cand at least one constant inconfig.h.
Will do.
Thanks,
Yi.
Quoted 27 lines
Quoted 17 lines
- Fix duplicate redirect xattr check, correct questions and default actions, and handle cases of duplicate redirect xattr in different layers. (Amir)
- Fix impure xattr comments and invalid error message. (Amir & Vivek)----------------
Changes since v2(v1):
- Add "-n -p -y" options. (Comment from Amir and Darrick)
- Change underlying dirs input to '-o' option like mount(8). (Miklos)
- Remove invalid opaque check. (Miklos)
- Correct redirect xattr check. (Amir and Miklos)
- Fix lower target lookup, handle the missing case of opaque and redirect parent.
- Add impure xattr check. (Amir)Quoted 7 lines
zhangyi (F) (5):
overlay: implement fsck utility fsck.overlay: correct redirect xattr check fsck.overlay: add origin count fsck.overlay: add merge and redirect subdir count fsck.overlay: add impure xattr check.