]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
fstests: add a new rw_hint helper
authorChristoph Hellwig <hch@lst.de>
Thu, 8 May 2025 05:34:31 +0000 (07:34 +0200)
committerZorro Lang <zlang@kernel.org>
Thu, 8 May 2025 19:17:17 +0000 (03:17 +0800)
Add a tool to set the life time hint via fcntl.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
.gitignore
src/Makefile
src/rw_hint.c [new file with mode: 0644]

index 4fd817243dca37715d9a6ca52afa0f7fecfabc64..f22cff8fb6c4cf51e9b654dc714068f2a4019594 100644 (file)
@@ -203,6 +203,7 @@ tags
 /src/aio-dio-regress/aio-last-ref-held-by-io
 /src/aio-dio-regress/aiocp
 /src/aio-dio-regress/aiodio_sparse2
+/src/rw_hint
 /src/vfs/vfstest
 /src/vfs/mount-idmapped
 /src/log-writes/replay-log
index 6ac72b3662570dd9bbcb90d4b23df931b7cd5b9e..2cc1fb40d9f1aef5fdf0818a4a25cc67a9a11820 100644 (file)
@@ -35,7 +35,8 @@ 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 min_dio_alignment
+       uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault min_dio_alignment \
+       rw_hint
 
 EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \
              btrfs_crc32c_forged_name.py popdir.pl popattr.py \
diff --git a/src/rw_hint.c b/src/rw_hint.c
new file mode 100644 (file)
index 0000000..d4290e4
--- /dev/null
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 Christoph Hellwig
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+
+int main(int argc, char **argv)
+{
+       uint64_t hint = -1;
+       int fd;
+
+       if (argc < 3) {
+               fprintf(stderr,
+"usage: %s file not_set|none|short|medium|long|extreme\n",
+                       argv[0]);
+               return 1;
+       }
+
+       if (!strcmp(argv[2], "not_set"))
+               hint = RWH_WRITE_LIFE_NOT_SET;
+       else if (!strcmp(argv[2], "none"))
+               hint = RWH_WRITE_LIFE_NONE;
+       else if (!strcmp(argv[2], "short"))
+               hint = RWH_WRITE_LIFE_SHORT;
+       else if (!strcmp(argv[2], "medium"))
+               hint = RWH_WRITE_LIFE_MEDIUM;
+       else if (!strcmp(argv[2], "long"))
+               hint = RWH_WRITE_LIFE_LONG;
+       else if (!strcmp(argv[2], "extreme"))
+               hint = RWH_WRITE_LIFE_EXTREME;
+
+       if (hint == -1) {
+               fprintf(stderr, "invalid hint %s\n", argv[2]);
+               return 1;
+       }
+
+       fd = open(argv[1], O_WRONLY);
+       if (fd < 0) {
+               perror("open");
+               return 1;
+       }
+       if (fcntl(fd, F_SET_RW_HINT, &hint))
+               perror("fcntl");
+       return 0;
+}