master
h 1,086 lines 37.2 KB
Raw
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
28 #include "crypto/block.h"
29 #include "qemu/bswap.h"
30 #include "qemu/coroutine.h"
31 #include "qemu/units.h"
32 #include "block/block_int.h"
33
34 //#define DEBUG_ALLOC
35 //#define DEBUG_ALLOC2
36 //#define DEBUG_EXT
37
38 #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
39
40 #define QCOW_CRYPT_NONE 0
41 #define QCOW_CRYPT_AES 1
42 #define QCOW_CRYPT_LUKS 2
43
44 #define QCOW_MAX_CRYPT_CLUSTERS 32
45 #define QCOW_MAX_SNAPSHOTS 65536
46
47 /* Field widths in qcow2 mean normal cluster offsets cannot reach
48 * 64PB; depending on cluster size, compressed clusters can have a
49 * smaller limit (64PB for up to 16k clusters, then ramps down to
50 * 512TB for 2M clusters). */
51 #define QCOW_MAX_CLUSTER_OFFSET ((1ULL << 56) - 1)
52
53 /* 8 MB refcount table is enough for 2 PB images at 64k cluster size
54 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
55 #define QCOW_MAX_REFTABLE_SIZE (8 * MiB)
56
57 /* 32 MB L1 table is enough for 2 PB images at 64k cluster size
58 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
59 #define QCOW_MAX_L1_SIZE (32 * MiB)
60
61 /* Allow for an average of 1k per snapshot table entry, should be plenty of
62 * space for snapshot names and IDs */
63 #define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
64
65 /* Maximum amount of extra data per snapshot table entry to accept */
66 #define QCOW_MAX_SNAPSHOT_EXTRA_DATA 1024
67
68 /* Bitmap header extension constraints */
69 #define QCOW2_MAX_BITMAPS 65535
70 #define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS)
71
72 /* Maximum of parallel sub-request per guest request */
73 #define QCOW2_MAX_WORKERS 8
74
75 /* indicate that the refcount of the referenced cluster is exactly one. */
76 #define QCOW_OFLAG_COPIED (1ULL << 63)
77 /* indicate that the cluster is compressed (they never have the copied flag) */
78 #define QCOW_OFLAG_COMPRESSED (1ULL << 62)
79 /* The cluster reads as all zeros */
80 #define QCOW_OFLAG_ZERO (1ULL << 0)
81
82 #define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32
83
84 /* The subcluster X [0..31] is allocated */
85 #define QCOW_OFLAG_SUB_ALLOC(X) (1ULL << (X))
86 /* The subcluster X [0..31] reads as zeroes */
87 #define QCOW_OFLAG_SUB_ZERO(X) (QCOW_OFLAG_SUB_ALLOC(X) << 32)
88 /* Subclusters [X, Y) (0 <= X <= Y <= 32) are allocated */
89 #define QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) \
90 (QCOW_OFLAG_SUB_ALLOC(Y) - QCOW_OFLAG_SUB_ALLOC(X))
91 /* Subclusters [X, Y) (0 <= X <= Y <= 32) read as zeroes */
92 #define QCOW_OFLAG_SUB_ZERO_RANGE(X, Y) \
93 (QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) << 32)
94 /* L2 entry bitmap with all allocation bits set */
95 #define QCOW_L2_BITMAP_ALL_ALLOC (QCOW_OFLAG_SUB_ALLOC_RANGE(0, 32))
96 /* L2 entry bitmap with all "read as zeroes" bits set */
97 #define QCOW_L2_BITMAP_ALL_ZEROES (QCOW_OFLAG_SUB_ZERO_RANGE(0, 32))
98
99 /* Size of normal and extended L2 entries */
100 #define L2E_SIZE_NORMAL (sizeof(uint64_t))
101 #define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2)
102
103 /* Size of L1 table entries */
104 #define L1E_SIZE (sizeof(uint64_t))
105
106 /* Size of reftable entries */
107 #define REFTABLE_ENTRY_SIZE (sizeof(uint64_t))
108
109 #define MIN_CLUSTER_BITS 9
110 #define MAX_CLUSTER_BITS 21
111
112 /* Defined in the qcow2 spec (compressed cluster descriptor) */
113 #define QCOW2_COMPRESSED_SECTOR_SIZE 512U
114
115 /* Must be at least 2 to cover COW */
116 #define MIN_L2_CACHE_SIZE 2 /* cache entries */
117
118 /* Must be at least 4 to cover all cases of refcount table growth */
119 #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
120
121 #ifdef CONFIG_LINUX
122 #define DEFAULT_L2_CACHE_MAX_SIZE (32 * MiB)
123 #define DEFAULT_CACHE_CLEAN_INTERVAL 600 /* seconds */
124 #else
125 #define DEFAULT_L2_CACHE_MAX_SIZE (8 * MiB)
126 /* Cache clean interval is currently available only on Linux, so must be 0 */
127 #define DEFAULT_CACHE_CLEAN_INTERVAL 0
128 #endif
129
130 #define DEFAULT_CLUSTER_SIZE 65536
131
132 #define QCOW2_OPT_DATA_FILE "data-file"
133 #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
134 #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
135 #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
136 #define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
137 #define QCOW2_OPT_DISCARD_NO_UNREF "discard-no-unref"
138 #define QCOW2_OPT_OVERLAP "overlap-check"
139 #define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
140 #define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
141 #define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
142 #define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
143 #define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
144 #define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
145 #define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
146 #define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
147 #define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
148 #define QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY "overlap-check.bitmap-directory"
149 #define QCOW2_OPT_CACHE_SIZE "cache-size"
150 #define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
151 #define QCOW2_OPT_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size"
152 #define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
153 #define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
154
155 typedef struct QCowHeader {
156 uint32_t magic;
157 uint32_t version;
158 uint64_t backing_file_offset;
159 uint32_t backing_file_size;
160 uint32_t cluster_bits;
161 uint64_t size; /* in bytes */
162 uint32_t crypt_method;
163 uint32_t l1_size; /* XXX: save number of clusters instead ? */
164 uint64_t l1_table_offset;
165 uint64_t refcount_table_offset;
166 uint32_t refcount_table_clusters;
167 uint32_t nb_snapshots;
168 uint64_t snapshots_offset;
169
170 /* The following fields are only valid for version >= 3 */
171 uint64_t incompatible_features;
172 uint64_t compatible_features;
173 uint64_t autoclear_features;
174
175 uint32_t refcount_order;
176 uint32_t header_length;
177
178 /* Additional fields */
179 uint8_t compression_type;
180
181 /* header must be a multiple of 8 */
182 uint8_t padding[7];
183 } QEMU_PACKED QCowHeader;
184
185 QEMU_BUILD_BUG_ON(!QEMU_IS_ALIGNED(sizeof(QCowHeader), 8));
186
187 typedef struct QEMU_PACKED QCowSnapshotHeader {
188 /* header is 8 byte aligned */
189 uint64_t l1_table_offset;
190
191 uint32_t l1_size;
192 uint16_t id_str_size;
193 uint16_t name_size;
194
195 uint32_t date_sec;
196 uint32_t date_nsec;
197
198 uint64_t vm_clock_nsec;
199
200 uint32_t vm_state_size;
201 uint32_t extra_data_size; /* for extension */
202 /* extra data follows */
203 /* id_str follows */
204 /* name follows */
205 } QCowSnapshotHeader;
206
207 typedef struct QEMU_PACKED QCowSnapshotExtraData {
208 uint64_t vm_state_size_large;
209 uint64_t disk_size;
210 uint64_t icount;
211 } QCowSnapshotExtraData;
212
213
214 typedef struct QCowSnapshot {
215 uint64_t l1_table_offset;
216 uint32_t l1_size;
217 char *id_str;
218 char *name;
219 uint64_t disk_size;
220 uint64_t vm_state_size;
221 uint32_t date_sec;
222 uint32_t date_nsec;
223 uint64_t vm_clock_nsec;
224 /* icount value for the moment when snapshot was taken */
225 uint64_t icount;
226 /* Size of all extra data, including QCowSnapshotExtraData if available */
227 uint32_t extra_data_size;
228 /* Data beyond QCowSnapshotExtraData, if any */
229 void *unknown_extra_data;
230 } QCowSnapshot;
231
232 struct Qcow2Cache;
233 typedef struct Qcow2Cache Qcow2Cache;
234
235 typedef struct Qcow2CryptoHeaderExtension {
236 uint64_t offset;
237 uint64_t length;
238 } QEMU_PACKED Qcow2CryptoHeaderExtension;
239
240 typedef struct Qcow2UnknownHeaderExtension {
241 uint32_t magic;
242 uint32_t len;
243 QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
244 uint8_t data[];
245 } Qcow2UnknownHeaderExtension;
246
247 enum {
248 QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
249 QCOW2_FEAT_TYPE_COMPATIBLE = 1,
250 QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
251 };
252
253 /* Incompatible feature bits */
254 enum {
255 QCOW2_INCOMPAT_DIRTY_BITNR = 0,
256 QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
257 QCOW2_INCOMPAT_DATA_FILE_BITNR = 2,
258 QCOW2_INCOMPAT_COMPRESSION_BITNR = 3,
259 QCOW2_INCOMPAT_EXTL2_BITNR = 4,
260 QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
261 QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
262 QCOW2_INCOMPAT_DATA_FILE = 1 << QCOW2_INCOMPAT_DATA_FILE_BITNR,
263 QCOW2_INCOMPAT_COMPRESSION = 1 << QCOW2_INCOMPAT_COMPRESSION_BITNR,
264 QCOW2_INCOMPAT_EXTL2 = 1 << QCOW2_INCOMPAT_EXTL2_BITNR,
265
266 QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY
267 | QCOW2_INCOMPAT_CORRUPT
268 | QCOW2_INCOMPAT_DATA_FILE
269 | QCOW2_INCOMPAT_COMPRESSION
270 | QCOW2_INCOMPAT_EXTL2,
271 };
272
273 /* Compatible feature bits */
274 enum {
275 QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
276 QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
277
278 QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS,
279 };
280
281 /* Autoclear feature bits */
282 enum {
283 QCOW2_AUTOCLEAR_BITMAPS_BITNR = 0,
284 QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR = 1,
285 QCOW2_AUTOCLEAR_BITMAPS = 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR,
286 QCOW2_AUTOCLEAR_DATA_FILE_RAW = 1 << QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR,
287
288 QCOW2_AUTOCLEAR_MASK = QCOW2_AUTOCLEAR_BITMAPS
289 | QCOW2_AUTOCLEAR_DATA_FILE_RAW,
290 };
291
292 enum qcow2_discard_type {
293 QCOW2_DISCARD_NEVER = 0,
294 QCOW2_DISCARD_ALWAYS,
295 QCOW2_DISCARD_REQUEST,
296 QCOW2_DISCARD_SNAPSHOT,
297 QCOW2_DISCARD_OTHER,
298 QCOW2_DISCARD_MAX
299 };
300
301 typedef struct Qcow2Feature {
302 uint8_t type;
303 uint8_t bit;
304 char name[46];
305 } QEMU_PACKED Qcow2Feature;
306
307 typedef struct Qcow2DiscardRegion {
308 BlockDriverState *bs;
309 uint64_t offset;
310 uint64_t bytes;
311 QTAILQ_ENTRY(Qcow2DiscardRegion) next;
312 } Qcow2DiscardRegion;
313
314 typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
315 uint64_t index);
316 typedef void Qcow2SetRefcountFunc(void *refcount_array,
317 uint64_t index, uint64_t value);
318
319 typedef struct Qcow2BitmapHeaderExt {
320 uint32_t nb_bitmaps;
321 uint32_t reserved32;
322 uint64_t bitmap_directory_size;
323 uint64_t bitmap_directory_offset;
324 } QEMU_PACKED Qcow2BitmapHeaderExt;
325
326 #define QCOW2_MAX_THREADS 4
327
328 typedef struct BDRVQcow2State {
329 int cluster_bits;
330 int cluster_size;
331 int l2_slice_size;
332 int subcluster_bits;
333 int subcluster_size;
334 int subclusters_per_cluster;
335 int l2_bits;
336 int l2_size;
337 int l1_size;
338 int l1_vm_state_index;
339 int refcount_block_bits;
340 int refcount_block_size;
341 int csize_shift;
342 int csize_mask;
343 uint64_t cluster_offset_mask;
344 uint64_t l1_table_offset;
345 uint64_t *l1_table;
346
347 Qcow2Cache *l2_table_cache;
348 Qcow2Cache *refcount_block_cache;
349 /* Non-NULL while the timer is running */
350 Coroutine *cache_clean_timer_co;
351 unsigned cache_clean_interval;
352 QemuCoSleep cache_clean_timer_wake;
353 CoQueue cache_clean_timer_exit;
354
355 QLIST_HEAD(, QCowL2Meta) cluster_allocs;
356
357 uint64_t *refcount_table;
358 uint64_t refcount_table_offset;
359 uint32_t refcount_table_size;
360 uint32_t max_refcount_table_index; /* Last used entry in refcount_table */
361 uint64_t free_cluster_index;
362 uint64_t free_byte_offset;
363
364 CoMutex lock;
365
366 Qcow2CryptoHeaderExtension crypto_header; /* QCow2 header extension */
367 QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime options */
368 QCryptoBlock *crypto; /* Disk encryption format driver */
369 bool crypt_physical_offset; /* Whether to use virtual or physical offset
370 for encryption initialization vector tweak */
371 uint32_t crypt_method_header;
372 uint64_t snapshots_offset;
373 int snapshots_size;
374 unsigned int nb_snapshots;
375 QCowSnapshot *snapshots;
376
377 uint32_t nb_bitmaps;
378 uint64_t bitmap_directory_size;
379 uint64_t bitmap_directory_offset;
380
381 int flags;
382 int qcow_version;
383 bool use_lazy_refcounts;
384 int refcount_order;
385 int refcount_bits;
386 uint64_t refcount_max;
387
388 Qcow2GetRefcountFunc *get_refcount;
389 Qcow2SetRefcountFunc *set_refcount;
390
391 bool discard_passthrough[QCOW2_DISCARD_MAX];
392
393 bool discard_no_unref;
394
395 int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
396 bool signaled_corruption;
397
398 uint64_t incompatible_features;
399 uint64_t compatible_features;
400 uint64_t autoclear_features;
401
402 size_t unknown_header_fields_size;
403 void *unknown_header_fields;
404 QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
405 QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
406 bool cache_discards;
407
408 /* Backing file path and format as stored in the image (this is not the
409 * effective path/format, which may be the result of a runtime option
410 * override) */
411 char *image_backing_file;
412 char *image_backing_format;
413 char *image_data_file;
414
415 CoQueue thread_task_queue;
416 int nb_threads;
417
418 BdrvChild *data_file;
419
420 bool metadata_preallocation_checked;
421 bool metadata_preallocation;
422 /*
423 * Compression type used for the image. Default: 0 - ZLIB
424 * The image compression type is set on image creation.
425 * For now, the only way to change the compression type
426 * is to convert the image with the desired compression type set.
427 */
428 Qcow2CompressionType compression_type;
429 } BDRVQcow2State;
430
431 typedef struct Qcow2COWRegion {
432 /**
433 * Offset of the COW region in bytes from the start of the first cluster
434 * touched by the request.
435 */
436 unsigned offset;
437
438 /** Number of bytes to copy */
439 unsigned nb_bytes;
440 } Qcow2COWRegion;
441
442 /**
443 * Describes an in-flight (part of a) write request that writes to clusters
444 * that need to have their L2 table entries updated (because they are
445 * newly allocated or need changes in their L2 bitmaps)
446 */
447 typedef struct QCowL2Meta
448 {
449 /** Guest offset of the first updated cluster */
450 uint64_t offset;
451
452 /** Host offset of the first updated cluster */
453 uint64_t alloc_offset;
454
455 /** Number of updated clusters */
456 int nb_clusters;
457
458 /** Do not free the old clusters */
459 bool keep_old_clusters;
460
461 /**
462 * Requests that overlap with this allocation and wait to be restarted
463 * when the allocating request has completed.
464 */
465 CoQueue dependent_requests;
466
467 /**
468 * The COW Region immediately before the area the guest actually
469 * writes to. This (part of the) write request starts at
470 * cow_start.offset + cow_start.nb_bytes.
471 */
472 Qcow2COWRegion cow_start;
473
474 /**
475 * The COW Region immediately after the area the guest actually
476 * writes to. This (part of the) write request ends at cow_end.offset
477 * (which must always be set even when cow_end.nb_bytes is 0).
478 */
479 Qcow2COWRegion cow_end;
480
481 /*
482 * Indicates that COW regions are already handled and do not require
483 * any more processing.
484 */
485 bool skip_cow;
486
487 /**
488 * Indicates that this is not a normal write request but a preallocation.
489 * If the image has extended L2 entries this means that no new individual
490 * subclusters will be marked as allocated in the L2 bitmap (but any
491 * existing contents of that bitmap will be kept).
492 */
493 bool prealloc;
494
495 /**
496 * The I/O vector with the data from the actual guest write request.
497 * If non-NULL, this is meant to be merged together with the data
498 * from @cow_start and @cow_end into one single write operation.
499 */
500 QEMUIOVector *data_qiov;
501 size_t data_qiov_offset;
502
503 /** Pointer to next L2Meta of the same write request */
504 struct QCowL2Meta *next;
505
506 QLIST_ENTRY(QCowL2Meta) next_in_flight;
507 } QCowL2Meta;
508
509 /*
510 * In images with standard L2 entries all clusters are treated as if
511 * they had one subcluster so QCow2ClusterType and QCow2SubclusterType
512 * can be mapped to each other and have the exact same meaning
513 * (QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC cannot happen in these images).
514 *
515 * In images with extended L2 entries QCow2ClusterType refers to the
516 * complete cluster and QCow2SubclusterType to each of the individual
517 * subclusters, so there are several possible combinations:
518 *
519 * |--------------+---------------------------|
520 * | Cluster type | Possible subcluster types |
521 * |--------------+---------------------------|
522 * | UNALLOCATED | UNALLOCATED_PLAIN |
523 * | | ZERO_PLAIN |
524 * |--------------+---------------------------|
525 * | NORMAL | UNALLOCATED_ALLOC |
526 * | | ZERO_ALLOC |
527 * | | NORMAL |
528 * |--------------+---------------------------|
529 * | COMPRESSED | COMPRESSED |
530 * |--------------+---------------------------|
531 *
532 * QCOW2_SUBCLUSTER_INVALID means that the L2 entry is incorrect and
533 * the image should be marked corrupt.
534 */
535
536 typedef enum QCow2ClusterType {
537 QCOW2_CLUSTER_UNALLOCATED,
538 QCOW2_CLUSTER_ZERO_PLAIN,
539 QCOW2_CLUSTER_ZERO_ALLOC,
540 QCOW2_CLUSTER_NORMAL,
541 QCOW2_CLUSTER_COMPRESSED,
542 } QCow2ClusterType;
543
544 typedef enum QCow2SubclusterType {
545 QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN,
546 QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC,
547 QCOW2_SUBCLUSTER_ZERO_PLAIN,
548 QCOW2_SUBCLUSTER_ZERO_ALLOC,
549 QCOW2_SUBCLUSTER_NORMAL,
550 QCOW2_SUBCLUSTER_COMPRESSED,
551 QCOW2_SUBCLUSTER_INVALID,
552 } QCow2SubclusterType;
553
554 typedef enum QCow2MetadataOverlap {
555 QCOW2_OL_MAIN_HEADER_BITNR = 0,
556 QCOW2_OL_ACTIVE_L1_BITNR = 1,
557 QCOW2_OL_ACTIVE_L2_BITNR = 2,
558 QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
559 QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
560 QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
561 QCOW2_OL_INACTIVE_L1_BITNR = 6,
562 QCOW2_OL_INACTIVE_L2_BITNR = 7,
563 QCOW2_OL_BITMAP_DIRECTORY_BITNR = 8,
564
565 QCOW2_OL_MAX_BITNR = 9,
566
567 QCOW2_OL_NONE = 0,
568 QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
569 QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
570 QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
571 QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
572 QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
573 QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
574 QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
575 /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
576 * reads. */
577 QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
578 QCOW2_OL_BITMAP_DIRECTORY = (1 << QCOW2_OL_BITMAP_DIRECTORY_BITNR),
579 } QCow2MetadataOverlap;
580
581 /* Perform all overlap checks which can be done in constant time */
582 #define QCOW2_OL_CONSTANT \
583 (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
584 QCOW2_OL_SNAPSHOT_TABLE | QCOW2_OL_BITMAP_DIRECTORY)
585
586 /* Perform all overlap checks which don't require disk access */
587 #define QCOW2_OL_CACHED \
588 (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
589 QCOW2_OL_INACTIVE_L1)
590
591 /* Perform all overlap checks */
592 #define QCOW2_OL_ALL \
593 (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
594
595 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
596 #define L1E_RESERVED_MASK 0x7f000000000001ffULL
597 #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
598 #define L2E_STD_RESERVED_MASK 0x3f000000000001feULL
599
600 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
601 #define REFT_RESERVED_MASK 0x1ffULL
602
603 #define INV_OFFSET (-1ULL)
604
605 static inline bool has_subclusters(BDRVQcow2State *s)
606 {
607 return s->incompatible_features & QCOW2_INCOMPAT_EXTL2;
608 }
609
610 static inline size_t l2_entry_size(BDRVQcow2State *s)
611 {
612 return has_subclusters(s) ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL;
613 }
614
615 static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice,
616 int idx)
617 {
618 idx *= l2_entry_size(s) / sizeof(uint64_t);
619 return be64_to_cpu(l2_slice[idx]);
620 }
621
622 static inline uint64_t get_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice,
623 int idx)
624 {
625 if (has_subclusters(s)) {
626 idx *= l2_entry_size(s) / sizeof(uint64_t);
627 return be64_to_cpu(l2_slice[idx + 1]);
628 } else {
629 return 0; /* For convenience only; this value has no meaning. */
630 }
631 }
632
633 static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice,
634 int idx, uint64_t entry)
635 {
636 idx *= l2_entry_size(s) / sizeof(uint64_t);
637 l2_slice[idx] = cpu_to_be64(entry);
638 }
639
640 static inline void set_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice,
641 int idx, uint64_t bitmap)
642 {
643 assert(has_subclusters(s));
644 idx *= l2_entry_size(s) / sizeof(uint64_t);
645 l2_slice[idx + 1] = cpu_to_be64(bitmap);
646 }
647
648 static inline bool GRAPH_RDLOCK has_data_file(BlockDriverState *bs)
649 {
650 BDRVQcow2State *s = bs->opaque;
651 return (s->data_file != bs->file);
652 }
653
654 static inline bool data_file_is_raw(BlockDriverState *bs)
655 {
656 BDRVQcow2State *s = bs->opaque;
657 return !!(s->autoclear_features & QCOW2_AUTOCLEAR_DATA_FILE_RAW);
658 }
659
660 static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset)
661 {
662 return offset & ~(s->cluster_size - 1);
663 }
664
665 static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
666 {
667 return offset & (s->cluster_size - 1);
668 }
669
670 static inline int64_t offset_into_subcluster(BDRVQcow2State *s, int64_t offset)
671 {
672 return offset & (s->subcluster_size - 1);
673 }
674
675 static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
676 {
677 return (size + (s->cluster_size - 1)) >> s->cluster_bits;
678 }
679
680 static inline uint64_t size_to_subclusters(BDRVQcow2State *s, uint64_t size)
681 {
682 return (size + (s->subcluster_size - 1)) >> s->subcluster_bits;
683 }
684
685 static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size)
686 {
687 int shift = s->cluster_bits + s->l2_bits;
688 return (size + (1ULL << shift) - 1) >> shift;
689 }
690
691 static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset)
692 {
693 return offset >> (s->l2_bits + s->cluster_bits);
694 }
695
696 static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
697 {
698 return (offset >> s->cluster_bits) & (s->l2_size - 1);
699 }
700
701 static inline int offset_to_l2_slice_index(BDRVQcow2State *s, int64_t offset)
702 {
703 return (offset >> s->cluster_bits) & (s->l2_slice_size - 1);
704 }
705
706 static inline int offset_to_sc_index(BDRVQcow2State *s, int64_t offset)
707 {
708 return (offset >> s->subcluster_bits) & (s->subclusters_per_cluster - 1);
709 }
710
711 static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)
712 {
713 return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
714 }
715
716 static inline QCow2ClusterType GRAPH_RDLOCK
717 qcow2_get_cluster_type(BlockDriverState *bs, uint64_t l2_entry)
718 {
719 BDRVQcow2State *s = bs->opaque;
720
721 if (l2_entry & QCOW_OFLAG_COMPRESSED) {
722 return QCOW2_CLUSTER_COMPRESSED;
723 } else if ((l2_entry & QCOW_OFLAG_ZERO) && !has_subclusters(s)) {
724 if (l2_entry & L2E_OFFSET_MASK) {
725 return QCOW2_CLUSTER_ZERO_ALLOC;
726 }
727 return QCOW2_CLUSTER_ZERO_PLAIN;
728 } else if (!(l2_entry & L2E_OFFSET_MASK)) {
729 /* Offset 0 generally means unallocated, but it is ambiguous with
730 * external data files because 0 is a valid offset there. However, all
731 * clusters in external data files always have refcount 1, so we can
732 * rely on QCOW_OFLAG_COPIED to disambiguate. */
733 if (has_data_file(bs) && (l2_entry & QCOW_OFLAG_COPIED)) {
734 return QCOW2_CLUSTER_NORMAL;
735 } else {
736 return QCOW2_CLUSTER_UNALLOCATED;
737 }
738 } else {
739 return QCOW2_CLUSTER_NORMAL;
740 }
741 }
742
743 /*
744 * In an image without subsclusters @l2_bitmap is ignored and
745 * @sc_index must be 0.
746 * Return QCOW2_SUBCLUSTER_INVALID if an invalid l2 entry is detected
747 * (this checks the whole entry and bitmap, not only the bits related
748 * to subcluster @sc_index).
749 */
750 static inline GRAPH_RDLOCK
751 QCow2SubclusterType qcow2_get_subcluster_type(BlockDriverState *bs,
752 uint64_t l2_entry,
753 uint64_t l2_bitmap,
754 unsigned sc_index)
755 {
756 BDRVQcow2State *s = bs->opaque;
757 QCow2ClusterType type = qcow2_get_cluster_type(bs, l2_entry);
758 assert(sc_index < s->subclusters_per_cluster);
759
760 if (has_subclusters(s)) {
761 switch (type) {
762 case QCOW2_CLUSTER_COMPRESSED:
763 return QCOW2_SUBCLUSTER_COMPRESSED;
764 case QCOW2_CLUSTER_NORMAL:
765 if ((l2_bitmap >> 32) & l2_bitmap) {
766 return QCOW2_SUBCLUSTER_INVALID;
767 } else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) {
768 return QCOW2_SUBCLUSTER_ZERO_ALLOC;
769 } else if (l2_bitmap & QCOW_OFLAG_SUB_ALLOC(sc_index)) {
770 return QCOW2_SUBCLUSTER_NORMAL;
771 } else {
772 return QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC;
773 }
774 case QCOW2_CLUSTER_UNALLOCATED:
775 if (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC) {
776 return QCOW2_SUBCLUSTER_INVALID;
777 } else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) {
778 return QCOW2_SUBCLUSTER_ZERO_PLAIN;
779 } else {
780 return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;
781 }
782 default:
783 g_assert_not_reached();
784 }
785 } else {
786 switch (type) {
787 case QCOW2_CLUSTER_COMPRESSED:
788 return QCOW2_SUBCLUSTER_COMPRESSED;
789 case QCOW2_CLUSTER_ZERO_PLAIN:
790 return QCOW2_SUBCLUSTER_ZERO_PLAIN;
791 case QCOW2_CLUSTER_ZERO_ALLOC:
792 return QCOW2_SUBCLUSTER_ZERO_ALLOC;
793 case QCOW2_CLUSTER_NORMAL:
794 return QCOW2_SUBCLUSTER_NORMAL;
795 case QCOW2_CLUSTER_UNALLOCATED:
796 return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;
797 default:
798 g_assert_not_reached();
799 }
800 }
801 }
802
803 static inline bool qcow2_cluster_is_allocated(QCow2ClusterType type)
804 {
805 return (type == QCOW2_CLUSTER_COMPRESSED || type == QCOW2_CLUSTER_NORMAL ||
806 type == QCOW2_CLUSTER_ZERO_ALLOC);
807 }
808
809 /* Check whether refcounts are eager or lazy */
810 static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)
811 {
812 return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
813 }
814
815 static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
816 {
817 return m->offset + m->cow_start.offset;
818 }
819
820 static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
821 {
822 return m->offset + m->cow_end.offset + m->cow_end.nb_bytes;
823 }
824
825 static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
826 {
827 return r1 > r2 ? r1 - r2 : r2 - r1;
828 }
829
830 static inline
831 uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset)
832 {
833 return offset >> (s->refcount_block_bits + s->cluster_bits);
834 }
835
836 /* qcow2.c functions */
837 int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
838 int refcount_order, bool generous_increase,
839 uint64_t *refblock_count);
840
841 int GRAPH_RDLOCK qcow2_mark_dirty(BlockDriverState *bs);
842 int GRAPH_RDLOCK qcow2_mark_corrupt(BlockDriverState *bs);
843 int GRAPH_RDLOCK qcow2_update_header(BlockDriverState *bs);
844
845 void GRAPH_RDLOCK
846 qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
847 int64_t size, const char *message_format, ...)
848 G_GNUC_PRINTF(5, 6);
849
850 int qcow2_validate_table(BlockDriverState *bs, uint64_t offset,
851 uint64_t entries, size_t entry_len,
852 int64_t max_size_bytes, const char *table_name,
853 Error **errp);
854
855 /* qcow2-refcount.c functions */
856 int coroutine_fn GRAPH_RDLOCK qcow2_refcount_init(BlockDriverState *bs);
857 void qcow2_refcount_close(BlockDriverState *bs);
858
859 int GRAPH_RDLOCK qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
860 uint64_t *refcount);
861
862 int GRAPH_RDLOCK
863 qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
864 uint64_t addend, bool decrease,
865 enum qcow2_discard_type type);
866
867 int64_t GRAPH_RDLOCK
868 qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
869 uint64_t additional_clusters, bool exact_size,
870 int new_refblock_index,
871 uint64_t new_refblock_offset);
872
873 int64_t GRAPH_RDLOCK
874 qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
875
876 int64_t GRAPH_RDLOCK coroutine_fn
877 qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
878 int64_t nb_clusters);
879
880 int64_t coroutine_fn GRAPH_RDLOCK qcow2_alloc_bytes(BlockDriverState *bs, int size);
881 void GRAPH_RDLOCK qcow2_free_clusters(BlockDriverState *bs,
882 int64_t offset, int64_t size,
883 enum qcow2_discard_type type);
884 void GRAPH_RDLOCK
885 qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry,
886 enum qcow2_discard_type type);
887 void GRAPH_RDLOCK
888 qcow2_discard_cluster(BlockDriverState *bs, uint64_t offset,
889 uint64_t length, QCow2ClusterType ctype,
890 enum qcow2_discard_type dtype);
891
892 int GRAPH_RDLOCK
893 qcow2_update_snapshot_refcount(BlockDriverState *bs, int64_t l1_table_offset,
894 int l1_size, int addend);
895
896 int GRAPH_RDLOCK qcow2_flush_caches(BlockDriverState *bs);
897 int GRAPH_RDLOCK qcow2_write_caches(BlockDriverState *bs);
898 int coroutine_fn qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
899 BdrvCheckMode fix);
900
901 void GRAPH_RDLOCK qcow2_process_discards(BlockDriverState *bs, int ret);
902
903 int GRAPH_RDLOCK
904 qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
905 int64_t size);
906 int GRAPH_RDLOCK
907 qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
908 int64_t size, bool data_file);
909
910 int coroutine_fn qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
911 void **refcount_table,
912 int64_t *refcount_table_size,
913 int64_t offset, int64_t size);
914
915 int GRAPH_RDLOCK
916 qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
917 BlockDriverAmendStatusCB *status_cb,
918 void *cb_opaque, Error **errp);
919 int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs);
920
921 int64_t coroutine_fn GRAPH_RDLOCK
922 qcow2_get_last_cluster(BlockDriverState *bs, int64_t size);
923
924 int coroutine_fn GRAPH_RDLOCK
925 qcow2_detect_metadata_preallocation(BlockDriverState *bs);
926
927 /* qcow2-cluster.c functions */
928 int GRAPH_RDLOCK
929 qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size);
930
931 int coroutine_fn GRAPH_RDLOCK
932 qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size);
933
934 int GRAPH_RDLOCK qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
935 int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
936 uint8_t *buf, int nb_sectors, bool enc, Error **errp);
937
938 int GRAPH_RDLOCK
939 qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset,
940 unsigned int *bytes, uint64_t *host_offset,
941 QCow2SubclusterType *subcluster_type);
942
943 int coroutine_fn GRAPH_RDLOCK
944 qcow2_alloc_host_offset(BlockDriverState *bs, uint64_t offset,
945 unsigned int *bytes, uint64_t *host_offset,
946 QCowL2Meta **m);
947
948 int coroutine_fn GRAPH_RDLOCK
949 qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset,
950 int compressed_size, uint64_t *host_offset);
951 void GRAPH_RDLOCK
952 qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_entry,
953 uint64_t *coffset, int *csize);
954
955 int coroutine_fn GRAPH_RDLOCK
956 qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
957
958 void coroutine_fn GRAPH_RDLOCK
959 qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);
960
961 int GRAPH_RDLOCK
962 qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
963 enum qcow2_discard_type type, bool full_discard);
964
965 int coroutine_fn GRAPH_RDLOCK
966 qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
967 int flags);
968
969 void coroutine_mixed_fn
970 qcow2_wait_for_dependencies(BlockDriverState *bs, uint64_t guest_offset,
971 uint64_t bytes);
972
973 int GRAPH_RDLOCK
974 qcow2_expand_zero_clusters(BlockDriverState *bs,
975 BlockDriverAmendStatusCB *status_cb,
976 void *cb_opaque);
977
978 /* qcow2-snapshot.c functions */
979 int GRAPH_RDLOCK
980 qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
981
982 int GRAPH_RDLOCK
983 qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
984
985 int GRAPH_RDLOCK
986 qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id,
987 const char *name, Error **errp);
988
989 int GRAPH_RDLOCK
990 qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
991
992 int GRAPH_RDLOCK
993 qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_id,
994 const char *name, Error **errp);
995
996 void qcow2_free_snapshots(BlockDriverState *bs);
997 int coroutine_fn GRAPH_RDLOCK
998 qcow2_read_snapshots(BlockDriverState *bs, Error **errp);
999 int GRAPH_RDLOCK qcow2_write_snapshots(BlockDriverState *bs);
1000
1001 int coroutine_fn GRAPH_RDLOCK
1002 qcow2_check_read_snapshot_table(BlockDriverState *bs, BdrvCheckResult *result,
1003 BdrvCheckMode fix);
1004
1005 int coroutine_fn GRAPH_RDLOCK
1006 qcow2_check_fix_snapshot_table(BlockDriverState *bs, BdrvCheckResult *result,
1007 BdrvCheckMode fix);
1008
1009 /* qcow2-cache.c functions */
1010 Qcow2Cache * GRAPH_RDLOCK
1011 qcow2_cache_create(BlockDriverState *bs, int num_tables, unsigned table_size);
1012
1013 int qcow2_cache_destroy(Qcow2Cache *c);
1014
1015 void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
1016 int GRAPH_RDLOCK qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
1017 int GRAPH_RDLOCK qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c);
1018 int GRAPH_RDLOCK qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
1019 Qcow2Cache *dependency);
1020 void qcow2_cache_depends_on_flush(Qcow2Cache *c);
1021
1022 void qcow2_cache_clean_unused(Qcow2Cache *c);
1023 int GRAPH_RDLOCK qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
1024
1025 int GRAPH_RDLOCK
1026 qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
1027 void **table);
1028
1029 int GRAPH_RDLOCK
1030 qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
1031 void **table);
1032
1033 void qcow2_cache_put(Qcow2Cache *c, void **table);
1034 void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64_t offset);
1035 void qcow2_cache_discard(Qcow2Cache *c, void *table);
1036
1037 /* qcow2-bitmap.c functions */
1038 int coroutine_fn GRAPH_RDLOCK
1039 qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
1040 void **refcount_table,
1041 int64_t *refcount_table_size);
1042
1043 bool coroutine_fn GRAPH_RDLOCK
1044 qcow2_load_dirty_bitmaps(BlockDriverState *bs, bool *header_updated,
1045 Error **errp);
1046
1047 bool GRAPH_RDLOCK
1048 qcow2_get_bitmap_info_list(BlockDriverState *bs,
1049 Qcow2BitmapInfoList **info_list, Error **errp);
1050
1051 int GRAPH_RDLOCK qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
1052 int GRAPH_RDLOCK qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
1053
1054 int coroutine_fn GRAPH_RDLOCK
1055 qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp);
1056
1057 bool GRAPH_RDLOCK
1058 qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, bool release_stored,
1059 Error **errp);
1060
1061 bool coroutine_fn GRAPH_RDLOCK
1062 qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name,
1063 uint32_t granularity, Error **errp);
1064
1065 int coroutine_fn GRAPH_RDLOCK
1066 qcow2_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
1067 Error **errp);
1068
1069 bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs);
1070 uint64_t qcow2_get_persistent_dirty_bitmap_size(BlockDriverState *bs,
1071 uint32_t cluster_size);
1072
1073 ssize_t coroutine_fn
1074 qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
1075 const void *src, size_t src_size);
1076 ssize_t coroutine_fn
1077 qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
1078 const void *src, size_t src_size);
1079 int coroutine_fn
1080 qcow2_co_encrypt(BlockDriverState *bs, uint64_t host_offset,
1081 uint64_t guest_offset, void *buf, size_t len);
1082 int coroutine_fn
1083 qcow2_co_decrypt(BlockDriverState *bs, uint64_t host_offset,
1084 uint64_t guest_offset, void *buf, size_t len);
1085
1086 #endif