linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE
@ 2025-05-09 17:00 Amir Goldstein
  2025-05-09 17:00 ` [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles Amir Goldstein
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Amir Goldstein @ 2025-05-09 17:00 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

This is a test for new flag AT_HANDLE_CONNECTABLE from v6.13.
See man page update of this flag here [1].

This v2 fixes the failures that you observed with tmpfs and nfs.

Thanks,
Amir.

[1] https://lore.kernel.org/linux-fsdevel/20250330163502.1415011-1-amir73il@gmail.com/

Changes since v1:
- Remove unpredictable test case of open fh after move to new parent
- Add check that open fds are connected

Amir Goldstein (2):
  open_by_handle: add support for testing connectable file handles
  open_by_handle: add a test for connectable file handles

 common/rc             | 16 ++++++++--
 src/open_by_handle.c  | 53 ++++++++++++++++++++++++++------
 tests/generic/777     | 70 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/777.out |  5 ++++
 4 files changed, 132 insertions(+), 12 deletions(-)
 create mode 100755 tests/generic/777
 create mode 100644 tests/generic/777.out

-- 
2.34.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles
  2025-05-09 17:00 [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
@ 2025-05-09 17:00 ` Amir Goldstein
  2025-05-25 10:49   ` Zorro Lang
  2025-05-09 17:00 ` [PATCH v2 2/2] open_by_handle: add a test for " Amir Goldstein
  2025-05-23 14:20 ` [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
  2 siblings, 1 reply; 10+ messages in thread
From: Amir Goldstein @ 2025-05-09 17:00 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

Test for kernel and filesystem support for conenctable file handles.

With -N flag, encode connectable file handles and fail the test if the
kernel or filesystem do not support conenctable file handles.

Verify that decoding connectable file handles always results in a non
empty path of the fd.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 common/rc            | 16 ++++++++++---
 src/open_by_handle.c | 53 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/common/rc b/common/rc
index 6592c835..6407b744 100644
--- a/common/rc
+++ b/common/rc
@@ -3829,8 +3829,14 @@ _require_freeze()
 }
 
 # Does NFS export work on this fs?
-_require_exportfs()
+_require_open_by_handle()
 {
+	local what="NFS export"
+	local opts="$1"
+	if [ "$1" == "-N" ]; then
+		what="connectable file handles"
+	fi
+
 	_require_test_program "open_by_handle"
 
 	# virtiofs doesn't support open_by_handle_at(2) yet, though the syscall
@@ -3841,10 +3847,14 @@ _require_exportfs()
 		_notrun "$FSTYP doesn't support open_by_handle_at(2)"
 
 	mkdir -p "$TEST_DIR"/exportfs_test
-	$here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
-		|| _notrun "$FSTYP does not support NFS export"
+	$here/src/open_by_handle $opts -c "$TEST_DIR"/exportfs_test 2>&1 \
+		|| _notrun "$FSTYP does not support $what"
 }
 
+_require_exportfs()
+{
+	_require_open_by_handle
+}
 
 # Does shutdown work on this fs?
 _require_scratch_shutdown()
diff --git a/src/open_by_handle.c b/src/open_by_handle.c
index a99cce4b..7b664201 100644
--- a/src/open_by_handle.c
+++ b/src/open_by_handle.c
@@ -96,6 +96,9 @@ Examples:
 #ifndef AT_HANDLE_MNT_ID_UNIQUE
 #	define AT_HANDLE_MNT_ID_UNIQUE 0x001
 #endif
+#ifndef AT_HANDLE_CONNECTABLE
+#	define AT_HANDLE_CONNECTABLE   0x002
+#endif
 
 #define MAXFILES 1024
 
@@ -121,6 +124,7 @@ void usage(void)
 	fprintf(stderr, "open_by_handle -d <test_dir> [N] - unlink test files and hardlinks, drop caches and try to open by handle\n");
 	fprintf(stderr, "open_by_handle -m <test_dir> [N] - rename test files, drop caches and try to open by handle\n");
 	fprintf(stderr, "open_by_handle -M <test_dir> [N] - do not silently skip the mount ID verifications\n");
+	fprintf(stderr, "open_by_handle -N <test_dir> [N] - encode connectable file handles\n");
 	fprintf(stderr, "open_by_handle -p <test_dir>     - create/delete and try to open by handle also test_dir itself\n");
 	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");
@@ -130,14 +134,16 @@ void usage(void)
 	fprintf(stderr, "open_by_handle -C <feature>      - check if <feature> is supported by the kernel.\n");
 	fprintf(stderr, "  <feature> can be any of the following values:\n");
 	fprintf(stderr, "  - AT_HANDLE_MNT_ID_UNIQUE\n");
+	fprintf(stderr, "  - AT_HANDLE_CONNECTABLE\n");
 	exit(EXIT_FAILURE);
 }
 
-static int do_name_to_handle_at(const char *fname, struct file_handle *fh,
-				int bufsz, bool force_check_mountid)
+static int do_name_to_handle_at(const char *fname, struct file_handle *fh, int bufsz,
+				bool force_check_mountid, bool connectable)
 {
 	int ret;
 	int mntid_short;
+	int at_flags;
 
 	static bool skip_mntid, skip_mntid_unique;
 
@@ -181,18 +187,24 @@ static int do_name_to_handle_at(const char *fname, struct file_handle *fh,
 		}
 	}
 
+	at_flags = connectable ? AT_HANDLE_CONNECTABLE : 0;
 	fh->handle_bytes = bufsz;
-	ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, 0);
+	ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, at_flags);
 	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);
+		ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, at_flags);
 	}
 	if (ret < 0) {
-		fprintf(stderr, "%s: name_to_handle: %m\n", fname);
+		/* No filesystem support for encoding connectable file handles (e.g. overlayfs)? */
+		if (connectable)
+			fprintf(stderr, "%s: name_to_handle_at(AT_HANDLE_CONNECTABLE) not supported by %s\n",
+					fname, errno == EINVAL ? "kernel" : "filesystem");
+		else
+			fprintf(stderr, "%s: name_to_handle: %m\n", fname);
 		return EXIT_FAILURE;
 	}
 
@@ -245,8 +257,17 @@ static int check_feature(const char *feature)
 			return EXIT_FAILURE;
 		}
 		return 0;
+	} else if (!strcmp(feature, "AT_HANDLE_CONNECTABLE")) {
+		int ret = name_to_handle_at(AT_FDCWD, ".", NULL, NULL, AT_HANDLE_CONNECTABLE);
+		/* If AT_HANDLE_CONNECTABLE is supported, we get EFAULT. */
+		if (ret < 0 && errno == EINVAL) {
+			fprintf(stderr, "name_to_handle_at(AT_HANDLE_CONNECTABLE) not supported by running kernel\n");
+			return EXIT_FAILURE;
+		}
+		return 0;
 	}
 
+
 	fprintf(stderr, "unknown feature name '%s'\n", feature);
 	return EXIT_FAILURE;
 }
@@ -270,13 +291,13 @@ 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	force_check_mountid = 0;
+	bool	force_check_mountid = 0, connectable = 0;
 	int	bufsz = MAX_HANDLE_SZ;
 
 	if (argc < 2)
 		usage();
 
-	while ((c = getopt(argc, argv, "cC:ludmMrwapknhi:o:sz")) != -1) {
+	while ((c = getopt(argc, argv, "cC:ludmMNrwapknhi:o:sz")) != -1) {
 		switch (c) {
 		case 'c':
 			create = 1;
@@ -313,6 +334,9 @@ int main(int argc, char **argv)
 		case 'M':
 			force_check_mountid = 1;
 			break;
+		case 'N':
+			connectable = 1;
+			break;
 		case 'p':
 			parent = 1;
 			break;
@@ -445,7 +469,8 @@ int main(int argc, char **argv)
 				return EXIT_FAILURE;
 			}
 		} else {
-			ret = do_name_to_handle_at(fname, &handle[i].fh, bufsz, force_check_mountid);
+			ret = do_name_to_handle_at(fname, &handle[i].fh, bufsz,
+						   force_check_mountid, connectable);
 			if (ret)
 				return EXIT_FAILURE;
 		}
@@ -475,7 +500,8 @@ int main(int argc, char **argv)
 				return EXIT_FAILURE;
 			}
 		} else {
-			ret = do_name_to_handle_at(test_dir, &dir_handle.fh, bufsz, force_check_mountid);
+			ret = do_name_to_handle_at(test_dir, &dir_handle.fh, bufsz,
+						   force_check_mountid, connectable);
 			if (ret)
 				return EXIT_FAILURE;
 		}
@@ -589,6 +615,15 @@ int main(int argc, char **argv)
 		errno = 0;
 		fd = open_by_handle_at(mount_fd, &handle[i].fh, wrafter ? O_RDWR : O_RDONLY);
 		if ((nlink || keepopen) && fd >= 0) {
+			char linkname[PATH_MAX];
+			char procname[64];
+			sprintf(procname, "/proc/self/fd/%i", fd);
+			int n = readlink(procname, linkname, PATH_MAX);
+
+			/* check that fd is "connected" - that is has a non empty path */
+			if (connectable && n <= 1) {
+				printf("open_by_handle(%s) returned a disconnected fd!\n", fname);
+			}
 			if (rd) {
 				char buf[4] = {0};
 				int size = read(fd, buf, 4);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] open_by_handle: add a test for connectable file handles
  2025-05-09 17:00 [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
  2025-05-09 17:00 ` [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles Amir Goldstein
@ 2025-05-09 17:00 ` Amir Goldstein
  2025-05-09 17:06   ` Amir Goldstein
  2025-05-23 14:20 ` [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
  2 siblings, 1 reply; 10+ messages in thread
From: Amir Goldstein @ 2025-05-09 17:00 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

This is a variant of generic/477 with connectable file handles.
This test uses load and store of file handles from a temp file to test
decoding connectable file handles after cycle mount and after renames.

Decoding connectable file handles after being moved to a new parent
is expected to fail on some filesystems, but not on filesystems that
do not really get unmounted in mount cycle like tmpfs, so skip this test.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 tests/generic/777     | 70 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/777.out |  5 ++++
 2 files changed, 75 insertions(+)
 create mode 100755 tests/generic/777
 create mode 100644 tests/generic/777.out

diff --git a/tests/generic/777 b/tests/generic/777
new file mode 100755
index 00000000..d8d33e55
--- /dev/null
+++ b/tests/generic/777
@@ -0,0 +1,70 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2018-2025 CTERA Networks. All Rights Reserved.
+#
+# FS QA Test No. 777
+#
+# Check open by connectable file handle after cycle mount.
+#
+# This is a variant of test 477 with connectable file handles.
+# This test uses load and store of file handles from a temp file to test
+# decoding file handles after cycle mount and after directory renames.
+# Decoding connectable file handles after being moved to a new parent
+# is expected to fail on some filesystems, but not on filesystems that
+# do not really get unmounted in mount cycle like tmpfs, so skip this test.
+#
+. ./common/preamble
+_begin_fstest auto quick exportfs
+
+# Import common functions.
+. ./common/filter
+
+
+# Modify as appropriate.
+_require_test
+# Require connectable file handles support
+_require_open_by_handle -N
+
+NUMFILES=10
+testroot=$TEST_DIR/$seq-dir
+testdir=$testroot/testdir
+
+# Create test dir and test files, encode connectable file handles and store to tmp file
+create_test_files()
+{
+	rm -rf $testdir
+	mkdir -p $testdir
+	$here/src/open_by_handle -N -cwp -o $tmp.handles_file $testdir $NUMFILES
+}
+
+# Decode connectable file handles loaded from tmp file
+test_file_handles()
+{
+	local opt=$1
+	local when=$2
+
+	echo test_file_handles after $when
+	$here/src/open_by_handle $opt -i $tmp.handles_file $TEST_DIR $NUMFILES
+}
+
+# Decode file handles of files/dir after cycle mount
+create_test_files
+_test_cycle_mount
+test_file_handles -rp "cycle mount"
+
+# Decode file handles of files/dir after rename of parent and cycle mount
+create_test_files $testdir
+rm -rf $testdir.renamed
+mv $testdir $testdir.renamed/
+_test_cycle_mount
+test_file_handles -rp "rename parent"
+
+# Decode file handles of files/dir after rename of grandparent and cycle mount
+create_test_files $testdir
+rm -rf $testroot.renamed
+mv $testroot $testroot.renamed/
+_test_cycle_mount
+test_file_handles -rp "rename grandparent"
+
+status=0
+exit
diff --git a/tests/generic/777.out b/tests/generic/777.out
new file mode 100644
index 00000000..c0617681
--- /dev/null
+++ b/tests/generic/777.out
@@ -0,0 +1,5 @@
+QA output created by 777
+test_file_handles after cycle mount
+test_file_handles after rename parent
+test_file_handles after rename grandparent
+test_file_handles after move to new parent
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/2] open_by_handle: add a test for connectable file handles
  2025-05-09 17:00 ` [PATCH v2 2/2] open_by_handle: add a test for " Amir Goldstein
@ 2025-05-09 17:06   ` Amir Goldstein
  0 siblings, 0 replies; 10+ messages in thread
From: Amir Goldstein @ 2025-05-09 17:06 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

On Fri, May 9, 2025 at 7:00 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> This is a variant of generic/477 with connectable file handles.
> This test uses load and store of file handles from a temp file to test
> decoding connectable file handles after cycle mount and after renames.
>
> Decoding connectable file handles after being moved to a new parent
> is expected to fail on some filesystems, but not on filesystems that
> do not really get unmounted in mount cycle like tmpfs, so skip this test.
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  tests/generic/777     | 70 +++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/777.out |  5 ++++
>  2 files changed, 75 insertions(+)
>  create mode 100755 tests/generic/777
>  create mode 100644 tests/generic/777.out
>
> diff --git a/tests/generic/777 b/tests/generic/777
> new file mode 100755
> index 00000000..d8d33e55
> --- /dev/null
> +++ b/tests/generic/777
> @@ -0,0 +1,70 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2018-2025 CTERA Networks. All Rights Reserved.
> +#
> +# FS QA Test No. 777
> +#
> +# Check open by connectable file handle after cycle mount.
> +#
> +# This is a variant of test 477 with connectable file handles.
> +# This test uses load and store of file handles from a temp file to test
> +# decoding file handles after cycle mount and after directory renames.
> +# Decoding connectable file handles after being moved to a new parent
> +# is expected to fail on some filesystems, but not on filesystems that
> +# do not really get unmounted in mount cycle like tmpfs, so skip this test.
> +#
> +. ./common/preamble
> +_begin_fstest auto quick exportfs
> +
> +# Import common functions.
> +. ./common/filter
> +
> +
> +# Modify as appropriate.
> +_require_test
> +# Require connectable file handles support
> +_require_open_by_handle -N
> +
> +NUMFILES=10
> +testroot=$TEST_DIR/$seq-dir
> +testdir=$testroot/testdir
> +
> +# Create test dir and test files, encode connectable file handles and store to tmp file
> +create_test_files()
> +{
> +       rm -rf $testdir
> +       mkdir -p $testdir
> +       $here/src/open_by_handle -N -cwp -o $tmp.handles_file $testdir $NUMFILES
> +}
> +
> +# Decode connectable file handles loaded from tmp file
> +test_file_handles()
> +{
> +       local opt=$1
> +       local when=$2
> +
> +       echo test_file_handles after $when
> +       $here/src/open_by_handle $opt -i $tmp.handles_file $TEST_DIR $NUMFILES
> +}
> +
> +# Decode file handles of files/dir after cycle mount
> +create_test_files
> +_test_cycle_mount
> +test_file_handles -rp "cycle mount"
> +
> +# Decode file handles of files/dir after rename of parent and cycle mount
> +create_test_files $testdir
> +rm -rf $testdir.renamed
> +mv $testdir $testdir.renamed/
> +_test_cycle_mount
> +test_file_handles -rp "rename parent"
> +
> +# Decode file handles of files/dir after rename of grandparent and cycle mount
> +create_test_files $testdir
> +rm -rf $testroot.renamed
> +mv $testroot $testroot.renamed/
> +_test_cycle_mount
> +test_file_handles -rp "rename grandparent"
> +
> +status=0
> +exit
> diff --git a/tests/generic/777.out b/tests/generic/777.out
> new file mode 100644
> index 00000000..c0617681
> --- /dev/null
> +++ b/tests/generic/777.out
> @@ -0,0 +1,5 @@
> +QA output created by 777
> +test_file_handles after cycle mount
> +test_file_handles after rename parent
> +test_file_handles after rename grandparent
> +test_file_handles after move to new parent

OOPS this line was supposed to be removed - resending

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE
  2025-05-09 17:00 [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
  2025-05-09 17:00 ` [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles Amir Goldstein
  2025-05-09 17:00 ` [PATCH v2 2/2] open_by_handle: add a test for " Amir Goldstein
@ 2025-05-23 14:20 ` Amir Goldstein
  2025-05-23 14:50   ` Zorro Lang
  2 siblings, 1 reply; 10+ messages in thread
From: Amir Goldstein @ 2025-05-23 14:20 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

Hi Zorro.

Ping.

On Fri, May 9, 2025 at 7:00 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> This is a test for new flag AT_HANDLE_CONNECTABLE from v6.13.
> See man page update of this flag here [1].
>
> This v2 fixes the failures that you observed with tmpfs and nfs.
>
> Thanks,
> Amir.
>
> [1] https://lore.kernel.org/linux-fsdevel/20250330163502.1415011-1-amir73il@gmail.com/
>
> Changes since v1:
> - Remove unpredictable test case of open fh after move to new parent
> - Add check that open fds are connected
>
> Amir Goldstein (2):
>   open_by_handle: add support for testing connectable file handles
>   open_by_handle: add a test for connectable file handles
>
>  common/rc             | 16 ++++++++--
>  src/open_by_handle.c  | 53 ++++++++++++++++++++++++++------
>  tests/generic/777     | 70 +++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/777.out |  5 ++++
>  4 files changed, 132 insertions(+), 12 deletions(-)
>  create mode 100755 tests/generic/777
>  create mode 100644 tests/generic/777.out
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE
  2025-05-23 14:20 ` [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
@ 2025-05-23 14:50   ` Zorro Lang
  2025-05-23 17:11     ` Amir Goldstein
  0 siblings, 1 reply; 10+ messages in thread
From: Zorro Lang @ 2025-05-23 14:50 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

On Fri, May 23, 2025 at 04:20:29PM +0200, Amir Goldstein wrote:
> Hi Zorro.
> 
> Ping.

Sure Amir, don't worry, this patchset is already in my testing list.
I'll merge it after testing passed :)

> 
> On Fri, May 9, 2025 at 7:00 PM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > This is a test for new flag AT_HANDLE_CONNECTABLE from v6.13.
> > See man page update of this flag here [1].
> >
> > This v2 fixes the failures that you observed with tmpfs and nfs.
> >
> > Thanks,
> > Amir.
> >
> > [1] https://lore.kernel.org/linux-fsdevel/20250330163502.1415011-1-amir73il@gmail.com/
> >
> > Changes since v1:
> > - Remove unpredictable test case of open fh after move to new parent
> > - Add check that open fds are connected
> >
> > Amir Goldstein (2):
> >   open_by_handle: add support for testing connectable file handles
> >   open_by_handle: add a test for connectable file handles
> >
> >  common/rc             | 16 ++++++++--
> >  src/open_by_handle.c  | 53 ++++++++++++++++++++++++++------
> >  tests/generic/777     | 70 +++++++++++++++++++++++++++++++++++++++++++
> >  tests/generic/777.out |  5 ++++
> >  4 files changed, 132 insertions(+), 12 deletions(-)
> >  create mode 100755 tests/generic/777
> >  create mode 100644 tests/generic/777.out
> >
> > --
> > 2.34.1
> >
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE
  2025-05-23 14:50   ` Zorro Lang
@ 2025-05-23 17:11     ` Amir Goldstein
  2025-05-25  5:36       ` Zorro Lang
  0 siblings, 1 reply; 10+ messages in thread
From: Amir Goldstein @ 2025-05-23 17:11 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

On Fri, May 23, 2025 at 4:50 PM Zorro Lang <zlang@redhat.com> wrote:
>
> On Fri, May 23, 2025 at 04:20:29PM +0200, Amir Goldstein wrote:
> > Hi Zorro.
> >
> > Ping.
>
> Sure Amir, don't worry, this patchset is already in my testing list.
> I'll merge it after testing passed :)
>

Thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE
  2025-05-23 17:11     ` Amir Goldstein
@ 2025-05-25  5:36       ` Zorro Lang
  2025-05-25  7:40         ` Amir Goldstein
  0 siblings, 1 reply; 10+ messages in thread
From: Zorro Lang @ 2025-05-25  5:36 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

On Fri, May 23, 2025 at 07:11:23PM +0200, Amir Goldstein wrote:
> On Fri, May 23, 2025 at 4:50 PM Zorro Lang <zlang@redhat.com> wrote:
> >
> > On Fri, May 23, 2025 at 04:20:29PM +0200, Amir Goldstein wrote:
> > > Hi Zorro.
> > >
> > > Ping.
> >
> > Sure Amir, don't worry, this patchset is already in my testing list.
> > I'll merge it after testing passed :)
> >
> 
> Thanks!

Hi Amir,

Although the v2 test passed on tmpfs, but it still fails on nfsv4.2, the
diff output as [1]. Is that as your expected? Anyway I think this's not
a big issue, so we still can merge this test case at first (as it's blocked
long time), then fix this failure later :)

Thanks,
Zorro


[1]
--- /dev/fd/63	2025-05-23 17:25:52.283688434 -0400
+++ generic/777.out.bad	2025-05-23 17:25:51.955645147 -0400
@@ -1,4 +1,34 @@
 QA output created by 777
 test_file_handles after cycle mount
+open_by_handle(/mnt/xfstests/test/nfs-client/file000000) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000001) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000002) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000003) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000004) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000005) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000006) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000007) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000008) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000009) returned 116 incorrectly on a linked file!
 test_file_handles after rename parent
