xref: /qemu/tests/qemu-iotests/103 (revision 3be2024aefe0024ada2fb5044c230c867ef59c67)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2a1cb48a3SMax Reitz#
3a1cb48a3SMax Reitz# Test case for qcow2 metadata cache size specification
4a1cb48a3SMax Reitz#
5a1cb48a3SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
6a1cb48a3SMax Reitz#
7a1cb48a3SMax Reitz# This program is free software; you can redistribute it and/or modify
8a1cb48a3SMax Reitz# it under the terms of the GNU General Public License as published by
9a1cb48a3SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10a1cb48a3SMax Reitz# (at your option) any later version.
11a1cb48a3SMax Reitz#
12a1cb48a3SMax Reitz# This program is distributed in the hope that it will be useful,
13a1cb48a3SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14a1cb48a3SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a1cb48a3SMax Reitz# GNU General Public License for more details.
16a1cb48a3SMax Reitz#
17a1cb48a3SMax Reitz# You should have received a copy of the GNU General Public License
18a1cb48a3SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19a1cb48a3SMax Reitz#
20a1cb48a3SMax Reitz
21a1cb48a3SMax Reitz# creator
22a1cb48a3SMax Reitzowner=mreitz@redhat.com
23a1cb48a3SMax Reitz
24a1cb48a3SMax Reitzseq=$(basename $0)
25a1cb48a3SMax Reitzecho "QA output created by $seq"
26a1cb48a3SMax Reitz
27a1cb48a3SMax Reitzstatus=1	# failure is the default!
28a1cb48a3SMax Reitz
29a1cb48a3SMax Reitz_cleanup()
30a1cb48a3SMax Reitz{
31a1cb48a3SMax Reitz	_cleanup_test_img
32a1cb48a3SMax Reitz}
33a1cb48a3SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
34a1cb48a3SMax Reitz
35a1cb48a3SMax Reitz# get standard environment, filters and checks
36a1cb48a3SMax Reitz. ./common.rc
37a1cb48a3SMax Reitz. ./common.filter
38a1cb48a3SMax Reitz
39a1cb48a3SMax Reitz_supported_fmt qcow2
40c5f7c0afSPeter Lieven_supported_proto file nfs
41*3be2024aSMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1,
42*3be2024aSMax Reitz# and generally impossible with external data files
43*3be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' data_file
44a1cb48a3SMax Reitz
45a1cb48a3SMax ReitzIMG_SIZE=64K
46a1cb48a3SMax Reitz
47a1cb48a3SMax Reitz_make_test_img $IMG_SIZE
48a1cb48a3SMax Reitz$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
49a1cb48a3SMax Reitz
50a1cb48a3SMax Reitzecho
51a1cb48a3SMax Reitzecho '=== Testing invalid option combinations ==='
52a1cb48a3SMax Reitzecho
53a1cb48a3SMax Reitz
54a1cb48a3SMax Reitz# all sizes set at the same time
55a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1.25M,l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \
56a1cb48a3SMax Reitz    2>&1 | _filter_testdir | _filter_imgfmt
57a1cb48a3SMax Reitz# l2-cache-size may not exceed cache-size
58a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,l2-cache-size=2M $TEST_IMG" 2>&1 \
59a1cb48a3SMax Reitz    | _filter_testdir | _filter_imgfmt
60a1cb48a3SMax Reitz# refcount-cache-size may not exceed cache-size
61a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,refcount-cache-size=2M $TEST_IMG" 2>&1 \
62a1cb48a3SMax Reitz    | _filter_testdir | _filter_imgfmt
63a1cb48a3SMax Reitz# 0 should be a valid size (e.g. for enforcing the minimum), so this should not
64a1cb48a3SMax Reitz# work
65a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0,l2-cache-size=0,refcount-cache-size=0 $TEST_IMG" \
66a1cb48a3SMax Reitz    2>&1 | _filter_testdir | _filter_imgfmt
67a1cb48a3SMax Reitz
684450c396SAlberto Garcia# Invalid cache entry sizes
694450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=256 $TEST_IMG" \
704450c396SAlberto Garcia    2>&1 | _filter_testdir | _filter_imgfmt
714450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=4242 $TEST_IMG" \
724450c396SAlberto Garcia    2>&1 | _filter_testdir | _filter_imgfmt
734450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=128k $TEST_IMG" \
744450c396SAlberto Garcia    2>&1 | _filter_testdir | _filter_imgfmt
754450c396SAlberto Garcia
76a1cb48a3SMax Reitzecho
77a1cb48a3SMax Reitzecho '=== Testing valid option combinations ==='
78a1cb48a3SMax Reitzecho
79a1cb48a3SMax Reitz
80a1cb48a3SMax Reitz# There should be a reasonable and working minimum
81a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
82a1cb48a3SMax Reitz    | _filter_qemu_io
83a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
84a1cb48a3SMax Reitz    | _filter_qemu_io
85a1cb48a3SMax Reitz$QEMU_IO -c "open -o refcount-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
86a1cb48a3SMax Reitz    | _filter_qemu_io
87a1cb48a3SMax Reitz
88a1cb48a3SMax Reitz# Derive cache sizes from combined size (with a reasonable ratio, but we cannot
89a1cb48a3SMax Reitz# test that)
90a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M $TEST_IMG" -c 'read -P 42 0 64k' \
91a1cb48a3SMax Reitz    | _filter_qemu_io
92a1cb48a3SMax Reitz# Fix one cache, derive the other
93a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,l2-cache-size=1M $TEST_IMG" \
94a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
95a1cb48a3SMax Reitz    | _filter_qemu_io
96a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,refcount-cache-size=1M $TEST_IMG" \
97a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
98a1cb48a3SMax Reitz    | _filter_qemu_io
99a1cb48a3SMax Reitz# Directly set both caches
100a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \
101a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
102a1cb48a3SMax Reitz    | _filter_qemu_io
103a1cb48a3SMax Reitz
1044450c396SAlberto Garcia# Valid cache entry sizes
1054450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=512 $TEST_IMG" \
1064450c396SAlberto Garcia    2>&1 | _filter_testdir | _filter_imgfmt
1074450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=16k $TEST_IMG" \
1084450c396SAlberto Garcia    2>&1 | _filter_testdir | _filter_imgfmt
1094450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=64k $TEST_IMG" \
1104450c396SAlberto Garcia    2>&1 | _filter_testdir | _filter_imgfmt
1114450c396SAlberto Garcia
1124450c396SAlberto Garcia
113a4291eafSMax Reitzecho
114a4291eafSMax Reitzecho '=== Testing minimal L2 cache and COW ==='
115a4291eafSMax Reitzecho
116a4291eafSMax Reitz
117a4291eafSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG"
118a4291eafSMax Reitz# This requires a COW operation, which accesses two L2 tables simultaneously
119a4291eafSMax Reitz# (COW source and destination), so there must be enough space in the cache to
120a4291eafSMax Reitz# place both tables there (and qemu should not crash)
121a4291eafSMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'write 0 64k' | _filter_qemu_io
122a4291eafSMax Reitz
123a1cb48a3SMax Reitz# success, all done
124a1cb48a3SMax Reitzecho '*** done'
125a1cb48a3SMax Reitzrm -f $seq.full
126a1cb48a3SMax Reitzstatus=0
127