Commit ed6ccf0f518aea8fab18815c8b18b2819524e4c2

Authored by Kevin Wolf
Committed by Anthony Liguori
1 parent c142442b

qcow2: Rename global functions

The qcow2 source is now split into several more manageable files. During the
conversion quite some functions that were static before needed to be changed to
be global to make the source compile again.

We were lucky enough not to get name conflicts with these additional global
names, but they are not nice. This patch adds a qcow2_ prefix to all of the
global functions in qcow2.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
block/qcow2-cluster.c
... ... @@ -28,7 +28,7 @@
28 28 #include "block_int.h"
29 29 #include "block/qcow2.h"
30 30  
31   -int grow_l1_table(BlockDriverState *bs, int min_size)
  31 +int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
32 32 {
33 33 BDRVQcowState *s = bs->opaque;
34 34 int new_l1_size, new_l1_size2, ret, i;
... ... @@ -51,7 +51,7 @@ int grow_l1_table(BlockDriverState *bs, int min_size)
51 51 memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
52 52  
53 53 /* write new table (align to cluster) */
54   - new_l1_table_offset = alloc_clusters(bs, new_l1_size2);
  54 + new_l1_table_offset = qcow2_alloc_clusters(bs, new_l1_size2);
55 55  
56 56 for(i = 0; i < s->l1_size; i++)
57 57 new_l1_table[i] = cpu_to_be64(new_l1_table[i]);
... ... @@ -68,7 +68,7 @@ int grow_l1_table(BlockDriverState *bs, int min_size)
68 68 sizeof(data)) != sizeof(data))
69 69 goto fail;
70 70 qemu_free(s->l1_table);
71   - free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t));
  71 + qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t));
72 72 s->l1_table_offset = new_l1_table_offset;
73 73 s->l1_table = new_l1_table;
74 74 s->l1_size = new_l1_size;
... ... @@ -78,7 +78,7 @@ int grow_l1_table(BlockDriverState *bs, int min_size)
78 78 return -EIO;
79 79 }
80 80  
81   -void l2_cache_reset(BlockDriverState *bs)
  81 +void qcow2_l2_cache_reset(BlockDriverState *bs)
82 82 {
83 83 BDRVQcowState *s = bs->opaque;
84 84  
... ... @@ -191,7 +191,7 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index)
191 191  
192 192 /* allocate a new l2 entry */
193 193  
194   - l2_offset = alloc_clusters(bs, s->l2_size * sizeof(uint64_t));
  194 + l2_offset = qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t));
195 195  
196 196 /* update the L1 entry */
197 197  
... ... @@ -260,10 +260,10 @@ static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t *l2_tab
260 260 /* The crypt function is compatible with the linux cryptoloop
261 261 algorithm for < 4 GB images. NOTE: out_buf == in_buf is
262 262 supported */
263   -void encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
264   - uint8_t *out_buf, const uint8_t *in_buf,
265   - int nb_sectors, int enc,
266   - const AES_KEY *key)
  263 +void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
  264 + uint8_t *out_buf, const uint8_t *in_buf,
  265 + int nb_sectors, int enc,
  266 + const AES_KEY *key)
