Skip to contentSkip to conversation

Crash consistency xfstest using dm-log-writes

RFC PATCH Superseded Amir Goldstein 3 participants 13 messages Aug 23, 2017 – Aug 30, 2017 VFS

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Crash consistency xfstest using dm-log-writes

Hi all,

I've collected these patches that have been sitting in Josef Bacik's tree for a few years and kicked them a bit into shape. The dm-log-writes target has been merged to kernel v4.1, see:
https://github.com/torvalds/linux/blob/master/Documentation/device-mapper/log-writes.txt

I have been getting frequent test failures, both fsck and file checksum errors while testing xfs, ext4 and btrfs. The patterns of failures are quite different between the different file systems.
I tested on two systems, one with SSD and one with spinning disk. I personally believe those error imply either a wrong assumptions on I/O model that the test tools are making or a test implementation bug.

Decided to post the patches anyway, because it may take me a while to debug the failures, so giving other develpers a chance to produce more test results on their systems and maybe help in debugging the test failures.

Some data points from my tests:
- ext4 test results seem more consistent than xfs test results - with some random seed values I could not get ext4 to fail
and with some random seed values, like the ones provided in the patch, ext4 test failed with exactly the same fsck error, on the same log mark on both SSD and spinning disk systems.
- With the random seed values in this patch set, ext4 test always failed with the same fsck error (end of extent exceeds allowed value).
- btrfs test also failed with the provided random seed values, but with slightly different fsck errors each run.
- Unlike ext4 and btrfs, xfs tests seemed to fail arbitrarily for any value of random seed I tried.
- xfs tests fail sometimes on file checksum error, each run on a different file and I've never seen xfs failing on fsck error.
- Tests were much more likely to fail with xfs on spinning disk (9 out of 10) compared to xfs on SSD (1 out of 10).
- Removing -o discard mount option, adding fsx AIO (-A) and disabling mapped read/write (-W -R) did not improve xfs test failures as far as I can tell

Any tips and pointers to other things I could test before diving into tracing would be much appreciated.

If anyone can run the test to get additional data points that would be much appreciated as well.

Thanks,
Amir.

P.S.: Josef,

Because I split the patches and made some changes, I did not keep your S-O-B. After you review my changes, if you like, I can restore your S-O-B.

Amir Goldstein (8):
common/rc: convert some egrep to grep
common/rc: fix _require_xfs_io_command params check
fsx: fixes to random seed
fsx: fix path of .fsx* files
fsx: add support for integrity check with dm-log-writes target
log-writes: add replay-log program to replay dm-log-writes target
fstests: add support for working with dm-log-writes target
fstests: add crash consistency fsx test using dm-log-writes

 .gitignore                   |   1 +
 README                       |   2 +
 common/dmlogwrites           |  86 ++++++++++
 common/rc                    |  15 +-
 doc/auxiliary-programs.txt   |   8 +
 doc/requirement-checking.txt |  20 +++
 ltp/fsx.c                    | 152 ++++++++++++++---
 src/Makefile                 |   2 +-
 src/log-writes/Makefile      |  23 +++
 src/log-writes/SOURCE        |   6 +
 src/log-writes/log-writes.c  | 379 +++++++++++++++++++++++++++++++++++++++++++
 src/log-writes/log-writes.h  |  70 ++++++++
 src/log-writes/replay-log.c  | 348 +++++++++++++++++++++++++++++++++++++++
 tests/generic/500            | 128 +++++++++++++++
 tests/generic/500.out        |   2 +
 tests/generic/group          |   1 +
 16 files changed, 1212 insertions(+), 31 deletions(-)
 create mode 100644 common/dmlogwrites
 create mode 100644 src/log-writes/Makefile
 create mode 100644 src/log-writes/SOURCE
 create mode 100644 src/log-writes/log-writes.c
 create mode 100644 src/log-writes/log-writes.h
 create mode 100644 src/log-writes/replay-log.c
 create mode 100755 tests/generic/500
 create mode 100644 tests/generic/500.out
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH 1/8 common/rc: convert some egrep to grep

---
 common/rc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
common/rc +4 -4
index 9c5f54a..9d7b783 100644
@@ -2177,7 +2177,7 @@ _require_xfs_io_command()
 		;;
 	"fsmap" )
 		testio=`$XFS_IO_PROG -f -c "fsmap" $testfile 2>&1`
-		echo $testio | egrep -q "Inappropriate ioctl" && \
+		echo $testio | grep -q "Inappropriate ioctl" && \
 			_notrun "xfs_io $command support is missing"
 		;;
 	"open")
@@ -2185,12 +2185,12 @@ _require_xfs_io_command()
 		# a new -C flag was introduced to execute one shot commands.
 		# Check for -C flag support as an indication for the bug fix.
 		testio=`$XFS_IO_PROG -F -f -C "open $testfile" $testfile 2>&1`
-		echo $testio | egrep -q "invalid option" && \
+		echo $testio | grep -q "invalid option" && \
 			_notrun "xfs_io $command support is missing"
 		;;
 	"scrub"|"repair")
 		testio=`$XFS_IO_PROG -x -c "$command dummy 0" $TEST_DIR 2>&1`
-		echo $testio | egrep -q "Inappropriate ioctl" && \
+		echo $testio | grep -q "Inappropriate ioctl" && \
 			_notrun "xfs_io $command support is missing"
 		;;
 	"utimes" )
