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