From 250615da6f01e99c055b7fc3bd9a2c1deac644e0 Mon Sep 17 00:00:00 2001 From: Amir Goldstein Date: Tue, 20 Jul 2021 17:45:43 +0300 Subject: [PATCH] src/t_dir_offset2: 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. This is a regression test for kernel commit .... ("ovl: skip stale entries in merge dir cache iteration") Signed-off-by: Amir Goldstein --- src/t_dir_offset2.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/t_dir_offset2.c b/src/t_dir_offset2.c index 75b41c1a..026bc8f3 100644 --- a/src/t_dir_offset2.c +++ b/src/t_dir_offset2.c @@ -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; } -- 2.32.0