erofs-utils: rebuild: set the appropriate `dev` field for dirs
authorHongzhen Luo <hongzhen@linux.alibaba.com>
Wed, 27 Nov 2024 11:13:46 +0000 (19:13 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 29 Nov 2024 07:27:12 +0000 (15:27 +0800)
commit80156068eb4980342c0ad3ee47ac7261acce5caf
tree5f68fd6f1c5a7083c165db3616cef43a7893f930
parentee7d3dc1dd95a6f832d96c39fab65407963f1123
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.

Fixes: f64d9d02576b ("erofs-utils: introduce incremental builds")
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Link: https://lore.kernel.org/r/20241127111346.49290-1-hongzhen@linux.alibaba.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
lib/rebuild.c
lib/tar.c