diff mbox series

[1/2] xfs: test the xfs_db path command

Message ID 161647322430.3430916.12437291741320143904.stgit@magnolia (mailing list archive)
State New
Headers show
Series fstests: test xfs_db directory navigation | expand

Commit Message

Darrick J. Wong March 23, 2021, 4:20 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Add a new test to make sure the xfs_db path command works the way the
author thinks it should.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 tests/xfs/917     |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/917.out |   19 ++++++++++
 tests/xfs/group   |    1 +
 3 files changed, 118 insertions(+)
 create mode 100755 tests/xfs/917
 create mode 100644 tests/xfs/917.out

Comments

Chandan Babu R March 25, 2021, 9:33 a.m. UTC | #1
On 23 Mar 2021 at 09:50, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Add a new test to make sure the xfs_db path command works the way the
> author thinks it should.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  tests/xfs/917     |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/xfs/917.out |   19 ++++++++++
>  tests/xfs/group   |    1 +
>  3 files changed, 118 insertions(+)
>  create mode 100755 tests/xfs/917
>  create mode 100644 tests/xfs/917.out
>
>
> diff --git a/tests/xfs/917 b/tests/xfs/917
> new file mode 100755
> index 00000000..bf21b290
> --- /dev/null
> +++ b/tests/xfs/917
> @@ -0,0 +1,98 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2021 Oracle.  All Rights Reserved.
> +#
> +# FS QA Test No. 917
> +#
> +# Make sure the xfs_db path command works the way the author thinks it does.
> +# This means that it can navigate to random inodes, fails on paths that don't
> +# resolve.
> +#
> +seq=`basename $0`
> +seqres=$RESULT_DIR/$seq
> +echo "QA output created by $seq"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1    # failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +
> +# real QA test starts here
> +_supported_fs xfs
> +_require_xfs_db_command "path"
> +_require_scratch
> +
> +echo "Format filesystem and populate"
> +_scratch_mkfs > $seqres.full
> +_scratch_mount >> $seqres.full
> +
> +mkdir $SCRATCH_MNT/a
> +mkdir $SCRATCH_MNT/a/b
> +$XFS_IO_PROG -f -c 'pwrite 0 61' $SCRATCH_MNT/a/c >> $seqres.full
> +ln -s -f c $SCRATCH_MNT/a/d
> +mknod $SCRATCH_MNT/a/e b 8 0
> +ln -s -f b $SCRATCH_MNT/a/f

Later in the test script, there are two checks corresponding to accessibility
of file symlink and dir symlink. However, $SCRATCH_MNT/a/d and
$SCRATCH_MNT/a/f are actually referring to non-existant files since current
working directory at the time of invocation of ln command is the xfstests
directory.

i.e. 'c' and 'b' arguments to 'ln' command above must be qualified with
$SCRATCH_MNT/a/.

> +
> +_scratch_unmount
> +
> +echo "Check xfs_db path on directories"
> +_scratch_xfs_db -c 'path /a' -c print | grep -q 'sfdir.*count.* 5$' || \
> +	echo "Did not find directory /a"
> +
> +_scratch_xfs_db -c 'path /a/b' -c print | grep -q sfdir || \
> +	echo "Did not find empty sf directory /a/b"
> +
> +echo "Check xfs_db path on files"
> +_scratch_xfs_db -c 'path /a/c' -c print | grep -q 'core.size.*61' || \
> +	echo "Did not find 61-byte file /a/c"
> +
> +echo "Check xfs_db path on file symlinks"
> +_scratch_xfs_db -c 'path /a/d' -c print | grep -q symlink || \
> +	echo "Did not find symlink /a/d"
> +
> +echo "Check xfs_db path on bdevs"
> +_scratch_xfs_db -c 'path /a/e' -c print | grep -q 'format.*dev' || \
> +	echo "Did not find bdev /a/e"
> +
> +echo "Check xfs_db path on dir symlinks"
> +_scratch_xfs_db -c 'path /a/f' -c print | grep -q symlink || \
> +	echo "Did not find symlink /a/f"

