111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 3426d52d8SDaniel P. Berrange# 4f4649069SEric Blake# Test encrypted read/write using plain bdrv_pread/bdrv_pwrite 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. Berrange 48426d52d8SDaniel P. BerrangeSECRET="secret,id=sec0,data=astrochicken" 49426d52d8SDaniel P. BerrangeSECRETALT="secret,id=sec0,data=platypus" 50426d52d8SDaniel P. Berrange 51426d52d8SDaniel P. Berrange_make_test_img --object $SECRET -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10" $size 52426d52d8SDaniel P. Berrange 535a840549SMax ReitzIMGSPEC="driver=$IMGFMT,encrypt.key-secret=sec0,file.filename=$TEST_IMG" 54426d52d8SDaniel P. Berrange 55426d52d8SDaniel P. BerrangeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 56426d52d8SDaniel P. Berrange 57426d52d8SDaniel P. Berrangeecho 58426d52d8SDaniel P. Berrangeecho "== reading whole image ==" 59426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET -c "read -P 0 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 60426d52d8SDaniel P. Berrange 61426d52d8SDaniel P. Berrangeecho 62426d52d8SDaniel P. Berrangeecho "== rewriting whole image ==" 63426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 64426d52d8SDaniel P. Berrange 65426d52d8SDaniel P. Berrangeecho 66426d52d8SDaniel P. Berrangeecho "== verify pattern ==" 67426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 68426d52d8SDaniel P. Berrange 69426d52d8SDaniel P. Berrangeecho 70426d52d8SDaniel P. Berrangeecho "== verify open failure with wrong password ==" 71426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRETALT -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 72426d52d8SDaniel P. Berrange 735a840549SMax Reitz_cleanup_test_img 745a840549SMax Reitz 755a840549SMax Reitzecho 765a840549SMax Reitzecho "== verify that has_zero_init returns false when preallocating ==" 775a840549SMax Reitz 785a840549SMax Reitz# Empty source file 795a840549SMax Reitzif [ -n "$TEST_IMG_FILE" ]; then 805a840549SMax Reitz TEST_IMG_FILE="${TEST_IMG_FILE}.orig" _make_test_img $size 815a840549SMax Reitzelse 825a840549SMax Reitz TEST_IMG="${TEST_IMG}.orig" _make_test_img $size 835a840549SMax Reitzfi 845a840549SMax Reitz 855a840549SMax Reitz$QEMU_IMG convert -O "$IMGFMT" --object $SECRET \ 865a840549SMax Reitz -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10,preallocation=metadata" \ 875a840549SMax Reitz "${TEST_IMG}.orig" "$TEST_IMG" 885a840549SMax Reitz 895a840549SMax Reitz$QEMU_IMG compare --object $SECRET --image-opts "${IMGSPEC}.orig" "$IMGSPEC" 905a840549SMax Reitz 91426d52d8SDaniel P. Berrange 92426d52d8SDaniel P. Berrange# success, all done 93426d52d8SDaniel P. Berrangeecho "*** done" 94426d52d8SDaniel P. Berrangerm -f $seq.full 95426d52d8SDaniel P. Berrangestatus=0 96