qemu

FORK: QEMU emulator
git clone https://git.neptards.moe/neptards/qemu.git
Log | Files | Refs | Submodules | LICENSE

215 (3960B)


      1 #!/usr/bin/env bash
      2 # group: rw quick
      3 #
      4 # Test case for copy-on-read into qcow2, using the COR filter driver
      5 #
      6 # Copyright (C) 2018 Red Hat, Inc.
      7 #
      8 # This program is free software; you can redistribute it and/or modify
      9 # it under the terms of the GNU General Public License as published by
     10 # the Free Software Foundation; either version 2 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This program is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # You should have received a copy of the GNU General Public License
     19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20 #
     21 
     22 seq="$(basename $0)"
     23 echo "QA output created by $seq"
     24 
     25 status=1 # failure is the default!
     26 
     27 # get standard environment, filters and checks
     28 . ./common.rc
     29 . ./common.filter
     30 
     31 TEST_WRAP="$TEST_DIR/t.wrap.qcow2"
     32 BLKDBG_CONF="$TEST_DIR/blkdebug.conf"
     33 
     34 # Sanity check: our use of blkdebug fails if $TEST_DIR contains spaces
     35 # or other problems
     36 case "$TEST_DIR" in
     37     *[^-_a-zA-Z0-9/]*)
     38         _notrun "Suspicious TEST_DIR='$TEST_DIR', cowardly refusing to run" ;;
     39 esac
     40 
     41 _cleanup()
     42 {
     43     _cleanup_test_img
     44     _rm_test_img "$TEST_WRAP"
     45     rm -f "$BLKDBG_CONF"
     46 }
     47 trap "_cleanup; exit \$status" 0 1 2 3 15
     48 
     49 # Test is supported for any backing file; but we force qcow2 for our wrapper.
     50 _supported_fmt generic
     51 _supported_proto generic
     52 # LUKS support may be possible, but it complicates things.
     53 _unsupported_fmt luks
     54 _unsupported_imgopts "subformat=streamOptimized"
     55 
     56 echo
     57 echo '=== Copy-on-read ==='
     58 echo
     59 
     60 # Prep the images
     61 # VPC rounds image sizes to a specific geometry, force a specific size.
     62 if [ "$IMGFMT" = "vpc" ]; then
     63     IMGOPTS=$(_optstr_add "$IMGOPTS" "force_size")
     64 fi
     65 _make_test_img 4G
     66 $QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io
     67 IMGPROTO=file IMGFMT=qcow2 TEST_IMG_FILE="$TEST_WRAP" \
     68     _make_test_img --no-opts -F "$IMGFMT" -b "$TEST_IMG" | _filter_img_create
     69 $QEMU_IO -f qcow2 -c "write -z -u 1M 64k" "$TEST_WRAP" | _filter_qemu_io
     70 
     71 # Ensure that a read of two clusters, but where one is already allocated,
     72 # does not re-write the allocated cluster
     73 cat > "$BLKDBG_CONF" <<EOF
     74 [inject-error]
     75 event = "cor_write"
     76 sector = "2048"
     77 EOF
     78 $QEMU_IO -c "open \
     79  -o driver=copy-on-read,file.driver=blkdebug,file.config=$BLKDBG_CONF,file.image.driver=qcow2 $TEST_WRAP" \
     80  -c "read -P 0 1M 128k" | _filter_qemu_io
     81 
     82 # Read the areas we want copied. A zero-length read should still be a
     83 # no-op.  The next read is under 2G, but aligned so that rounding to
     84 # clusters copies more than 2G of zeroes. The final read will pick up
     85 # the non-zero data in the same cluster.  Since a 2G read may exhaust
     86 # memory on some machines (particularly 32-bit), we skip the test if
     87 # that fails due to memory pressure.
     88 $QEMU_IO \
     89     -c "open -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
     90     -c "read 0 0" \
     91     | _filter_qemu_io
     92 output=$($QEMU_IO \
     93          -c "open -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
     94          -c "read -P 0 1k $((2*1024*1024*1024 - 512))" \
     95          2>&1 | _filter_qemu_io)
     96 case $output in
     97     *allocate*)
     98         _notrun "Insufficent memory to run test" ;;
     99     *) printf '%s\n' "$output" ;;
    100 esac
    101 $QEMU_IO \
    102     -c "open -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
    103     -c "read -P 0 $((3*1024*1024*1024 + 1024)) 1k" \
    104     | _filter_qemu_io
    105 
    106 # Copy-on-read is incompatible with read-only
    107 $QEMU_IO \
    108     -c "open -r -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
    109     2>&1 | _filter_testdir
    110 
    111 # Break the backing chain, and show that images are identical, and that
    112 # we properly copied over explicit zeros.
    113 $QEMU_IMG rebase -u -b "" -f qcow2 "$TEST_WRAP"
    114 $QEMU_IO -f qcow2 -c map "$TEST_WRAP"
    115 _check_test_img
    116 $QEMU_IMG compare -f $IMGFMT -F qcow2 "$TEST_IMG" "$TEST_WRAP"
    117 
    118 # success, all done
    119 echo '*** done'
    120 status=0