19c468a01SWenchao Xia#!/bin/bash 29c468a01SWenchao Xia# 3f33d2873SWenchao Xia# Test export internal snapshot by qemu-nbd, convert it by qemu-img. 49c468a01SWenchao Xia# 59c468a01SWenchao Xia# Copyright (C) 2013 IBM, Inc. 69c468a01SWenchao Xia# 79c468a01SWenchao Xia# Based on 029. 89c468a01SWenchao Xia# 99c468a01SWenchao Xia# This program is free software; you can redistribute it and/or modify 109c468a01SWenchao Xia# it under the terms of the GNU General Public License as published by 119c468a01SWenchao Xia# the Free Software Foundation; either version 2 of the License, or 129c468a01SWenchao Xia# (at your option) any later version. 139c468a01SWenchao Xia# 149c468a01SWenchao Xia# This program is distributed in the hope that it will be useful, 159c468a01SWenchao Xia# but WITHOUT ANY WARRANTY; without even the implied warranty of 169c468a01SWenchao Xia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 179c468a01SWenchao Xia# GNU General Public License for more details. 189c468a01SWenchao Xia# 199c468a01SWenchao Xia# You should have received a copy of the GNU General Public License 209c468a01SWenchao Xia# along with this program. If not, see <http://www.gnu.org/licenses/>. 219c468a01SWenchao Xia# 229c468a01SWenchao Xia 239c468a01SWenchao Xia# creator 249c468a01SWenchao Xiaowner=xiawenc@linux.vnet.ibm.com 259c468a01SWenchao Xia 269c468a01SWenchao Xiaseq=`basename $0` 279c468a01SWenchao Xiaecho "QA output created by $seq" 289c468a01SWenchao Xia 299c468a01SWenchao Xiastatus=1 # failure is the default! 309c468a01SWenchao Xia 319c468a01SWenchao Xia_export_nbd_snapshot() 329c468a01SWenchao Xia{ 33*e6d5d6fdSDaniel P. Berrangé nbd_server_start_unix_socket "$TEST_IMG" -l $1 349c468a01SWenchao Xia} 359c468a01SWenchao Xia 369c468a01SWenchao Xia_export_nbd_snapshot1() 379c468a01SWenchao Xia{ 38*e6d5d6fdSDaniel P. Berrangé nbd_server_start_unix_socket "$TEST_IMG" -l snapshot.name=$1 399c468a01SWenchao Xia} 409c468a01SWenchao Xia 419c468a01SWenchao Xia_cleanup() 429c468a01SWenchao Xia{ 43*e6d5d6fdSDaniel P. Berrangé nbd_server_stop 449c468a01SWenchao Xia _cleanup_test_img 45f33d2873SWenchao Xia rm -f "$converted_image" 469c468a01SWenchao Xia} 479c468a01SWenchao Xiatrap "_cleanup; exit \$status" 0 1 2 3 15 489c468a01SWenchao Xia 499c468a01SWenchao Xia# get standard environment, filters and checks 509c468a01SWenchao Xia. ./common.rc 519c468a01SWenchao Xia. ./common.filter 529c468a01SWenchao Xia. ./common.pattern 53*e6d5d6fdSDaniel P. Berrangé. ./common.nbd 549c468a01SWenchao Xia 559c468a01SWenchao Xia_supported_fmt qcow2 569c468a01SWenchao Xia_supported_proto file 579c8ab1aeSFam Zheng_supported_os Linux 589c468a01SWenchao Xia_require_command QEMU_NBD 595262caa7SMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1 605262caa7SMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' 619c468a01SWenchao Xia 62*e6d5d6fdSDaniel P. Berrangénbd_snapshot_img="nbd:unix:$nbd_unix_socket" 63*e6d5d6fdSDaniel P. Berrangé 64*e6d5d6fdSDaniel P. Berrangéconverted_image=$TEST_IMG.converted 65*e6d5d6fdSDaniel P. Berrangé 668f9e835fSKevin Wolf# Use -f raw instead of -f $IMGFMT for the NBD connection 678f9e835fSKevin WolfQEMU_IO_NBD="$QEMU_IO -f raw --cache=$CACHEMODE" 688f9e835fSKevin Wolf 699c468a01SWenchao Xiaecho 709c468a01SWenchao Xiaecho "== preparing image ==" 719c468a01SWenchao Xia_make_test_img 64M 729c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xa 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 739c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xb 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 749c468a01SWenchao Xia$QEMU_IMG snapshot -c sn1 "$TEST_IMG" 759c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 769c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 779c468a01SWenchao Xia_check_test_img 789c468a01SWenchao Xia 799c468a01SWenchao Xiaecho 809c468a01SWenchao Xiaecho "== verifying the image file with patterns ==" 819c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 829c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 839c468a01SWenchao Xia 849c468a01SWenchao Xia_export_nbd_snapshot sn1 859c468a01SWenchao Xia 869c468a01SWenchao Xiaecho 879c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 1 ==" 881104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 891104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 909c468a01SWenchao Xia 919c468a01SWenchao Xia_export_nbd_snapshot1 sn1 929c468a01SWenchao Xia 939c468a01SWenchao Xiaecho 949c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 2 ==" 951104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 961104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 979c468a01SWenchao Xia 98f33d2873SWenchao Xia$QEMU_IMG convert "$TEST_IMG" -l sn1 -O qcow2 "$converted_image" 99f33d2873SWenchao Xia 100f33d2873SWenchao Xiaecho 101f33d2873SWenchao Xiaecho "== verifying the converted snapshot with patterns, method 1 ==" 102f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io 103f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io 104f33d2873SWenchao Xia 105f33d2873SWenchao Xia$QEMU_IMG convert "$TEST_IMG" -l snapshot.name=sn1 -O qcow2 "$converted_image" 106f33d2873SWenchao Xia 107f33d2873SWenchao Xiaecho 108f33d2873SWenchao Xiaecho "== verifying the converted snapshot with patterns, method 2 ==" 109f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io 110f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io 111f33d2873SWenchao Xia 1129c468a01SWenchao Xia# success, all done 1139c468a01SWenchao Xiaecho "*** done" 1149c468a01SWenchao Xiarm -f $seq.full 1159c468a01SWenchao Xiastatus=0 116