111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2dc68afe0SStefan Hajnoczi# 3dc68afe0SStefan Hajnoczi# Test qcow2 lazy refcounts 4dc68afe0SStefan Hajnoczi# 5dc68afe0SStefan Hajnoczi# Copyright (C) 2012 Red Hat, Inc. 6dc68afe0SStefan Hajnoczi# Copyright IBM, Corp. 2010 7dc68afe0SStefan Hajnoczi# 8dc68afe0SStefan Hajnoczi# Based on test 038. 9dc68afe0SStefan Hajnoczi# 10dc68afe0SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 11dc68afe0SStefan Hajnoczi# it under the terms of the GNU General Public License as published by 12dc68afe0SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 13dc68afe0SStefan Hajnoczi# (at your option) any later version. 14dc68afe0SStefan Hajnoczi# 15dc68afe0SStefan Hajnoczi# This program is distributed in the hope that it will be useful, 16dc68afe0SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 17dc68afe0SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18dc68afe0SStefan Hajnoczi# GNU General Public License for more details. 19dc68afe0SStefan Hajnoczi# 20dc68afe0SStefan Hajnoczi# You should have received a copy of the GNU General Public License 21dc68afe0SStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 22dc68afe0SStefan Hajnoczi# 23dc68afe0SStefan Hajnoczi 24dc68afe0SStefan Hajnoczi# creator 25dc68afe0SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com 26dc68afe0SStefan Hajnoczi 27dc68afe0SStefan Hajnocziseq=`basename $0` 28dc68afe0SStefan Hajnocziecho "QA output created by $seq" 29dc68afe0SStefan Hajnoczi 30dc68afe0SStefan Hajnoczistatus=1 # failure is the default! 31dc68afe0SStefan Hajnoczi 32dc68afe0SStefan Hajnoczi_cleanup() 33dc68afe0SStefan Hajnoczi{ 34dc68afe0SStefan Hajnoczi _cleanup_test_img 35dc68afe0SStefan Hajnoczi} 36dc68afe0SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15 37dc68afe0SStefan Hajnoczi 38dc68afe0SStefan Hajnoczi# get standard environment, filters and checks 39dc68afe0SStefan Hajnoczi. ./common.rc 40dc68afe0SStefan Hajnoczi. ./common.filter 41dc68afe0SStefan Hajnoczi 42dc68afe0SStefan Hajnoczi_supported_fmt qcow2 431f7bf7d0SPeter Lieven_supported_proto file 44dc68afe0SStefan Hajnoczi_supported_os Linux 45755c5fe7SNir Soffer_default_cache_mode writethrough 46755c5fe7SNir Soffer_supported_cache_modes writethrough 47*3be2024aSMax Reitz# Some of these test cases expect no external data file so that all 48*3be2024aSMax Reitz# clusters are part of the qcow2 image and refcounted 49*3be2024aSMax Reitz_unsupported_imgopts data_file 50dc68afe0SStefan Hajnoczi 51dc68afe0SStefan Hajnoczisize=128M 52dc68afe0SStefan Hajnoczi 53dc68afe0SStefan Hajnocziecho 54dc68afe0SStefan Hajnocziecho "== Checking that image is clean on shutdown ==" 55dc68afe0SStefan Hajnoczi 56407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 57dc68afe0SStefan Hajnoczi 58f897e393SJeff Cody$QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io 59dc68afe0SStefan Hajnoczi 60dc68afe0SStefan Hajnoczi# The dirty bit must not be set 61ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 62dc68afe0SStefan Hajnoczi_check_test_img 63dc68afe0SStefan Hajnoczi 64dc68afe0SStefan Hajnocziecho 65dc68afe0SStefan Hajnocziecho "== Creating a dirty image file ==" 66dc68afe0SStefan Hajnoczi 67407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 68dc68afe0SStefan Hajnoczi 698af224d6SAndrey Shinkevich_NO_VALGRIND \ 70934659c4SMax Reitz$QEMU_IO -c "write -P 0x5a 0 512" \ 713f394472SMax Reitz -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 723f394472SMax Reitz | _filter_qemu_io 73dc68afe0SStefan Hajnoczi 74dc68afe0SStefan Hajnoczi# The dirty bit must be set 75ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 76dc68afe0SStefan Hajnoczi_check_test_img 77dc68afe0SStefan Hajnoczi 78dc68afe0SStefan Hajnocziecho 79dc68afe0SStefan Hajnocziecho "== Read-only access must still work ==" 80dc68afe0SStefan Hajnoczi 81fef9c191SJeff Cody$QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io 82dc68afe0SStefan Hajnoczi 83dc68afe0SStefan Hajnoczi# The dirty bit must be set 84ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 85dc68afe0SStefan Hajnoczi 86dc68afe0SStefan Hajnocziecho 87dc68afe0SStefan Hajnocziecho "== Repairing the image file must succeed ==" 88dc68afe0SStefan Hajnoczi 89c6bb9ad1SFederico Simoncelli_check_test_img -r all 90dc68afe0SStefan Hajnoczi 91dc68afe0SStefan Hajnoczi# The dirty bit must not be set 92ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 93dc68afe0SStefan Hajnoczi 94dc68afe0SStefan Hajnocziecho 95dc68afe0SStefan Hajnocziecho "== Data should still be accessible after repair ==" 96dc68afe0SStefan Hajnoczi 97fef9c191SJeff Cody$QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io 98dc68afe0SStefan Hajnoczi 99dc68afe0SStefan Hajnocziecho 100dc68afe0SStefan Hajnocziecho "== Opening a dirty image read/write should repair it ==" 101dc68afe0SStefan Hajnoczi 102407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 103dc68afe0SStefan Hajnoczi 1048af224d6SAndrey Shinkevich_NO_VALGRIND \ 105934659c4SMax Reitz$QEMU_IO -c "write -P 0x5a 0 512" \ 1063f394472SMax Reitz -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 1073f394472SMax Reitz | _filter_qemu_io 108dc68afe0SStefan Hajnoczi 109dc68afe0SStefan Hajnoczi# The dirty bit must be set 110ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 111dc68afe0SStefan Hajnoczi 112fef9c191SJeff Cody$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io 113dc68afe0SStefan Hajnoczi 114dc68afe0SStefan Hajnoczi# The dirty bit must not be set 115ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 116dc68afe0SStefan Hajnoczi 117dc68afe0SStefan Hajnocziecho 118dc68afe0SStefan Hajnocziecho "== Creating an image file with lazy_refcounts=off ==" 119dc68afe0SStefan Hajnoczi 120407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=off" $size 121dc68afe0SStefan Hajnoczi 1228af224d6SAndrey Shinkevich_NO_VALGRIND \ 123934659c4SMax Reitz$QEMU_IO -c "write -P 0x5a 0 512" \ 1243f394472SMax Reitz -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 1253f394472SMax Reitz | _filter_qemu_io 126dc68afe0SStefan Hajnoczi 127dc68afe0SStefan Hajnoczi# The dirty bit must not be set since lazy_refcounts=off 128ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 129dc68afe0SStefan Hajnoczi_check_test_img 130dc68afe0SStefan Hajnoczi 1314c2e5f8fSKevin Wolfecho 1324c2e5f8fSKevin Wolfecho "== Committing to a backing file with lazy_refcounts=on ==" 1334c2e5f8fSKevin Wolf 134407fb56aSMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size 1354c2e5f8fSKevin Wolf 136407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" $size 1374c2e5f8fSKevin Wolf 1384c2e5f8fSKevin Wolf$QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io 1394c2e5f8fSKevin Wolf$QEMU_IMG commit "$TEST_IMG" 1404c2e5f8fSKevin Wolf 1414c2e5f8fSKevin Wolf# The dirty bit must not be set 142ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 143ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG".base dump-header | grep incompatible_features 1444c2e5f8fSKevin Wolf 1454c2e5f8fSKevin Wolf_check_test_img 1464c2e5f8fSKevin WolfTEST_IMG="$TEST_IMG".base _check_test_img 1474c2e5f8fSKevin Wolf 148e615053bSKevin Wolfecho 149e615053bSKevin Wolfecho "== Changing lazy_refcounts setting at runtime ==" 150e615053bSKevin Wolf 151407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=off" $size 152e615053bSKevin Wolf 1538af224d6SAndrey Shinkevich_NO_VALGRIND \ 154e615053bSKevin Wolf$QEMU_IO -c "reopen -o lazy-refcounts=on" \ 155e615053bSKevin Wolf -c "write -P 0x5a 0 512" \ 156e615053bSKevin Wolf -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 157e615053bSKevin Wolf | _filter_qemu_io 158e615053bSKevin Wolf 159e615053bSKevin Wolf# The dirty bit must be set 160e615053bSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 161e615053bSKevin Wolf_check_test_img 162e615053bSKevin Wolf 163407fb56aSMax Reitz_make_test_img -o "compat=1.1,lazy_refcounts=on" $size 164e615053bSKevin Wolf 1658af224d6SAndrey Shinkevich_NO_VALGRIND \ 166e615053bSKevin Wolf$QEMU_IO -c "reopen -o lazy-refcounts=off" \ 167e615053bSKevin Wolf -c "write -P 0x5a 0 512" \ 168e615053bSKevin Wolf -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ 169e615053bSKevin Wolf | _filter_qemu_io 170e615053bSKevin Wolf 171e615053bSKevin Wolf# The dirty bit must not be set 172e615053bSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features 173e615053bSKevin Wolf_check_test_img 174e615053bSKevin Wolf 1754c2e5f8fSKevin Wolf 176dc68afe0SStefan Hajnoczi# success, all done 177dc68afe0SStefan Hajnocziecho "*** done" 178dc68afe0SStefan Hajnoczirm -f $seq.full 179dc68afe0SStefan Hajnoczistatus=0 180dc68afe0SStefan Hajnoczi 181