diff options
author | Kevin Wolf <kwolf@redhat.com> | 2009-05-28 16:07:07 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-06-16 15:18:36 -0500 |
commit | ed6ccf0f518aea8fab18815c8b18b2819524e4c2 (patch) | |
tree | bdefff9a932778670b3467431b767a0395cdd560 /block | |
parent | c142442b06c51df60d000145d18af60ae5f0ac1c (diff) | |
download | qemu-ed6ccf0f518aea8fab18815c8b18b2819524e4c2.zip qemu-ed6ccf0f518aea8fab18815c8b18b2819524e4c2.tar.gz qemu-ed6ccf0f518aea8fab18815c8b18b2819524e4c2.tar.bz2 |
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>
Diffstat (limited to 'block')
-rw-r--r-- | block/qcow2-cluster.c | 63 | ||||
-rw-r--r-- | block/qcow2-refcount.c | 40 | ||||
-rw-r--r-- | block/qcow2-snapshot.c | 34 | ||||
-rw-r--r-- | block/qcow2.c | 55 | ||||
-rw-r--r-- | block/qcow2.h | 54 |
5 files changed, 125 insertions, 121 deletions
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 494cc91..99215fa 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -28,7 +28,7 @@ #include "block_int.h" #include "block/qcow2.h" -int grow_l1_table(BlockDriverState *bs, int min_size) +int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) { BDRVQcowState *s = bs->opaque; int new_l1_size, new_l1_size2, ret, i; @@ -51,7 +51,7 @@ int grow_l1_table(BlockDriverState *bs, int min_size) memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); /* write new table (align to cluster) */ - new_l1_table_offset = alloc_clusters(bs, new_l1_size2); + new_l1_table_offset = qcow2_alloc_clusters(bs, new_l1_size2); for(i = 0; i < s->l1_size; i++) new_l1_table[i] = cpu_to_be64(new_l1_table[i]); @@ -68,7 +68,7 @@ int grow_l1_table(BlockDriverState *bs, int min_size) sizeof(data)) != sizeof(data)) goto fail; qemu_free(s->l1_table); - free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t)); + qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t)); s->l1_table_offset = new_l1_table_offset; s->l1_table = new_l1_table; s->l1_size = new_l1_size; @@ -78,7 +78,7 @@ int grow_l1_table(BlockDriverState *bs, int min_size) return -EIO; } -void l2_cache_reset(BlockDriverState *bs) +void qcow2_l2_cache_reset(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; @@ -191,7 +191,7 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index) /* allocate a new l2 entry */ - l2_offset = alloc_clusters(bs, s->l2_size * sizeof(uint64_t)); + l2_offset = qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t)); /* update the L1 entry */ @@ -260,10 +260,10 @@ static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t *l2_tab /* The crypt function is compatible with the linux cryptoloop algorithm for < 4 GB images. NOTE: out_buf == in_buf is supported */ -void encrypt_sectors(BDRVQcowState *s, int64_t sector_num, - uint8_t *out_buf, const uint8_t *in_buf, - int nb_sectors, int enc, - const AES_KEY *key) +void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num, + uint8_t *out_buf, const uint8_t *in_buf, + int nb_sectors, int enc, + const AES_KEY *key) { union { uint64_t ll[2]; @@ -292,12 +292,12 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, while (nb_sectors > 0) { n = nb_sectors; - cluster_offset = get_cluster_offset(bs, sector_num << 9, &n); + cluster_offset = qcow2_get_cluster_offset(bs, sector_num << 9, &n); index_in_cluster = sector_num & (s->cluster_sectors - 1); if (!cluster_offset) { if (bs->backing_hd) { /* read from the base image */ - n1 = backing_read1(bs->backing_hd, sector_num, buf, n); + n1 = qcow2_backing_read1(bs->backing_hd, sector_num, buf, n); if (n1 > 0) { ret = bdrv_read(bs->backing_hd, sector_num, buf, n1); if (ret < 0) @@ -307,7 +307,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, memset(buf, 0, 512 * n); } } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { - if (decompress_cluster(s, cluster_offset) < 0) + if (qcow2_decompress_cluster(s, cluster_offset) < 0) return -1; memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n); } else { @@ -315,7 +315,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, if (ret != n * 512) return -1; if (s->crypt_method) { - encrypt_sectors(s, sector_num, buf, buf, n, 0, + qcow2_encrypt_sectors(s, sector_num, buf, buf, n, 0, &s->aes_decrypt_key); } } @@ -339,7 +339,7 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, if (ret < 0) return ret; if (s->crypt_method) { - encrypt_sectors(s, start_sect + n_start, + qcow2_encrypt_sectors(s, start_sect + n_start, s->cluster_data, s->cluster_data, n, 1, &s->aes_encrypt_key); @@ -368,7 +368,8 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, * */ -uint64_t get_cluster_offset(BlockDriverState *bs, uint64_t offset, int *num) +uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, + int *num) { BDRVQcowState *s = bs->opaque; int l1_index, l2_index; @@ -466,7 +467,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, l1_index = offset >> (s->l2_bits + s->cluster_bits); if (l1_index >= s->l1_size) { - ret = grow_l1_table(bs, l1_index + 1); + ret = qcow2_grow_l1_table(bs, l1_index + 1); if (ret < 0) return 0; } @@ -482,7 +483,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, return 0; } else { if (l2_offset) - free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t)); + qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t)); l2_table = l2_allocate(bs, l1_index); if (l2_table == NULL) return 0; @@ -513,9 +514,9 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, * */ -uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs, - uint64_t offset, - int compressed_size) +uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, + uint64_t offset, + int compressed_size) { BDRVQcowState *s = bs->opaque; int l2_index, ret; @@ -531,9 +532,9 @@ uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs, return cluster_offset & ~QCOW_OFLAG_COPIED; if (cluster_offset) - free_any_clusters(bs, cluster_offset, 1); + qcow2_free_any_clusters(bs, cluster_offset, 1); - cluster_offset = alloc_bytes(bs, compressed_size); + cluster_offset = qcow2_alloc_bytes(bs, compressed_size); nb_csectors = ((cluster_offset + compressed_size - 1) >> 9) - (cluster_offset >> 9); @@ -554,7 +555,7 @@ uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs, return cluster_offset; } -int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, +int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, QCowL2Meta *m) { BDRVQcowState *s = bs->opaque; @@ -607,8 +608,8 @@ int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, goto err; for (i = 0; i < j; i++) - free_any_clusters(bs, be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, - 1); + qcow2_free_any_clusters(bs, + be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED, 1); ret = 0; err: @@ -629,10 +630,10 @@ err: * */ -uint64_t alloc_cluster_offset(BlockDriverState *bs, - uint64_t offset, - int n_start, int n_end, - int *num, QCowL2Meta *m) +uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs, + uint64_t offset, + int n_start, int n_end, + int *num, QCowL2Meta *m) { BDRVQcowState *s = bs->opaque; int l2_index, ret; @@ -688,7 +689,7 @@ uint64_t alloc_cluster_offset(BlockDriverState *bs, /* allocate a new cluster */ - cluster_offset = alloc_clusters(bs, nb_clusters * s->cluster_size); + cluster_offset = qcow2_alloc_clusters(bs, nb_clusters * s->cluster_size); /* save info needed for meta data update */ m->offset = offset; @@ -730,7 +731,7 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size, return 0; } -int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) +int qcow2_decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) { int ret, csize, nb_csectors, sector_offset; uint64_t coffset; diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3f461c6..b38390c 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -34,7 +34,7 @@ static int update_refcount(BlockDriverState *bs, /*********************************************************/ /* refcount handling */ -int refcount_init(BlockDriverState *bs) +int qcow2_refcount_init(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; int ret, refcount_table_size2, i; @@ -55,7 +55,7 @@ int refcount_init(BlockDriverState *bs) return -ENOMEM; } -void refcount_close(BlockDriverState *bs) +void qcow2_refcount_close(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; qemu_free(s->refcount_block_cache); @@ -154,10 +154,10 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size) s->refcount_table_offset = table_offset; update_refcount(bs, table_offset, new_table_size2, 1); - free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t)); + qcow2_free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t)); return 0; fail: - free_clusters(bs, table_offset, new_table_size2); + qcow2_free_clusters(bs, table_offset, new_table_size2); qemu_free(new_table); return -EIO; } @@ -334,7 +334,7 @@ retry: return (s->free_cluster_index - nb_clusters) << s->cluster_bits; } -int64_t alloc_clusters(BlockDriverState *bs, int64_t size) +int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size) { int64_t offset; @@ -345,7 +345,7 @@ int64_t alloc_clusters(BlockDriverState *bs, int64_t size) /* only used to allocate compressed sectors. We try to allocate contiguous sectors. size must be <= cluster_size */ -int64_t alloc_bytes(BlockDriverState *bs, int size) +int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size) { BDRVQcowState *s = bs->opaque; int64_t offset, cluster_offset; @@ -353,7 +353,7 @@ int64_t alloc_bytes(BlockDriverState *bs, int size) assert(size > 0 && size <= s->cluster_size); if (s->free_byte_offset == 0) { - s->free_byte_offset = alloc_clusters(bs, s->cluster_size); + s->free_byte_offset = qcow2_alloc_clusters(bs, s->cluster_size); } redo: free_in_cluster = s->cluster_size - @@ -368,7 +368,7 @@ int64_t alloc_bytes(BlockDriverState *bs, int size) if ((offset & (s->cluster_size - 1)) != 0) update_cluster_refcount(bs, offset >> s->cluster_bits, 1); } else { - offset = alloc_clusters(bs, s->cluster_size); + offset = qcow2_alloc_clusters(bs, s->cluster_size); cluster_offset = s->free_byte_offset & ~(s->cluster_size - 1); if ((cluster_offset + s->cluster_size) == offset) { /* we are lucky: contiguous data */ @@ -383,7 +383,7 @@ int64_t alloc_bytes(BlockDriverState *bs, int size) return offset; } -void free_clusters(BlockDriverState *bs, +void qcow2_free_clusters(BlockDriverState *bs, int64_t offset, int64_t size) { update_refcount(bs, offset, size, -1); @@ -396,7 +396,7 @@ void free_clusters(BlockDriverState *bs, * */ -void free_any_clusters(BlockDriverState *bs, +void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t cluster_offset, int nb_clusters) { BDRVQcowState *s = bs->opaque; @@ -407,12 +407,13 @@ void free_any_clusters(BlockDriverState *bs, int nb_csectors; nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; - free_clusters(bs, (cluster_offset & s->cluster_offset_mask) & ~511, - nb_csectors * 512); + qcow2_free_clusters(bs, + (cluster_offset & s->cluster_offset_mask) & ~511, + nb_csectors * 512); return; } - free_clusters(bs, cluster_offset, nb_clusters << s->cluster_bits); + qcow2_free_clusters(bs, cluster_offset, nb_clusters << s->cluster_bits); return; } @@ -424,7 +425,8 @@ void free_any_clusters(BlockDriverState *bs, -void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size) +void qcow2_create_refcount_update(QCowCreateState *s, int64_t offset, + int64_t size) { int refcount; int64_t start, last, cluster_offset; @@ -442,17 +444,15 @@ void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size) } /* update the refcounts of snapshots and the copied flag */ -int update_snapshot_refcount(BlockDriverState *bs, - int64_t l1_table_offset, - int l1_size, - int addend) +int qcow2_update_snapshot_refcount(BlockDriverState *bs, + int64_t l1_table_offset, int l1_size, int addend) { BDRVQcowState *s = bs->opaque; uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, l1_allocated; int64_t old_offset, old_l2_offset; int l2_size, i, j, l1_modified, l2_modified, nb_csectors, refcount; - l2_cache_reset(bs); + qcow2_l2_cache_reset(bs); l2_table = NULL; l1_table = NULL; @@ -771,7 +771,7 @@ fail: * Returns 0 if no errors are found, the number of errors in case the image is * detected as corrupted, and -errno when an internal error occured. */ -int check_refcounts(BlockDriverState *bs) +int qcow2_check_refcounts(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; int64_t size; diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 2883e50..e1e4d89 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -46,7 +46,7 @@ typedef struct __attribute__((packed)) QCowSnapshotHeader { /* name follows */ } QCowSnapshotHeader; -void qcow_free_snapshots(BlockDriverState *bs) +void qcow2_free_snapshots(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; int i; @@ -60,7 +60,7 @@ void qcow_free_snapshots(BlockDriverState *bs) s->nb_snapshots = 0; } -int qcow_read_snapshots(BlockDriverState *bs) +int qcow2_read_snapshots(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; QCowSnapshotHeader h; @@ -111,7 +111,7 @@ int qcow_read_snapshots(BlockDriverState *bs) s->snapshots_size = offset - s->snapshots_offset; return 0; fail: - qcow_free_snapshots(bs); + qcow2_free_snapshots(bs); return -1; } @@ -137,7 +137,7 @@ static int qcow_write_snapshots(BlockDriverState *bs) } snapshots_size = offset; - snapshots_offset = alloc_clusters(bs, snapshots_size); + snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); offset = snapshots_offset; for(i = 0; i < s->nb_snapshots; i++) { @@ -177,7 +177,7 @@ static int qcow_write_snapshots(BlockDriverState *bs) goto fail; /* free the old snapshot table */ - free_clusters(bs, s->snapshots_offset, s->snapshots_size); + qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size); s->snapshots_offset = snapshots_offset; s->snapshots_size = snapshots_size; return 0; @@ -229,7 +229,7 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name) } /* if no id is provided, a new one is constructed */ -int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) +int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { BDRVQcowState *s = bs->opaque; QCowSnapshot *snapshots1, sn1, *sn = &sn1; @@ -258,12 +258,12 @@ int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) sn->date_nsec = sn_info->date_nsec; sn->vm_clock_nsec = sn_info->vm_clock_nsec; - ret = update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1); + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1); if (ret < 0) goto fail; /* create the L1 table of the snapshot */ - sn->l1_table_offset = alloc_clusters(bs, s->l1_size * sizeof(uint64_t)); + sn->l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t)); sn->l1_size = s->l1_size; l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); @@ -298,7 +298,7 @@ int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) } /* copy the snapshot 'snapshot_name' into the current disk image */ -int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) +int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) { BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; @@ -309,10 +309,10 @@ int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) return -ENOENT; sn = &s->snapshots[snapshot_index]; - if (update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0) + if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0) goto fail; - if (grow_l1_table(bs, sn->l1_size) < 0) + if (qcow2_grow_l1_table(bs, sn->l1_size) < 0) goto fail; s->l1_size = sn->l1_size; @@ -328,7 +328,7 @@ int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) be64_to_cpus(&s->l1_table[i]); } - if (update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0) + if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1) < 0) goto fail; #ifdef DEBUG_ALLOC @@ -339,7 +339,7 @@ int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) return -EIO; } -int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) +int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) { BDRVQcowState *s = bs->opaque; QCowSnapshot *sn; @@ -350,14 +350,14 @@ int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) return -ENOENT; sn = &s->snapshots[snapshot_index]; - ret = update_snapshot_refcount(bs, sn->l1_table_offset, sn->l1_size, -1); + ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset, sn->l1_size, -1); if (ret < 0) return ret; /* must update the copied flag on the current cluster offsets */ - ret = update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0); if (ret < 0) return ret; - free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t)); + qcow2_free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t)); qemu_free(sn->id_str); qemu_free(sn->name); @@ -374,7 +374,7 @@ int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) return 0; } -int qcow_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) +int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) { BDRVQcowState *s = bs->opaque; QEMUSnapshotInfo *sn_tab, *sn_info; diff --git a/block/qcow2.c b/block/qcow2.c index aeaedb7..9acbddf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -227,7 +227,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) + 512); s->cluster_cache_offset = -1; - if (refcount_init(bs) < 0) + if (qcow2_refcount_init(bs) < 0) goto fail; /* read qcow2 extensions */ @@ -247,7 +247,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) goto fail; bs->backing_file[len] = '\0'; } - if (qcow_read_snapshots(bs) < 0) + if (qcow2_read_snapshots(bs) < 0) goto fail; #ifdef DEBUG_ALLOC @@ -256,8 +256,8 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) return 0; fail: - qcow_free_snapshots(bs); - refcount_close(bs); + qcow2_free_snapshots(bs); + qcow2_refcount_close(bs); qemu_free(s->l1_table); qemu_free(s->l2_cache); qemu_free(s->cluster_cache); @@ -314,13 +314,13 @@ static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num, uint64_t cluster_offset; *pnum = nb_sectors; - cluster_offset = get_cluster_offset(bs, sector_num << 9, pnum); + cluster_offset = qcow2_get_cluster_offset(bs, sector_num << 9, pnum); return (cluster_offset != 0); } /* handle reading after the end of the backing file */ -int backing_read1(BlockDriverState *bs, +int qcow2_backing_read1(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors) { int n1; @@ -405,7 +405,7 @@ static void qcow_aio_read_cb(void *opaque, int ret) /* nothing to do */ } else { if (s->crypt_method) { - encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf, + qcow2_encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf, acb->n, 0, &s->aes_decrypt_key); } @@ -423,13 +423,14 @@ static void qcow_aio_read_cb(void *opaque, int ret) /* prepare next AIO request */ acb->n = acb->nb_sectors; - acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, &acb->n); + acb->cluster_offset = + qcow2_get_cluster_offset(bs, acb->sector_num << 9, &acb->n); index_in_cluster = acb->sector_num & (s->cluster_sectors - 1); if (!acb->cluster_offset) { if (bs->backing_hd) { /* read from the base image */ - n1 = backing_read1(bs->backing_hd, acb->sector_num, + n1 = qcow2_backing_read1(bs->backing_hd, acb->sector_num, acb->buf, acb->n); if (n1 > 0) { acb->hd_iov.iov_base = (void *)acb->buf; @@ -454,7 +455,7 @@ static void qcow_aio_read_cb(void *opaque, int ret) } } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ - if (decompress_cluster(s, acb->cluster_offset) < 0) + if (qcow2_decompress_cluster(s, acb->cluster_offset) < 0) goto done; memcpy(acb->buf, s->cluster_cache + index_in_cluster * 512, 512 * acb->n); @@ -541,8 +542,8 @@ static void qcow_aio_write_cb(void *opaque, int ret) if (ret < 0) goto done; - if (alloc_cluster_link_l2(bs, acb->cluster_offset, &acb->l2meta) < 0) { - free_any_clusters(bs, acb->cluster_offset, acb->l2meta.nb_clusters); + if (qcow2_alloc_cluster_link_l2(bs, acb->cluster_offset, &acb->l2meta) < 0) { + qcow2_free_any_clusters(bs, acb->cluster_offset, acb->l2meta.nb_clusters); goto done; } @@ -562,7 +563,7 @@ static void qcow_aio_write_cb(void *opaque, int ret) n_end > QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors) n_end = QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors; - acb->cluster_offset = alloc_cluster_offset(bs, acb->sector_num << 9, + acb->cluster_offset = qcow2_alloc_cluster_offset(bs, acb->sector_num << 9, index_in_cluster, n_end, &acb->n, &acb->l2meta); if (!acb->cluster_offset || (acb->cluster_offset & 511) != 0) { @@ -574,7 +575,7 @@ static void qcow_aio_write_cb(void *opaque, int ret) acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); } - encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf, + qcow2_encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf, acb->n, 1, &s->aes_encrypt_key); src_buf = acb->cluster_data; } else { @@ -623,7 +624,7 @@ static void qcow_close(BlockDriverState *bs) qemu_free(s->l2_cache); qemu_free(s->cluster_cache); qemu_free(s->cluster_data); - refcount_close(bs); + qcow2_refcount_close(bs); bdrv_delete(s->hd); } @@ -733,10 +734,12 @@ static int qcow_create2(const char *filename, int64_t total_size, s->refcount_block = qemu_mallocz(ref_clusters * s->cluster_size); /* update refcounts */ - create_refcount_update(s, 0, header_size); - create_refcount_update(s, s->l1_table_offset, l1_size * sizeof(uint64_t)); - create_refcount_update(s, s->refcount_table_offset, s->cluster_size); - create_refcount_update(s, s->refcount_block_offset, ref_clusters * s->cluster_size); + qcow2_create_refcount_update(s, 0, header_size); + qcow2_create_refcount_update(s, s->l1_table_offset, + l1_size * sizeof(uint64_t)); + qcow2_create_refcount_update(s, s->refcount_table_offset, s->cluster_size); + qcow2_create_refcount_update(s, s->refcount_block_offset, + ref_clusters * s->cluster_size); /* write all the data */ write(fd, &header, sizeof(header)); @@ -877,8 +880,8 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, /* could not compress: write normal cluster */ bdrv_write(bs, sector_num, buf, s->cluster_sectors); } else { - cluster_offset = alloc_compressed_cluster_offset(bs, sector_num << 9, - out_len); + cluster_offset = qcow2_alloc_compressed_cluster_offset(bs, + sector_num << 9, out_len); if (!cluster_offset) return -1; cluster_offset &= s->cluster_offset_mask; @@ -910,7 +913,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) static int qcow_check(BlockDriverState *bs) { - return check_refcounts(bs); + return qcow2_check_refcounts(bs); } #if 0 @@ -1003,10 +1006,10 @@ static BlockDriver bdrv_qcow2 = { .bdrv_aio_writev = qcow_aio_writev, .bdrv_write_compressed = qcow_write_compressed, - .bdrv_snapshot_create = qcow_snapshot_create, - .bdrv_snapshot_goto = qcow_snapshot_goto, - .bdrv_snapshot_delete = qcow_snapshot_delete, - .bdrv_snapshot_list = qcow_snapshot_list, + .bdrv_snapshot_create = qcow2_snapshot_create, + .bdrv_snapshot_goto = qcow2_snapshot_goto, + .bdrv_snapshot_delete = qcow2_snapshot_delete, + .bdrv_snapshot_list = qcow2_snapshot_list, .bdrv_get_info = qcow_get_info, .bdrv_put_buffer = qcow_put_buffer, diff --git a/block/qcow2.h b/block/qcow2.h index 397f21d..d734003 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -148,56 +148,56 @@ static inline int64_t align_offset(int64_t offset, int n) // FIXME Need qcow2_ prefix to global functions /* qcow2.c functions */ -void l2_cache_reset(BlockDriverState *bs); -int backing_read1(BlockDriverState *bs, +int qcow2_backing_read1(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); /* qcow2-refcount.c functions */ -int refcount_init(BlockDriverState *bs); -void refcount_close(BlockDriverState *bs); +int qcow2_refcount_init(BlockDriverState *bs); +void qcow2_refcount_close(BlockDriverState *bs); -int64_t alloc_clusters(BlockDriverState *bs, int64_t size); -int64_t alloc_bytes(BlockDriverState *bs, int size); -void free_clusters(BlockDriverState *bs, +int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size); +int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size); +void qcow2_free_clusters(BlockDriverState *bs, int64_t offset, int64_t size); -void free_any_clusters(BlockDriverState *bs, +void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t cluster_offset, int nb_clusters); -void create_refcount_update(QCowCreateState *s, int64_t offset, int64_t size); -int update_snapshot_refcount(BlockDriverState *bs, - int64_t l1_table_offset, - int l1_size, - int addend); +void qcow2_create_refcount_update(QCowCreateState *s, int64_t offset, + int64_t size); +int qcow2_update_snapshot_refcount(BlockDriverState *bs, + int64_t l1_table_offset, int l1_size, int addend); -int check_refcounts(BlockDriverState *bs); +int qcow2_check_refcounts(BlockDriverState *bs); /* qcow2-cluster.c functions */ -int grow_l1_table(BlockDriverState *bs, int min_size); -int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset); -void encrypt_sectors(BDRVQcowState *s, int64_t sector_num, +int qcow2_grow_l1_table(BlockDriverState *bs, int min_size); +void qcow2_l2_cache_reset(BlockDriverState *bs); +int qcow2_decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset); +void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num, uint8_t *out_buf, const uint8_t *in_buf, int nb_sectors, int enc, const AES_KEY *key); -uint64_t get_cluster_offset(BlockDriverState *bs, uint64_t offset, int *num); -uint64_t alloc_cluster_offset(BlockDriverState *bs, +uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, + int *num); +uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, int n_start, int n_end, int *num, QCowL2Meta *m); -uint64_t alloc_compressed_cluster_offset(BlockDriverState *bs, +uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset, int compressed_size); -int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, +int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset, QCowL2Meta *m); /* qcow2-snapshot.c functions */ -int qcow_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); -int qcow_snapshot_goto(BlockDriverState *bs, const char *snapshot_id); -int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); -int qcow_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab); +int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); +int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id); +int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); +int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab); -void qcow_free_snapshots(BlockDriverState *bs); -int qcow_read_snapshots(BlockDriverState *bs); +void qcow2_free_snapshots(BlockDriverState *bs); +int qcow2_read_snapshots(BlockDriverState *bs); #endif |