xref: /openbmc/qemu/tests/qemu-iotests/142 (revision 871c71b1bad2d2647641500603a2236869135c7f)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
28f7acbe6SKevin Wolf#
38f7acbe6SKevin Wolf# Test for configuring cache modes of arbitrary nodes (requires O_DIRECT)
48f7acbe6SKevin Wolf#
58f7acbe6SKevin Wolf# Copyright (C) 2015 Red Hat, Inc.
68f7acbe6SKevin Wolf#
78f7acbe6SKevin Wolf# This program is free software; you can redistribute it and/or modify
88f7acbe6SKevin Wolf# it under the terms of the GNU General Public License as published by
98f7acbe6SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
108f7acbe6SKevin Wolf# (at your option) any later version.
118f7acbe6SKevin Wolf#
128f7acbe6SKevin Wolf# This program is distributed in the hope that it will be useful,
138f7acbe6SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
148f7acbe6SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
158f7acbe6SKevin Wolf# GNU General Public License for more details.
168f7acbe6SKevin Wolf#
178f7acbe6SKevin Wolf# You should have received a copy of the GNU General Public License
188f7acbe6SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
198f7acbe6SKevin Wolf#
208f7acbe6SKevin Wolf
218f7acbe6SKevin Wolf# creator
228f7acbe6SKevin Wolfowner=kwolf@redhat.com
238f7acbe6SKevin Wolf
248f7acbe6SKevin Wolfseq=`basename $0`
258f7acbe6SKevin Wolfecho "QA output created by $seq"
268f7acbe6SKevin Wolf
278f7acbe6SKevin Wolfstatus=1	# failure is the default!
288f7acbe6SKevin Wolf
298f7acbe6SKevin Wolf_cleanup()
308f7acbe6SKevin Wolf{
318f7acbe6SKevin Wolf    _cleanup_test_img
32f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.snap"
338f7acbe6SKevin Wolf}
348f7acbe6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
358f7acbe6SKevin Wolf
368f7acbe6SKevin Wolf# get standard environment, filters and checks
378f7acbe6SKevin Wolf. ./common.rc
388f7acbe6SKevin Wolf. ./common.filter
398f7acbe6SKevin Wolf
408f7acbe6SKevin Wolf_supported_fmt qcow2
418f7acbe6SKevin Wolf_supported_proto file
428f7acbe6SKevin Wolf
438f7acbe6SKevin Wolf# We test all cache modes anyway, but O_DIRECT needs to be supported
448f7acbe6SKevin Wolf_default_cache_mode none
458f7acbe6SKevin Wolf_supported_cache_modes none directsync
468f7acbe6SKevin Wolf
478cedcffdSEric Blakedo_run_qemu()
488f7acbe6SKevin Wolf{
498f7acbe6SKevin Wolf    echo Testing: "$@"
508f7acbe6SKevin Wolf    (
518f7acbe6SKevin Wolf        if ! test -t 0; then
528f7acbe6SKevin Wolf            while read cmd; do
538f7acbe6SKevin Wolf                echo $cmd
548f7acbe6SKevin Wolf            done
558f7acbe6SKevin Wolf        fi
568f7acbe6SKevin Wolf        echo quit
578f7acbe6SKevin Wolf    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
588f7acbe6SKevin Wolf    echo
598f7acbe6SKevin Wolf}
608f7acbe6SKevin Wolf
618cedcffdSEric Blakerun_qemu()
628f7acbe6SKevin Wolf{
6369404d9eSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp
648f7acbe6SKevin Wolf}
658f7acbe6SKevin Wolf
668f7acbe6SKevin Wolfsize=128M
678f7acbe6SKevin Wolf
688f7acbe6SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size
698f7acbe6SKevin WolfTEST_IMG="$TEST_IMG.snap" _make_test_img $size
70b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" $size -F $IMGFMT
718f7acbe6SKevin Wolf
728f7acbe6SKevin Wolfecho
738f7acbe6SKevin Wolfecho === Simple test for all cache modes ===
748f7acbe6SKevin Wolfecho
758f7acbe6SKevin Wolf
768f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=none
778f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=directsync
788f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=writeback
798f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=writethrough
808f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=unsafe
818f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=invalid_value
828f7acbe6SKevin Wolf
838f7acbe6SKevin Wolfecho
848f7acbe6SKevin Wolfecho === Check inheritance of cache modes ===
858f7acbe6SKevin Wolfecho
868f7acbe6SKevin Wolf
878f7acbe6SKevin Wolffiles="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
888f7acbe6SKevin Wolfids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
898f7acbe6SKevin Wolf
908cedcffdSEric Blakecheck_cache_all()
918f7acbe6SKevin Wolf{
928f7acbe6SKevin Wolf    # cache.direct is supposed to be inherited by both bs->file and
938f7acbe6SKevin Wolf    # bs->backing
948f7acbe6SKevin Wolf
95b43671f8SEric Blake    printf "cache.direct=on on none0\n"
9673ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
97b43671f8SEric Blake    printf "\ncache.direct=on on file\n"
9873ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
99b43671f8SEric Blake    printf "\ncache.direct=on on backing\n"
10073ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
101b43671f8SEric Blake    printf "\ncache.direct=on on backing-file\n"
10273ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
1038f7acbe6SKevin Wolf
1048f7acbe6SKevin Wolf    # cache.writeback is supposed to be inherited by bs->backing; bs->file
1058f7acbe6SKevin Wolf    # always gets cache.writeback=on
1068f7acbe6SKevin Wolf
107b43671f8SEric Blake    printf "\n\ncache.writeback=off on none0\n"
10873ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
109b43671f8SEric Blake    printf "\ncache.writeback=off on file\n"
11061de4c68SKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "doesn't" -e "does not"
111b43671f8SEric Blake    printf "\ncache.writeback=off on backing\n"
11261de4c68SKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "doesn't" -e "does not"
113b43671f8SEric Blake    printf "\ncache.writeback=off on backing-file\n"
11461de4c68SKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "doesn't" -e "does not"
1158f7acbe6SKevin Wolf
1168f7acbe6SKevin Wolf    # cache.no-flush is supposed to be inherited by both bs->file and bs->backing
1178f7acbe6SKevin Wolf
118b43671f8SEric Blake    printf "\n\ncache.no-flush=on on none0\n"
11973ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
120b43671f8SEric Blake    printf "\ncache.no-flush=on on file\n"
12173ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
122b43671f8SEric Blake    printf "\ncache.no-flush=on on backing\n"
12373ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
124b43671f8SEric Blake    printf "\ncache.no-flush=on on backing-file\n"
12573ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
1268f7acbe6SKevin Wolf}
1278f7acbe6SKevin Wolf
1288f7acbe6SKevin Wolfecho
1298f7acbe6SKevin Wolfecho "--- Configure cache modes on the command line ---"
1308f7acbe6SKevin Wolfecho
1318f7acbe6SKevin Wolf
1328f7acbe6SKevin Wolf# First check the inherited cache mode after opening the image.
1338f7acbe6SKevin Wolf
134c83f9fbaSKevin Wolfhmp_cmds="info block none0
135c83f9fbaSKevin Wolfinfo block image
1368f7acbe6SKevin Wolfinfo block file
1378f7acbe6SKevin Wolfinfo block backing
1388f7acbe6SKevin Wolfinfo block backing-file"
1398f7acbe6SKevin Wolf
1408f7acbe6SKevin Wolfcheck_cache_all
1418f7acbe6SKevin Wolf
1428f7acbe6SKevin Wolfecho
1438f7acbe6SKevin Wolfecho "--- Cache modes after reopen (live snapshot) ---"
1448f7acbe6SKevin Wolfecho
1458f7acbe6SKevin Wolf
1468f7acbe6SKevin Wolf# Then trigger a reopen and check that the cache modes are still the same.
1478f7acbe6SKevin Wolf
1488f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
1498f7acbe6SKevin Wolfinfo block
1508f7acbe6SKevin Wolfinfo block image
1518f7acbe6SKevin Wolfinfo block file
1528f7acbe6SKevin Wolfinfo block backing
1538f7acbe6SKevin Wolfinfo block backing-file"
1548f7acbe6SKevin Wolf
1558f7acbe6SKevin Wolfcheck_cache_all
1568f7acbe6SKevin Wolf
1578f7acbe6SKevin Wolfecho
1588f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, flags) ---"
1598f7acbe6SKevin Wolfecho
1608f7acbe6SKevin Wolf
1618f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
1628f7acbe6SKevin Wolf# new cache mode is specified in the flags, not as an option.
1638f7acbe6SKevin Wolf
1648f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -c none"
165c83f9fbaSKevin Wolfinfo block none0
1668f7acbe6SKevin Wolfinfo block image
1678f7acbe6SKevin Wolfinfo block file
1688f7acbe6SKevin Wolfinfo block backing
1698f7acbe6SKevin Wolfinfo block backing-file'
1708f7acbe6SKevin Wolf
1718f7acbe6SKevin Wolfcheck_cache_all
1728f7acbe6SKevin Wolf
1738f7acbe6SKevin Wolfecho
1748f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, options) ---"
1758f7acbe6SKevin Wolfecho
1768f7acbe6SKevin Wolf
1778f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
1788f7acbe6SKevin Wolf# new cache mode is specified as an option, not in the flags.
1798f7acbe6SKevin Wolf
1808f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -o cache.direct=on"
181c83f9fbaSKevin Wolfinfo block none0
1828f7acbe6SKevin Wolfinfo block image
1838f7acbe6SKevin Wolfinfo block file
1848f7acbe6SKevin Wolfinfo block backing
1858f7acbe6SKevin Wolfinfo block backing-file'
1868f7acbe6SKevin Wolf
1878f7acbe6SKevin Wolfcheck_cache_all
1888f7acbe6SKevin Wolf
1898f7acbe6SKevin Wolfecho
1908f7acbe6SKevin Wolfecho "--- Change cache modes after snapshot ---"
1918f7acbe6SKevin Wolfecho
1928f7acbe6SKevin Wolf
1938f7acbe6SKevin Wolf# This checks that the original image doesn't inherit from the snapshot
1948f7acbe6SKevin Wolf
1958f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
1968f7acbe6SKevin Wolfqemu-io none0 \"reopen -c none\"
1978f7acbe6SKevin Wolfinfo block none0
1988f7acbe6SKevin Wolfinfo block image
1998f7acbe6SKevin Wolfinfo block file
2008f7acbe6SKevin Wolfinfo block backing
2018f7acbe6SKevin Wolfinfo block backing-file"
2028f7acbe6SKevin Wolf
2038f7acbe6SKevin Wolfcheck_cache_all
2048f7acbe6SKevin Wolf
2058f7acbe6SKevin Wolfecho
2068f7acbe6SKevin Wolfecho "--- Change cache mode in parent, child has explicit option in JSON ---"
2078f7acbe6SKevin Wolfecho
2088f7acbe6SKevin Wolf
2098f7acbe6SKevin Wolf# This checks that children with options explicitly set by the json:
2108f7acbe6SKevin Wolf# pseudo-protocol don't inherit these options from their parents.
2118f7acbe6SKevin Wolf#
2128f7acbe6SKevin Wolf# Yes, blkdebug::json:... is criminal, but I can't see another way to have a
2138f7acbe6SKevin Wolf# BDS initialised with the json: pseudo-protocol, but still have it inherit
2148f7acbe6SKevin Wolf# options from its parent node.
2158f7acbe6SKevin Wolf
21619dbecdcSKevin Wolfhmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\"
217c83f9fbaSKevin Wolfinfo block none0
2188f7acbe6SKevin Wolfinfo block image
2198f7acbe6SKevin Wolfinfo block blkdebug
2208f7acbe6SKevin Wolfinfo block file"
2218f7acbe6SKevin Wolf
22273ac451fSKevin Wolfecho "$hmp_cmds" | run_qemu -drive if=none,file="blkdebug::json:{\"filename\":\"$TEST_IMG\",,\"cache\":{\"direct\":false}}",node-name=image,file.node-name=blkdebug,file.image.node-name=file | grep "Cache"
2238f7acbe6SKevin Wolf
2248f7acbe6SKevin Wolfecho
2258f7acbe6SKevin Wolfecho "=== Check that referenced BDSes don't inherit ==="
2268f7acbe6SKevin Wolfecho
2278f7acbe6SKevin Wolf
2288f7acbe6SKevin Wolfdrv_bkfile="if=none,driver=file,filename=$TEST_IMG.base,node-name=backing-file"
2298f7acbe6SKevin Wolfdrv_bk="if=none,file=json:{'driver':'$IMGFMT',,'file':'backing-file',,'node-name':'backing'}"
2308f7acbe6SKevin Wolfdrv_file="if=none,driver=file,filename=$TEST_IMG,node-name=file"
2318f7acbe6SKevin Wolfdrv_img="if=none,id=blk,file=json:{'driver':'$IMGFMT',,'file':'file',,'backing':'backing',,'node-name':'image'}"
2328f7acbe6SKevin Wolf
2338cedcffdSEric Blakecheck_cache_all_separate()
2348f7acbe6SKevin Wolf{
2358f7acbe6SKevin Wolf    # Check cache.direct
2368f7acbe6SKevin Wolf
237b43671f8SEric Blake    printf "cache.direct=on on blk\n"
23873ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img",cache.direct=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
239b43671f8SEric Blake    printf "\ncache.direct=on on file\n"
24073ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file",cache.direct=on -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
241b43671f8SEric Blake    printf "\ncache.direct=on on backing\n"
24273ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cache.direct=on -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
243b43671f8SEric Blake    printf "\ncache.direct=on on backing-file\n"
24473ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.direct=on -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
2458f7acbe6SKevin Wolf
2468f7acbe6SKevin Wolf    # Check cache.writeback
2478f7acbe6SKevin Wolf
248b43671f8SEric Blake    printf "\n\ncache.writeback=off on blk\n"
24973ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
250b43671f8SEric Blake    printf "\ncache.writeback=off on file\n"
25173ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file",cache.writeback=off -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
252b43671f8SEric Blake    printf "\ncache.writeback=off on backing\n"
25373ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cache.writeback=off -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
254b43671f8SEric Blake    printf "\ncache.writeback=off on backing-file\n"
25573ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.writeback=off -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
2568f7acbe6SKevin Wolf
2578f7acbe6SKevin Wolf    # Check cache.no-flush
2588f7acbe6SKevin Wolf
259b43671f8SEric Blake    printf "\n\ncache.no-flush=on on blk\n"
26073ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img",cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
261b43671f8SEric Blake    printf "\ncache.no-flush=on on file\n"
26273ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file",cache.no-flush=on -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
263b43671f8SEric Blake    printf "\ncache.no-flush=on on backing\n"
26473ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cache.no-flush=on -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
265b43671f8SEric Blake    printf "\ncache.no-flush=on on backing-file\n"
26673ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.no-flush=on -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
2678f7acbe6SKevin Wolf}
2688f7acbe6SKevin Wolf
2698f7acbe6SKevin Wolfecho
2708f7acbe6SKevin Wolfecho "--- Configure cache modes on the command line ---"
2718f7acbe6SKevin Wolfecho
2728f7acbe6SKevin Wolf
2738f7acbe6SKevin Wolf# First check the inherited cache mode after opening the image.
2748f7acbe6SKevin Wolf
2758f7acbe6SKevin Wolfhmp_cmds="info block image
2768f7acbe6SKevin Wolfinfo block file
2778f7acbe6SKevin Wolfinfo block backing
2788f7acbe6SKevin Wolfinfo block backing-file"
2798f7acbe6SKevin Wolf
2808f7acbe6SKevin Wolfcheck_cache_all_separate
2818f7acbe6SKevin Wolf
2828f7acbe6SKevin Wolfecho
2838f7acbe6SKevin Wolfecho "--- Cache modes after reopen (live snapshot) ---"
2848f7acbe6SKevin Wolfecho
2858f7acbe6SKevin Wolf
2868f7acbe6SKevin Wolf# Then trigger a reopen and check that the cache modes are still the same.
2878f7acbe6SKevin Wolf
2888f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n blk $TEST_IMG.snap $IMGFMT
2898f7acbe6SKevin Wolfinfo block blk
2908f7acbe6SKevin Wolfinfo block image
2918f7acbe6SKevin Wolfinfo block file
2928f7acbe6SKevin Wolfinfo block backing
2938f7acbe6SKevin Wolfinfo block backing-file"
2948f7acbe6SKevin Wolf
2958f7acbe6SKevin Wolfcheck_cache_all_separate
2968f7acbe6SKevin Wolf
2978f7acbe6SKevin Wolfecho
2988f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, flags) ---"
2998f7acbe6SKevin Wolfecho
3008f7acbe6SKevin Wolf
3018f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
3028f7acbe6SKevin Wolf# new cache mode is specified as flags, not as option.
3038f7acbe6SKevin Wolf
3048f7acbe6SKevin Wolfhmp_cmds='qemu-io blk "reopen -c none"
3058f7acbe6SKevin Wolfinfo block image
3068f7acbe6SKevin Wolfinfo block file
3078f7acbe6SKevin Wolfinfo block backing
3088f7acbe6SKevin Wolfinfo block backing-file'
3098f7acbe6SKevin Wolf
3108f7acbe6SKevin Wolfcheck_cache_all_separate
3118f7acbe6SKevin Wolf
3128f7acbe6SKevin Wolf
3138f7acbe6SKevin Wolfecho
3148f7acbe6SKevin Wolfecho "=== Reopening children instead of the root ==="
3158f7acbe6SKevin Wolfecho
3168f7acbe6SKevin Wolf
3178f7acbe6SKevin Wolffiles="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
3188f7acbe6SKevin Wolfids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
3198f7acbe6SKevin Wolf
3208f7acbe6SKevin Wolfecho
3218f7acbe6SKevin Wolfecho "--- Basic reopen ---"
3228f7acbe6SKevin Wolfecho
3238f7acbe6SKevin Wolf
3248f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on"
325c83f9fbaSKevin Wolfinfo block none0
3268f7acbe6SKevin Wolfinfo block image
3278f7acbe6SKevin Wolfinfo block file
3288f7acbe6SKevin Wolfinfo block backing
3298f7acbe6SKevin Wolfinfo block backing-file'
3308f7acbe6SKevin Wolf
3318f7acbe6SKevin Wolfcheck_cache_all
3328f7acbe6SKevin Wolf
3338f7acbe6SKevin Wolfecho
3348f7acbe6SKevin Wolfecho "--- Change cache mode after reopening child ---"
3358f7acbe6SKevin Wolfecho
3368f7acbe6SKevin Wolf
3378f7acbe6SKevin Wolf# This checks that children with options explicitly set with reopen don't
3388f7acbe6SKevin Wolf# inherit these options from their parents any more
3398f7acbe6SKevin Wolf
3408f7acbe6SKevin Wolf# TODO Implement node-name support for 'qemu-io' HMP command for -c
3418f7acbe6SKevin Wolf# Can use only -o to access child node options for now
3428f7acbe6SKevin Wolf
343bfd18d1eSKevin Wolfhmp_cmds="qemu-io none0 \"reopen -o file.cache.direct=off,file.cache.no-flush=off\"
344bfd18d1eSKevin Wolfqemu-io none0 \"reopen -o backing.file.cache.direct=off,backing.file.cache.no-flush=on\"
3458f7acbe6SKevin Wolfqemu-io none0 \"reopen -c none\"
3468f7acbe6SKevin Wolfinfo block image
3478f7acbe6SKevin Wolfinfo block file
3488f7acbe6SKevin Wolfinfo block backing
3498f7acbe6SKevin Wolfinfo block backing-file"
3508f7acbe6SKevin Wolf
3518f7acbe6SKevin Wolfecho "$hmp_cmds" | run_qemu -drive "$files","$ids" | grep "Cache"
3528f7acbe6SKevin Wolf
353*5dbd0ce1SKevin Wolfecho
354*5dbd0ce1SKevin Wolfecho "--- Alignment after changing O_DIRECT ---"
355*5dbd0ce1SKevin Wolfecho
356*5dbd0ce1SKevin Wolf
357*5dbd0ce1SKevin Wolf# Directly test the protocol level: Can unaligned requests succeed even if
358*5dbd0ce1SKevin Wolf# O_DIRECT was only enabled through a reopen and vice versa?
359*5dbd0ce1SKevin Wolf
360*5dbd0ce1SKevin Wolf# Ensure image size is a multiple of the sector size (required for O_DIRECT)
361*5dbd0ce1SKevin Wolf$QEMU_IMG create -f file "$TEST_IMG" 1M | _filter_img_create
362*5dbd0ce1SKevin Wolf
363*5dbd0ce1SKevin Wolf# And write some data (not strictly necessary, but it feels better to actually
364*5dbd0ce1SKevin Wolf# have something to be read)
365*5dbd0ce1SKevin Wolf$QEMU_IO -f file -c 'write 0 4096' "$TEST_IMG" | _filter_qemu_io
366*5dbd0ce1SKevin Wolf
367*5dbd0ce1SKevin Wolf$QEMU_IO --cache=writeback -f file $TEST_IMG <<EOF | _filter_qemu_io
368*5dbd0ce1SKevin Wolfread 42 42
369*5dbd0ce1SKevin Wolfreopen -o cache.direct=on
370*5dbd0ce1SKevin Wolfread 42 42
371*5dbd0ce1SKevin Wolfreopen -o cache.direct=off
372*5dbd0ce1SKevin Wolfread 42 42
373*5dbd0ce1SKevin WolfEOF
374*5dbd0ce1SKevin Wolf$QEMU_IO --cache=none -f file $TEST_IMG <<EOF | _filter_qemu_io
375*5dbd0ce1SKevin Wolfread 42 42
376*5dbd0ce1SKevin Wolfreopen -o cache.direct=off
377*5dbd0ce1SKevin Wolfread 42 42
378*5dbd0ce1SKevin Wolfreopen -o cache.direct=on
379*5dbd0ce1SKevin Wolfread 42 42
380*5dbd0ce1SKevin WolfEOF
381*5dbd0ce1SKevin Wolf
3828f7acbe6SKevin Wolf# success, all done
3838f7acbe6SKevin Wolfecho "*** done"
3848f7acbe6SKevin Wolfrm -f $seq.full
3858f7acbe6SKevin Wolfstatus=0
386