267 267 {
268 268 union {
269 269 uint64_t ll[2];
... ... @@ -292,12 +292,12 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
292 292  
293 293 while (nb_sectors > 0) {
294 294 n = nb_sectors;
295   - cluster_offset = get_cluster_offset(bs, sector_num << 9, &n);
  295 + cluster_offset = qcow2_get_cluster_offset(bs, sector_num << 9, &n);
296 296 index_in_cluster = sector_num & (s->cluster_sectors - 1);
297 297 if (!cluster_offset) {
298 298 if (bs->backing_hd) {
299 299 /* read from the base image */
300   - n1 = backing_read1(bs->backing_hd, sector_num, buf, n);
  300 + n1 = qcow2_backing_read1(bs->backing_hd, sector_num, buf, n);
301 301 if (n1 > 0) {
302 302 ret = bdrv_read(bs->backing_hd, sector_num, buf, n1);
303 303 if (ret < 0)
... ... @@ -307,7 +307,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
307 307 memset(buf, 0, 512 * n);
308 308 }
309 309 } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
310   - if (decompress_cluster(s, cluster_offset) < 0)
  310 + if (qcow2_decompress_cluster(s, cluster_offset) < 0)
311 311 return -1;
312 312 memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n);
313 313 } else {
... ... @@ -315,7 +315,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
315 315 if (ret != n * 512)
316 316 return -1;
317 317 if (s->crypt_method) {
318   - encrypt_sectors(s, sector_num, buf, buf, n, 0,
  318 + qcow2_encrypt_sectors(s, sector_num, buf, buf, n, 0,
319 319 &s->aes_decrypt_key);
320 320 }
321 321 }
... ... @@ -339,7 +339,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,
339 339 if (ret < 0)
340 340 return ret;
341 341 if (s->crypt_method) {
342   - encrypt_sectors(s, start_sect + n_start,
  342 + qcow2_encrypt_sectors(s, start_sect + n_start,
343 343 s->cluster_data,
344 344 s->cluster_data, n, 1,
345 345 &s->aes_encrypt_key);
... ... @@ -368,7 +368,8 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,
368 368 *
369 369 */
370 370  
371   -uint64_t get_cluster_offset(BlockDriverState *bs, uint64_t offset, int *num)
  371 +uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
  372 + int *num)
372 373 {
373 374 BDRVQcowState *s = bs->opaque;
374 375 int l1_index, l2_index;
... ... @@ -466,7 +467,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
466 467  
467 468 l1_index = offset >> (s->l2_bits + s->cluster_bits);
468 469 if (l1_index >= s->l1_size) {
469   - ret = grow_l1_table(bs, l1_index + 1);
  470 + ret = qcow2_grow_l1_table(bs, l1_index + 1);
470 471 if (ret < 0)
471 472 return 0;
472 473 }
... ... @@ -482,7 +483,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
482 483 return 0;
483 484 } else {
484 485 if (l2_offset)
485   - free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t));
  486 + qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t));
486 487 l2_table = l2_allocate(bs, l1_index);
487 488 if (l2_table == NULL)
488 489 return 0;
... ... @@ -513,9 +514,9 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
513 514 *
514 515 */
515 516  
516   -uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs,
517   - uint64_t offset,
518   - int compressed_size)
  517 +uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
  518 + uint64_t offset,
  519 + int compressed_size)
519 520 {
520 521 BDRVQcowState *s = bs->opaque;
521 522 int l2_index, ret;
... ... @@ -531,9 +532,9 @@ uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs,
531 532 return cluster_offset & ~QCOW_OFLAG_COPIED;
532 533  
533 534 if (cluster_offset)
534   - free_any_clusters(bs, cluster_offset, 1);
  535 + qcow2_free_any_clusters(bs, cluster_offset, 1);
535 536  
536   - cluster_offset = alloc_bytes(bs, compressed_size);
  537 + cluster_offset = qcow2_alloc_bytes(bs, compressed_size);
537 538 nb_csectors = ((cluster_offset + compressed_size - 1) >> 9) -
538 539 (cluster_offset >> 9);
539 540  
... ... @@ -554,7 +555,7 @@ uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs,
554 555 return cluster_offset;
555 556 }
556 557  
557   -int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
  558 +int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
558 559 QCowL2Meta *m)
559 560 {
560 561 BDRVQcowState *s = bs->opaque;
... ... @@ -607,8 +608,8 @@ int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
607 608 goto err;
608 609  
609 610 for (i = 0; i < j; i++)
610   - free_any_clusters(bs, be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED,
611   - 1);
  611 + qcow2_free_any_clusters(bs,
  612 + be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1);
612 613  
613 614 ret = 0;
614 615 err:
... ... @@ -629,10 +630,10 @@ err:
629 630 *
630 631 */
631 632  
632   -uint64_t alloc_cluster_offset(BlockDriverState *bs,
633   - uint64_t offset,
634   - int n_start, int n_end,
635   - int *num, QCowL2Meta *m)
  633 +uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs,
  634 + uint64_t offset,
  635 + int n_start, int n_end,
  636 + int *num, QCowL2Meta *m)
