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 2/5] src/t_dir_offset2: Add an option to find file by name
Date: Sun, 25 Apr 2021 10:14:42 +0300 [thread overview]
Message-ID: <20210425071445.29547-3-amir73il@gmail.com> (raw)
In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com>
Will be used to check for missing/stale entries.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
src/t_dir_offset2.c | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/src/t_dir_offset2.c b/src/t_dir_offset2.c
index 7aeb990e..7af24519 100644
--- a/src/t_dir_offset2.c
+++ b/src/t_dir_offset2.c
@@ -8,11 +8,13 @@
* that these offsets are seekable to entry with the right inode.
*/
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
@@ -32,7 +34,7 @@ static uint64_t d_ino_history[HISTORY_LEN];
void usage()
{
- fprintf(stderr, "usage: t_dir_offset2: <dir> [bufsize]\n");
+ fprintf(stderr, "usage: t_dir_offset2: <dir> [[bufsize] <filename> [-v]]\n");
exit(EXIT_FAILURE);
}
@@ -45,6 +47,9 @@ int main(int argc, char *argv[])
int bpos, total, i;
off_t lret;
int retval = EXIT_SUCCESS;
+ const char *filename = NULL;
+ int exists = 0, found = 0;
+ int verbose = 0;
if (argc > 2) {
bufsize = atoi(argv[2]);
@@ -52,6 +57,12 @@ int main(int argc, char *argv[])
usage();
if (bufsize > BUF_SIZE)
bufsize = BUF_SIZE;
+
+ if (argc > 3) {
+ filename = argv[3];
+ if (argc > 4 && !strcmp(argv[4], "-v"))
+ verbose = 1;
+ }
} else if (argc < 2) {
usage();
}
@@ -62,6 +73,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ if (filename) {
+ exists = !faccessat(fd, filename, F_OK, AT_SYMLINK_NOFOLLOW);
+ if (!exists && errno != ENOENT) {
+ perror("faccessat");
+ exit(EXIT_FAILURE);
+ }
+ }
+
total = 0;
for ( ; ; ) {
nread = syscall(SYS_getdents64, fd, buf, bufsize);
@@ -91,10 +110,28 @@ int main(int argc, char *argv[])
}
d_off_history[total] = d->d_off;
d_ino_history[total] = d->d_ino;
+ if (filename) {
+ if (verbose)
+ 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))
+ found = 1;
+ }
bpos += d->d_reclen;
}
}
+ if (filename) {
+ if (exists == found) {
+ printf("entry %s %sfound as expected\n", filename, found ? "" : "not ");
+ } else {
+ fprintf(stderr, "%s entry %s\n",
+ exists ? "missing" : "stale", filename);
+ exit(EXIT_FAILURE);
+ }
+ }
+
/* check if seek works correctly */
d = (struct linux_dirent64 *)buf;
for (i = total - 1; i >= 0; i--)
--
2.31.1
next prev 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 ` Amir Goldstein [this message]
2021-04-25 7:14 ` [PATCH v2 3/5] src/t_dir_offset2: Add option to create or unlink file Amir Goldstein
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-3-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).