Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Block driver for the QCOW version 2 format |
| 3 | * |
| 4 | * Copyright (c) 2004-2006 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef BLOCK_QCOW2_H |
| 26 | #define BLOCK_QCOW2_H |
| 27 | |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 28 | #include "crypto/block.h" |
Daniel P. Berrange | 10817bf | 2015-09-01 14:48:02 +0100 | [diff] [blame] | 29 | #include "qemu/coroutine.h" |
Leonid Bloch | b6a95c6 | 2018-09-26 19:04:41 +0300 | [diff] [blame] | 30 | #include "qemu/units.h" |
Vladimir Sementsov-Ogievskiy | 9353db4 | 2019-05-06 17:27:34 +0300 | [diff] [blame] | 31 | #include "block/block_int.h" |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 32 | |
Filip Navara | 14899cd | 2009-06-23 19:17:30 -0500 | [diff] [blame] | 33 | //#define DEBUG_ALLOC |
| 34 | //#define DEBUG_ALLOC2 |
| 35 | //#define DEBUG_EXT |
| 36 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 37 | #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 38 | |
| 39 | #define QCOW_CRYPT_NONE 0 |
| 40 | #define QCOW_CRYPT_AES 1 |
Daniel P. Berrange | 4652b8f | 2017-06-23 17:24:12 +0100 | [diff] [blame] | 41 | #define QCOW_CRYPT_LUKS 2 |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 42 | |
| 43 | #define QCOW_MAX_CRYPT_CLUSTERS 32 |
Kevin Wolf | ce48f2f4 | 2014-03-26 13:05:45 +0100 | [diff] [blame] | 44 | #define QCOW_MAX_SNAPSHOTS 65536 |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 45 | |
Eric Blake | 77d6a21 | 2018-11-13 17:03:18 -0600 | [diff] [blame] | 46 | /* Field widths in qcow2 mean normal cluster offsets cannot reach |
| 47 | * 64PB; depending on cluster size, compressed clusters can have a |
| 48 | * smaller limit (64PB for up to 16k clusters, then ramps down to |
| 49 | * 512TB for 2M clusters). */ |
| 50 | #define QCOW_MAX_CLUSTER_OFFSET ((1ULL << 56) - 1) |
| 51 | |
Kevin Wolf | 2b5d595 | 2014-03-26 13:05:50 +0100 | [diff] [blame] | 52 | /* 8 MB refcount table is enough for 2 PB images at 64k cluster size |
| 53 | * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */ |
Markus Armbruster | 1463212 | 2019-01-11 20:14:01 +0100 | [diff] [blame] | 54 | #define QCOW_MAX_REFTABLE_SIZE (8 * MiB) |
Kevin Wolf | 2b5d595 | 2014-03-26 13:05:50 +0100 | [diff] [blame] | 55 | |
Kevin Wolf | 6a83f8b | 2014-03-26 13:06:06 +0100 | [diff] [blame] | 56 | /* 32 MB L1 table is enough for 2 PB images at 64k cluster size |
| 57 | * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */ |
Markus Armbruster | 1463212 | 2019-01-11 20:14:01 +0100 | [diff] [blame] | 58 | #define QCOW_MAX_L1_SIZE (32 * MiB) |
Kevin Wolf | 6a83f8b | 2014-03-26 13:06:06 +0100 | [diff] [blame] | 59 | |
Kevin Wolf | 5dae6e3 | 2014-03-26 13:06:07 +0100 | [diff] [blame] | 60 | /* Allow for an average of 1k per snapshot table entry, should be plenty of |
| 61 | * space for snapshot names and IDs */ |
| 62 | #define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS) |
| 63 | |
Max Reitz | fcf9a6b | 2019-10-11 17:28:02 +0200 | [diff] [blame] | 64 | /* Maximum amount of extra data per snapshot table entry to accept */ |
| 65 | #define QCOW_MAX_SNAPSHOT_EXTRA_DATA 1024 |
| 66 | |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 67 | /* Bitmap header extension constraints */ |
| 68 | #define QCOW2_MAX_BITMAPS 65535 |
| 69 | #define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS) |
| 70 | |
Vladimir Sementsov-Ogievskiy | d710cf5 | 2019-09-16 20:53:24 +0300 | [diff] [blame] | 71 | /* Maximum of parallel sub-request per guest request */ |
| 72 | #define QCOW2_MAX_WORKERS 8 |
| 73 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 74 | /* indicate that the refcount of the referenced cluster is exactly one. */ |
Peter Maydell | 127c84e | 2013-08-23 17:35:45 +0100 | [diff] [blame] | 75 | #define QCOW_OFLAG_COPIED (1ULL << 63) |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 76 | /* indicate that the cluster is compressed (they never have the copied flag) */ |
Peter Maydell | 127c84e | 2013-08-23 17:35:45 +0100 | [diff] [blame] | 77 | #define QCOW_OFLAG_COMPRESSED (1ULL << 62) |
Kevin Wolf | 6377af4 | 2012-03-16 15:02:38 +0100 | [diff] [blame] | 78 | /* The cluster reads as all zeros */ |
Peter Maydell | 127c84e | 2013-08-23 17:35:45 +0100 | [diff] [blame] | 79 | #define QCOW_OFLAG_ZERO (1ULL << 0) |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 80 | |
Alberto Garcia | d0346b5 | 2020-07-10 18:12:51 +0200 | [diff] [blame] | 81 | #define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32 |
| 82 | |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 83 | /* The subcluster X [0..31] is allocated */ |
| 84 | #define QCOW_OFLAG_SUB_ALLOC(X) (1ULL << (X)) |
| 85 | /* The subcluster X [0..31] reads as zeroes */ |
| 86 | #define QCOW_OFLAG_SUB_ZERO(X) (QCOW_OFLAG_SUB_ALLOC(X) << 32) |
| 87 | /* Subclusters [X, Y) (0 <= X <= Y <= 32) are allocated */ |
| 88 | #define QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) \ |
| 89 | (QCOW_OFLAG_SUB_ALLOC(Y) - QCOW_OFLAG_SUB_ALLOC(X)) |
| 90 | /* Subclusters [X, Y) (0 <= X <= Y <= 32) read as zeroes */ |
| 91 | #define QCOW_OFLAG_SUB_ZERO_RANGE(X, Y) \ |
| 92 | (QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) << 32) |
| 93 | /* L2 entry bitmap with all allocation bits set */ |
| 94 | #define QCOW_L2_BITMAP_ALL_ALLOC (QCOW_OFLAG_SUB_ALLOC_RANGE(0, 32)) |
| 95 | /* L2 entry bitmap with all "read as zeroes" bits set */ |
| 96 | #define QCOW_L2_BITMAP_ALL_ZEROES (QCOW_OFLAG_SUB_ZERO_RANGE(0, 32)) |
| 97 | |
Alberto Garcia | c8fd855 | 2020-07-10 18:12:54 +0200 | [diff] [blame] | 98 | /* Size of normal and extended L2 entries */ |
| 99 | #define L2E_SIZE_NORMAL (sizeof(uint64_t)) |
| 100 | #define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2) |
| 101 | |
Alberto Garcia | 02b1ecf | 2020-08-28 13:08:28 +0200 | [diff] [blame] | 102 | /* Size of L1 table entries */ |
| 103 | #define L1E_SIZE (sizeof(uint64_t)) |
| 104 | |
| 105 | /* Size of reftable entries */ |
| 106 | #define REFTABLE_ENTRY_SIZE (sizeof(uint64_t)) |
| 107 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 108 | #define MIN_CLUSTER_BITS 9 |
Kevin Wolf | 80ee15a | 2009-09-15 12:30:43 +0200 | [diff] [blame] | 109 | #define MAX_CLUSTER_BITS 21 |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 110 | |
Alberto Garcia | b6c2469 | 2019-05-10 19:22:54 +0300 | [diff] [blame] | 111 | /* Defined in the qcow2 spec (compressed cluster descriptor) */ |
| 112 | #define QCOW2_COMPRESSED_SECTOR_SIZE 512U |
Alberto Garcia | b6c2469 | 2019-05-10 19:22:54 +0300 | [diff] [blame] | 113 | |
Max Reitz | 57e2166 | 2015-06-01 18:09:17 +0200 | [diff] [blame] | 114 | /* Must be at least 2 to cover COW */ |
Alberto Garcia | 1221fe6 | 2018-02-05 16:33:36 +0200 | [diff] [blame] | 115 | #define MIN_L2_CACHE_SIZE 2 /* cache entries */ |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 116 | |
Kevin Wolf | 29c1a73 | 2011-01-10 17:17:28 +0100 | [diff] [blame] | 117 | /* Must be at least 4 to cover all cases of refcount table growth */ |
Max Reitz | 440ba08 | 2014-08-18 22:07:31 +0200 | [diff] [blame] | 118 | #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */ |
| 119 | |
Leonid Bloch | 80668d0 | 2018-09-26 19:04:44 +0300 | [diff] [blame] | 120 | #ifdef CONFIG_LINUX |
Markus Armbruster | 1463212 | 2019-01-11 20:14:01 +0100 | [diff] [blame] | 121 | #define DEFAULT_L2_CACHE_MAX_SIZE (32 * MiB) |
Leonid Bloch | e957b50 | 2018-09-26 19:04:46 +0300 | [diff] [blame] | 122 | #define DEFAULT_CACHE_CLEAN_INTERVAL 600 /* seconds */ |
Leonid Bloch | 80668d0 | 2018-09-26 19:04:44 +0300 | [diff] [blame] | 123 | #else |
Markus Armbruster | 1463212 | 2019-01-11 20:14:01 +0100 | [diff] [blame] | 124 | #define DEFAULT_L2_CACHE_MAX_SIZE (8 * MiB) |
Leonid Bloch | e957b50 | 2018-09-26 19:04:46 +0300 | [diff] [blame] | 125 | /* Cache clean interval is currently available only on Linux, so must be 0 */ |
| 126 | #define DEFAULT_CACHE_CLEAN_INTERVAL 0 |
Leonid Bloch | 80668d0 | 2018-09-26 19:04:44 +0300 | [diff] [blame] | 127 | #endif |
Max Reitz | 440ba08 | 2014-08-18 22:07:31 +0200 | [diff] [blame] | 128 | |
Markus Armbruster | 1463212 | 2019-01-11 20:14:01 +0100 | [diff] [blame] | 129 | #define DEFAULT_CLUSTER_SIZE 65536 |
Kevin Wolf | 99cce9f | 2011-05-31 15:01:46 +0200 | [diff] [blame] | 130 | |
Kevin Wolf | 0e8c08b | 2019-01-29 17:13:57 +0100 | [diff] [blame] | 131 | #define QCOW2_OPT_DATA_FILE "data-file" |
Kevin Wolf | 64aa99d | 2013-07-17 14:45:34 +0200 | [diff] [blame] | 132 | #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts" |
| 133 | #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request" |
| 134 | #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot" |
| 135 | #define QCOW2_OPT_DISCARD_OTHER "pass-discard-other" |
Max Reitz | 05de7e8 | 2013-10-10 11:09:25 +0200 | [diff] [blame] | 136 | #define QCOW2_OPT_OVERLAP "overlap-check" |
Max Reitz | ee42b5c | 2014-08-20 19:59:35 +0200 | [diff] [blame] | 137 | #define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template" |
Max Reitz | 05de7e8 | 2013-10-10 11:09:25 +0200 | [diff] [blame] | 138 | #define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header" |
| 139 | #define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1" |
| 140 | #define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2" |
| 141 | #define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table" |
| 142 | #define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block" |
| 143 | #define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table" |
| 144 | #define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1" |
| 145 | #define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2" |
Vladimir Sementsov-Ogievskiy | 0e4e431 | 2018-07-05 18:15:15 +0300 | [diff] [blame] | 146 | #define QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY "overlap-check.bitmap-directory" |
Max Reitz | 6c1c8d5 | 2014-08-18 22:07:33 +0200 | [diff] [blame] | 147 | #define QCOW2_OPT_CACHE_SIZE "cache-size" |
| 148 | #define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size" |
Alberto Garcia | 1221fe6 | 2018-02-05 16:33:36 +0200 | [diff] [blame] | 149 | #define QCOW2_OPT_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size" |
Max Reitz | 6c1c8d5 | 2014-08-18 22:07:33 +0200 | [diff] [blame] | 150 | #define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size" |
Alberto Garcia | 279621c | 2015-08-04 15:14:40 +0300 | [diff] [blame] | 151 | #define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval" |
Kevin Wolf | acdfb48 | 2013-03-18 13:08:10 +0100 | [diff] [blame] | 152 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 153 | typedef struct QCowHeader { |
| 154 | uint32_t magic; |
| 155 | uint32_t version; |
| 156 | uint64_t backing_file_offset; |
| 157 | uint32_t backing_file_size; |
| 158 | uint32_t cluster_bits; |
| 159 | uint64_t size; /* in bytes */ |
| 160 | uint32_t crypt_method; |
| 161 | uint32_t l1_size; /* XXX: save number of clusters instead ? */ |
| 162 | uint64_t l1_table_offset; |
| 163 | uint64_t refcount_table_offset; |
| 164 | uint32_t refcount_table_clusters; |
| 165 | uint32_t nb_snapshots; |
| 166 | uint64_t snapshots_offset; |
Kevin Wolf | 6744cba | 2011-12-15 12:20:58 +0100 | [diff] [blame] | 167 | |
| 168 | /* The following fields are only valid for version >= 3 */ |
| 169 | uint64_t incompatible_features; |
| 170 | uint64_t compatible_features; |
| 171 | uint64_t autoclear_features; |
| 172 | |
| 173 | uint32_t refcount_order; |
| 174 | uint32_t header_length; |
Denis Plotnikov | 572ad97 | 2020-05-07 11:25:18 +0300 | [diff] [blame] | 175 | |
| 176 | /* Additional fields */ |
| 177 | uint8_t compression_type; |
| 178 | |
| 179 | /* header must be a multiple of 8 */ |
| 180 | uint8_t padding[7]; |
Jeff Cody | c4217f6 | 2013-09-25 12:08:50 -0400 | [diff] [blame] | 181 | } QEMU_PACKED QCowHeader; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 182 | |
Denis Plotnikov | 572ad97 | 2020-05-07 11:25:18 +0300 | [diff] [blame] | 183 | QEMU_BUILD_BUG_ON(!QEMU_IS_ALIGNED(sizeof(QCowHeader), 8)); |
| 184 | |
Kevin Wolf | ce48f2f4 | 2014-03-26 13:05:45 +0100 | [diff] [blame] | 185 | typedef struct QEMU_PACKED QCowSnapshotHeader { |
| 186 | /* header is 8 byte aligned */ |
| 187 | uint64_t l1_table_offset; |
| 188 | |
| 189 | uint32_t l1_size; |
| 190 | uint16_t id_str_size; |
| 191 | uint16_t name_size; |
| 192 | |
| 193 | uint32_t date_sec; |
| 194 | uint32_t date_nsec; |
| 195 | |
| 196 | uint64_t vm_clock_nsec; |
| 197 | |
| 198 | uint32_t vm_state_size; |
| 199 | uint32_t extra_data_size; /* for extension */ |
| 200 | /* extra data follows */ |
| 201 | /* id_str follows */ |
| 202 | /* name follows */ |
| 203 | } QCowSnapshotHeader; |
| 204 | |
| 205 | typedef struct QEMU_PACKED QCowSnapshotExtraData { |
| 206 | uint64_t vm_state_size_large; |
| 207 | uint64_t disk_size; |
Pavel Dovgalyuk | bbacffc | 2020-10-03 20:13:02 +0300 | [diff] [blame] | 208 | uint64_t icount; |
Kevin Wolf | ce48f2f4 | 2014-03-26 13:05:45 +0100 | [diff] [blame] | 209 | } QCowSnapshotExtraData; |
| 210 | |
| 211 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 212 | typedef struct QCowSnapshot { |
| 213 | uint64_t l1_table_offset; |
| 214 | uint32_t l1_size; |
| 215 | char *id_str; |
| 216 | char *name; |
Kevin Wolf | 90b2775 | 2012-04-11 16:33:50 +0200 | [diff] [blame] | 217 | uint64_t disk_size; |
Kevin Wolf | c2c9a46 | 2011-11-16 11:35:54 +0100 | [diff] [blame] | 218 | uint64_t vm_state_size; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 219 | uint32_t date_sec; |
| 220 | uint32_t date_nsec; |
| 221 | uint64_t vm_clock_nsec; |
Pavel Dovgalyuk | bbacffc | 2020-10-03 20:13:02 +0300 | [diff] [blame] | 222 | /* icount value for the moment when snapshot was taken */ |
| 223 | uint64_t icount; |
Max Reitz | fcf9a6b | 2019-10-11 17:28:02 +0200 | [diff] [blame] | 224 | /* Size of all extra data, including QCowSnapshotExtraData if available */ |
| 225 | uint32_t extra_data_size; |
| 226 | /* Data beyond QCowSnapshotExtraData, if any */ |
| 227 | void *unknown_extra_data; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 228 | } QCowSnapshot; |
| 229 | |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 230 | struct Qcow2Cache; |
| 231 | typedef struct Qcow2Cache Qcow2Cache; |
| 232 | |
Daniel P. Berrange | 4652b8f | 2017-06-23 17:24:12 +0100 | [diff] [blame] | 233 | typedef struct Qcow2CryptoHeaderExtension { |
| 234 | uint64_t offset; |
| 235 | uint64_t length; |
| 236 | } QEMU_PACKED Qcow2CryptoHeaderExtension; |
| 237 | |
Kevin Wolf | 75bab85 | 2012-02-02 14:52:08 +0100 | [diff] [blame] | 238 | typedef struct Qcow2UnknownHeaderExtension { |
| 239 | uint32_t magic; |
| 240 | uint32_t len; |
| 241 | QLIST_ENTRY(Qcow2UnknownHeaderExtension) next; |
| 242 | uint8_t data[]; |
| 243 | } Qcow2UnknownHeaderExtension; |
| 244 | |
Kevin Wolf | cfcc4c6 | 2012-04-12 15:20:27 +0200 | [diff] [blame] | 245 | enum { |
| 246 | QCOW2_FEAT_TYPE_INCOMPATIBLE = 0, |
| 247 | QCOW2_FEAT_TYPE_COMPATIBLE = 1, |
| 248 | QCOW2_FEAT_TYPE_AUTOCLEAR = 2, |
| 249 | }; |
| 250 | |
Stefan Hajnoczi | c61d000 | 2012-07-27 09:05:19 +0100 | [diff] [blame] | 251 | /* Incompatible feature bits */ |
| 252 | enum { |
Kevin Wolf | 93c2493 | 2019-01-14 16:48:25 +0100 | [diff] [blame] | 253 | QCOW2_INCOMPAT_DIRTY_BITNR = 0, |
| 254 | QCOW2_INCOMPAT_CORRUPT_BITNR = 1, |
| 255 | QCOW2_INCOMPAT_DATA_FILE_BITNR = 2, |
Denis Plotnikov | 572ad97 | 2020-05-07 11:25:18 +0300 | [diff] [blame] | 256 | QCOW2_INCOMPAT_COMPRESSION_BITNR = 3, |
Alberto Garcia | 7be2025 | 2020-07-10 18:13:13 +0200 | [diff] [blame] | 257 | QCOW2_INCOMPAT_EXTL2_BITNR = 4, |
Kevin Wolf | 93c2493 | 2019-01-14 16:48:25 +0100 | [diff] [blame] | 258 | QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR, |
| 259 | QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR, |
| 260 | QCOW2_INCOMPAT_DATA_FILE = 1 << QCOW2_INCOMPAT_DATA_FILE_BITNR, |
Denis Plotnikov | 572ad97 | 2020-05-07 11:25:18 +0300 | [diff] [blame] | 261 | QCOW2_INCOMPAT_COMPRESSION = 1 << QCOW2_INCOMPAT_COMPRESSION_BITNR, |
Alberto Garcia | 7be2025 | 2020-07-10 18:13:13 +0200 | [diff] [blame] | 262 | QCOW2_INCOMPAT_EXTL2 = 1 << QCOW2_INCOMPAT_EXTL2_BITNR, |
Stefan Hajnoczi | c61d000 | 2012-07-27 09:05:19 +0100 | [diff] [blame] | 263 | |
Kevin Wolf | 93c2493 | 2019-01-14 16:48:25 +0100 | [diff] [blame] | 264 | QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY |
Kevin Wolf | 0e8c08b | 2019-01-29 17:13:57 +0100 | [diff] [blame] | 265 | | QCOW2_INCOMPAT_CORRUPT |
Denis Plotnikov | 572ad97 | 2020-05-07 11:25:18 +0300 | [diff] [blame] | 266 | | QCOW2_INCOMPAT_DATA_FILE |
Alberto Garcia | 7be2025 | 2020-07-10 18:13:13 +0200 | [diff] [blame] | 267 | | QCOW2_INCOMPAT_COMPRESSION |
| 268 | | QCOW2_INCOMPAT_EXTL2, |
Stefan Hajnoczi | c61d000 | 2012-07-27 09:05:19 +0100 | [diff] [blame] | 269 | }; |
| 270 | |
Stefan Hajnoczi | bfe8043 | 2012-07-27 09:05:22 +0100 | [diff] [blame] | 271 | /* Compatible feature bits */ |
| 272 | enum { |
| 273 | QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0, |
| 274 | QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR, |
| 275 | |
| 276 | QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS, |
| 277 | }; |
| 278 | |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 279 | /* Autoclear feature bits */ |
| 280 | enum { |
Kevin Wolf | 93c2493 | 2019-01-14 16:48:25 +0100 | [diff] [blame] | 281 | QCOW2_AUTOCLEAR_BITMAPS_BITNR = 0, |
| 282 | QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR = 1, |
| 283 | QCOW2_AUTOCLEAR_BITMAPS = 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR, |
| 284 | QCOW2_AUTOCLEAR_DATA_FILE_RAW = 1 << QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR, |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 285 | |
Kevin Wolf | 6c3944d | 2019-02-22 14:29:38 +0100 | [diff] [blame] | 286 | QCOW2_AUTOCLEAR_MASK = QCOW2_AUTOCLEAR_BITMAPS |
| 287 | | QCOW2_AUTOCLEAR_DATA_FILE_RAW, |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 288 | }; |
| 289 | |
Kevin Wolf | 6cfcb9b | 2013-06-19 13:44:18 +0200 | [diff] [blame] | 290 | enum qcow2_discard_type { |
| 291 | QCOW2_DISCARD_NEVER = 0, |
| 292 | QCOW2_DISCARD_ALWAYS, |
| 293 | QCOW2_DISCARD_REQUEST, |
| 294 | QCOW2_DISCARD_SNAPSHOT, |
| 295 | QCOW2_DISCARD_OTHER, |
| 296 | QCOW2_DISCARD_MAX |
| 297 | }; |
| 298 | |
Kevin Wolf | cfcc4c6 | 2012-04-12 15:20:27 +0200 | [diff] [blame] | 299 | typedef struct Qcow2Feature { |
| 300 | uint8_t type; |
| 301 | uint8_t bit; |
| 302 | char name[46]; |
| 303 | } QEMU_PACKED Qcow2Feature; |
| 304 | |
Kevin Wolf | 0b919fa | 2013-06-19 13:44:20 +0200 | [diff] [blame] | 305 | typedef struct Qcow2DiscardRegion { |
| 306 | BlockDriverState *bs; |
| 307 | uint64_t offset; |
| 308 | uint64_t bytes; |
| 309 | QTAILQ_ENTRY(Qcow2DiscardRegion) next; |
| 310 | } Qcow2DiscardRegion; |
| 311 | |
Max Reitz | 7453c96 | 2015-02-10 15:28:50 -0500 | [diff] [blame] | 312 | typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array, |
| 313 | uint64_t index); |
| 314 | typedef void Qcow2SetRefcountFunc(void *refcount_array, |
| 315 | uint64_t index, uint64_t value); |
| 316 | |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 317 | typedef struct Qcow2BitmapHeaderExt { |
| 318 | uint32_t nb_bitmaps; |
| 319 | uint32_t reserved32; |
| 320 | uint64_t bitmap_directory_size; |
| 321 | uint64_t bitmap_directory_offset; |
| 322 | } QEMU_PACKED Qcow2BitmapHeaderExt; |
| 323 | |
Vladimir Sementsov-Ogievskiy | 8ac0f15 | 2019-05-06 17:27:41 +0300 | [diff] [blame] | 324 | #define QCOW2_MAX_THREADS 4 |
| 325 | |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 326 | typedef struct BDRVQcow2State { |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 327 | int cluster_bits; |
| 328 | int cluster_size; |
Alberto Garcia | 3c2e511 | 2018-02-05 16:33:13 +0200 | [diff] [blame] | 329 | int l2_slice_size; |
Alberto Garcia | d0346b5 | 2020-07-10 18:12:51 +0200 | [diff] [blame] | 330 | int subcluster_bits; |
| 331 | int subcluster_size; |
| 332 | int subclusters_per_cluster; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 333 | int l2_bits; |
| 334 | int l2_size; |
| 335 | int l1_size; |
| 336 | int l1_vm_state_index; |
Max Reitz | 1d13d65 | 2014-10-22 14:09:28 +0200 | [diff] [blame] | 337 | int refcount_block_bits; |
| 338 | int refcount_block_size; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 339 | int csize_shift; |
| 340 | int csize_mask; |
| 341 | uint64_t cluster_offset_mask; |
| 342 | uint64_t l1_table_offset; |
| 343 | uint64_t *l1_table; |
Kevin Wolf | 29c1a73 | 2011-01-10 17:17:28 +0100 | [diff] [blame] | 344 | |
shiliyang | 5f14f31 | 2020-10-30 11:35:12 +0800 | [diff] [blame] | 345 | Qcow2Cache *l2_table_cache; |
| 346 | Qcow2Cache *refcount_block_cache; |
Alberto Garcia | 279621c | 2015-08-04 15:14:40 +0300 | [diff] [blame] | 347 | QEMUTimer *cache_clean_timer; |
| 348 | unsigned cache_clean_interval; |
Kevin Wolf | 29c1a73 | 2011-01-10 17:17:28 +0100 | [diff] [blame] | 349 | |
Paolo Bonzini | b58deb3 | 2018-12-06 11:58:10 +0100 | [diff] [blame] | 350 | QLIST_HEAD(, QCowL2Meta) cluster_allocs; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 351 | |
| 352 | uint64_t *refcount_table; |
| 353 | uint64_t refcount_table_offset; |
| 354 | uint32_t refcount_table_size; |
Alberto Garcia | 7061a07 | 2017-02-01 14:38:28 +0200 | [diff] [blame] | 355 | uint32_t max_refcount_table_index; /* Last used entry in refcount_table */ |
Kevin Wolf | bb572ae | 2014-03-26 13:05:51 +0100 | [diff] [blame] | 356 | uint64_t free_cluster_index; |
| 357 | uint64_t free_byte_offset; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 358 | |
Kevin Wolf | 68d100e | 2011-06-30 17:42:09 +0200 | [diff] [blame] | 359 | CoMutex lock; |
| 360 | |
Daniel P. Berrange | 4652b8f | 2017-06-23 17:24:12 +0100 | [diff] [blame] | 361 | Qcow2CryptoHeaderExtension crypto_header; /* QCow2 header extension */ |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 362 | QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime options */ |
| 363 | QCryptoBlock *crypto; /* Disk encryption format driver */ |
Daniel P. Berrange | 4652b8f | 2017-06-23 17:24:12 +0100 | [diff] [blame] | 364 | bool crypt_physical_offset; /* Whether to use virtual or physical offset |
| 365 | for encryption initialization vector tweak */ |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 366 | uint32_t crypt_method_header; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 367 | uint64_t snapshots_offset; |
| 368 | int snapshots_size; |
Kevin Wolf | ce48f2f4 | 2014-03-26 13:05:45 +0100 | [diff] [blame] | 369 | unsigned int nb_snapshots; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 370 | QCowSnapshot *snapshots; |
Anthony Liguori | 06d9260 | 2011-11-14 15:09:46 -0600 | [diff] [blame] | 371 | |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 372 | uint32_t nb_bitmaps; |
| 373 | uint64_t bitmap_directory_size; |
| 374 | uint64_t bitmap_directory_offset; |
| 375 | |
Anthony Liguori | 06d9260 | 2011-11-14 15:09:46 -0600 | [diff] [blame] | 376 | int flags; |
Kevin Wolf | 6744cba | 2011-12-15 12:20:58 +0100 | [diff] [blame] | 377 | int qcow_version; |
Kevin Wolf | 74c4510 | 2013-03-15 10:35:08 +0100 | [diff] [blame] | 378 | bool use_lazy_refcounts; |
Max Reitz | b6481f3 | 2013-09-03 10:09:53 +0200 | [diff] [blame] | 379 | int refcount_order; |
Max Reitz | 346a53d | 2015-02-10 15:28:43 -0500 | [diff] [blame] | 380 | int refcount_bits; |
| 381 | uint64_t refcount_max; |
Kevin Wolf | 6744cba | 2011-12-15 12:20:58 +0100 | [diff] [blame] | 382 | |
Max Reitz | 7453c96 | 2015-02-10 15:28:50 -0500 | [diff] [blame] | 383 | Qcow2GetRefcountFunc *get_refcount; |
| 384 | Qcow2SetRefcountFunc *set_refcount; |
| 385 | |
Kevin Wolf | 67af674 | 2013-06-19 13:44:19 +0200 | [diff] [blame] | 386 | bool discard_passthrough[QCOW2_DISCARD_MAX]; |
| 387 | |
Max Reitz | 3e35539 | 2013-10-10 11:09:24 +0200 | [diff] [blame] | 388 | int overlap_check; /* bitmask of Qcow2MetadataOverlap values */ |
Max Reitz | 85186eb | 2014-09-05 16:07:16 +0200 | [diff] [blame] | 389 | bool signaled_corruption; |
Max Reitz | 3e35539 | 2013-10-10 11:09:24 +0200 | [diff] [blame] | 390 | |
Kevin Wolf | 6744cba | 2011-12-15 12:20:58 +0100 | [diff] [blame] | 391 | uint64_t incompatible_features; |
| 392 | uint64_t compatible_features; |
| 393 | uint64_t autoclear_features; |
| 394 | |
| 395 | size_t unknown_header_fields_size; |
shiliyang | 5f14f31 | 2020-10-30 11:35:12 +0800 | [diff] [blame] | 396 | void *unknown_header_fields; |
Kevin Wolf | 75bab85 | 2012-02-02 14:52:08 +0100 | [diff] [blame] | 397 | QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext; |
Kevin Wolf | 0b919fa | 2013-06-19 13:44:20 +0200 | [diff] [blame] | 398 | QTAILQ_HEAD (, Qcow2DiscardRegion) discards; |
| 399 | bool cache_discards; |
Kevin Wolf | e4603fe | 2015-04-07 15:03:16 +0200 | [diff] [blame] | 400 | |
| 401 | /* Backing file path and format as stored in the image (this is not the |
| 402 | * effective path/format, which may be the result of a runtime option |
| 403 | * override) */ |
| 404 | char *image_backing_file; |
| 405 | char *image_backing_format; |
Kevin Wolf | 9b890bd | 2019-01-15 19:02:40 +0100 | [diff] [blame] | 406 | char *image_data_file; |
Vladimir Sementsov-Ogievskiy | ceb029c | 2018-06-20 17:48:37 +0300 | [diff] [blame] | 407 | |
Vladimir Sementsov-Ogievskiy | 6f13a31 | 2019-05-06 17:27:38 +0300 | [diff] [blame] | 408 | CoQueue thread_task_queue; |
| 409 | int nb_threads; |
Kevin Wolf | 93c2493 | 2019-01-14 16:48:25 +0100 | [diff] [blame] | 410 | |
| 411 | BdrvChild *data_file; |
Vladimir Sementsov-Ogievskiy | 69f4750 | 2019-04-08 19:26:17 +0300 | [diff] [blame] | 412 | |
| 413 | bool metadata_preallocation_checked; |
| 414 | bool metadata_preallocation; |
Denis Plotnikov | 572ad97 | 2020-05-07 11:25:18 +0300 | [diff] [blame] | 415 | /* |
| 416 | * Compression type used for the image. Default: 0 - ZLIB |
| 417 | * The image compression type is set on image creation. |
| 418 | * For now, the only way to change the compression type |
| 419 | * is to convert the image with the desired compression type set. |
| 420 | */ |
| 421 | Qcow2CompressionType compression_type; |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 422 | } BDRVQcow2State; |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 423 | |
Kevin Wolf | 593fb83 | 2012-12-07 18:08:43 +0100 | [diff] [blame] | 424 | typedef struct Qcow2COWRegion { |
| 425 | /** |
| 426 | * Offset of the COW region in bytes from the start of the first cluster |
| 427 | * touched by the request. |
| 428 | */ |
Alberto Garcia | e034f5b | 2017-06-19 16:40:03 +0300 | [diff] [blame] | 429 | unsigned offset; |
Kevin Wolf | 593fb83 | 2012-12-07 18:08:43 +0100 | [diff] [blame] | 430 | |
Kevin Wolf | 8556739 | 2016-06-01 14:08:56 +0200 | [diff] [blame] | 431 | /** Number of bytes to copy */ |
Alberto Garcia | e034f5b | 2017-06-19 16:40:03 +0300 | [diff] [blame] | 432 | unsigned nb_bytes; |
Kevin Wolf | 593fb83 | 2012-12-07 18:08:43 +0100 | [diff] [blame] | 433 | } Qcow2COWRegion; |
| 434 | |
Kevin Wolf | f50f88b | 2012-12-07 18:08:46 +0100 | [diff] [blame] | 435 | /** |
| 436 | * Describes an in-flight (part of a) write request that writes to clusters |
Alberto Garcia | 3441ad4 | 2020-10-07 18:13:23 +0200 | [diff] [blame] | 437 | * that need to have their L2 table entries updated (because they are |
| 438 | * newly allocated or need changes in their L2 bitmaps) |
Kevin Wolf | f50f88b | 2012-12-07 18:08:46 +0100 | [diff] [blame] | 439 | */ |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 440 | typedef struct QCowL2Meta |
| 441 | { |
Alberto Garcia | 3441ad4 | 2020-10-07 18:13:23 +0200 | [diff] [blame] | 442 | /** Guest offset of the first updated cluster */ |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 443 | uint64_t offset; |
Kevin Wolf | 1d3afd6 | 2012-12-07 18:08:42 +0100 | [diff] [blame] | 444 | |
Alberto Garcia | 3441ad4 | 2020-10-07 18:13:23 +0200 | [diff] [blame] | 445 | /** Host offset of the first updated cluster */ |
Kevin Wolf | 250196f | 2012-03-02 14:10:54 +0100 | [diff] [blame] | 446 | uint64_t alloc_offset; |
Kevin Wolf | 1d3afd6 | 2012-12-07 18:08:42 +0100 | [diff] [blame] | 447 | |
Alberto Garcia | 3441ad4 | 2020-10-07 18:13:23 +0200 | [diff] [blame] | 448 | /** Number of updated clusters */ |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 449 | int nb_clusters; |
Kevin Wolf | 1d3afd6 | 2012-12-07 18:08:42 +0100 | [diff] [blame] | 450 | |
Max Reitz | 564a6b6 | 2017-05-04 01:11:18 +0200 | [diff] [blame] | 451 | /** Do not free the old clusters */ |
| 452 | bool keep_old_clusters; |
| 453 | |
Kevin Wolf | 1d3afd6 | 2012-12-07 18:08:42 +0100 | [diff] [blame] | 454 | /** |
| 455 | * Requests that overlap with this allocation and wait to be restarted |
| 456 | * when the allocating request has completed. |
| 457 | */ |
Kevin Wolf | 68d100e | 2011-06-30 17:42:09 +0200 | [diff] [blame] | 458 | CoQueue dependent_requests; |
Kevin Wolf | f214978 | 2009-08-31 16:48:49 +0200 | [diff] [blame] | 459 | |
Kevin Wolf | 593fb83 | 2012-12-07 18:08:43 +0100 | [diff] [blame] | 460 | /** |
Alberto Garcia | 3441ad4 | 2020-10-07 18:13:23 +0200 | [diff] [blame] | 461 | * The COW Region immediately before the area the guest actually |
| 462 | * writes to. This (part of the) write request starts at |
| 463 | * cow_start.offset + cow_start.nb_bytes. |
Kevin Wolf | 593fb83 | 2012-12-07 18:08:43 +0100 | [diff] [blame] | 464 | */ |
| 465 | Qcow2COWRegion cow_start; |
| 466 | |
| 467 | /** |
Alberto Garcia | 3441ad4 | 2020-10-07 18:13:23 +0200 | [diff] [blame] | 468 | * The COW Region immediately after the area the guest actually |
| 469 | * writes to. This (part of the) write request ends at cow_end.offset |
| 470 | * (which must always be set even when cow_end.nb_bytes is 0). |
Kevin Wolf | 593fb83 | 2012-12-07 18:08:43 +0100 | [diff] [blame] | 471 | */ |
| 472 | Qcow2COWRegion cow_end; |
| 473 | |
Anton Nefedov | c8bb23c | 2019-05-16 17:27:49 +0300 | [diff] [blame] | 474 | /* |
| 475 | * Indicates that COW regions are already handled and do not require |
| 476 | * any more processing. |
| 477 | */ |
| 478 | bool skip_cow; |
| 479 | |
Alberto Garcia | ee22a9d | 2017-06-19 16:40:08 +0300 | [diff] [blame] | 480 | /** |
Alberto Garcia | 40dee94 | 2020-07-10 18:13:12 +0200 | [diff] [blame] | 481 | * Indicates that this is not a normal write request but a preallocation. |
| 482 | * If the image has extended L2 entries this means that no new individual |
| 483 | * subclusters will be marked as allocated in the L2 bitmap (but any |
| 484 | * existing contents of that bitmap will be kept). |
| 485 | */ |
| 486 | bool prealloc; |
| 487 | |
| 488 | /** |
Alberto Garcia | ee22a9d | 2017-06-19 16:40:08 +0300 | [diff] [blame] | 489 | * The I/O vector with the data from the actual guest write request. |
| 490 | * If non-NULL, this is meant to be merged together with the data |
| 491 | * from @cow_start and @cow_end into one single write operation. |
| 492 | */ |
| 493 | QEMUIOVector *data_qiov; |
Vladimir Sementsov-Ogievskiy | 5396234 | 2019-06-04 19:15:14 +0300 | [diff] [blame] | 494 | size_t data_qiov_offset; |
Alberto Garcia | ee22a9d | 2017-06-19 16:40:08 +0300 | [diff] [blame] | 495 | |
Kevin Wolf | 88c6588 | 2013-03-26 17:50:11 +0100 | [diff] [blame] | 496 | /** Pointer to next L2Meta of the same write request */ |
| 497 | struct QCowL2Meta *next; |
| 498 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 499 | QLIST_ENTRY(QCowL2Meta) next_in_flight; |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 500 | } QCowL2Meta; |
| 501 | |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 502 | /* |
| 503 | * In images with standard L2 entries all clusters are treated as if |
| 504 | * they had one subcluster so QCow2ClusterType and QCow2SubclusterType |
| 505 | * can be mapped to each other and have the exact same meaning |
| 506 | * (QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC cannot happen in these images). |
| 507 | * |
| 508 | * In images with extended L2 entries QCow2ClusterType refers to the |
| 509 | * complete cluster and QCow2SubclusterType to each of the individual |
| 510 | * subclusters, so there are several possible combinations: |
| 511 | * |
| 512 | * |--------------+---------------------------| |
| 513 | * | Cluster type | Possible subcluster types | |
| 514 | * |--------------+---------------------------| |
| 515 | * | UNALLOCATED | UNALLOCATED_PLAIN | |
| 516 | * | | ZERO_PLAIN | |
| 517 | * |--------------+---------------------------| |
| 518 | * | NORMAL | UNALLOCATED_ALLOC | |
| 519 | * | | ZERO_ALLOC | |
| 520 | * | | NORMAL | |
| 521 | * |--------------+---------------------------| |
| 522 | * | COMPRESSED | COMPRESSED | |
| 523 | * |--------------+---------------------------| |
| 524 | * |
| 525 | * QCOW2_SUBCLUSTER_INVALID means that the L2 entry is incorrect and |
| 526 | * the image should be marked corrupt. |
| 527 | */ |
| 528 | |
Eric Blake | 3ef9521 | 2017-05-06 19:05:45 -0500 | [diff] [blame] | 529 | typedef enum QCow2ClusterType { |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 530 | QCOW2_CLUSTER_UNALLOCATED, |
Eric Blake | fdfab37 | 2017-05-06 19:05:46 -0500 | [diff] [blame] | 531 | QCOW2_CLUSTER_ZERO_PLAIN, |
| 532 | QCOW2_CLUSTER_ZERO_ALLOC, |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 533 | QCOW2_CLUSTER_NORMAL, |
| 534 | QCOW2_CLUSTER_COMPRESSED, |
Eric Blake | 3ef9521 | 2017-05-06 19:05:45 -0500 | [diff] [blame] | 535 | } QCow2ClusterType; |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 536 | |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 537 | typedef enum QCow2SubclusterType { |
| 538 | QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN, |
| 539 | QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC, |
| 540 | QCOW2_SUBCLUSTER_ZERO_PLAIN, |
| 541 | QCOW2_SUBCLUSTER_ZERO_ALLOC, |
| 542 | QCOW2_SUBCLUSTER_NORMAL, |
| 543 | QCOW2_SUBCLUSTER_COMPRESSED, |
| 544 | QCOW2_SUBCLUSTER_INVALID, |
| 545 | } QCow2SubclusterType; |
| 546 | |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 547 | typedef enum QCow2MetadataOverlap { |
Vladimir Sementsov-Ogievskiy | 0e4e431 | 2018-07-05 18:15:15 +0300 | [diff] [blame] | 548 | QCOW2_OL_MAIN_HEADER_BITNR = 0, |
| 549 | QCOW2_OL_ACTIVE_L1_BITNR = 1, |
| 550 | QCOW2_OL_ACTIVE_L2_BITNR = 2, |
| 551 | QCOW2_OL_REFCOUNT_TABLE_BITNR = 3, |
| 552 | QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4, |
| 553 | QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5, |
| 554 | QCOW2_OL_INACTIVE_L1_BITNR = 6, |
| 555 | QCOW2_OL_INACTIVE_L2_BITNR = 7, |
| 556 | QCOW2_OL_BITMAP_DIRECTORY_BITNR = 8, |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 557 | |
Vladimir Sementsov-Ogievskiy | 0e4e431 | 2018-07-05 18:15:15 +0300 | [diff] [blame] | 558 | QCOW2_OL_MAX_BITNR = 9, |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 559 | |
Vladimir Sementsov-Ogievskiy | 0e4e431 | 2018-07-05 18:15:15 +0300 | [diff] [blame] | 560 | QCOW2_OL_NONE = 0, |
| 561 | QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR), |
| 562 | QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR), |
| 563 | QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR), |
| 564 | QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR), |
| 565 | QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR), |
| 566 | QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR), |
| 567 | QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR), |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 568 | /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv |
| 569 | * reads. */ |
Vladimir Sementsov-Ogievskiy | 0e4e431 | 2018-07-05 18:15:15 +0300 | [diff] [blame] | 570 | QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR), |
| 571 | QCOW2_OL_BITMAP_DIRECTORY = (1 << QCOW2_OL_BITMAP_DIRECTORY_BITNR), |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 572 | } QCow2MetadataOverlap; |
| 573 | |
Max Reitz | 4a273c3 | 2013-10-10 11:09:27 +0200 | [diff] [blame] | 574 | /* Perform all overlap checks which can be done in constant time */ |
| 575 | #define QCOW2_OL_CONSTANT \ |
| 576 | (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \ |
Vladimir Sementsov-Ogievskiy | 0e4e431 | 2018-07-05 18:15:15 +0300 | [diff] [blame] | 577 | QCOW2_OL_SNAPSHOT_TABLE | QCOW2_OL_BITMAP_DIRECTORY) |
Max Reitz | 4a273c3 | 2013-10-10 11:09:27 +0200 | [diff] [blame] | 578 | |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 579 | /* Perform all overlap checks which don't require disk access */ |
| 580 | #define QCOW2_OL_CACHED \ |
Max Reitz | 4a273c3 | 2013-10-10 11:09:27 +0200 | [diff] [blame] | 581 | (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \ |
| 582 | QCOW2_OL_INACTIVE_L1) |
| 583 | |
| 584 | /* Perform all overlap checks */ |
| 585 | #define QCOW2_OL_ALL \ |
| 586 | (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2) |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 587 | |
Hu Tao | 46bae92 | 2014-01-21 11:30:02 +0800 | [diff] [blame] | 588 | #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL |
Vladimir Sementsov-Ogievskiy | 98bc07d | 2021-09-14 15:24:53 +0300 | [diff] [blame] | 589 | #define L1E_RESERVED_MASK 0x7f000000000001ffULL |
Hu Tao | 46bae92 | 2014-01-21 11:30:02 +0800 | [diff] [blame] | 590 | #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL |
Vladimir Sementsov-Ogievskiy | 289ef5f | 2021-09-14 15:24:51 +0300 | [diff] [blame] | 591 | #define L2E_STD_RESERVED_MASK 0x3f000000000001feULL |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 592 | |
Hu Tao | 46bae92 | 2014-01-21 11:30:02 +0800 | [diff] [blame] | 593 | #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL |
Vladimir Sementsov-Ogievskiy | 8fba395 | 2021-09-14 15:24:54 +0300 | [diff] [blame] | 594 | #define REFT_RESERVED_MASK 0x1ffULL |
Kevin Wolf | 76dc9e0 | 2012-03-16 14:09:08 +0100 | [diff] [blame] | 595 | |
Kevin Wolf | c6d619c | 2019-01-18 14:40:36 +0100 | [diff] [blame] | 596 | #define INV_OFFSET (-1ULL) |
| 597 | |
Alberto Garcia | a3c7d91 | 2020-07-10 18:12:50 +0200 | [diff] [blame] | 598 | static inline bool has_subclusters(BDRVQcow2State *s) |
| 599 | { |
Alberto Garcia | 7be2025 | 2020-07-10 18:13:13 +0200 | [diff] [blame] | 600 | return s->incompatible_features & QCOW2_INCOMPAT_EXTL2; |
Alberto Garcia | a3c7d91 | 2020-07-10 18:12:50 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Alberto Garcia | c8fd855 | 2020-07-10 18:12:54 +0200 | [diff] [blame] | 603 | static inline size_t l2_entry_size(BDRVQcow2State *s) |
| 604 | { |
| 605 | return has_subclusters(s) ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL; |
| 606 | } |
| 607 | |
Alberto Garcia | 12c6aeb | 2020-07-10 18:12:48 +0200 | [diff] [blame] | 608 | static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, |
| 609 | int idx) |
| 610 | { |
Alberto Garcia | 39a9f0a | 2020-07-10 18:12:55 +0200 | [diff] [blame] | 611 | idx *= l2_entry_size(s) / sizeof(uint64_t); |
Alberto Garcia | 12c6aeb | 2020-07-10 18:12:48 +0200 | [diff] [blame] | 612 | return be64_to_cpu(l2_slice[idx]); |
| 613 | } |
| 614 | |
Alberto Garcia | 39a9f0a | 2020-07-10 18:12:55 +0200 | [diff] [blame] | 615 | static inline uint64_t get_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice, |
| 616 | int idx) |
| 617 | { |
| 618 | if (has_subclusters(s)) { |
| 619 | idx *= l2_entry_size(s) / sizeof(uint64_t); |
| 620 | return be64_to_cpu(l2_slice[idx + 1]); |
| 621 | } else { |
| 622 | return 0; /* For convenience only; this value has no meaning. */ |
| 623 | } |
| 624 | } |
| 625 | |
Alberto Garcia | 12c6aeb | 2020-07-10 18:12:48 +0200 | [diff] [blame] | 626 | static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice, |
| 627 | int idx, uint64_t entry) |
| 628 | { |
Alberto Garcia | 39a9f0a | 2020-07-10 18:12:55 +0200 | [diff] [blame] | 629 | idx *= l2_entry_size(s) / sizeof(uint64_t); |
Alberto Garcia | 12c6aeb | 2020-07-10 18:12:48 +0200 | [diff] [blame] | 630 | l2_slice[idx] = cpu_to_be64(entry); |
| 631 | } |
| 632 | |
Alberto Garcia | 39a9f0a | 2020-07-10 18:12:55 +0200 | [diff] [blame] | 633 | static inline void set_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice, |
| 634 | int idx, uint64_t bitmap) |
| 635 | { |
| 636 | assert(has_subclusters(s)); |
| 637 | idx *= l2_entry_size(s) / sizeof(uint64_t); |
| 638 | l2_slice[idx + 1] = cpu_to_be64(bitmap); |
| 639 | } |
| 640 | |
Kevin Wolf | 93c2493 | 2019-01-14 16:48:25 +0100 | [diff] [blame] | 641 | static inline bool has_data_file(BlockDriverState *bs) |
| 642 | { |
| 643 | BDRVQcow2State *s = bs->opaque; |
| 644 | return (s->data_file != bs->file); |
| 645 | } |
| 646 | |
Kevin Wolf | 6c3944d | 2019-02-22 14:29:38 +0100 | [diff] [blame] | 647 | static inline bool data_file_is_raw(BlockDriverState *bs) |
| 648 | { |
| 649 | BDRVQcow2State *s = bs->opaque; |
| 650 | return !!(s->autoclear_features & QCOW2_AUTOCLEAR_DATA_FILE_RAW); |
| 651 | } |
| 652 | |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 653 | static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset) |
Kevin Wolf | 3b8e2e2 | 2013-03-26 17:50:02 +0100 | [diff] [blame] | 654 | { |
| 655 | return offset & ~(s->cluster_size - 1); |
| 656 | } |
| 657 | |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 658 | static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset) |
Kevin Wolf | c37f4cd | 2013-03-26 17:50:03 +0100 | [diff] [blame] | 659 | { |
| 660 | return offset & (s->cluster_size - 1); |
| 661 | } |
| 662 | |
Alberto Garcia | 3e71981 | 2020-07-10 18:12:53 +0200 | [diff] [blame] | 663 | static inline int64_t offset_into_subcluster(BDRVQcow2State *s, int64_t offset) |
| 664 | { |
| 665 | return offset & (s->subcluster_size - 1); |
| 666 | } |
| 667 | |
Max Reitz | b6d36de | 2015-09-14 16:39:47 +0200 | [diff] [blame] | 668 | static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size) |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 669 | { |
| 670 | return (size + (s->cluster_size - 1)) >> s->cluster_bits; |
| 671 | } |
| 672 | |
Alberto Garcia | 3e71981 | 2020-07-10 18:12:53 +0200 | [diff] [blame] | 673 | static inline uint64_t size_to_subclusters(BDRVQcow2State *s, uint64_t size) |
| 674 | { |
| 675 | return (size + (s->subcluster_size - 1)) >> s->subcluster_bits; |
| 676 | } |
| 677 | |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 678 | static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size) |
Stefan Hajnoczi | 419b19d | 2010-04-28 11:36:11 +0100 | [diff] [blame] | 679 | { |
| 680 | int shift = s->cluster_bits + s->l2_bits; |
| 681 | return (size + (1ULL << shift) - 1) >> shift; |
| 682 | } |
| 683 | |
Alberto Garcia | 05b5b6e | 2018-02-05 16:33:12 +0200 | [diff] [blame] | 684 | static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset) |
| 685 | { |
| 686 | return offset >> (s->l2_bits + s->cluster_bits); |
| 687 | } |
| 688 | |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 689 | static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset) |
Kevin Wolf | 17a71e5 | 2013-03-26 17:49:56 +0100 | [diff] [blame] | 690 | { |
| 691 | return (offset >> s->cluster_bits) & (s->l2_size - 1); |
| 692 | } |
| 693 | |
Alberto Garcia | 8f81817 | 2018-02-05 16:33:14 +0200 | [diff] [blame] | 694 | static inline int offset_to_l2_slice_index(BDRVQcow2State *s, int64_t offset) |
| 695 | { |
| 696 | return (offset >> s->cluster_bits) & (s->l2_slice_size - 1); |
| 697 | } |
| 698 | |
Alberto Garcia | a53e8b7 | 2020-07-10 18:12:52 +0200 | [diff] [blame] | 699 | static inline int offset_to_sc_index(BDRVQcow2State *s, int64_t offset) |
| 700 | { |
| 701 | return (offset >> s->subcluster_bits) & (s->subclusters_per_cluster - 1); |
| 702 | } |
| 703 | |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 704 | static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s) |
Kevin Wolf | 1ebf561 | 2013-09-06 12:20:08 +0200 | [diff] [blame] | 705 | { |
| 706 | return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits); |
| 707 | } |
| 708 | |
Kevin Wolf | 808c2bb | 2019-01-17 18:42:40 +0100 | [diff] [blame] | 709 | static inline QCow2ClusterType qcow2_get_cluster_type(BlockDriverState *bs, |
| 710 | uint64_t l2_entry) |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 711 | { |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 712 | BDRVQcow2State *s = bs->opaque; |
| 713 | |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 714 | if (l2_entry & QCOW_OFLAG_COMPRESSED) { |
| 715 | return QCOW2_CLUSTER_COMPRESSED; |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 716 | } else if ((l2_entry & QCOW_OFLAG_ZERO) && !has_subclusters(s)) { |
Eric Blake | fdfab37 | 2017-05-06 19:05:46 -0500 | [diff] [blame] | 717 | if (l2_entry & L2E_OFFSET_MASK) { |
| 718 | return QCOW2_CLUSTER_ZERO_ALLOC; |
| 719 | } |
| 720 | return QCOW2_CLUSTER_ZERO_PLAIN; |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 721 | } else if (!(l2_entry & L2E_OFFSET_MASK)) { |
Kevin Wolf | a4ea184 | 2019-01-29 13:47:24 +0100 | [diff] [blame] | 722 | /* Offset 0 generally means unallocated, but it is ambiguous with |
| 723 | * external data files because 0 is a valid offset there. However, all |
| 724 | * clusters in external data files always have refcount 1, so we can |
| 725 | * rely on QCOW_OFLAG_COPIED to disambiguate. */ |
| 726 | if (has_data_file(bs) && (l2_entry & QCOW_OFLAG_COPIED)) { |
| 727 | return QCOW2_CLUSTER_NORMAL; |
| 728 | } else { |
| 729 | return QCOW2_CLUSTER_UNALLOCATED; |
| 730 | } |
Kevin Wolf | 68d000a | 2012-03-14 19:15:03 +0100 | [diff] [blame] | 731 | } else { |
| 732 | return QCOW2_CLUSTER_NORMAL; |
| 733 | } |
| 734 | } |
| 735 | |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 736 | /* |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 737 | * In an image without subsclusters @l2_bitmap is ignored and |
| 738 | * @sc_index must be 0. |
| 739 | * Return QCOW2_SUBCLUSTER_INVALID if an invalid l2 entry is detected |
| 740 | * (this checks the whole entry and bitmap, not only the bits related |
| 741 | * to subcluster @sc_index). |
| 742 | */ |
| 743 | static inline |
| 744 | QCow2SubclusterType qcow2_get_subcluster_type(BlockDriverState *bs, |
| 745 | uint64_t l2_entry, |
| 746 | uint64_t l2_bitmap, |
| 747 | unsigned sc_index) |
| 748 | { |
| 749 | BDRVQcow2State *s = bs->opaque; |
| 750 | QCow2ClusterType type = qcow2_get_cluster_type(bs, l2_entry); |
| 751 | assert(sc_index < s->subclusters_per_cluster); |
| 752 | |
| 753 | if (has_subclusters(s)) { |
| 754 | switch (type) { |
| 755 | case QCOW2_CLUSTER_COMPRESSED: |
| 756 | return QCOW2_SUBCLUSTER_COMPRESSED; |
| 757 | case QCOW2_CLUSTER_NORMAL: |
| 758 | if ((l2_bitmap >> 32) & l2_bitmap) { |
| 759 | return QCOW2_SUBCLUSTER_INVALID; |
| 760 | } else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) { |
| 761 | return QCOW2_SUBCLUSTER_ZERO_ALLOC; |
| 762 | } else if (l2_bitmap & QCOW_OFLAG_SUB_ALLOC(sc_index)) { |
| 763 | return QCOW2_SUBCLUSTER_NORMAL; |
| 764 | } else { |
| 765 | return QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC; |
| 766 | } |
| 767 | case QCOW2_CLUSTER_UNALLOCATED: |
| 768 | if (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC) { |
| 769 | return QCOW2_SUBCLUSTER_INVALID; |
| 770 | } else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) { |
| 771 | return QCOW2_SUBCLUSTER_ZERO_PLAIN; |
| 772 | } else { |
| 773 | return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; |
| 774 | } |
| 775 | default: |
| 776 | g_assert_not_reached(); |
| 777 | } |
| 778 | } else { |
Alberto Garcia | 3f9c6b3 | 2020-07-10 18:13:03 +0200 | [diff] [blame] | 779 | switch (type) { |
| 780 | case QCOW2_CLUSTER_COMPRESSED: |
| 781 | return QCOW2_SUBCLUSTER_COMPRESSED; |
| 782 | case QCOW2_CLUSTER_ZERO_PLAIN: |
| 783 | return QCOW2_SUBCLUSTER_ZERO_PLAIN; |
| 784 | case QCOW2_CLUSTER_ZERO_ALLOC: |
| 785 | return QCOW2_SUBCLUSTER_ZERO_ALLOC; |
| 786 | case QCOW2_CLUSTER_NORMAL: |
| 787 | return QCOW2_SUBCLUSTER_NORMAL; |
| 788 | case QCOW2_CLUSTER_UNALLOCATED: |
| 789 | return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN; |
| 790 | default: |
| 791 | g_assert_not_reached(); |
| 792 | } |
Alberto Garcia | 34905d8 | 2020-07-10 18:12:56 +0200 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | |
Alberto Garcia | c94d037 | 2020-07-10 18:12:58 +0200 | [diff] [blame] | 796 | static inline bool qcow2_cluster_is_allocated(QCow2ClusterType type) |
| 797 | { |
| 798 | return (type == QCOW2_CLUSTER_COMPRESSED || type == QCOW2_CLUSTER_NORMAL || |
| 799 | type == QCOW2_CLUSTER_ZERO_ALLOC); |
| 800 | } |
| 801 | |
Stefan Hajnoczi | bfe8043 | 2012-07-27 09:05:22 +0100 | [diff] [blame] | 802 | /* Check whether refcounts are eager or lazy */ |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 803 | static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s) |
Stefan Hajnoczi | bfe8043 | 2012-07-27 09:05:22 +0100 | [diff] [blame] | 804 | { |
| 805 | return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY); |
| 806 | } |
Kevin Wolf | c142442 | 2009-05-28 16:07:06 +0200 | [diff] [blame] | 807 | |
Kevin Wolf | 65eb2e3 | 2013-03-26 17:49:58 +0100 | [diff] [blame] | 808 | static inline uint64_t l2meta_cow_start(QCowL2Meta *m) |
| 809 | { |
| 810 | return m->offset + m->cow_start.offset; |
| 811 | } |
| 812 | |
| 813 | static inline uint64_t l2meta_cow_end(QCowL2Meta *m) |
| 814 | { |
Kevin Wolf | 8556739 | 2016-06-01 14:08:56 +0200 | [diff] [blame] | 815 | return m->offset + m->cow_end.offset + m->cow_end.nb_bytes; |
Kevin Wolf | 65eb2e3 | 2013-03-26 17:49:58 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Max Reitz | 0e06528 | 2015-02-10 15:28:48 -0500 | [diff] [blame] | 818 | static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2) |
Max Reitz | 2aabe7c | 2015-02-10 15:28:47 -0500 | [diff] [blame] | 819 | { |
| 820 | return r1 > r2 ? r1 - r2 : r2 - r1; |
| 821 | } |
| 822 | |
Pavel Butsykin | 46b732c | 2017-09-18 15:42:29 +0300 | [diff] [blame] | 823 | static inline |
| 824 | uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset) |
| 825 | { |
| 826 | return offset >> (s->refcount_block_bits + s->cluster_bits); |
| 827 | } |
| 828 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 829 | /* qcow2.c functions */ |
Max Reitz | 12cc30a | 2017-06-13 22:21:03 +0200 | [diff] [blame] | 830 | int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size, |
| 831 | int refcount_order, bool generous_increase, |
| 832 | uint64_t *refblock_count); |
| 833 | |
Kevin Wolf | 280d373 | 2012-12-07 18:08:47 +0100 | [diff] [blame] | 834 | int qcow2_mark_dirty(BlockDriverState *bs); |
Max Reitz | 69c9872 | 2013-08-30 14:34:24 +0200 | [diff] [blame] | 835 | int qcow2_mark_corrupt(BlockDriverState *bs); |
| 836 | int qcow2_mark_consistent(BlockDriverState *bs); |
Kevin Wolf | e24e49e | 2012-02-02 12:32:31 +0100 | [diff] [blame] | 837 | int qcow2_update_header(BlockDriverState *bs); |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 838 | |
Max Reitz | 85186eb | 2014-09-05 16:07:16 +0200 | [diff] [blame] | 839 | void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset, |
| 840 | int64_t size, const char *message_format, ...) |
| 841 | GCC_FMT_ATTR(5, 6); |
| 842 | |
Alberto Garcia | 0cf0e59 | 2018-03-06 18:14:06 +0200 | [diff] [blame] | 843 | int qcow2_validate_table(BlockDriverState *bs, uint64_t offset, |
| 844 | uint64_t entries, size_t entry_len, |
| 845 | int64_t max_size_bytes, const char *table_name, |
| 846 | Error **errp); |
| 847 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 848 | /* qcow2-refcount.c functions */ |
Kevin Wolf | ed6ccf0 | 2009-05-28 16:07:07 +0200 | [diff] [blame] | 849 | int qcow2_refcount_init(BlockDriverState *bs); |
| 850 | void qcow2_refcount_close(BlockDriverState *bs); |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 851 | |
Max Reitz | 7324c10 | 2015-02-10 15:28:46 -0500 | [diff] [blame] | 852 | int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index, |
Max Reitz | 0e06528 | 2015-02-10 15:28:48 -0500 | [diff] [blame] | 853 | uint64_t *refcount); |
Max Reitz | 4475191 | 2014-10-27 11:12:54 +0100 | [diff] [blame] | 854 | |
Max Reitz | 32b6444 | 2013-09-03 10:09:52 +0200 | [diff] [blame] | 855 | int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index, |
Max Reitz | 0e06528 | 2015-02-10 15:28:48 -0500 | [diff] [blame] | 856 | uint64_t addend, bool decrease, |
Max Reitz | 2aabe7c | 2015-02-10 15:28:47 -0500 | [diff] [blame] | 857 | enum qcow2_discard_type type); |
Max Reitz | 32b6444 | 2013-09-03 10:09:52 +0200 | [diff] [blame] | 858 | |
Max Reitz | 772d1f9 | 2017-06-13 22:21:05 +0200 | [diff] [blame] | 859 | int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset, |
| 860 | uint64_t additional_clusters, bool exact_size, |
| 861 | int new_refblock_index, |
| 862 | uint64_t new_refblock_offset); |
| 863 | |
Kevin Wolf | bb572ae | 2014-03-26 13:05:51 +0100 | [diff] [blame] | 864 | int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size); |
Max Reitz | b6d36de | 2015-09-14 16:39:47 +0200 | [diff] [blame] | 865 | int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, |
| 866 | int64_t nb_clusters); |
Kevin Wolf | ed6ccf0 | 2009-05-28 16:07:07 +0200 | [diff] [blame] | 867 | int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size); |
| 868 | void qcow2_free_clusters(BlockDriverState *bs, |
Kevin Wolf | 6cfcb9b | 2013-06-19 13:44:18 +0200 | [diff] [blame] | 869 | int64_t offset, int64_t size, |
| 870 | enum qcow2_discard_type type); |
Alberto Garcia | 3fec237 | 2020-09-08 16:08:28 +0200 | [diff] [blame] | 871 | void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry, |
| 872 | enum qcow2_discard_type type); |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 873 | |
Kevin Wolf | ed6ccf0 | 2009-05-28 16:07:07 +0200 | [diff] [blame] | 874 | int qcow2_update_snapshot_refcount(BlockDriverState *bs, |
| 875 | int64_t l1_table_offset, int l1_size, int addend); |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 876 | |
Paolo Bonzini | 8b220eb | 2018-03-01 17:36:14 +0100 | [diff] [blame] | 877 | int coroutine_fn qcow2_flush_caches(BlockDriverState *bs); |
| 878 | int coroutine_fn qcow2_write_caches(BlockDriverState *bs); |
Kevin Wolf | 166acf5 | 2012-05-11 18:18:36 +0200 | [diff] [blame] | 879 | int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, |
| 880 | BdrvCheckMode fix); |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 881 | |
Kevin Wolf | 0b919fa | 2013-06-19 13:44:20 +0200 | [diff] [blame] | 882 | void qcow2_process_discards(BlockDriverState *bs, int ret); |
| 883 | |
Max Reitz | 231bb26 | 2013-10-10 11:09:23 +0200 | [diff] [blame] | 884 | int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 885 | int64_t size); |
Max Reitz | 231bb26 | 2013-10-10 11:09:23 +0200 | [diff] [blame] | 886 | int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset, |
Kevin Wolf | 966b000 | 2019-01-15 20:39:06 +0100 | [diff] [blame] | 887 | int64_t size, bool data_file); |
Vladimir Sementsov-Ogievskiy | 8a5bb1f | 2017-06-28 15:05:07 +0300 | [diff] [blame] | 888 | int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res, |
| 889 | void **refcount_table, |
| 890 | int64_t *refcount_table_size, |
| 891 | int64_t offset, int64_t size); |
Max Reitz | a40f1c2 | 2013-08-30 14:34:25 +0200 | [diff] [blame] | 892 | |
Max Reitz | 791c9a0 | 2015-07-27 17:51:37 +0200 | [diff] [blame] | 893 | int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, |
| 894 | BlockDriverAmendStatusCB *status_cb, |
| 895 | void *cb_opaque, Error **errp); |
Pavel Butsykin | 46b732c | 2017-09-18 15:42:29 +0300 | [diff] [blame] | 896 | int qcow2_shrink_reftable(BlockDriverState *bs); |
Pavel Butsykin | 163bc39 | 2017-09-29 15:16:13 +0300 | [diff] [blame] | 897 | int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); |
Vladimir Sementsov-Ogievskiy | 69f4750 | 2019-04-08 19:26:17 +0300 | [diff] [blame] | 898 | int qcow2_detect_metadata_preallocation(BlockDriverState *bs); |
Max Reitz | 791c9a0 | 2015-07-27 17:51:37 +0200 | [diff] [blame] | 899 | |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 900 | /* qcow2-cluster.c functions */ |
Kevin Wolf | 2cf7cfa | 2013-05-14 16:14:33 +0200 | [diff] [blame] | 901 | int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, |
| 902 | bool exact_size); |
Pavel Butsykin | 46b732c | 2017-09-18 15:42:29 +0300 | [diff] [blame] | 903 | int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size); |
Max Reitz | e23e400 | 2013-08-30 14:34:28 +0200 | [diff] [blame] | 904 | int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index); |
Kevin Wolf | ff99129 | 2015-09-07 17:12:56 +0200 | [diff] [blame] | 905 | int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, |
Daniel P. Berrange | 446d306 | 2017-06-23 17:24:09 +0100 | [diff] [blame] | 906 | uint8_t *buf, int nb_sectors, bool enc, Error **errp); |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 907 | |
Alberto Garcia | 388e581 | 2020-07-10 18:12:44 +0200 | [diff] [blame] | 908 | int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, |
Alberto Garcia | ca4a0bb | 2020-07-10 18:12:59 +0200 | [diff] [blame] | 909 | unsigned int *bytes, uint64_t *host_offset, |
Alberto Garcia | 10dabdc5 | 2020-07-10 18:13:00 +0200 | [diff] [blame] | 910 | QCow2SubclusterType *subcluster_type); |
Alberto Garcia | bfd0989 | 2020-09-11 16:09:42 +0200 | [diff] [blame] | 911 | int qcow2_alloc_host_offset(BlockDriverState *bs, uint64_t offset, |
| 912 | unsigned int *bytes, uint64_t *host_offset, |
| 913 | QCowL2Meta **m); |
Kevin Wolf | 77e023f | 2019-02-27 10:26:24 +0100 | [diff] [blame] | 914 | int qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, |
| 915 | uint64_t offset, |
| 916 | int compressed_size, |
| 917 | uint64_t *host_offset); |
Vladimir Sementsov-Ogievskiy | a6e0984 | 2021-09-14 15:24:47 +0300 | [diff] [blame] | 918 | void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_entry, |
| 919 | uint64_t *coffset, int *csize); |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 920 | |
Kevin Wolf | 148da7e | 2010-01-20 15:03:01 +0100 | [diff] [blame] | 921 | int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); |
Kevin Wolf | 8b24cd1 | 2018-06-28 17:05:45 +0200 | [diff] [blame] | 922 | void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m); |
Eric Blake | d2cb36a | 2017-05-06 19:05:52 -0500 | [diff] [blame] | 923 | int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, |
| 924 | uint64_t bytes, enum qcow2_discard_type type, |
| 925 | bool full_discard); |
Alberto Garcia | a6841a2 | 2020-07-10 18:13:10 +0200 | [diff] [blame] | 926 | int qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset, |
| 927 | uint64_t bytes, int flags); |
Kevin Wolf | 45aba42 | 2009-05-28 16:07:05 +0200 | [diff] [blame] | 928 | |
Max Reitz | 4057a2b | 2014-10-27 11:12:53 +0100 | [diff] [blame] | 929 | int qcow2_expand_zero_clusters(BlockDriverState *bs, |
Max Reitz | 8b13976 | 2015-07-27 17:51:32 +0200 | [diff] [blame] | 930 | BlockDriverAmendStatusCB *status_cb, |
| 931 | void *cb_opaque); |
Max Reitz | 32b6444 | 2013-09-03 10:09:52 +0200 | [diff] [blame] | 932 | |
Kevin Wolf | c142442 | 2009-05-28 16:07:06 +0200 | [diff] [blame] | 933 | /* qcow2-snapshot.c functions */ |
Kevin Wolf | ed6ccf0 | 2009-05-28 16:07:07 +0200 | [diff] [blame] | 934 | int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); |
| 935 | int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id); |
Wenchao Xia | a89d89d | 2013-09-11 14:04:33 +0800 | [diff] [blame] | 936 | int qcow2_snapshot_delete(BlockDriverState *bs, |
| 937 | const char *snapshot_id, |
| 938 | const char *name, |
| 939 | Error **errp); |
Kevin Wolf | ed6ccf0 | 2009-05-28 16:07:07 +0200 | [diff] [blame] | 940 | int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab); |
Wenchao Xia | 7b4c478 | 2013-12-04 17:10:54 +0800 | [diff] [blame] | 941 | int qcow2_snapshot_load_tmp(BlockDriverState *bs, |
| 942 | const char *snapshot_id, |
| 943 | const char *name, |
| 944 | Error **errp); |
Kevin Wolf | c142442 | 2009-05-28 16:07:06 +0200 | [diff] [blame] | 945 | |
Kevin Wolf | ed6ccf0 | 2009-05-28 16:07:07 +0200 | [diff] [blame] | 946 | void qcow2_free_snapshots(BlockDriverState *bs); |
Max Reitz | ecf6c7c | 2019-10-11 17:28:01 +0200 | [diff] [blame] | 947 | int qcow2_read_snapshots(BlockDriverState *bs, Error **errp); |
Max Reitz | e0314b5 | 2019-10-11 17:28:03 +0200 | [diff] [blame] | 948 | int qcow2_write_snapshots(BlockDriverState *bs); |
Kevin Wolf | c142442 | 2009-05-28 16:07:06 +0200 | [diff] [blame] | 949 | |
Max Reitz | 8bc584f | 2019-10-11 17:28:06 +0200 | [diff] [blame] | 950 | int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, |
| 951 | BdrvCheckResult *result, |
| 952 | BdrvCheckMode fix); |
Max Reitz | fe446b5 | 2019-10-11 17:28:07 +0200 | [diff] [blame] | 953 | int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs, |
| 954 | BdrvCheckResult *result, |
| 955 | BdrvCheckMode fix); |
Max Reitz | 8bc584f | 2019-10-11 17:28:06 +0200 | [diff] [blame] | 956 | |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 957 | /* qcow2-cache.c functions */ |
Alberto Garcia | 1221fe6 | 2018-02-05 16:33:36 +0200 | [diff] [blame] | 958 | Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables, |
| 959 | unsigned table_size); |
Alberto Garcia | e64d407 | 2018-02-05 16:33:08 +0200 | [diff] [blame] | 960 | int qcow2_cache_destroy(Qcow2Cache *c); |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 961 | |
Alberto Garcia | 2d135ee | 2018-02-05 16:33:06 +0200 | [diff] [blame] | 962 | void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table); |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 963 | int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c); |
Denis V. Lunev | f3c3b87 | 2016-06-02 18:58:15 +0300 | [diff] [blame] | 964 | int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c); |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 965 | int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c, |
| 966 | Qcow2Cache *dependency); |
Kevin Wolf | 3de0a29 | 2011-01-14 15:55:38 +0100 | [diff] [blame] | 967 | void qcow2_cache_depends_on_flush(Qcow2Cache *c); |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 968 | |
Alberto Garcia | b2f68bf | 2018-02-05 16:33:09 +0200 | [diff] [blame] | 969 | void qcow2_cache_clean_unused(Qcow2Cache *c); |
Max Reitz | e7108fe | 2013-09-03 10:09:51 +0200 | [diff] [blame] | 970 | int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c); |
| 971 | |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 972 | int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, |
| 973 | void **table); |
| 974 | int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, |
| 975 | void **table); |
Alberto Garcia | 2013c3d | 2018-02-05 16:33:07 +0200 | [diff] [blame] | 976 | void qcow2_cache_put(Qcow2Cache *c, void **table); |
Alberto Garcia | 6e6fa76 | 2018-02-05 16:33:11 +0200 | [diff] [blame] | 977 | void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64_t offset); |
Alberto Garcia | 77aadd7 | 2018-02-05 16:33:10 +0200 | [diff] [blame] | 978 | void qcow2_cache_discard(Qcow2Cache *c, void *table); |
Kevin Wolf | 4938109 | 2011-01-10 17:15:10 +0100 | [diff] [blame] | 979 | |
Vladimir Sementsov-Ogievskiy | 88ddffa | 2017-06-28 15:05:08 +0300 | [diff] [blame] | 980 | /* qcow2-bitmap.c functions */ |
| 981 | int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res, |
| 982 | void **refcount_table, |
| 983 | int64_t *refcount_table_size); |
Vladimir Sementsov-Ogievskiy | 0c1e9d2 | 2021-02-02 15:49:51 +0300 | [diff] [blame] | 984 | bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, bool *header_updated, |
| 985 | Error **errp); |
Vladimir Sementsov-Ogievskiy | 83bad8c | 2021-02-02 15:49:50 +0300 | [diff] [blame] | 986 | bool qcow2_get_bitmap_info_list(BlockDriverState *bs, |
| 987 | Qcow2BitmapInfoList **info_list, Error **errp); |
Vladimir Sementsov-Ogievskiy | 1b6b056 | 2017-06-28 15:05:14 +0300 | [diff] [blame] | 988 | int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); |
John Snow | d19c6b3 | 2019-03-11 21:51:46 +0300 | [diff] [blame] | 989 | int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp); |
Vladimir Sementsov-Ogievskiy | 526e31d | 2021-02-02 15:49:52 +0300 | [diff] [blame] | 990 | bool qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, |
Vladimir Sementsov-Ogievskiy | 644ddbb | 2019-09-27 15:23:52 +0300 | [diff] [blame] | 991 | bool release_stored, Error **errp); |
Vladimir Sementsov-Ogievskiy | 169b879 | 2017-06-28 15:05:20 +0300 | [diff] [blame] | 992 | int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); |
Vladimir Sementsov-Ogievskiy | d2c3080 | 2019-09-20 11:25:43 +0300 | [diff] [blame] | 993 | bool qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs, |
| 994 | const char *name, |
| 995 | uint32_t granularity, |
Vladimir Sementsov-Ogievskiy | b56a1e3 | 2019-09-20 11:25:42 +0300 | [diff] [blame] | 996 | Error **errp); |
Vladimir Sementsov-Ogievskiy | d2c3080 | 2019-09-20 11:25:43 +0300 | [diff] [blame] | 997 | int qcow2_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, |
| 998 | const char *name, |
| 999 | Error **errp); |
Eric Blake | ef893b5 | 2020-05-12 20:16:42 -0500 | [diff] [blame] | 1000 | bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs); |
Eric Blake | 5d72c68 | 2020-05-21 14:21:34 -0500 | [diff] [blame] | 1001 | uint64_t qcow2_get_persistent_dirty_bitmap_size(BlockDriverState *bs, |
| 1002 | uint32_t cluster_size); |
Vladimir Sementsov-Ogievskiy | d1258dd | 2017-06-28 15:05:11 +0300 | [diff] [blame] | 1003 | |
Vladimir Sementsov-Ogievskiy | 56e2f1d | 2019-05-06 17:27:35 +0300 | [diff] [blame] | 1004 | ssize_t coroutine_fn |
| 1005 | qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size, |
| 1006 | const void *src, size_t src_size); |
| 1007 | ssize_t coroutine_fn |
| 1008 | qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size, |
| 1009 | const void *src, size_t src_size); |
Vladimir Sementsov-Ogievskiy | 8ac0f15 | 2019-05-06 17:27:41 +0300 | [diff] [blame] | 1010 | int coroutine_fn |
Maxim Levitsky | 603fbd0 | 2019-09-15 23:36:54 +0300 | [diff] [blame] | 1011 | qcow2_co_encrypt(BlockDriverState *bs, uint64_t host_offset, |
| 1012 | uint64_t guest_offset, void *buf, size_t len); |
Vladimir Sementsov-Ogievskiy | 8ac0f15 | 2019-05-06 17:27:41 +0300 | [diff] [blame] | 1013 | int coroutine_fn |
Maxim Levitsky | 603fbd0 | 2019-09-15 23:36:54 +0300 | [diff] [blame] | 1014 | qcow2_co_decrypt(BlockDriverState *bs, uint64_t host_offset, |
| 1015 | uint64_t guest_offset, void *buf, size_t len); |
Vladimir Sementsov-Ogievskiy | 56e2f1d | 2019-05-06 17:27:35 +0300 | [diff] [blame] | 1016 | |
Kevin Wolf | f7d0fe0 | 2009-05-28 16:07:04 +0200 | [diff] [blame] | 1017 | #endif |