@@ -2209,7 +2209,7 @@ _require_xfs_io_command()
 		_notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
 	echo $testio | grep -q "foreign file active" && \
 		_notrun "xfs_io $command not supported on $FSTYP"
-	echo $testio | egrep -q "Function not implemented" && \
+	echo $testio | grep -q "Function not implemented" && \
 		_notrun "xfs_io $command support is missing (missing syscall?)"
 
 	if [ -n "$param" -a $param_checked -eq 0 ]; then
Signature · 1 line
2.7.4
#2 lore raw

RFC PATCH 2/8 common/rc: fix _require_xfs_io_command params check

In reply to Amir Goldstein

When _require_xfs_io_command is passed command parameters, the resulting error from invalid parameters may be ignored.

For example, the following bogus params would not abort the test:
_require_xfs_io_command "falloc" "-X" _require_xfs_io_command "fiemap" "-X"

Fix this by looking for the relevant error message.

---
 common/rc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
common/rc +6 -1
index 9d7b783..44b98f6 100644
@@ -2212,9 +2212,14 @@ _require_xfs_io_command()
 	echo $testio | grep -q "Function not implemented" && \
 		_notrun "xfs_io $command support is missing (missing syscall?)"
 
-	if [ -n "$param" -a $param_checked -eq 0 ]; then
+	[ -n "$param" ] || return
+
+	if [ $param_checked -eq 0 ]; then
 		$XFS_IO_PROG -c "help $command" | grep -q "^ $param --" || \
 			_notrun "xfs_io $command doesn't support $param"
+	else
+		echo $testio | grep -q "invalid option" && \
+			_notrun "xfs_io $command doesn't support $param"
 	fi
 }
 
Signature · 1 line
2.7.4
#3 lore raw

RFC PATCH 3/8 fsx: fixes to random seed

In reply to Amir Goldstein

Not sure why, but with initstate()/setstate(), sfx generates same events regadless of the input seed argument.

Change to use srandom() to fix the problem.

Add pid to auto random seed, so parallel fsx executions with auto seed will use different seed values.

At this time there are 6 tests that use sfx, out of which:
2 use -S 0 as seed (gettime()) - generic/{075,112} 2 do not specify seed (default = 1) - generic/{091,263} 1 uses explicit constant seed - generic/127
1 uses explicit $RANDOM seed - generic/231

This change affects all those tests.
The tests that intended to randomize the seed will now really randomize the seed.
The tests that intended to use a constant seed will still use a constant seed, but resulting event sequence will be different than before this change.

---
 ltp/fsx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ltp/fsx.c +4 -4
index 3713bbe..572df75 100644
@@ -116,7 +116,6 @@ int	fd;				/* fd for our test file */
 blksize_t	block_size = 0;
 off_t		file_size = 0;
 off_t		biggest = 0;
-char		state[256];
 unsigned long	testcalls = 0;		/* calls to function "test" */
 
 unsigned long	simulatedopcount = 0;	/* -b flag */
@@ -1909,8 +1908,10 @@ main(int argc, char **argv)
                         break;
 		case 'S':
                         seed = getnum(optarg, &endp);
-			if (seed == 0)
+			if (seed == 0) {
 				seed = time(0) % 10000;
+				seed += (int)getpid();
+			}
 			if (!quiet)
 				fprintf(stdout, "Seed set to %d\n", seed);
 			if (seed < 0)
@@ -1948,8 +1949,7 @@ main(int argc, char **argv)
 	signal(SIGUSR1,	cleanup);
 	signal(SIGUSR2,	cleanup);
 
-	initstate(seed, state, 256);
-	setstate(state);
+	srandom(seed);
 	fd = open(fname,
 		O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666);
 	if (fd < 0) {
Signature · 1 line
2.7.4
#6 lore raw

RFC PATCH 4/8 fsx: fix path of .fsx* files

In reply to Amir Goldstein

When command line arg -P <dirpath> is used, compose the path for .fsxgood .fsxlog .fsxops files from dirpath and work file basename.

This fix is ported from LTP.

---
 ltp/fsx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
ltp/fsx.c +8 -4
index 572df75..1502905 100644
@@ -1581,7 +1581,7 @@ usage(void)
 "	-L: fsxLite - no file creations & no file size changes\n\
 	-N numops: total # operations to do (default infinity)\n\
 	-O: use oplen (see -o flag) for every op (default random)\n\
-	-P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
+	-P: save .fsxlog .fsxops and .fsxgood files in dirpath (default ./)\n\
 	-S seed: for random # generator (default 1) 0 gets timestamp\n\
 	-W: mapped write operations DISabled\n\
         -R: read() system calls only (mapped reads disabled)\n\
@@ -1761,6 +1761,7 @@ main(int argc, char **argv)
 	char	*endp;
 	char goodfile[1024];
 	char logfile[1024];
+	int dirpath = 0;
 	struct stat statbuf;
 
 	goodfile[0] = 0;
@@ -1902,6 +1903,9 @@ main(int argc, char **argv)
 			strcat(goodfile, "/");
 			strncpy(logfile, optarg, sizeof(logfile));
 			strcat(logfile, "/");
+			strncpy(opsfile, optarg, sizeof(logfile));
+			strcat(opsfile, "/");
+			dirpath = 1;
 			break;
                 case 'R':
                         mapped_reads = 0;
@@ -1978,21 +1982,21 @@ main(int argc, char **argv)
 		}
 	}
 #endif
