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