--
chandan
Darrick J. Wong March 25, 2021, 4:33 p.m. UTC | #2
On Thu, Mar 25, 2021 at 03:03:14PM +0530, Chandan Babu R wrote:
> On 23 Mar 2021 at 09:50, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > Add a new test to make sure the xfs_db path command works the way the
> > author thinks it should.
> >
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> >  tests/xfs/917     |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  tests/xfs/917.out |   19 ++++++++++
> >  tests/xfs/group   |    1 +
> >  3 files changed, 118 insertions(+)
> >  create mode 100755 tests/xfs/917
> >  create mode 100644 tests/xfs/917.out
> >
> >
> > diff --git a/tests/xfs/917 b/tests/xfs/917
> > new file mode 100755
> > index 00000000..bf21b290
> > --- /dev/null
> > +++ b/tests/xfs/917
> > @@ -0,0 +1,98 @@
> > +#! /bin/bash
> > +# SPDX-License-Identifier: GPL-2.0-or-later
> > +# Copyright (c) 2021 Oracle.  All Rights Reserved.
> > +#
> > +# FS QA Test No. 917
> > +#
> > +# Make sure the xfs_db path command works the way the author thinks it does.
> > +# This means that it can navigate to random inodes, fails on paths that don't
> > +# resolve.
> > +#
> > +seq=`basename $0`
> > +seqres=$RESULT_DIR/$seq
> > +echo "QA output created by $seq"
> > +
> > +here=`pwd`
> > +tmp=/tmp/$$
> > +status=1    # failure is the default!
> > +trap "_cleanup; exit \$status" 0 1 2 3 15
> > +
> > +_cleanup()
> > +{
> > +	cd /
> > +	rm -f $tmp.*
> > +}
> > +
> > +# get standard environment, filters and checks
> > +. ./common/rc
> > +. ./common/filter
> > +
> > +# real QA test starts here
> > +_supported_fs xfs
> > +_require_xfs_db_command "path"
> > +_require_scratch
> > +
> > +echo "Format filesystem and populate"
> > +_scratch_mkfs > $seqres.full
> > +_scratch_mount >> $seqres.full
> > +
> > +mkdir $SCRATCH_MNT/a
> > +mkdir $SCRATCH_MNT/a/b
> > +$XFS_IO_PROG -f -c 'pwrite 0 61' $SCRATCH_MNT/a/c >> $seqres.full
> > +ln -s -f c $SCRATCH_MNT/a/d
> > +mknod $SCRATCH_MNT/a/e b 8 0
> > +ln -s -f b $SCRATCH_MNT/a/f
> 
> Later in the test script, there are two checks corresponding to accessibility
> of file symlink and dir symlink. However, $SCRATCH_MNT/a/d and
> $SCRATCH_MNT/a/f are actually referring to non-existant files since current
> working directory at the time of invocation of ln command is the xfstests
> directory.
> 
> i.e. 'c' and 'b' arguments to 'ln' command above must be qualified with
> $SCRATCH_MNT/a/.

Hm?  d and f look fine to me:

$ ./check xfs/917
$ mount /dev/sdf /opt
$ cd /opt/a
$ ls
total 4
drwxr-xr-x 2 root root    6 Mar 25 09:25 b/
-rw------- 1 root root   61 Mar 25 09:25 c
lrwxrwxrwx 1 root root    1 Mar 25 09:25 d -> c
brw-r--r-- 1 root root 8, 0 Mar 25 09:25 e
lrwxrwxrwx 1 root root    1 Mar 25 09:25 f -> b/

The link target is copied verbatim into the symlink, so I don't see why
they need to be qualified?

(FWIW the path command doesn't resolve symlinks, so it really only
checks that /a/d and /a/f exist and are of type symlink.)

--D