636 637 {
637 638 BDRVQcowState *s = bs->opaque;
638 639 int l2_index, ret;
... ... @@ -688,7 +689,7 @@ uint64_t alloc_cluster_offset(BlockDriverState *bs,
688 689  
689 690 /* allocate a new cluster */
690 691  
691   - cluster_offset = alloc_clusters(bs, nb_clusters * s->cluster_size);
  692 + cluster_offset = qcow2_alloc_clusters(bs, nb_clusters * s->cluster_size);
692 693  
693 694 /* save info needed for meta data update */
694 695 m->offset = offset;
... ... @@ -730,7 +731,7 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
730 731 return 0;
731 732 }
732 733  
733   -int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
  734 +int qcow2_decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
734 735 {
735 736 int ret, csize, nb_csectors, sector_offset;
736 737 uint64_t coffset;
... ...
block/qcow2-refcount.c
... ... @@ -34,7 +34,7 @@ static int update_refcount(BlockDriverState *bs,
34 34 /*********************************************************/
35 35 /* refcount handling */
36 36  
37   -int refcount_init(BlockDriverState *bs)
  37 +int qcow2_refcount_init(BlockDriverState *bs)
38 38 {
39 39 BDRVQcowState *s = bs->opaque;
40 40 int ret, refcount_table_size2, i;
... ... @@ -55,7 +55,7 @@ int refcount_init(BlockDriverState *bs)
55 55 return -ENOMEM;
56 56 }
57 57  
58   -void refcount_close(BlockDriverState *bs)
  58 +void qcow2_refcount_close(BlockDriverState *bs)
59 59 {
60 60 BDRVQcowState *s = bs->opaque;
61 61 qemu_free(s->refcount_block_cache);
... ... @@ -154,10 +154,10 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
154 154 s->refcount_table_offset = table_offset;
155 155  
156 156 update_refcount(bs, table_offset, new_table_size2, 1);
157   - free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t));
  157 + qcow2_free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t));
158 158 return 0;
159 159 fail:
160   - free_clusters(bs, table_offset, new_table_size2);
  160 + qcow2_free_clusters(bs, table_offset, new_table_size2);
161 161 qemu_free(new_table);
162 162 return -EIO;
163 163 }
... ... @@ -334,7 +334,7 @@ retry:
334 334 return (s->free_cluster_index - nb_clusters) << s->cluster_bits;
335 335 }
336 336  
337   -int64_t alloc_clusters(BlockDriverState *bs, int64_t size)
  337 +int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size)
