xref: /openbmc/qemu/block/qcow2.h (revision 1dde0f48d53ad39401ec5064a61162d6784aad44)
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 "qemu/aes.h"
29 #include "block/coroutine.h"
30 
31 //#define DEBUG_ALLOC
32 //#define DEBUG_ALLOC2
33 //#define DEBUG_EXT
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 
40 #define QCOW_MAX_CRYPT_CLUSTERS 32
41 #define QCOW_MAX_SNAPSHOTS 65536
42 
43 /* 8 MB refcount table is enough for 2 PB images at 64k cluster size
44  * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
45 #define QCOW_MAX_REFTABLE_SIZE 0x800000
46 
47 /* 32 MB L1 table is enough for 2 PB images at 64k cluster size
48  * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
49 #define QCOW_MAX_L1_SIZE 0x2000000
50 
51 /* Allow for an average of 1k per snapshot table entry, should be plenty of
52  * space for snapshot names and IDs */
53 #define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
54 
55 /* indicate that the refcount of the referenced cluster is exactly one. */
56 #define QCOW_OFLAG_COPIED     (1ULL << 63)
57 /* indicate that the cluster is compressed (they never have the copied flag) */
58 #define QCOW_OFLAG_COMPRESSED (1ULL << 62)
59 /* The cluster reads as all zeros */
60 #define QCOW_OFLAG_ZERO (1ULL << 0)
61 
62 #define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */
63 
64 #define MIN_CLUSTER_BITS 9
65 #define MAX_CLUSTER_BITS 21
66 
67 #define MIN_L2_CACHE_SIZE 1 /* cluster */
68 
69 /* Must be at least 4 to cover all cases of refcount table growth */
70 #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
71 
72 #define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */
73 
74 /* The refblock cache needs only a fourth of the L2 cache size to cover as many
75  * clusters */
76 #define DEFAULT_L2_REFCOUNT_SIZE_RATIO 4
77 
78 #define DEFAULT_CLUSTER_SIZE 65536
79 
80 
81 #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
82 #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
83 #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
84 #define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
85 #define QCOW2_OPT_OVERLAP "overlap-check"
86 #define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
87 #define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
88 #define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
89 #define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
90 #define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
91 #define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
92 #define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
93 #define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
94 #define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
95 #define QCOW2_OPT_CACHE_SIZE "cache-size"
96 #define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
97 #define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
98 
99 typedef struct QCowHeader {
100     uint32_t magic;
101     uint32_t version;
102     uint64_t backing_file_offset;
103     uint32_t backing_file_size;
104     uint32_t cluster_bits;
105     uint64_t size; /* in bytes */
106     uint32_t crypt_method;
107     uint32_t l1_size; /* XXX: save number of clusters instead ? */
108     uint64_t l1_table_offset;
109     uint64_t refcount_table_offset;
110     uint32_t refcount_table_clusters;
111     uint32_t nb_snapshots;
112     uint64_t snapshots_offset;
113 
114     /* The following fields are only valid for version >= 3 */
115     uint64_t incompatible_features;
116     uint64_t compatible_features;
117     uint64_t autoclear_features;
118 
119     uint32_t refcount_order;
120     uint32_t header_length;
121 } QEMU_PACKED QCowHeader;
122 
123 typedef struct QEMU_PACKED QCowSnapshotHeader {
124     /* header is 8 byte aligned */
125     uint64_t l1_table_offset;
126 
127     uint32_t l1_size;
128     uint16_t id_str_size;
129     uint16_t name_size;
130 
131     uint32_t date_sec;
132     uint32_t date_nsec;
133 
134     uint64_t vm_clock_nsec;
135 
136     uint32_t vm_state_size;
137     uint32_t extra_data_size; /* for extension */
138     /* extra data follows */
139     /* id_str follows */
140     /* name follows  */
141 } QCowSnapshotHeader;
142 
143 typedef struct QEMU_PACKED QCowSnapshotExtraData {
144     uint64_t vm_state_size_large;
145     uint64_t disk_size;
146 } QCowSnapshotExtraData;
147 
148 
149 typedef struct QCowSnapshot {
150     uint64_t l1_table_offset;
151     uint32_t l1_size;
152     char *id_str;
153     char *name;
154     uint64_t disk_size;
155     uint64_t vm_state_size;
156     uint32_t date_sec;
157     uint32_t date_nsec;
158     uint64_t vm_clock_nsec;
159 } QCowSnapshot;
160 
161 struct Qcow2Cache;
162 typedef struct Qcow2Cache Qcow2Cache;
163 
164 typedef struct Qcow2UnknownHeaderExtension {
165     uint32_t magic;
166     uint32_t len;
167     QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
168     uint8_t data[];
169 } Qcow2UnknownHeaderExtension;
170 
171 enum {
172     QCOW2_FEAT_TYPE_INCOMPATIBLE    = 0,
173     QCOW2_FEAT_TYPE_COMPATIBLE      = 1,
174     QCOW2_FEAT_TYPE_AUTOCLEAR       = 2,
175 };
176 
177 /* Incompatible feature bits */
178 enum {
179     QCOW2_INCOMPAT_DIRTY_BITNR   = 0,
180     QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
181     QCOW2_INCOMPAT_DIRTY         = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
182     QCOW2_INCOMPAT_CORRUPT       = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
183 
184     QCOW2_INCOMPAT_MASK          = QCOW2_INCOMPAT_DIRTY
185                                  | QCOW2_INCOMPAT_CORRUPT,
186 };
187 
188 /* Compatible feature bits */
189 enum {
190     QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
191     QCOW2_COMPAT_LAZY_REFCOUNTS       = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
192 
193     QCOW2_COMPAT_FEAT_MASK            = QCOW2_COMPAT_LAZY_REFCOUNTS,
194 };
195 
196 enum qcow2_discard_type {
197     QCOW2_DISCARD_NEVER = 0,
198     QCOW2_DISCARD_ALWAYS,
199     QCOW2_DISCARD_REQUEST,
200     QCOW2_DISCARD_SNAPSHOT,
201     QCOW2_DISCARD_OTHER,
202     QCOW2_DISCARD_MAX
203 };
204 
205 typedef struct Qcow2Feature {
206     uint8_t type;
207     uint8_t bit;
208     char    name[46];
209 } QEMU_PACKED Qcow2Feature;
210 
211 typedef struct Qcow2DiscardRegion {
212     BlockDriverState *bs;
213     uint64_t offset;
214     uint64_t bytes;
215     QTAILQ_ENTRY(Qcow2DiscardRegion) next;
216 } Qcow2DiscardRegion;
217 
218 typedef struct BDRVQcowState {
219     int cluster_bits;
220     int cluster_size;
221     int cluster_sectors;
222     int l2_bits;
223     int l2_size;
224     int l1_size;
225     int l1_vm_state_index;
226     int csize_shift;
227     int csize_mask;
228     uint64_t cluster_offset_mask;
229     uint64_t l1_table_offset;
230     uint64_t *l1_table;
231 
232     Qcow2Cache* l2_table_cache;
233     Qcow2Cache* refcount_block_cache;
234 
235     uint8_t *cluster_cache;
236     uint8_t *cluster_data;
237     uint64_t cluster_cache_offset;
238     QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs;
239 
240     uint64_t *refcount_table;
241     uint64_t refcount_table_offset;
242     uint32_t refcount_table_size;
243     uint64_t free_cluster_index;
244     uint64_t free_byte_offset;
245 
246     CoMutex lock;
247 
248     uint32_t crypt_method; /* current crypt method, 0 if no key yet */
249     uint32_t crypt_method_header;
250     AES_KEY aes_encrypt_key;
251     AES_KEY aes_decrypt_key;
252     uint64_t snapshots_offset;
253     int snapshots_size;
254     unsigned int nb_snapshots;
255     QCowSnapshot *snapshots;
256 
257     int flags;
258     int qcow_version;
259     bool use_lazy_refcounts;
260     int refcount_order;
261 
262     bool discard_passthrough[QCOW2_DISCARD_MAX];
263 
264     int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
265     bool signaled_corruption;
266 
267     uint64_t incompatible_features;
268     uint64_t compatible_features;
269     uint64_t autoclear_features;
270 
271     size_t unknown_header_fields_size;
272     void* unknown_header_fields;
273     QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
274     QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
275     bool cache_discards;
276 } BDRVQcowState;
277 
278 /* XXX: use std qcow open function ? */
279 typedef struct QCowCreateState {
280     int cluster_size;
281     int cluster_bits;
282     uint16_t *refcount_block;
283     uint64_t *refcount_table;
284     int64_t l1_table_offset;
285     int64_t refcount_table_offset;
286     int64_t refcount_block_offset;
287 } QCowCreateState;
288 
289 struct QCowAIOCB;
290 
291 typedef struct Qcow2COWRegion {
292     /**
293      * Offset of the COW region in bytes from the start of the first cluster
294      * touched by the request.
295      */
296     uint64_t    offset;
297 
298     /** Number of sectors to copy */
299     int         nb_sectors;
300 } Qcow2COWRegion;
301 
302 /**
303  * Describes an in-flight (part of a) write request that writes to clusters
304  * that are not referenced in their L2 table yet.
305  */
306 typedef struct QCowL2Meta
307 {
308     /** Guest offset of the first newly allocated cluster */
309     uint64_t offset;
310 
311     /** Host offset of the first newly allocated cluster */
312     uint64_t alloc_offset;
313 
314     /**
315      * Number of sectors from the start of the first allocated cluster to
316      * the end of the (possibly shortened) request
317      */
318     int nb_available;
319 
320     /** Number of newly allocated clusters */
321     int nb_clusters;
322 
323     /**
324      * Requests that overlap with this allocation and wait to be restarted
325      * when the allocating request has completed.
326      */
327     CoQueue dependent_requests;
328 
329     /**
330      * The COW Region between the start of the first allocated cluster and the
331      * area the guest actually writes to.
332      */
333     Qcow2COWRegion cow_start;
334 
335     /**
336      * The COW Region between the area the guest actually writes to and the
337      * end of the last allocated cluster.
338      */
339     Qcow2COWRegion cow_end;
340 
341     /** Pointer to next L2Meta of the same write request */
342     struct QCowL2Meta *next;
343 
344     QLIST_ENTRY(QCowL2Meta) next_in_flight;
345 } QCowL2Meta;
346 
347 enum {
348     QCOW2_CLUSTER_UNALLOCATED,
349     QCOW2_CLUSTER_NORMAL,
350     QCOW2_CLUSTER_COMPRESSED,
351     QCOW2_CLUSTER_ZERO
352 };
353 
354 typedef enum QCow2MetadataOverlap {
355     QCOW2_OL_MAIN_HEADER_BITNR    = 0,
356     QCOW2_OL_ACTIVE_L1_BITNR      = 1,
357     QCOW2_OL_ACTIVE_L2_BITNR      = 2,
358     QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
359     QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
360     QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
361     QCOW2_OL_INACTIVE_L1_BITNR    = 6,
362     QCOW2_OL_INACTIVE_L2_BITNR    = 7,
363 
364     QCOW2_OL_MAX_BITNR            = 8,
365 
366     QCOW2_OL_NONE           = 0,
367     QCOW2_OL_MAIN_HEADER    = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
368     QCOW2_OL_ACTIVE_L1      = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
369     QCOW2_OL_ACTIVE_L2      = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
370     QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
371     QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
372     QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
373     QCOW2_OL_INACTIVE_L1    = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
374     /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
375      * reads. */
376     QCOW2_OL_INACTIVE_L2    = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
377 } QCow2MetadataOverlap;
378 
379 /* Perform all overlap checks which can be done in constant time */
380 #define QCOW2_OL_CONSTANT \
381     (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
382      QCOW2_OL_SNAPSHOT_TABLE)
383 
384 /* Perform all overlap checks which don't require disk access */
385 #define QCOW2_OL_CACHED \
386     (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
387      QCOW2_OL_INACTIVE_L1)
388 
389 /* Perform all overlap checks */
390 #define QCOW2_OL_ALL \
391     (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
392 
393 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
394 #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
395 #define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
396 
397 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
398 
399 static inline int64_t start_of_cluster(BDRVQcowState *s, int64_t offset)
400 {
401     return offset & ~(s->cluster_size - 1);
402 }
403 
404 static inline int64_t offset_into_cluster(BDRVQcowState *s, int64_t offset)
405 {
406     return offset & (s->cluster_size - 1);
407 }
408 
409 static inline int size_to_clusters(BDRVQcowState *s, int64_t size)
410 {
411     return (size + (s->cluster_size - 1)) >> s->cluster_bits;
412 }
413 
414 static inline int64_t size_to_l1(BDRVQcowState *s, int64_t size)
415 {
416     int shift = s->cluster_bits + s->l2_bits;
417     return (size + (1ULL << shift) - 1) >> shift;
418 }
419 
420 static inline int offset_to_l2_index(BDRVQcowState *s, int64_t offset)
421 {
422     return (offset >> s->cluster_bits) & (s->l2_size - 1);
423 }
424 
425 static inline int64_t align_offset(int64_t offset, int n)
426 {
427     offset = (offset + n - 1) & ~(n - 1);
428     return offset;
429 }
430 
431 static inline int64_t qcow2_vm_state_offset(BDRVQcowState *s)
432 {
433     return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
434 }
435 
436 static inline uint64_t qcow2_max_refcount_clusters(BDRVQcowState *s)
437 {
438     return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
439 }
440 
441 static inline int qcow2_get_cluster_type(uint64_t l2_entry)
442 {
443     if (l2_entry & QCOW_OFLAG_COMPRESSED) {
444         return QCOW2_CLUSTER_COMPRESSED;
445     } else if (l2_entry & QCOW_OFLAG_ZERO) {
446         return QCOW2_CLUSTER_ZERO;
447     } else if (!(l2_entry & L2E_OFFSET_MASK)) {
448         return QCOW2_CLUSTER_UNALLOCATED;
449     } else {
450         return QCOW2_CLUSTER_NORMAL;
451     }
452 }
453 
454 /* Check whether refcounts are eager or lazy */
455 static inline bool qcow2_need_accurate_refcounts(BDRVQcowState *s)
456 {
457     return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
458 }
459 
460 static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
461 {
462     return m->offset + m->cow_start.offset;
463 }
464 
465 static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
466 {
467     return m->offset + m->cow_end.offset
468         + (m->cow_end.nb_sectors << BDRV_SECTOR_BITS);
469 }
470 
471 // FIXME Need qcow2_ prefix to global functions
472 
473 /* qcow2.c functions */
474 int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
475                   int64_t sector_num, int nb_sectors);
476 
477 int qcow2_mark_dirty(BlockDriverState *bs);
478 int qcow2_mark_corrupt(BlockDriverState *bs);
479 int qcow2_mark_consistent(BlockDriverState *bs);
480 int qcow2_update_header(BlockDriverState *bs);
481 
482 void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
483                              int64_t size, const char *message_format, ...)
484                              GCC_FMT_ATTR(5, 6);
485 
486 /* qcow2-refcount.c functions */
487 int qcow2_refcount_init(BlockDriverState *bs);
488 void qcow2_refcount_close(BlockDriverState *bs);
489 
490 int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
491                                   int addend, enum qcow2_discard_type type);
492 
493 int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
494 int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
495     int nb_clusters);
496 int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
497 void qcow2_free_clusters(BlockDriverState *bs,
498                           int64_t offset, int64_t size,
499                           enum qcow2_discard_type type);
500 void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
501                              int nb_clusters, enum qcow2_discard_type type);
502 
503 int qcow2_update_snapshot_refcount(BlockDriverState *bs,
504     int64_t l1_table_offset, int l1_size, int addend);
505 
506 int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
507                           BdrvCheckMode fix);
508 
509 void qcow2_process_discards(BlockDriverState *bs, int ret);
510 
511 int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
512                                  int64_t size);
513 int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
514                                   int64_t size);
515 
516 /* qcow2-cluster.c functions */
517 int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
518                         bool exact_size);
519 int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
520 void qcow2_l2_cache_reset(BlockDriverState *bs);
521 int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
522 void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
523                      uint8_t *out_buf, const uint8_t *in_buf,
524                      int nb_sectors, int enc,
525                      const AES_KEY *key);
526 
527 int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
528     int *num, uint64_t *cluster_offset);
529 int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
530     int *num, uint64_t *host_offset, QCowL2Meta **m);
531 uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
532                                          uint64_t offset,
533                                          int compressed_size);
534 
535 int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
536 int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
537     int nb_sectors, enum qcow2_discard_type type);
538 int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors);
539 
540 int qcow2_expand_zero_clusters(BlockDriverState *bs);
541 
542 /* qcow2-snapshot.c functions */
543 int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
544 int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
545 int qcow2_snapshot_delete(BlockDriverState *bs,
546                           const char *snapshot_id,
547                           const char *name,
548                           Error **errp);
549 int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
550 int qcow2_snapshot_load_tmp(BlockDriverState *bs,
551                             const char *snapshot_id,
552                             const char *name,
553                             Error **errp);
554 
555 void qcow2_free_snapshots(BlockDriverState *bs);
556 int qcow2_read_snapshots(BlockDriverState *bs);
557 
558 /* qcow2-cache.c functions */
559 Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);
560 int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
561 
562 void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
563 int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
564 int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
565     Qcow2Cache *dependency);
566 void qcow2_cache_depends_on_flush(Qcow2Cache *c);
567 
568 int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
569 
570 int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
571     void **table);
572 int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
573     void **table);
574 int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table);
575 
576 #endif
577