Bug 114951

Summary: overlayfs issue with nftw(3) with FTW_MOUNT flag set
Product: File System Reporter: Gerardo Exequiel Pozzi (vmlinuz386)
Component: OtherAssignee: fs_other
Status: REOPENED ---    
Severity: normal CC: jarek.przygodzki, miklos, quorum.laval, szg00000
Priority: P1    
Hardware: i386   
OS: Linux   
Kernel Version: 4.x Subsystem:
Regression: No Bisected commit-id:
Attachments: ntfw-example.c

Description Gerardo Exequiel Pozzi 2016-03-19 17:09:11 UTC
Created attachment 209871 [details]
ntfw-example.c

Looks like nftw(3) gets confused with files inside directories, since are not show at all.

# tree /tmp/test
/tmp/test
├── lowerdir
│   ├── d1
│   │   ├── d11
│   │   │   ├── d111
│   │   │   │   └── f1111
│   │   │   └── f111
│   │   └── f11
│   └── f1
├── mntdir
├── upperdir
└── workdir

# mount -t overlay tstovly /tmp/test/mntdir/ -o lowerdir=/tmp/test/lowerdir,upperdir=/tmp/test/upperdir,workdir=/tmp/test/workdir,ro

example from ntfw(3) manpage modified:

Without FTW_MOUNT
$ ./nftw-example /tmp/test/mntdir/d1/
d    0      80   /tmp/test/mntdir/d1                      17 d1
f    1       0   /tmp/test/mntdir/d1/f11                  20 f11
d    1      80   /tmp/test/mntdir/d1/d11                  20 d11
d    2      60   /tmp/test/mntdir/d1/d11/d111             24 d111
f    3       0   /tmp/test/mntdir/d1/d11/d111/f1111       29 f1111
f    2       0   /tmp/test/mntdir/d1/d11/f111             24 f111

With FTW_MOUNT
$ ./nftw-example /tmp/test/mntdir/d1/ m
d    0      80   /tmp/test/mntdir/d1                      17 d1
d    1      80   /tmp/test/mntdir/d1/d11                  20 d11
d    2      60   /tmp/test/mntdir/d1/d11/d111             24 d111
Comment 1 quorum.laval 2016-11-14 13:38:38 UTC
From glibc2-24/io/ftw.c:

<snippet>

if (result == 0
      && (flag == FTW_NS
          || !(data->flags & FTW_MOUNT) || st.st_dev == data->dev))

<snippet>

st.st_dev == data->dev is false in the cases of non-directory objects,
since st_dev is reported from upper/lower filesystem and ->dev is
reported from overlayfs [0]. So when FTW_NS and FTW_MOUNT are
positionned, non-directory objects will not be reported by nftw(3).

I sent a patch to lkml: https://lkml.org/lkml/2016/11/14/351
Comment 2 quorum.laval 2016-11-14 14:17:35 UTC
When flag is not equal to FTW_NS and FTW_MOUNT is positionned, non-directory objects will not be reported by nftw(3).

sorry for the mistake.
Comment 3 Gerardo Exequiel Pozzi 2018-01-16 22:37:55 UTC
patch is not applied to upstream.