From: Amir Goldstein <amir73il@gmail.com>
To: Eryu Guan <guaneryu@gmail.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
Dan Carpenter <dan.carpenter@oracle.com>,
Lubos Dolezel <lubos@dolezel.info>,
linux-unionfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH v2 1/2] open_by_handle: add option -z to query file handle size
Date: Sun, 14 Jun 2020 10:01:08 +0300 [thread overview]
Message-ID: <20200614070109.29842-2-amir73il@gmail.com> (raw)
In-Reply-To: <20200614070109.29842-1-amir73il@gmail.com>
Instead of using MAX_HANDLE_SZ, query the filesystem buffer size
and use that buffer size to get the file handle.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
src/open_by_handle.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/open_by_handle.c b/src/open_by_handle.c
index 4fdfacd7..0f74ed08 100644
--- a/src/open_by_handle.c
+++ b/src/open_by_handle.c
@@ -114,6 +114,7 @@ void usage(void)
fprintf(stderr, "open_by_handle -i <handles_file> <test_dir> [N] - read test files handles from file and try to open by handle\n");
fprintf(stderr, "open_by_handle -o <handles_file> <test_dir> [N] - get file handles of test files and write handles to file\n");
fprintf(stderr, "open_by_handle -s <test_dir> [N] - wait in sleep loop after opening files by handle to keep them open\n");
+ fprintf(stderr, "open_by_handle -z <test_dir> [N] - query filesystem required buffer size\n");
exit(EXIT_FAILURE);
}
@@ -136,11 +137,12 @@ int main(int argc, char **argv)
int create = 0, delete = 0, nlink = 1, move = 0;
int rd = 0, wr = 0, wrafter = 0, parent = 0;
int keepopen = 0, drop_caches = 1, sleep_loop = 0;
+ int bufsz = MAX_HANDLE_SZ;
if (argc < 2)
usage();
- while ((c = getopt(argc, argv, "cludmrwapknhi:o:s")) != -1) {
+ while ((c = getopt(argc, argv, "cludmrwapknhi:o:sz")) != -1) {
switch (c) {
case 'c':
create = 1;
@@ -199,6 +201,9 @@ int main(int argc, char **argv)
case 's':
sleep_loop = 1;
break;
+ case 'z':
+ bufsz = 0;
+ break;
default:
fprintf(stderr, "illegal option '%s'\n", argv[optind]);
case 'h':
@@ -300,8 +305,16 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
} else {
- handle[i].fh.handle_bytes = MAX_HANDLE_SZ;
+ handle[i].fh.handle_bytes = bufsz;
ret = name_to_handle_at(AT_FDCWD, fname, &handle[i].fh, &mount_id, 0);
+ if (bufsz < handle[i].fh.handle_bytes) {
+ /* Query the filesystem required bufsz and the file handle */
+ if (ret != -1 || errno != EOVERFLOW) {
+ fprintf(stderr, "Unexpected result from name_to_handle_at(%s)\n", fname);
+ return EXIT_FAILURE;
+ }
+ ret = name_to_handle_at(AT_FDCWD, fname, &handle[i].fh, &mount_id, 0);
+ }
if (ret < 0) {
strcat(fname, ": name_to_handle");
perror(fname);
@@ -334,8 +347,16 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
} else {
- dir_handle.fh.handle_bytes = MAX_HANDLE_SZ;
+ dir_handle.fh.handle_bytes = bufsz;
ret = name_to_handle_at(AT_FDCWD, test_dir, &dir_handle.fh, &mount_id, 0);
+ if (bufsz < dir_handle.fh.handle_bytes) {
+ /* Query the filesystem required bufsz and the file handle */
+ if (ret != -1 || errno != EOVERFLOW) {
+ fprintf(stderr, "Unexpected result from name_to_handle_at(%s)\n", dname);
+ return EXIT_FAILURE;
+ }
+ ret = name_to_handle_at(AT_FDCWD, test_dir, &dir_handle.fh, &mount_id, 0);
+ }
if (ret < 0) {
strcat(dname, ": name_to_handle");
perror(dname);
--
2.17.1
next prev parent reply other threads:[~2020-06-14 7:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-14 7:01 [PATCH v2 0/2] Overlayfs tests for file handle bugs Amir Goldstein
2020-06-14 7:01 ` Amir Goldstein [this message]
2020-06-14 7:01 ` [PATCH v2 2/2] overlay: regression test for two " 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=20200614070109.29842-2-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=fstests@vger.kernel.org \
--cc=guaneryu@gmail.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=lubos@dolezel.info \
--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).