--- /dev/null
+#!/bin/bash
+#
+# Test the inflight counter in /sys/block/$dev/inflight and /proc/diskstats.
+# Regression test for patch "blk-mq: fix sysfs inflight counter".
+#
+# Copyright (C) 2018 Omar Sandoval
+#
+# 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, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>.
+
+DESCRIPTION="do I/O and check the inflight counter"
+QUICK=1
+
+requires() {
+ _have_module null_blk
+}
+
+show_inflight() {
+ awk '{ printf "sysfs reads %d\nsysfs writes %d\n", $1, $2 }' /sys/block/nullb0/inflight
+ awk '$3 == "nullb0" { print "diskstats " $12 }' /proc/diskstats
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ for ((queue_mode = 1; queue_mode <= 2; queue_mode++)) do
+ echo "queue mode $queue_mode"
+
+ modprobe -r null_blk
+ modprobe null_blk queue_mode="$queue_mode" irqmode=2 \
+ completion_nsec=500000000 || continue
+
+ udevadm settle
+
+ dd if=/dev/nullb0 of=/dev/null bs=4096 iflag=direct count=1 status=none &
+ sleep 0.1
+ show_inflight
+
+ dd if=/dev/zero of=/dev/nullb0 bs=4096 oflag=direct count=1 status=none &
+ sleep 0.1
+ show_inflight
+
+ wait
+ show_inflight
+
+ modprobe -r null_blk
+ done
+
+ echo "Test complete"
+}