1dbc7b014SEric Blake#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3dbc7b014SEric Blake# 4dbc7b014SEric Blake# Test qemu-nbd -A 5dbc7b014SEric Blake# 6*1cfd21ccSEric Blake# Copyright (C) 2018-2021 Red Hat, Inc. 7dbc7b014SEric Blake# 8dbc7b014SEric Blake# This program is free software; you can redistribute it and/or modify 9dbc7b014SEric Blake# it under the terms of the GNU General Public License as published by 10dbc7b014SEric Blake# the Free Software Foundation; either version 2 of the License, or 11dbc7b014SEric Blake# (at your option) any later version. 12dbc7b014SEric Blake# 13dbc7b014SEric Blake# This program is distributed in the hope that it will be useful, 14dbc7b014SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of 15dbc7b014SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16dbc7b014SEric Blake# GNU General Public License for more details. 17dbc7b014SEric Blake# 18dbc7b014SEric Blake# You should have received a copy of the GNU General Public License 19dbc7b014SEric Blake# along with this program. If not, see <http://www.gnu.org/licenses/>. 20dbc7b014SEric Blake# 21dbc7b014SEric Blake 22dbc7b014SEric Blakeseq="$(basename $0)" 23dbc7b014SEric Blakeecho "QA output created by $seq" 24dbc7b014SEric Blake 25dbc7b014SEric Blakestatus=1 # failure is the default! 26dbc7b014SEric Blake 27dbc7b014SEric Blake_cleanup() 28dbc7b014SEric Blake{ 29dbc7b014SEric Blake _cleanup_test_img 30dbc7b014SEric Blake nbd_server_stop 31dbc7b014SEric Blake} 32dbc7b014SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15 33dbc7b014SEric Blake 34dbc7b014SEric Blake# get standard environment, filters and checks 35*1cfd21ccSEric Blakecd .. 36dbc7b014SEric Blake. ./common.rc 37dbc7b014SEric Blake. ./common.filter 38dbc7b014SEric Blake. ./common.nbd 39dbc7b014SEric Blake 40dbc7b014SEric Blake_supported_fmt qcow2 41dbc7b014SEric Blake_supported_proto file 42dbc7b014SEric Blake_supported_os Linux 43dbc7b014SEric Blake_require_command QEMU_NBD 44dbc7b014SEric Blake 45dbc7b014SEric Blakeecho 46dbc7b014SEric Blakeecho "=== Initial image setup ===" 47dbc7b014SEric Blakeecho 48dbc7b014SEric Blake 49dbc7b014SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img 4M 50dbc7b014SEric Blake$QEMU_IO -c 'w 0 2M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io 51dbc7b014SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 4M 52dbc7b014SEric Blake$QEMU_IO -c 'w 1M 2M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io 53dbc7b014SEric Blake 54dbc7b014SEric Blakeecho 55dbc7b014SEric Blakeecho "=== Check allocation over NBD ===" 56dbc7b014SEric Blakeecho 57dbc7b014SEric Blake 58dbc7b014SEric Blake$QEMU_IMG map --output=json -f qcow2 "$TEST_IMG" 59dbc7b014SEric BlakeIMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" 60dbc7b014SEric Blakenbd_server_start_unix_socket -r -f qcow2 -A "$TEST_IMG" 61*1cfd21ccSEric Blake# Inspect what the server is exposing 62*1cfd21ccSEric Blake$QEMU_NBD --list -k $nbd_unix_socket 63dbc7b014SEric Blake# Normal -f raw NBD block status loses access to allocation information 64dbc7b014SEric Blake$QEMU_IMG map --output=json --image-opts \ 65dbc7b014SEric Blake "$IMG" | _filter_qemu_img_map 66dbc7b014SEric Blake# But when we use -A, coupled with x-dirty-bitmap in the client for feeding 67dbc7b014SEric Blake# 2-bit block status from an alternative NBD metadata context (note that 68dbc7b014SEric Blake# the client code for x-dirty-bitmap intentionally collapses all depths 69dbc7b014SEric Blake# beyond 2 into a single value), we can determine: 70dbc7b014SEric Blake# unallocated (depth 0) => "zero":false, "data":true 71dbc7b014SEric Blake# local (depth 1) => "zero":false, "data":false 72dbc7b014SEric Blake# backing (depth 2+) => "zero":true, "data":true 73dbc7b014SEric Blake$QEMU_IMG map --output=json --image-opts \ 74dbc7b014SEric Blake "$IMG,x-dirty-bitmap=qemu:allocation-depth" | _filter_qemu_img_map 75dbc7b014SEric Blake# More accurate results can be obtained by other NBD clients such as 76dbc7b014SEric Blake# libnbd, but this test works without such external dependencies. 77dbc7b014SEric Blake 78dbc7b014SEric Blake# success, all done 79dbc7b014SEric Blakeecho '*** done' 80dbc7b014SEric Blakerm -f $seq.full 81dbc7b014SEric Blakestatus=0 82