1*9c468a01SWenchao Xia#!/bin/bash 2*9c468a01SWenchao Xia# 3*9c468a01SWenchao Xia# Test export internal snapshot by qemu-nbd. 4*9c468a01SWenchao Xia# 5*9c468a01SWenchao Xia# Copyright (C) 2013 IBM, Inc. 6*9c468a01SWenchao Xia# 7*9c468a01SWenchao Xia# Based on 029. 8*9c468a01SWenchao Xia# 9*9c468a01SWenchao Xia# This program is free software; you can redistribute it and/or modify 10*9c468a01SWenchao Xia# it under the terms of the GNU General Public License as published by 11*9c468a01SWenchao Xia# the Free Software Foundation; either version 2 of the License, or 12*9c468a01SWenchao Xia# (at your option) any later version. 13*9c468a01SWenchao Xia# 14*9c468a01SWenchao Xia# This program is distributed in the hope that it will be useful, 15*9c468a01SWenchao Xia# but WITHOUT ANY WARRANTY; without even the implied warranty of 16*9c468a01SWenchao Xia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*9c468a01SWenchao Xia# GNU General Public License for more details. 18*9c468a01SWenchao Xia# 19*9c468a01SWenchao Xia# You should have received a copy of the GNU General Public License 20*9c468a01SWenchao Xia# along with this program. If not, see <http://www.gnu.org/licenses/>. 21*9c468a01SWenchao Xia# 22*9c468a01SWenchao Xia 23*9c468a01SWenchao Xia# creator 24*9c468a01SWenchao Xiaowner=xiawenc@linux.vnet.ibm.com 25*9c468a01SWenchao Xia 26*9c468a01SWenchao Xiaseq=`basename $0` 27*9c468a01SWenchao Xiaecho "QA output created by $seq" 28*9c468a01SWenchao Xia 29*9c468a01SWenchao Xiahere=`pwd` 30*9c468a01SWenchao Xiatmp=/tmp/$$ 31*9c468a01SWenchao Xiastatus=1 # failure is the default! 32*9c468a01SWenchao Xia 33*9c468a01SWenchao Xianbd_unix_socket=$TEST_DIR/test_qemu_nbd_socket 34*9c468a01SWenchao Xianbd_snapshot_img="nbd:unix:$nbd_unix_socket" 35*9c468a01SWenchao Xia 36*9c468a01SWenchao Xia_cleanup_nbd() 37*9c468a01SWenchao Xia{ 38*9c468a01SWenchao Xia if [ -n "$NBD_SNAPSHOT_PID" ]; then 39*9c468a01SWenchao Xia kill "$NBD_SNAPSHOT_PID" 40*9c468a01SWenchao Xia fi 41*9c468a01SWenchao Xia rm -f "$nbd_unix_socket" 42*9c468a01SWenchao Xia} 43*9c468a01SWenchao Xia 44*9c468a01SWenchao Xia_wait_for_nbd() 45*9c468a01SWenchao Xia{ 46*9c468a01SWenchao Xia for ((i = 0; i < 300; i++)) 47*9c468a01SWenchao Xia do 48*9c468a01SWenchao Xia if [ -r "$nbd_unix_socket" ]; then 49*9c468a01SWenchao Xia return 50*9c468a01SWenchao Xia fi 51*9c468a01SWenchao Xia sleep 0.1 52*9c468a01SWenchao Xia done 53*9c468a01SWenchao Xia echo "Failed in check of unix socket created by qemu-nbd" 54*9c468a01SWenchao Xia exit 1 55*9c468a01SWenchao Xia} 56*9c468a01SWenchao Xia 57*9c468a01SWenchao Xia_export_nbd_snapshot() 58*9c468a01SWenchao Xia{ 59*9c468a01SWenchao Xia _cleanup_nbd 60*9c468a01SWenchao Xia $QEMU_NBD -v -t -k "$nbd_unix_socket" "$TEST_IMG" -l $1 & 61*9c468a01SWenchao Xia NBD_SNAPSHOT_PID=$! 62*9c468a01SWenchao Xia _wait_for_nbd 63*9c468a01SWenchao Xia} 64*9c468a01SWenchao Xia 65*9c468a01SWenchao Xia_export_nbd_snapshot1() 66*9c468a01SWenchao Xia{ 67*9c468a01SWenchao Xia _cleanup_nbd 68*9c468a01SWenchao Xia $QEMU_NBD -v -t -k "$nbd_unix_socket" "$TEST_IMG" -l snapshot.name=$1 & 69*9c468a01SWenchao Xia NBD_SNAPSHOT_PID=$! 70*9c468a01SWenchao Xia _wait_for_nbd 71*9c468a01SWenchao Xia} 72*9c468a01SWenchao Xia 73*9c468a01SWenchao Xia_cleanup() 74*9c468a01SWenchao Xia{ 75*9c468a01SWenchao Xia _cleanup_nbd 76*9c468a01SWenchao Xia _cleanup_test_img 77*9c468a01SWenchao Xia} 78*9c468a01SWenchao Xiatrap "_cleanup; exit \$status" 0 1 2 3 15 79*9c468a01SWenchao Xia 80*9c468a01SWenchao Xia# get standard environment, filters and checks 81*9c468a01SWenchao Xia. ./common.rc 82*9c468a01SWenchao Xia. ./common.filter 83*9c468a01SWenchao Xia. ./common.pattern 84*9c468a01SWenchao Xia 85*9c468a01SWenchao Xia_supported_fmt qcow2 86*9c468a01SWenchao Xia_supported_proto file 87*9c468a01SWenchao Xia_require_command QEMU_NBD 88*9c468a01SWenchao Xia 89*9c468a01SWenchao Xiaecho 90*9c468a01SWenchao Xiaecho "== preparing image ==" 91*9c468a01SWenchao Xia_make_test_img 64M 92*9c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xa 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 93*9c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xb 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 94*9c468a01SWenchao Xia$QEMU_IMG snapshot -c sn1 "$TEST_IMG" 95*9c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 96*9c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 97*9c468a01SWenchao Xia_check_test_img 98*9c468a01SWenchao Xia 99*9c468a01SWenchao Xiaecho 100*9c468a01SWenchao Xiaecho "== verifying the image file with patterns ==" 101*9c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io 102*9c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io 103*9c468a01SWenchao Xia 104*9c468a01SWenchao Xia_export_nbd_snapshot sn1 105*9c468a01SWenchao Xia 106*9c468a01SWenchao Xiaecho 107*9c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 1 ==" 108*9c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 109*9c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 110*9c468a01SWenchao Xia 111*9c468a01SWenchao Xia_export_nbd_snapshot1 sn1 112*9c468a01SWenchao Xia 113*9c468a01SWenchao Xiaecho 114*9c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 2 ==" 115*9c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 116*9c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io 117*9c468a01SWenchao Xia 118*9c468a01SWenchao Xia# success, all done 119*9c468a01SWenchao Xiaecho "*** done" 120*9c468a01SWenchao Xiarm -f $seq.full 121*9c468a01SWenchao Xiastatus=0 122