From: Amir Goldstein <amir73il@gmail.com>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: fstests@vger.kernel.org, Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Chuck Lever <chuck.lever@oracle.com>,
Jeff Layton <jlayton@kernel.org>,
Alexander Aring <alex.aring@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>,
Christoph Hellwig <hch@infradead.org>,
Josef Bacik <josef@toxicpanda.com>,
linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH xfstests v2 2/2] open_by_handle: add tests for u64 mount ID
Date: Mon, 2 Sep 2024 19:21:09 +0200 [thread overview]
Message-ID: <CAOQ4uxgS6DvsbUsEoM1Vr2wcd_7Bj=xFXMAy4z9PphTu+G6RaQ@mail.gmail.com> (raw)
In-Reply-To: <20240902164554.928371-2-cyphar@cyphar.com>
On Mon, Sep 2, 2024 at 6:46 PM Aleksa Sarai <cyphar@cyphar.com> wrote:
>
> Now that open_by_handle_at(2) can return u64 mount IDs, do some tests to
> make sure they match properly as part of the regular open_by_handle
> tests.
>
> Link: https://lore.kernel.org/all/20240828-exportfs-u64-mount-id-v3-0-10c2c4c16708@cyphar.com/
> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> ---
> v2:
> - Remove -M argument and always do the mount ID tests. [Amir Goldstein]
> - Do not error out if the kernel doesn't support STATX_MNT_ID_UNIQUE
> or AT_HANDLE_MNT_ID_UNIQUE. [Amir Goldstein]
> - v1: <https://lore.kernel.org/all/20240828103706.2393267-1-cyphar@cyphar.com/>
Looks good.
You may add:
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
It'd be nice to get a verification that this is indeed tested on the latest
upstream and does not regress the tests that run the open_by_handle program.
Thanks,
Amir.
>
> src/open_by_handle.c | 128 +++++++++++++++++++++++++++++++++----------
> 1 file changed, 99 insertions(+), 29 deletions(-)
>
> diff --git a/src/open_by_handle.c b/src/open_by_handle.c
> index d9c802ca9bd1..0ad591da632e 100644
> --- a/src/open_by_handle.c
> +++ b/src/open_by_handle.c
> @@ -86,10 +86,16 @@ Examples:
> #include <errno.h>
> #include <linux/limits.h>
> #include <libgen.h>
> +#include <stdint.h>
> +#include <stdbool.h>
>
> #include <sys/stat.h>
> #include "statx.h"
>
> +#ifndef AT_HANDLE_MNT_ID_UNIQUE
> +# define AT_HANDLE_MNT_ID_UNIQUE 0x001
> +#endif
> +
> #define MAXFILES 1024
>
> struct handle {
> @@ -120,6 +126,94 @@ void usage(void)
> exit(EXIT_FAILURE);
> }
>
> +int do_name_to_handle_at(const char *fname, struct file_handle *fh, int bufsz)
> +{
> + int ret;
> + int mntid_short;
> +
> + static bool skip_mntid_unique;
> +
> + uint64_t statx_mntid_short = 0, statx_mntid_unique = 0;
> + struct statx statxbuf;
> +
> + /* Get both the short and unique mount id. */
> + if (statx(AT_FDCWD, fname, 0, STATX_MNT_ID, &statxbuf) < 0) {
> + fprintf(stderr, "%s: statx(STATX_MNT_ID): %m\n", fname);
> + return EXIT_FAILURE;
> + }
> + if (!(statxbuf.stx_mask & STATX_MNT_ID)) {
> + fprintf(stderr, "%s: no STATX_MNT_ID in stx_mask\n", fname);
> + return EXIT_FAILURE;
> + }
> + statx_mntid_short = statxbuf.stx_mnt_id;
> +
> + if (!skip_mntid_unique) {
> + if (statx(AT_FDCWD, fname, 0, STATX_MNT_ID_UNIQUE, &statxbuf) < 0) {
> + fprintf(stderr, "%s: statx(STATX_MNT_ID_UNIQUE): %m\n", fname);
> + return EXIT_FAILURE;
> + }
> + /*
> + * STATX_MNT_ID_UNIQUE was added fairly recently in Linux 6.8, so if the
> + * kernel doesn't give us a unique mount ID just skip it.
> + */
> + if ((skip_mntid_unique |= !(statxbuf.stx_mask & STATX_MNT_ID_UNIQUE)))
> + printf("statx(STATX_MNT_ID_UNIQUE) not supported by running kernel -- skipping unique mount ID test\n");
> + else
> + statx_mntid_unique = statxbuf.stx_mnt_id;
> + }
> +
> + fh->handle_bytes = bufsz;
> + ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, 0);
> + if (bufsz < fh->handle_bytes) {
> + /* Query the filesystem required bufsz and the file handle */
> + if (ret != -1 || errno != EOVERFLOW) {
> + fprintf(stderr, "%s: unexpected result from name_to_handle_at: %d (%m)\n", fname, ret);
> + return EXIT_FAILURE;
> + }
> + ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, 0);
> + }
> + if (ret < 0) {
> + fprintf(stderr, "%s: name_to_handle: %m\n", fname);
> + return EXIT_FAILURE;
> + }
> +
> + if (mntid_short != (int) statx_mntid_short) {
> + fprintf(stderr, "%s: name_to_handle_at returned a different mount ID to STATX_MNT_ID: %u != %lu\n", fname, mntid_short, statx_mntid_short);
> + return EXIT_FAILURE;
> + }
> +
> + if (!skip_mntid_unique && statx_mntid_unique != 0) {
> + struct handle dummy_fh;
> + uint64_t mntid_unique = 0;
> +
> + /*
> + * Get the unique mount ID. We don't need to get another copy of the
> + * handle so store it in a dummy struct.
> + */
> + dummy_fh.fh.handle_bytes = fh->handle_bytes;
> + ret = name_to_handle_at(AT_FDCWD, fname, &dummy_fh.fh, (int *) &mntid_unique, AT_HANDLE_MNT_ID_UNIQUE);
> + if (ret < 0) {
> + if (errno != EINVAL) {
> + fprintf(stderr, "%s: name_to_handle_at(AT_HANDLE_MNT_ID_UNIQUE): %m\n", fname);
> + return EXIT_FAILURE;
> + }
> + /*
> + * EINVAL means AT_HANDLE_MNT_ID_UNIQUE is not supported, so skip
> + * the check in that case.
> + */
> + printf("name_to_handle_at(AT_HANDLE_MNT_ID_UNIQUE) not supported by running kernel -- skipping unique mount ID test\n");
> + skip_mntid_unique = true;
> + } else {
> + if (mntid_unique != statx_mntid_unique) {
> + fprintf(stderr, "%s: name_to_handle_at(AT_HANDLE_MNT_ID_UNIQUE) returned a different mount ID to STATX_MNT_ID_UNIQUE: %lu != %lu\n", fname, mntid_unique, statx_mntid_unique);
> + return EXIT_FAILURE;
> + }
> + }
> + }
> +
> + return 0;
> +}
> +
> int main(int argc, char **argv)
> {
> int i, c;
> @@ -132,7 +226,7 @@ int main(int argc, char **argv)
> char fname2[PATH_MAX];
> char *test_dir;
> char *mount_dir;
> - int mount_fd, mount_id;
> + int mount_fd;
> char *infile = NULL, *outfile = NULL;
> int in_fd = 0, out_fd = 0;
> int numfiles = 1;
> @@ -307,21 +401,9 @@ int main(int argc, char **argv)
> return EXIT_FAILURE;
> }
> } else {
> - 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);
> + ret = do_name_to_handle_at(fname, &handle[i].fh, bufsz);
> + if (ret < 0)
> return EXIT_FAILURE;
> - }
> }
> if (keepopen) {
> /* Open without close to keep unlinked files around */
> @@ -349,21 +431,9 @@ int main(int argc, char **argv)
> return EXIT_FAILURE;
> }
> } else {
> - 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);
> + ret = do_name_to_handle_at(test_dir, &dir_handle.fh, bufsz);
> + if (ret < 0)
> return EXIT_FAILURE;
> - }
> }
> if (out_fd) {
> ret = write(out_fd, (char *)&dir_handle, sizeof(*handle));
> --
> 2.46.0
>
next prev parent reply other threads:[~2024-09-02 17:21 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 10:19 [PATCH RESEND v3 0/2] fhandle: expose u64 mount id to name_to_handle_at(2) Aleksa Sarai
2024-08-28 10:19 ` [PATCH RESEND v3 1/2] uapi: explain how per-syscall AT_* flags should be allocated Aleksa Sarai
2024-09-02 12:46 ` Jan Kara
2024-08-28 10:19 ` [PATCH RESEND v3 2/2] fhandle: expose u64 mount id to name_to_handle_at(2) Aleksa Sarai
2024-09-02 12:54 ` Jan Kara
2024-08-28 10:37 ` [PATCH xfstests v1 1/2] statx: update headers to include newer statx fields Aleksa Sarai
2024-08-28 10:37 ` [PATCH xfstests v1 2/2] open_by_handle: add tests for u64 mount ID Aleksa Sarai
2024-08-30 17:10 ` Amir Goldstein
2024-09-01 12:57 ` Aleksa Sarai
2024-09-02 14:16 ` [PATCH RESEND v3 0/2] fhandle: expose u64 mount id to name_to_handle_at(2) Christian Brauner
2024-09-02 16:45 ` [PATCH xfstests v2 1/2] statx: update headers to include newer statx fields Aleksa Sarai
2024-09-02 16:45 ` [PATCH xfstests v2 2/2] open_by_handle: add tests for u64 mount ID Aleksa Sarai
2024-09-02 17:21 ` Amir Goldstein [this message]
2024-09-03 6:41 ` Aleksa Sarai
2024-09-03 9:08 ` Amir Goldstein
2024-09-04 16:30 ` Aleksa Sarai
2024-09-04 16:44 ` Amir Goldstein
2024-09-04 17:53 ` Aleksa Sarai
2024-09-03 7:54 ` Amir Goldstein
2024-09-03 9:11 ` Aleksa Sarai
2024-09-03 6:49 ` [PATCH xfstests v2 1/2] statx: update headers to include newer statx fields Amir Goldstein
2024-09-04 17:56 ` [PATCH xfstests v3 1/2] open_by_handle: verify u32 and u64 mount IDs Aleksa Sarai
2024-09-04 17:56 ` [PATCH xfstests v3 2/2] generic/756: test name_to_handle_at(AT_HANDLE_MNT_ID_UNIQUE) explicitly Aleksa Sarai
2024-09-04 18:49 ` Amir Goldstein
2024-09-04 19:00 ` Aleksa Sarai
2024-09-04 18:29 ` [PATCH xfstests v3 1/2] open_by_handle: verify u32 and u64 mount IDs Amir Goldstein
2024-09-04 19:48 ` [PATCH xfstests v4 " Aleksa Sarai
2024-09-04 19:48 ` [PATCH xfstests v4 2/2] generic/756: test name_to_handle_at(AT_HANDLE_MNT_ID_UNIQUE) explicitly Aleksa Sarai
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='CAOQ4uxgS6DvsbUsEoM1Vr2wcd_7Bj=xFXMAy4z9PphTu+G6RaQ@mail.gmail.com' \
--to=amir73il@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alex.aring@gmail.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=cyphar@cyphar.com \
--cc=fstests@vger.kernel.org \
--cc=hch@infradead.org \
--cc=irogers@google.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=jolsa@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=viro@zeniv.linux.org.uk \
/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).