338 338 {
339 339 int64_t offset;
340 340  
... ... @@ -345,7 +345,7 @@ int64_t alloc_clusters(BlockDriverState *bs, int64_t size)
345 345  
346 346 /* only used to allocate compressed sectors. We try to allocate
347 347 contiguous sectors. size must be <= cluster_size */
348   -int64_t alloc_bytes(BlockDriverState *bs, int size)
  348 +int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
349 349 {
350 350 BDRVQcowState *s = bs->opaque;
351 351 int64_t offset, cluster_offset;
... ... @@ -353,7 +353,7 @@ int64_t alloc_bytes(BlockDriverState *bs, int size)
353 353  
354 354 assert(size > 0 && size <= s->cluster_size);
355 355 if (s->free_byte_offset == 0) {
356   - s->free_byte_offset = alloc_clusters(bs, s->cluster_size);
  356 + s->free_byte_offset = qcow2_alloc_clusters(bs, s->cluster_size);
357 357 }
358 358 redo:
359 359 free_in_cluster = s->cluster_size -
... ... @@ -368,7 +368,7 @@ int64_t alloc_bytes(BlockDriverState *bs, int size)
368 368 if ((offset & (s->cluster_size - 1)) != 0)
369 369 update_cluster_refcount(bs, offset >> s->cluster_bits, 1);
370 370 } else {
371   - offset = alloc_clusters(bs, s->cluster_size);
  371 + offset = qcow2_alloc_clusters(bs, s->cluster_size);
372 372 cluster_offset = s->free_byte_offset & ~(s->cluster_size - 1);
373 373 if ((cluster_offset + s->cluster_size) == offset) {
374 374 /* we are lucky: contiguous data */
... ... @@ -383,7 +383,7 @@ int64_t alloc_bytes(BlockDriverState *bs, int size)
383 383 return offset;
384 384 }
385 385  
386   -void free_clusters(BlockDriverState *bs,
  386 +void qcow2_free_clusters(BlockDriverState *bs,
387 387 int64_t offset, int64_t size)
388 388 {
389 389 update_refcount(bs, offset, size, -1);
... ... @@ -396,7 +396,7 @@ void free_clusters(BlockDriverState *bs,
396 396 *
397 397 */
398 398  
399   -void free_any_clusters(BlockDriverState *bs,
  399 +void qcow2_free_any_clusters(BlockDriverState *bs,
400 400 uint64_t cluster_offset, int nb_clusters)
401 401 {
402 402 BDRVQcowState *s = bs->opaque;
... ... @@ -407,12 +407,13 @@ void free_any_clusters(BlockDriverState *bs,
407 407 int nb_csectors;
408 408 nb_csectors = ((cluster_offset >> s->csize_shift) &
409 409 s->csize_mask) + 1;
410   - free_clusters(bs, (cluster_offset & s->cluster_offset_mask) & ~511,
411   - nb_csectors * 512);
  410 + qcow2_free_clusters(bs,
  411 + (cluster_offset & s->cluster_offset_mask) & ~511,
  412 + nb_csectors * 512);
412 413 return;
413 414 }
414 415  
415   - free_clusters(bs, cluster_offset, nb_clusters << s->cluster_bits);
  416 + qcow2_free_clusters(bs, cluster_offset, nb_clusters << s->cluster_bits);
416 417  
417 418 return;
418 419 }
... ... @@ -424,7 +425,8 @@ void free_any_clusters(BlockDriverState *bs,
424 425  
425 426  
426 427  
427   -void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size)
  428 +void qcow2_create_refcount_update(QCowCreateState *s, int64_t offset,
  429 + int64_t size)
428 430 {
429 431 int refcount;
430 432 int64_t start, last, cluster_offset;
... ... @@ -442,17 +444,15 @@ void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size)
442 444 }
443 445  
444 446 /* update the refcounts of snapshots and the copied flag */
445   -int update_snapshot_refcount(BlockDriverState *bs,
446   - int64_t l1_table_offset,
447   - int l1_size,
448   - int addend)
  447 +int qcow2_update_snapshot_refcount(BlockDriverState *bs,
  448 + int64_t l1_table_offset, int l1_size, int addend)
449 449 {
450 450 BDRVQcowState *s = bs->opaque;
451 451 uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, l1_allocated;
452 452 int64_t old_offset, old_l2_offset;
453 453 int l2_size, i, j, l1_modified, l2_modified, nb_csectors, refcount;
454 454  
455   - l2_cache_reset(bs);
  455 + qcow2_l2_cache_reset(bs);
456 456  
457 457 l2_table = NULL;
458 458 l1_table = NULL;
... ... @@ -771,7 +771,7 @@ fail:
771 771 * Returns 0 if no errors are found, the number of errors in case the image is
772 772 * detected as corrupted, and -errno when an internal error occured.
773 773 */
774   -int check_refcounts(BlockDriverState *bs)
  774 +int qcow2_check_refcounts(BlockDriverState *bs)
775 775 {
776 776 BDRVQcowState *s = bs->opaque;
777 777 int64_t size;
... ...
block/qcow2-snapshot.c
... ... @@ -46,7 +46,7 @@ typedef struct __attribute__((packed)) QCowSnapshotHeader {
46 46 /* name follows */
47 47 } QCowSnapshotHeader;
48 48  
49   -void qcow_free_snapshots(BlockDriverState *bs)
  49 +void qcow2_free_snapshots(BlockDriverState *bs)
50 50 {
51 51 BDRVQcowState *s = bs->opaque;
52 52 int i;
... ... @@ -60,7 +60,7 @@ void qcow_free_snapshots(BlockDriverState *bs)
60 60 s->nb_snapshots = 0;
61 61 }
62 62  
63   -int qcow_read_snapshots(BlockDriverState *bs)
  63 +int qcow2_read_snapshots(BlockDriverState *bs)
64 64 {
65 65 BDRVQcowState *s = bs->opaque;
66 66 QCowSnapshotHeader h;
... ... @@ -111,7 +111,7 @@ int qcow_read_snapshots(BlockDriverState *bs)
111 111 s->snapshots_size = offset - s->snapshots_offset;
112 112 return 0;
113 113 fail:
114   - qcow_free_snapshots(bs);
  114 + qcow2_free_snapshots(bs);
115 115 return -1;
116 116 }
117 117  
... ... @@ -137,7 +137,7 @@ static int qcow_write_snapshots(BlockDriverState *bs)
137 137 }
138 138 snapshots_size = offset;
139 139  
140   - snapshots_offset = alloc_clusters(bs, snapshots_size);
  140 + snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size);
141 141 offset = snapshots_offset;
142 142  
143 143 for(i = 0; i < s->nb_snapshots; i++) {
... ... @@ -177,7 +177,7 @@ static int qcow_write_snapshots(BlockDriverState *bs)
177 177 goto fail;
178 178  
179 179 /* free the old snapshot table */
180   - free_clusters(bs, s->snapshots_offset, s->snapshots_size);
  180 + qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size);
181 181 s->snapshots_offset = snapshots_offset;
182 182 s->snapshots_size = snapshots_size;
183 183 return 0;
... ... @@ -229,7 +229,7 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name)
229 229 }
230 230  
231 231 /* if no id is provided, a new one is constructed */
232   -int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
  232 +int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
233 233 {
234 234 BDRVQcowState *s = bs->opaque;
235 235 QCowSnapshot *snapshots1, sn1, *sn = &sn1;
... ... @@ -258,12 +258,12 @@ int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
258 258 sn->date_nsec = sn_info->date_nsec;
259 259 sn->vm_clock_nsec = sn_info->vm_clock_nsec;
260 260  
261   - ret = update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
  261 + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
262 262 if (ret < 0)
263 263 goto fail;
264 264  
265 265 /* create the L1 table of the snapshot */
266   - sn->l1_table_offset = alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
  266 + sn->l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
267 267 sn->l1_size = s->l1_size;
268 268  
269 269 l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
... ... @@ -298,7 +298,7 @@ int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
298 298 }
299 299  
300 300 /* copy the snapshot 'snapshot_name' into the current disk image */
301   -int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
  301 +int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
302 302 {
303 303 BDRVQcowState *s = bs->opaque;
304 304 QCowSnapshot *sn;
... ... @@ -309,10 +309,10 @@ int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
309 309 return -ENOENT;
310 310 sn = &s->snapshots[snapshot_index];
311 311  
312   - if (update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0)
  312 + if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0)
313 313 goto fail;
314 314  
315   - if (grow_l1_table(bs, sn->l1_size) < 0)
  315 + if (qcow2_grow_l1_table(bs, sn->l1_size) < 0)
316 316 goto fail;
317 317  
318 318 s->l1_size = sn->l1_size;
... ... @@ -328,7 +328,7 @@ int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
328 328 be64_to_cpus(&s->l1_table[i]);
329 329 }
330 330  
331   - if (update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0)
  331 + if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0)
332 332 goto fail;
333 333  
334 334 #ifdef DEBUG_ALLOC
... ... @@ -339,7 +339,7 @@ int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
339 339 return -EIO;
340 340 }
341 341  
342   -int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
  342 +int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
