1#!/usr/bin/env bash 2# 3# qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034) 4# 5# Copyright (C) 2016-2017 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27status=1 # failure is the default! 28 29_cleanup() 30{ 31 _cleanup_test_img 32} 33trap "_cleanup; exit \$status" 0 1 2 3 15 34 35# get standard environment, filters and checks 36. ./common.rc 37. ./common.filter 38 39_supported_fmt qcow2 40_supported_proto file 41_supported_os Linux 42 43CLUSTER_SIZE=4k 44size=$((128 * 1024 * 1024)) 45 46# This test requires zero clusters, added in v3 images 47_unsupported_imgopts compat=0.10 48 49echo 50echo == backing file contains zeros == 51 52CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 53_make_test_img -b "$TEST_IMG.base" 54 55# Make sure that the whole cluster is allocated even for partial write_zeroes 56# when the backing file contains zeros 57 58# X = non-zero data sector in backing file 59# - = sector unallocated in whole backing chain 60# 0 = sector touched by write_zeroes request 61 62# 1. Tail unaligned: 00 00 -- -- 63# 2. Head unaligned: -- -- 00 00 64# 3. Both unaligned: -- 00 00 -- 65# 4. Both, 2 clusters: -- -- -- 00 | 00 -- -- -- 66 67$QEMU_IO -c "write -z 0 2k" "$TEST_IMG" | _filter_qemu_io 68$QEMU_IO -c "write -z 10k 2k" "$TEST_IMG" | _filter_qemu_io 69$QEMU_IO -c "write -z 17k 2k" "$TEST_IMG" | _filter_qemu_io 70$QEMU_IO -c "write -z 27k 2k" "$TEST_IMG" | _filter_qemu_io 71$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 72 73echo 74echo == backing file contains non-zero data before write_zeroes == 75 76CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 77_make_test_img -b "$TEST_IMG.base" 78 79# Single cluster; non-zero data at the cluster start 80# ... | XX -- 00 -- | ... 81$QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io 82$QEMU_IO -c "write -z 34k 1k" "$TEST_IMG" | _filter_qemu_io 83$QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io 84$QEMU_IO -c "read -P 0 33k 3k" "$TEST_IMG" | _filter_qemu_io 85 86# Single cluster; non-zero data exists, but not at the cluster start 87# ... | -- XX 00 -- | ... 88$QEMU_IO -c "write -P 0x11 65k 1k" "$TEST_IMG.base" | _filter_qemu_io 89$QEMU_IO -c "write -z 66k 1k" "$TEST_IMG" | _filter_qemu_io 90$QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io 91$QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io 92$QEMU_IO -c "read -P 0 66k 2k" "$TEST_IMG" | _filter_qemu_io 93 94$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 95 96echo 97echo == backing file contains non-zero data after write_zeroes == 98 99CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 100_make_test_img -b "$TEST_IMG.base" 101 102# Single cluster; non-zero data directly after request 103# ... | -- 00 XX -- | ... 104$QEMU_IO -c "write -P 0x11 34k 1k" "$TEST_IMG.base" | _filter_qemu_io 105$QEMU_IO -c "write -z 33k 1k" "$TEST_IMG" | _filter_qemu_io 106$QEMU_IO -c "read -P 0 32k 2k" "$TEST_IMG" | _filter_qemu_io 107$QEMU_IO -c "read -P 0x11 34k 1k" "$TEST_IMG" | _filter_qemu_io 108$QEMU_IO -c "read -P 0 35k 1k" "$TEST_IMG" | _filter_qemu_io 109 110# Single cluster; non-zero data exists, but not directly after request 111# ... | -- 00 -- XX | ... 112$QEMU_IO -c "write -P 0x11 43k 1k" "$TEST_IMG.base" | _filter_qemu_io 113$QEMU_IO -c "write -z 41k 1k" "$TEST_IMG" | _filter_qemu_io 114$QEMU_IO -c "read -P 0x11 43k 1k" "$TEST_IMG" | _filter_qemu_io 115$QEMU_IO -c "read -P 0 40k 3k" "$TEST_IMG" | _filter_qemu_io 116 117$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 118 119echo 120echo == write_zeroes covers non-zero data == 121 122CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 123_make_test_img -b "$TEST_IMG.base" 124 125# non-zero data at front of request 126# Backing file: -- XX -- -- 127# Active layer: -- 00 00 -- 128 129$QEMU_IO -c "write -P 0x11 5k 1k" "$TEST_IMG.base" | _filter_qemu_io 130$QEMU_IO -c "write -z 5k 2k" "$TEST_IMG" | _filter_qemu_io 131$QEMU_IO -c "read -P 0 4k 4k" "$TEST_IMG" | _filter_qemu_io 132 133# non-zero data at end of request 134# Backing file: -- -- XX -- 135# Active layer: -- 00 00 -- 136 137$QEMU_IO -c "write -P 0x11 14k 1k" "$TEST_IMG.base" | _filter_qemu_io 138$QEMU_IO -c "write -z 13k 2k" "$TEST_IMG" | _filter_qemu_io 139$QEMU_IO -c "read -P 0 12k 4k" "$TEST_IMG" | _filter_qemu_io 140 141# non-zero data matches size of request 142# Backing file: -- XX XX -- 143# Active layer: -- 00 00 -- 144 145$QEMU_IO -c "write -P 0x11 21k 2k" "$TEST_IMG.base" | _filter_qemu_io 146$QEMU_IO -c "write -z 21k 2k" "$TEST_IMG" | _filter_qemu_io 147$QEMU_IO -c "read -P 0 20k 4k" "$TEST_IMG" | _filter_qemu_io 148 149# non-zero data smaller than request 150# Backing file: -- -X X- -- 151# Active layer: -- 00 00 -- 152 153$QEMU_IO -c "write -P 0x11 30208 1k" "$TEST_IMG.base" | _filter_qemu_io 154$QEMU_IO -c "write -z 29k 2k" "$TEST_IMG" | _filter_qemu_io 155$QEMU_IO -c "read -P 0 28k 4k" "$TEST_IMG" | _filter_qemu_io 156 157$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 158 159echo 160echo == spanning two clusters, non-zero before request == 161 162CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 163_make_test_img -b "$TEST_IMG.base" 164 165# Two clusters; non-zero data before request: 166# 1. At cluster start: 32k: XX -- -- 00 | 00 -- -- -- 167# 2. Between unallocated space: 48k: -- XX -- 00 | 00 -- -- -- 168# 3. Directly before request: 64k: -- -- XX 00 | 00 -- -- -- 169 170$QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io 171$QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io 172$QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io 173$QEMU_IO -c "read -P 0 33k 7k" "$TEST_IMG" | _filter_qemu_io 174 175$QEMU_IO -c "write -P 0x11 49k 1k" "$TEST_IMG.base" | _filter_qemu_io 176$QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io 177$QEMU_IO -c "read -P 0 48k 1k" "$TEST_IMG" | _filter_qemu_io 178$QEMU_IO -c "read -P 0x11 49k 1k" "$TEST_IMG" | _filter_qemu_io 179$QEMU_IO -c "read -P 0 50k 6k" "$TEST_IMG" | _filter_qemu_io 180 181$QEMU_IO -c "write -P 0x11 66k 1k" "$TEST_IMG.base" | _filter_qemu_io 182$QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io 183$QEMU_IO -c "read -P 0 64k 2k" "$TEST_IMG" | _filter_qemu_io 184$QEMU_IO -c "read -P 0x11 66k 1k" "$TEST_IMG" | _filter_qemu_io 185$QEMU_IO -c "read -P 0 67k 5k" "$TEST_IMG" | _filter_qemu_io 186 187$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 188 189echo 190echo == spanning two clusters, non-zero after request == 191 192CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 193_make_test_img -b "$TEST_IMG.base" 194 195# Two clusters; non-zero data after request: 196# 1. Directly after request: 32k: -- -- -- 00 | 00 XX -- -- 197# 2. Between unallocated space: 48k: -- -- -- 00 | 00 -- XX -- 198# 3. At cluster end: 64k: -- -- -- 00 | 00 -- -- XX 199 200$QEMU_IO -c "write -P 0x11 37k 1k" "$TEST_IMG.base" | _filter_qemu_io 201$QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io 202$QEMU_IO -c "read -P 0 32k 5k" "$TEST_IMG" | _filter_qemu_io 203$QEMU_IO -c "read -P 0x11 37k 1k" "$TEST_IMG" | _filter_qemu_io 204$QEMU_IO -c "read -P 0 38k 2k" "$TEST_IMG" | _filter_qemu_io 205 206$QEMU_IO -c "write -P 0x11 54k 1k" "$TEST_IMG.base" | _filter_qemu_io 207$QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io 208$QEMU_IO -c "read -P 0 48k 6k" "$TEST_IMG" | _filter_qemu_io 209$QEMU_IO -c "read -P 0x11 54k 1k" "$TEST_IMG" | _filter_qemu_io 210$QEMU_IO -c "read -P 0 55k 1k" "$TEST_IMG" | _filter_qemu_io 211 212$QEMU_IO -c "write -P 0x11 71k 1k" "$TEST_IMG.base" | _filter_qemu_io 213$QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io 214$QEMU_IO -c "read -P 0 64k 7k" "$TEST_IMG" | _filter_qemu_io 215$QEMU_IO -c "read -P 0x11 71k 1k" "$TEST_IMG" | _filter_qemu_io 216 217$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 218 219echo 220echo == spanning two clusters, partially overwriting backing file == 221 222CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 223_make_test_img -b "$TEST_IMG.base" 224 225# Backing file: -- -- XX XX | XX XX -- -- 226# Active layer: -- -- XX 00 | 00 XX -- -- 227 228$QEMU_IO -c "write -P 0x11 2k 4k" "$TEST_IMG.base" | _filter_qemu_io 229$QEMU_IO -c "write -z 3k 2k" "$TEST_IMG" | _filter_qemu_io 230$QEMU_IO -c "read -P 0 0k 2k" "$TEST_IMG" | _filter_qemu_io 231$QEMU_IO -c "read -P 0x11 2k 1k" "$TEST_IMG" | _filter_qemu_io 232$QEMU_IO -c "read -P 0 3k 2k" "$TEST_IMG" | _filter_qemu_io 233$QEMU_IO -c "read -P 0x11 5k 1k" "$TEST_IMG" | _filter_qemu_io 234$QEMU_IO -c "read -P 0 6k 2k" "$TEST_IMG" | _filter_qemu_io 235 236$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 237 238echo 239echo == spanning multiple clusters, non-zero in first cluster == 240 241CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 242_make_test_img -b "$TEST_IMG.base" 243 244# Backing file: 64k: XX XX -- -- | -- -- -- -- | -- -- -- -- 245# Active layer: 64k: XX XX 00 00 | 00 00 00 00 | 00 -- -- -- 246 247$QEMU_IO -c "write -P 0x11 64k 2k" "$TEST_IMG.base" | _filter_qemu_io 248$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io 249$QEMU_IO -c "read -P 0x11 64k 2k" "$TEST_IMG" | _filter_qemu_io 250$QEMU_IO -c "read -P 0 66k 10k" "$TEST_IMG" | _filter_qemu_io 251 252$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 253 254echo 255echo == spanning multiple clusters, non-zero in intermediate cluster == 256 257CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 258_make_test_img -b "$TEST_IMG.base" 259 260# Backing file: 64k: -- -- -- -- | -- XX XX -- | -- -- -- -- 261# Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- -- -- 262 263$QEMU_IO -c "write -P 0x11 69k 2k" "$TEST_IMG.base" | _filter_qemu_io 264$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io 265$QEMU_IO -c "read -P 0 64k 12k" "$TEST_IMG" | _filter_qemu_io 266 267$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 268 269echo 270echo == spanning multiple clusters, non-zero in final cluster == 271 272CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 273_make_test_img -b "$TEST_IMG.base" 274 275# Backing file: 64k: -- -- -- -- | -- -- -- -- | -- -- XX XX 276# Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- XX XX 277 278$QEMU_IO -c "write -P 0x11 74k 2k" "$TEST_IMG.base" | _filter_qemu_io 279$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io 280$QEMU_IO -c "read -P 0 64k 10k" "$TEST_IMG" | _filter_qemu_io 281$QEMU_IO -c "read -P 0x11 74k 2k" "$TEST_IMG" | _filter_qemu_io 282 283$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 284 285echo 286echo == spanning multiple clusters, partially overwriting backing file == 287 288CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size 289_make_test_img -b "$TEST_IMG.base" 290 291# Backing file: 64k: -- XX XX XX | XX XX XX XX | XX XX XX -- 292# Active layer: 64k: -- XX 00 00 | 00 00 00 00 | 00 XX XX -- 293 294$QEMU_IO -c "write -P 0x11 65k 10k" "$TEST_IMG.base" | _filter_qemu_io 295$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io 296$QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io 297$QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io 298$QEMU_IO -c "read -P 0 66k 7k" "$TEST_IMG" | _filter_qemu_io 299$QEMU_IO -c "read -P 0x11 73k 2k" "$TEST_IMG" | _filter_qemu_io 300$QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io 301 302$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 303 304echo 305echo == unaligned image tail cluster, no allocation needed == 306 307# With no backing file, write to all or part of unallocated partial cluster 308# will mark the cluster as zero, but does not allocate. 309# Re-create the image each time to get back to unallocated clusters. 310 311# Write at the front: sector-wise, the request is: 128m... | 00 -- -- -- 312_make_test_img $((size + 2048)) 313$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io 314$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 315$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 316 317# Write at the back: sector-wise, the request is: 128m... | -- -- -- 00 318_make_test_img $((size + 2048)) 319$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io 320$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 321$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 322 323# Write at middle: sector-wise, the request is: 128m... | -- 00 00 -- 324_make_test_img $((size + 2048)) 325$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io 326$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 327$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 328 329# Write entire cluster: sector-wise, the request is: 128m... | 00 00 00 00 330_make_test_img $((size + 2048)) 331$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io 332$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 333$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 334 335# Repeat with backing file holding unallocated cluster. 336CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024)) 337 338# Write at the front: sector-wise, the request is: 339# backing: 128m... | -- -- 340# active: 128m... | 00 -- -- -- 341_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 342$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io 343$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 344$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 345 346# Write at the back: sector-wise, the request is: 347# backing: 128m... | -- -- 348# active: 128m... | -- -- -- 00 349_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 350$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io 351$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 352$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 353 354# Write at middle: sector-wise, the request is: 355# backing: 128m... | -- -- 356# active: 128m... | -- 00 00 -- 357_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 358$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io 359$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 360$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 361 362# Write entire cluster: sector-wise, the request is: 363# backing: 128m... | -- -- 364# active: 128m... | 00 00 00 00 365_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 366$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io 367$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 368$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 369 370# Repeat with backing file holding zero'd cluster 371$QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io 372 373# Write at the front: sector-wise, the request is: 374# backing: 128m... | 00 00 375# active: 128m... | 00 -- -- -- 376_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 377$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io 378$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 379$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 380 381# Write at the back: sector-wise, the request is: 382# backing: 128m... | 00 00 383# active: 128m... | -- -- -- 00 384_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 385$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io 386$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 387$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 388 389# Write at middle: sector-wise, the request is: 390# backing: 128m... | 00 00 391# active: 128m... | -- 00 00 -- 392_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 393$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io 394$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 395$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 396 397# Write entire cluster: sector-wise, the request is: 398# backing: 128m... | 00 00 399# active: 128m... | 00 00 00 00 400_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 401$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io 402$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io 403$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 404 405# A preallocated cluster maintains its allocation, whether it stays as 406# data due to a partial write: 407# Convert 128m... | XX XX => ... | XX 00 408_make_test_img $((size + 1024)) 409$QEMU_IO -c "write -P 1 $((size)) 1024" "$TEST_IMG" | _filter_qemu_io 410$QEMU_IO -c "write -z $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io 411$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io 412$QEMU_IO -c "read -P 0 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io 413$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io 414$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 415 416# or because it is the entire cluster and can use the zero flag: 417# Convert 128m... | XX XX => ... | 00 00 418$QEMU_IO -c "write -z $((size)) 1024" "$TEST_IMG" | _filter_qemu_io 419$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io 420$QEMU_IO -c "read -P 0 $size 1024" "$TEST_IMG" | _filter_qemu_io 421$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 422 423echo 424echo == unaligned image tail cluster, allocation required == 425 426# Write beyond backing file must COW 427# Backing file: 128m... | XX -- 428# Active layer: 128m... | -- -- 00 -- 429CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024)) 430_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 431$QEMU_IO -c "write -P 1 $((size)) 512" "$TEST_IMG.base" | _filter_qemu_io 432$QEMU_IO -c "write -z $((size + 1024)) 512" "$TEST_IMG" | _filter_qemu_io 433$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io 434$QEMU_IO -c "read -P 0 $((size + 512)) 1536" "$TEST_IMG" | _filter_qemu_io 435$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 436 437# Writes at boundaries of (partial) cluster must not lose mid-cluster data 438# Backing file: 128m: ... | -- XX 439# Active layer: 128m: ... | 00 -- -- 00 440CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024)) 441_make_test_img -b "$TEST_IMG.base" $((size + 2048)) 442$QEMU_IO -c "write -P 1 $((size + 512)) 512" "$TEST_IMG.base" | _filter_qemu_io 443$QEMU_IO -c "write -z $((size)) 512" "$TEST_IMG" | _filter_qemu_io 444$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io 445$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io 446$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io 447$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io 448$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io 449$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io 450$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io 451$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 452 453# success, all done 454echo "*** done" 455rm -f $seq.full 456status=0 457