190fe66f0SKlim Kireev /* 290fe66f0SKlim Kireev * Block driver for Parallels disk image format 390fe66f0SKlim Kireev * 490fe66f0SKlim Kireev * Copyright (c) 2015-2017 Virtuozzo, Inc. 590fe66f0SKlim Kireev * Authors: 690fe66f0SKlim Kireev * 2016-2017 Klim S. Kireev <klim.kireev@virtuozzo.com> 790fe66f0SKlim Kireev * 2015 Denis V. Lunev <den@openvz.org> 890fe66f0SKlim Kireev * 990fe66f0SKlim Kireev * This code was originally based on comparing different disk images created 1090fe66f0SKlim Kireev * by Parallels. Currently it is based on opened OpenVZ sources 1190fe66f0SKlim Kireev * available at 1290fe66f0SKlim Kireev * https://github.com/OpenVZ/ploop 1390fe66f0SKlim Kireev * 1490fe66f0SKlim Kireev * Permission is hereby granted, free of charge, to any person obtaining a copy 1590fe66f0SKlim Kireev * of this software and associated documentation files (the "Software"), to deal 1690fe66f0SKlim Kireev * in the Software without restriction, including without limitation the rights 1790fe66f0SKlim Kireev * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1890fe66f0SKlim Kireev * copies of the Software, and to permit persons to whom the Software is 1990fe66f0SKlim Kireev * furnished to do so, subject to the following conditions: 2090fe66f0SKlim Kireev * 2190fe66f0SKlim Kireev * The above copyright notice and this permission notice shall be included in 2290fe66f0SKlim Kireev * all copies or substantial portions of the Software. 2390fe66f0SKlim Kireev * 2490fe66f0SKlim Kireev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2590fe66f0SKlim Kireev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2690fe66f0SKlim Kireev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2790fe66f0SKlim Kireev * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2890fe66f0SKlim Kireev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2990fe66f0SKlim Kireev * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 3090fe66f0SKlim Kireev * THE SOFTWARE. 3190fe66f0SKlim Kireev */ 3290fe66f0SKlim Kireev #ifndef BLOCK_PARALLELS_H 3390fe66f0SKlim Kireev #define BLOCK_PARALLELS_H 3490fe66f0SKlim Kireev #include "qemu/coroutine.h" 3590fe66f0SKlim Kireev 36908b1c84SKlim Kireev #define HEADS_NUMBER 16 37908b1c84SKlim Kireev #define SEC_IN_CYL 32 3890fe66f0SKlim Kireev #define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ 3990fe66f0SKlim Kireev 4090fe66f0SKlim Kireev /* always little-endian */ 4190fe66f0SKlim Kireev typedef struct ParallelsHeader { 4290fe66f0SKlim Kireev char magic[16]; /* "WithoutFreeSpace" */ 4390fe66f0SKlim Kireev uint32_t version; 4490fe66f0SKlim Kireev uint32_t heads; 4590fe66f0SKlim Kireev uint32_t cylinders; 4690fe66f0SKlim Kireev uint32_t tracks; 4790fe66f0SKlim Kireev uint32_t bat_entries; 4890fe66f0SKlim Kireev uint64_t nb_sectors; 4990fe66f0SKlim Kireev uint32_t inuse; 5090fe66f0SKlim Kireev uint32_t data_off; 51baefd977SVladimir Sementsov-Ogievskiy uint32_t flags; 52baefd977SVladimir Sementsov-Ogievskiy uint64_t ext_off; 5390fe66f0SKlim Kireev } QEMU_PACKED ParallelsHeader; 5490fe66f0SKlim Kireev 5590fe66f0SKlim Kireev typedef enum ParallelsPreallocMode { 5690fe66f0SKlim Kireev PRL_PREALLOC_MODE_FALLOCATE = 0, 5790fe66f0SKlim Kireev PRL_PREALLOC_MODE_TRUNCATE = 1, 5890fe66f0SKlim Kireev PRL_PREALLOC_MODE__MAX = 2, 5990fe66f0SKlim Kireev } ParallelsPreallocMode; 6090fe66f0SKlim Kireev 6190fe66f0SKlim Kireev typedef struct BDRVParallelsState { 6290fe66f0SKlim Kireev /** Locking is conservative, the lock protects 6390fe66f0SKlim Kireev * - image file extending (truncate, fallocate) 6490fe66f0SKlim Kireev * - any access to block allocation table 6590fe66f0SKlim Kireev */ 6690fe66f0SKlim Kireev CoMutex lock; 6790fe66f0SKlim Kireev 6890fe66f0SKlim Kireev ParallelsHeader *header; 6990fe66f0SKlim Kireev uint32_t header_size; 7090fe66f0SKlim Kireev bool header_unclean; 7190fe66f0SKlim Kireev 7290fe66f0SKlim Kireev unsigned long *bat_dirty_bmap; 7390fe66f0SKlim Kireev unsigned int bat_dirty_block; 7490fe66f0SKlim Kireev 75e185100fSDenis V. Lunev unsigned long *used_bmap; 76e185100fSDenis V. Lunev unsigned long used_bmap_size; 77e185100fSDenis V. Lunev 7890fe66f0SKlim Kireev uint32_t *bat_bitmap; 7990fe66f0SKlim Kireev unsigned int bat_size; 8090fe66f0SKlim Kireev 81c0b15453SAlexander Ivanov int64_t data_start; 8290fe66f0SKlim Kireev int64_t data_end; 8390fe66f0SKlim Kireev uint64_t prealloc_size; 8490fe66f0SKlim Kireev ParallelsPreallocMode prealloc_mode; 8590fe66f0SKlim Kireev 8690fe66f0SKlim Kireev unsigned int tracks; 87e0b5207fSVladimir Sementsov-Ogievskiy unsigned int cluster_size; 8890fe66f0SKlim Kireev 8990fe66f0SKlim Kireev unsigned int off_multiplier; 9090fe66f0SKlim Kireev Error *migration_blocker; 9190fe66f0SKlim Kireev } BDRVParallelsState; 9290fe66f0SKlim Kireev 931f051dcbSKevin Wolf int GRAPH_RDLOCK 941f051dcbSKevin Wolf parallels_read_format_extension(BlockDriverState *bs, int64_t ext_off, 951f051dcbSKevin Wolf Error **errp); 96baefd977SVladimir Sementsov-Ogievskiy 9790fe66f0SKlim Kireev #endif 98