-	strncat(goodfile, fname, 256);
+	strncat(goodfile, dirpath ? basename(fname) : fname, 256);
 	strcat (goodfile, ".fsxgood");
 	fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
 	if (fsxgoodfd < 0) {
 		prterr(goodfile);
 		exit(92);
 	}
-	strncat(logfile, fname, 256);
+	strncat(logfile, dirpath ? basename(fname) : fname, 256);
 	strcat (logfile, ".fsxlog");
 	fsxlogf = fopen(logfile, "w");
 	if (fsxlogf == NULL) {
 		prterr(logfile);
 		exit(93);
 	}
-	strncat(opsfile, fname, 256);
+	strncat(opsfile, dirpath ? basename(fname) : fname, 256);
 	strcat(opsfile, ".fsxops");
 	unlink(opsfile);
 
Signature · 1 line
2.7.4
#7 lore raw

RFC PATCH 5/8 fsx: add support for integrity check with dm-log-writes target

In reply to Amir Goldstein

Cherry-picked the relevant fsx bits from commit 70d41e17164b in Josef Bacik's fstests tree (https://github.com/josefbacik/fstests).
Quoting from Josef's commit message:

I've rigged up fsx to have an integrity check mode. Basically it works like it normally works, but when it fsync()'s it marks the log with a unique mark and dumps it's buffer to a file with the mark in the filename. I did this with a system() call simply because it was the fastest. I can link the device-mapper libraries and do it programatically if that would be preferred, but this works pretty well.

[Amir:]
- Fix some exit codes
- Require -P dirpath for -i logdev

---
 ltp/fsx.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 120 insertions(+), 22 deletions(-)
ltp/fsx.c +120 -22
index 1502905..7e9713e 100644
@@ -67,15 +67,17 @@ int			logcount = 0;	/* total ops */
  * be careful in how we select the different operations. The active operations
  * are mapped to numbers as follows:
  *
- *		lite	!lite
- * READ:	0	0
- * WRITE:	1	1
- * MAPREAD:	2	2
- * MAPWRITE:	3	3
- * TRUNCATE:	-	4
- * FALLOCATE:	-	5
- * PUNCH HOLE:	-	6
- * ZERO RANGE:	-	7
+ *			lite	!lite	integrity
+ * READ:		0	0	0
+ * WRITE:		1	1	1
+ * MAPREAD:		2	2	2
+ * MAPWRITE:		3	3	3
+ * TRUNCATE:		-	4	4
+ * FALLOCATE:		-	5	5
+ * PUNCH HOLE:		-	6	6
+ * ZERO RANGE:		-	7	7
+ * COLLAPSE RANGE:	-	8	8
+ * FSYNC:		-	-	9
  *
  * When mapped read/writes are disabled, they are simply converted to normal
  * reads and writes. When fallocate/fpunch calls are disabled, they are
@@ -102,6 +104,10 @@ int			logcount = 0;	/* total ops */
 #define OP_INSERT_RANGE	9
 #define OP_MAX_FULL		10
 
+/* integrity operations */
+#define OP_FSYNC		10
+#define OP_MAX_INTEGRITY	11
+
 #undef PAGE_SIZE
 #define PAGE_SIZE       getpagesize()
 #undef PAGE_MASK
@@ -111,6 +117,9 @@ char	*original_buf;			/* a pointer to the original data */
 char	*good_buf;			/* a pointer to the correct data */
 char	*temp_buf;			/* a pointer to the current data */
 char	*fname;				/* name of our test file */
+char	*bname;				/* basename of our test file */
+char	*logdev;			/* -i flag */
+char	dname[1024];			/* -P flag */
 int	fd;				/* fd for our test file */
 
 blksize_t	block_size = 0;
@@ -148,9 +157,11 @@ int     zero_range_calls = 1;           /* -z flag disables */
 int	collapse_range_calls = 1;	/* -C flag disables */
 int	insert_range_calls = 1;		/* -I flag disables */
 int 	mapped_reads = 1;		/* -R flag disables it */
+int	integrity = 0;			/* -i flag */
 int	fsxgoodfd = 0;
 int	o_direct;			/* -Z */
 int	aio = 0;
+int	mark_nr = 0;
 
 int page_size;
 int page_mask;
@@ -397,6 +408,9 @@ logdump(void)
 			if (overlap)
 				prt("\t******IIII");
 			break;
+		case OP_FSYNC:
+			prt("FSYNC");
+			break;
 		default:
 			prt("BOGUS LOG ENTRY (operation code = %d)!",
 			    lp->operation);
@@ -500,6 +514,42 @@ report_failure(int status)
 				        *(((unsigned char *)(cp)) + 1)))
 
 void
+mark_log(void)
+{
+	char command[256];
+	int ret;
+
+	snprintf(command, 256, "dmsetup message %s 0 mark %s.mark%d", logdev,
+		 bname, mark_nr);
+	ret = system(command);
+	if (ret) {
+		prterr("dmsetup mark failed");
+		exit(101);
+	}
+}
+
+void
+dump_fsync_buffer(void)
+{
+	char fname_buffer[1024];
+	int good_fd;
+
+	if (!good_buf)
+		return;
+
+	snprintf(fname_buffer, 1024, "%s%s.mark%d", dname,
+		 bname, mark_nr);
+	good_fd = open(fname_buffer, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+	if (good_fd < 0) {
+		prterr(fname_buffer);
+		exit(102);
+	}
+
+	save_buffer(good_buf, file_size, good_fd);
+	close(good_fd);
+}
+
+void
 check_buffers(unsigned offset, unsigned size)
 {
 	unsigned char c, t;
@@ -1250,6 +1300,26 @@ docloseopen(void)
 	}
 }
 
