linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] overlay/077: check for inconsistent d_ino/st_ino
@ 2021-07-22 17:02 Amir Goldstein
  0 siblings, 0 replies; only message in thread
From: Amir Goldstein @ 2021-07-22 17:02 UTC (permalink / raw)
  To: Eryu Guan; +Cc: Miklos Szeredi, linux-unionfs, fstests

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")

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

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(-)

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;
 		}
diff --git a/tests/overlay/077 b/tests/overlay/077
index 6510f81f..49dc8144 100755
--- a/tests/overlay/077
+++ b/tests/overlay/077
@@ -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"
-- 
2.32.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-22 17:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 17:02 [PATCH] overlay/077: check for inconsistent d_ino/st_ino Amir Goldstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).