summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-11-11 14:12:48 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-02-16 19:47:38 -0500
commit9369486a24fcf2d3297d2d5a9dab7939059c3270 (patch)
tree21f3fd8be44ca89abb145a98a083cc19d83caa97
parentf465fe9aa61235a458f6fad89a2018d514a24141 (diff)
Add bcachefs/001 for pagecache_add lock deadlock torture test
-rw-r--r--.gitignore1
-rw-r--r--src/Makefile2
-rw-r--r--src/dio_mmap_torture.c104
-rwxr-xr-xtests/bcachefs/00144
-rw-r--r--tests/bcachefs/001.out2
-rw-r--r--tests/bcachefs/Makefile24
6 files changed, 176 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 5cc3a5e4..e9a5d59f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@ tags
/src/dio-buf-fault
/src/dio-interleaved
/src/dio-invalidate-cache
+/src/dio_mmap_torture
/src/dirhash_collide
/src/dirperf
/src/dirstress
diff --git a/src/Makefile b/src/Makefile
index e7442487..8778dbc4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \
t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc \
t_mmap_writev_overlap checkpoint_journal mmap-rw-fault allocstale \
t_mmap_cow_memory_failure fake-dump-rootino dio-buf-fault rewinddir-test \
- readdir-while-renames
+ readdir-while-renames dio_mmap_torture
LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \
diff --git a/src/dio_mmap_torture.c b/src/dio_mmap_torture.c
new file mode 100644
index 00000000..22967d49
--- /dev/null
+++ b/src/dio_mmap_torture.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020 Kent Overstreet
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+static const unsigned nr_procs = 3;
+
+int main(int argc, char *argv[])
+{
+ unsigned long i, nr_iters = 0;
+ char *fname = NULL, *my_file, *next_file;
+ pid_t children[nr_procs];
+ int childnr, my_fd, next_fd, c;
+
+ while ((c = getopt(argc, argv, "n:f:")) >= 0) {
+ switch (c) {
+ case 'n':
+ errno = 0;
+ nr_iters = strtoul(optarg, NULL, 10);
+ if (errno) {
+ fprintf(stderr, "Error parsing -n: %m\n");
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'f':
+ fname = optarg;
+ break;
+ default:
+ fprintf(stderr, "Usage: dio_mmap_torture -n iters -f filename\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ for (i = 0; i < nr_procs; i++) {
+ children[i] = fork();
+ if (!children[i])
+ goto do_io;
+
+ }
+
+ for (i = 0; i < nr_procs; i++) {
+ int status;
+ waitpid(children[i], &status, 0);
+ }
+
+ exit(EXIT_SUCCESS);
+do_io:
+ childnr = i;
+
+ asprintf(&my_file, "%s.%lu", fname, i);
+ my_fd = open(my_file, O_RDWR|O_CREAT|O_DIRECT, 0644);
+ if (my_fd < 0) {
+ fprintf(stderr, "Error opening %s: %m\n", my_file);
+ exit(EXIT_FAILURE);
+ }
+
+ i = (i + 1) % nr_procs;
+
+ asprintf(&next_file, "%s.%lu", fname, i);
+ next_fd = open(next_file, O_RDWR|O_CREAT, 0644);
+ if (next_fd < 0) {
+ fprintf(stderr, "Error opening %s: %m\n", next_file);
+ exit(EXIT_FAILURE);
+ }
+
+ if (ftruncate(next_fd, 4096)) {
+ fprintf(stderr, "ftruncate error: %m\n");
+ exit(EXIT_FAILURE);
+ }
+
+ void *p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, next_fd, 0);
+ if (p == MAP_FAILED) {
+ fprintf(stderr, "mmap error: %m\n");
+ exit(EXIT_FAILURE);
+ }
+
+ mlockall(MCL_CURRENT|MCL_FUTURE);
+
+ for (i = 0; i < nr_iters; i++) {
+ int ret = pwrite(my_fd, p, 4096, 0);
+ //fprintf(stderr, "child %u write ret %i\n", childnr, ret);
+
+ if (ret < 0) {
+ fprintf(stderr, "write error: %m\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (ret != 4096)
+ fprintf(stderr, "short write: %u/%u\n", ret, 4096);
+ }
+
+ exit(EXIT_SUCCESS);
+}
diff --git a/tests/bcachefs/001 b/tests/bcachefs/001
new file mode 100755
index 00000000..eb7df385
--- /dev/null
+++ b/tests/bcachefs/001
@@ -0,0 +1,44 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Kent Overstreet. All Rights Reserved.
+#
+# FS QA Test 609
+# Test DIO writes from buffers mmapped from files that are also having dio
+# writes done to them
+
+. ./common/preamble
+_begin_fstest rw auto quick
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+_supported_fs generic
+_require_scratch
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+$here/src/dio_mmap_torture -n 10000 -f $SCRATCH_MNT/$seq
+
+# success, all done
+echo "Silence is goodness ..."
+status=0
+exit
diff --git a/tests/bcachefs/001.out b/tests/bcachefs/001.out
new file mode 100644
index 00000000..014292ca
--- /dev/null
+++ b/tests/bcachefs/001.out
@@ -0,0 +1,2 @@
+QA output created by 001
+Silence is goodness ...
diff --git a/tests/bcachefs/Makefile b/tests/bcachefs/Makefile
new file mode 100644
index 00000000..1b72a1a1
--- /dev/null
+++ b/tests/bcachefs/Makefile
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 2003-2005 Silicon Graphics, Inc. All Rights Reserved.
+#
+
+TOPDIR = ../..
+include $(TOPDIR)/include/builddefs
+include $(TOPDIR)/include/buildgrouplist
+
+BTRFS_DIR = btrfs
+TARGET_DIR = $(PKG_LIB_DIR)/$(TESTS_DIR)/$(BTRFS_DIR)
+DIRT = group.list
+
+default: $(DIRT)
+
+include $(BUILDRULES)
+
+install:
+ $(INSTALL) -m 755 -d $(TARGET_DIR)
+ $(INSTALL) -m 755 $(TESTS) $(TARGET_DIR)
+ $(INSTALL) -m 644 group.list $(TARGET_DIR)
+ $(INSTALL) -m 644 $(OUTFILES) $(TARGET_DIR)
+
+# Nothing.
+install-dev install-lib: