]> Git Repo - qemu.git/blame - block/qcow2.h
block/dirty-bitmap: add deserialize_ones func
[qemu.git] / block / qcow2.h
CommitLineData
f7d0fe02
KW
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
b25b387f 28#include "crypto/block.h"
10817bf0 29#include "qemu/coroutine.h"
f7d0fe02 30
14899cdf
FN
31//#define DEBUG_ALLOC
32//#define DEBUG_ALLOC2
33//#define DEBUG_EXT
34
f7d0fe02 35#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
f7d0fe02
KW
36
37#define QCOW_CRYPT_NONE 0
38#define QCOW_CRYPT_AES 1
4652b8f3 39#define QCOW_CRYPT_LUKS 2
f7d0fe02
KW
40
41#define QCOW_MAX_CRYPT_CLUSTERS 32
ce48f2f4 42#define QCOW_MAX_SNAPSHOTS 65536
f7d0fe02 43
2b5d5953
KW
44/* 8 MB refcount table is enough for 2 PB images at 64k cluster size
45 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
46#define QCOW_MAX_REFTABLE_SIZE 0x800000
47
6a83f8b5
KW
48/* 32 MB L1 table is enough for 2 PB images at 64k cluster size
49 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
50#define QCOW_MAX_L1_SIZE 0x2000000
51
5dae6e30
KW
52/* Allow for an average of 1k per snapshot table entry, should be plenty of
53 * space for snapshot names and IDs */
54#define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
55
f7d0fe02 56/* indicate that the refcount of the referenced cluster is exactly one. */
127c84e1 57#define QCOW_OFLAG_COPIED (1ULL << 63)
f7d0fe02 58/* indicate that the cluster is compressed (they never have the copied flag) */
127c84e1 59#define QCOW_OFLAG_COMPRESSED (1ULL << 62)
6377af48 60/* The cluster reads as all zeros */
127c84e1 61#define QCOW_OFLAG_ZERO (1ULL << 0)
f7d0fe02 62
f7d0fe02 63#define MIN_CLUSTER_BITS 9
80ee15a6 64#define MAX_CLUSTER_BITS 21
f7d0fe02 65
57e21669
HR
66/* Must be at least 2 to cover COW */
67#define MIN_L2_CACHE_SIZE 2 /* clusters */
f7d0fe02 68
29c1a730 69/* Must be at least 4 to cover all cases of refcount table growth */
440ba08a
HR
70#define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
71
bc85ef26
HR
72/* Whichever is more */
73#define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */
440ba08a
HR
74#define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */
75
76/* The refblock cache needs only a fourth of the L2 cache size to cover as many
77 * clusters */
78#define DEFAULT_L2_REFCOUNT_SIZE_RATIO 4
29c1a730 79
99cce9fa
KW
80#define DEFAULT_CLUSTER_SIZE 65536
81
acdfb480 82
64aa99d3
KW
83#define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
84#define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
85#define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
86#define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
05de7e86 87#define QCOW2_OPT_OVERLAP "overlap-check"
ee42b5ce 88#define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
05de7e86
HR
89#define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
90#define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
91#define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
92#define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
93#define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
94#define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
95#define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
96#define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
6c1c8d5d
HR
97#define QCOW2_OPT_CACHE_SIZE "cache-size"
98#define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
99#define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
279621c0 100#define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
acdfb480 101
f7d0fe02
KW
102typedef struct QCowHeader {
103 uint32_t magic;
104 uint32_t version;
105 uint64_t backing_file_offset;
106 uint32_t backing_file_size;
107 uint32_t cluster_bits;
108 uint64_t size; /* in bytes */
109 uint32_t crypt_method;
110 uint32_t l1_size; /* XXX: save number of clusters instead ? */
111 uint64_t l1_table_offset;
112 uint64_t refcount_table_offset;
113 uint32_t refcount_table_clusters;
114 uint32_t nb_snapshots;
115 uint64_t snapshots_offset;
6744cbab
KW
116
117 /* The following fields are only valid for version >= 3 */
118 uint64_t incompatible_features;
119 uint64_t compatible_features;
120 uint64_t autoclear_features;
121
122 uint32_t refcount_order;
123 uint32_t header_length;
c4217f64 124} QEMU_PACKED QCowHeader;
f7d0fe02 125
ce48f2f4
KW
126typedef struct QEMU_PACKED QCowSnapshotHeader {
127 /* header is 8 byte aligned */
128 uint64_t l1_table_offset;
129
130 uint32_t l1_size;
131 uint16_t id_str_size;
132 uint16_t name_size;
133
134 uint32_t date_sec;
135 uint32_t date_nsec;
136
137 uint64_t vm_clock_nsec;
138
139 uint32_t vm_state_size;
140 uint32_t extra_data_size; /* for extension */
141 /* extra data follows */
142 /* id_str follows */
143 /* name follows */
144} QCowSnapshotHeader;
145
146typedef struct QEMU_PACKED QCowSnapshotExtraData {
147 uint64_t vm_state_size_large;
148 uint64_t disk_size;
149} QCowSnapshotExtraData;
150
151
f7d0fe02
KW
152typedef struct QCowSnapshot {
153 uint64_t l1_table_offset;
154 uint32_t l1_size;
155 char *id_str;
156 char *name;
90b27759 157 uint64_t disk_size;
c2c9a466 158 uint64_t vm_state_size;
f7d0fe02
KW
159 uint32_t date_sec;
160 uint32_t date_nsec;
161 uint64_t vm_clock_nsec;
162} QCowSnapshot;
163
49381094
KW
164struct Qcow2Cache;
165typedef struct Qcow2Cache Qcow2Cache;
166
4652b8f3
DB
167typedef struct Qcow2CryptoHeaderExtension {
168 uint64_t offset;
169 uint64_t length;
170} QEMU_PACKED Qcow2CryptoHeaderExtension;
171
75bab85c
KW
172typedef struct Qcow2UnknownHeaderExtension {
173 uint32_t magic;
174 uint32_t len;
175 QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
176 uint8_t data[];
177} Qcow2UnknownHeaderExtension;
178
cfcc4c62
KW
179enum {
180 QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
181 QCOW2_FEAT_TYPE_COMPATIBLE = 1,
182 QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
183};
184
c61d0004
SH
185/* Incompatible feature bits */
186enum {
187 QCOW2_INCOMPAT_DIRTY_BITNR = 0,
69c98726 188 QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
c61d0004 189 QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
69c98726 190 QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
c61d0004 191
69c98726
HR
192 QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY
193 | QCOW2_INCOMPAT_CORRUPT,
c61d0004
SH
194};
195
bfe8043e
SH
196/* Compatible feature bits */
197enum {
198 QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
199 QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
200
201 QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS,
202};
203
6cfcb9b8
KW
204enum qcow2_discard_type {
205 QCOW2_DISCARD_NEVER = 0,
206 QCOW2_DISCARD_ALWAYS,
207 QCOW2_DISCARD_REQUEST,
208 QCOW2_DISCARD_SNAPSHOT,
209 QCOW2_DISCARD_OTHER,
210 QCOW2_DISCARD_MAX
211};
212
cfcc4c62
KW
213typedef struct Qcow2Feature {
214 uint8_t type;
215 uint8_t bit;
216 char name[46];
217} QEMU_PACKED Qcow2Feature;
218
0b919fae
KW
219typedef struct Qcow2DiscardRegion {
220 BlockDriverState *bs;
221 uint64_t offset;
222 uint64_t bytes;
223 QTAILQ_ENTRY(Qcow2DiscardRegion) next;
224} Qcow2DiscardRegion;
225
7453c96b
HR
226typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
227 uint64_t index);
228typedef void Qcow2SetRefcountFunc(void *refcount_array,
229 uint64_t index, uint64_t value);
230
ff99129a 231typedef struct BDRVQcow2State {
f7d0fe02
KW
232 int cluster_bits;
233 int cluster_size;
234 int cluster_sectors;
235 int l2_bits;
236 int l2_size;
237 int l1_size;
238 int l1_vm_state_index;
1d13d654
HR
239 int refcount_block_bits;
240 int refcount_block_size;
f7d0fe02
KW
241 int csize_shift;
242 int csize_mask;
243 uint64_t cluster_offset_mask;
244 uint64_t l1_table_offset;
245 uint64_t *l1_table;
29c1a730
KW
246
247 Qcow2Cache* l2_table_cache;
248 Qcow2Cache* refcount_block_cache;
279621c0
AG
249 QEMUTimer *cache_clean_timer;
250 unsigned cache_clean_interval;
29c1a730 251
f7d0fe02
KW
252 uint8_t *cluster_cache;
253 uint8_t *cluster_data;
254 uint64_t cluster_cache_offset;
72cf2d4f 255 QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs;
f7d0fe02
KW
256
257 uint64_t *refcount_table;
258 uint64_t refcount_table_offset;
259 uint32_t refcount_table_size;
7061a078 260 uint32_t max_refcount_table_index; /* Last used entry in refcount_table */
bb572aef
KW
261 uint64_t free_cluster_index;
262 uint64_t free_byte_offset;
f7d0fe02 263
68d100e9
KW
264 CoMutex lock;
265
4652b8f3 266 Qcow2CryptoHeaderExtension crypto_header; /* QCow2 header extension */
b25b387f
DB
267 QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime options */
268 QCryptoBlock *crypto; /* Disk encryption format driver */
4652b8f3
DB
269 bool crypt_physical_offset; /* Whether to use virtual or physical offset
270 for encryption initialization vector tweak */
f7d0fe02 271 uint32_t crypt_method_header;
f7d0fe02
KW
272 uint64_t snapshots_offset;
273 int snapshots_size;
ce48f2f4 274 unsigned int nb_snapshots;
f7d0fe02 275 QCowSnapshot *snapshots;
06d9260f
AL
276
277 int flags;
6744cbab 278 int qcow_version;
74c4510a 279 bool use_lazy_refcounts;
b6481f37 280 int refcount_order;
346a53df
HR
281 int refcount_bits;
282 uint64_t refcount_max;
6744cbab 283
7453c96b
HR
284 Qcow2GetRefcountFunc *get_refcount;
285 Qcow2SetRefcountFunc *set_refcount;
286
67af674e
KW
287 bool discard_passthrough[QCOW2_DISCARD_MAX];
288
3e355390 289 int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
85186ebd 290 bool signaled_corruption;
3e355390 291
6744cbab
KW
292 uint64_t incompatible_features;
293 uint64_t compatible_features;
294 uint64_t autoclear_features;
295
296 size_t unknown_header_fields_size;
297 void* unknown_header_fields;
75bab85c 298 QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
0b919fae
KW
299 QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
300 bool cache_discards;
e4603fe1
KW
301
302 /* Backing file path and format as stored in the image (this is not the
303 * effective path/format, which may be the result of a runtime option
304 * override) */
305 char *image_backing_file;
306 char *image_backing_format;
ff99129a 307} BDRVQcow2State;
f7d0fe02 308
593fb83c
KW
309typedef struct Qcow2COWRegion {
310 /**
311 * Offset of the COW region in bytes from the start of the first cluster
312 * touched by the request.
313 */
e034f5bc 314 unsigned offset;
593fb83c 315
85567393 316 /** Number of bytes to copy */
e034f5bc 317 unsigned nb_bytes;
593fb83c
KW
318} Qcow2COWRegion;
319
f50f88b9
KW
320/**
321 * Describes an in-flight (part of a) write request that writes to clusters
322 * that are not referenced in their L2 table yet.
323 */
45aba42f
KW
324typedef struct QCowL2Meta
325{
1d3afd64 326 /** Guest offset of the first newly allocated cluster */
45aba42f 327 uint64_t offset;
1d3afd64 328
1d3afd64 329 /** Host offset of the first newly allocated cluster */
250196f1 330 uint64_t alloc_offset;
1d3afd64 331
1d3afd64 332 /** Number of newly allocated clusters */
45aba42f 333 int nb_clusters;
1d3afd64 334
564a6b69
HR
335 /** Do not free the old clusters */
336 bool keep_old_clusters;
337
1d3afd64
KW
338 /**
339 * Requests that overlap with this allocation and wait to be restarted
340 * when the allocating request has completed.
341 */
68d100e9 342 CoQueue dependent_requests;
f214978a 343
593fb83c
KW
344 /**
345 * The COW Region between the start of the first allocated cluster and the
346 * area the guest actually writes to.
347 */
348 Qcow2COWRegion cow_start;
349
350 /**
351 * The COW Region between the area the guest actually writes to and the
352 * end of the last allocated cluster.
353 */
354 Qcow2COWRegion cow_end;
355
ee22a9d8
AG
356 /**
357 * The I/O vector with the data from the actual guest write request.
358 * If non-NULL, this is meant to be merged together with the data
359 * from @cow_start and @cow_end into one single write operation.
360 */
361 QEMUIOVector *data_qiov;
362
88c6588c
KW
363 /** Pointer to next L2Meta of the same write request */
364 struct QCowL2Meta *next;
365
72cf2d4f 366 QLIST_ENTRY(QCowL2Meta) next_in_flight;
45aba42f
KW
367} QCowL2Meta;
368
3ef95218 369typedef enum QCow2ClusterType {
68d000a3 370 QCOW2_CLUSTER_UNALLOCATED,
fdfab37d
EB
371 QCOW2_CLUSTER_ZERO_PLAIN,
372 QCOW2_CLUSTER_ZERO_ALLOC,
68d000a3
KW
373 QCOW2_CLUSTER_NORMAL,
374 QCOW2_CLUSTER_COMPRESSED,
3ef95218 375} QCow2ClusterType;
68d000a3 376
a40f1c2a
HR
377typedef enum QCow2MetadataOverlap {
378 QCOW2_OL_MAIN_HEADER_BITNR = 0,
379 QCOW2_OL_ACTIVE_L1_BITNR = 1,
380 QCOW2_OL_ACTIVE_L2_BITNR = 2,
381 QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
382 QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
383 QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
384 QCOW2_OL_INACTIVE_L1_BITNR = 6,
385 QCOW2_OL_INACTIVE_L2_BITNR = 7,
386
387 QCOW2_OL_MAX_BITNR = 8,
388
389 QCOW2_OL_NONE = 0,
390 QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
391 QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
392 QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
393 QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
394 QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
395 QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
396 QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
397 /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
398 * reads. */
399 QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
400} QCow2MetadataOverlap;
401
4a273c39
HR
402/* Perform all overlap checks which can be done in constant time */
403#define QCOW2_OL_CONSTANT \
404 (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
405 QCOW2_OL_SNAPSHOT_TABLE)
406
a40f1c2a
HR
407/* Perform all overlap checks which don't require disk access */
408#define QCOW2_OL_CACHED \
4a273c39
HR
409 (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
410 QCOW2_OL_INACTIVE_L1)
411
412/* Perform all overlap checks */
413#define QCOW2_OL_ALL \
414 (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
a40f1c2a 415
46bae927
HT
416#define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
417#define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
68d000a3
KW
418#define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
419
46bae927 420#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
76dc9e0c 421
ff99129a 422static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset)
3b8e2e26
KW
423{
424 return offset & ~(s->cluster_size - 1);
425}
426
ff99129a 427static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
c37f4cd7
KW
428{
429 return offset & (s->cluster_size - 1);
430}
431
b6d36def 432static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
f7d0fe02
KW
433{
434 return (size + (s->cluster_size - 1)) >> s->cluster_bits;
435}
436
ff99129a 437static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size)
419b19d9
SH
438{
439 int shift = s->cluster_bits + s->l2_bits;
440 return (size + (1ULL << shift) - 1) >> shift;
441}
442
ff99129a 443static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
17a71e58
KW
444{
445 return (offset >> s->cluster_bits) & (s->l2_size - 1);
446}
447
c142442b
KW
448static inline int64_t align_offset(int64_t offset, int n)
449{
450 offset = (offset + n - 1) & ~(n - 1);
451 return offset;
452}
453
ff99129a 454static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)
1ebf561c
KW
455{
456 return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
457}
458
ff99129a 459static inline uint64_t qcow2_max_refcount_clusters(BDRVQcow2State *s)
2b5d5953
KW
460{
461 return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
462}
463
3ef95218 464static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
68d000a3
KW
465{
466 if (l2_entry & QCOW_OFLAG_COMPRESSED) {
467 return QCOW2_CLUSTER_COMPRESSED;
6377af48 468 } else if (l2_entry & QCOW_OFLAG_ZERO) {
fdfab37d
EB
469 if (l2_entry & L2E_OFFSET_MASK) {
470 return QCOW2_CLUSTER_ZERO_ALLOC;
471 }
472 return QCOW2_CLUSTER_ZERO_PLAIN;
68d000a3
KW
473 } else if (!(l2_entry & L2E_OFFSET_MASK)) {
474 return QCOW2_CLUSTER_UNALLOCATED;
475 } else {
476 return QCOW2_CLUSTER_NORMAL;
477 }
478}
479
bfe8043e 480/* Check whether refcounts are eager or lazy */
ff99129a 481static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)
bfe8043e
SH
482{
483 return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
484}
c142442b 485
65eb2e35
KW
486static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
487{
488 return m->offset + m->cow_start.offset;
489}
490
491static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
492{
85567393 493 return m->offset + m->cow_end.offset + m->cow_end.nb_bytes;
65eb2e35
KW
494}
495
0e06528e 496static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
2aabe7c7
HR
497{
498 return r1 > r2 ? r1 - r2 : r2 - r1;
499}
500
f7d0fe02 501/* qcow2.c functions */
bd28f835
KW
502int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
503 int64_t sector_num, int nb_sectors);
280d3735
KW
504
505int qcow2_mark_dirty(BlockDriverState *bs);
69c98726
HR
506int qcow2_mark_corrupt(BlockDriverState *bs);
507int qcow2_mark_consistent(BlockDriverState *bs);
e24e49e6 508int qcow2_update_header(BlockDriverState *bs);
f7d0fe02 509
85186ebd
HR
510void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
511 int64_t size, const char *message_format, ...)
512 GCC_FMT_ATTR(5, 6);
513
f7d0fe02 514/* qcow2-refcount.c functions */
ed6ccf0f
KW
515int qcow2_refcount_init(BlockDriverState *bs);
516void qcow2_refcount_close(BlockDriverState *bs);
f7d0fe02 517
7324c10f 518int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
0e06528e 519 uint64_t *refcount);
44751917 520
32b6444d 521int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
0e06528e 522 uint64_t addend, bool decrease,
2aabe7c7 523 enum qcow2_discard_type type);
32b6444d 524
bb572aef 525int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
b6d36def
HR
526int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
527 int64_t nb_clusters);
ed6ccf0f
KW
528int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
529void qcow2_free_clusters(BlockDriverState *bs,
6cfcb9b8
KW
530 int64_t offset, int64_t size,
531 enum qcow2_discard_type type);
532void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
533 int nb_clusters, enum qcow2_discard_type type);
f7d0fe02 534
ed6ccf0f
KW
535int qcow2_update_snapshot_refcount(BlockDriverState *bs,
536 int64_t l1_table_offset, int l1_size, int addend);
f7d0fe02 537
166acf54
KW
538int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
539 BdrvCheckMode fix);
f7d0fe02 540
0b919fae
KW
541void qcow2_process_discards(BlockDriverState *bs, int ret);
542
231bb267 543int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
a40f1c2a 544 int64_t size);
231bb267 545int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
a40f1c2a
HR
546 int64_t size);
547
791c9a00
HR
548int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
549 BlockDriverAmendStatusCB *status_cb,
550 void *cb_opaque, Error **errp);
551
45aba42f 552/* qcow2-cluster.c functions */
2cf7cfa1
KW
553int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
554 bool exact_size);
e23e400e 555int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
66f82cee 556int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
ff99129a 557int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
446d306d 558 uint8_t *buf, int nb_sectors, bool enc, Error **errp);
45aba42f 559
1c46efaa 560int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
ecfe1863 561 unsigned int *bytes, uint64_t *cluster_offset);
f4f0d391 562int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
d46a0bb2
KW
563 unsigned int *bytes, uint64_t *host_offset,
564 QCowL2Meta **m);
ed6ccf0f 565uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
45aba42f
KW
566 uint64_t offset,
567 int compressed_size);
568
148da7ea 569int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
d2cb36af
EB
570int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
571 uint64_t bytes, enum qcow2_discard_type type,
572 bool full_discard);
573int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
574 uint64_t bytes, int flags);
45aba42f 575
4057a2b2 576int qcow2_expand_zero_clusters(BlockDriverState *bs,
8b13976d
HR
577 BlockDriverAmendStatusCB *status_cb,
578 void *cb_opaque);
32b6444d 579
c142442b 580/* qcow2-snapshot.c functions */
ed6ccf0f
KW
581int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
582int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
a89d89d3
WX
583int qcow2_snapshot_delete(BlockDriverState *bs,
584 const char *snapshot_id,
585 const char *name,
586 Error **errp);
ed6ccf0f 587int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
7b4c4781
WX
588int qcow2_snapshot_load_tmp(BlockDriverState *bs,
589 const char *snapshot_id,
590 const char *name,
591 Error **errp);
c142442b 592
ed6ccf0f
KW
593void qcow2_free_snapshots(BlockDriverState *bs);
594int qcow2_read_snapshots(BlockDriverState *bs);
c142442b 595
49381094 596/* qcow2-cache.c functions */
6af4e9ea 597Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);
49381094
KW
598int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
599
72e80b89
AG
600void qcow2_cache_entry_mark_dirty(BlockDriverState *bs, Qcow2Cache *c,
601 void *table);
49381094 602int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
f3c3b87d 603int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c);
49381094
KW
604int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
605 Qcow2Cache *dependency);
3de0a294 606void qcow2_cache_depends_on_flush(Qcow2Cache *c);
49381094 607
279621c0 608void qcow2_cache_clean_unused(BlockDriverState *bs, Qcow2Cache *c);
e7108fea
HR
609int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
610
49381094
KW
611int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
612 void **table);
613int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
614 void **table);
a3f1afb4 615void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table);
49381094 616
f7d0fe02 617#endif
This page took 0.56105 seconds and 4 git commands to generate.