Hi, On 9/4/23 4:57 PM, Amir Goldstein wrote: > On Mon, Sep 4, 2023 at 10:47 AM Jingbo Xu <jefflexu@xxxxxxxxxxxxxxxxx> wrote: >> >> Hi, all, >> >> I found an issue may be related to overlayfs on the latest master branch >> [1] when I'm developing tarfs mode for erofs-utils [2], which converts >> and merges tar layers into one merged erofs image with overlayfs-like model. >> >> The issue is that, the whiteout from lowerdir may still shows up in the >> merged directory. Though this issue is initially found with erofs, it >> can also be reproduced with ext4. Following is a simple reproducer with >> ext4. >> >> ``` >> mkdir -p /mnt/lower1/dir /mnt/lower2 >> mknod /mnt/lower1/file1 c 0 0 >> mknod /mnt/lower1/dir/file2 c 0 0 >> mount -t overlay none -olowerdir=/mnt/lower1:/mnt/lower2 /mnt2 >> >> # ls -l /mnt2/ >> total 4 >> drwxr-xr-x 2 root root 4096 Sep 4 14:40 dir >> >> # ls -l /mnt2/dir >> ls: cannot access /mnt2/dir/file2: No such file or directory >> total 0 >> c????????? ? ? ? ? ? file2 >> ``` >> >> It seems that this issue is relevant to whether the parent directory of >> the whiteout is a merged directory or not. In the above example, file1 >> is hidden from the merged directory as expected (with its parent >> directory '/' a merged directory), while file2 shows up unexpectedly >> (with its parent directory '/dir' from lowerdir). >> >> >> I also noticed that this issue doesn't exist if the whiteout is created >> by overlayfs itself rather than handcrafted with mknod like: >> >> ``` >> mkdir -p /mnt/lower/dir /mnt/upper /mnt/work >> touch /mnt/lower/file1 >> touch /mnt/lower/dir/file2 >> mount -t overlay none >> -olowerdir=/mnt/lower,upperdir=/mnt/upper,workdir=/mnt/work /mnt1 >> rm /mnt1/file1 >> rm /mnt1/dir/file2 >> umount /mnt1 >> mount -t overlay -olowerdir=/mnt/upper:/mnt/lower none /mnt2 >> >> # ls -l /mnt2/ >> total 8 >> drwxr-xr-x 1 root root 4096 Sep 4 15:45 dir >> >> # ls -l /mnt2/dir/ >> total 0 >> ``` >> >> I'm not sure if it's a known issue or not, or due to my mishandling. >> Appreciate if you could shed a light on this. >> > > The case of whiteouts creates by overlayfs itself was reported > by zhangyi and handled by this patchs set: > > https://lore.kernel.org/linux-unionfs/1509486350-21362-1-git-send-email-amir73il@xxxxxxxxx/ Thanks for the reply and it's really helpful to me. I can understand in the normal use case, whiteout can not appear in non-merged directory without origin xattr, except it's hand crafted. But indeed we suffer from this issue in the tarfs for erofs-utils we are developing. As described previously, in tarfs mode erofs-utils can convert each tar layer into one separate erofs image, and then merge these erofs images into one merged erofs image in a overlayfs-like model. Suppose: layer 0 + layer 1 + layer 2 --> merged /foo/bar /foo/bar (whiteout) To speed the merging process, we may merge the two top-most layers (layer 1 and layer 2) first, and then make layer0 merged into the final merged image as: layer 1 + layer 2 --> merged-intermediate /foo/bar /foo/bar (whiteout) layer0 + merged-intermediate --> merged Then there comes the problem: when merging layer1 and layer2, I need to keep the whiteout in the intermediate merged image though the target of the whiteout has showed up in underlying layer (/foo/bar in layer 1), because I have no idea if "/foo/bar" exits in the following further underlying layer (layer 0). Reusing this logic, the whiteout is kept there in the final merged image after merging layer0 and merged-intermediate. Then if "/foo" is not a merged directory, the "/foo/bar" whiteout will be exposed in the overlayfs unexpectedly. Currently we work around this in erofs-utils side. Apart from setting origin xattr on the parent directory of the whiteout, I'm not sure if the above use case is reasonable enough to fix this in the kernel side. -- Thanks, Jingbo