From: Omar Sandoval Date: Fri, 18 Aug 2017 19:22:58 +0000 (-0700) Subject: loop: test direct I/O mode + custom block size X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cdeb97ed5b95b67af478146c57977933f7a72e36;p=users%2Fsagi%2Fblktests.git loop: test direct I/O mode + custom block size Signed-off-by: Omar Sandoval --- diff --git a/common/loop b/common/loop new file mode 100644 index 0000000..eb8027c --- /dev/null +++ b/common/loop @@ -0,0 +1,47 @@ +#!/bin/bash +# +# Loop device helper functions. +# +# Copyright (C) 2017 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 . + + +_have_lo_flags_blocksize() { + local tmpfile loop_dev + + # XXX: $TMPDIR isn't set up for requires(), should it be? + if ! tmpfile="$(mktemp "blktests.${TEST_NAME//\//.}.XXX")" || + ! truncate -s 1M "$tmpfile"; then + SKIP_REASON="could not create temporary file" + return 1 + fi + + if ! loop_dev="$(losetup -f --show "$tmpfile" 2>/dev/null)"; then + SKIP_REASON="could not get loop device" + rm -f "$tmpfile" + return 1 + fi + + if ! src/loblksize "$loop_dev" >/dev/null 2>&1; then + SKIP_REASON="kernel does not support LO_FLAGS_BLOCKSIZE" + losetup -d "$loop_dev" + rm -f "$tmpfile" + return 1 + fi + + losetup -d "$loop_dev" + rm -f "$tmpfile" + return 0 +} diff --git a/tests/loop/002 b/tests/loop/002 index 533e993..8f03070 100755 --- a/tests/loop/002 +++ b/tests/loop/002 @@ -22,39 +22,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +. common/loop + DESCRIPTION="try various loop device block sizes" QUICK=1 requires() { - local tmpfile loop_dev - - if ! _have_src_program loblksize; then - return 1 - fi - - # XXX: $TMPDIR isn't set up for requires(), should it be? - if ! tmpfile="$(mktemp "blktests.${TEST_NAME//\//.}.XXX")" || - ! truncate -s 1M "$tmpfile"; then - SKIP_REASON="could not create temporary file" - return 1 - fi - - if ! loop_dev="$(losetup -f --show "$tmpfile" 2>/dev/null)"; then - SKIP_REASON="could not get loop device" - rm -f "$tmpfile" - return 1 - fi - - if ! src/loblksize "$loop_dev" >/dev/null 2>&1; then - SKIP_REASON="kernel does not support LO_FLAGS_BLOCKSIZE" - losetup -d "$loop_dev" - rm -f "$tmpfile" - return 1 - fi - - losetup -d "$loop_dev" - rm -f "$tmpfile" - return 0 + _have_program xfs_io && _have_src_program loblksize && _have_lo_flags_blocksize } test() { diff --git a/tests/loop/004 b/tests/loop/004 new file mode 100755 index 0000000..c5c96e4 --- /dev/null +++ b/tests/loop/004 @@ -0,0 +1,55 @@ +#!/bin/bash +# +# Tests LO_FLAGS_BLOCKSIZE together with LO_FLAGS_DIRECT_IO. +# +# Copyright (C) 2017 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 . + +. common/loop +. common/scsi_debug + +DESCRIPTION="combine loop direct I/O mode and a custom block size" +QUICK=1 + +requires() { + _have_program xfs_io && _have_scsi_debug && _have_src_program loblksize && _have_lo_flags_blocksize +} + +test() { + local loop_dev + + echo "Running ${TEST_NAME}" + + if ! _init_scsi_debug sector_size=4096; then + return 1 + fi + + if ! loop_dev="$(losetup -f --show "/dev/${SCSI_DEBUG_DEVICES[0]}")"; then + _exit_scsi_debug + return 1 + fi + + src/loblksize "$loop_dev" 4096 + losetup --direct-io=on "$loop_dev" + cat "/sys/block/${loop_dev#/dev/}/loop/dio" + xfs_io -f -d -c 'pwrite 0 4096' "$loop_dev" >/dev/null + dd if="$loop_dev" bs=4096 count=1 iflag=direct status=none | sha256sum + + losetup -d "$loop_dev" + udevadm settle + _exit_scsi_debug + + echo "Test complete" +} diff --git a/tests/loop/004.out b/tests/loop/004.out new file mode 100644 index 0000000..787e80f --- /dev/null +++ b/tests/loop/004.out @@ -0,0 +1,4 @@ +Running loop/004 +1 +769bd186841c10e5b1106b55986206c0e87fc05a7f565fdee01b5abcaff6ae78 - +Test complete