linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Eryu Guan <guaneryu@gmail.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	linux-unionfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH] overlay/077: check for inconsistent d_ino/st_ino
Date: Thu, 22 Jul 2021 20:02:16 +0300	[thread overview]
Message-ID: <20210722170216.424666-1-amir73il@gmail.com> (raw)

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


                 reply	other threads:[~2021-07-22 17:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210722170216.424666-1-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).