overlay/077: check for inconsistent d_ino/st_ino
PATCH 1/1 overlay/077: check for inconsistent d_ino/st_ino
After unlink of a directory entry, that entry may still apear in getdents results of an already open directory fd, but it should return a d_ino value that is consistent with the already observed st_ino of that entry.
Remove redundant break condition from gendents read loop.
For testing of inconsistent d_ino/st_ino we need to unlink an entry whose st_ino is not that of the upper inode.
In the former merge dir setup we unlink all the files in the lower dir after copyup, so they all use st_ino of the upper inode.
Let the unlinked file f100 reside in a lower path that is not being unlinked so it will have the st_ino of the lower inode.
This is a regression test for kernel commit fcb7f373684d ("ovl: skip stale entries in merge dir cache iteration")
---
Eryu,
This increases the test coverage of overlay/077 to detect another overlay readdir issue that is fixed in current overlayfs-next.
Thanks,
Amir.
src/t_dir_offset2.c | 18 ++++++++++++------ tests/overlay/077 | 5 +++-- 2 files changed, 15 insertions(+), 8 deletions(-)
src/t_dir_offset2.c +12 -6
@@ -44,6 +44,7 @@ int main(int argc, char *argv[])char buf[BUF_SIZE ];int nread, bufsize =BUF_SIZE ;struct linux_dirent64 *d; +struct stat st = {};int bpos, total, i;off_t lret;int retval =EXIT_SUCCESS ;
@@ -81,9 +82,9 @@ int main(int argc, char *argv[]) }if (filename) { - exists = !faccessat (fd, filename,F_OK ,AT_SYMLINK_NOFOLLOW ); + exists = !fstatat (fd, filename, &st,AT_SYMLINK_NOFOLLOW );if (!exists && errno !=ENOENT ) { -perror ("faccessat" ); +perror ("fstatat" );exit (EXIT_FAILURE ); } }
@@ -139,9 +140,6 @@ int main(int argc, char *argv[])continue ; } -if (nread ==0 ) -break ; -for (bpos =0 ; bpos < nread; total++) { d = (struct linux_dirent64 *) (buf + bpos);
@@ -165,8 +163,16 @@ int main(int argc, char *argv[])printf ("entry #%d: %s (d_ino=%lld, d_off=%lld)\n" , i, d->d_name, (long long int )d->d_ino, (long long int )d->d_off); -if (!strcmp (filename, d->d_name)) +if (!strcmp (filename, d->d_name)) { found =1 ; +if (st.st_ino && d->d_ino != st.st_ino) { +fprintf (stderr,"entry %s has inconsistent d_ino (%lld != %lld)\n" , + filename, + (long long int )d->d_ino, + (long long int )st.st_ino); + } + } + } bpos += d->d_reclen; }
tests/overlay/077 +3 -2
@@ -46,8 +46,8 @@ mkdir -p $lowerdir/merge $lowerdir/former $upperdir/pure $upperdir/impure create_files $lowerdir/merge m # Files to be moved into impure upper dir create_files $lowerdir o -# File to be copied up to make former merge dir impure -touch $lowerdir/former/f100 +# File to be moved into former merge dir to make it impure +touch $lowerdir/f100 _scratch_mount
@@ -57,6 +57,7 @@ create_files $SCRATCH_MNT/former f touch $SCRATCH_MNT/merge/m100 # Move copied up files so readdir will need to lookup origin d_ino mv $SCRATCH_MNT/o* $SCRATCH_MNT/impure/ +mv $SCRATCH_MNT/f100 $SCRATCH_MNT/former/ # Remove the lower directory and mount overlay again to create # a "former merge dir"
Signature · 1 line
2.32.0