1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef BLOCK_QCOW2_H
26#define BLOCK_QCOW2_H
27
28#include "crypto/block.h"
29#include "qemu/coroutine.h"
30
31
32
33
34
35#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
36
37#define QCOW_CRYPT_NONE 0
38#define QCOW_CRYPT_AES 1
39#define QCOW_CRYPT_LUKS 2
40
41#define QCOW_MAX_CRYPT_CLUSTERS 32
42#define QCOW_MAX_SNAPSHOTS 65536
43
44
45
46#define QCOW_MAX_REFTABLE_SIZE 0x800000
47
48
49
50#define QCOW_MAX_L1_SIZE 0x2000000
51
52
53
54#define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
55
56
57#define QCOW2_MAX_BITMAPS 65535
58#define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS)
59
60
61#define QCOW_OFLAG_COPIED (1ULL << 63)
62
63#define QCOW_OFLAG_COMPRESSED (1ULL << 62)
64
65#define QCOW_OFLAG_ZERO (1ULL << 0)
66
67#define MIN_CLUSTER_BITS 9
68#define MAX_CLUSTER_BITS 21
69
70
71#define MIN_L2_CACHE_SIZE 2
72
73
74#define MIN_REFCOUNT_CACHE_SIZE 4
75
76
77#define DEFAULT_L2_CACHE_CLUSTERS 8
78#define DEFAULT_L2_CACHE_BYTE_SIZE 1048576
79
80
81
82#define DEFAULT_L2_REFCOUNT_SIZE_RATIO 4
83
84#define DEFAULT_CLUSTER_SIZE 65536
85
86
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_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size"
104#define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
105#define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
106
107typedef struct QCowHeader {
108 uint32_t magic;
109 uint32_t version;
110 uint64_t backing_file_offset;
111 uint32_t backing_file_size;
112 uint32_t cluster_bits;
113 uint64_t size;
114 uint32_t crypt_method;
115 uint32_t l1_size;
116 uint64_t l1_table_offset;
117 uint64_t refcount_table_offset;
118 uint32_t refcount_table_clusters;
119 uint32_t nb_snapshots;
120 uint64_t snapshots_offset;
121
122
123 uint64_t incompatible_features;
124 uint64_t compatible_features;
125 uint64_t autoclear_features;
126
127 uint32_t refcount_order;
128 uint32_t header_length;
129} QEMU_PACKED QCowHeader;
130
131typedef struct QEMU_PACKED QCowSnapshotHeader {
132
133 uint64_t l1_table_offset;
134
135 uint32_t l1_size;
136 uint16_t id_str_size;
137 uint16_t name_size;
138
139 uint32_t date_sec;
140 uint32_t date_nsec;
141
142 uint64_t vm_clock_nsec;
143
144 uint32_t vm_state_size;
145 uint32_t extra_data_size;
146
147
148
149} QCowSnapshotHeader;
150
151typedef struct QEMU_PACKED QCowSnapshotExtraData {
152 uint64_t vm_state_size_large;
153 uint64_t disk_size;
154} QCowSnapshotExtraData;
155
156
157typedef struct QCowSnapshot {
158 uint64_t l1_table_offset;
159 uint32_t l1_size;
160 char *id_str;
161 char *name;
162 uint64_t disk_size;
163 uint64_t vm_state_size;
164 uint32_t date_sec;
165 uint32_t date_nsec;
166 uint64_t vm_clock_nsec;
167} QCowSnapshot;
168
169struct Qcow2Cache;
170typedef struct Qcow2Cache Qcow2Cache;
171
172typedef struct Qcow2CryptoHeaderExtension {
173 uint64_t offset;
174 uint64_t length;
175} QEMU_PACKED Qcow2CryptoHeaderExtension;
176
177typedef struct Qcow2UnknownHeaderExtension {
178 uint32_t magic;
179 uint32_t len;
180 QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
181 uint8_t data[];
182} Qcow2UnknownHeaderExtension;
183
184enum {
185 QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
186 QCOW2_FEAT_TYPE_COMPATIBLE = 1,
187 QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
188};
189
190
191enum {
192 QCOW2_INCOMPAT_DIRTY_BITNR = 0,
193 QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
194 QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
195 QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
196
197 QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY
198 | QCOW2_INCOMPAT_CORRUPT,
199};
200
201
202enum {
203 QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
204 QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
205
206 QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS,
207};
208
209
210enum {
211 QCOW2_AUTOCLEAR_BITMAPS_BITNR = 0,
212 QCOW2_AUTOCLEAR_BITMAPS = 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR,
213
214 QCOW2_AUTOCLEAR_MASK = QCOW2_AUTOCLEAR_BITMAPS,
215};
216
217enum qcow2_discard_type {
218 QCOW2_DISCARD_NEVER = 0,
219 QCOW2_DISCARD_ALWAYS,
220 QCOW2_DISCARD_REQUEST,
221 QCOW2_DISCARD_SNAPSHOT,
222 QCOW2_DISCARD_OTHER,
223 QCOW2_DISCARD_MAX
224};
225
226typedef struct Qcow2Feature {
227 uint8_t type;
228 uint8_t bit;
229 char name[46];
230} QEMU_PACKED Qcow2Feature;
231
232typedef struct Qcow2DiscardRegion {
233 BlockDriverState *bs;
234 uint64_t offset;
235 uint64_t bytes;
236 QTAILQ_ENTRY(Qcow2DiscardRegion) next;
237} Qcow2DiscardRegion;
238
239typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
240 uint64_t index);
241typedef void Qcow2SetRefcountFunc(void *refcount_array,
242 uint64_t index, uint64_t value);
243
244typedef struct Qcow2BitmapHeaderExt {
245 uint32_t nb_bitmaps;
246 uint32_t reserved32;
247 uint64_t bitmap_directory_size;
248 uint64_t bitmap_directory_offset;
249} QEMU_PACKED Qcow2BitmapHeaderExt;
250
251typedef struct BDRVQcow2State {
252 int cluster_bits;
253 int cluster_size;
254 int cluster_sectors;
255 int l2_slice_size;
256 int l2_bits;
257 int l2_size;
258 int l1_size;
259 int l1_vm_state_index;
260 int refcount_block_bits;
261 int refcount_block_size;
262 int csize_shift;
263 int csize_mask;
264 uint64_t cluster_offset_mask;
265 uint64_t l1_table_offset;
266 uint64_t *l1_table;
267
268 Qcow2Cache* l2_table_cache;
269 Qcow2Cache* refcount_block_cache;
270 QEMUTimer *cache_clean_timer;
271 unsigned cache_clean_interval;
272
273 uint8_t *cluster_cache;
274 uint8_t *cluster_data;
275 uint64_t cluster_cache_offset;
276 QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs;
277
278 uint64_t *refcount_table;
279 uint64_t refcount_table_offset;
280 uint32_t refcount_table_size;
281 uint32_t max_refcount_table_index;
282 uint64_t free_cluster_index;
283 uint64_t free_byte_offset;
284
285 CoMutex lock;
286
287 Qcow2CryptoHeaderExtension crypto_header;
288 QCryptoBlockOpenOptions *crypto_opts;
289 QCryptoBlock *crypto;
290 bool crypt_physical_offset;
291
292 uint32_t crypt_method_header;
293 uint64_t snapshots_offset;
294 int snapshots_size;
295 unsigned int nb_snapshots;
296 QCowSnapshot *snapshots;
297
298 uint32_t nb_bitmaps;
299 uint64_t bitmap_directory_size;
300 uint64_t bitmap_directory_offset;
301 bool dirty_bitmaps_loaded;
302
303 int flags;
304 int qcow_version;
305 bool use_lazy_refcounts;
306 int refcount_order;
307 int refcount_bits;
308 uint64_t refcount_max;
309
310 Qcow2GetRefcountFunc *get_refcount;
311 Qcow2SetRefcountFunc *set_refcount;
312
313 bool discard_passthrough[QCOW2_DISCARD_MAX];
314
315 int overlap_check;
316 bool signaled_corruption;
317
318 uint64_t incompatible_features;
319 uint64_t compatible_features;
320 uint64_t autoclear_features;
321
322 size_t unknown_header_fields_size;
323 void* unknown_header_fields;
324 QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
325 QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
326 bool cache_discards;
327
328
329
330
331 char *image_backing_file;
332 char *image_backing_format;
333} BDRVQcow2State;
334
335typedef struct Qcow2COWRegion {
336
337
338
339
340 unsigned offset;
341
342
343 unsigned nb_bytes;
344} Qcow2COWRegion;
345
346
347
348
349
350typedef struct QCowL2Meta
351{
352
353 uint64_t offset;
354
355
356 uint64_t alloc_offset;
357
358
359 int nb_clusters;
360
361
362 bool keep_old_clusters;
363
364
365
366
367
368 CoQueue dependent_requests;
369
370
371
372
373
374 Qcow2COWRegion cow_start;
375
376
377
378
379
380 Qcow2COWRegion cow_end;
381
382
383
384
385
386
387 QEMUIOVector *data_qiov;
388
389
390 struct QCowL2Meta *next;
391
392 QLIST_ENTRY(QCowL2Meta) next_in_flight;
393} QCowL2Meta;
394
395typedef enum QCow2ClusterType {
396 QCOW2_CLUSTER_UNALLOCATED,
397 QCOW2_CLUSTER_ZERO_PLAIN,
398 QCOW2_CLUSTER_ZERO_ALLOC,
399 QCOW2_CLUSTER_NORMAL,
400 QCOW2_CLUSTER_COMPRESSED,
401} QCow2ClusterType;
402
403typedef enum QCow2MetadataOverlap {
404 QCOW2_OL_MAIN_HEADER_BITNR = 0,
405 QCOW2_OL_ACTIVE_L1_BITNR = 1,
406 QCOW2_OL_ACTIVE_L2_BITNR = 2,
407 QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
408 QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
409 QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
410 QCOW2_OL_INACTIVE_L1_BITNR = 6,
411 QCOW2_OL_INACTIVE_L2_BITNR = 7,
412
413 QCOW2_OL_MAX_BITNR = 8,
414
415 QCOW2_OL_NONE = 0,
416 QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
417 QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
418 QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
419 QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
420 QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
421 QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
422 QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
423
424
425 QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
426} QCow2MetadataOverlap;
427
428
429#define QCOW2_OL_CONSTANT \
430 (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
431 QCOW2_OL_SNAPSHOT_TABLE)
432
433
434#define QCOW2_OL_CACHED \
435 (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
436 QCOW2_OL_INACTIVE_L1)
437
438
439#define QCOW2_OL_ALL \
440 (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
441
442#define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
443#define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
444#define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
445
446#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
447
448static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset)
449{
450 return offset & ~(s->cluster_size - 1);
451}
452
453static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
454{
455 return offset & (s->cluster_size - 1);
456}
457
458static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
459{
460 return (size + (s->cluster_size - 1)) >> s->cluster_bits;
461}
462
463static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size)
464{
465 int shift = s->cluster_bits + s->l2_bits;
466 return (size + (1ULL << shift) - 1) >> shift;
467}
468
469static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset)
470{
471 return offset >> (s->l2_bits + s->cluster_bits);
472}
473
474static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
475{
476 return (offset >> s->cluster_bits) & (s->l2_size - 1);
477}
478
479static inline int offset_to_l2_slice_index(BDRVQcow2State *s, int64_t offset)
480{
481 return (offset >> s->cluster_bits) & (s->l2_slice_size - 1);
482}
483
484static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)
485{
486 return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
487}
488
489static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
490{
491 if (l2_entry & QCOW_OFLAG_COMPRESSED) {
492 return QCOW2_CLUSTER_COMPRESSED;
493 } else if (l2_entry & QCOW_OFLAG_ZERO) {
494 if (l2_entry & L2E_OFFSET_MASK) {
495 return QCOW2_CLUSTER_ZERO_ALLOC;
496 }
497 return QCOW2_CLUSTER_ZERO_PLAIN;
498 } else if (!(l2_entry & L2E_OFFSET_MASK)) {
499 return QCOW2_CLUSTER_UNALLOCATED;
500 } else {
501 return QCOW2_CLUSTER_NORMAL;
502 }
503}
504
505
506static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)
507{
508 return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
509}
510
511static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
512{
513 return m->offset + m->cow_start.offset;
514}
515
516static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
517{
518 return m->offset + m->cow_end.offset + m->cow_end.nb_bytes;
519}
520
521static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
522{
523 return r1 > r2 ? r1 - r2 : r2 - r1;
524}
525
526static inline
527uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset)
528{
529 return offset >> (s->refcount_block_bits + s->cluster_bits);
530}
531
532
533int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
534 int refcount_order, bool generous_increase,
535 uint64_t *refblock_count);
536
537int qcow2_mark_dirty(BlockDriverState *bs);
538int qcow2_mark_corrupt(BlockDriverState *bs);
539int qcow2_mark_consistent(BlockDriverState *bs);
540int qcow2_update_header(BlockDriverState *bs);
541
542void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
543 int64_t size, const char *message_format, ...)
544 GCC_FMT_ATTR(5, 6);
545
546int qcow2_validate_table(BlockDriverState *bs, uint64_t offset,
547 uint64_t entries, size_t entry_len,
548 int64_t max_size_bytes, const char *table_name,
549 Error **errp);
550
551
552int qcow2_refcount_init(BlockDriverState *bs);
553void qcow2_refcount_close(BlockDriverState *bs);
554
555int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
556 uint64_t *refcount);
557
558int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
559 uint64_t addend, bool decrease,
560 enum qcow2_discard_type type);
561
562int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
563 uint64_t additional_clusters, bool exact_size,
564 int new_refblock_index,
565 uint64_t new_refblock_offset);
566
567int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
568int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
569 int64_t nb_clusters);
570int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
571void qcow2_free_clusters(BlockDriverState *bs,
572 int64_t offset, int64_t size,
573 enum qcow2_discard_type type);
574void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
575 int nb_clusters, enum qcow2_discard_type type);
576
577int qcow2_update_snapshot_refcount(BlockDriverState *bs,
578 int64_t l1_table_offset, int l1_size, int addend);
579
580int coroutine_fn qcow2_flush_caches(BlockDriverState *bs);
581int coroutine_fn qcow2_write_caches(BlockDriverState *bs);
582int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
583 BdrvCheckMode fix);
584
585void qcow2_process_discards(BlockDriverState *bs, int ret);
586
587int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
588 int64_t size);
589int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
590 int64_t size);
591int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
592 void **refcount_table,
593 int64_t *refcount_table_size,
594 int64_t offset, int64_t size);
595
596int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
597 BlockDriverAmendStatusCB *status_cb,
598 void *cb_opaque, Error **errp);
599int qcow2_shrink_reftable(BlockDriverState *bs);
600int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size);
601
602
603int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
604 bool exact_size);
605int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size);
606int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
607int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
608int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
609 uint8_t *buf, int nb_sectors, bool enc, Error **errp);
610
611int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
612 unsigned int *bytes, uint64_t *cluster_offset);
613int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
614 unsigned int *bytes, uint64_t *host_offset,
615 QCowL2Meta **m);
616uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
617 uint64_t offset,
618 int compressed_size);
619
620int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
621int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
622 uint64_t bytes, enum qcow2_discard_type type,
623 bool full_discard);
624int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
625 uint64_t bytes, int flags);
626
627int qcow2_expand_zero_clusters(BlockDriverState *bs,
628 BlockDriverAmendStatusCB *status_cb,
629 void *cb_opaque);
630
631
632int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
633int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
634int qcow2_snapshot_delete(BlockDriverState *bs,
635 const char *snapshot_id,
636 const char *name,
637 Error **errp);
638int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
639int qcow2_snapshot_load_tmp(BlockDriverState *bs,
640 const char *snapshot_id,
641 const char *name,
642 Error **errp);
643
644void qcow2_free_snapshots(BlockDriverState *bs);
645int qcow2_read_snapshots(BlockDriverState *bs);
646
647
648Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
649 unsigned table_size);
650int qcow2_cache_destroy(Qcow2Cache *c);
651
652void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
653int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
654int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c);
655int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
656 Qcow2Cache *dependency);
657void qcow2_cache_depends_on_flush(Qcow2Cache *c);
658
659void qcow2_cache_clean_unused(Qcow2Cache *c);
660int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
661
662int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
663 void **table);
664int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
665 void **table);
666void qcow2_cache_put(Qcow2Cache *c, void **table);
667void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64_t offset);
668void qcow2_cache_discard(Qcow2Cache *c, void *table);
669
670
671int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
672 void **refcount_table,
673 int64_t *refcount_table_size);
674bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp);
675int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_updated,
676 Error **errp);
677int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
678void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp);
679int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
680bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
681 const char *name,
682 uint32_t granularity,
683 Error **errp);
684void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs,
685 const char *name,
686 Error **errp);
687
688#endif
689