+void
+dofsync(void)
+{
+	int ret;
+
+	if (testcalls <= simulatedopcount)
+		return;
+	if (debug)
+		prt("%lu fsync\n", testcalls);
+	log4(OP_FSYNC, 0, 0, 0);
+	ret = fsync(fd);
+	if (ret < 0) {
+		prterr("dofsync");
+		report_failure(190);
+	}
+	mark_log();
+	dump_fsync_buffer();
+	printf("Dumped fsync buffer mark %d\n", mark_nr);
+	mark_nr++;
+}
 
 #define TRIM_OFF(off, size)			\
 do {						\
@@ -1397,8 +1467,10 @@ test(void)
 	/* calculate appropriate op to run */
 	if (lite)
 		op = rv % OP_MAX_LITE;
-	else
+	else if (!integrity)
 		op = rv % OP_MAX_FULL;
+	else
+		op = rv % OP_MAX_INTEGRITY;
 
 	switch(op) {
 	case OP_TRUNCATE:
@@ -1522,6 +1594,9 @@ have_op:
 
 		do_insert_range(offset, size);
 		break;
+	case OP_FSYNC:
+		dofsync();
+		break;
 	default:
 		prterr("test: unknown operation");
 		report_failure(42);
@@ -1541,7 +1616,7 @@ void
 usage(void)
 {
 	fprintf(stdout, "usage: %s",
-		"fsx [-dnqxAFLOWZ] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\
+		"fsx [-dnqxAFLOWZ] [-b opnum] [-c Prob] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] [-i logdev] fname\n\
 	-b opnum: beginning operation number (default 1)\n\
 	-c P: 1 in P chance of file close+open at each op (default infinity)\n\
 	-d: debug output for all operations\n\
@@ -1586,6 +1661,7 @@ usage(void)
 	-W: mapped write operations DISabled\n\
         -R: read() system calls only (mapped reads disabled)\n\
         -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
+	-i logdev: do integrity testing, logdev is the dm log writes device\n\
 	fname: this filename is REQUIRED (no default)\n");
 	exit(90);
 }
@@ -1758,7 +1834,7 @@ int
 main(int argc, char **argv)
 {
 	int	i, style, ch;
-	char	*endp;
+	char	*endp, *tmp;
 	char goodfile[1024];
 	char logfile[1024];
 	int dirpath = 0;
@@ -1766,6 +1842,7 @@ main(int argc, char **argv)
 
 	goodfile[0] = 0;
 	logfile[0] = 0;
+	dname[0] = 0;
 
 	page_size = getpagesize();
 	page_mask = page_size - 1;
@@ -1775,7 +1852,7 @@ main(int argc, char **argv)
 	setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
 
 	while ((ch = getopt_long(argc, argv,
-				 "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ",
+				 "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZi:",
 				 longopts, NULL)) != EOF)
 		switch (ch) {
 		case 'b':
@@ -1899,13 +1976,13 @@ main(int argc, char **argv)
 			randomoplen = 0;
 			break;
 		case 'P':
-			strncpy(goodfile, optarg, sizeof(goodfile));
-			strcat(goodfile, "/");
-			strncpy(logfile, optarg, sizeof(logfile));
-			strcat(logfile, "/");
-			strncpy(opsfile, optarg, sizeof(logfile));
-			strcat(opsfile, "/");
+			strncpy(dname, optarg, sizeof(dname));
+			strcat(dname, "/");
 			dirpath = 1;
+
+			strncpy(goodfile, dname, sizeof(goodfile));
+			strncpy(logfile, dname, sizeof(logfile));
+			strncpy(opsfile, dname, sizeof(logfile));
 			break;
                 case 'R':
                         mapped_reads = 0;
@@ -1929,6 +2006,14 @@ main(int argc, char **argv)
 		case 'Z':
 			o_direct = O_DIRECT;
 			break;
+		case 'i':
+			integrity = 1;
+			logdev = strdup(optarg);
+			if (!logdev) {
+				prterr("strdup");
+				exit(99);
+			}
+			break;
 		case 256:  /* --replay-ops */
 			replayops = optarg;
 			break;
@@ -1940,7 +2025,19 @@ main(int argc, char **argv)
 	argv += optind;
 	if (argc != 1)
 		usage();
+
+	if (integrity && !dirpath) {
+		fprintf(stderr, "option -i <logdev> requires -P <dirpath>\n");
+		usage();
+	}
+
 	fname = argv[0];
+	tmp = strdup(fname);
+	if (!tmp) {
+		prterr("strdup");
+		exit(99);
+	}
+	bname = basename(tmp);
 
 	signal(SIGHUP,	cleanup);
 	signal(SIGINT,	cleanup);
@@ -1982,21 +2079,21 @@ main(int argc, char **argv)
 		}
 	}
 #endif
-	strncat(goodfile, dirpath ? basename(fname) : fname, 256);
+	strncat(goodfile, dirpath ? bname : fname, 256);
 	strcat (goodfile, ".fsxgood");
 	fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
 	if (fsxgoodfd < 0) {
 		prterr(goodfile);
 		exit(92);
 	}
-	strncat(logfile, dirpath ? basename(fname) : fname, 256);
+	strncat(logfile, dirpath ? bname : fname, 256);
 	strcat (logfile, ".fsxlog");
 	fsxlogf = fopen(logfile, "w");
 	if (fsxlogf == NULL) {
 		prterr(logfile);
 		exit(93);
 	}
-	strncat(opsfile, dirpath ? basename(fname) : fname, 256);
+	strncat(opsfile, dirpath ? bname : fname, 256);
 	strcat(opsfile, ".fsxops");
 	unlink(opsfile);
 
@@ -2072,6 +2169,7 @@ main(int argc, char **argv)
 		if (!test())
 			break;
 
+	free(tmp);
 	if (close(fd)) {
 		prterr("close");
 		report_failure(99);
Signature · 1 line
2.7.4
#8 lore raw

RFC PATCH 6/8 log-writes: add replay-log program to replay dm-log-writes target

In reply to Amir Goldstein

Imported Josef Bacik's code from:
https://github.com/josefbacik/log-writes.git

Specialized program for replaying a write log that was recorded by device mapper log-writes target. The tools is used to perform crash consistency tests, allowing to run an arbitrary check tool (fsck) at specified checkpoints in the write log.

[Amir:]
- Add project Makefile and SOURCE files
- Document the replay-log auxiliary program

---
 .gitignore                  |   1 +
 doc/auxiliary-programs.txt  |   8 +
 src/Makefile                |   2 +-
 src/log-writes/Makefile     |  23 +++
 src/log-writes/SOURCE       |   6 +
 src/log-writes/log-writes.c | 379 ++++++++++++++++++++++++++++++++++++++++++++
 src/log-writes/log-writes.h |  70 ++++++++
 src/log-writes/replay-log.c | 348 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 836 insertions(+), 1 deletion(-)
 create mode 100644 src/log-writes/Makefile
 create mode 100644 src/log-writes/SOURCE
 create mode 100644 src/log-writes/log-writes.c
 create mode 100644 src/log-writes/log-writes.h
 create mode 100644 src/log-writes/replay-log.c
.gitignore +1 -0
index fcbc0cd..c26c92f 100644
@@ -153,6 +153,7 @@
 /src/t_mmap_stale_pmd
 /src/t_mmap_cow_race
 /src/t_mmap_fallocate
+/src/log-writes/replay-log
 
 # dmapi/ binaries
 /dmapi/src/common/cmd/read_invis
doc/auxiliary-programs.txt +8 -0
index bcab453..de15832 100644
@@ -18,6 +18,7 @@ Contents:
  - af_unix		-- Create an AF_UNIX socket
  - dmerror		-- fault injection block device control
  - fsync-err		-- tests fsync error reporting after failed writeback
+ - log-writes/replay-log -- Replay log from device mapper log-writes target
  - open_by_handle	-- open_by_handle_at syscall exercise
  - stat_test		-- statx syscall exercise
  - t_dir_type		-- print directory entries and their file type
@@ -46,6 +47,13 @@ fsync-err
 	writeback and test that errors are reported during fsync and cleared
 	afterward.
 
+log-writes/replay-log
+
+	Specialized program for replaying a write log that was recorded by
+	device mapper log-writes target.  The tools is used to perform crash
+	consistency tests, allowing to run an arbitrary check tool (fsck) at
+	specified checkpoints in the write log.
+
 open_by_handle
 
 	The open_by_handle program exercises the open_by_handle_at() system
src/Makefile +1 -1
index b8aff49..7d1306b 100644
@@ -25,7 +25,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \
 	dio-invalidate-cache stat_test t_encrypted_d_revalidate
 
-SUBDIRS =
+SUBDIRS = log-writes
 
 LLDLIBS = $(LIBATTR) $(LIBHANDLE) $(LIBACL) -lpthread
 
src/log-writes/Makefile new file +23 -0
new file mode 100644
index 0000000..d114177
@@ -0,0 +1,23 @@
+TOPDIR = ../..
+include $(TOPDIR)/include/builddefs
+
+TARGETS = replay-log
+
+CFILES = replay-log.c log-writes.c
+LDIRT = $(TARGETS)
+
+default: depend $(TARGETS)
+
+depend: .dep
+
+include $(BUILDRULES)
+
+$(TARGETS): $(CFILES)
+	@echo "    [CC]    $@"
+	$(Q)$(LTLINK) $(CFILES) -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS)
+
+install:
+	$(INSTALL) -m 755 -d $(PKG_LIB_DIR)/src/log-writes
+	$(INSTALL) -m 755 $(TARGETS) $(PKG_LIB_DIR)/src/log-writes
+
+-include .dep
src/log-writes/SOURCE new file +6 -0
new file mode 100644
index 0000000..d6d143c
@@ -0,0 +1,6 @@
+From:
+https://github.com/josefbacik/log-writes.git
+
+description	Helper code for dm-log-writes target
+owner	Josef Bacik <[email protected]>
+URL	https://github.com/josefbacik/log-writes.git
src/log-writes/log-writes.c new file +379 -0

379 lines not on this page · raw message

src/log-writes/log-writes.h new file +70 -0

70 lines not on this page · raw message

src/log-writes/replay-log.c new file +348 -0

348 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

RFC PATCH 7/8 fstests: add support for working with dm-log-writes target

In reply to Amir Goldstein

Cherry-picked the relevant common bits from commit 70d41e17164b in Josef Bacik's fstests tree (https://github.com/josefbacik/fstests).
Quoting from Josef's commit message:

This patch adds the supporting code for using the dm-log-writes target. The dmlogwrites code is similar to the dmflakey code, it just gives us functions to build and tear down a dm-log-writes target. We add a new LOGWRITES_DEV variable to take in the device we will use as the log and add checks for that.

[Amir:]
- Removed unneeded _test_falloc_support
- Moved _require_log_writes to dmlogwrites
- Document _require_log_writes

---
 README                       |  2 ++
 common/dmlogwrites           | 86 ++++++++++++++++++++++++++++++++++++++++++++
 doc/requirement-checking.txt | 20 +++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 common/dmlogwrites
README +2 -0
index 9456fa7..4963d28 100644
@@ -91,6 +91,8 @@ Preparing system for tests:
              - set TEST_XFS_SCRUB=1 to have _check_xfs_filesystem run
                xfs_scrub -vd to scrub the filesystem metadata online before
                unmounting to run the offline check.
+             - setenv LOGWRITES_DEV to a block device to use for power fail
+               testing.
 
         - or add a case to the switch in common/config assigning
           these variables based on the hostname of your test
common/dmlogwrites new file +86 -0

86 lines not on this page · raw message

doc/requirement-checking.txt +20 -0
index 95d10e6..4e01b1f 100644
@@ -21,6 +21,10 @@ they have.  This is done with _require_<xxx> macros, which may take parameters.
 
 	_require_statx
 
+ (4) Device mapper requirement.
+
+	_require_dm_target
+	_require_log_writes
 
 ====================
 GENERAL REQUIREMENTS
@@ -102,3 +106,19 @@ _require_statx
 
      The test requires the use of the statx() system call and will be skipped
      if it isn't available in the kernel.
+
+
+==========================
+DEVICE MAPPER REQUIREMENTS
+==========================
+
+_require_dm_target <name>
+
+     The test requires the use of the device mapper target and will be skipped
+     if it isn't available in the kernel.
+
+_require_log_writes
+
+     The test requires the use of the device mapper target log-writes.
+     The test also requires the test program log-writes/replay-log is built
+     and will be skipped if either isn't available.
Signature · 1 line
2.7.4
#12 lore raw

RFC PATCH 8/8 fstests: add crash consistency fsx test using dm-log-writes

In reply to Amir Goldstein

DO NOT MERGE!!! this test fails most likely due to test bug.

The random seed values in this patch fail the test consistently on ext4 always with the same fsck error.
btrfs also fails, but with slightly different fsck errors each run. xfs fails sometimes on file checksum error.

Cherry-picked the test from commit 70d41e17164b
in Josef Bacik's fstests tree (https://github.com/josefbacik/fstests).
Quoting from Josef's commit message:

The test just runs some ops and exits, then finds all of the good buffers in the directory we provided and:
- replays up to the mark given
- mounts the file system and compares the md5sum
- unmounts and fsck's to check for metadata integrity

dm-log-writes will pretend to do discard and the replay-log tool will replay it properly depending on the underlying device, either by writing 0's or actually calling the discard ioctl, so I've enabled discard in the test for maximum fun.

[Amir:]
- Removed unneeded _test_falloc_support dynamic FSX_OPTS
- Added place holders for using constant random seeds
- Add test to new 'replay' group

---
 tests/generic/500     | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/500.out |   2 +
 tests/generic/group   |   1 +
 3 files changed, 131 insertions(+)
 create mode 100755 tests/generic/500
 create mode 100644 tests/generic/500.out
tests/generic/500 new file +128 -0
new file mode 100755
index 0000000..b56eab1
@@ -0,0 +1,128 @@
+#! /bin/bash
+# FS QA Test No. 500
+#
+# Run fsx with log writes to verify power fail safeness.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015 Facebook. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1	# failure is the default!
+
+_cleanup()
+{
+	_cleanup_log_writes
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/dmlogwrites
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch_nocheck
+_require_log_writes
+
+rm -f $seqres.full
+rm -rf $TEST_DIR/fsxtests
+
+check_files()
+{
+	local _name=$1
+
+	# Now look for our files
+	for i in $(find $SANITY_DIR -type f | grep $_name | grep mark)
+	do
+		local filename=$(basename $i)
+		local mark="${filename##*.}"
+		local expected_size=`_ls_l -h $i | awk '{ print $5 }'`
+		echo "checking $filename ($expected_size)" >> $seqres.full
+		_replay_log $filename
+		_scratch_mount
+		local expected_md5=$(md5sum $i | cut -f 1 -d ' ')
+		local md5=$(md5sum $SCRATCH_MNT/$_name | cut -f 1 -d ' ')
+		local size=`_ls_l -h $SCRATCH_MNT/$_name | awk '{ print $5 }'`
+		[ "${md5}x" != "${expected_md5}x" ] && _fatal "$filename ($size) md5sum mismatched"
+		_scratch_unmount
+		_check_scratch_fs
+	done
+}
+
+SANITY_DIR=$TEST_DIR/fsxtests
+mkdir $SANITY_DIR
+
+# Create the log
+_init_log_writes
+
+_log_writes_mkfs >> $seqres.full 2>&1
+
+# Log writes emulates discard support, turn it on for maximum crying.
+_mount_log_writes -o discard
+
+FSX_OPTS="-N 300 -P $SANITY_DIR -i $LOGWRITES_DMDEV"
+# Set random seeds for fsx runs (0 for timestamp + pid)
+S1=2885
+S2=2886
+S3=2887
+S4=2888
+# Run fsx for a while
+run_check $here/ltp/fsx $FSX_OPTS -S $S1 $SCRATCH_MNT/testfile1 &
+run_check $here/ltp/fsx $FSX_OPTS -S $S2 $SCRATCH_MNT/testfile2 &
+run_check $here/ltp/fsx $FSX_OPTS -S $S3 $SCRATCH_MNT/testfile3 &
+run_check $here/ltp/fsx $FSX_OPTS -S $S4 $SCRATCH_MNT/testfile4 &
+wait
+test1_md5=$(md5sum $SCRATCH_MNT/testfile1 | cut -f 1 -d ' ')
+test2_md5=$(md5sum $SCRATCH_MNT/testfile2 | cut -f 1 -d ' ')
+test3_md5=$(md5sum $SCRATCH_MNT/testfile3 | cut -f 1 -d ' ')
+test4_md5=$(md5sum $SCRATCH_MNT/testfile4 | cut -f 1 -d ' ')
+
+# Unmount the scratch dir and tear down the log writes target
+_unmount_log_writes
+_log_writes_mark end
+_log_writes_remove
+
+for i in testfile1 testfile2 testfile3 testfile4
+do
+	check_files $i
+done
+
+# Check the end
+_replay_log end
+_scratch_mount
+md5=$(md5sum $SCRATCH_MNT/testfile1 | cut -f 1 -d ' ')
+[ "${md5}x" != "${test1_md5}x" ] && _fatal "testfile1 end md5sum mismatched"
+md5=$(md5sum $SCRATCH_MNT/testfile2 | cut -f 1 -d ' ')
+[ "${md5}x" != "${test2_md5}x" ] && _fatal "testfile2 end md5sum mismatched"
+md5=$(md5sum $SCRATCH_MNT/testfile3 | cut -f 1 -d ' ')
+[ "${md5}x" != "${test3_md5}x" ] && _fatal "testfile3 end md5sum mismatched"
+md5=$(md5sum $SCRATCH_MNT/testfile4 | cut -f 1 -d ' ')
+[ "${md5}x" != "${test4_md5}x" ] && _fatal "testfile4 end md5sum mismatched"
+_scratch_unmount
+_check_scratch_fs
+
+echo "Silence is golden"
+status=0
+exit
+
tests/generic/500.out new file +2 -0
new file mode 100644
index 0000000..883b2ca
@@ -0,0 +1,2 @@
+QA output created by 500
+Silence is golden
tests/generic/group +1 -0
index 044ec3f..2396b72 100644
@@ -453,3 +453,4 @@
 448 auto quick rw
 449 auto quick acl enospc
 450 auto quick rw
+500 auto log replay
Signature · 1 line
2.7.4
#10 lore raw

Re: [RFC][PATCH 7/8] fstests: add support for working with dm-log-writes target

In reply to Amir Goldstein
Quoted 24 lines · Amir Goldstein

Cherry-picked the relevant common bits from commit 70d41e17164b in Josef Bacik's fstests tree (https://github.com/josefbacik/fstests).
Quoting from Josef's commit message:

This patch adds the supporting code for using the dm-log-writes target. The dmlogwrites code is similar to the dmflakey code, it just gives us functions to build and tear down a dm-log-writes target. We add a new LOGWRITES_DEV variable to take in the device we will use as the log and add checks for that.

[Amir:]
- Removed unneeded _test_falloc_support
- Moved _require_log_writes to dmlogwrites
- Document _require_log_writes

---
 README                       |  2 ++
 common/dmlogwrites           | 86 ++++++++++++++++++++++++++++++++++++++++++++
 doc/requirement-checking.txt | 20 +++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 common/dmlogwrites

...

Quoted 12 lines
common/dmlogwrites new file +12 -0
+
+_init_log_writes()
+{
+       local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
+       LOGWRITES_NAME=logwrites-test
+       LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME
+       LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $SCRATCH_DEV $LOGWRITES_DEV"
+       $DMSETUP_PROG create $LOGWRITES_NAME --table "$LOGWRITES_TABLE" || \
+               _fatal "failed to create log-writes device"
+       $DMSETUP_PROG mknodes > /dev/null 2>&1
+}
+

...

common/dmlogwrites line 83

Quoted 4 lines
common/dmlogwrites new file +4 -0
+_cleanup_log_writes()
+{
+       # If dmsetup load fails then we need to make sure to do resume here
+       # otherwise the umount will hang

Josef,

Care to explain this comment?
What do you mean by "resume" here? is this a real concern?

Quoted 3 lines
common/dmlogwrites new file +3 -0
+       $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
+       _log_writes_remove
+}
#11 lore raw

Re: [RFC][PATCH 7/8] fstests: add support for working with dm-log-writes target

Quoted 48 lines · Amir Goldstein
Quoted 24 lines · Amir Goldstein

Cherry-picked the relevant common bits from commit 70d41e17164b in Josef Bacik's fstests tree (https://github.com/josefbacik/fstests).
Quoting from Josef's commit message:

This patch adds the supporting code for using the dm-log-writes target. The dmlogwrites code is similar to the dmflakey code, it just gives us functions to build and tear down a dm-log-writes target. We add a new LOGWRITES_DEV variable to take in the device we will use as the log and add checks for that.

[Amir:]
- Removed unneeded _test_falloc_support
- Moved _require_log_writes to dmlogwrites
- Document _require_log_writes

---
 README                       |  2 ++
 common/dmlogwrites           | 86 ++++++++++++++++++++++++++++++++++++++++++++
 doc/requirement-checking.txt | 20 +++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 common/dmlogwrites

...

Quoted 12 lines
common/dmlogwrites new file +12 -0
+
+_init_log_writes()
+{
+       local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
+       LOGWRITES_NAME=logwrites-test
+       LOGWRITES_DMDEV=/dev/mapper/$LOGWRITES_NAME
+       LOGWRITES_TABLE="0 $BLK_DEV_SIZE log-writes $SCRATCH_DEV $LOGWRITES_DEV"
+       $DMSETUP_PROG create $LOGWRITES_NAME --table "$LOGWRITES_TABLE" || \
+               _fatal "failed to create log-writes device"
+       $DMSETUP_PROG mknodes > /dev/null 2>&1
+}
+

...

common/dmlogwrites line 83

Quoted 4 lines
common/dmlogwrites new file +4 -0
+_cleanup_log_writes()
+{
+       # If dmsetup load fails then we need to make sure to do resume here
+       # otherwise the umount will hang

Josef,

Quoted 3 lines

Care to explain this comment?
What do you mean by "resume" here? is this a real concern?

I don't know, I think I had this weird suspend/resume thing before but got rid of it and forgot to remove the comment. Thanks,

Josef

#4 lore raw

Re: [RFC][PATCH 3/8] fsx: fixes to random seed

In reply to Amir Goldstein
Quoted 14 lines · Amir Goldstein

Not sure why, but with initstate()/setstate(), sfx generates same events regadless of the input seed argument.

Change to use srandom() to fix the problem.

Add pid to auto random seed, so parallel fsx executions with auto seed will use different seed values.

At this time there are 6 tests that use sfx, out of which:
2 use -S 0 as seed (gettime()) - generic/{075,112} 2 do not specify seed (default = 1) - generic/{091,263} 1 uses explicit constant seed - generic/127
1 uses explicit $RANDOM seed - generic/231

Quoted 8 lines

This change affects all those tests.
The tests that intended to randomize the seed will now really randomize the seed.
The tests that intended to use a constant seed will still use a constant seed, but resulting event sequence will be different than before this change.

Eryu,

While the rest of the series make take longer time to land, I think you should consider applying this patch, or at least test how it affects test results on your test systems.

Please let me know if you observe the same behavior as I do (you can use fsx -d to output all events to stdout)

I wonder what is your opinion of randomized seed vs. constant seed in xfstest... anyway, the tests 075,112,231 seem to have been using effectively constant seed up to now, not as author intended.

Cheers,
Amir.

Quoted 41 lines
---
 ltp/fsx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ltp/fsx.c +4 -5
index 3713bbe..572df75 100644
@@ -116,7 +116,6 @@ int fd;                             /* fd for our test file */
 blksize_t      block_size = 0;
 off_t          file_size = 0;
 off_t          biggest = 0;
-char           state[256];
 unsigned long  testcalls = 0;          /* calls to function "test" */
 
 unsigned long  simulatedopcount = 0;   /* -b flag */
@@ -1909,8 +1908,10 @@ main(int argc, char **argv)
                         break;
                case 'S':
                         seed = getnum(optarg, &endp);
-                       if (seed == 0)
+                       if (seed == 0) {
                                seed = time(0) % 10000;
+                               seed += (int)getpid();
+                       }
                        if (!quiet)
                                fprintf(stdout, "Seed set to %d\n", seed);
                        if (seed < 0)
@@ -1948,8 +1949,7 @@ main(int argc, char **argv)
        signal(SIGUSR1, cleanup);
        signal(SIGUSR2, cleanup);
 
-       initstate(seed, state, 256);
-       setstate(state);
+       srandom(seed);
        fd = open(fname,
                O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666);
        if (fd < 0) {
--

2.7.4

#5 lore raw

Re: [RFC][PATCH 3/8] fsx: fixes to random seed

Quoted 22 lines · Amir Goldstein
Quoted 21 lines · Amir Goldstein

Not sure why, but with initstate()/setstate(), sfx generates same events regadless of the input seed argument.

Change to use srandom() to fix the problem.

Add pid to auto random seed, so parallel fsx executions with auto seed will use different seed values.

At this time there are 6 tests that use sfx, out of which:
2 use -S 0 as seed (gettime()) - generic/{075,112} 2 do not specify seed (default = 1) - generic/{091,263} 1 uses explicit constant seed - generic/127
1 uses explicit $RANDOM seed - generic/231

This change affects all those tests.
The tests that intended to randomize the seed will now really randomize the seed.
The tests that intended to use a constant seed will still use a constant seed, but resulting event sequence will be different than before this change.

Quoted 7 lines
Quoted 1 line

Eryu,

While the rest of the series make take longer time to land, I think you should consider applying this patch, or at least test how it affects test results on your test systems.

Sorry I got to this so late.. and thanks a lot for all the work you've done for this log-write test!

Quoted 3 lines

Please let me know if you observe the same behavior as I do (you can use fsx -d to output all events to stdout)

Yes, I saw the same symptom as you've observed, the operation sequences are always the same no matter what seed I fed to fsx, I'm testing on both RHEL6 and RHEL7 hosts. It's so weird that seed doesn't have any effect on initstate and setstate, I'm not sure why either.. But your patch does change fsx to random mode.

Quoted 5 lines

I wonder what is your opinion of randomized seed vs. constant seed in xfstest... anyway, the tests 075,112,231 seem to have been using effectively constant seed up to now, not as author intended.

I agree with Josef here, be as random as possible and print out the seed for debug purpose. So I think this patch is fine. I tested the affected tests a few times and they went on well.

Thanks!

Eryu