]> Git Repo - qemu.git/blob - block/qcow2.h
a8d6f757b1f8949f495418682ae5f0d9c7a39a42
[qemu.git] / block / qcow2.h
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/coroutine.h"
30 #include "qemu/units.h"
31
32 //#define DEBUG_ALLOC
33 //#define DEBUG_ALLOC2
34 //#define DEBUG_EXT
35
36 #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
37
38 #define QCOW_CRYPT_NONE 0
39 #define QCOW_CRYPT_AES  1
40 #define QCOW_CRYPT_LUKS 2
41
42 #define QCOW_MAX_CRYPT_CLUSTERS 32
43 #define QCOW_MAX_SNAPSHOTS 65536
44
45 /* 8 MB refcount table is enough for 2 PB images at 64k cluster size
46  * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
47 #define QCOW_MAX_REFTABLE_SIZE S_8MiB
48
49 /* 32 MB L1 table is enough for 2 PB images at 64k cluster size
50  * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
51 #define QCOW_MAX_L1_SIZE S_32MiB
52
53 /* Allow for an average of 1k per snapshot table entry, should be plenty of
54  * space for snapshot names and IDs */
55 #define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
56
57 /* Bitmap header extension constraints */
58 #define QCOW2_MAX_BITMAPS 65535
59 #define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS)
60
61 /* indicate that the refcount of the referenced cluster is exactly one. */
62 #define QCOW_OFLAG_COPIED     (1ULL << 63)
63 /* indicate that the cluster is compressed (they never have the copied flag) */
64 #define QCOW_OFLAG_COMPRESSED (1ULL << 62)
65 /* The cluster reads as all zeros */
66 #define QCOW_OFLAG_ZERO (1ULL << 0)
67
68 #define MIN_CLUSTER_BITS 9
69 #define MAX_CLUSTER_BITS 21
70
71 /* Must be at least 2 to cover COW */
72 #define MIN_L2_CACHE_SIZE 2 /* cache entries */
73
74 /* Must be at least 4 to cover all cases of refcount table growth */
75 #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
76
77 /* Whichever is more */
78 #define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */
79 #define DEFAULT_L2_CACHE_SIZE S_1MiB
80
81 #define DEFAULT_CLUSTER_SIZE S_64KiB
82
83
84 #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
85 #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
86 #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
87 #define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
88 #define QCOW2_OPT_OVERLAP "overlap-check"
89 #define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
90 #define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
91 #define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
92 #define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
93 #define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
94 #define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
95 #define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
96 #define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
97 #define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
98 #define QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY "overlap-check.bitmap-directory"
99 #define QCOW2_OPT_CACHE_SIZE "cache-size"
100 #define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
101 #define QCOW2_OPT_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size"
102 #define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
103 #define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
104
105 typedef struct QCowHeader {
106     uint32_t magic;
107     uint32_t version;
108     uint64_t backing_file_offset;
109     uint32_t backing_file_size;
110     uint32_t cluster_bits;
111     uint64_t size; /* in bytes */
112     uint32_t crypt_method;
113     uint32_t l1_size; /* XXX: save number of clusters instead ? */
114     uint64_t l1_table_offset;
115     uint64_t refcount_table_offset;
116     uint32_t refcount_table_clusters;
117     uint32_t nb_snapshots;
118     uint64_t snapshots_offset;
119
120     /* The following fields are only valid for version >= 3 */
121     uint64_t incompatible_features;
122     uint64_t compatible_features;
123     uint64_t autoclear_features;
124
125     uint32_t refcount_order;
126     uint32_t header_length;
127 } QEMU_PACKED QCowHeader;
128
129 typedef struct QEMU_PACKED QCowSnapshotHeader {
130     /* header is 8 byte aligned */
131     uint64_t l1_table_offset;
132
133     uint32_t l1_size;
134     uint16_t id_str_size;
135     uint16_t name_size;
136
137     uint32_t date_sec;
138     uint32_t date_nsec;
139
140     uint64_t vm_clock_nsec;
141
142     uint32_t vm_state_size;
143     uint32_t extra_data_size; /* for extension */
144     /* extra data follows */
145     /* id_str follows */
146     /* name follows  */
147 } QCowSnapshotHeader;
148
149 typedef struct QEMU_PACKED QCowSnapshotExtraData {
150     uint64_t vm_state_size_large;
151     uint64_t disk_size;
152 } QCowSnapshotExtraData;
153
154
155 typedef struct QCowSnapshot {
156     uint64_t l1_table_offset;
157     uint32_t l1_size;
158     char *id_str;
159     char *name;
160     uint64_t disk_size;
161     uint64_t vm_state_size;
162     uint32_t date_sec;
163     uint32_t date_nsec;
164     uint64_t vm_clock_nsec;
165 } QCowSnapshot;
166
167 struct Qcow2Cache;
168 typedef struct Qcow2Cache Qcow2Cache;
169
170 typedef struct Qcow2CryptoHeaderExtension {
171     uint64_t offset;
172     uint64_t length;
173 } QEMU_PACKED Qcow2CryptoHeaderExtension;
174
175 typedef struct Qcow2UnknownHeaderExtension {
176     uint32_t magic;
177     uint32_t len;
178     QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
179     uint8_t data[];
180 } Qcow2UnknownHeaderExtension;
181
182 enum {
183     QCOW2_FEAT_TYPE_INCOMPATIBLE    = 0,
184     QCOW2_FEAT_TYPE_COMPATIBLE      = 1,
185     QCOW2_FEAT_TYPE_AUTOCLEAR       = 2,
186 };
187
188 /* Incompatible feature bits */
189 enum {
190     QCOW2_INCOMPAT_DIRTY_BITNR   = 0,
191     QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
192     QCOW2_INCOMPAT_DIRTY         = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
193     QCOW2_INCOMPAT_CORRUPT       = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
194
195     QCOW2_INCOMPAT_MASK          = QCOW2_INCOMPAT_DIRTY
196                                  | QCOW2_INCOMPAT_CORRUPT,
197 };
198
199 /* Compatible feature bits */
200 enum {
201     QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
202     QCOW2_COMPAT_LAZY_REFCOUNTS       = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
203
204     QCOW2_COMPAT_FEAT_MASK            = QCOW2_COMPAT_LAZY_REFCOUNTS,
205 };
206
207 /* Autoclear feature bits */
208 enum {
209     QCOW2_AUTOCLEAR_BITMAPS_BITNR = 0,
210     QCOW2_AUTOCLEAR_BITMAPS       = 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR,
211
212     QCOW2_AUTOCLEAR_MASK          = QCOW2_AUTOCLEAR_BITMAPS,
213 };
214
215 enum qcow2_discard_type {
216     QCOW2_DISCARD_NEVER = 0,
217     QCOW2_DISCARD_ALWAYS,
218     QCOW2_DISCARD_REQUEST,
219     QCOW2_DISCARD_SNAPSHOT,
220     QCOW2_DISCARD_OTHER,
221     QCOW2_DISCARD_MAX
222 };
223
224 typedef struct Qcow2Feature {
225     uint8_t type;
226     uint8_t bit;
227     char    name[46];
228 } QEMU_PACKED Qcow2Feature;
229
230 typedef struct Qcow2DiscardRegion {
231     BlockDriverState *bs;
232     uint64_t offset;
233     uint64_t bytes;
234     QTAILQ_ENTRY(Qcow2DiscardRegion) next;
235 } Qcow2DiscardRegion;
236
237 typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
238                                       uint64_t index);
239 typedef void Qcow2SetRefcountFunc(void *refcount_array,
240                                   uint64_t index, uint64_t value);
241
242 typedef struct Qcow2BitmapHeaderExt {
243     uint32_t nb_bitmaps;
244     uint32_t reserved32;
245     uint64_t bitmap_directory_size;
246     uint64_t bitmap_directory_offset;
247 } QEMU_PACKED Qcow2BitmapHeaderExt;
248
249 typedef struct BDRVQcow2State {
250     int cluster_bits;
251     int cluster_size;
252     int cluster_sectors;
253     int l2_slice_size;
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; /* Last used entry in refcount_table */
280     uint64_t free_cluster_index;
281     uint64_t free_byte_offset;
282
283     CoMutex lock;
284
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;
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     bool dirty_bitmaps_loaded;
300
301     int flags;
302     int qcow_version;
303     bool use_lazy_refcounts;
304     int refcount_order;
305     int refcount_bits;
306     uint64_t refcount_max;
307
308     Qcow2GetRefcountFunc *get_refcount;
309     Qcow2SetRefcountFunc *set_refcount;
310
311     bool discard_passthrough[QCOW2_DISCARD_MAX];
312
313     int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
314     bool signaled_corruption;
315
316     uint64_t incompatible_features;
317     uint64_t compatible_features;
318     uint64_t autoclear_features;
319
320     size_t unknown_header_fields_size;
321     void* unknown_header_fields;
322     QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
323     QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
324     bool cache_discards;
325
326     /* Backing file path and format as stored in the image (this is not the
327      * effective path/format, which may be the result of a runtime option
328      * override) */
329     char *image_backing_file;
330     char *image_backing_format;
331
332     CoQueue compress_wait_queue;
333     int nb_compress_threads;
334 } BDRVQcow2State;
335
336 typedef struct Qcow2COWRegion {
337     /**
338      * Offset of the COW region in bytes from the start of the first cluster
339      * touched by the request.
340      */
341     unsigned    offset;
342
343     /** Number of bytes to copy */
344     unsigned    nb_bytes;
345 } Qcow2COWRegion;
346
347 /**
348  * Describes an in-flight (part of a) write request that writes to clusters
349  * that are not referenced in their L2 table yet.
350  */
351 typedef struct QCowL2Meta
352 {
353     /** Guest offset of the first newly allocated cluster */
354     uint64_t offset;
355
356     /** Host offset of the first newly allocated cluster */
357     uint64_t alloc_offset;
358
359     /** Number of newly allocated clusters */
360     int nb_clusters;
361
362     /** Do not free the old clusters */
363     bool keep_old_clusters;
364
365     /**
366      * Requests that overlap with this allocation and wait to be restarted
367      * when the allocating request has completed.
368      */
369     CoQueue dependent_requests;
370
371     /**
372      * The COW Region between the start of the first allocated cluster and the
373      * area the guest actually writes to.
374      */
375     Qcow2COWRegion cow_start;
376
377     /**
378      * The COW Region between the area the guest actually writes to and the
379      * end of the last allocated cluster.
380      */
381     Qcow2COWRegion cow_end;
382
383     /**
384      * The I/O vector with the data from the actual guest write request.
385      * If non-NULL, this is meant to be merged together with the data
386      * from @cow_start and @cow_end into one single write operation.
387      */
388     QEMUIOVector *data_qiov;
389
390     /** Pointer to next L2Meta of the same write request */
391     struct QCowL2Meta *next;
392
393     QLIST_ENTRY(QCowL2Meta) next_in_flight;
394 } QCowL2Meta;
395
396 typedef enum QCow2ClusterType {
397     QCOW2_CLUSTER_UNALLOCATED,
398     QCOW2_CLUSTER_ZERO_PLAIN,
399     QCOW2_CLUSTER_ZERO_ALLOC,
400     QCOW2_CLUSTER_NORMAL,
401     QCOW2_CLUSTER_COMPRESSED,
402 } QCow2ClusterType;
403
404 typedef enum QCow2MetadataOverlap {
405     QCOW2_OL_MAIN_HEADER_BITNR      = 0,
406     QCOW2_OL_ACTIVE_L1_BITNR        = 1,
407     QCOW2_OL_ACTIVE_L2_BITNR        = 2,
408     QCOW2_OL_REFCOUNT_TABLE_BITNR   = 3,
409     QCOW2_OL_REFCOUNT_BLOCK_BITNR   = 4,
410     QCOW2_OL_SNAPSHOT_TABLE_BITNR   = 5,
411     QCOW2_OL_INACTIVE_L1_BITNR      = 6,
412     QCOW2_OL_INACTIVE_L2_BITNR      = 7,
413     QCOW2_OL_BITMAP_DIRECTORY_BITNR = 8,
414
415     QCOW2_OL_MAX_BITNR              = 9,
416
417     QCOW2_OL_NONE             = 0,
418     QCOW2_OL_MAIN_HEADER      = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
419     QCOW2_OL_ACTIVE_L1        = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
420     QCOW2_OL_ACTIVE_L2        = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
421     QCOW2_OL_REFCOUNT_TABLE   = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
422     QCOW2_OL_REFCOUNT_BLOCK   = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
423     QCOW2_OL_SNAPSHOT_TABLE   = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
424     QCOW2_OL_INACTIVE_L1      = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
425     /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
426      * reads. */
427     QCOW2_OL_INACTIVE_L2      = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
428     QCOW2_OL_BITMAP_DIRECTORY = (1 << QCOW2_OL_BITMAP_DIRECTORY_BITNR),
429 } QCow2MetadataOverlap;
430
431 /* Perform all overlap checks which can be done in constant time */
432 #define QCOW2_OL_CONSTANT \
433     (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
434      QCOW2_OL_SNAPSHOT_TABLE | QCOW2_OL_BITMAP_DIRECTORY)
435
436 /* Perform all overlap checks which don't require disk access */
437 #define QCOW2_OL_CACHED \
438     (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
439      QCOW2_OL_INACTIVE_L1)
440
441 /* Perform all overlap checks */
442 #define QCOW2_OL_ALL \
443     (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
444
445 #define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
446 #define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
447 #define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
448
449 #define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
450
451 static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset)
452 {
453     return offset & ~(s->cluster_size - 1);
454 }
455
456 static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
457 {
458     return offset & (s->cluster_size - 1);
459 }
460
461 static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
462 {
463     return (size + (s->cluster_size - 1)) >> s->cluster_bits;
464 }
465
466 static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size)
467 {
468     int shift = s->cluster_bits + s->l2_bits;
469     return (size + (1ULL << shift) - 1) >> shift;
470 }
471
472 static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset)
473 {
474     return offset >> (s->l2_bits + s->cluster_bits);
475 }
476
477 static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
478 {
479     return (offset >> s->cluster_bits) & (s->l2_size - 1);
480 }
481
482 static inline int offset_to_l2_slice_index(BDRVQcow2State *s, int64_t offset)
483 {
484     return (offset >> s->cluster_bits) & (s->l2_slice_size - 1);
485 }
486
487 static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)
488 {
489     return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
490 }
491
492 static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
493 {
494     if (l2_entry & QCOW_OFLAG_COMPRESSED) {
495         return QCOW2_CLUSTER_COMPRESSED;
496     } else if (l2_entry & QCOW_OFLAG_ZERO) {
497         if (l2_entry & L2E_OFFSET_MASK) {
498             return QCOW2_CLUSTER_ZERO_ALLOC;
499         }
500         return QCOW2_CLUSTER_ZERO_PLAIN;
501     } else if (!(l2_entry & L2E_OFFSET_MASK)) {
502         return QCOW2_CLUSTER_UNALLOCATED;
503     } else {
504         return QCOW2_CLUSTER_NORMAL;
505     }
506 }
507
508 /* Check whether refcounts are eager or lazy */
509 static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)
510 {
511     return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
512 }
513
514 static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
515 {
516     return m->offset + m->cow_start.offset;
517 }
518
519 static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
520 {
521     return m->offset + m->cow_end.offset + m->cow_end.nb_bytes;
522 }
523
524 static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
525 {
526     return r1 > r2 ? r1 - r2 : r2 - r1;
527 }
528
529 static inline
530 uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset)
531 {
532     return offset >> (s->refcount_block_bits + s->cluster_bits);
533 }
534
535 /* qcow2.c functions */
536 int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
537                                      int refcount_order, bool generous_increase,
538                                      uint64_t *refblock_count);
539
540 int qcow2_mark_dirty(BlockDriverState *bs);
541 int qcow2_mark_corrupt(BlockDriverState *bs);
542 int qcow2_mark_consistent(BlockDriverState *bs);
543 int qcow2_update_header(BlockDriverState *bs);
544
545 void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
546                              int64_t size, const char *message_format, ...)
547                              GCC_FMT_ATTR(5, 6);
548
549 int qcow2_validate_table(BlockDriverState *bs, uint64_t offset,
550                          uint64_t entries, size_t entry_len,
551                          int64_t max_size_bytes, const char *table_name,
552                          Error **errp);
553
554 /* qcow2-refcount.c functions */
555 int qcow2_refcount_init(BlockDriverState *bs);
556 void qcow2_refcount_close(BlockDriverState *bs);
557
558 int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
559                        uint64_t *refcount);
560
561 int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
562                                   uint64_t addend, bool decrease,
563                                   enum qcow2_discard_type type);
564
565 int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
566                             uint64_t additional_clusters, bool exact_size,
567                             int new_refblock_index,
568                             uint64_t new_refblock_offset);
569
570 int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
571 int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
572                                 int64_t nb_clusters);
573 int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
574 void qcow2_free_clusters(BlockDriverState *bs,
575                           int64_t offset, int64_t size,
576                           enum qcow2_discard_type type);
577 void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
578                              int nb_clusters, enum qcow2_discard_type type);
579
580 int qcow2_update_snapshot_refcount(BlockDriverState *bs,
581     int64_t l1_table_offset, int l1_size, int addend);
582
583 int coroutine_fn qcow2_flush_caches(BlockDriverState *bs);
584 int coroutine_fn qcow2_write_caches(BlockDriverState *bs);
585 int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
586                           BdrvCheckMode fix);
587
588 void qcow2_process_discards(BlockDriverState *bs, int ret);
589
590 int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
591                                  int64_t size);
592 int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
593                                   int64_t size);
594 int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
595                              void **refcount_table,
596                              int64_t *refcount_table_size,
597                              int64_t offset, int64_t size);
598
599 int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
600                                 BlockDriverAmendStatusCB *status_cb,
601                                 void *cb_opaque, Error **errp);
602 int qcow2_shrink_reftable(BlockDriverState *bs);
603 int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size);
604
605 /* qcow2-cluster.c functions */
606 int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
607                         bool exact_size);
608 int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size);
609 int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
610 int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
611 int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
612                           uint8_t *buf, int nb_sectors, bool enc, Error **errp);
613
614 int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
615                              unsigned int *bytes, uint64_t *cluster_offset);
616 int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
617                                unsigned int *bytes, uint64_t *host_offset,
618                                QCowL2Meta **m);
619 uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
620                                          uint64_t offset,
621                                          int compressed_size);
622
623 int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
624 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);
625 int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
626                           uint64_t bytes, enum qcow2_discard_type type,
627                           bool full_discard);
628 int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
629                           uint64_t bytes, int flags);
630
631 int qcow2_expand_zero_clusters(BlockDriverState *bs,
632                                BlockDriverAmendStatusCB *status_cb,
633                                void *cb_opaque);
634
635 /* qcow2-snapshot.c functions */
636 int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
637 int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
638 int qcow2_snapshot_delete(BlockDriverState *bs,
639                           const char *snapshot_id,
640                           const char *name,
641                           Error **errp);
642 int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
643 int qcow2_snapshot_load_tmp(BlockDriverState *bs,
644                             const char *snapshot_id,
645                             const char *name,
646                             Error **errp);
647
648 void qcow2_free_snapshots(BlockDriverState *bs);
649 int qcow2_read_snapshots(BlockDriverState *bs);
650
651 /* qcow2-cache.c functions */
652 Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
653                                unsigned table_size);
654 int qcow2_cache_destroy(Qcow2Cache *c);
655
656 void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
657 int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
658 int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c);
659 int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
660     Qcow2Cache *dependency);
661 void qcow2_cache_depends_on_flush(Qcow2Cache *c);
662
663 void qcow2_cache_clean_unused(Qcow2Cache *c);
664 int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
665
666 int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
667     void **table);
668 int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
669     void **table);
670 void qcow2_cache_put(Qcow2Cache *c, void **table);
671 void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64_t offset);
672 void qcow2_cache_discard(Qcow2Cache *c, void *table);
673
674 /* qcow2-bitmap.c functions */
675 int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
676                                   void **refcount_table,
677                                   int64_t *refcount_table_size);
678 bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp);
679 int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_updated,
680                                  Error **errp);
681 int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
682 void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp);
683 int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
684 bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
685                                       const char *name,
686                                       uint32_t granularity,
687                                       Error **errp);
688 void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs,
689                                           const char *name,
690                                           Error **errp);
691
692 #endif
This page took 0.052162 seconds and 2 git commands to generate.