2 * Block driver for the QCOW version 2 format
4 * Copyright (c) 2004-2006 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
28 #include "crypto/block.h"
29 #include "qemu/coroutine.h"
32 //#define DEBUG_ALLOC2
35 #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
37 #define QCOW_CRYPT_NONE 0
38 #define QCOW_CRYPT_AES 1
39 #define QCOW_CRYPT_LUKS 2
41 #define QCOW_MAX_CRYPT_CLUSTERS 32
42 #define QCOW_MAX_SNAPSHOTS 65536
44 /* 8 MB refcount table is enough for 2 PB images at 64k cluster size
45 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
46 #define QCOW_MAX_REFTABLE_SIZE 0x800000
48 /* 32 MB L1 table is enough for 2 PB images at 64k cluster size
49 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
50 #define QCOW_MAX_L1_SIZE 0x2000000
52 /* Allow for an average of 1k per snapshot table entry, should be plenty of
53 * space for snapshot names and IDs */
54 #define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
56 /* Bitmap header extension constraints */
57 #define QCOW2_MAX_BITMAPS 65535
58 #define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS)
60 /* indicate that the refcount of the referenced cluster is exactly one. */
61 #define QCOW_OFLAG_COPIED (1ULL << 63)
62 /* indicate that the cluster is compressed (they never have the copied flag) */
63 #define QCOW_OFLAG_COMPRESSED (1ULL << 62)
64 /* The cluster reads as all zeros */
65 #define QCOW_OFLAG_ZERO (1ULL << 0)
67 #define MIN_CLUSTER_BITS 9
68 #define MAX_CLUSTER_BITS 21
70 /* Must be at least 2 to cover COW */
71 #define MIN_L2_CACHE_SIZE 2 /* clusters */
73 /* Must be at least 4 to cover all cases of refcount table growth */
74 #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
76 /* Whichever is more */
77 #define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */
78 #define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */
80 /* The refblock cache needs only a fourth of the L2 cache size to cover as many
82 #define DEFAULT_L2_REFCOUNT_SIZE_RATIO 4
84 #define DEFAULT_CLUSTER_SIZE 65536
87 #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
88 #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
89 #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
90 #define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
91 #define QCOW2_OPT_OVERLAP "overlap-check"
92 #define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
93 #define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
94 #define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
95 #define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
96 #define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
97 #define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
98 #define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
99 #define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
100 #define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
101 #define QCOW2_OPT_CACHE_SIZE "cache-size"
102 #define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
103 #define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
104 #define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
106 typedef struct QCowHeader
{
109 uint64_t backing_file_offset
;
110 uint32_t backing_file_size
;
111 uint32_t cluster_bits
;
112 uint64_t size
; /* in bytes */
113 uint32_t crypt_method
;
114 uint32_t l1_size
; /* XXX: save number of clusters instead ? */
115 uint64_t l1_table_offset
;
116 uint64_t refcount_table_offset
;
117 uint32_t refcount_table_clusters
;
118 uint32_t nb_snapshots
;
119 uint64_t snapshots_offset
;
121 /* The following fields are only valid for version >= 3 */
122 uint64_t incompatible_features
;
123 uint64_t compatible_features
;
124 uint64_t autoclear_features
;
126 uint32_t refcount_order
;
127 uint32_t header_length
;
128 } QEMU_PACKED QCowHeader
;
130 typedef struct QEMU_PACKED QCowSnapshotHeader
{
131 /* header is 8 byte aligned */
132 uint64_t l1_table_offset
;
135 uint16_t id_str_size
;
141 uint64_t vm_clock_nsec
;
143 uint32_t vm_state_size
;
144 uint32_t extra_data_size
; /* for extension */
145 /* extra data follows */
148 } QCowSnapshotHeader
;
150 typedef struct QEMU_PACKED QCowSnapshotExtraData
{
151 uint64_t vm_state_size_large
;
153 } QCowSnapshotExtraData
;
156 typedef struct QCowSnapshot
{
157 uint64_t l1_table_offset
;
162 uint64_t vm_state_size
;
165 uint64_t vm_clock_nsec
;
169 typedef struct Qcow2Cache Qcow2Cache
;
171 typedef struct Qcow2CryptoHeaderExtension
{
174 } QEMU_PACKED Qcow2CryptoHeaderExtension
;
176 typedef struct Qcow2UnknownHeaderExtension
{
179 QLIST_ENTRY(Qcow2UnknownHeaderExtension
) next
;
181 } Qcow2UnknownHeaderExtension
;
184 QCOW2_FEAT_TYPE_INCOMPATIBLE
= 0,
185 QCOW2_FEAT_TYPE_COMPATIBLE
= 1,
186 QCOW2_FEAT_TYPE_AUTOCLEAR
= 2,
189 /* Incompatible feature bits */
191 QCOW2_INCOMPAT_DIRTY_BITNR
= 0,
192 QCOW2_INCOMPAT_CORRUPT_BITNR
= 1,
193 QCOW2_INCOMPAT_DIRTY
= 1 << QCOW2_INCOMPAT_DIRTY_BITNR
,
194 QCOW2_INCOMPAT_CORRUPT
= 1 << QCOW2_INCOMPAT_CORRUPT_BITNR
,
196 QCOW2_INCOMPAT_MASK
= QCOW2_INCOMPAT_DIRTY
197 | QCOW2_INCOMPAT_CORRUPT
,
200 /* Compatible feature bits */
202 QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR
= 0,
203 QCOW2_COMPAT_LAZY_REFCOUNTS
= 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR
,
205 QCOW2_COMPAT_FEAT_MASK
= QCOW2_COMPAT_LAZY_REFCOUNTS
,
208 /* Autoclear feature bits */
210 QCOW2_AUTOCLEAR_BITMAPS_BITNR
= 0,
211 QCOW2_AUTOCLEAR_BITMAPS
= 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR
,
213 QCOW2_AUTOCLEAR_MASK
= QCOW2_AUTOCLEAR_BITMAPS
,
216 enum qcow2_discard_type
{
217 QCOW2_DISCARD_NEVER
= 0,
218 QCOW2_DISCARD_ALWAYS
,
219 QCOW2_DISCARD_REQUEST
,
220 QCOW2_DISCARD_SNAPSHOT
,
225 typedef struct Qcow2Feature
{
229 } QEMU_PACKED Qcow2Feature
;
231 typedef struct Qcow2DiscardRegion
{
232 BlockDriverState
*bs
;
235 QTAILQ_ENTRY(Qcow2DiscardRegion
) next
;
236 } Qcow2DiscardRegion
;
238 typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array
,
240 typedef void Qcow2SetRefcountFunc(void *refcount_array
,
241 uint64_t index
, uint64_t value
);
243 typedef struct Qcow2BitmapHeaderExt
{
246 uint64_t bitmap_directory_size
;
247 uint64_t bitmap_directory_offset
;
248 } QEMU_PACKED Qcow2BitmapHeaderExt
;
250 typedef struct BDRVQcow2State
{
257 int l1_vm_state_index
;
258 int refcount_block_bits
;
259 int refcount_block_size
;
262 uint64_t cluster_offset_mask
;
263 uint64_t l1_table_offset
;
266 Qcow2Cache
* l2_table_cache
;
267 Qcow2Cache
* refcount_block_cache
;
268 QEMUTimer
*cache_clean_timer
;
269 unsigned cache_clean_interval
;
271 uint8_t *cluster_cache
;
272 uint8_t *cluster_data
;
273 uint64_t cluster_cache_offset
;
274 QLIST_HEAD(QCowClusterAlloc
, QCowL2Meta
) cluster_allocs
;
276 uint64_t *refcount_table
;
277 uint64_t refcount_table_offset
;
278 uint32_t refcount_table_size
;
279 uint32_t max_refcount_table_index
; /* Last used entry in refcount_table */
280 uint64_t free_cluster_index
;
281 uint64_t free_byte_offset
;
285 Qcow2CryptoHeaderExtension crypto_header
; /* QCow2 header extension */
286 QCryptoBlockOpenOptions
*crypto_opts
; /* Disk encryption runtime options */
287 QCryptoBlock
*crypto
; /* Disk encryption format driver */
288 bool crypt_physical_offset
; /* Whether to use virtual or physical offset
289 for encryption initialization vector tweak */
290 uint32_t crypt_method_header
;
291 uint64_t snapshots_offset
;
293 unsigned int nb_snapshots
;
294 QCowSnapshot
*snapshots
;
297 uint64_t bitmap_directory_size
;
298 uint64_t bitmap_directory_offset
;
302 bool use_lazy_refcounts
;
305 uint64_t refcount_max
;
307 Qcow2GetRefcountFunc
*get_refcount
;
308 Qcow2SetRefcountFunc
*set_refcount
;
310 bool discard_passthrough
[QCOW2_DISCARD_MAX
];
312 int overlap_check
; /* bitmask of Qcow2MetadataOverlap values */
313 bool signaled_corruption
;
315 uint64_t incompatible_features
;
316 uint64_t compatible_features
;
317 uint64_t autoclear_features
;
319 size_t unknown_header_fields_size
;
320 void* unknown_header_fields
;
321 QLIST_HEAD(, Qcow2UnknownHeaderExtension
) unknown_header_ext
;
322 QTAILQ_HEAD (, Qcow2DiscardRegion
) discards
;
325 /* Backing file path and format as stored in the image (this is not the
326 * effective path/format, which may be the result of a runtime option
328 char *image_backing_file
;
329 char *image_backing_format
;
332 typedef struct Qcow2COWRegion
{
334 * Offset of the COW region in bytes from the start of the first cluster
335 * touched by the request.
339 /** Number of bytes to copy */
344 * Describes an in-flight (part of a) write request that writes to clusters
345 * that are not referenced in their L2 table yet.
347 typedef struct QCowL2Meta
349 /** Guest offset of the first newly allocated cluster */
352 /** Host offset of the first newly allocated cluster */
353 uint64_t alloc_offset
;
355 /** Number of newly allocated clusters */
358 /** Do not free the old clusters */
359 bool keep_old_clusters
;
362 * Requests that overlap with this allocation and wait to be restarted
363 * when the allocating request has completed.
365 CoQueue dependent_requests
;
368 * The COW Region between the start of the first allocated cluster and the
369 * area the guest actually writes to.
371 Qcow2COWRegion cow_start
;
374 * The COW Region between the area the guest actually writes to and the
375 * end of the last allocated cluster.
377 Qcow2COWRegion cow_end
;
380 * The I/O vector with the data from the actual guest write request.
381 * If non-NULL, this is meant to be merged together with the data
382 * from @cow_start and @cow_end into one single write operation.
384 QEMUIOVector
*data_qiov
;
386 /** Pointer to next L2Meta of the same write request */
387 struct QCowL2Meta
*next
;
389 QLIST_ENTRY(QCowL2Meta
) next_in_flight
;
392 typedef enum QCow2ClusterType
{
393 QCOW2_CLUSTER_UNALLOCATED
,
394 QCOW2_CLUSTER_ZERO_PLAIN
,
395 QCOW2_CLUSTER_ZERO_ALLOC
,
396 QCOW2_CLUSTER_NORMAL
,
397 QCOW2_CLUSTER_COMPRESSED
,
400 typedef enum QCow2MetadataOverlap
{
401 QCOW2_OL_MAIN_HEADER_BITNR
= 0,
402 QCOW2_OL_ACTIVE_L1_BITNR
= 1,
403 QCOW2_OL_ACTIVE_L2_BITNR
= 2,
404 QCOW2_OL_REFCOUNT_TABLE_BITNR
= 3,
405 QCOW2_OL_REFCOUNT_BLOCK_BITNR
= 4,
406 QCOW2_OL_SNAPSHOT_TABLE_BITNR
= 5,
407 QCOW2_OL_INACTIVE_L1_BITNR
= 6,
408 QCOW2_OL_INACTIVE_L2_BITNR
= 7,
410 QCOW2_OL_MAX_BITNR
= 8,
413 QCOW2_OL_MAIN_HEADER
= (1 << QCOW2_OL_MAIN_HEADER_BITNR
),
414 QCOW2_OL_ACTIVE_L1
= (1 << QCOW2_OL_ACTIVE_L1_BITNR
),
415 QCOW2_OL_ACTIVE_L2
= (1 << QCOW2_OL_ACTIVE_L2_BITNR
),
416 QCOW2_OL_REFCOUNT_TABLE
= (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR
),
417 QCOW2_OL_REFCOUNT_BLOCK
= (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR
),
418 QCOW2_OL_SNAPSHOT_TABLE
= (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR
),
419 QCOW2_OL_INACTIVE_L1
= (1 << QCOW2_OL_INACTIVE_L1_BITNR
),
420 /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
422 QCOW2_OL_INACTIVE_L2
= (1 << QCOW2_OL_INACTIVE_L2_BITNR
),
423 } QCow2MetadataOverlap
;
425 /* Perform all overlap checks which can be done in constant time */
426 #define QCOW2_OL_CONSTANT \
427 (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
428 QCOW2_OL_SNAPSHOT_TABLE)
430 /* Perform all overlap checks which don't require disk access */
431 #define QCOW2_OL_CACHED \
432 (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
433 QCOW2_OL_INACTIVE_L1)
435 /* Perform all overlap checks */
436 #define QCOW2_OL_ALL \
437 (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
439 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
440 #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
441 #define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
443 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
445 static inline int64_t start_of_cluster(BDRVQcow2State
*s
, int64_t offset
)
447 return offset
& ~(s
->cluster_size
- 1);
450 static inline int64_t offset_into_cluster(BDRVQcow2State
*s
, int64_t offset
)
452 return offset
& (s
->cluster_size
- 1);
455 static inline uint64_t size_to_clusters(BDRVQcow2State
*s
, uint64_t size
)
457 return (size
+ (s
->cluster_size
- 1)) >> s
->cluster_bits
;
460 static inline int64_t size_to_l1(BDRVQcow2State
*s
, int64_t size
)
462 int shift
= s
->cluster_bits
+ s
->l2_bits
;
463 return (size
+ (1ULL << shift
) - 1) >> shift
;
466 static inline int offset_to_l2_index(BDRVQcow2State
*s
, int64_t offset
)
468 return (offset
>> s
->cluster_bits
) & (s
->l2_size
- 1);
471 static inline int64_t align_offset(int64_t offset
, int n
)
473 offset
= (offset
+ n
- 1) & ~(n
- 1);
477 static inline int64_t qcow2_vm_state_offset(BDRVQcow2State
*s
)
479 return (int64_t)s
->l1_vm_state_index
<< (s
->cluster_bits
+ s
->l2_bits
);
482 static inline uint64_t qcow2_max_refcount_clusters(BDRVQcow2State
*s
)
484 return QCOW_MAX_REFTABLE_SIZE
>> s
->cluster_bits
;
487 static inline QCow2ClusterType
qcow2_get_cluster_type(uint64_t l2_entry
)
489 if (l2_entry
& QCOW_OFLAG_COMPRESSED
) {
490 return QCOW2_CLUSTER_COMPRESSED
;
491 } else if (l2_entry
& QCOW_OFLAG_ZERO
) {
492 if (l2_entry
& L2E_OFFSET_MASK
) {
493 return QCOW2_CLUSTER_ZERO_ALLOC
;
495 return QCOW2_CLUSTER_ZERO_PLAIN
;
496 } else if (!(l2_entry
& L2E_OFFSET_MASK
)) {
497 return QCOW2_CLUSTER_UNALLOCATED
;
499 return QCOW2_CLUSTER_NORMAL
;
503 /* Check whether refcounts are eager or lazy */
504 static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State
*s
)
506 return !(s
->incompatible_features
& QCOW2_INCOMPAT_DIRTY
);
509 static inline uint64_t l2meta_cow_start(QCowL2Meta
*m
)
511 return m
->offset
+ m
->cow_start
.offset
;
514 static inline uint64_t l2meta_cow_end(QCowL2Meta
*m
)
516 return m
->offset
+ m
->cow_end
.offset
+ m
->cow_end
.nb_bytes
;
519 static inline uint64_t refcount_diff(uint64_t r1
, uint64_t r2
)
521 return r1
> r2
? r1
- r2
: r2
- r1
;
524 /* qcow2.c functions */
525 int qcow2_backing_read1(BlockDriverState
*bs
, QEMUIOVector
*qiov
,
526 int64_t sector_num
, int nb_sectors
);
528 int64_t qcow2_refcount_metadata_size(int64_t clusters
, size_t cluster_size
,
529 int refcount_order
, bool generous_increase
,
530 uint64_t *refblock_count
);
532 int qcow2_mark_dirty(BlockDriverState
*bs
);
533 int qcow2_mark_corrupt(BlockDriverState
*bs
);
534 int qcow2_mark_consistent(BlockDriverState
*bs
);
535 int qcow2_update_header(BlockDriverState
*bs
);
537 void qcow2_signal_corruption(BlockDriverState
*bs
, bool fatal
, int64_t offset
,
538 int64_t size
, const char *message_format
, ...)
541 /* qcow2-refcount.c functions */
542 int qcow2_refcount_init(BlockDriverState
*bs
);
543 void qcow2_refcount_close(BlockDriverState
*bs
);
545 int qcow2_get_refcount(BlockDriverState
*bs
, int64_t cluster_index
,
548 int qcow2_update_cluster_refcount(BlockDriverState
*bs
, int64_t cluster_index
,
549 uint64_t addend
, bool decrease
,
550 enum qcow2_discard_type type
);
552 int64_t qcow2_alloc_clusters(BlockDriverState
*bs
, uint64_t size
);
553 int64_t qcow2_alloc_clusters_at(BlockDriverState
*bs
, uint64_t offset
,
554 int64_t nb_clusters
);
555 int64_t qcow2_alloc_bytes(BlockDriverState
*bs
, int size
);
556 void qcow2_free_clusters(BlockDriverState
*bs
,
557 int64_t offset
, int64_t size
,
558 enum qcow2_discard_type type
);
559 void qcow2_free_any_clusters(BlockDriverState
*bs
, uint64_t l2_entry
,
560 int nb_clusters
, enum qcow2_discard_type type
);
562 int qcow2_update_snapshot_refcount(BlockDriverState
*bs
,
563 int64_t l1_table_offset
, int l1_size
, int addend
);
565 int qcow2_check_refcounts(BlockDriverState
*bs
, BdrvCheckResult
*res
,
568 void qcow2_process_discards(BlockDriverState
*bs
, int ret
);
570 int qcow2_check_metadata_overlap(BlockDriverState
*bs
, int ign
, int64_t offset
,
572 int qcow2_pre_write_overlap_check(BlockDriverState
*bs
, int ign
, int64_t offset
,
574 int qcow2_inc_refcounts_imrt(BlockDriverState
*bs
, BdrvCheckResult
*res
,
575 void **refcount_table
,
576 int64_t *refcount_table_size
,
577 int64_t offset
, int64_t size
);
579 int qcow2_change_refcount_order(BlockDriverState
*bs
, int refcount_order
,
580 BlockDriverAmendStatusCB
*status_cb
,
581 void *cb_opaque
, Error
**errp
);
583 /* qcow2-cluster.c functions */
584 int qcow2_grow_l1_table(BlockDriverState
*bs
, uint64_t min_size
,
586 int qcow2_write_l1_entry(BlockDriverState
*bs
, int l1_index
);
587 int qcow2_decompress_cluster(BlockDriverState
*bs
, uint64_t cluster_offset
);
588 int qcow2_encrypt_sectors(BDRVQcow2State
*s
, int64_t sector_num
,
589 uint8_t *buf
, int nb_sectors
, bool enc
, Error
**errp
);
591 int qcow2_get_cluster_offset(BlockDriverState
*bs
, uint64_t offset
,
592 unsigned int *bytes
, uint64_t *cluster_offset
);
593 int qcow2_alloc_cluster_offset(BlockDriverState
*bs
, uint64_t offset
,
594 unsigned int *bytes
, uint64_t *host_offset
,
596 uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState
*bs
,
598 int compressed_size
);
600 int qcow2_alloc_cluster_link_l2(BlockDriverState
*bs
, QCowL2Meta
*m
);
601 int qcow2_cluster_discard(BlockDriverState
*bs
, uint64_t offset
,
602 uint64_t bytes
, enum qcow2_discard_type type
,
604 int qcow2_cluster_zeroize(BlockDriverState
*bs
, uint64_t offset
,
605 uint64_t bytes
, int flags
);
607 int qcow2_expand_zero_clusters(BlockDriverState
*bs
,
608 BlockDriverAmendStatusCB
*status_cb
,
611 /* qcow2-snapshot.c functions */
612 int qcow2_snapshot_create(BlockDriverState
*bs
, QEMUSnapshotInfo
*sn_info
);
613 int qcow2_snapshot_goto(BlockDriverState
*bs
, const char *snapshot_id
);
614 int qcow2_snapshot_delete(BlockDriverState
*bs
,
615 const char *snapshot_id
,
618 int qcow2_snapshot_list(BlockDriverState
*bs
, QEMUSnapshotInfo
**psn_tab
);
619 int qcow2_snapshot_load_tmp(BlockDriverState
*bs
,
620 const char *snapshot_id
,
624 void qcow2_free_snapshots(BlockDriverState
*bs
);
625 int qcow2_read_snapshots(BlockDriverState
*bs
);
627 /* qcow2-cache.c functions */
628 Qcow2Cache
*qcow2_cache_create(BlockDriverState
*bs
, int num_tables
);
629 int qcow2_cache_destroy(BlockDriverState
* bs
, Qcow2Cache
*c
);
631 void qcow2_cache_entry_mark_dirty(BlockDriverState
*bs
, Qcow2Cache
*c
,
633 int qcow2_cache_flush(BlockDriverState
*bs
, Qcow2Cache
*c
);
634 int qcow2_cache_write(BlockDriverState
*bs
, Qcow2Cache
*c
);
635 int qcow2_cache_set_dependency(BlockDriverState
*bs
, Qcow2Cache
*c
,
636 Qcow2Cache
*dependency
);
637 void qcow2_cache_depends_on_flush(Qcow2Cache
*c
);
639 void qcow2_cache_clean_unused(BlockDriverState
*bs
, Qcow2Cache
*c
);
640 int qcow2_cache_empty(BlockDriverState
*bs
, Qcow2Cache
*c
);
642 int qcow2_cache_get(BlockDriverState
*bs
, Qcow2Cache
*c
, uint64_t offset
,
644 int qcow2_cache_get_empty(BlockDriverState
*bs
, Qcow2Cache
*c
, uint64_t offset
,
646 void qcow2_cache_put(BlockDriverState
*bs
, Qcow2Cache
*c
, void **table
);
648 /* qcow2-bitmap.c functions */
649 int qcow2_check_bitmaps_refcounts(BlockDriverState
*bs
, BdrvCheckResult
*res
,
650 void **refcount_table
,
651 int64_t *refcount_table_size
);
652 bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState
*bs
, Error
**errp
);
653 int qcow2_reopen_bitmaps_rw(BlockDriverState
*bs
, Error
**errp
);
654 void qcow2_store_persistent_dirty_bitmaps(BlockDriverState
*bs
, Error
**errp
);
655 int qcow2_reopen_bitmaps_ro(BlockDriverState
*bs
, Error
**errp
);
656 bool qcow2_can_store_new_dirty_bitmap(BlockDriverState
*bs
,
658 uint32_t granularity
,
660 void qcow2_remove_persistent_dirty_bitmap(BlockDriverState
*bs
,