+open_by_handle(/mnt/xfstests/test/nfs-client/file000000) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000001) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000002) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000003) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000004) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000005) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000006) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000007) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000008) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000009) returned 116 incorrectly on a linked file!
 test_file_handles after rename grandparent
+open_by_handle(/mnt/xfstests/test/nfs-client/file000000) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000001) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000002) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000003) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000004) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000005) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000006) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000007) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000008) returned 116 incorrectly on a linked file!
+open_by_handle(/mnt/xfstests/test/nfs-client/file000009) returned 116 incorrectly on a linked file!

> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE
  2025-05-25  5:36       ` Zorro Lang
@ 2025-05-25  7:40         ` Amir Goldstein
  0 siblings, 0 replies; 10+ messages in thread
From: Amir Goldstein @ 2025-05-25  7:40 UTC (permalink / raw)
  To: Zorro Lang
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

On Sun, May 25, 2025 at 7:36 AM Zorro Lang <zlang@redhat.com> wrote:
>
> On Fri, May 23, 2025 at 07:11:23PM +0200, Amir Goldstein wrote:
> > On Fri, May 23, 2025 at 4:50 PM Zorro Lang <zlang@redhat.com> wrote:
> > >
> > > On Fri, May 23, 2025 at 04:20:29PM +0200, Amir Goldstein wrote:
> > > > Hi Zorro.
> > > >
> > > > Ping.
> > >
> > > Sure Amir, don't worry, this patchset is already in my testing list.
> > > I'll merge it after testing passed :)
> > >
> >
> > Thanks!
>
> Hi Amir,
>
> Although the v2 test passed on tmpfs, but it still fails on nfsv4.2, the
> diff output as [1]. Is that as your expected? Anyway I think this's not
> a big issue, so we still can merge this test case at first (as it's blocked
> long time), then fix this failure later :)