> 
> > +
> > +_scratch_unmount
> > +
> > +echo "Check xfs_db path on directories"
> > +_scratch_xfs_db -c 'path /a' -c print | grep -q 'sfdir.*count.* 5$' || \
> > +	echo "Did not find directory /a"
> > +
> > +_scratch_xfs_db -c 'path /a/b' -c print | grep -q sfdir || \
> > +	echo "Did not find empty sf directory /a/b"
> > +
> > +echo "Check xfs_db path on files"
> > +_scratch_xfs_db -c 'path /a/c' -c print | grep -q 'core.size.*61' || \
> > +	echo "Did not find 61-byte file /a/c"
> > +
> > +echo "Check xfs_db path on file symlinks"
> > +_scratch_xfs_db -c 'path /a/d' -c print | grep -q symlink || \
> > +	echo "Did not find symlink /a/d"
> > +
> > +echo "Check xfs_db path on bdevs"
> > +_scratch_xfs_db -c 'path /a/e' -c print | grep -q 'format.*dev' || \
> > +	echo "Did not find bdev /a/e"
> > +
> > +echo "Check xfs_db path on dir symlinks"
> > +_scratch_xfs_db -c 'path /a/f' -c print | grep -q symlink || \
> > +	echo "Did not find symlink /a/f"
> 
> --
> chandan
Chandan Babu R March 26, 2021, 3:31 a.m. UTC | #3
On 25 Mar 2021 at 22:03, Darrick J. Wong wrote:
> On Thu, Mar 25, 2021 at 03:03:14PM +0530, Chandan Babu R wrote:
>> On 23 Mar 2021 at 09:50, Darrick J. Wong wrote:
>> > From: Darrick J. Wong <djwong@kernel.org>
>> >
>> > Add a new test to make sure the xfs_db path command works the way the
>> > author thinks it should.
>> >
>> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
>> > ---
>> >  tests/xfs/917     |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >  tests/xfs/917.out |   19 ++++++++++
>> >  tests/xfs/group   |    1 +
>> >  3 files changed, 118 insertions(+)
>> >  create mode 100755 tests/xfs/917
>> >  create mode 100644 tests/xfs/917.out
>> >
>> >
>> > diff --git a/tests/xfs/917 b/tests/xfs/917
>> > new file mode 100755
>> > index 00000000..bf21b290
>> > --- /dev/null
>> > +++ b/tests/xfs/917
>> > @@ -0,0 +1,98 @@
>> > +#! /bin/bash
>> > +# SPDX-License-Identifier: GPL-2.0-or-later
>> > +# Copyright (c) 2021 Oracle.  All Rights Reserved.
>> > +#
>> > +# FS QA Test No. 917
>> > +#
>> > +# Make sure the xfs_db path command works the way the author thinks it does.
>> > +# This means that it can navigate to random inodes, fails on paths that don't
>> > +# resolve.
>> > +#
>> > +seq=`basename $0`
>> > +seqres=$RESULT_DIR/$seq
>> > +echo "QA output created by $seq"
>> > +
>> > +here=`pwd`
>> > +tmp=/tmp/$$
>> > +status=1    # failure is the default!
>> > +trap "_cleanup; exit \$status" 0 1 2 3 15
>> > +
>> > +_cleanup()
>> > +{
>> > +	cd /
>> > +	rm -f $tmp.*
>> > +}
>> > +
>> > +# get standard environment, filters and checks
>> > +. ./common/rc
>> > +. ./common/filter
>> > +
>> > +# real QA test starts here
>> > +_supported_fs xfs
>> > +_require_xfs_db_command "path"
>> > +_require_scratch
>> > +
>> > +echo "Format filesystem and populate"
>> > +_scratch_mkfs > $seqres.full
>> > +_scratch_mount >> $seqres.full
>> > +
>> > +mkdir $SCRATCH_MNT/a
>> > +mkdir $SCRATCH_MNT/a/b
>> > +$XFS_IO_PROG -f -c 'pwrite 0 61' $SCRATCH_MNT/a/c >> $seqres.full
>> > +ln -s -f c $SCRATCH_MNT/a/d
>> > +mknod $SCRATCH_MNT/a/e b 8 0
>> > +ln -s -f b $SCRATCH_MNT/a/f
>> 
>> Later in the test script, there are two checks corresponding to accessibility
>> of file symlink and dir symlink. However, $SCRATCH_MNT/a/d and
>> $SCRATCH_MNT/a/f are actually referring to non-existant files since current
>> working directory at the time of invocation of ln command is the xfstests
>> directory.
>> 
>> i.e. 'c' and 'b' arguments to 'ln' command above must be qualified with
>> $SCRATCH_MNT/a/.
>
> Hm?  d and f look fine to me:
>
> $ ./check xfs/917
> $ mount /dev/sdf /opt
> $ cd /opt/a
> $ ls
> total 4
> drwxr-xr-x 2 root root    6 Mar 25 09:25 b/
> -rw------- 1 root root   61 Mar 25 09:25 c
> lrwxrwxrwx 1 root root    1 Mar 25 09:25 d -> c
> brw-r--r-- 1 root root 8, 0 Mar 25 09:25 e
> lrwxrwxrwx 1 root root    1 Mar 25 09:25 f -> b/
>
> The link target is copied verbatim into the symlink, so I don't see why
> they need to be qualified?
>
> (FWIW the path command doesn't resolve symlinks, so it really only
> checks that /a/d and /a/f exist and are of type symlink.)

Sorry, I got confused. The patch looks good to me.

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
diff mbox series

Patch

