1a1cb48a3SMax Reitz#!/bin/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 Reitzhere=$PWD 28a1cb48a3SMax Reitzstatus=1 # failure is the default! 29a1cb48a3SMax Reitz 30a1cb48a3SMax Reitz_cleanup() 31a1cb48a3SMax Reitz{ 32a1cb48a3SMax Reitz _cleanup_test_img 33a1cb48a3SMax Reitz} 34a1cb48a3SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 35a1cb48a3SMax Reitz 36a1cb48a3SMax Reitz# get standard environment, filters and checks 37a1cb48a3SMax Reitz. ./common.rc 38a1cb48a3SMax Reitz. ./common.filter 39a1cb48a3SMax Reitz 40a1cb48a3SMax Reitz_supported_fmt qcow2 41c5f7c0afSPeter Lieven_supported_proto file nfs 42a1cb48a3SMax Reitz_supported_os Linux 43a03a57a0SMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1 44a03a57a0SMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' 45a1cb48a3SMax Reitz 46a1cb48a3SMax ReitzIMG_SIZE=64K 47a1cb48a3SMax Reitz 48a1cb48a3SMax Reitz_make_test_img $IMG_SIZE 49a1cb48a3SMax Reitz$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io 50a1cb48a3SMax Reitz 51a1cb48a3SMax Reitzecho 52a1cb48a3SMax Reitzecho '=== Testing invalid option combinations ===' 53a1cb48a3SMax Reitzecho 54a1cb48a3SMax Reitz 55a1cb48a3SMax Reitz# all sizes set at the same time 56a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1.25M,l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \ 57a1cb48a3SMax Reitz 2>&1 | _filter_testdir | _filter_imgfmt 58a1cb48a3SMax Reitz# l2-cache-size may not exceed cache-size 59a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,l2-cache-size=2M $TEST_IMG" 2>&1 \ 60a1cb48a3SMax Reitz | _filter_testdir | _filter_imgfmt 61a1cb48a3SMax Reitz# refcount-cache-size may not exceed cache-size 62a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,refcount-cache-size=2M $TEST_IMG" 2>&1 \ 63a1cb48a3SMax Reitz | _filter_testdir | _filter_imgfmt 64a1cb48a3SMax Reitz# 0 should be a valid size (e.g. for enforcing the minimum), so this should not 65a1cb48a3SMax Reitz# work 66a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0,l2-cache-size=0,refcount-cache-size=0 $TEST_IMG" \ 67a1cb48a3SMax Reitz 2>&1 | _filter_testdir | _filter_imgfmt 68a1cb48a3SMax Reitz 69*4450c396SAlberto Garcia# Invalid cache entry sizes 70*4450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=256 $TEST_IMG" \ 71*4450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 72*4450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=4242 $TEST_IMG" \ 73*4450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 74*4450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=128k $TEST_IMG" \ 75*4450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 76*4450c396SAlberto Garcia 77a1cb48a3SMax Reitzecho 78a1cb48a3SMax Reitzecho '=== Testing valid option combinations ===' 79a1cb48a3SMax Reitzecho 80a1cb48a3SMax Reitz 81a1cb48a3SMax Reitz# There should be a reasonable and working minimum 82a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ 83a1cb48a3SMax Reitz | _filter_qemu_io 84a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ 85a1cb48a3SMax Reitz | _filter_qemu_io 86a1cb48a3SMax Reitz$QEMU_IO -c "open -o refcount-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ 87a1cb48a3SMax Reitz | _filter_qemu_io 88a1cb48a3SMax Reitz 89a1cb48a3SMax Reitz# Derive cache sizes from combined size (with a reasonable ratio, but we cannot 90a1cb48a3SMax Reitz# test that) 91a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M $TEST_IMG" -c 'read -P 42 0 64k' \ 92a1cb48a3SMax Reitz | _filter_qemu_io 93a1cb48a3SMax Reitz# Fix one cache, derive the other 94a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,l2-cache-size=1M $TEST_IMG" \ 95a1cb48a3SMax Reitz -c 'read -P 42 0 64k' \ 96a1cb48a3SMax Reitz | _filter_qemu_io 97a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,refcount-cache-size=1M $TEST_IMG" \ 98a1cb48a3SMax Reitz -c 'read -P 42 0 64k' \ 99a1cb48a3SMax Reitz | _filter_qemu_io 100a1cb48a3SMax Reitz# Directly set both caches 101a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \ 102a1cb48a3SMax Reitz -c 'read -P 42 0 64k' \ 103a1cb48a3SMax Reitz | _filter_qemu_io 104a1cb48a3SMax Reitz 105*4450c396SAlberto Garcia# Valid cache entry sizes 106*4450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=512 $TEST_IMG" \ 107*4450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 108*4450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=16k $TEST_IMG" \ 109*4450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 110*4450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=64k $TEST_IMG" \ 111*4450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 112*4450c396SAlberto Garcia 113*4450c396SAlberto Garcia 114a4291eafSMax Reitzecho 115a4291eafSMax Reitzecho '=== Testing minimal L2 cache and COW ===' 116a4291eafSMax Reitzecho 117a4291eafSMax Reitz 118a4291eafSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 119a4291eafSMax Reitz# This requires a COW operation, which accesses two L2 tables simultaneously 120a4291eafSMax Reitz# (COW source and destination), so there must be enough space in the cache to 121a4291eafSMax Reitz# place both tables there (and qemu should not crash) 122a4291eafSMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'write 0 64k' | _filter_qemu_io 123a4291eafSMax Reitz 124a1cb48a3SMax Reitz# success, all done 125a1cb48a3SMax Reitzecho '*** done' 126a1cb48a3SMax Reitzrm -f $seq.full 127a1cb48a3SMax Reitzstatus=0 128