343 343 {
344 344 BDRVQcowState *s = bs->opaque;
345 345 QCowSnapshot *sn;
... ... @@ -350,14 +350,14 @@ int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
350 350 return -ENOENT;
351 351 sn = &s->snapshots[snapshot_index];
352 352  
353   - ret = update_snapshot_refcount(bs, sn->l1_table_offset, sn->l1_size, -1);
  353 + ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset, sn->l1_size, -1);
354 354 if (ret < 0)
355 355 return ret;
356 356 /* must update the copied flag on the current cluster offsets */
357   - ret = update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
  357 + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
358 358 if (ret < 0)
359 359 return ret;
360   - free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t));
  360 + qcow2_free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t));
361 361  
362 362 qemu_free(sn->id_str);
363 363 qemu_free(sn->name);
... ... @@ -374,7 +374,7 @@ int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
374 374 return 0;
375 375 }
376 376  
377   -int qcow_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
  377 +int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
378 378 {
379 379 BDRVQcowState *s = bs->opaque;
380 380 QEMUSnapshotInfo *sn_tab, *sn_info;
... ...
block/qcow2.c
... ... @@ -227,7 +227,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
227 227 + 512);
228 228 s->cluster_cache_offset = -1;
229 229  
230   - if (refcount_init(bs) < 0)
  230 + if (qcow2_refcount_init(bs) < 0)