It seems like a kernel bug, so the test is good.

Looking at nfsv4.2 implementation, it does not implement fh_to_parent(),
so AT_HANDLE_CONNECTALE should not be supported and the test
should have notrun due to "does not support connectable file handles"

I will post a patch to fix the kernel and setup my env to test nfsv4.2.

Thanks!
Amir.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles
  2025-05-09 17:00 ` [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles Amir Goldstein
@ 2025-05-25 10:49   ` Zorro Lang
  0 siblings, 0 replies; 10+ messages in thread
From: Zorro Lang @ 2025-05-25 10:49 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Aleksa Sarai, Christian Brauner, Jan Kara, Chuck Lever,
	Jeff Layton, fstests, linux-fsdevel

On Fri, May 09, 2025 at 07:00:32PM +0200, Amir Goldstein wrote:
> Test for kernel and filesystem support for conenctable file handles.
> 
> With -N flag, encode connectable file handles and fail the test if the
> kernel or filesystem do not support conenctable file handles.
> 
> Verify that decoding connectable file handles always results in a non
> empty path of the fd.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---

Reviewed-by: Zorro Lang <zlang@redhat.com>

>  common/rc            | 16 ++++++++++---
>  src/open_by_handle.c | 53 ++++++++++++++++++++++++++++++++++++--------
>  2 files changed, 57 insertions(+), 12 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index 6592c835..6407b744 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -3829,8 +3829,14 @@ _require_freeze()
>  }
>  
>  # Does NFS export work on this fs?
> -_require_exportfs()
> +_require_open_by_handle()
>  {
> +	local what="NFS export"
> +	local opts="$1"
> +	if [ "$1" == "-N" ]; then
> +		what="connectable file handles"
> +	fi
> +
>  	_require_test_program "open_by_handle"
>  
>  	# virtiofs doesn't support open_by_handle_at(2) yet, though the syscall
> @@ -3841,10 +3847,14 @@ _require_exportfs()
>  		_notrun "$FSTYP doesn't support open_by_handle_at(2)"
>  
>  	mkdir -p "$TEST_DIR"/exportfs_test
> -	$here/src/open_by_handle -c "$TEST_DIR"/exportfs_test 2>&1 \
> -		|| _notrun "$FSTYP does not support NFS export"
> +	$here/src/open_by_handle $opts -c "$TEST_DIR"/exportfs_test 2>&1 \
> +		|| _notrun "$FSTYP does not support $what"
>  }
>  
> +_require_exportfs()
> +{
> +	_require_open_by_handle
> +}
>  
>  # Does shutdown work on this fs?
>  _require_scratch_shutdown()
> diff --git a/src/open_by_handle.c b/src/open_by_handle.c
> index a99cce4b..7b664201 100644
> --- a/src/open_by_handle.c
> +++ b/src/open_by_handle.c
> @@ -96,6 +96,9 @@ Examples:
>  #ifndef AT_HANDLE_MNT_ID_UNIQUE
>  #	define AT_HANDLE_MNT_ID_UNIQUE 0x001
>  #endif
> +#ifndef AT_HANDLE_CONNECTABLE
> +#	define AT_HANDLE_CONNECTABLE   0x002
> +#endif
>  
>  #define MAXFILES 1024
>  
> @@ -121,6 +124,7 @@ void usage(void)
>  	fprintf(stderr, "open_by_handle -d <test_dir> [N] - unlink test files and hardlinks, drop caches and try to open by handle\n");
>  	fprintf(stderr, "open_by_handle -m <test_dir> [N] - rename test files, drop caches and try to open by handle\n");
>  	fprintf(stderr, "open_by_handle -M <test_dir> [N] - do not silently skip the mount ID verifications\n");
> +	fprintf(stderr, "open_by_handle -N <test_dir> [N] - encode connectable file handles\n");
>  	fprintf(stderr, "open_by_handle -p <test_dir>     - create/delete and try to open by handle also test_dir itself\n");
>  	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");
> @@ -130,14 +134,16 @@ void usage(void)
>  	fprintf(stderr, "open_by_handle -C <feature>      - check if <feature> is supported by the kernel.\n");
>  	fprintf(stderr, "  <feature> can be any of the following values:\n");
>  	fprintf(stderr, "  - AT_HANDLE_MNT_ID_UNIQUE\n");
> +	fprintf(stderr, "  - AT_HANDLE_CONNECTABLE\n");
>  	exit(EXIT_FAILURE);
>  }
>  
> -static int do_name_to_handle_at(const char *fname, struct file_handle *fh,
> -				int bufsz, bool force_check_mountid)
> +static int do_name_to_handle_at(const char *fname, struct file_handle *fh, int bufsz,
> +				bool force_check_mountid, bool connectable)
>  {
>  	int ret;
>  	int mntid_short;
> +	int at_flags;
>  
>  	static bool skip_mntid, skip_mntid_unique;
>  
> @@ -181,18 +187,24 @@ static int do_name_to_handle_at(const char *fname, struct file_handle *fh,
>  		}
>  	}
>  
> +	at_flags = connectable ? AT_HANDLE_CONNECTABLE : 0;
>  	fh->handle_bytes = bufsz;
> -	ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, 0);
> +	ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, at_flags);
>  	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);
> +		ret = name_to_handle_at(AT_FDCWD, fname, fh, &mntid_short, at_flags);
>  	}
>  	if (ret < 0) {
> -		fprintf(stderr, "%s: name_to_handle: %m\n", fname);
> +		/* No filesystem support for encoding connectable file handles (e.g. overlayfs)? */
> +		if (connectable)
> +			fprintf(stderr, "%s: name_to_handle_at(AT_HANDLE_CONNECTABLE) not supported by %s\n",
> +					fname, errno == EINVAL ? "kernel" : "filesystem");
> +		else
> +			fprintf(stderr, "%s: name_to_handle: %m\n", fname);
>  		return EXIT_FAILURE;
>  	}
>  
> @@ -245,8 +257,17 @@ static int check_feature(const char *feature)
>  			return EXIT_FAILURE;
>  		}
>  		return 0;
> +	} else if (!strcmp(feature, "AT_HANDLE_CONNECTABLE")) {
> +		int ret = name_to_handle_at(AT_FDCWD, ".", NULL, NULL, AT_HANDLE_CONNECTABLE);
> +		/* If AT_HANDLE_CONNECTABLE is supported, we get EFAULT. */
> +		if (ret < 0 && errno == EINVAL) {
> +			fprintf(stderr, "name_to_handle_at(AT_HANDLE_CONNECTABLE) not supported by running kernel\n");
> +			return EXIT_FAILURE;
> +		}
> +		return 0;
>  	}
>  
> +
>  	fprintf(stderr, "unknown feature name '%s'\n", feature);
>  	return EXIT_FAILURE;
>  }
> @@ -270,13 +291,13 @@ 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	force_check_mountid = 0;
> +	bool	force_check_mountid = 0, connectable = 0;
>  	int	bufsz = MAX_HANDLE_SZ;
>  
>  	if (argc < 2)
>  		usage();
>  
> -	while ((c = getopt(argc, argv, "cC:ludmMrwapknhi:o:sz")) != -1) {
> +	while ((c = getopt(argc, argv, "cC:ludmMNrwapknhi:o:sz")) != -1) {
>  		switch (c) {
>  		case 'c':
>  			create = 1;
> @@ -313,6 +334,9 @@ int main(int argc, char **argv)
>  		case 'M':
>  			force_check_mountid = 1;
>  			break;
> +		case 'N':
> +			connectable = 1;
> +			break;
>  		case 'p':
>  			parent = 1;
>  			break;
> @@ -445,7 +469,8 @@ int main(int argc, char **argv)
>  				return EXIT_FAILURE;
>  			}
>  		} else {
> -			ret = do_name_to_handle_at(fname, &handle[i].fh, bufsz, force_check_mountid);
> +			ret = do_name_to_handle_at(fname, &handle[i].fh, bufsz,
> +						   force_check_mountid, connectable);
>  			if (ret)
>  				return EXIT_FAILURE;
>  		}
> @@ -475,7 +500,8 @@ int main(int argc, char **argv)
>  				return EXIT_FAILURE;
>  			}
>  		} else {
> -			ret = do_name_to_handle_at(test_dir, &dir_handle.fh, bufsz, force_check_mountid);
> +			ret = do_name_to_handle_at(test_dir, &dir_handle.fh, bufsz,
> +						   force_check_mountid, connectable);
>  			if (ret)
>  				return EXIT_FAILURE;
>  		}
> @@ -589,6 +615,15 @@ int main(int argc, char **argv)
>  		errno = 0;
>  		fd = open_by_handle_at(mount_fd, &handle[i].fh, wrafter ? O_RDWR : O_RDONLY);
>  		if ((nlink || keepopen) && fd >= 0) {
> +			char linkname[PATH_MAX];
> +			char procname[64];
> +			sprintf(procname, "/proc/self/fd/%i", fd);
> +			int n = readlink(procname, linkname, PATH_MAX);
> +
> +			/* check that fd is "connected" - that is has a non empty path */
> +			if (connectable && n <= 1) {
> +				printf("open_by_handle(%s) returned a disconnected fd!\n", fname);
> +			}
>  			if (rd) {
>  				char buf[4] = {0};
>  				int size = read(fd, buf, 4);
> -- 
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-05-25 10:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-09 17:00 [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
2025-05-09 17:00 ` [PATCH v2 1/2] open_by_handle: add support for testing connectable file handles Amir Goldstein
2025-05-25 10:49   ` Zorro Lang
2025-05-09 17:00 ` [PATCH v2 2/2] open_by_handle: add a test for " Amir Goldstein
2025-05-09 17:06   ` Amir Goldstein
2025-05-23 14:20 ` [PATCH v2 0/2] Tests for AT_HANDLE_CONNECTABLE Amir Goldstein
2025-05-23 14:50   ` Zorro Lang
2025-05-23 17:11     ` Amir Goldstein
2025-05-25  5:36       ` Zorro Lang
2025-05-25  7:40         ` Amir Goldstein

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).