blob: 423b2ad7271a7f48e841d9efcc7bda56995ff67d [file] [log] [blame]
Klim Kireev90fe66f2018-01-12 12:01:20 +03001/*
2* Block driver for Parallels disk image format
3*
4* Copyright (c) 2015-2017 Virtuozzo, Inc.
5* Authors:
6* 2016-2017 Klim S. Kireev <klim.kireev@virtuozzo.com>
7* 2015 Denis V. Lunev <den@openvz.org>
8*
9* This code was originally based on comparing different disk images created
10* by Parallels. Currently it is based on opened OpenVZ sources
11* available at
12* https://github.com/OpenVZ/ploop
13*
14* Permission is hereby granted, free of charge, to any person obtaining a copy
15* of this software and associated documentation files (the "Software"), to deal
16* in the Software without restriction, including without limitation the rights
17* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18* copies of the Software, and to permit persons to whom the Software is
19* furnished to do so, subject to the following conditions:
20*
21* The above copyright notice and this permission notice shall be included in
22* all copies or substantial portions of the Software.
23*
24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30* THE SOFTWARE.
31*/
32#ifndef BLOCK_PARALLELS_H
33#define BLOCK_PARALLELS_H
34#include "qemu/coroutine.h"
Klim Kireev90fe66f2018-01-12 12:01:20 +030035
Klim Kireev908b1c82018-01-12 12:01:21 +030036#define HEADS_NUMBER 16
37#define SEC_IN_CYL 32
Klim Kireev90fe66f2018-01-12 12:01:20 +030038#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */
39
40/* always little-endian */
41typedef struct ParallelsHeader {
42 char magic[16]; /* "WithoutFreeSpace" */
43 uint32_t version;
44 uint32_t heads;
45 uint32_t cylinders;
46 uint32_t tracks;
47 uint32_t bat_entries;
48 uint64_t nb_sectors;
49 uint32_t inuse;
50 uint32_t data_off;
Vladimir Sementsov-Ogievskiybaefd972021-02-24 13:47:05 +030051 uint32_t flags;
52 uint64_t ext_off;
Klim Kireev90fe66f2018-01-12 12:01:20 +030053} QEMU_PACKED ParallelsHeader;
54
55typedef enum ParallelsPreallocMode {
56 PRL_PREALLOC_MODE_FALLOCATE = 0,
57 PRL_PREALLOC_MODE_TRUNCATE = 1,
58 PRL_PREALLOC_MODE__MAX = 2,
59} ParallelsPreallocMode;
60
61typedef struct BDRVParallelsState {
62 /** Locking is conservative, the lock protects
63 * - image file extending (truncate, fallocate)
64 * - any access to block allocation table
65 */
66 CoMutex lock;
67
68 ParallelsHeader *header;
69 uint32_t header_size;
70 bool header_unclean;
71
72 unsigned long *bat_dirty_bmap;
73 unsigned int bat_dirty_block;
74
Denis V. Luneve1851002023-09-18 20:00:50 +020075 unsigned long *used_bmap;
76 unsigned long used_bmap_size;
77
Klim Kireev90fe66f2018-01-12 12:01:20 +030078 uint32_t *bat_bitmap;
79 unsigned int bat_size;
80
Alexander Ivanovc0b15452023-07-18 12:44:27 +020081 int64_t data_start;
Klim Kireev90fe66f2018-01-12 12:01:20 +030082 int64_t data_end;
83 uint64_t prealloc_size;
84 ParallelsPreallocMode prealloc_mode;
85
86 unsigned int tracks;
Vladimir Sementsov-Ogievskiye0b52072021-02-24 13:47:04 +030087 unsigned int cluster_size;
Klim Kireev90fe66f2018-01-12 12:01:20 +030088
89 unsigned int off_multiplier;
90 Error *migration_blocker;
91} BDRVParallelsState;
92
Kevin Wolf1f051dc2023-10-27 17:53:33 +020093int GRAPH_RDLOCK
94parallels_read_format_extension(BlockDriverState *bs, int64_t ext_off,
95 Error **errp);
Vladimir Sementsov-Ogievskiybaefd972021-02-24 13:47:05 +030096
Klim Kireev90fe66f2018-01-12 12:01:20 +030097#endif