All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: fstests@vger.kernel.org
Cc: "Darrick J. Wong" <djwong@kernel.org>,
	Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH v2] generic/728: Add mmap + DIO write test
Date: Wed,  7 Jun 2023 14:47:05 +0200	[thread overview]
Message-ID: <20230607124705.1180081-1-agruenba@redhat.com> (raw)

This is the same as generic/647, but with an additional test that writes
a memory-mapped page onto itself using direct I/O.

For direct I/O writes, the kernel will invalidate the page cache before
and after carrying out the write.  This puts filesystems that fault in
pages on demand and then carry out the write with page faults disabled
into a position in which they will not be able to make any progress.
---
 src/mmap-rw-fault.c   | 33 ++++++++++++++++++++++++++++++---
 tests/generic/728     | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/generic/728.out |  2 ++
 3 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100755 tests/generic/728
 create mode 100644 tests/generic/728.out

diff --git a/src/mmap-rw-fault.c b/src/mmap-rw-fault.c
index 82f9d978..161d9f79 100644
--- a/src/mmap-rw-fault.c
+++ b/src/mmap-rw-fault.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <errno.h>
 #include <err.h>
+#include <getopt.h>
 
 char *filename;
 unsigned int page_size;
@@ -109,11 +110,29 @@ static ssize_t do_write(int fd, const void *buf, size_t count, off_t offset)
 	return count2;
 }
 
+static void usage(const char *argv0)
+{
+	fprintf(stderr, "Usage: %s [-2] {filename}\n", argv0);
+	exit(2);
+}
+
 int main(int argc, char *argv[])
 {
-	if (argc != 2)
-		errx(1, "no test filename argument given");
-	filename = argv[1];
+	int opt, opt_2 = 0;
+
+	while ((opt = getopt(argc, argv, "2")) != -1) {
+		switch(opt) {
+		case '2':
+			opt_2 = 1;
+			break;
+		default:
+			usage(argv[0]);
+		}
+	}
+
+	if (optind + 1 != argc)
+		usage(argv[0]);
+	filename = argv[optind];
 
 	page_size = ret = sysconf(_SC_PAGE_SIZE);
 	if (ret == -1)
@@ -179,6 +198,14 @@ int main(int argc, char *argv[])
 		errx(1, "pread (D_DIRECT) from hole is broken");
 	done();
 
+	if (opt_2) {
+		init('f', O_RDWR | O_DIRECT);
+		ret = do_write(fd, addr + page_size, page_size, page_size);
+		if (ret != page_size)
+			err(1, "pwrite %s (O_DIRECT): %ld != %u", filename, ret, page_size);
+		done();
+	}
+
 	if (unlink(filename))
 		err(1, "unlink %s", filename);
 
diff --git a/tests/generic/728 b/tests/generic/728
new file mode 100755
index 00000000..483c7b73
--- /dev/null
+++ b/tests/generic/728
@@ -0,0 +1,42 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 Red Hat, Inc.  All Rights Reserved.
+#
+# FS QA Test 728
+#
+# Trigger page faults in the same file during read and write
+#
+# This is generic/647 with an additional test that writes a memory-mapped page
+# onto itself using direct I/O.
+#
+# The kernel will invalidate the page cache before carrying out the write, so
+# filesystems that fault in the page and then carry out the direct I/O write
+# with page faults disabled will never make any progress.
+#
+. ./common/preamble
+_begin_fstest auto quick
+
+# Override the default cleanup function.
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+	rm -f $TEST_DIR/mmap-rw-fault.tmp
+}
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+
+_supported_fs generic
+_require_test
+_require_odirect
+_require_test_program mmap-rw-fault
+
+echo "Silence is golden"
+
+$here/src/mmap-rw-fault -2 $TEST_DIR/mmap-rw-fault.tmp
+
+status=$?
+exit
diff --git a/tests/generic/728.out b/tests/generic/728.out
new file mode 100644
index 00000000..ab39f45f
--- /dev/null
+++ b/tests/generic/728.out
@@ -0,0 +1,2 @@
+QA output created by 728
+Silence is golden
-- 
2.40.0


             reply	other threads:[~2023-06-07 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 12:47 Andreas Gruenbacher [this message]
2023-06-07 14:43 ` [PATCH v2] generic/728: Add mmap + DIO write test Darrick J. Wong

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=20230607124705.1180081-1-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    --cc=djwong@kernel.org \
    --cc=fstests@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.