111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw 3426d52d8SDaniel P. Berrange# 4426d52d8SDaniel P. Berrange# Test encrypted read/write using backing files 5426d52d8SDaniel P. Berrange# 6426d52d8SDaniel P. Berrange# Copyright (C) 2017 Red Hat, Inc. 7426d52d8SDaniel P. Berrange# 8426d52d8SDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 9426d52d8SDaniel P. Berrange# it under the terms of the GNU General Public License as published by 10426d52d8SDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 11426d52d8SDaniel P. Berrange# (at your option) any later version. 12426d52d8SDaniel P. Berrange# 13426d52d8SDaniel P. Berrange# This program is distributed in the hope that it will be useful, 14426d52d8SDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 15426d52d8SDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16426d52d8SDaniel P. Berrange# GNU General Public License for more details. 17426d52d8SDaniel P. Berrange# 18426d52d8SDaniel P. Berrange# You should have received a copy of the GNU General Public License 19426d52d8SDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 20426d52d8SDaniel P. Berrange# 21426d52d8SDaniel P. Berrange 22426d52d8SDaniel P. Berrange# creator 23426d52d8SDaniel P. Berrangeowner=berrange@redhat.com 24426d52d8SDaniel P. Berrange 25426d52d8SDaniel P. Berrangeseq=`basename $0` 26426d52d8SDaniel P. Berrangeecho "QA output created by $seq" 27426d52d8SDaniel P. Berrange 28426d52d8SDaniel P. Berrangestatus=1 # failure is the default! 29426d52d8SDaniel P. Berrange 30426d52d8SDaniel P. Berrange_cleanup() 31426d52d8SDaniel P. Berrange{ 32426d52d8SDaniel P. Berrange _cleanup_test_img 33426d52d8SDaniel P. Berrange} 34426d52d8SDaniel P. Berrangetrap "_cleanup; exit \$status" 0 1 2 3 15 35426d52d8SDaniel P. Berrange 36426d52d8SDaniel P. Berrange# get standard environment, filters and checks 37426d52d8SDaniel P. Berrange. ./common.rc 38426d52d8SDaniel P. Berrange. ./common.filter 39426d52d8SDaniel P. Berrange 40426d52d8SDaniel P. Berrange_supported_fmt qcow2 41*9677061eSThomas Huth_supported_proto file 42426d52d8SDaniel P. Berrange_supported_os Linux 43d2a839edSMax Reitz_require_working_luks 44426d52d8SDaniel P. Berrange 45426d52d8SDaniel P. Berrange 46426d52d8SDaniel P. Berrangesize=16M 47426d52d8SDaniel P. BerrangeTEST_IMG_BASE=$TEST_IMG.base 48426d52d8SDaniel P. BerrangeSECRET0="secret,id=sec0,data=astrochicken" 49426d52d8SDaniel P. BerrangeSECRET1="secret,id=sec1,data=furby" 50426d52d8SDaniel P. Berrange 51426d52d8SDaniel P. BerrangeTEST_IMG_SAVE=$TEST_IMG 52426d52d8SDaniel P. BerrangeTEST_IMG=$TEST_IMG_BASE 53426d52d8SDaniel P. Berrangeecho "== create base ==" 54426d52d8SDaniel P. Berrange_make_test_img --object $SECRET0 -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10" $size 55426d52d8SDaniel P. BerrangeTEST_IMG=$TEST_IMG_SAVE 56426d52d8SDaniel P. Berrange 57426d52d8SDaniel P. BerrangeIMGSPECBASE="driver=$IMGFMT,file.filename=$TEST_IMG_BASE,encrypt.key-secret=sec0" 58426d52d8SDaniel P. BerrangeIMGSPEC="driver=$IMGFMT,file.filename=$TEST_IMG,backing.driver=$IMGFMT,backing.file.filename=$TEST_IMG_BASE,backing.encrypt.key-secret=sec0,encrypt.key-secret=sec1" 59426d52d8SDaniel P. BerrangeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 60426d52d8SDaniel P. Berrange 61426d52d8SDaniel P. Berrangeecho 62426d52d8SDaniel P. Berrangeecho "== writing whole image ==" 63426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "write -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 64426d52d8SDaniel P. Berrange 65426d52d8SDaniel P. Berrangeecho 66426d52d8SDaniel P. Berrangeecho "== verify pattern ==" 67426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir 68426d52d8SDaniel P. Berrange 69426d52d8SDaniel P. Berrangeecho "== create overlay ==" 70d5b23994SMax Reitz_make_test_img --object $SECRET1 -o "encrypt.format=luks,encrypt.key-secret=sec1,encrypt.iter-time=10" -b "$TEST_IMG_BASE" -F $IMGFMT 71426d52d8SDaniel P. Berrange 72426d52d8SDaniel P. Berrangeecho 73426d52d8SDaniel P. Berrangeecho "== writing part of a cluster ==" 74426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "write -P 0xe 0 1024" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 75426d52d8SDaniel P. Berrange 76426d52d8SDaniel P. Berrangeecho 77426d52d8SDaniel P. Berrangeecho "== verify pattern ==" 78426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0xe 0 1024" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 79426d52d8SDaniel P. Berrangeecho 80426d52d8SDaniel P. Berrangeecho "== verify pattern ==" 81426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0xa 1024 64512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 82426d52d8SDaniel P. Berrange 83426d52d8SDaniel P. Berrange 84426d52d8SDaniel P. Berrange# success, all done 85426d52d8SDaniel P. Berrangeecho "*** done" 86426d52d8SDaniel P. Berrangerm -f $seq.full 87426d52d8SDaniel P. Berrangestatus=0 88