1baefd977SVladimir Sementsov-Ogievskiy /* 2baefd977SVladimir Sementsov-Ogievskiy * Support of Parallels Format Extension. It's a part of Parallels format 3baefd977SVladimir Sementsov-Ogievskiy * driver. 4baefd977SVladimir Sementsov-Ogievskiy * 5baefd977SVladimir Sementsov-Ogievskiy * Copyright (c) 2021 Virtuozzo International GmbH 6baefd977SVladimir Sementsov-Ogievskiy * 7baefd977SVladimir Sementsov-Ogievskiy * Permission is hereby granted, free of charge, to any person obtaining a copy 8baefd977SVladimir Sementsov-Ogievskiy * of this software and associated documentation files (the "Software"), to deal 9baefd977SVladimir Sementsov-Ogievskiy * in the Software without restriction, including without limitation the rights 10baefd977SVladimir Sementsov-Ogievskiy * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11baefd977SVladimir Sementsov-Ogievskiy * copies of the Software, and to permit persons to whom the Software is 12baefd977SVladimir Sementsov-Ogievskiy * furnished to do so, subject to the following conditions: 13baefd977SVladimir Sementsov-Ogievskiy * 14baefd977SVladimir Sementsov-Ogievskiy * The above copyright notice and this permission notice shall be included in 15baefd977SVladimir Sementsov-Ogievskiy * all copies or substantial portions of the Software. 16baefd977SVladimir Sementsov-Ogievskiy * 17baefd977SVladimir Sementsov-Ogievskiy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18baefd977SVladimir Sementsov-Ogievskiy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19baefd977SVladimir Sementsov-Ogievskiy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20baefd977SVladimir Sementsov-Ogievskiy * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21baefd977SVladimir Sementsov-Ogievskiy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22baefd977SVladimir Sementsov-Ogievskiy * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23baefd977SVladimir Sementsov-Ogievskiy * THE SOFTWARE. 24baefd977SVladimir Sementsov-Ogievskiy */ 25baefd977SVladimir Sementsov-Ogievskiy 26baefd977SVladimir Sementsov-Ogievskiy #include "qemu/osdep.h" 27baefd977SVladimir Sementsov-Ogievskiy #include "qapi/error.h" 28baefd977SVladimir Sementsov-Ogievskiy #include "block/block_int.h" 29baefd977SVladimir Sementsov-Ogievskiy #include "parallels.h" 30baefd977SVladimir Sementsov-Ogievskiy #include "crypto/hash.h" 31baefd977SVladimir Sementsov-Ogievskiy #include "qemu/uuid.h" 325df022cfSPeter Maydell #include "qemu/memalign.h" 33baefd977SVladimir Sementsov-Ogievskiy 34baefd977SVladimir Sementsov-Ogievskiy #define PARALLELS_FORMAT_EXTENSION_MAGIC 0xAB234CEF23DCEA87ULL 35baefd977SVladimir Sementsov-Ogievskiy 36baefd977SVladimir Sementsov-Ogievskiy #define PARALLELS_END_OF_FEATURES_MAGIC 0x0ULL 37baefd977SVladimir Sementsov-Ogievskiy #define PARALLELS_DIRTY_BITMAP_FEATURE_MAGIC 0x20385FAE252CB34AULL 38baefd977SVladimir Sementsov-Ogievskiy 39baefd977SVladimir Sementsov-Ogievskiy typedef struct ParallelsFormatExtensionHeader { 40baefd977SVladimir Sementsov-Ogievskiy uint64_t magic; /* PARALLELS_FORMAT_EXTENSION_MAGIC */ 41baefd977SVladimir Sementsov-Ogievskiy uint8_t check_sum[16]; 42baefd977SVladimir Sementsov-Ogievskiy } QEMU_PACKED ParallelsFormatExtensionHeader; 43baefd977SVladimir Sementsov-Ogievskiy 44baefd977SVladimir Sementsov-Ogievskiy typedef struct ParallelsFeatureHeader { 45baefd977SVladimir Sementsov-Ogievskiy uint64_t magic; 46baefd977SVladimir Sementsov-Ogievskiy uint64_t flags; 47baefd977SVladimir Sementsov-Ogievskiy uint32_t data_size; 48baefd977SVladimir Sementsov-Ogievskiy uint32_t _unused; 49baefd977SVladimir Sementsov-Ogievskiy } QEMU_PACKED ParallelsFeatureHeader; 50baefd977SVladimir Sementsov-Ogievskiy 51baefd977SVladimir Sementsov-Ogievskiy typedef struct ParallelsDirtyBitmapFeature { 52baefd977SVladimir Sementsov-Ogievskiy uint64_t size; 53baefd977SVladimir Sementsov-Ogievskiy uint8_t id[16]; 54baefd977SVladimir Sementsov-Ogievskiy uint32_t granularity; 55baefd977SVladimir Sementsov-Ogievskiy uint32_t l1_size; 56baefd977SVladimir Sementsov-Ogievskiy /* L1 table follows */ 57baefd977SVladimir Sementsov-Ogievskiy } QEMU_PACKED ParallelsDirtyBitmapFeature; 58baefd977SVladimir Sementsov-Ogievskiy 59baefd977SVladimir Sementsov-Ogievskiy /* Given L1 table read bitmap data from the image and populate @bitmap */ 60baefd977SVladimir Sementsov-Ogievskiy static int parallels_load_bitmap_data(BlockDriverState *bs, 61baefd977SVladimir Sementsov-Ogievskiy const uint64_t *l1_table, 62baefd977SVladimir Sementsov-Ogievskiy uint32_t l1_size, 63baefd977SVladimir Sementsov-Ogievskiy BdrvDirtyBitmap *bitmap, 64baefd977SVladimir Sementsov-Ogievskiy Error **errp) 65baefd977SVladimir Sementsov-Ogievskiy { 66baefd977SVladimir Sementsov-Ogievskiy BDRVParallelsState *s = bs->opaque; 67baefd977SVladimir Sementsov-Ogievskiy int ret = 0; 68baefd977SVladimir Sementsov-Ogievskiy uint64_t offset, limit; 69baefd977SVladimir Sementsov-Ogievskiy uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); 70baefd977SVladimir Sementsov-Ogievskiy uint8_t *buf = NULL; 71baefd977SVladimir Sementsov-Ogievskiy uint64_t i, tab_size = 72baefd977SVladimir Sementsov-Ogievskiy DIV_ROUND_UP(bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size), 73baefd977SVladimir Sementsov-Ogievskiy s->cluster_size); 74baefd977SVladimir Sementsov-Ogievskiy 75baefd977SVladimir Sementsov-Ogievskiy if (tab_size != l1_size) { 76baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Bitmap table size %" PRIu32 " does not correspond " 77baefd977SVladimir Sementsov-Ogievskiy "to bitmap size and cluster size. Expected %" PRIu64, 78baefd977SVladimir Sementsov-Ogievskiy l1_size, tab_size); 79baefd977SVladimir Sementsov-Ogievskiy return -EINVAL; 80baefd977SVladimir Sementsov-Ogievskiy } 81baefd977SVladimir Sementsov-Ogievskiy 82baefd977SVladimir Sementsov-Ogievskiy buf = qemu_blockalign(bs, s->cluster_size); 83baefd977SVladimir Sementsov-Ogievskiy limit = bdrv_dirty_bitmap_serialization_coverage(s->cluster_size, bitmap); 84baefd977SVladimir Sementsov-Ogievskiy for (i = 0, offset = 0; i < tab_size; ++i, offset += limit) { 85baefd977SVladimir Sementsov-Ogievskiy uint64_t count = MIN(bm_size - offset, limit); 86baefd977SVladimir Sementsov-Ogievskiy uint64_t entry = l1_table[i]; 87baefd977SVladimir Sementsov-Ogievskiy 88baefd977SVladimir Sementsov-Ogievskiy if (entry == 0) { 89baefd977SVladimir Sementsov-Ogievskiy /* No need to deserialize zeros because @bitmap is cleared. */ 90baefd977SVladimir Sementsov-Ogievskiy continue; 91baefd977SVladimir Sementsov-Ogievskiy } 92baefd977SVladimir Sementsov-Ogievskiy 93baefd977SVladimir Sementsov-Ogievskiy if (entry == 1) { 94baefd977SVladimir Sementsov-Ogievskiy bdrv_dirty_bitmap_deserialize_ones(bitmap, offset, count, false); 95baefd977SVladimir Sementsov-Ogievskiy } else { 96baefd977SVladimir Sementsov-Ogievskiy ret = bdrv_pread(bs->file, entry << BDRV_SECTOR_BITS, buf, 97baefd977SVladimir Sementsov-Ogievskiy s->cluster_size); 98baefd977SVladimir Sementsov-Ogievskiy if (ret < 0) { 99baefd977SVladimir Sementsov-Ogievskiy error_setg_errno(errp, -ret, 100baefd977SVladimir Sementsov-Ogievskiy "Failed to read bitmap data cluster"); 101baefd977SVladimir Sementsov-Ogievskiy goto finish; 102baefd977SVladimir Sementsov-Ogievskiy } 103baefd977SVladimir Sementsov-Ogievskiy bdrv_dirty_bitmap_deserialize_part(bitmap, buf, offset, count, 104baefd977SVladimir Sementsov-Ogievskiy false); 105baefd977SVladimir Sementsov-Ogievskiy } 106baefd977SVladimir Sementsov-Ogievskiy } 107baefd977SVladimir Sementsov-Ogievskiy ret = 0; 108baefd977SVladimir Sementsov-Ogievskiy 109baefd977SVladimir Sementsov-Ogievskiy bdrv_dirty_bitmap_deserialize_finish(bitmap); 110baefd977SVladimir Sementsov-Ogievskiy 111baefd977SVladimir Sementsov-Ogievskiy finish: 112baefd977SVladimir Sementsov-Ogievskiy qemu_vfree(buf); 113baefd977SVladimir Sementsov-Ogievskiy 114baefd977SVladimir Sementsov-Ogievskiy return ret; 115baefd977SVladimir Sementsov-Ogievskiy } 116baefd977SVladimir Sementsov-Ogievskiy 117baefd977SVladimir Sementsov-Ogievskiy /* 118baefd977SVladimir Sementsov-Ogievskiy * @data buffer (of @data_size size) is the Dirty bitmaps feature which 119baefd977SVladimir Sementsov-Ogievskiy * consists of ParallelsDirtyBitmapFeature followed by L1 table. 120baefd977SVladimir Sementsov-Ogievskiy */ 121baefd977SVladimir Sementsov-Ogievskiy static BdrvDirtyBitmap *parallels_load_bitmap(BlockDriverState *bs, 122baefd977SVladimir Sementsov-Ogievskiy uint8_t *data, 123baefd977SVladimir Sementsov-Ogievskiy size_t data_size, 124baefd977SVladimir Sementsov-Ogievskiy Error **errp) 125baefd977SVladimir Sementsov-Ogievskiy { 126baefd977SVladimir Sementsov-Ogievskiy int ret; 127baefd977SVladimir Sementsov-Ogievskiy ParallelsDirtyBitmapFeature bf; 128baefd977SVladimir Sementsov-Ogievskiy g_autofree uint64_t *l1_table = NULL; 129baefd977SVladimir Sementsov-Ogievskiy BdrvDirtyBitmap *bitmap; 130baefd977SVladimir Sementsov-Ogievskiy QemuUUID uuid; 131baefd977SVladimir Sementsov-Ogievskiy char uuidstr[UUID_FMT_LEN + 1]; 132baefd977SVladimir Sementsov-Ogievskiy int i; 133baefd977SVladimir Sementsov-Ogievskiy 134baefd977SVladimir Sementsov-Ogievskiy if (data_size < sizeof(bf)) { 135baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Too small Bitmap Feature area in Parallels Format " 136baefd977SVladimir Sementsov-Ogievskiy "Extension: %zu bytes, expected at least %zu bytes", 137baefd977SVladimir Sementsov-Ogievskiy data_size, sizeof(bf)); 138baefd977SVladimir Sementsov-Ogievskiy return NULL; 139baefd977SVladimir Sementsov-Ogievskiy } 140baefd977SVladimir Sementsov-Ogievskiy memcpy(&bf, data, sizeof(bf)); 141baefd977SVladimir Sementsov-Ogievskiy bf.size = le64_to_cpu(bf.size); 142baefd977SVladimir Sementsov-Ogievskiy bf.granularity = le32_to_cpu(bf.granularity) << BDRV_SECTOR_BITS; 143baefd977SVladimir Sementsov-Ogievskiy bf.l1_size = le32_to_cpu(bf.l1_size); 144baefd977SVladimir Sementsov-Ogievskiy data += sizeof(bf); 145baefd977SVladimir Sementsov-Ogievskiy data_size -= sizeof(bf); 146baefd977SVladimir Sementsov-Ogievskiy 147baefd977SVladimir Sementsov-Ogievskiy if (bf.size != bs->total_sectors) { 148baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Bitmap size (in sectors) %" PRId64 " differs from " 149baefd977SVladimir Sementsov-Ogievskiy "disk size in sectors %" PRId64, bf.size, bs->total_sectors); 150baefd977SVladimir Sementsov-Ogievskiy return NULL; 151baefd977SVladimir Sementsov-Ogievskiy } 152baefd977SVladimir Sementsov-Ogievskiy 153baefd977SVladimir Sementsov-Ogievskiy if (bf.l1_size * sizeof(uint64_t) > data_size) { 154baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Bitmaps feature corrupted: l1 table exceeds " 155baefd977SVladimir Sementsov-Ogievskiy "extension data_size"); 156baefd977SVladimir Sementsov-Ogievskiy return NULL; 157baefd977SVladimir Sementsov-Ogievskiy } 158baefd977SVladimir Sementsov-Ogievskiy 159baefd977SVladimir Sementsov-Ogievskiy memcpy(&uuid, bf.id, sizeof(uuid)); 160baefd977SVladimir Sementsov-Ogievskiy qemu_uuid_unparse(&uuid, uuidstr); 161baefd977SVladimir Sementsov-Ogievskiy bitmap = bdrv_create_dirty_bitmap(bs, bf.granularity, uuidstr, errp); 162baefd977SVladimir Sementsov-Ogievskiy if (!bitmap) { 163baefd977SVladimir Sementsov-Ogievskiy return NULL; 164baefd977SVladimir Sementsov-Ogievskiy } 165baefd977SVladimir Sementsov-Ogievskiy 166baefd977SVladimir Sementsov-Ogievskiy l1_table = g_new(uint64_t, bf.l1_size); 167baefd977SVladimir Sementsov-Ogievskiy for (i = 0; i < bf.l1_size; i++, data += sizeof(uint64_t)) { 168baefd977SVladimir Sementsov-Ogievskiy l1_table[i] = ldq_le_p(data); 169baefd977SVladimir Sementsov-Ogievskiy } 170baefd977SVladimir Sementsov-Ogievskiy 171baefd977SVladimir Sementsov-Ogievskiy ret = parallels_load_bitmap_data(bs, l1_table, bf.l1_size, bitmap, errp); 172baefd977SVladimir Sementsov-Ogievskiy if (ret < 0) { 173baefd977SVladimir Sementsov-Ogievskiy bdrv_release_dirty_bitmap(bitmap); 174baefd977SVladimir Sementsov-Ogievskiy return NULL; 175baefd977SVladimir Sementsov-Ogievskiy } 176baefd977SVladimir Sementsov-Ogievskiy 177baefd977SVladimir Sementsov-Ogievskiy /* We support format extension only for RO parallels images. */ 178baefd977SVladimir Sementsov-Ogievskiy assert(!(bs->open_flags & BDRV_O_RDWR)); 179baefd977SVladimir Sementsov-Ogievskiy bdrv_dirty_bitmap_set_readonly(bitmap, true); 180baefd977SVladimir Sementsov-Ogievskiy 181baefd977SVladimir Sementsov-Ogievskiy return bitmap; 182baefd977SVladimir Sementsov-Ogievskiy } 183baefd977SVladimir Sementsov-Ogievskiy 184baefd977SVladimir Sementsov-Ogievskiy static int parallels_parse_format_extension(BlockDriverState *bs, 185baefd977SVladimir Sementsov-Ogievskiy uint8_t *ext_cluster, Error **errp) 186baefd977SVladimir Sementsov-Ogievskiy { 187baefd977SVladimir Sementsov-Ogievskiy BDRVParallelsState *s = bs->opaque; 188baefd977SVladimir Sementsov-Ogievskiy int ret; 189baefd977SVladimir Sementsov-Ogievskiy int remaining = s->cluster_size; 190baefd977SVladimir Sementsov-Ogievskiy uint8_t *pos = ext_cluster; 191baefd977SVladimir Sementsov-Ogievskiy ParallelsFormatExtensionHeader eh; 192baefd977SVladimir Sementsov-Ogievskiy g_autofree uint8_t *hash = NULL; 193baefd977SVladimir Sementsov-Ogievskiy size_t hash_len = 0; 194baefd977SVladimir Sementsov-Ogievskiy GSList *bitmaps = NULL, *el; 195baefd977SVladimir Sementsov-Ogievskiy 196baefd977SVladimir Sementsov-Ogievskiy memcpy(&eh, pos, sizeof(eh)); 197baefd977SVladimir Sementsov-Ogievskiy eh.magic = le64_to_cpu(eh.magic); 198baefd977SVladimir Sementsov-Ogievskiy pos += sizeof(eh); 199baefd977SVladimir Sementsov-Ogievskiy remaining -= sizeof(eh); 200baefd977SVladimir Sementsov-Ogievskiy 201baefd977SVladimir Sementsov-Ogievskiy if (eh.magic != PARALLELS_FORMAT_EXTENSION_MAGIC) { 202baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Wrong parallels Format Extension magic: 0x%" PRIx64 203baefd977SVladimir Sementsov-Ogievskiy ", expected: 0x%llx", eh.magic, 204baefd977SVladimir Sementsov-Ogievskiy PARALLELS_FORMAT_EXTENSION_MAGIC); 205baefd977SVladimir Sementsov-Ogievskiy goto fail; 206baefd977SVladimir Sementsov-Ogievskiy } 207baefd977SVladimir Sementsov-Ogievskiy 208baefd977SVladimir Sementsov-Ogievskiy ret = qcrypto_hash_bytes(QCRYPTO_HASH_ALG_MD5, (char *)pos, remaining, 209baefd977SVladimir Sementsov-Ogievskiy &hash, &hash_len, errp); 210baefd977SVladimir Sementsov-Ogievskiy if (ret < 0) { 211baefd977SVladimir Sementsov-Ogievskiy goto fail; 212baefd977SVladimir Sementsov-Ogievskiy } 213baefd977SVladimir Sementsov-Ogievskiy 214baefd977SVladimir Sementsov-Ogievskiy if (hash_len != sizeof(eh.check_sum) || 215baefd977SVladimir Sementsov-Ogievskiy memcmp(hash, eh.check_sum, sizeof(eh.check_sum)) != 0) { 216baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Wrong checksum in Format Extension header. Format " 217baefd977SVladimir Sementsov-Ogievskiy "extension is corrupted."); 218baefd977SVladimir Sementsov-Ogievskiy goto fail; 219baefd977SVladimir Sementsov-Ogievskiy } 220baefd977SVladimir Sementsov-Ogievskiy 221baefd977SVladimir Sementsov-Ogievskiy while (true) { 222baefd977SVladimir Sementsov-Ogievskiy ParallelsFeatureHeader fh; 223baefd977SVladimir Sementsov-Ogievskiy BdrvDirtyBitmap *bitmap; 224baefd977SVladimir Sementsov-Ogievskiy 225baefd977SVladimir Sementsov-Ogievskiy if (remaining < sizeof(fh)) { 226baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Can not read feature header, as remaining bytes " 227baefd977SVladimir Sementsov-Ogievskiy "(%d) in Format Extension is less than Feature header " 228baefd977SVladimir Sementsov-Ogievskiy "size (%zu)", remaining, sizeof(fh)); 229baefd977SVladimir Sementsov-Ogievskiy goto fail; 230baefd977SVladimir Sementsov-Ogievskiy } 231baefd977SVladimir Sementsov-Ogievskiy 232baefd977SVladimir Sementsov-Ogievskiy memcpy(&fh, pos, sizeof(fh)); 233baefd977SVladimir Sementsov-Ogievskiy pos += sizeof(fh); 234baefd977SVladimir Sementsov-Ogievskiy remaining -= sizeof(fh); 235baefd977SVladimir Sementsov-Ogievskiy 236baefd977SVladimir Sementsov-Ogievskiy fh.magic = le64_to_cpu(fh.magic); 237baefd977SVladimir Sementsov-Ogievskiy fh.flags = le64_to_cpu(fh.flags); 238baefd977SVladimir Sementsov-Ogievskiy fh.data_size = le32_to_cpu(fh.data_size); 239baefd977SVladimir Sementsov-Ogievskiy 240baefd977SVladimir Sementsov-Ogievskiy if (fh.flags) { 241baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Flags for extension feature are unsupported"); 242baefd977SVladimir Sementsov-Ogievskiy goto fail; 243baefd977SVladimir Sementsov-Ogievskiy } 244baefd977SVladimir Sementsov-Ogievskiy 245baefd977SVladimir Sementsov-Ogievskiy if (fh.data_size > remaining) { 246baefd977SVladimir Sementsov-Ogievskiy error_setg(errp, "Feature data_size exceedes Format Extension " 247baefd977SVladimir Sementsov-Ogievskiy "cluster"); 248baefd977SVladimir Sementsov-Ogievskiy goto fail; 249baefd977SVladimir Sementsov-Ogievskiy } 250baefd977SVladimir Sementsov-Ogievskiy 251baefd977SVladimir Sementsov-Ogievskiy switch (fh.magic) { 252baefd977SVladimir Sementsov-Ogievskiy case PARALLELS_END_OF_FEATURES_MAGIC: 253baefd977SVladimir Sementsov-Ogievskiy return 0; 254baefd977SVladimir Sementsov-Ogievskiy 255baefd977SVladimir Sementsov-Ogievskiy case PARALLELS_DIRTY_BITMAP_FEATURE_MAGIC: 256baefd977SVladimir Sementsov-Ogievskiy bitmap = parallels_load_bitmap(bs, pos, fh.data_size, errp); 257baefd977SVladimir Sementsov-Ogievskiy if (!bitmap) { 258baefd977SVladimir Sementsov-Ogievskiy goto fail; 259baefd977SVladimir Sementsov-Ogievskiy } 260baefd977SVladimir Sementsov-Ogievskiy bitmaps = g_slist_append(bitmaps, bitmap); 261baefd977SVladimir Sementsov-Ogievskiy break; 262baefd977SVladimir Sementsov-Ogievskiy 263baefd977SVladimir Sementsov-Ogievskiy default: 264*3f1db959SPhilippe Mathieu-Daudé error_setg(errp, "Unknown feature: 0x%" PRIx64, fh.magic); 265baefd977SVladimir Sementsov-Ogievskiy goto fail; 266baefd977SVladimir Sementsov-Ogievskiy } 267baefd977SVladimir Sementsov-Ogievskiy 268baefd977SVladimir Sementsov-Ogievskiy pos = ext_cluster + QEMU_ALIGN_UP(pos + fh.data_size - ext_cluster, 8); 269baefd977SVladimir Sementsov-Ogievskiy } 270baefd977SVladimir Sementsov-Ogievskiy 271baefd977SVladimir Sementsov-Ogievskiy fail: 272baefd977SVladimir Sementsov-Ogievskiy for (el = bitmaps; el; el = el->next) { 273baefd977SVladimir Sementsov-Ogievskiy bdrv_release_dirty_bitmap(el->data); 274baefd977SVladimir Sementsov-Ogievskiy } 275baefd977SVladimir Sementsov-Ogievskiy g_slist_free(bitmaps); 276baefd977SVladimir Sementsov-Ogievskiy 277baefd977SVladimir Sementsov-Ogievskiy return -EINVAL; 278baefd977SVladimir Sementsov-Ogievskiy } 279baefd977SVladimir Sementsov-Ogievskiy 280baefd977SVladimir Sementsov-Ogievskiy int parallels_read_format_extension(BlockDriverState *bs, 281baefd977SVladimir Sementsov-Ogievskiy int64_t ext_off, Error **errp) 282baefd977SVladimir Sementsov-Ogievskiy { 283baefd977SVladimir Sementsov-Ogievskiy BDRVParallelsState *s = bs->opaque; 284baefd977SVladimir Sementsov-Ogievskiy int ret; 285baefd977SVladimir Sementsov-Ogievskiy uint8_t *ext_cluster = qemu_blockalign(bs, s->cluster_size); 286baefd977SVladimir Sementsov-Ogievskiy 287baefd977SVladimir Sementsov-Ogievskiy assert(ext_off > 0); 288baefd977SVladimir Sementsov-Ogievskiy 289baefd977SVladimir Sementsov-Ogievskiy ret = bdrv_pread(bs->file, ext_off, ext_cluster, s->cluster_size); 290baefd977SVladimir Sementsov-Ogievskiy if (ret < 0) { 291baefd977SVladimir Sementsov-Ogievskiy error_setg_errno(errp, -ret, "Failed to read Format Extension cluster"); 292baefd977SVladimir Sementsov-Ogievskiy goto out; 293baefd977SVladimir Sementsov-Ogievskiy } 294baefd977SVladimir Sementsov-Ogievskiy 295baefd977SVladimir Sementsov-Ogievskiy ret = parallels_parse_format_extension(bs, ext_cluster, errp); 296baefd977SVladimir Sementsov-Ogievskiy 297baefd977SVladimir Sementsov-Ogievskiy out: 298baefd977SVladimir Sementsov-Ogievskiy qemu_vfree(ext_cluster); 299baefd977SVladimir Sementsov-Ogievskiy 300baefd977SVladimir Sementsov-Ogievskiy return ret; 301baefd977SVladimir Sementsov-Ogievskiy } 302