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