generic/755: test that inode's ctime is updated on unlink
Subsystems (2)
PATCH 1/1 generic/755: test that inode's ctime is updated on unlink
---
HCH suggested I roll a fstest for this problem that I found in btrfs the other day. In principle, we probably could expand this to other dir operations and to check the parent timestamps, but having to do all that in C is a pain. I didn't see a good way to use xfs_io for this, however.
--- src/Makefile | 2 +- src/unlink-ctime.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/755 | 26 ++++++++++++++++++++++++++ tests/generic/755.out | 2 ++ 4 files changed, 79 insertions(+), 1 deletion(-)
src/Makefile +1 -1
@@ -34,7 +34,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \ - uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault + uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault unlink-ctime EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py popdir.pl popattr.py \
src/unlink-ctime.c new file +50 -0
50 lines not on this page · raw message
tests/generic/755 new file +26 -0
@@ -0,0 +1,26 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024, Jeff Layton <[email protected]> +# +# FS QA Test No. 755 +# +# Create a file, stat it and then unlink it. Does the ctime of the +# target inode change? +# +. ./common/preamble +_begin_fstest auto quick + +# Import common functions. +. ./common/filter +. ./common/dmerror + +_require_test +_require_test_program unlink-ctime + +testfile="$TEST_DIR/unlink-ctime.$$" + +$here/src/unlink-ctime $testfile + +echo Silence is golden +status=0 +exit
tests/generic/755.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 755 +Silence is golden
---
base-commit: f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bd
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
On Tue, Aug 13, 2024 at 02:21:08PM -0400, Jeff Layton wrote:
Hi Jeff :)
Any description about this case test for?
Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>---
HCH suggested I roll a fstest for this problem that I found in btrfs the other day. In principle, we probably could expand this to other dir operations and to check the parent timestamps, but having to do all that in C is a pain. I didn't see a good way to usexfs_iofor this, however.
Is there a kernel commit or patch link about the bug which you found?
Quoted 12 lines
--- src/Makefile | 2 +- src/unlink-ctime.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/755 | 26 ++++++++++++++++++++++++++ tests/generic/755.out | 2 ++ 4 files changed, 79 insertions(+), 1 deletion(-)src/Makefile +0
-0
src/Makefile LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ · line 37
Quoted 5 lines
src/Makefile +1
-1@@ -34,7 +34,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \ - uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault + uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault unlink-ctime
The .gitignore need updating too.
Quoted 37 lines
src/Makefile +0
-0EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py popdir.pl popattr.py \src/unlink-ctime.c new file +28
-0@@ -0,0 +1,50 @@ +#define _GNU_SOURCE 1 +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <sys/stat.h> + +int main (int argc,char **argv) +{ +int fd, ret; +struct statx before, after; + +if (argc <2 ) { +fprintf (stderr,"Must specify filename!\n" ); +return 1 ; + } + + fd =open (argv[1 ],O_RDWR |O_CREAT ,0600 ); +if (fd <0 ) { +perror ("open" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &before); +if (ret) { +perror ("statx" ); +return 1 ; + }
src/unlink-ctime.c line 38
Quoted 10 lines
src/unlink-ctime.c new file +10
-0+ +sleep (1 ); + + ret =unlink (argv[1 ]); +if (ret) { +perror ("unlink" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &after);
So you need to keep the "fd" after unlink. If so, there might not be a way through xfs_io to do that.
Quoted 19 lines
src/unlink-ctime.c new file +12
-0+if (ret) { +perror ("statx" ); +return 1 ; + } + +if (before.stx_ctime.tv_nsec == after.stx_ctime.tv_nsec && + before.stx_ctime.tv_sec == after.stx_ctime.tv_sec) { +printf ("No change to ctime after unlink!\n" ); +return 1 ; + } +return 0 ; +}tests/generic/755 new file +1
-0@@ -0,0 +1,26 @@ +#! /bin/bash
tests/generic/755 line 11
Quoted 10 lines
tests/generic/755 new file +10
-0+# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024, Jeff Layton <[email protected]> +# +# FS QA Test No. 755 +# +# Create a file, stat it and then unlink it. Does the ctime of the +# target inode change? +# +. ./common/preamble +_begin_fstest auto quick
^^^^^^
unlinktests/generic/755 line 15
Quoted 4 lines
tests/generic/755 new file +4
-0+ +# Import common functions. +. ./common/filter +. ./common/dmerror
Why dmerror and filter are needed? If not necessary, remove these 3 lines.
Others looks good to me.
Thanks,
Zorro
Quoted 29 lines
tests/generic/755 new file +11
-0+ +_require_test +_require_test_program unlink-ctime + +testfile="$TEST_DIR/unlink-ctime.$$" + +$here/src/unlink-ctime $testfile + +echo Silence is golden +status=0 +exittests/generic/755.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 755 +Silence is golden ---base-commit:
f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bdBest regards,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 6 lines · Zorro Lang
On Tue, Aug 13, 2024 at 02:21:08PM -0400, Jeff Layton wrote:
Hi Jeff :)
Any description about this case test for?
Yes. I should have put that info in the commit. Can you add it if the patch otherwise looks OK?
https://lore.kernel.org/linux-btrfs/[email protected]/
Thanks,
Quoted 156 lines
Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>---
HCH suggested I roll a fstest for this problem that I found in btrfs the other day. In principle, we probably could expand this to other dir operations and to check the parent timestamps, but having to do all that in C is a pain. I didn't see a good way to usexfs_iofor this, however.Is there a kernel commit or patch link about the bug which you found?
Quoted 12 lines
--- src/Makefile | 2 +- src/unlink-ctime.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/755 | 26 ++++++++++++++++++++++++++ tests/generic/755.out | 2 ++ 4 files changed, 79 insertions(+), 1 deletion(-)src/Makefile +0
-0src/Makefile LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ · line 37
Quoted 5 lines
src/Makefile +1
-1@@ -34,7 +34,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \ - uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault + uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault unlink-ctimeThe .gitignore need updating too.
Quoted 37 lines
src/Makefile +0
-0EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py popdir.pl popattr.py \src/unlink-ctime.c new file +28
-0@@ -0,0 +1,50 @@ +#define _GNU_SOURCE 1 +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <sys/stat.h> + +int main (int argc,char **argv) +{ +int fd, ret; +struct statx before, after; + +if (argc <2 ) { +fprintf (stderr,"Must specify filename!\n" ); +return 1 ; + } + + fd =open (argv[1 ],O_RDWR |O_CREAT ,0600 ); +if (fd <0 ) { +perror ("open" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &before); +if (ret) { +perror ("statx" ); +return 1 ; + }src/unlink-ctime.c line 38
Quoted 10 lines
src/unlink-ctime.c new file +10
-0+ +sleep (1 ); + + ret =unlink (argv[1 ]); +if (ret) { +perror ("unlink" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &after);So you need to keep the "fd" after unlink. If so, there might not be a way through
xfs_ioto do that.Quoted 19 lines
src/unlink-ctime.c new file +12
-0+if (ret) { +perror ("statx" ); +return 1 ; + } + +if (before.stx_ctime.tv_nsec == after.stx_ctime.tv_nsec && + before.stx_ctime.tv_sec == after.stx_ctime.tv_sec) { +printf ("No change to ctime after unlink!\n" ); +return 1 ; + } +return 0 ; +}tests/generic/755 new file +1
-0@@ -0,0 +1,26 @@ +#! /bin/bashtests/generic/755 line 11
Quoted 10 lines
tests/generic/755 new file +10
-0+# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024, Jeff Layton <[email protected]> +# +# FS QA Test No. 755 +# +# Create a file, stat it and then unlink it. Does the ctime of the +# target inode change? +# +. ./common/preamble +_begin_fstest auto quick^^^^^^ unlinktests/generic/755 line 15
Quoted 4 lines
tests/generic/755 new file +4
-0+ +# Import common functions. +. ./common/filter +. ./common/dmerrorWhy dmerror and filter are needed? If not necessary, remove these 3 lines.
Others looks good to me.
Thanks,
ZorroQuoted 29 lines
tests/generic/755 new file +11
-0+ +_require_test +_require_test_program unlink-ctime + +testfile="$TEST_DIR/unlink-ctime.$$" + +$here/src/unlink-ctime $testfile + +echo Silence is golden +status=0 +exittests/generic/755.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 755 +Silence is golden ---base-commit:
f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bdBest regards,
Signature · 1 line
Jeff Layton <[email protected]>
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Zorro Lang
On Tue, Aug 13, 2024 at 02:21:08PM -0400, Jeff Layton wrote:
Hi Jeff :)
Quoted 7 lines
Quoted 2 lines
Any description about this case test for?
Yes. I should have put that info in the commit. Can you add it if the patch otherwise looks OK?
https://lore.kernel.org/linux-btrfs/[email protected]/
Hi Jeff,
I saw this patch has gotten 3 RVBs, it's going to be in btrfs tree. I think it's good enough. BTW, you can add "_fixed_by_kernel_commit" to the test case, see below tests/generic/755 ...
By reading above link, I think this issue doesn't need a C program (to reproduce), it can be done in bash script. e.g.
# touch file # link file linkfile # ctime1=$(stat -c %Z file) # sleep 2 # ctime2=$(stat -c %Z file) # if [ "$ctime1" == "$ctime2" ];then ....
Does that make sense to you?
Quoted 32 lines
Thanks,
Quoted 29 lines
Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>---
HCH suggested I roll a fstest for this problem that I found in btrfs the other day. In principle, we probably could expand this to other dir operations and to check the parent timestamps, but having to do all that in C is a pain. I didn't see a good way to usexfs_iofor this, however.Is there a kernel commit or patch link about the bug which you found?
Quoted 12 lines
--- src/Makefile | 2 +- src/unlink-ctime.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/755 | 26 ++++++++++++++++++++++++++ tests/generic/755.out | 2 ++ 4 files changed, 79 insertions(+), 1 deletion(-)src/Makefile +0
-0src/Makefile LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ · line 37
Quoted 5 lines
src/Makefile +1
-1@@ -34,7 +34,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \ - uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault + uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault unlink-ctimeThe .gitignore need updating too.
[need changing]
Quoted 75 lines
Quoted 75 lines
Quoted 38 lines
src/Makefile +0
-0EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py popdir.pl popattr.py \src/unlink-ctime.c new file +28
-0@@ -0,0 +1,50 @@ +#define _GNU_SOURCE 1 +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <sys/stat.h> + +int main (int argc,char **argv) +{ +int fd, ret; +struct statx before, after; + +if (argc <2 ) { +fprintf (stderr,"Must specify filename!\n" ); +return 1 ; + } + + fd =open (argv[1 ],O_RDWR |O_CREAT ,0600 ); +if (fd <0 ) { +perror ("open" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &before); +if (ret) { +perror ("statx" ); +return 1 ; + }src/unlink-ctime.c line 38
Quoted 10 lines
src/unlink-ctime.c new file +10
-0+ +sleep (1 ); + + ret =unlink (argv[1 ]); +if (ret) { +perror ("unlink" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &after);So you need to keep the "fd" after unlink. If so, there might not be a way through
xfs_ioto do that.Quoted 23 lines
src/unlink-ctime.c new file +12
-0+if (ret) { +perror ("statx" ); +return 1 ; + } + +if (before.stx_ctime.tv_nsec == after.stx_ctime.tv_nsec && + before.stx_ctime.tv_sec == after.stx_ctime.tv_sec) { +printf ("No change to ctime after unlink!\n" ); +return 1 ; + } +return 0 ; +}tests/generic/755 new file +5
-0@@ -0,0 +1,26 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024, Jeff Layton <[email protected]> +# +# FS QA Test No. 755
Quoted 8 lines
Quoted 8 lines
tests/generic/755 line 11
Quoted 6 lines
tests/generic/755 new file +6
-0+# +# Create a file, stat it and then unlink it. Does the ctime of the +# target inode change? +# +. ./common/preamble +_begin_fstest auto quick^^^^^^ unlink
[need changing]
Quoted 8 lines
Quoted 8 lines
tests/generic/755 line 15
Quoted 5 lines
tests/generic/755 new file +4
-0+ +# Import common functions. +. ./common/filter +. ./common/dmerrorWhy dmerror and filter are needed? If not necessary, remove these 3 lines.
[need changing]
Quoted 9 lines
Quoted 9 lines
Others looks good to me.
Thanks,
Zorrotests/generic/755 line 18
Quoted 3 lines
tests/generic/755 new file +3
-0+ +_require_test +_require_test_program unlink-ctime
_fixed_by_kernel_commit XXXXXXXXXXXX btrfs: update target inode's ctime on unlink
Quoted 31 lines
Quoted 27 lines
Quoted 26 lines
tests/generic/755 new file +8
-0+ +testfile="$TEST_DIR/unlink-ctime.$$" + +$here/src/unlink-ctime $testfile + +echo Silence is golden +status=0 +exittests/generic/755.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 755 +Silence is golden ---base-commit:
f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bdBest regards,
Signature · 1 line
Jeff Layton <[email protected]>Signature · 1 line
Jeff Layton <[email protected]>
Quoted 23 lines · Zorro Lang
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Zorro Lang
On Tue, Aug 13, 2024 at 02:21:08PM -0400, Jeff Layton wrote:
Hi Jeff :)
Quoted 7 lines
Quoted 2 lines
Any description about this case test for?
Yes. I should have put that info in the commit. Can you add it if the patch otherwise looks OK?
https://lore.kernel.org/linux-btrfs/[email protected]/Hi Jeff,
I saw this patch has gotten 3 RVBs, it's going to be in btrfs tree. I think it's good enough. BTW, you can add "
_fixed_by_kernel_commit" to the test case, see below tests/generic/755 ...By reading above link, I think this issue doesn't need a C program (to reproduce), it can be done in bash script. e.g.
Quoted 9 lines
# touch file # link file linkfile # ctime1=$(stat -c %Z file) # sleep 2 # ctime2=$(stat -c %Z file) # if [ "$ctime1" == "$ctime2" ];then ....Does that make sense to you?
It does. I was trying to replicate the original report which showed that we didn't update the ctime when unlinking the last dentry on an inode, but this should replicate the btrfs bug just as well.
I'm fine with going this route if it's what you'd prefer. Let me know.
Quoted 176 lines
Quoted 32 lines
Thanks,
Quoted 29 lines
Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>---
HCH suggested I roll a fstest for this problem that I found in btrfs the other day. In principle, we probably could expand this to other dir operations and to check the parent timestamps, but having to do all that in C is a pain. I didn't see a good way to usexfs_iofor this, however.Is there a kernel commit or patch link about the bug which you found?
Quoted 12 lines
--- src/Makefile | 2 +- src/unlink-ctime.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/755 | 26 ++++++++++++++++++++++++++ tests/generic/755.out | 2 ++ 4 files changed, 79 insertions(+), 1 deletion(-)src/Makefile +0
-0src/Makefile LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ · line 37
Quoted 5 lines
src/Makefile +1
-1@@ -34,7 +34,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \ - uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault + uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault unlink-ctimeThe .gitignore need updating too.
[need changing]
Quoted 75 lines
Quoted 75 lines
Quoted 38 lines
src/Makefile +0
-0EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py popdir.pl popattr.py \src/unlink-ctime.c new file +28
-0@@ -0,0 +1,50 @@ +#define _GNU_SOURCE 1 +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <sys/stat.h> + +int main (int argc,char **argv) +{ +int fd, ret; +struct statx before, after; + +if (argc <2 ) { +fprintf (stderr,"Must specify filename!\n" ); +return 1 ; + } + + fd =open (argv[1 ],O_RDWR |O_CREAT ,0600 ); +if (fd <0 ) { +perror ("open" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &before); +if (ret) { +perror ("statx" ); +return 1 ; + }src/unlink-ctime.c line 38
Quoted 10 lines
src/unlink-ctime.c new file +10
-0+ +sleep (1 ); + + ret =unlink (argv[1 ]); +if (ret) { +perror ("unlink" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &after);So you need to keep the "fd" after unlink. If so, there might not be a way through
xfs_ioto do that.Quoted 23 lines
src/unlink-ctime.c new file +12
-0+if (ret) { +perror ("statx" ); +return 1 ; + } + +if (before.stx_ctime.tv_nsec == after.stx_ctime.tv_nsec && + before.stx_ctime.tv_sec == after.stx_ctime.tv_sec) { +printf ("No change to ctime after unlink!\n" ); +return 1 ; + } +return 0 ; +}tests/generic/755 new file +5
-0@@ -0,0 +1,26 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024, Jeff Layton <[email protected]> +# +# FS QA Test No. 755Quoted 8 lines
Quoted 8 lines
tests/generic/755 line 11
Quoted 6 lines
tests/generic/755 new file +6
-0+# +# Create a file, stat it and then unlink it. Does the ctime of the +# target inode change? +# +. ./common/preamble +_begin_fstest auto quick^^^^^^ unlink[need changing]
Quoted 8 lines
Quoted 8 lines
tests/generic/755 line 15
Quoted 5 lines
tests/generic/755 new file +4
-0+ +# Import common functions. +. ./common/filter +. ./common/dmerrorWhy dmerror and filter are needed? If not necessary, remove these 3 lines.
[need changing]
Quoted 9 lines
Quoted 9 lines
Others looks good to me.
Thanks,
Zorrotests/generic/755 line 18
Quoted 3 lines
tests/generic/755 new file +3
-0+ +_require_test +_require_test_program unlink-ctime
_fixed_by_kernel_commitXXXXXXXXXXXX btrfs: update target inode's ctime on unlinkQuoted 31 lines
Quoted 27 lines
Quoted 26 lines
tests/generic/755 new file +8
-0+ +testfile="$TEST_DIR/unlink-ctime.$$" + +$here/src/unlink-ctime $testfile + +echo Silence is golden +status=0 +exittests/generic/755.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 755 +Silence is golden ---base-commit:
f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bdBest regards,
Signature · 1 line
Jeff Layton <[email protected]>Signature · 1 line
Jeff Layton <[email protected]>
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 31 lines · Jeff Layton
Quoted 30 lines · Zorro Lang
Quoted 5 lines · Jeff Layton
Quoted 4 lines · Zorro Lang
On Tue, Aug 13, 2024 at 02:21:08PM -0400, Jeff Layton wrote:
Hi Jeff :)
Quoted 7 lines
Quoted 2 lines
Any description about this case test for?
Yes. I should have put that info in the commit. Can you add it if the patch otherwise looks OK?
https://lore.kernel.org/linux-btrfs/[email protected]/Hi Jeff,
I saw this patch has gotten 3 RVBs, it's going to be in btrfs tree. I think it's good enough. BTW, you can add "
_fixed_by_kernel_commit" to the test case, see below tests/generic/755 ...By reading above link, I think this issue doesn't need a C program (to reproduce), it can be done in bash script. e.g.
# touch file # link file linkfile # ctime1=$(stat -c %Z file) # sleep 2 # ctime2=$(stat -c %Z file) # if [ "$ctime1" == "$ctime2" ];then ....
Quoted 8 lines
Quoted 2 lines
Does that make sense to you?
It does. I was trying to replicate the original report which showed that we didn't update the ctime when unlinking the last dentry on an inode, but this should replicate the btrfs bug just as well.
I'm fine with going this route if it's what you'd prefer. Let me know.
Thanks! If it can be a pure bash script test case, that would be better. I tried my above test steps, it can reproduce this bug too.
Thanks,
Zorro
Quoted 181 lines
Quoted 177 lines
Quoted 33 lines
Thanks,
Quoted 29 lines
Quoted 7 lines
Signed-off-by Jeff Layton <[email protected]>---
HCH suggested I roll a fstest for this problem that I found in btrfs the other day. In principle, we probably could expand this to other dir operations and to check the parent timestamps, but having to do all that in C is a pain. I didn't see a good way to usexfs_iofor this, however.Is there a kernel commit or patch link about the bug which you found?
Quoted 12 lines
--- src/Makefile | 2 +- src/unlink-ctime.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/755 | 26 ++++++++++++++++++++++++++ tests/generic/755.out | 2 ++ 4 files changed, 79 insertions(+), 1 deletion(-)src/Makefile +0
-0src/Makefile LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ · line 37
Quoted 5 lines
src/Makefile +1
-1@@ -34,7 +34,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \ - uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault + uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault unlink-ctimeThe .gitignore need updating too.
[need changing]
Quoted 75 lines
Quoted 75 lines
Quoted 38 lines
src/Makefile +0
-0EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py popdir.pl popattr.py \src/unlink-ctime.c new file +28
-0@@ -0,0 +1,50 @@ +#define _GNU_SOURCE 1 +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <sys/stat.h> + +int main (int argc,char **argv) +{ +int fd, ret; +struct statx before, after; + +if (argc <2 ) { +fprintf (stderr,"Must specify filename!\n" ); +return 1 ; + } + + fd =open (argv[1 ],O_RDWR |O_CREAT ,0600 ); +if (fd <0 ) { +perror ("open" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &before); +if (ret) { +perror ("statx" ); +return 1 ; + }src/unlink-ctime.c line 38
Quoted 10 lines
src/unlink-ctime.c new file +10
-0+ +sleep (1 ); + + ret =unlink (argv[1 ]); +if (ret) { +perror ("unlink" ); +return 1 ; + } + + ret =statx (fd,"" ,AT_EMPTY_PATH ,STATX_CTIME , &after);So you need to keep the "fd" after unlink. If so, there might not be a way through
xfs_ioto do that.Quoted 23 lines
src/unlink-ctime.c new file +12
-0+if (ret) { +perror ("statx" ); +return 1 ; + } + +if (before.stx_ctime.tv_nsec == after.stx_ctime.tv_nsec && + before.stx_ctime.tv_sec == after.stx_ctime.tv_sec) { +printf ("No change to ctime after unlink!\n" ); +return 1 ; + } +return 0 ; +}tests/generic/755 new file +5
-0@@ -0,0 +1,26 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024, Jeff Layton <[email protected]> +# +# FS QA Test No. 755Quoted 8 lines
Quoted 8 lines
tests/generic/755 line 11
Quoted 6 lines
tests/generic/755 new file +6
-0+# +# Create a file, stat it and then unlink it. Does the ctime of the +# target inode change? +# +. ./common/preamble +_begin_fstest auto quick^^^^^^ unlink[need changing]
Quoted 8 lines
Quoted 8 lines
tests/generic/755 line 15
Quoted 5 lines
tests/generic/755 new file +4
-0+ +# Import common functions. +. ./common/filter +. ./common/dmerrorWhy dmerror and filter are needed? If not necessary, remove these 3 lines.
[need changing]
Quoted 9 lines
Quoted 9 lines
Others looks good to me.
Thanks,
Zorrotests/generic/755 line 18
Quoted 3 lines
tests/generic/755 new file +3
-0+ +_require_test +_require_test_program unlink-ctime
_fixed_by_kernel_commitXXXXXXXXXXXX btrfs: update target inode's ctime on unlinkQuoted 31 lines
Quoted 27 lines
Quoted 26 lines
tests/generic/755 new file +8
-0+ +testfile="$TEST_DIR/unlink-ctime.$$" + +$here/src/unlink-ctime $testfile + +echo Silence is golden +status=0 +exittests/generic/755.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 755 +Silence is golden ---base-commit:
f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bdBest regards,
Signature · 1 line
Jeff Layton <[email protected]>Signature · 1 line
Jeff Layton <[email protected]>Signature · 1 line
Jeff Layton <[email protected]>