231 231 goto fail;
232 232  
233 233 /* read qcow2 extensions */
... ... @@ -247,7 +247,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
247 247 goto fail;
248 248 bs->backing_file[len] = '\0';
249 249 }
250   - if (qcow_read_snapshots(bs) < 0)
  250 + if (qcow2_read_snapshots(bs) < 0)
251 251 goto fail;
252 252  
253 253 #ifdef DEBUG_ALLOC
... ... @@ -256,8 +256,8 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
256 256 return 0;
257 257  
258 258 fail:
259   - qcow_free_snapshots(bs);
260   - refcount_close(bs);
  259 + qcow2_free_snapshots(bs);
  260 + qcow2_refcount_close(bs);
261 261 qemu_free(s->l1_table);
262 262 qemu_free(s->l2_cache);
263 263 qemu_free(s->cluster_cache);
... ... @@ -314,13 +314,13 @@ static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
314 314 uint64_t cluster_offset;
315 315  
316 316 *pnum = nb_sectors;
317   - cluster_offset = get_cluster_offset(bs, sector_num << 9, pnum);
  317 + cluster_offset = qcow2_get_cluster_offset(bs, sector_num << 9, pnum);
318 318  
319 319 return (cluster_offset != 0);
320 320 }
321 321  
322 322 /* handle reading after the end of the backing file */
323   -int backing_read1(BlockDriverState *bs,
  323 +int qcow2_backing_read1(BlockDriverState *bs,
324 324 int64_t sector_num, uint8_t *buf, int nb_sectors)
325 325 {
326 326 int n1;
... ... @@ -405,7 +405,7 @@ static void qcow_aio_read_cb(void *opaque, int ret)
405 405 /* nothing to do */
406 406 } else {
407 407 if (s->crypt_method) {
408   - encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
  408 + qcow2_encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
409 409 acb->n, 0,
410 410 &s->aes_decrypt_key);
411 411 }
... ... @@ -423,13 +423,14 @@ static void qcow_aio_read_cb(void *opaque, int ret)
423 423  
424 424 /* prepare next AIO request */
425 425 acb->n = acb->nb_sectors;
426   - acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, &acb->n);
  426 + acb->cluster_offset =
  427 + qcow2_get_cluster_offset(bs, acb->sector_num << 9, &acb->n);
