erofs-utils: introduce `struct erofs_rebuild_getdentry_ctx`
PATCH 1/2 erofs-utils: introduce `struct erofs_rebuild_getdentry_ctx`
There are so many parameters in erofs_rebuild_get_dentry(), let's wrap these parameters into struct erofs_rebuild_getdentry_ctx.
--- include/erofs/rebuild.h | 12 +++++++-- lib/rebuild.c | 59 ++++++++++++++++++++++++----------------- lib/tar.c | 17 +++++++++--- 3 files changed, 59 insertions(+), 29 deletions(-)
include/erofs/rebuild.h +10 -2
@@ -15,8 +15,16 @@ enum erofs_rebuild_datamode { EROFS_REBUILD_DATA_FULL, }; -struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd, -char *path,bool aufs,bool *whout,bool *opq,bool to_head); +struct erofs_rebuild_getdentry_ctx { +struct erofs_inode *pwd; +char *path; +bool aufs; +bool *whout; +bool *opq; +bool to_head; +}; + +struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_rebuild_getdentry_ctx *ctx);int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi,enum erofs_rebuild_datamode mode);
lib/rebuild.c +35 -24
131 lines not on this page · raw message
lib/tar.c +14 -3
@@ -657,6 +657,7 @@ int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar)char path[PATH_MAX ];struct erofs_pax_header eh = tar->global;struct erofs_sb_info *sbi = root->sbi; +struct erofs_rebuild_getdentry_ctx dctx;bool whout, opq, e = false;struct stat st;erofs_off_t tar_offset, dataoff;
@@ -907,7 +908,13 @@ out_eot:erofs_dbg ("parsing %s (mode %05o)" , eh.path, st.st_mode); - d =erofs_rebuild_get_dentry (root, eh.path, tar->aufs, &whout, &opq, true); + dctx.pwd = root; + dctx.path = eh.path; + dctx.aufs = tar->aufs; + dctx.whout = &whout; + dctx.opq = &opq; + dctx.to_head = true; + d =erofs_rebuild_get_dentry (&dctx);if (IS_ERR (d)) { ret =PTR_ERR (d); goto out;
@@ -945,8 +952,12 @@ out_eot: } d->inode =NULL ; - d2 =erofs_rebuild_get_dentry (root, eh.link, tar->aufs, - &dumb, &dumb, false); + dctx.pwd = root; + dctx.path = eh.link; + dctx.aufs = tar->aufs; + dctx.whout = dctx.opq = &dumb; + dctx.to_head = false; + d2 =erofs_rebuild_get_dentry (&dctx);if (IS_ERR (d2)) { ret =PTR_ERR (d2); goto out;
Signature · 1 line
2.43.5
PATCH 2/2 erofs-utils: rebuild: set the appropriate `dev` field for dirs
Currently, setting a default dev value (i.e., 0) for directories during parsing tar files can lead to the following error:
<E> erofs: bogus i_mode (0) @ nid 0
<E> erofs: failed to read inode @ 0
Consider the following incremental build scenario, where the path "dir1/dir2" is currently being parsed in tarerofs_parse_tar() and the directory "dir1" has never appeared before. erofs_rebuild_get_dentry() will call erofs_rebuild_mkdir() to allocate a new inode for "dir1", with its dev field set to 0 by default.
During the dump tree phase, since dir1->dev matches sbi->dev (both are 0), erofs_rebuild_load_basedir() will be called to read the contents of directory "dir1" from the disk. However, since there is no information for the new directory "dir1" on the disk, the above error occurs.
This patch resolves the above issue by setting the appropriate value for the directory's dev field during the tar file parsing phase.
--- include/erofs/rebuild.h | 1 + lib/rebuild.c | 7 +++++-- lib/tar.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-)
include/erofs/rebuild.h +1 -0
@@ -22,6 +22,7 @@ struct erofs_rebuild_getdentry_ctx {bool *whout;bool *opq;bool to_head; +int dev; };struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_rebuild_getdentry_ctx *ctx);
lib/rebuild.c +5 -2
@@ -27,7 +27,7 @@#endif static struct erofs_dentry *erofs_rebuild_mkdir (struct erofs_inode *dir, -const char *s) +const char *s,int dev) {struct erofs_inode *inode;struct erofs_dentry *d;
@@ -47,6 +47,7 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, inode->i_gid =getgid (); inode->i_mtime = inode->sbi->build_time; inode->i_mtime_nsec = inode->sbi->build_time_nsec; + inode->dev = dev;erofs_init_empty_dir (inode); d =erofs_d_alloc (dir, s);
@@ -119,7 +120,7 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_rebuild_getdentry_ctx d->type =EROFS_FT_UNKNOWN ; d->inode = ctx->pwd; }else { - d =erofs_rebuild_mkdir (ctx->pwd, s); + d =erofs_rebuild_mkdir (ctx->pwd, s, ctx->dev);if (IS_ERR (d))return d; ctx->pwd = d->inode;
@@ -292,6 +293,7 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx) dctx.aufs = false; dctx.whout = dctx.opq = &dumb; dctx.to_head = false; + dctx.dev = dir->sbi->dev; d =erofs_rebuild_get_dentry (&dctx);if (IS_ERR (d)) { ret =PTR_ERR (d);
@@ -460,6 +462,7 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx) dctx.aufs = false; dctx.whout = dctx.opq = &dumb; dctx.to_head = false; + dctx.dev = dir->sbi->dev; d =erofs_rebuild_get_dentry (&dctx);if (IS_ERR (d)) { ret =PTR_ERR (d);
lib/tar.c +2 -0
@@ -914,6 +914,7 @@ out_eot: dctx.whout = &whout; dctx.opq = &opq; dctx.to_head = true; + dctx.dev = tar->dev; d =erofs_rebuild_get_dentry (&dctx);if (IS_ERR (d)) { ret =PTR_ERR (d);
@@ -957,6 +958,7 @@ out_eot: dctx.aufs = tar->aufs; dctx.whout = dctx.opq = &dumb; dctx.to_head = false; + dctx.dev = tar->dev; d2 =erofs_rebuild_get_dentry (&dctx);if (IS_ERR (d2)) { ret =PTR_ERR (d2);
Signature · 1 line
2.43.5
Re: [PATCH 2/2] erofs-utils: rebuild: set the appropriate `dev` field for dirs
Quoted 54 lines · Hongzhen Luo
Currently, setting a default
devvalue (i.e., 0) for directories during parsing tar files can lead to the following error:<E> erofs: bogus
i_mode(0) @ nid 0
<E> erofs: failed to read inode @ 0Consider the following incremental build scenario, where the path "dir1/dir2" is currently being parsed in
tarerofs_parse_tar()and the directory "dir1" has never appeared before.erofs_rebuild_get_dentry()will callerofs_rebuild_mkdir()to allocate a new inode for "dir1", with itsdevfield set to 0 by default.During the dump tree phase, since
dir1->devmatchessbi->dev(both are 0),erofs_rebuild_load_basedir()will be called to read the contents of directory "dir1" from the disk. However, since there is no information for the new directory "dir1" on the disk, the above error occurs.This patch resolves the above issue by setting the appropriate value for the directory's
devfield during the tar file parsing phase.Fixes f64d9d02576b ("erofs-utils: introduce incremental builds")Signed-off-by Hongzhen Luo <[email protected]>--- include/erofs/rebuild.h | 1 + lib/rebuild.c | 7 +++++-- lib/tar.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-)include/erofs/rebuild.h +1
-0@@ -22,6 +22,7 @@ struct erofs_rebuild_getdentry_ctx {bool *whout;bool *opq;bool to_head; +int dev; };struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_rebuild_getdentry_ctx *ctx);lib/rebuild.c +1
-1@@ -27,7 +27,7 @@#endif static struct erofs_dentry *erofs_rebuild_mkdir (struct erofs_inode *dir, -const char *s) +const char *s,int dev) {struct erofs_inode *inode;struct erofs_dentry *d;
lib/rebuild.c static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, · line 50
Quoted 4 lines
lib/rebuild.c +1
-0@@ -47,6 +47,7 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, inode->i_gid =getgid (); inode->i_mtime = inode->sbi->build_time; inode->i_mtime_nsec = inode->sbi->build_time_nsec; + inode->dev = dev;
Why not just use inode->dir->dev?
Thanks,
Gao Xiang
Re: [PATCH 2/2] erofs-utils: rebuild: set the appropriate `dev` field for dirs
Quoted 63 lines · Gao Xiang
Quoted 52 lines · Hongzhen Luo
Currently, setting a default
devvalue (i.e., 0) for directories during parsing tar files can lead to the following error:<E> erofs: bogus
i_mode(0) @ nid 0
<E> erofs: failed to read inode @ 0Consider the following incremental build scenario, where the path "dir1/dir2" is currently being parsed in
tarerofs_parse_tar()and the directory "dir1" has never appeared before.erofs_rebuild_get_dentry()will callerofs_rebuild_mkdir()to allocate a new inode for "dir1", with itsdevfield set to 0 by default.During the dump tree phase, since
dir1->devmatchessbi->dev(both are 0),erofs_rebuild_load_basedir()will be called to read the contents of directory "dir1" from the disk. However, since there is no information for the new directory "dir1" on the disk, the above error occurs.This patch resolves the above issue by setting the appropriate value for the directory's
devfield during the tar file parsing phase.Fixes f64d9d02576b ("erofs-utils: introduce incremental builds")Signed-off-by Hongzhen Luo <[email protected]>---
include/erofs/rebuild.h| 1 +
lib/rebuild.c | 7 +++++--
lib/tar.c | 2 ++3 files changed, 8 insertions(+), 2 deletions(-)include/erofs/rebuild.h +1
-0@@ -22,6 +22,7 @@ struct erofs_rebuild_getdentry_ctx { bool *whout; bool *opq; bool to_head; + int dev; }; struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_rebuild_getdentry_ctx *ctx);lib/rebuild.c +1
-1@@ -27,7 +27,7 @@ #endif static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, - const char *s) + const char *s, int dev) { struct erofs_inode *inode; struct erofs_dentry *d;lib/rebuild.c static struct erofs_dentry · line 51
Quoted 5 lines
lib/rebuild.c +1
-0@@ -47,6 +47,7 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, inode->i_gid = getgid(); inode->i_mtime = inode->sbi->build_time; inode->i_mtime_nsec = inode->sbi->build_time_nsec; + inode->dev = dev;Why not just use
inode->dir->dev?
Quoted 2 lines
Thanks,
Gao Xiang
Yes, I didn't see that; this makes it much simpler. I'll give it a try and send another version of the patch later.
---
Thanks,
Hongzhen Luo
Re: [PATCH 2/2] erofs-utils: rebuild: set the appropriate `dev` field for dirs
In reply to Gao XiangQuoted 63 lines · Gao Xiang
Quoted 52 lines · Hongzhen Luo
Currently, setting a default
devvalue (i.e., 0) for directories during parsing tar files can lead to the following error:<E> erofs: bogus
i_mode(0) @ nid 0
<E> erofs: failed to read inode @ 0Consider the following incremental build scenario, where the path "dir1/dir2" is currently being parsed in
tarerofs_parse_tar()and the directory "dir1" has never appeared before.erofs_rebuild_get_dentry()will callerofs_rebuild_mkdir()to allocate a new inode for "dir1", with itsdevfield set to 0 by default.During the dump tree phase, since
dir1->devmatchessbi->dev(both are 0),erofs_rebuild_load_basedir()will be called to read the contents of directory "dir1" from the disk. However, since there is no information for the new directory "dir1" on the disk, the above error occurs.This patch resolves the above issue by setting the appropriate value for the directory's
devfield during the tar file parsing phase.Fixes f64d9d02576b ("erofs-utils: introduce incremental builds")Signed-off-by Hongzhen Luo <[email protected]>---
include/erofs/rebuild.h| 1 +
lib/rebuild.c | 7 +++++--
lib/tar.c | 2 ++3 files changed, 8 insertions(+), 2 deletions(-)include/erofs/rebuild.h +1
-0@@ -22,6 +22,7 @@ struct erofs_rebuild_getdentry_ctx { bool *whout; bool *opq; bool to_head; + int dev; }; struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_rebuild_getdentry_ctx *ctx);lib/rebuild.c +1
-1@@ -27,7 +27,7 @@ #endif static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, - const char *s) + const char *s, int dev) { struct erofs_inode *inode; struct erofs_dentry *d;lib/rebuild.c static struct erofs_dentry · line 51
Quoted 5 lines
lib/rebuild.c +1
-0@@ -47,6 +47,7 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, inode->i_gid = getgid(); inode->i_mtime = inode->sbi->build_time; inode->i_mtime_nsec = inode->sbi->build_time_nsec; + inode->dev = dev;Why not just use
inode->dir->dev?
Quoted 2 lines
Thanks,
Gao Xiang
Just use inode->dev = dir->dev to set the dev field during the parse tar phase seems don't work because the dev filed of the root is 0. Did I misunderstand something?
---
Thanks,
Hongzhen Luo