xref: /openbmc/qemu/tests/qemu-iotests/142 (revision b43671f80cda8d0f11dcb929ed76fbd680c29cec)
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 Wolfstatus=1	# failure is the default!
298f7acbe6SKevin Wolf
308f7acbe6SKevin Wolf_cleanup()
318f7acbe6SKevin Wolf{
328f7acbe6SKevin Wolf    _cleanup_test_img
338f7acbe6SKevin Wolf    rm -f $TEST_IMG.snap
348f7acbe6SKevin Wolf}
358f7acbe6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
368f7acbe6SKevin Wolf
378f7acbe6SKevin Wolf# get standard environment, filters and checks
388f7acbe6SKevin Wolf. ./common.rc
398f7acbe6SKevin Wolf. ./common.filter
408f7acbe6SKevin Wolf
418f7acbe6SKevin Wolf_supported_fmt qcow2
428f7acbe6SKevin Wolf_supported_proto file
438f7acbe6SKevin Wolf_supported_os Linux
448f7acbe6SKevin Wolf
458f7acbe6SKevin Wolf# We test all cache modes anyway, but O_DIRECT needs to be supported
468f7acbe6SKevin Wolf_default_cache_mode none
478f7acbe6SKevin Wolf_supported_cache_modes none directsync
488f7acbe6SKevin Wolf
498f7acbe6SKevin Wolffunction do_run_qemu()
508f7acbe6SKevin Wolf{
518f7acbe6SKevin Wolf    echo Testing: "$@"
528f7acbe6SKevin Wolf    (
538f7acbe6SKevin Wolf        if ! test -t 0; then
548f7acbe6SKevin Wolf            while read cmd; do
558f7acbe6SKevin Wolf                echo $cmd
568f7acbe6SKevin Wolf            done
578f7acbe6SKevin Wolf        fi
588f7acbe6SKevin Wolf        echo quit
598f7acbe6SKevin Wolf    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
608f7acbe6SKevin Wolf    echo
618f7acbe6SKevin Wolf}
628f7acbe6SKevin Wolf
638f7acbe6SKevin Wolffunction run_qemu()
648f7acbe6SKevin Wolf{
6569404d9eSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp
668f7acbe6SKevin Wolf}
678f7acbe6SKevin Wolf
688f7acbe6SKevin Wolfsize=128M
698f7acbe6SKevin Wolf
708f7acbe6SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size
718f7acbe6SKevin WolfTEST_IMG="$TEST_IMG.snap" _make_test_img $size
728f7acbe6SKevin Wolf_make_test_img -b "$TEST_IMG.base" $size
738f7acbe6SKevin Wolf
748f7acbe6SKevin Wolfecho
758f7acbe6SKevin Wolfecho === Simple test for all cache modes ===
768f7acbe6SKevin Wolfecho
778f7acbe6SKevin Wolf
788f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=none
798f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=directsync
808f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=writeback
818f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=writethrough
828f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=unsafe
838f7acbe6SKevin Wolfrun_qemu -drive file="$TEST_IMG",cache=invalid_value
848f7acbe6SKevin Wolf
858f7acbe6SKevin Wolfecho
868f7acbe6SKevin Wolfecho === Check inheritance of cache modes ===
878f7acbe6SKevin Wolfecho
888f7acbe6SKevin Wolf
898f7acbe6SKevin Wolffiles="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
908f7acbe6SKevin Wolfids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
918f7acbe6SKevin Wolf
928f7acbe6SKevin Wolffunction check_cache_all()
938f7acbe6SKevin Wolf{
948f7acbe6SKevin Wolf    # cache.direct is supposed to be inherited by both bs->file and
958f7acbe6SKevin Wolf    # bs->backing
968f7acbe6SKevin Wolf
97*b43671f8SEric Blake    printf "cache.direct=on on none0\n"
9873ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
99*b43671f8SEric Blake    printf "\ncache.direct=on on file\n"
10073ac451fSKevin 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"
101*b43671f8SEric Blake    printf "\ncache.direct=on on backing\n"
10273ac451fSKevin 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"
103*b43671f8SEric Blake    printf "\ncache.direct=on on backing-file\n"
10473ac451fSKevin 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"
1058f7acbe6SKevin Wolf
1068f7acbe6SKevin Wolf    # cache.writeback is supposed to be inherited by bs->backing; bs->file
1078f7acbe6SKevin Wolf    # always gets cache.writeback=on
1088f7acbe6SKevin Wolf
109*b43671f8SEric Blake    printf "\n\ncache.writeback=off on none0\n"
11073ac451fSKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
111*b43671f8SEric Blake    printf "\ncache.writeback=off on file\n"
11261de4c68SKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "doesn't" -e "does not"
113*b43671f8SEric Blake    printf "\ncache.writeback=off on backing\n"
11461de4c68SKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "doesn't" -e "does not"
115*b43671f8SEric Blake    printf "\ncache.writeback=off on backing-file\n"
11661de4c68SKevin Wolf    echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "doesn't" -e "does not"
1178f7acbe6SKevin Wolf
1188f7acbe6SKevin Wolf    # cache.no-flush is supposed to be inherited by both bs->file and bs->backing
1198f7acbe6SKevin Wolf
120*b43671f8SEric Blake    printf "\n\ncache.no-flush=on on none0\n"
12173ac451fSKevin 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"
122*b43671f8SEric Blake    printf "\ncache.no-flush=on on file\n"
12373ac451fSKevin 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"
124*b43671f8SEric Blake    printf "\ncache.no-flush=on on backing\n"
12573ac451fSKevin 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"
126*b43671f8SEric Blake    printf "\ncache.no-flush=on on backing-file\n"
12773ac451fSKevin 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"
1288f7acbe6SKevin Wolf}
1298f7acbe6SKevin Wolf
1308f7acbe6SKevin Wolfecho
1318f7acbe6SKevin Wolfecho "--- Configure cache modes on the command line ---"
1328f7acbe6SKevin Wolfecho
1338f7acbe6SKevin Wolf
1348f7acbe6SKevin Wolf# First check the inherited cache mode after opening the image.
1358f7acbe6SKevin Wolf
136c83f9fbaSKevin Wolfhmp_cmds="info block none0
137c83f9fbaSKevin Wolfinfo block image
1388f7acbe6SKevin Wolfinfo block file
1398f7acbe6SKevin Wolfinfo block backing
1408f7acbe6SKevin Wolfinfo block backing-file"
1418f7acbe6SKevin Wolf
1428f7acbe6SKevin Wolfcheck_cache_all
1438f7acbe6SKevin Wolf
1448f7acbe6SKevin Wolfecho
1458f7acbe6SKevin Wolfecho "--- Cache modes after reopen (live snapshot) ---"
1468f7acbe6SKevin Wolfecho
1478f7acbe6SKevin Wolf
1488f7acbe6SKevin Wolf# Then trigger a reopen and check that the cache modes are still the same.
1498f7acbe6SKevin Wolf
1508f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
1518f7acbe6SKevin Wolfinfo block
1528f7acbe6SKevin Wolfinfo block image
1538f7acbe6SKevin Wolfinfo block file
1548f7acbe6SKevin Wolfinfo block backing
1558f7acbe6SKevin Wolfinfo block backing-file"
1568f7acbe6SKevin Wolf
1578f7acbe6SKevin Wolfcheck_cache_all
1588f7acbe6SKevin Wolf
1598f7acbe6SKevin Wolfecho
1608f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, flags) ---"
1618f7acbe6SKevin Wolfecho
1628f7acbe6SKevin Wolf
1638f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
1648f7acbe6SKevin Wolf# new cache mode is specified in the flags, not as an option.
1658f7acbe6SKevin Wolf
1668f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -c none"
167c83f9fbaSKevin Wolfinfo block none0
1688f7acbe6SKevin Wolfinfo block image
1698f7acbe6SKevin Wolfinfo block file
1708f7acbe6SKevin Wolfinfo block backing
1718f7acbe6SKevin Wolfinfo block backing-file'
1728f7acbe6SKevin Wolf
1738f7acbe6SKevin Wolfcheck_cache_all
1748f7acbe6SKevin Wolf
1758f7acbe6SKevin Wolfecho
1768f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, options) ---"
1778f7acbe6SKevin Wolfecho
1788f7acbe6SKevin Wolf
1798f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
1808f7acbe6SKevin Wolf# new cache mode is specified as an option, not in the flags.
1818f7acbe6SKevin Wolf
1828f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -o cache.direct=on"
183c83f9fbaSKevin Wolfinfo block none0
1848f7acbe6SKevin Wolfinfo block image
1858f7acbe6SKevin Wolfinfo block file
1868f7acbe6SKevin Wolfinfo block backing
1878f7acbe6SKevin Wolfinfo block backing-file'
1888f7acbe6SKevin Wolf
1898f7acbe6SKevin Wolfcheck_cache_all
1908f7acbe6SKevin Wolf
1918f7acbe6SKevin Wolfecho
1928f7acbe6SKevin Wolfecho "--- Change cache modes after snapshot ---"
1938f7acbe6SKevin Wolfecho
1948f7acbe6SKevin Wolf
1958f7acbe6SKevin Wolf# This checks that the original image doesn't inherit from the snapshot
1968f7acbe6SKevin Wolf
1978f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
1988f7acbe6SKevin Wolfqemu-io none0 \"reopen -c none\"
1998f7acbe6SKevin Wolfinfo block none0
2008f7acbe6SKevin Wolfinfo block image
2018f7acbe6SKevin Wolfinfo block file
2028f7acbe6SKevin Wolfinfo block backing
2038f7acbe6SKevin Wolfinfo block backing-file"
2048f7acbe6SKevin Wolf
2058f7acbe6SKevin Wolfcheck_cache_all
2068f7acbe6SKevin Wolf
2078f7acbe6SKevin Wolfecho
2088f7acbe6SKevin Wolfecho "--- Change cache mode in parent, child has explicit option in JSON ---"
2098f7acbe6SKevin Wolfecho
2108f7acbe6SKevin Wolf
2118f7acbe6SKevin Wolf# This checks that children with options explicitly set by the json:
2128f7acbe6SKevin Wolf# pseudo-protocol don't inherit these options from their parents.
2138f7acbe6SKevin Wolf#
2148f7acbe6SKevin Wolf# Yes, blkdebug::json:... is criminal, but I can't see another way to have a
2158f7acbe6SKevin Wolf# BDS initialised with the json: pseudo-protocol, but still have it inherit
2168f7acbe6SKevin Wolf# options from its parent node.
2178f7acbe6SKevin Wolf
21819dbecdcSKevin Wolfhmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\"
219c83f9fbaSKevin Wolfinfo block none0
2208f7acbe6SKevin Wolfinfo block image
2218f7acbe6SKevin Wolfinfo block blkdebug
2228f7acbe6SKevin Wolfinfo block file"
2238f7acbe6SKevin Wolf
22473ac451fSKevin 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"
2258f7acbe6SKevin Wolf
2268f7acbe6SKevin Wolfecho
2278f7acbe6SKevin Wolfecho "=== Check that referenced BDSes don't inherit ==="
2288f7acbe6SKevin Wolfecho
2298f7acbe6SKevin Wolf
2308f7acbe6SKevin Wolfdrv_bkfile="if=none,driver=file,filename=$TEST_IMG.base,node-name=backing-file"
2318f7acbe6SKevin Wolfdrv_bk="if=none,file=json:{'driver':'$IMGFMT',,'file':'backing-file',,'node-name':'backing'}"
2328f7acbe6SKevin Wolfdrv_file="if=none,driver=file,filename=$TEST_IMG,node-name=file"
2338f7acbe6SKevin Wolfdrv_img="if=none,id=blk,file=json:{'driver':'$IMGFMT',,'file':'file',,'backing':'backing',,'node-name':'image'}"
2348f7acbe6SKevin Wolf
2358f7acbe6SKevin Wolffunction check_cache_all_separate()
2368f7acbe6SKevin Wolf{
2378f7acbe6SKevin Wolf    # Check cache.direct
2388f7acbe6SKevin Wolf
239*b43671f8SEric Blake    printf "cache.direct=on on blk\n"
24073ac451fSKevin 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"
241*b43671f8SEric Blake    printf "\ncache.direct=on on file\n"
24273ac451fSKevin 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"
243*b43671f8SEric Blake    printf "\ncache.direct=on on backing\n"
24473ac451fSKevin 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"
245*b43671f8SEric Blake    printf "\ncache.direct=on on backing-file\n"
24673ac451fSKevin 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"
2478f7acbe6SKevin Wolf
2488f7acbe6SKevin Wolf    # Check cache.writeback
2498f7acbe6SKevin Wolf
250*b43671f8SEric Blake    printf "\n\ncache.writeback=off on blk\n"
25173ac451fSKevin 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"
252*b43671f8SEric Blake    printf "\ncache.writeback=off on file\n"
25373ac451fSKevin 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"
254*b43671f8SEric Blake    printf "\ncache.writeback=off on backing\n"
25573ac451fSKevin 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"
256*b43671f8SEric Blake    printf "\ncache.writeback=off on backing-file\n"
25773ac451fSKevin 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"
2588f7acbe6SKevin Wolf
2598f7acbe6SKevin Wolf    # Check cache.no-flush
2608f7acbe6SKevin Wolf
261*b43671f8SEric Blake    printf "\n\ncache.no-flush=on on blk\n"
26273ac451fSKevin 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"
263*b43671f8SEric Blake    printf "\ncache.no-flush=on on file\n"
26473ac451fSKevin 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"
265*b43671f8SEric Blake    printf "\ncache.no-flush=on on backing\n"
26673ac451fSKevin 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"
267*b43671f8SEric Blake    printf "\ncache.no-flush=on on backing-file\n"
26873ac451fSKevin 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"
2698f7acbe6SKevin Wolf}
2708f7acbe6SKevin Wolf
2718f7acbe6SKevin Wolfecho
2728f7acbe6SKevin Wolfecho "--- Configure cache modes on the command line ---"
2738f7acbe6SKevin Wolfecho
2748f7acbe6SKevin Wolf
2758f7acbe6SKevin Wolf# First check the inherited cache mode after opening the image.
2768f7acbe6SKevin Wolf
2778f7acbe6SKevin Wolfhmp_cmds="info block image
2788f7acbe6SKevin Wolfinfo block file
2798f7acbe6SKevin Wolfinfo block backing
2808f7acbe6SKevin Wolfinfo block backing-file"
2818f7acbe6SKevin Wolf
2828f7acbe6SKevin Wolfcheck_cache_all_separate
2838f7acbe6SKevin Wolf
2848f7acbe6SKevin Wolfecho
2858f7acbe6SKevin Wolfecho "--- Cache modes after reopen (live snapshot) ---"
2868f7acbe6SKevin Wolfecho
2878f7acbe6SKevin Wolf
2888f7acbe6SKevin Wolf# Then trigger a reopen and check that the cache modes are still the same.
2898f7acbe6SKevin Wolf
2908f7acbe6SKevin Wolfhmp_cmds="snapshot_blkdev -n blk $TEST_IMG.snap $IMGFMT
2918f7acbe6SKevin Wolfinfo block blk
2928f7acbe6SKevin Wolfinfo block image
2938f7acbe6SKevin Wolfinfo block file
2948f7acbe6SKevin Wolfinfo block backing
2958f7acbe6SKevin Wolfinfo block backing-file"
2968f7acbe6SKevin Wolf
2978f7acbe6SKevin Wolfcheck_cache_all_separate
2988f7acbe6SKevin Wolf
2998f7acbe6SKevin Wolfecho
3008f7acbe6SKevin Wolfecho "--- Change cache modes with reopen (qemu-io command, flags) ---"
3018f7acbe6SKevin Wolfecho
3028f7acbe6SKevin Wolf
3038f7acbe6SKevin Wolf# This one actually changes the cache mode with the reopen. For this test, the
3048f7acbe6SKevin Wolf# new cache mode is specified as flags, not as option.
3058f7acbe6SKevin Wolf
3068f7acbe6SKevin Wolfhmp_cmds='qemu-io blk "reopen -c none"
3078f7acbe6SKevin Wolfinfo block image
3088f7acbe6SKevin Wolfinfo block file
3098f7acbe6SKevin Wolfinfo block backing
3108f7acbe6SKevin Wolfinfo block backing-file'
3118f7acbe6SKevin Wolf
3128f7acbe6SKevin Wolfcheck_cache_all_separate
3138f7acbe6SKevin Wolf
3148f7acbe6SKevin Wolf
3158f7acbe6SKevin Wolfecho
3168f7acbe6SKevin Wolfecho "=== Reopening children instead of the root ==="
3178f7acbe6SKevin Wolfecho
3188f7acbe6SKevin Wolf
3198f7acbe6SKevin Wolffiles="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
3208f7acbe6SKevin Wolfids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
3218f7acbe6SKevin Wolf
3228f7acbe6SKevin Wolfecho
3238f7acbe6SKevin Wolfecho "--- Basic reopen ---"
3248f7acbe6SKevin Wolfecho
3258f7acbe6SKevin Wolf
3268f7acbe6SKevin Wolfhmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on"
327c83f9fbaSKevin Wolfinfo block none0
3288f7acbe6SKevin Wolfinfo block image
3298f7acbe6SKevin Wolfinfo block file
3308f7acbe6SKevin Wolfinfo block backing
3318f7acbe6SKevin Wolfinfo block backing-file'
3328f7acbe6SKevin Wolf
3338f7acbe6SKevin Wolfcheck_cache_all
3348f7acbe6SKevin Wolf
3358f7acbe6SKevin Wolfecho
3368f7acbe6SKevin Wolfecho "--- Change cache mode after reopening child ---"
3378f7acbe6SKevin Wolfecho
3388f7acbe6SKevin Wolf
3398f7acbe6SKevin Wolf# This checks that children with options explicitly set with reopen don't
3408f7acbe6SKevin Wolf# inherit these options from their parents any more
3418f7acbe6SKevin Wolf
3428f7acbe6SKevin Wolf# TODO Implement node-name support for 'qemu-io' HMP command for -c
3438f7acbe6SKevin Wolf# Can use only -o to access child node options for now
3448f7acbe6SKevin Wolf
345bfd18d1eSKevin Wolfhmp_cmds="qemu-io none0 \"reopen -o file.cache.direct=off,file.cache.no-flush=off\"
346bfd18d1eSKevin Wolfqemu-io none0 \"reopen -o backing.file.cache.direct=off,backing.file.cache.no-flush=on\"
3478f7acbe6SKevin Wolfqemu-io none0 \"reopen -c none\"
3488f7acbe6SKevin Wolfinfo block image
3498f7acbe6SKevin Wolfinfo block file
3508f7acbe6SKevin Wolfinfo block backing
3518f7acbe6SKevin Wolfinfo block backing-file"
3528f7acbe6SKevin Wolf
3538f7acbe6SKevin Wolfecho "$hmp_cmds" | run_qemu -drive "$files","$ids" | grep "Cache"
3548f7acbe6SKevin Wolf
3558f7acbe6SKevin Wolf# success, all done
3568f7acbe6SKevin Wolfecho "*** done"
3578f7acbe6SKevin Wolfrm -f $seq.full
3588f7acbe6SKevin Wolfstatus=0
359