root / block / qcow2.h @ 737e150e
History | View | Annotate | Download (11.4 kB)
1 | f7d0fe02 | Kevin Wolf | /*
|
---|---|---|---|
2 | f7d0fe02 | Kevin Wolf | * Block driver for the QCOW version 2 format
|
3 | f7d0fe02 | Kevin Wolf | *
|
4 | f7d0fe02 | Kevin Wolf | * Copyright (c) 2004-2006 Fabrice Bellard
|
5 | f7d0fe02 | Kevin Wolf | *
|
6 | f7d0fe02 | Kevin Wolf | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | f7d0fe02 | Kevin Wolf | * of this software and associated documentation files (the "Software"), to deal
|
8 | f7d0fe02 | Kevin Wolf | * in the Software without restriction, including without limitation the rights
|
9 | f7d0fe02 | Kevin Wolf | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | f7d0fe02 | Kevin Wolf | * copies of the Software, and to permit persons to whom the Software is
|
11 | f7d0fe02 | Kevin Wolf | * furnished to do so, subject to the following conditions:
|
12 | f7d0fe02 | Kevin Wolf | *
|
13 | f7d0fe02 | Kevin Wolf | * The above copyright notice and this permission notice shall be included in
|
14 | f7d0fe02 | Kevin Wolf | * all copies or substantial portions of the Software.
|
15 | f7d0fe02 | Kevin Wolf | *
|
16 | f7d0fe02 | Kevin Wolf | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | f7d0fe02 | Kevin Wolf | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | f7d0fe02 | Kevin Wolf | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | f7d0fe02 | Kevin Wolf | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | f7d0fe02 | Kevin Wolf | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | f7d0fe02 | Kevin Wolf | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | f7d0fe02 | Kevin Wolf | * THE SOFTWARE.
|
23 | f7d0fe02 | Kevin Wolf | */
|
24 | f7d0fe02 | Kevin Wolf | |
25 | f7d0fe02 | Kevin Wolf | #ifndef BLOCK_QCOW2_H
|
26 | f7d0fe02 | Kevin Wolf | #define BLOCK_QCOW2_H
|
27 | f7d0fe02 | Kevin Wolf | |
28 | 737e150e | Paolo Bonzini | #include "block/aes.h" |
29 | 737e150e | Paolo Bonzini | #include "block/coroutine.h" |
30 | f7d0fe02 | Kevin Wolf | |
31 | 14899cdf | Filip Navara | //#define DEBUG_ALLOC
|
32 | 14899cdf | Filip Navara | //#define DEBUG_ALLOC2
|
33 | 14899cdf | Filip Navara | //#define DEBUG_EXT
|
34 | 14899cdf | Filip Navara | |
35 | f7d0fe02 | Kevin Wolf | #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) |
36 | f7d0fe02 | Kevin Wolf | |
37 | f7d0fe02 | Kevin Wolf | #define QCOW_CRYPT_NONE 0 |
38 | f7d0fe02 | Kevin Wolf | #define QCOW_CRYPT_AES 1 |
39 | f7d0fe02 | Kevin Wolf | |
40 | f7d0fe02 | Kevin Wolf | #define QCOW_MAX_CRYPT_CLUSTERS 32 |
41 | f7d0fe02 | Kevin Wolf | |
42 | f7d0fe02 | Kevin Wolf | /* indicate that the refcount of the referenced cluster is exactly one. */
|
43 | f7d0fe02 | Kevin Wolf | #define QCOW_OFLAG_COPIED (1LL << 63) |
44 | f7d0fe02 | Kevin Wolf | /* indicate that the cluster is compressed (they never have the copied flag) */
|
45 | f7d0fe02 | Kevin Wolf | #define QCOW_OFLAG_COMPRESSED (1LL << 62) |
46 | 6377af48 | Kevin Wolf | /* The cluster reads as all zeros */
|
47 | 6377af48 | Kevin Wolf | #define QCOW_OFLAG_ZERO (1LL << 0) |
48 | f7d0fe02 | Kevin Wolf | |
49 | f7d0fe02 | Kevin Wolf | #define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */ |
50 | f7d0fe02 | Kevin Wolf | |
51 | f7d0fe02 | Kevin Wolf | #define MIN_CLUSTER_BITS 9 |
52 | 80ee15a6 | Kevin Wolf | #define MAX_CLUSTER_BITS 21 |
53 | f7d0fe02 | Kevin Wolf | |
54 | f7d0fe02 | Kevin Wolf | #define L2_CACHE_SIZE 16 |
55 | f7d0fe02 | Kevin Wolf | |
56 | 29c1a730 | Kevin Wolf | /* Must be at least 4 to cover all cases of refcount table growth */
|
57 | 29c1a730 | Kevin Wolf | #define REFCOUNT_CACHE_SIZE 4 |
58 | 29c1a730 | Kevin Wolf | |
59 | 99cce9fa | Kevin Wolf | #define DEFAULT_CLUSTER_SIZE 65536 |
60 | 99cce9fa | Kevin Wolf | |
61 | f7d0fe02 | Kevin Wolf | typedef struct QCowHeader { |
62 | f7d0fe02 | Kevin Wolf | uint32_t magic; |
63 | f7d0fe02 | Kevin Wolf | uint32_t version; |
64 | f7d0fe02 | Kevin Wolf | uint64_t backing_file_offset; |
65 | f7d0fe02 | Kevin Wolf | uint32_t backing_file_size; |
66 | f7d0fe02 | Kevin Wolf | uint32_t cluster_bits; |
67 | f7d0fe02 | Kevin Wolf | uint64_t size; /* in bytes */
|
68 | f7d0fe02 | Kevin Wolf | uint32_t crypt_method; |
69 | f7d0fe02 | Kevin Wolf | uint32_t l1_size; /* XXX: save number of clusters instead ? */
|
70 | f7d0fe02 | Kevin Wolf | uint64_t l1_table_offset; |
71 | f7d0fe02 | Kevin Wolf | uint64_t refcount_table_offset; |
72 | f7d0fe02 | Kevin Wolf | uint32_t refcount_table_clusters; |
73 | f7d0fe02 | Kevin Wolf | uint32_t nb_snapshots; |
74 | f7d0fe02 | Kevin Wolf | uint64_t snapshots_offset; |
75 | 6744cbab | Kevin Wolf | |
76 | 6744cbab | Kevin Wolf | /* The following fields are only valid for version >= 3 */
|
77 | 6744cbab | Kevin Wolf | uint64_t incompatible_features; |
78 | 6744cbab | Kevin Wolf | uint64_t compatible_features; |
79 | 6744cbab | Kevin Wolf | uint64_t autoclear_features; |
80 | 6744cbab | Kevin Wolf | |
81 | 6744cbab | Kevin Wolf | uint32_t refcount_order; |
82 | 6744cbab | Kevin Wolf | uint32_t header_length; |
83 | f7d0fe02 | Kevin Wolf | } QCowHeader; |
84 | f7d0fe02 | Kevin Wolf | |
85 | f7d0fe02 | Kevin Wolf | typedef struct QCowSnapshot { |
86 | f7d0fe02 | Kevin Wolf | uint64_t l1_table_offset; |
87 | f7d0fe02 | Kevin Wolf | uint32_t l1_size; |
88 | f7d0fe02 | Kevin Wolf | char *id_str;
|
89 | f7d0fe02 | Kevin Wolf | char *name;
|
90 | 90b27759 | Kevin Wolf | uint64_t disk_size; |
91 | c2c9a466 | Kevin Wolf | uint64_t vm_state_size; |
92 | f7d0fe02 | Kevin Wolf | uint32_t date_sec; |
93 | f7d0fe02 | Kevin Wolf | uint32_t date_nsec; |
94 | f7d0fe02 | Kevin Wolf | uint64_t vm_clock_nsec; |
95 | f7d0fe02 | Kevin Wolf | } QCowSnapshot; |
96 | f7d0fe02 | Kevin Wolf | |
97 | 49381094 | Kevin Wolf | struct Qcow2Cache;
|
98 | 49381094 | Kevin Wolf | typedef struct Qcow2Cache Qcow2Cache; |
99 | 49381094 | Kevin Wolf | |
100 | 75bab85c | Kevin Wolf | typedef struct Qcow2UnknownHeaderExtension { |
101 | 75bab85c | Kevin Wolf | uint32_t magic; |
102 | 75bab85c | Kevin Wolf | uint32_t len; |
103 | 75bab85c | Kevin Wolf | QLIST_ENTRY(Qcow2UnknownHeaderExtension) next; |
104 | 75bab85c | Kevin Wolf | uint8_t data[]; |
105 | 75bab85c | Kevin Wolf | } Qcow2UnknownHeaderExtension; |
106 | 75bab85c | Kevin Wolf | |
107 | cfcc4c62 | Kevin Wolf | enum {
|
108 | cfcc4c62 | Kevin Wolf | QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
|
109 | cfcc4c62 | Kevin Wolf | QCOW2_FEAT_TYPE_COMPATIBLE = 1,
|
110 | cfcc4c62 | Kevin Wolf | QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
|
111 | cfcc4c62 | Kevin Wolf | }; |
112 | cfcc4c62 | Kevin Wolf | |
113 | c61d0004 | Stefan Hajnoczi | /* Incompatible feature bits */
|
114 | c61d0004 | Stefan Hajnoczi | enum {
|
115 | c61d0004 | Stefan Hajnoczi | QCOW2_INCOMPAT_DIRTY_BITNR = 0,
|
116 | c61d0004 | Stefan Hajnoczi | QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
|
117 | c61d0004 | Stefan Hajnoczi | |
118 | c61d0004 | Stefan Hajnoczi | QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY, |
119 | c61d0004 | Stefan Hajnoczi | }; |
120 | c61d0004 | Stefan Hajnoczi | |
121 | bfe8043e | Stefan Hajnoczi | /* Compatible feature bits */
|
122 | bfe8043e | Stefan Hajnoczi | enum {
|
123 | bfe8043e | Stefan Hajnoczi | QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
|
124 | bfe8043e | Stefan Hajnoczi | QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
|
125 | bfe8043e | Stefan Hajnoczi | |
126 | bfe8043e | Stefan Hajnoczi | QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS, |
127 | bfe8043e | Stefan Hajnoczi | }; |
128 | bfe8043e | Stefan Hajnoczi | |
129 | cfcc4c62 | Kevin Wolf | typedef struct Qcow2Feature { |
130 | cfcc4c62 | Kevin Wolf | uint8_t type; |
131 | cfcc4c62 | Kevin Wolf | uint8_t bit; |
132 | cfcc4c62 | Kevin Wolf | char name[46]; |
133 | cfcc4c62 | Kevin Wolf | } QEMU_PACKED Qcow2Feature; |
134 | cfcc4c62 | Kevin Wolf | |
135 | f7d0fe02 | Kevin Wolf | typedef struct BDRVQcowState { |
136 | f7d0fe02 | Kevin Wolf | int cluster_bits;
|
137 | f7d0fe02 | Kevin Wolf | int cluster_size;
|
138 | f7d0fe02 | Kevin Wolf | int cluster_sectors;
|
139 | f7d0fe02 | Kevin Wolf | int l2_bits;
|
140 | f7d0fe02 | Kevin Wolf | int l2_size;
|
141 | f7d0fe02 | Kevin Wolf | int l1_size;
|
142 | f7d0fe02 | Kevin Wolf | int l1_vm_state_index;
|
143 | f7d0fe02 | Kevin Wolf | int csize_shift;
|
144 | f7d0fe02 | Kevin Wolf | int csize_mask;
|
145 | f7d0fe02 | Kevin Wolf | uint64_t cluster_offset_mask; |
146 | f7d0fe02 | Kevin Wolf | uint64_t l1_table_offset; |
147 | f7d0fe02 | Kevin Wolf | uint64_t *l1_table; |
148 | 29c1a730 | Kevin Wolf | |
149 | 29c1a730 | Kevin Wolf | Qcow2Cache* l2_table_cache; |
150 | 29c1a730 | Kevin Wolf | Qcow2Cache* refcount_block_cache; |
151 | 29c1a730 | Kevin Wolf | |
152 | f7d0fe02 | Kevin Wolf | uint8_t *cluster_cache; |
153 | f7d0fe02 | Kevin Wolf | uint8_t *cluster_data; |
154 | f7d0fe02 | Kevin Wolf | uint64_t cluster_cache_offset; |
155 | 72cf2d4f | Blue Swirl | QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs; |
156 | f7d0fe02 | Kevin Wolf | |
157 | f7d0fe02 | Kevin Wolf | uint64_t *refcount_table; |
158 | f7d0fe02 | Kevin Wolf | uint64_t refcount_table_offset; |
159 | f7d0fe02 | Kevin Wolf | uint32_t refcount_table_size; |
160 | f7d0fe02 | Kevin Wolf | int64_t free_cluster_index; |
161 | f7d0fe02 | Kevin Wolf | int64_t free_byte_offset; |
162 | f7d0fe02 | Kevin Wolf | |
163 | 68d100e9 | Kevin Wolf | CoMutex lock; |
164 | 68d100e9 | Kevin Wolf | |
165 | f7d0fe02 | Kevin Wolf | uint32_t crypt_method; /* current crypt method, 0 if no key yet */
|
166 | f7d0fe02 | Kevin Wolf | uint32_t crypt_method_header; |
167 | f7d0fe02 | Kevin Wolf | AES_KEY aes_encrypt_key; |
168 | f7d0fe02 | Kevin Wolf | AES_KEY aes_decrypt_key; |
169 | f7d0fe02 | Kevin Wolf | uint64_t snapshots_offset; |
170 | f7d0fe02 | Kevin Wolf | int snapshots_size;
|
171 | f7d0fe02 | Kevin Wolf | int nb_snapshots;
|
172 | f7d0fe02 | Kevin Wolf | QCowSnapshot *snapshots; |
173 | 06d9260f | Anthony Liguori | |
174 | 06d9260f | Anthony Liguori | int flags;
|
175 | 6744cbab | Kevin Wolf | int qcow_version;
|
176 | 6744cbab | Kevin Wolf | |
177 | 6744cbab | Kevin Wolf | uint64_t incompatible_features; |
178 | 6744cbab | Kevin Wolf | uint64_t compatible_features; |
179 | 6744cbab | Kevin Wolf | uint64_t autoclear_features; |
180 | 6744cbab | Kevin Wolf | |
181 | 6744cbab | Kevin Wolf | size_t unknown_header_fields_size; |
182 | 6744cbab | Kevin Wolf | void* unknown_header_fields;
|
183 | 75bab85c | Kevin Wolf | QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext; |
184 | f7d0fe02 | Kevin Wolf | } BDRVQcowState; |
185 | f7d0fe02 | Kevin Wolf | |
186 | f7d0fe02 | Kevin Wolf | /* XXX: use std qcow open function ? */
|
187 | f7d0fe02 | Kevin Wolf | typedef struct QCowCreateState { |
188 | f7d0fe02 | Kevin Wolf | int cluster_size;
|
189 | f7d0fe02 | Kevin Wolf | int cluster_bits;
|
190 | f7d0fe02 | Kevin Wolf | uint16_t *refcount_block; |
191 | f7d0fe02 | Kevin Wolf | uint64_t *refcount_table; |
192 | f7d0fe02 | Kevin Wolf | int64_t l1_table_offset; |
193 | f7d0fe02 | Kevin Wolf | int64_t refcount_table_offset; |
194 | f7d0fe02 | Kevin Wolf | int64_t refcount_block_offset; |
195 | f7d0fe02 | Kevin Wolf | } QCowCreateState; |
196 | f7d0fe02 | Kevin Wolf | |
197 | f214978a | Kevin Wolf | struct QCowAIOCB;
|
198 | f214978a | Kevin Wolf | |
199 | 593fb83c | Kevin Wolf | typedef struct Qcow2COWRegion { |
200 | 593fb83c | Kevin Wolf | /**
|
201 | 593fb83c | Kevin Wolf | * Offset of the COW region in bytes from the start of the first cluster
|
202 | 593fb83c | Kevin Wolf | * touched by the request.
|
203 | 593fb83c | Kevin Wolf | */
|
204 | 593fb83c | Kevin Wolf | uint64_t offset; |
205 | 593fb83c | Kevin Wolf | |
206 | 593fb83c | Kevin Wolf | /** Number of sectors to copy */
|
207 | 593fb83c | Kevin Wolf | int nb_sectors;
|
208 | 593fb83c | Kevin Wolf | } Qcow2COWRegion; |
209 | 593fb83c | Kevin Wolf | |
210 | f50f88b9 | Kevin Wolf | /**
|
211 | f50f88b9 | Kevin Wolf | * Describes an in-flight (part of a) write request that writes to clusters
|
212 | f50f88b9 | Kevin Wolf | * that are not referenced in their L2 table yet.
|
213 | f50f88b9 | Kevin Wolf | */
|
214 | 45aba42f | Kevin Wolf | typedef struct QCowL2Meta |
215 | 45aba42f | Kevin Wolf | { |
216 | 1d3afd64 | Kevin Wolf | /** Guest offset of the first newly allocated cluster */
|
217 | 45aba42f | Kevin Wolf | uint64_t offset; |
218 | 1d3afd64 | Kevin Wolf | |
219 | 1d3afd64 | Kevin Wolf | /** Host offset of the first newly allocated cluster */
|
220 | 250196f1 | Kevin Wolf | uint64_t alloc_offset; |
221 | 1d3afd64 | Kevin Wolf | |
222 | 1d3afd64 | Kevin Wolf | /**
|
223 | 1d3afd64 | Kevin Wolf | * Number of sectors from the start of the first allocated cluster to
|
224 | 1d3afd64 | Kevin Wolf | * the end of the (possibly shortened) request
|
225 | 1d3afd64 | Kevin Wolf | */
|
226 | 45aba42f | Kevin Wolf | int nb_available;
|
227 | 1d3afd64 | Kevin Wolf | |
228 | 1d3afd64 | Kevin Wolf | /** Number of newly allocated clusters */
|
229 | 45aba42f | Kevin Wolf | int nb_clusters;
|
230 | 1d3afd64 | Kevin Wolf | |
231 | 1d3afd64 | Kevin Wolf | /**
|
232 | 1d3afd64 | Kevin Wolf | * Requests that overlap with this allocation and wait to be restarted
|
233 | 1d3afd64 | Kevin Wolf | * when the allocating request has completed.
|
234 | 1d3afd64 | Kevin Wolf | */
|
235 | 68d100e9 | Kevin Wolf | CoQueue dependent_requests; |
236 | f214978a | Kevin Wolf | |
237 | 593fb83c | Kevin Wolf | /**
|
238 | 593fb83c | Kevin Wolf | * The COW Region between the start of the first allocated cluster and the
|
239 | 593fb83c | Kevin Wolf | * area the guest actually writes to.
|
240 | 593fb83c | Kevin Wolf | */
|
241 | 593fb83c | Kevin Wolf | Qcow2COWRegion cow_start; |
242 | 593fb83c | Kevin Wolf | |
243 | 593fb83c | Kevin Wolf | /**
|
244 | 593fb83c | Kevin Wolf | * The COW Region between the area the guest actually writes to and the
|
245 | 593fb83c | Kevin Wolf | * end of the last allocated cluster.
|
246 | 593fb83c | Kevin Wolf | */
|
247 | 593fb83c | Kevin Wolf | Qcow2COWRegion cow_end; |
248 | 593fb83c | Kevin Wolf | |
249 | 72cf2d4f | Blue Swirl | QLIST_ENTRY(QCowL2Meta) next_in_flight; |
250 | 45aba42f | Kevin Wolf | } QCowL2Meta; |
251 | 45aba42f | Kevin Wolf | |
252 | 68d000a3 | Kevin Wolf | enum {
|
253 | 68d000a3 | Kevin Wolf | QCOW2_CLUSTER_UNALLOCATED, |
254 | 68d000a3 | Kevin Wolf | QCOW2_CLUSTER_NORMAL, |
255 | 68d000a3 | Kevin Wolf | QCOW2_CLUSTER_COMPRESSED, |
256 | 6377af48 | Kevin Wolf | QCOW2_CLUSTER_ZERO |
257 | 68d000a3 | Kevin Wolf | }; |
258 | 68d000a3 | Kevin Wolf | |
259 | 68d000a3 | Kevin Wolf | #define L1E_OFFSET_MASK 0x00ffffffffffff00ULL |
260 | 68d000a3 | Kevin Wolf | #define L2E_OFFSET_MASK 0x00ffffffffffff00ULL |
261 | 68d000a3 | Kevin Wolf | #define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL |
262 | 68d000a3 | Kevin Wolf | |
263 | 76dc9e0c | Kevin Wolf | #define REFT_OFFSET_MASK 0xffffffffffffff00ULL |
264 | 76dc9e0c | Kevin Wolf | |
265 | 45aba42f | Kevin Wolf | static inline int size_to_clusters(BDRVQcowState *s, int64_t size) |
266 | f7d0fe02 | Kevin Wolf | { |
267 | f7d0fe02 | Kevin Wolf | return (size + (s->cluster_size - 1)) >> s->cluster_bits; |
268 | f7d0fe02 | Kevin Wolf | } |
269 | f7d0fe02 | Kevin Wolf | |
270 | 419b19d9 | Stefan Hajnoczi | static inline int size_to_l1(BDRVQcowState *s, int64_t size) |
271 | 419b19d9 | Stefan Hajnoczi | { |
272 | 419b19d9 | Stefan Hajnoczi | int shift = s->cluster_bits + s->l2_bits;
|
273 | 419b19d9 | Stefan Hajnoczi | return (size + (1ULL << shift) - 1) >> shift; |
274 | 419b19d9 | Stefan Hajnoczi | } |
275 | 419b19d9 | Stefan Hajnoczi | |
276 | c142442b | Kevin Wolf | static inline int64_t align_offset(int64_t offset, int n) |
277 | c142442b | Kevin Wolf | { |
278 | c142442b | Kevin Wolf | offset = (offset + n - 1) & ~(n - 1); |
279 | c142442b | Kevin Wolf | return offset;
|
280 | c142442b | Kevin Wolf | } |
281 | c142442b | Kevin Wolf | |
282 | 68d000a3 | Kevin Wolf | static inline int qcow2_get_cluster_type(uint64_t l2_entry) |
283 | 68d000a3 | Kevin Wolf | { |
284 | 68d000a3 | Kevin Wolf | if (l2_entry & QCOW_OFLAG_COMPRESSED) {
|
285 | 68d000a3 | Kevin Wolf | return QCOW2_CLUSTER_COMPRESSED;
|
286 | 6377af48 | Kevin Wolf | } else if (l2_entry & QCOW_OFLAG_ZERO) { |
287 | 6377af48 | Kevin Wolf | return QCOW2_CLUSTER_ZERO;
|
288 | 68d000a3 | Kevin Wolf | } else if (!(l2_entry & L2E_OFFSET_MASK)) { |
289 | 68d000a3 | Kevin Wolf | return QCOW2_CLUSTER_UNALLOCATED;
|
290 | 68d000a3 | Kevin Wolf | } else {
|
291 | 68d000a3 | Kevin Wolf | return QCOW2_CLUSTER_NORMAL;
|
292 | 68d000a3 | Kevin Wolf | } |
293 | 68d000a3 | Kevin Wolf | } |
294 | 68d000a3 | Kevin Wolf | |
295 | bfe8043e | Stefan Hajnoczi | /* Check whether refcounts are eager or lazy */
|
296 | bfe8043e | Stefan Hajnoczi | static inline bool qcow2_need_accurate_refcounts(BDRVQcowState *s) |
297 | bfe8043e | Stefan Hajnoczi | { |
298 | bfe8043e | Stefan Hajnoczi | return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
|
299 | bfe8043e | Stefan Hajnoczi | } |
300 | c142442b | Kevin Wolf | |
301 | f7d0fe02 | Kevin Wolf | // FIXME Need qcow2_ prefix to global functions
|
302 | f7d0fe02 | Kevin Wolf | |
303 | f7d0fe02 | Kevin Wolf | /* qcow2.c functions */
|
304 | bd28f835 | Kevin Wolf | int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
|
305 | bd28f835 | Kevin Wolf | int64_t sector_num, int nb_sectors);
|
306 | 280d3735 | Kevin Wolf | |
307 | 280d3735 | Kevin Wolf | int qcow2_mark_dirty(BlockDriverState *bs);
|
308 | e24e49e6 | Kevin Wolf | int qcow2_update_header(BlockDriverState *bs);
|
309 | f7d0fe02 | Kevin Wolf | |
310 | f7d0fe02 | Kevin Wolf | /* qcow2-refcount.c functions */
|
311 | ed6ccf0f | Kevin Wolf | int qcow2_refcount_init(BlockDriverState *bs);
|
312 | ed6ccf0f | Kevin Wolf | void qcow2_refcount_close(BlockDriverState *bs);
|
313 | f7d0fe02 | Kevin Wolf | |
314 | ed6ccf0f | Kevin Wolf | int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size); |
315 | 256900b1 | Kevin Wolf | int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
316 | 256900b1 | Kevin Wolf | int nb_clusters);
|
317 | ed6ccf0f | Kevin Wolf | int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
|
318 | ed6ccf0f | Kevin Wolf | void qcow2_free_clusters(BlockDriverState *bs,
|
319 | 45aba42f | Kevin Wolf | int64_t offset, int64_t size); |
320 | ed6ccf0f | Kevin Wolf | void qcow2_free_any_clusters(BlockDriverState *bs,
|
321 | 45aba42f | Kevin Wolf | uint64_t cluster_offset, int nb_clusters);
|
322 | f7d0fe02 | Kevin Wolf | |
323 | ed6ccf0f | Kevin Wolf | int qcow2_update_snapshot_refcount(BlockDriverState *bs,
|
324 | ed6ccf0f | Kevin Wolf | int64_t l1_table_offset, int l1_size, int addend); |
325 | f7d0fe02 | Kevin Wolf | |
326 | 166acf54 | Kevin Wolf | int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
327 | 166acf54 | Kevin Wolf | BdrvCheckMode fix); |
328 | f7d0fe02 | Kevin Wolf | |
329 | 45aba42f | Kevin Wolf | /* qcow2-cluster.c functions */
|
330 | 72893756 | Stefan Hajnoczi | int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size); |
331 | ed6ccf0f | Kevin Wolf | void qcow2_l2_cache_reset(BlockDriverState *bs);
|
332 | 66f82cee | Kevin Wolf | int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
|
333 | ed6ccf0f | Kevin Wolf | void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
334 | 45aba42f | Kevin Wolf | uint8_t *out_buf, const uint8_t *in_buf,
|
335 | 45aba42f | Kevin Wolf | int nb_sectors, int enc, |
336 | 45aba42f | Kevin Wolf | const AES_KEY *key);
|
337 | 45aba42f | Kevin Wolf | |
338 | 1c46efaa | Kevin Wolf | int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
339 | 1c46efaa | Kevin Wolf | int *num, uint64_t *cluster_offset);
|
340 | f4f0d391 | Kevin Wolf | int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
341 | f50f88b9 | Kevin Wolf | int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m); |
342 | ed6ccf0f | Kevin Wolf | uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, |
343 | 45aba42f | Kevin Wolf | uint64_t offset, |
344 | 45aba42f | Kevin Wolf | int compressed_size);
|
345 | 45aba42f | Kevin Wolf | |
346 | 148da7ea | Kevin Wolf | int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
|
347 | 5ea929e3 | Kevin Wolf | int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
348 | 5ea929e3 | Kevin Wolf | int nb_sectors);
|
349 | 621f0589 | Kevin Wolf | int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors); |
350 | 45aba42f | Kevin Wolf | |
351 | c142442b | Kevin Wolf | /* qcow2-snapshot.c functions */
|
352 | ed6ccf0f | Kevin Wolf | int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
|
353 | ed6ccf0f | Kevin Wolf | int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id); |
354 | ed6ccf0f | Kevin Wolf | int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); |
355 | ed6ccf0f | Kevin Wolf | int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
|
356 | 51ef6727 | edison | int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name); |
357 | c142442b | Kevin Wolf | |
358 | ed6ccf0f | Kevin Wolf | void qcow2_free_snapshots(BlockDriverState *bs);
|
359 | ed6ccf0f | Kevin Wolf | int qcow2_read_snapshots(BlockDriverState *bs);
|
360 | c142442b | Kevin Wolf | |
361 | 49381094 | Kevin Wolf | /* qcow2-cache.c functions */
|
362 | 6af4e9ea | Paolo Bonzini | Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);
|
363 | 49381094 | Kevin Wolf | int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
|
364 | 49381094 | Kevin Wolf | |
365 | 49381094 | Kevin Wolf | void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table); |
366 | 49381094 | Kevin Wolf | int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
|
367 | 49381094 | Kevin Wolf | int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
|
368 | 49381094 | Kevin Wolf | Qcow2Cache *dependency); |
369 | 3de0a294 | Kevin Wolf | void qcow2_cache_depends_on_flush(Qcow2Cache *c);
|
370 | 49381094 | Kevin Wolf | |
371 | 49381094 | Kevin Wolf | int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
372 | 49381094 | Kevin Wolf | void **table);
|
373 | 49381094 | Kevin Wolf | int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
374 | 49381094 | Kevin Wolf | void **table);
|
375 | 49381094 | Kevin Wolf | int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); |
376 | 49381094 | Kevin Wolf | |
377 | f7d0fe02 | Kevin Wolf | #endif |