[LTP] [PATCH 1/2] lib: Add tst_fsfreeze.c

Petr Vorel pvorel@suse.cz
Tue Mar 7 15:55:16 CET 2023


It will be needed for df01.sh run in XFS since kernel 5.19.
Instead of requiring users to have fsfreeze implement LTP helper.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/.gitignore     |  3 ++-
 testcases/lib/Makefile       |  2 +-
 testcases/lib/tst_fsfreeze.c | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 testcases/lib/tst_fsfreeze.c

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 34dea272d..fc8214b88 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -3,10 +3,12 @@
 /tst_check_kconfigs
 /tst_checkpoint
 /tst_device
+/tst_fsfreeze
 /tst_getconf
 /tst_get_free_pids
 /tst_get_median
 /tst_get_unused_port
+/tst_hexdump
 /tst_kvcmp
 /tst_net_iface_prefix
 /tst_net_ip_prefix
@@ -15,5 +17,4 @@
 /tst_rod
 /tst_sleep
 /tst_supported_fs
-/tst_hexdump
 /tst_timeout_kill
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index f4f8c8524..abdfe464c 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -12,6 +12,6 @@ MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
 			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
-			   tst_check_kconfigs tst_cgctl
+			   tst_check_kconfigs tst_cgctl tst_fsfreeze
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_fsfreeze.c b/testcases/lib/tst_fsfreeze.c
new file mode 100644
index 000000000..4b0b12cba
--- /dev/null
+++ b/testcases/lib/tst_fsfreeze.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2010 Hajime Taira <htaira@redhat.com>
+ *                    Masatake Yamato <yamato@redhat.com>
+ * Copyright (c) 2023 Petr Vorel <pvorel@suse.cz>
+ *
+ * Based on fsfreeze from util-linux.
+ */
+
+#include <linux/fs.h>
+#include <stdio.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+
+static void help(void)
+{
+	printf("Freeze and unfreeze the device.\n");
+	printf("Usage: tst_fsfreeze device\n");
+}
+
+int main(int argc, char *argv[])
+{
+	int fd;
+
+	if (argc < 2) {
+		help();
+		return 1;
+	}
+
+	fd = SAFE_OPEN(argv[1], O_RDONLY);
+	SAFE_IOCTL(fd, FIFREEZE, 0);
+	SAFE_IOCTL(fd, FITHAW, 0);
+	SAFE_CLOSE(fd);
+
+	return 0;
+}
-- 
2.39.2



More information about the ltp mailing list