fstests.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 v2 3/5] src/t_dir_offset2: Add option to create or unlink file
Date: Sun, 25 Apr 2021 10:14:43 +0300	[thread overview]
Message-ID: <20210425071445.29547-4-amir73il@gmail.com> (raw)
In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com>

Will be used to test missing/stale entries after modifications to
an open dirfd.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 src/t_dir_offset2.c | 56 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/src/t_dir_offset2.c b/src/t_dir_offset2.c
index 7af24519..75b41c1a 100644
--- a/src/t_dir_offset2.c
+++ b/src/t_dir_offset2.c
@@ -34,13 +34,13 @@ static uint64_t d_ino_history[HISTORY_LEN];
 
 void usage()
 {
-	fprintf(stderr, "usage: t_dir_offset2: <dir> [[bufsize] <filename> [-v]]\n");
+	fprintf(stderr, "usage: t_dir_offset2: <dir> [[bufsize] [-|+]<filename> [-v]]\n");
 	exit(EXIT_FAILURE);
 }
 
 int main(int argc, char *argv[])
 {
-	int fd;
+	int fd, fd2 = -1;
 	char buf[BUF_SIZE];
 	int nread, bufsize = BUF_SIZE;
 	struct linux_dirent64 *d;
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
 	int retval = EXIT_SUCCESS;
 	const char *filename = NULL;
 	int exists = 0, found = 0;
-	int verbose = 0;
+	int modify = 0, verbose = 0;
 
 	if (argc > 2) {
 		bufsize = atoi(argv[2]);
@@ -60,6 +60,13 @@ int main(int argc, char *argv[])
 
 		if (argc > 3) {
 			filename = argv[3];
+			/* +<filename> creates, -<filename> removes */
+			if (filename[0] == '+')
+				modify = 1;
+			else if (filename[0] == '-')
+				modify = -1;
+			if (modify)
+				filename++;
 			if (argc > 4 && !strcmp(argv[4], "-v"))
 				verbose = 1;
 		}
@@ -89,6 +96,49 @@ int main(int argc, char *argv[])
 			exit(EXIT_FAILURE);
 		}
 
+		if (modify && fd2 < 0 && total == 0) {
+			printf("getdents at offset 0 returned %d bytes\n", nread);
+
+			/* create/unlink entry after first getdents */
+			if (modify > 0) {
+				if (openat(fd, filename, O_CREAT, 0600) < 0) {
+					perror("openat");
+					exit(EXIT_FAILURE);
+				}
+				exists = 1;
+				printf("created entry %s\n", filename);
+			} else if (modify < 0) {
+				if (unlinkat(fd, filename, 0) < 0) {
+					perror("unlinkat");
+					exit(EXIT_FAILURE);
+				}
+				exists = 0;
+				printf("unlinked entry %s\n", filename);
+			}
+
+			/*
+			 * Old fd may not return new entry and may return stale
+			 * entries which is allowed.  Keep old fd open and open
+			 * a new fd to check for stale or missing entries later.
+			 */
+			fd2 = open(argv[1], O_RDONLY | O_DIRECTORY);
+			if (fd2 < 0) {
+				perror("open fd2");
+				exit(EXIT_FAILURE);
+			}
+		}
+
+		if (nread == 0) {
+			if (fd2 < 0 || fd == fd2)
+				break;
+
+			/* Re-iterate with new fd leaving old fd open */
+			fd = fd2;
+			total = 0;
+			found = 0;
+			continue;
+		}
+
 		if (nread == 0)
 			break;
 
-- 
2.31.1


  parent reply	other threads:[~2021-04-25  7:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-25  7:14 [PATCH v2 0/5] Test overlayfs readdir cache Amir Goldstein
2021-04-25  7:14 ` [PATCH v2 1/5] src/t_dir_offset2: Add an option to limit of buffer size Amir Goldstein
2021-04-25  7:14 ` [PATCH v2 2/5] src/t_dir_offset2: Add an option to find file by name Amir Goldstein
2021-04-25  7:14 ` Amir Goldstein [this message]
2021-04-25  7:14 ` [PATCH v2 4/5] generic: Test readdir of modified directrory Amir Goldstein
2021-04-25  7:14 ` [PATCH v2 5/5] overlay: Test invalidate of readdir cache Amir Goldstein
2021-04-26 10:07 ` [PATCH v2 0/5] Test overlayfs " Miklos Szeredi
2021-04-26 10:15   ` Amir Goldstein
2021-04-26 13:12     ` Miklos Szeredi
2021-04-26 15:22       ` Amir Goldstein

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=20210425071445.29547-4-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).