111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 39c468a01SWenchao Xia# 4f33d2873SWenchao Xia# Test export internal snapshot by qemu-nbd, convert it by qemu-img. 59c468a01SWenchao Xia# 69c468a01SWenchao Xia# Copyright (C) 2013 IBM, Inc. 79c468a01SWenchao Xia# 89c468a01SWenchao Xia# Based on 029. 99c468a01SWenchao Xia# 109c468a01SWenchao Xia# This program is free software; you can redistribute it and/or modify 119c468a01SWenchao Xia# it under the terms of the GNU General Public License as published by 129c468a01SWenchao Xia# the Free Software Foundation; either version 2 of the License, or 139c468a01SWenchao Xia# (at your option) any later version. 149c468a01SWenchao Xia# 159c468a01SWenchao Xia# This program is distributed in the hope that it will be useful, 169c468a01SWenchao Xia# but WITHOUT ANY WARRANTY; without even the implied warranty of 179c468a01SWenchao Xia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 189c468a01SWenchao Xia# GNU General Public License for more details. 199c468a01SWenchao Xia# 209c468a01SWenchao Xia# You should have received a copy of the GNU General Public License 219c468a01SWenchao Xia# along with this program. If not, see <http://www.gnu.org/licenses/>. 229c468a01SWenchao Xia# 239c468a01SWenchao Xia 249c468a01SWenchao Xia# creator 259c468a01SWenchao Xiaowner=xiawenc@linux.vnet.ibm.com 269c468a01SWenchao Xia 279c468a01SWenchao Xiaseq=`basename $0` 289c468a01SWenchao Xiaecho "QA output created by $seq" 299c468a01SWenchao Xia 309c468a01SWenchao Xiastatus=1 # failure is the default! 319c468a01SWenchao Xia 329c468a01SWenchao Xia_export_nbd_snapshot() 339c468a01SWenchao Xia{ 34e6d5d6fdSDaniel P. Berrangé nbd_server_start_unix_socket "$TEST_IMG" -l $1 359c468a01SWenchao Xia} 369c468a01SWenchao Xia 379c468a01SWenchao Xia_export_nbd_snapshot1() 389c468a01SWenchao Xia{ 39e6d5d6fdSDaniel P. Berrangé nbd_server_start_unix_socket "$TEST_IMG" -l snapshot.name=$1 409c468a01SWenchao Xia} 419c468a01SWenchao Xia 429c468a01SWenchao Xia_cleanup() 439c468a01SWenchao Xia{ 44e6d5d6fdSDaniel P. Berrangé nbd_server_stop 459c468a01SWenchao Xia _cleanup_test_img 46f91ecbd7SMax Reitz _rm_test_img "$converted_image" 479c468a01SWenchao Xia} 489c468a01SWenchao Xiatrap "_cleanup; exit \$status" 0 1 2 3 15 499c468a01SWenchao Xia 509c468a01SWenchao Xia# get standard environment, filters and checks 519c468a01SWenchao Xia. ./common.rc 529c468a01SWenchao Xia. ./common.filter 539c468a01SWenchao Xia. ./common.pattern 54e6d5d6fdSDaniel P. Berrangé. ./common.nbd 559c468a01SWenchao Xia 569c468a01SWenchao Xia_supported_fmt qcow2 579c468a01SWenchao Xia_supported_proto file 589c8ab1aeSFam Zheng_supported_os Linux 599c468a01SWenchao Xia_require_command QEMU_NBD 603be2024aSMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1, 613be2024aSMax Reitz# and generally impossible with external data files 623be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' data_file 639c468a01SWenchao Xia 64e6d5d6fdSDaniel P. Berrangénbd_snapshot_img="nbd:unix:$nbd_unix_socket" 65e6d5d6fdSDaniel P. Berrangé 66e6d5d6fdSDaniel P. Berrangéconverted_image=$TEST_IMG.converted 67e6d5d6fdSDaniel P. Berrangé 688f9e835fSKevin Wolf# Use -f raw instead of -f $IMGFMT for the NBD connection 698dff69b9SAarushi MehtaQEMU_IO_NBD="$QEMU_IO -f raw --cache=$CACHEMODE --aio=$AIOMODE" 708f9e835fSKevin Wolf 719c468a01SWenchao Xiaecho 729c468a01SWenchao Xiaecho "== preparing image ==" 739c468a01SWenchao Xia_make_test_img 64M 749c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xa 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 759c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xb 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 769c468a01SWenchao Xia$QEMU_IMG snapshot -c sn1 "$TEST_IMG" 779c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 789c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 799c468a01SWenchao Xia_check_test_img 809c468a01SWenchao Xia 819c468a01SWenchao Xiaecho 829c468a01SWenchao Xiaecho "== verifying the image file with patterns ==" 839c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 849c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 859c468a01SWenchao Xia 869c468a01SWenchao Xia_export_nbd_snapshot sn1 879c468a01SWenchao Xia 889c468a01SWenchao Xiaecho 899c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 1 ==" 901104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 911104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 929c468a01SWenchao Xia 939c468a01SWenchao Xia_export_nbd_snapshot1 sn1 949c468a01SWenchao Xia 959c468a01SWenchao Xiaecho 969c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 2 ==" 971104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 981104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 999c468a01SWenchao Xia 100f33d2873SWenchao Xia$QEMU_IMG convert "$TEST_IMG" -l sn1 -O qcow2 "$converted_image" 101f33d2873SWenchao Xia 102f33d2873SWenchao Xiaecho 103f33d2873SWenchao Xiaecho "== verifying the converted snapshot with patterns, method 1 ==" 104f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io 105f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io 106f33d2873SWenchao Xia 107f33d2873SWenchao Xia$QEMU_IMG convert "$TEST_IMG" -l snapshot.name=sn1 -O qcow2 "$converted_image" 108f33d2873SWenchao Xia 109f33d2873SWenchao Xiaecho 110f33d2873SWenchao Xiaecho "== verifying the converted snapshot with patterns, method 2 ==" 111f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io 112f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io 113f33d2873SWenchao Xia 1149c468a01SWenchao Xia# success, all done 1159c468a01SWenchao Xiaecho "*** done" 1169c468a01SWenchao Xiarm -f $seq.full 1179c468a01SWenchao Xiastatus=0 118