diff --git a/tests/xfs/917 b/tests/xfs/917
new file mode 100755
index 00000000..bf21b290
--- /dev/null
+++ b/tests/xfs/917
@@ -0,0 +1,98 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 917
+#
+# Make sure the xfs_db path command works the way the author thinks it does.
+# This means that it can navigate to random inodes, fails on paths that don't
+# resolve.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs xfs
+_require_xfs_db_command "path"
+_require_scratch
+
+echo "Format filesystem and populate"
+_scratch_mkfs > $seqres.full
+_scratch_mount >> $seqres.full
+
+mkdir $SCRATCH_MNT/a
+mkdir $SCRATCH_MNT/a/b
+$XFS_IO_PROG -f -c 'pwrite 0 61' $SCRATCH_MNT/a/c >> $seqres.full
+ln -s -f c $SCRATCH_MNT/a/d
+mknod $SCRATCH_MNT/a/e b 8 0
+ln -s -f b $SCRATCH_MNT/a/f
+
+_scratch_unmount
+
+echo "Check xfs_db path on directories"
+_scratch_xfs_db -c 'path /a' -c print | grep -q 'sfdir.*count.* 5$' || \
+	echo "Did not find directory /a"
+
+_scratch_xfs_db -c 'path /a/b' -c print | grep -q sfdir || \
+	echo "Did not find empty sf directory /a/b"
+
+echo "Check xfs_db path on files"
+_scratch_xfs_db -c 'path /a/c' -c print | grep -q 'core.size.*61' || \
+	echo "Did not find 61-byte file /a/c"
+
+echo "Check xfs_db path on file symlinks"
+_scratch_xfs_db -c 'path /a/d' -c print | grep -q symlink || \
+	echo "Did not find symlink /a/d"
+
+echo "Check xfs_db path on bdevs"
+_scratch_xfs_db -c 'path /a/e' -c print | grep -q 'format.*dev' || \
+	echo "Did not find bdev /a/e"
+
+echo "Check xfs_db path on dir symlinks"
+_scratch_xfs_db -c 'path /a/f' -c print | grep -q symlink || \
+	echo "Did not find symlink /a/f"
+
+echo "Check nonexistent path"
+_scratch_xfs_db -c 'path /does/not/exist'
+
+echo "Check xfs_db path on file path with multiple slashes"
+_scratch_xfs_db -c 'path /a////////c' -c print | grep -q 'core.size.*61' || \
+	echo "Did not find 61-byte file /a////////c"
+
+echo "Check xfs_db path on file path going in and out of /a to get to /a/c"
+_scratch_xfs_db -c 'path /a/.././a/.././a/c' -c print | grep -q 'core.size.*61' || \
+	echo "Did not find 61-byte file /a/.././a/.././a/c"
+
+echo "Check xfs_db path on file path going above the root to get to /a/c"
+_scratch_xfs_db -c 'path /../../../a/c' -c print | grep -q 'core.size.*61' || \
+	echo "Did not find 61-byte file  /../../../a/c"
+
+echo "Check xfs_db path on file path going to then above the root to get to /a/c"
+_scratch_xfs_db -c 'path /a/../../../a/c' -c print | grep -q 'core.size.*61' || \
+	echo "Did not find 61-byte file  /a/../../../a/c"
+
+echo "Check xfs_db path component that isn't a directory"
+_scratch_xfs_db -c 'path /a/c/b' -c print
+
+echo "Check xfs_db path on a dot-dot applied to a non-directory"
+_scratch_xfs_db -c 'path /a/c/../b' -c print
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/917.out b/tests/xfs/917.out
new file mode 100644
index 00000000..7c613c3d
--- /dev/null
+++ b/tests/xfs/917.out
@@ -0,0 +1,19 @@ 
+QA output created by 917
+Format filesystem and populate
+Check xfs_db path on directories
+Check xfs_db path on files
+Check xfs_db path on file symlinks
+Check xfs_db path on bdevs
+Check xfs_db path on dir symlinks
+Check nonexistent path
+/does/not/exist: No such file or directory
+Check xfs_db path on file path with multiple slashes
+Check xfs_db path on file path going in and out of /a to get to /a/c
+Check xfs_db path on file path going above the root to get to /a/c
+Check xfs_db path on file path going to then above the root to get to /a/c
+Check xfs_db path component that isn't a directory
+/a/c/b: Not a directory
+no current type
+Check xfs_db path on a dot-dot applied to a non-directory
+/a/c/../b: Not a directory
+no current type
diff --git a/tests/xfs/group b/tests/xfs/group
index eebe7dde..daa56787 100644
--- a/tests/xfs/group
+++ b/tests/xfs/group
@@ -517,3 +517,4 @@ 
 538 auto stress
 759 auto quick rw realtime
 760 auto quick rw realtime collapse insert unshare zero prealloc
+917 auto quick db