diff mbox series

[ndctl] ndctl, test: add a new unit test pfn metadata error clearing

Message ID 20180918201557.6043-1-vishal.l.verma@intel.com (mailing list archive)
State New, archived
Headers show
Series [ndctl] ndctl, test: add a new unit test pfn metadata error clearing | expand

Commit Message

Verma, Vishal L Sept. 18, 2018, 8:15 p.m. UTC
The pfn driver lacked a way to clear badblocks in the volatile struct
page area, but this is expected to be fixed for v4.20.
Add a unit test that creates an fsdax namespace, forces it to raw mode,
injects errors to the metadata area, and converts it back to fsdax.

For a kernel with the error clearing improvements, this will clear the
injected errors, but if the kernel changes are missing, the errors will
stay intact. At this point, convert the namespace back to raw mode and
check for the presence of badblocks.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 test/Makefile.am        |  3 +-
 test/pfn-meta-errors.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100755 test/pfn-meta-errors.sh
diff mbox series

Patch

diff --git a/test/Makefile.am b/test/Makefile.am
index 50bb2e4..ebdd23f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -24,7 +24,8 @@  TESTS =\
 	rescan-partitions.sh \
 	inject-smart.sh \
 	monitor.sh \
-	max_available_extent_ns.sh
+	max_available_extent_ns.sh \
+	pfn-meta-errors.sh
 
 check_PROGRAMS =\
 	libndctl \
diff --git a/test/pfn-meta-errors.sh b/test/pfn-meta-errors.sh
new file mode 100755
index 0000000..2b57f19
--- /dev/null
+++ b/test/pfn-meta-errors.sh
@@ -0,0 +1,74 @@ 
+#!/bin/bash -Ex
+
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2018 Intel Corporation. All rights reserved.
+
+blockdev=""
+rc=77
+
+. ./common
+
+force_raw()
+{
+	raw="$1"
+	$NDCTL disable-namespace "$dev"
+	echo "$raw" > "/sys/bus/nd/devices/$dev/force_raw"
+	$NDCTL enable-namespace "$dev"
+	echo "Set $dev to raw mode: $raw"
+	if [[ "$raw" == "1" ]]; then
+		raw_bdev=${blockdev}
+		test -b "/dev/$raw_bdev"
+	else
+		raw_bdev=""
+	fi
+}
+
+check_min_kver "4.20" || do_skip "may lack PFN metadata error handling"
+
+set -e
+trap 'err $LINENO' ERR
+
+# setup (reset nfit_test dimms)
+modprobe nfit_test
+$NDCTL disable-region -b $NFIT_TEST_BUS0 all
+$NDCTL zero-labels -b $NFIT_TEST_BUS0 all
+$NDCTL enable-region -b $NFIT_TEST_BUS0 all
+
+rc=1
+
+# create a fsdax namespace and clear errors (if any)
+dev="x"
+json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m fsdax)
+eval "$(echo "$json" | json2var)"
+[ $dev = "x" ] && echo "fail: $LINENO" && exit 1
+
+force_raw 1
+if read -r sector len < "/sys/block/$raw_bdev/badblocks"; then
+	dd of=/dev/$raw_bdev if=/dev/zero oflag=direct bs=512 seek="$sector" count="$len"
+fi
+force_raw 0
+
+# find dataoff from sb
+force_raw 1
+doff=$(hexdump -s $((4096 + 56)) -n 4 "/dev/$raw_bdev" | head -1 | cut -d' ' -f2-)
+doff=$(tr -d ' ' <<< "0x${doff#* }${doff%% *}")
+printf "pfn dataoff: %x\n" "$doff"
+dblk="$((doff/512))"
+
+metaoff="0x2000"
+mblk="$((metaoff/512))"
+
+# inject in the middle of the struct page area
+bb_inj=$(((dblk - mblk)/2))
+$NDCTL inject-error --block="$bb_inj" --count=32 $dev
+$NDCTL start-scrub && $NDCTL wait-scrub
+
+# after probe from the enable-namespace, the error should've been cleared
+force_raw 0
+force_raw 1
+if read -r sector len < "/sys/block/$raw_bdev/badblocks"; then
+	false
+fi
+
+_cleanup
+exit 0