[LTP] [PATCH v1] fs_fill_btrfs: btrfs fs_fill test set mkfs.btrfs -s 4k

Wei Gao wegao@suse.com
Mon Dec 18 14:11:42 CET 2023


On PPC64 the page size is 64K and this causes trouble on btrfs
filesystems of small size(LTP currently use 300M), the threads
could compete for a very small number of pages/blocks to actually
write the data. So force the test case with sector size 4k.
e.g. mkfs.btrfs -s 4k

Signed-off-by: Wei Gao <wegao@suse.com>
---
 runtest/fs                                  |   1 +
 testcases/kernel/fs/fs_fill/fs_fill.c       |   4 +
 testcases/kernel/fs/fs_fill/fs_fill_btrfs.c | 134 ++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 testcases/kernel/fs/fs_fill/fs_fill_btrfs.c

diff --git a/runtest/fs b/runtest/fs
index 1d753e0dd..3649a1a82 100644
--- a/runtest/fs
+++ b/runtest/fs
@@ -82,6 +82,7 @@ quota_remount_test01 quota_remount_test01.sh
 isofs isofs.sh
 
 fs_fill fs_fill
+fs_fill_btrfs fs_fill_btrfs
 
 binfmt_misc01 binfmt_misc01.sh
 binfmt_misc02 binfmt_misc02.sh
diff --git a/testcases/kernel/fs/fs_fill/fs_fill.c b/testcases/kernel/fs/fs_fill/fs_fill.c
index 2ecd8e2ad..4dcc6d3b6 100644
--- a/testcases/kernel/fs/fs_fill/fs_fill.c
+++ b/testcases/kernel/fs/fs_fill/fs_fill.c
@@ -129,5 +129,9 @@ static struct tst_test test = {
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = testrun,
+	.skip_filesystems = (const char *[]) {
+		"btrfs",
+		NULL
+	},
 	.tcnt = 2
 };
diff --git a/testcases/kernel/fs/fs_fill/fs_fill_btrfs.c b/testcases/kernel/fs/fs_fill/fs_fill_btrfs.c
new file mode 100644
index 000000000..315d283a4
--- /dev/null
+++ b/testcases/kernel/fs/fs_fill/fs_fill_btrfs.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*
+ * Runs several threads that fills up the filesystem repeatedly.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include "tst_safe_pthread.h"
+#include "tst_test.h"
+
+#define MNTPOINT "mntpoint"
+#define THREADS_DIR MNTPOINT "/subdir"
+
+static volatile int run;
+static unsigned int nthreads;
+static int enospc_cnt;
+static struct worker *workers;
+
+struct worker {
+	enum tst_fill_access_pattern pattern;
+	char dir[PATH_MAX];
+};
+
+static void *worker(void *p)
+{
+	struct worker *w = p;
+	DIR *d;
+	struct dirent *ent;
+	char file[PATH_MAX];
+
+	while (run) {
+		tst_fill_fs(w->dir, 1, w->pattern);
+
+		tst_atomic_inc(&enospc_cnt);
+
+		d = SAFE_OPENDIR(w->dir);
+		while ((ent = SAFE_READDIR(d))) {
+
+			if (!strcmp(ent->d_name, ".") ||
+			    !strcmp(ent->d_name, ".."))
+				continue;
+
+			snprintf(file, sizeof(file), "%s/%s",
+				 w->dir, ent->d_name);
+
+			tst_res(TINFO, "Unlinking %s", file);
+
+			SAFE_UNLINK(file);
+			break;
+		}
+		SAFE_CLOSEDIR(d);
+	}
+
+	return NULL;
+}
+
+static void testrun(unsigned int n)
+{
+	pthread_t threads[nthreads];
+	unsigned int i, ms;
+
+	tst_atomic_store(0, &enospc_cnt);
+
+	run = 1;
+	for (i = 0; i < nthreads; i++) {
+		workers[i].pattern = n;
+		SAFE_PTHREAD_CREATE(&threads[i], NULL, worker, &workers[i]);
+	}
+
+	for (ms = 0; ; ms++) {
+		usleep(1000);
+
+		if (ms >= 1000 && tst_atomic_load(&enospc_cnt))
+			break;
+
+		if (tst_atomic_load(&enospc_cnt) > 100)
+			break;
+	}
+
+	run = 0;
+	for (i = 0; i < nthreads; i++)
+		SAFE_PTHREAD_JOIN(threads[i], NULL);
+
+	tst_res(TPASS, "Got %i ENOSPC runtime %ims", enospc_cnt, ms);
+}
+
+static void setup(void)
+{
+	unsigned int i;
+
+	nthreads = tst_ncpus_conf() + 2;
+	workers = SAFE_MALLOC(sizeof(struct worker) * nthreads);
+
+	/*
+	 * Avoid creating the thread directories in the root of the filesystem
+	 * to not hit the root entries limit on a FAT16 filesystem.
+	 */
+	SAFE_MKDIR(THREADS_DIR, 0700);
+
+	for (i = 0; i < nthreads; i++) {
+		snprintf(workers[i].dir, sizeof(workers[i].dir),
+			 THREADS_DIR "/thread%i", i + 1);
+		SAFE_MKDIR(workers[i].dir, 0700);
+	}
+
+	tst_res(TINFO, "Running %i writer threads", nthreads);
+}
+
+static void cleanup(void)
+{
+	free(workers);
+}
+
+static struct tst_test test = {
+	.max_runtime = 60,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.dev_fs_opts = (const char *const[]){"-s 4k", NULL},
+	.dev_fs_type = "btrfs",
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = testrun,
+	.tcnt = 2
+};
-- 
2.35.3



More information about the ltp mailing list