Commit cfdca2b9 authored by Vladimir Sementsov-Ogievskiy's avatar Vladimir Sementsov-Ogievskiy Committed by Kevin Wolf
Browse files

iotests: handle tmpfs



Some tests requires O_DIRECT, or want it by default. Introduce smarter
O_DIRECT handling:

- Check O_DIRECT in common.rc, if it is requested by selected
cache-mode.

- Support second fall-through argument in _default_cache_mode

Inspired-by: Max's 23e1d054
Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200430124713.3067-2-vsementsov@virtuozzo.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 1b8c4589
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
_supported_fmt qcow2
_supported_proto file
_supported_os Linux
_default_cache_mode none
_supported_cache_modes writethrough none writeback
_default_cache_mode none writeback

size=1G

+35 −2
Original line number Diff line number Diff line
@@ -673,11 +673,44 @@ _supported_cache_modes()
    _notrun "not suitable for cache mode: $CACHEMODE"
}

# Check whether the filesystem supports O_DIRECT
_check_o_direct()
{
    $QEMU_IMG create -f raw "$TEST_IMG".test_o_direct 1M > /dev/null
    out=$($QEMU_IO -f raw -t none -c quit "$TEST_IMG".test_o_direct 2>&1)
    rm -f "$TEST_IMG".test_o_direct

    [[ "$out" != *"O_DIRECT"* ]]
}

_require_o_direct()
{
    if ! _check_o_direct; then
        _notrun "file system on $TEST_DIR does not support O_DIRECT"
    fi
}

_check_cache_mode()
{
    if [ $CACHEMODE == "none" ] || [ $CACHEMODE == "directsync" ]; then
        _require_o_direct
    fi
}

_check_cache_mode

# $1 - cache mode to use by default
# $2 - (optional) cache mode to use by default if O_DIRECT is not supported
_default_cache_mode()
{
    if $CACHEMODE_IS_DEFAULT; then
        if [ -z "$2" ] || _check_o_direct; then
            CACHEMODE="$1"
        QEMU_IO="$QEMU_IO --cache $1"
        else
            CACHEMODE="$2"
        fi
        QEMU_IO="$QEMU_IO --cache $CACHEMODE"
        _check_cache_mode
        return
    fi
}