From: Jeff Layton <jlayton@kernel.org>
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH fstests] generic/755: test that inode's ctime is updated on unlink
Date: Tue, 13 Aug 2024 14:21:08 -0400 [thread overview]
Message-ID: <20240813-master-v1-1-862678cc4000@kernel.org> (raw)
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
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(-)
diff --git a/src/Makefile b/src/Makefile
index 9979613711c9..c71fa41e4668 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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 \
diff --git a/src/unlink-ctime.c b/src/unlink-ctime.c
new file mode 100644
index 000000000000..7661e340eaba
--- /dev/null
+++ b/src/unlink-ctime.c
@@ -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;
+ }
+
+ sleep(1);
+
+ ret = unlink(argv[1]);
+ if (ret) {
+ perror("unlink");
+ return 1;
+ }
+
+ ret = statx(fd, "", AT_EMPTY_PATH, STATX_CTIME, &after);
+ 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;
+}
diff --git a/tests/generic/755 b/tests/generic/755
new file mode 100755
index 000000000000..500c51f99630
--- /dev/null
+++ b/tests/generic/755
@@ -0,0 +1,26 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2024, Jeff Layton <jlayton@kernel.org>
+#
+# 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
diff --git a/tests/generic/755.out b/tests/generic/755.out
new file mode 100644
index 000000000000..7c9ea51cd298
--- /dev/null
+++ b/tests/generic/755.out
@@ -0,0 +1,2 @@
+QA output created by 755
+Silence is golden
---
base-commit: f5ada754d5838d29fd270257003d0d123a9d1cd2
change-id: 20240813-master-e3b46de630bd
Best regards,
--
Jeff Layton <jlayton@kernel.org>
next reply other threads:[~2024-08-13 18:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 18:21 Jeff Layton [this message]
2024-08-16 12:55 ` [PATCH fstests] generic/755: test that inode's ctime is updated on unlink Zorro Lang
2024-08-16 12:58 ` Jeff Layton
2024-08-17 5:53 ` Zorro Lang
2024-08-19 11:39 ` Jeff Layton
2024-08-19 12:59 ` Zorro Lang
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=20240813-master-v1-1-862678cc4000@kernel.org \
--to=jlayton@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=hch@infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
/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).