427 428 index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
428 429  
429 430 if (!acb->cluster_offset) {
430 431 if (bs->backing_hd) {
431 432 /* read from the base image */
432   - n1 = backing_read1(bs->backing_hd, acb->sector_num,
  433 + n1 = qcow2_backing_read1(bs->backing_hd, acb->sector_num,
433 434 acb->buf, acb->n);
434 435 if (n1 > 0) {
435 436 acb->hd_iov.iov_base = (void *)acb->buf;
... ... @@ -454,7 +455,7 @@ static void qcow_aio_read_cb(void *opaque, int ret)
454 455 }
455 456 } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) {
456 457 /* add AIO support for compressed blocks ? */
457   - if (decompress_cluster(s, acb->cluster_offset) < 0)
  458 + if (qcow2_decompress_cluster(s, acb->cluster_offset) < 0)
458 459 goto done;
459 460 memcpy(acb->buf,
460 461 s->cluster_cache + index_in_cluster * 512, 512 * acb->n);
... ... @@ -541,8 +542,8 @@ static void qcow_aio_write_cb(void *opaque, int ret)
541 542 if (ret < 0)
542 543 goto done;
543 544  
544   - if (alloc_cluster_link_l2(bs, acb->cluster_offset, &acb->l2meta) < 0) {
545   - free_any_clusters(bs, acb->cluster_offset, acb->l2meta.nb_clusters);
  545 + if (qcow2_alloc_cluster_link_l2(bs, acb->cluster_offset, &acb->l2meta) < 0) {
  546 + qcow2_free_any_clusters(bs, acb->cluster_offset, acb->l2meta.nb_clusters);
546 547 goto done;
547 548 }
548 549  
... ... @@ -562,7 +563,7 @@ static void qcow_aio_write_cb(void *opaque, int ret)
562 563 n_end > QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors)
563 564 n_end = QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors;
564 565  
565   - acb->cluster_offset = alloc_cluster_offset(bs, acb->sector_num << 9,
  566 + acb->cluster_offset = qcow2_alloc_cluster_offset(bs, acb->sector_num << 9,
566 567 index_in_cluster,
567 568 n_end, &acb->n, &acb->l2meta);
568 569 if (!acb->cluster_offset || (acb->cluster_offset & 511) != 0) {
... ... @@ -574,7 +575,7 @@ static void qcow_aio_write_cb(void *opaque, int ret)
574 575 acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS *
575 576 s->cluster_size);
576 577 }
577   - encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
  578 + qcow2_encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
578 579 acb->n, 1, &s->aes_encrypt_key);
579 580 src_buf = acb->cluster_data;
580 581 } else {
... ... @@ -623,7 +624,7 @@ static void qcow_close(BlockDriverState *bs)
623 624 qemu_free(s->l2_cache);
624 625 qemu_free(s->cluster_cache);
625 626 qemu_free(s->cluster_data);
626   - refcount_close(bs);
  627 + qcow2_refcount_close(bs);
627 628 bdrv_delete(s->hd);
628 629 }
629 630  
... ... @@ -733,10 +734,12 @@ static int qcow_create2(const char *filename, int64_t total_size,
733 734 s->refcount_block = qemu_mallocz(ref_clusters * s->cluster_size);
734 735  
735 736 /* update refcounts */
736   - create_refcount_update(s, 0, header_size);
737   - create_refcount_update(s, s->l1_table_offset, l1_size * sizeof(uint64_t));
738   - create_refcount_update(s, s->refcount_table_offset, s->cluster_size);
739   - create_refcount_update(s, s->refcount_block_offset, ref_clusters * s->cluster_size);
  737 + qcow2_create_refcount_update(s, 0, header_size);
  738 + qcow2_create_refcount_update(s, s->l1_table_offset,
  739 + l1_size * sizeof(uint64_t));
  740 + qcow2_create_refcount_update(s, s->refcount_table_offset, s->cluster_size);
  741 + qcow2_create_refcount_update(s, s->refcount_block_offset,
  742 + ref_clusters * s->cluster_size);
740 743  
741 744 /* write all the data */
742 745 write(fd, &header, sizeof(header));
... ... @@ -877,8 +880,8 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
877 880 /* could not compress: write normal cluster */
878 881 bdrv_write(bs, sector_num, buf, s->cluster_sectors);
879 882 } else {
880   - cluster_offset = alloc_compressed_cluster_offset(bs, sector_num << 9,
881   - out_len);
  883 + cluster_offset = qcow2_alloc_compressed_cluster_offset(bs,
  884 + sector_num << 9, out_len);
882 885 if (!cluster_offset)
883 886 return -1;
884 887 cluster_offset &= s->cluster_offset_mask;
... ... @@ -910,7 +913,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
910 913  
911 914 static int qcow_check(BlockDriverState *bs)
912 915 {
913   - return check_refcounts(bs);
  916 + return qcow2_check_refcounts(bs);
914 917 }
915 918  
916 919 #if 0
... ... @@ -1003,10 +1006,10 @@ static BlockDriver bdrv_qcow2 = {
1003 1006 .bdrv_aio_writev = qcow_aio_writev,
1004 1007 .bdrv_write_compressed = qcow_write_compressed,
1005 1008  
1006   - .bdrv_snapshot_create = qcow_snapshot_create,
1007   - .bdrv_snapshot_goto = qcow_snapshot_goto,
1008   - .bdrv_snapshot_delete = qcow_snapshot_delete,
1009   - .bdrv_snapshot_list = qcow_snapshot_list,
  1009 + .bdrv_snapshot_create = qcow2_snapshot_create,
  1010 + .bdrv_snapshot_goto = qcow2_snapshot_goto,
  1011 + .bdrv_snapshot_delete = qcow2_snapshot_delete,
  1012 + .bdrv_snapshot_list = qcow2_snapshot_list,
1010 1013 .bdrv_get_info = qcow_get_info,
1011 1014  
1012 1015 .bdrv_put_buffer = qcow_put_buffer,
... ...
block/qcow2.h
... ... @@ -148,56 +148,56 @@ static inline int64_t align_offset(int64_t offset, int n)
148 148 // FIXME Need qcow2_ prefix to global functions
149 149  
150 150 /* qcow2.c functions */
151   -void l2_cache_reset(BlockDriverState *bs);
152   -int backing_read1(BlockDriverState *bs,
  151 +int qcow2_backing_read1(BlockDriverState *bs,
153 152 int64_t sector_num, uint8_t *buf, int nb_sectors);
154 153  
155 154 /* qcow2-refcount.c functions */
156   -int refcount_init(BlockDriverState *bs);
157   -void refcount_close(BlockDriverState *bs);
  155 +int qcow2_refcount_init(BlockDriverState *bs);
  156 +void qcow2_refcount_close(BlockDriverState *bs);
158 157  
159   -int64_t alloc_clusters(BlockDriverState *bs, int64_t size);
160   -int64_t alloc_bytes(BlockDriverState *bs, int size);
161   -void free_clusters(BlockDriverState *bs,
  158 +int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size);
  159 +int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
  160 +void qcow2_free_clusters(BlockDriverState *bs,
162 161 int64_t offset, int64_t size);
163   -void free_any_clusters(BlockDriverState *bs,
  162 +void qcow2_free_any_clusters(BlockDriverState *bs,
164 163 uint64_t cluster_offset, int nb_clusters);
165 164  
166   -void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size);
167   -int update_snapshot_refcount(BlockDriverState *bs,
168   - int64_t l1_table_offset,
169   - int l1_size,
170   - int addend);
  165 +void qcow2_create_refcount_update(QCowCreateState *s, int64_t offset,
  166 + int64_t size);
  167 +int qcow2_update_snapshot_refcount(BlockDriverState *bs,
  168 + int64_t l1_table_offset, int l1_size, int addend);
171 169  
172   -int check_refcounts(BlockDriverState *bs);
  170 +int qcow2_check_refcounts(BlockDriverState *bs);
173 171  
174 172 /* qcow2-cluster.c functions */
175   -int grow_l1_table(BlockDriverState *bs, int min_size);
176   -int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
177   -void encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
  173 +int qcow2_grow_l1_table(BlockDriverState *bs, int min_size);
  174 +void qcow2_l2_cache_reset(BlockDriverState *bs);
  175 +int qcow2_decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
  176 +void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
178 177 uint8_t *out_buf, const uint8_t *in_buf,
179 178 int nb_sectors, int enc,
180 179 const AES_KEY *key);
181 180  
182   -uint64_t get_cluster_offset(BlockDriverState *bs, uint64_t offset, int *num);
183   -uint64_t alloc_cluster_offset(BlockDriverState *bs,
  181 +uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
  182 + int *num);
  183 +uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs,
184 184 uint64_t offset,
185 185 int n_start, int n_end,
186 186 int *num, QCowL2Meta *m);
187   -uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs,
  187 +uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
188 188 uint64_t offset,
189 189 int compressed_size);
190 190  
191   -int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
  191 +int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
192 192 QCowL2Meta *m);
193 193  
194 194 /* qcow2-snapshot.c functions */
195   -int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
196   -int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
197   -int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
198   -int qcow_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
  195 +int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
  196 +int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
  197 +int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
  198 +int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
199 199  
200   -void qcow_free_snapshots(BlockDriverState *bs);
201   -int qcow_read_snapshots(BlockDriverState *bs);
  200 +void qcow2_free_snapshots(BlockDriverState *bs);
  201 +int qcow2_read_snapshots(BlockDriverState *bs);
202 202  
203 203 #endif
... ...