xref: /qemu/tests/qemu-iotests/142 (revision 19dbecdceef3f0800a96c25931d71b0b82c3a47a)
18f7acbe6SKevin Wolf#!/bin/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 Wolfhere=`pwd`
288f7acbe6SKevin Wolftmp=/tmp/$$
298f7acbe6SKevin Wolfstatus=1	# failure is the default!
308f7acbe6SKevin Wolf
318f7acbe6SKevin Wolf_cleanup()
328f7acbe6SKevin Wolf{
338f7acbe6SKevin Wolf    _cleanup_test_img
348f7acbe6SKevin Wolf    rm -f $TEST_IMG.snap
358f7acbe6SKevin Wolf}
368f7acbe6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
378f7acbe6SKevin Wolf
388f7acbe6SKevin Wolf# get standard environment, filters and checks
398f7acbe6SKevin Wolf. ./common.rc
408f7acbe6SKevin Wolf. ./common.filter
418f7acbe6SKevin Wolf
428f7acbe6SKevin Wolf_supported_fmt qcow2
438f7acbe6SKevin Wolf_supported_proto file
448f7acbe6SKevin Wolf_supported_os Linux
458f7acbe6SKevin Wolf
468f7acbe6SKevin Wolf# We test all cache modes anyway, but O_DIRECT needs to be supported
478f7acbe6SKevin Wolf_default_cache_mode none
488f7acbe6SKevin Wolf_supported_cache_modes none directsync
498f7acbe6SKevin Wolf
508f7acbe6SKevin Wolffunction do_run_qemu()
518f7acbe6SKevin Wolf{
528f7acbe6SKevin Wolf    echo Testing: "$@"
538f7acbe6SKevin Wolf    (
548f7acbe6SKevin Wolf        if ! test -t 0; then
558f7acbe6SKevin Wolf            while read cmd; do
568f7acbe6SKevin Wolf                echo $cmd
578f7acbe6SKevin Wolf            done
588f7acbe6SKevin Wolf        fi
598f7acbe6SKevin Wolf        echo quit
608f7acbe6SKevin Wolf    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
618f7acbe6SKevin Wolf    echo
628f7acbe6SKevin Wolf}
638f7acbe6SKevin Wolf
648f7acbe6SKevin Wolffunction run_qemu()
658f7acbe6SKevin Wolf{
668f7acbe6SKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu
678f7acbe6SKevin Wolf}
688f7acbe6SKevin Wolf
698f7acbe6SKevin Wolfsize=128M
708f7acbe6SKevin Wolf
718f7acbe6SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size
728f7acbe6SKevin WolfTEST_IMG="$TEST_IMG.snap" _make_test_img $size
738f7acbe6SKevin Wolf_make_test_img -b "$TEST_IMG.base" $size
748f7acbe6SKevin Wolf
758f7acbe6SKevin Wolfecho
768f7acbe6SKevin Wolfecho === Simple test for all cache modes ===
778f7acbe6SKevin Wolfecho
788f7acbe6SKevin Wolf
798f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=none
808f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=directsync
818f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=writeback
828f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=writethrough
838f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=unsafe
848f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=invalid_value
858f7acbe6SKevin Wolf
868f7acbe6SKevin Wolfecho
878f7acbe6SKevin Wolfecho === Check inheritance of cache modes ===
888f7acbe6SKevin Wolfecho
898f7acbe6SKevin Wolf
908f7acbe6SKevin Wolffiles="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
918f7acbe6SKevin Wolfids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
928f7acbe6SKevin Wolf
938f7acbe6SKevin Wolffunction check_cache_all()
948f7acbe6SKevin Wolf{
958f7acbe6SKevin Wolf    # cache.direct is supposed to be inherited by both bs->file and
968f7acbe6SKevin Wolf    # bs->backing
978f7acbe6SKevin Wolf
988f7acbe6SKevin Wolf    echo -e "cache.direct=on on none0"
9973ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
1008f7acbe6SKevin Wolf    echo -e "\ncache.direct=on on file"
10173ac451fSKevin 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"
1028f7acbe6SKevin Wolf    echo -e "\ncache.direct=on on backing"
10373ac451fSKevin 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"
1048f7acbe6SKevin Wolf    echo -e "\ncache.direct=on on backing-file"
10573ac451fSKevin 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"
1068f7acbe6SKevin Wolf
1078f7acbe6SKevin Wolf    # cache.writeback is supposed to be inherited by bs->backing; bs->file
1088f7acbe6SKevin Wolf    # always gets cache.writeback=on
1098f7acbe6SKevin Wolf
1108f7acbe6SKevin Wolf    echo -e "\n\ncache.writeback=off on none0"
11173ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
1128f7acbe6SKevin Wolf    echo -e "\ncache.writeback=off on file"
11373ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
1148f7acbe6SKevin Wolf    echo -e "\ncache.writeback=off on backing"
11573ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
1168f7acbe6SKevin Wolf    echo -e "\ncache.writeback=off on backing-file"
11773ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
1188f7acbe6SKevin Wolf
1198f7acbe6SKevin Wolf    # cache.no-flush is supposed to be inherited by both bs->file and bs->backing
1208f7acbe6SKevin Wolf
1218f7acbe6SKevin Wolf    echo -e "\n\ncache.no-flush=on on none0"
12273ac451fSKevin 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"
1238f7acbe6SKevin Wolf    echo -e "\ncache.no-flush=on on file"
12473ac451fSKevin 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"
1258f7acbe6SKevin Wolf    echo -e "\ncache.no-flush=on on backing"
12673ac451fSKevin 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"
1278f7acbe6SKevin Wolf    echo -e "\ncache.no-flush=on on backing-file"
12873ac451fSKevin 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"
1298f7acbe6SKevin Wolf}
1308f7acbe6SKevin Wolf
1318f7acbe6SKevin Wolfecho
1328f7acbe6SKevin Wolfecho "--- Configure cache modes on the command line ---"
1338f7acbe6SKevin Wolfecho
1348f7acbe6SKevin Wolf
1358f7acbe6SKevin Wolf# First check the inherited cache mode after opening the image.
1368f7acbe6SKevin Wolf
137c83f9fbaSKevin Wolfhmp_cmds="info block none0
138c83f9fbaSKevin Wolfinfo block image
1398f7acbe6SKevin Wolfinfo block file
1408f7acbe6SKevin Wolfinfo block backing
1418f7acbe6SKevin Wolfinfo block backing-file"
1428f7acbe6SKevin Wolf
1438f7acbe6SKevin Wolfcheck_cache_all
1448f7acbe6SKevin Wolf
1458f7acbe6SKevin Wolfecho
1468f7acbe6SKevin Wolfecho "--- Cache modes after reopen (live snapshot) ---"
1478f7acbe6SKevin Wolfecho
1488f7acbe6SKevin Wolf
1498f7acbe6SKevin Wolf# Then trigger a reopen and check that the cache modes are still the same.
1508f7acbe6SKevin Wolf
1518f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
1528f7acbe6SKevin Wolfinfo block
1538f7acbe6SKevin Wolfinfo block image
1548f7acbe6SKevin Wolfinfo block file
1558f7acbe6SKevin Wolfinfo block backing
1568f7acbe6SKevin Wolfinfo block backing-file"
1578f7acbe6SKevin Wolf
1588f7acbe6SKevin Wolfcheck_cache_all
1598f7acbe6SKevin Wolf
1608f7acbe6SKevin Wolfecho
1618f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, flags) ---"
1628f7acbe6SKevin Wolfecho
1638f7acbe6SKevin Wolf
1648f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
1658f7acbe6SKevin Wolf# new cache mode is specified in the flags, not as an option.
1668f7acbe6SKevin Wolf
1678f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -c none"
168c83f9fbaSKevin Wolfinfo block none0
1698f7acbe6SKevin Wolfinfo block image
1708f7acbe6SKevin Wolfinfo block file
1718f7acbe6SKevin Wolfinfo block backing
1728f7acbe6SKevin Wolfinfo block backing-file'
1738f7acbe6SKevin Wolf
1748f7acbe6SKevin Wolfcheck_cache_all
1758f7acbe6SKevin Wolf
1768f7acbe6SKevin Wolfecho
1778f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, options) ---"
1788f7acbe6SKevin Wolfecho
1798f7acbe6SKevin Wolf
1808f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
1818f7acbe6SKevin Wolf# new cache mode is specified as an option, not in the flags.
1828f7acbe6SKevin Wolf
1838f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -o cache.direct=on"
184c83f9fbaSKevin Wolfinfo block none0
1858f7acbe6SKevin Wolfinfo block image
1868f7acbe6SKevin Wolfinfo block file
1878f7acbe6SKevin Wolfinfo block backing
1888f7acbe6SKevin Wolfinfo block backing-file'
1898f7acbe6SKevin Wolf
1908f7acbe6SKevin Wolfcheck_cache_all
1918f7acbe6SKevin Wolf
1928f7acbe6SKevin Wolfecho
1938f7acbe6SKevin Wolfecho "--- Change cache modes after snapshot ---"
1948f7acbe6SKevin Wolfecho
1958f7acbe6SKevin Wolf
1968f7acbe6SKevin Wolf# This checks that the original image doesn't inherit from the snapshot
1978f7acbe6SKevin Wolf
1988f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
1998f7acbe6SKevin Wolfqemu-io none0 \"reopen -c none\"
2008f7acbe6SKevin Wolfinfo block none0
2018f7acbe6SKevin Wolfinfo block image
2028f7acbe6SKevin Wolfinfo block file
2038f7acbe6SKevin Wolfinfo block backing
2048f7acbe6SKevin Wolfinfo block backing-file"
2058f7acbe6SKevin Wolf
2068f7acbe6SKevin Wolfcheck_cache_all
2078f7acbe6SKevin Wolf
2088f7acbe6SKevin Wolfecho
2098f7acbe6SKevin Wolfecho "--- Change cache mode in parent, child has explicit option in JSON ---"
2108f7acbe6SKevin Wolfecho
2118f7acbe6SKevin Wolf
2128f7acbe6SKevin Wolf# This checks that children with options explicitly set by the json:
2138f7acbe6SKevin Wolf# pseudo-protocol don't inherit these options from their parents.
2148f7acbe6SKevin Wolf#
2158f7acbe6SKevin Wolf# Yes, blkdebug::json:... is criminal, but I can't see another way to have a
2168f7acbe6SKevin Wolf# BDS initialised with the json: pseudo-protocol, but still have it inherit
2178f7acbe6SKevin Wolf# options from its parent node.
2188f7acbe6SKevin Wolf
219*19dbecdcSKevin Wolfhmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\"
220c83f9fbaSKevin Wolfinfo block none0
2218f7acbe6SKevin Wolfinfo block image
2228f7acbe6SKevin Wolfinfo block blkdebug
2238f7acbe6SKevin Wolfinfo block file"
2248f7acbe6SKevin Wolf
22573ac451fSKevin 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"
2268f7acbe6SKevin Wolf
2278f7acbe6SKevin Wolfecho
2288f7acbe6SKevin Wolfecho "=== Check that referenced BDSes don't inherit ==="
2298f7acbe6SKevin Wolfecho
2308f7acbe6SKevin Wolf
2318f7acbe6SKevin Wolfdrv_bkfile="if=none,driver=file,filename=$TEST_IMG.base,node-name=backing-file"
2328f7acbe6SKevin Wolfdrv_bk="if=none,file=json:{'driver':'$IMGFMT',,'file':'backing-file',,'node-name':'backing'}"
2338f7acbe6SKevin Wolfdrv_file="if=none,driver=file,filename=$TEST_IMG,node-name=file"
2348f7acbe6SKevin Wolfdrv_img="if=none,id=blk,file=json:{'driver':'$IMGFMT',,'file':'file',,'backing':'backing',,'node-name':'image'}"
2358f7acbe6SKevin Wolf
2368f7acbe6SKevin Wolffunction check_cache_all_separate()
2378f7acbe6SKevin Wolf{
2388f7acbe6SKevin Wolf    # Check cache.direct
2398f7acbe6SKevin Wolf
2408f7acbe6SKevin Wolf    echo -e "cache.direct=on on blk"
24173ac451fSKevin 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"
2428f7acbe6SKevin Wolf    echo -e "\ncache.direct=on on file"
24373ac451fSKevin 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"
2448f7acbe6SKevin Wolf    echo -e "\ncache.direct=on on backing"
24573ac451fSKevin 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"
2468f7acbe6SKevin Wolf    echo -e "\ncache.direct=on on backing-file"
24773ac451fSKevin 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"
2488f7acbe6SKevin Wolf
2498f7acbe6SKevin Wolf    # Check cache.writeback
2508f7acbe6SKevin Wolf
2518f7acbe6SKevin Wolf    echo -e "\n\ncache.writeback=off on blk"
25273ac451fSKevin 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"
2538f7acbe6SKevin Wolf    echo -e "\ncache.writeback=off on file"
25473ac451fSKevin 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"
2558f7acbe6SKevin Wolf    echo -e "\ncache.writeback=off on backing"
25673ac451fSKevin 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"
2578f7acbe6SKevin Wolf    echo -e "\ncache.writeback=off on backing-file"
25873ac451fSKevin 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"
2598f7acbe6SKevin Wolf
2608f7acbe6SKevin Wolf    # Check cache.no-flush
2618f7acbe6SKevin Wolf
2628f7acbe6SKevin Wolf    echo -e "\n\ncache.no-flush=on on blk"
26373ac451fSKevin 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"
2648f7acbe6SKevin Wolf    echo -e "\ncache.no-flush=on on file"
26573ac451fSKevin 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"
2668f7acbe6SKevin Wolf    echo -e "\ncache.no-flush=on on backing"
26773ac451fSKevin 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"
2688f7acbe6SKevin Wolf    echo -e "\ncache.no-flush=on on backing-file"
26973ac451fSKevin 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"
2708f7acbe6SKevin Wolf}
2718f7acbe6SKevin Wolf
2728f7acbe6SKevin Wolfecho
2738f7acbe6SKevin Wolfecho "--- Configure cache modes on the command line ---"
2748f7acbe6SKevin Wolfecho
2758f7acbe6SKevin Wolf
2768f7acbe6SKevin Wolf# First check the inherited cache mode after opening the image.
2778f7acbe6SKevin Wolf
2788f7acbe6SKevin Wolfhmp_cmds="info block image
2798f7acbe6SKevin Wolfinfo block file
2808f7acbe6SKevin Wolfinfo block backing
2818f7acbe6SKevin Wolfinfo block backing-file"
2828f7acbe6SKevin Wolf
2838f7acbe6SKevin Wolfcheck_cache_all_separate
2848f7acbe6SKevin Wolf
2858f7acbe6SKevin Wolfecho
2868f7acbe6SKevin Wolfecho "--- Cache modes after reopen (live snapshot) ---"
2878f7acbe6SKevin Wolfecho
2888f7acbe6SKevin Wolf
2898f7acbe6SKevin Wolf# Then trigger a reopen and check that the cache modes are still the same.
2908f7acbe6SKevin Wolf
2918f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n blk $TEST_IMG.snap $IMGFMT
2928f7acbe6SKevin Wolfinfo block blk
2938f7acbe6SKevin Wolfinfo block image
2948f7acbe6SKevin Wolfinfo block file
2958f7acbe6SKevin Wolfinfo block backing
2968f7acbe6SKevin Wolfinfo block backing-file"
2978f7acbe6SKevin Wolf
2988f7acbe6SKevin Wolfcheck_cache_all_separate
2998f7acbe6SKevin Wolf
3008f7acbe6SKevin Wolfecho
3018f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, flags) ---"
3028f7acbe6SKevin Wolfecho
3038f7acbe6SKevin Wolf
3048f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
3058f7acbe6SKevin Wolf# new cache mode is specified as flags, not as option.
3068f7acbe6SKevin Wolf
3078f7acbe6SKevin Wolfhmp_cmds='qemu-io blk "reopen -c none"
3088f7acbe6SKevin Wolfinfo block image
3098f7acbe6SKevin Wolfinfo block file
3108f7acbe6SKevin Wolfinfo block backing
3118f7acbe6SKevin Wolfinfo block backing-file'
3128f7acbe6SKevin Wolf
3138f7acbe6SKevin Wolfcheck_cache_all_separate
3148f7acbe6SKevin Wolf
3158f7acbe6SKevin Wolf
3168f7acbe6SKevin Wolfecho
3178f7acbe6SKevin Wolfecho "=== Reopening children instead of the root ==="
3188f7acbe6SKevin Wolfecho
3198f7acbe6SKevin Wolf
3208f7acbe6SKevin Wolffiles="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
3218f7acbe6SKevin Wolfids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
3228f7acbe6SKevin Wolf
3238f7acbe6SKevin Wolfecho
3248f7acbe6SKevin Wolfecho "--- Basic reopen ---"
3258f7acbe6SKevin Wolfecho
3268f7acbe6SKevin Wolf
3278f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on"
328c83f9fbaSKevin Wolfinfo block none0
3298f7acbe6SKevin Wolfinfo block image
3308f7acbe6SKevin Wolfinfo block file
3318f7acbe6SKevin Wolfinfo block backing
3328f7acbe6SKevin Wolfinfo block backing-file'
3338f7acbe6SKevin Wolf
3348f7acbe6SKevin Wolfcheck_cache_all
3358f7acbe6SKevin Wolf
3368f7acbe6SKevin Wolfecho
3378f7acbe6SKevin Wolfecho "--- Change cache mode after reopening child ---"
3388f7acbe6SKevin Wolfecho
3398f7acbe6SKevin Wolf
3408f7acbe6SKevin Wolf# This checks that children with options explicitly set with reopen don't
3418f7acbe6SKevin Wolf# inherit these options from their parents any more
3428f7acbe6SKevin Wolf
3438f7acbe6SKevin Wolf# TODO Implement node-name support for 'qemu-io' HMP command for -c
3448f7acbe6SKevin Wolf# Can use only -o to access child node options for now
3458f7acbe6SKevin Wolf
346bfd18d1eSKevin Wolfhmp_cmds="qemu-io none0 \"reopen -o file.cache.direct=off,file.cache.no-flush=off\"
347bfd18d1eSKevin Wolfqemu-io none0 \"reopen -o backing.file.cache.direct=off,backing.file.cache.no-flush=on\"
3488f7acbe6SKevin Wolfqemu-io none0 \"reopen -c none\"
3498f7acbe6SKevin Wolfinfo block image
3508f7acbe6SKevin Wolfinfo block file
3518f7acbe6SKevin Wolfinfo block backing
3528f7acbe6SKevin Wolfinfo block backing-file"
3538f7acbe6SKevin Wolf
3548f7acbe6SKevin Wolfecho "$hmp_cmds" | run_qemu -drive "$files","$ids" | grep "Cache"
3558f7acbe6SKevin Wolf
3568f7acbe6SKevin Wolf# success, all done
3578f7acbe6SKevin Wolfecho "*** done"
3588f7acbe6SKevin Wolfrm -f $seq.full
3598f7acbe6SKevin Wolfstatus=0
360