erofs-utils: fix incorrect i_nlink in the unified rebuild logic
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 13 Jun 2024 02:37:06 +0000 (10:37 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 13 Jun 2024 02:43:42 +0000 (10:43 +0800)
Fixes: 203c847cc7d1 ("erofs-utils: unify the tree traversal for the rebuild mode")
Closes: https://github.com/erofs/erofsnightly/actions/runs/9492427961/job/26159566596
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240613023706.1269816-1-hsiangkao@linux.alibaba.com
lib/inode.c

index 7d4ccc4193a677d39825b0623275075791f5978d..92197591ef9e56796b0b0769c2e269446a533368 100644 (file)
@@ -1386,7 +1386,7 @@ static int erofs_rebuild_handle_directory(struct erofs_inode *dir)
        int ret;
 
        nr_subdirs = 0;
-       i_nlink = 2;
+       i_nlink = 0;
        list_for_each_entry_safe(d, n, &dir->i_subdirs, d_child) {
                if (cfg.c_ovlfs_strip && erofs_inode_is_whiteout(d->inode)) {
                        erofs_dbg("remove whiteout %s", d->inode->i_srcpath);
@@ -1399,6 +1399,8 @@ static int erofs_rebuild_handle_directory(struct erofs_inode *dir)
                ++nr_subdirs;
        }
 
+       DBG_BUGON(i_nlink < 2);         /* should have `.` and `..` */
+       DBG_BUGON(nr_subdirs < i_nlink);
        ret = erofs_prepare_dir_layout(dir, nr_subdirs);
        if (ret)
                return ret;