qcow2: Remove BDS parameter from qcow2_cache_put()

This function was only using the BlockDriverState parameter to pass it
to qcow2_cache_get_table_idx(). This is no longer necessary so this
parameter can be removed.

Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 6f98155489054a457563da77cdad1a66ebb3e896.1517840876.git.berto@igalia.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Alberto Garcia 2018-02-05 16:33:07 +02:00 committed by Max Reitz
parent 2d135ee92d
commit 2013c3d44d
4 changed files with 31 additions and 31 deletions

View File

@ -407,7 +407,7 @@ int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
return qcow2_cache_do_get(bs, c, offset, table, false); return qcow2_cache_do_get(bs, c, offset, table, false);
} }
void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table) void qcow2_cache_put(Qcow2Cache *c, void **table)
{ {
int i = qcow2_cache_get_table_idx(c, *table); int i = qcow2_cache_get_table_idx(c, *table);

View File

@ -317,7 +317,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table)
memcpy(l2_table, old_table, s->cluster_size); memcpy(l2_table, old_table, s->cluster_size);
qcow2_cache_put(bs, s->l2_table_cache, (void **) &old_table); qcow2_cache_put(s->l2_table_cache, (void **) &old_table);
} }
/* write the l2 table to the file */ /* write the l2 table to the file */
@ -345,7 +345,7 @@ static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table)
fail: fail:
trace_qcow2_l2_allocate_done(bs, l1_index, ret); trace_qcow2_l2_allocate_done(bs, l1_index, ret);
if (l2_table != NULL) { if (l2_table != NULL) {
qcow2_cache_put(bs, s->l2_table_cache, (void**) table); qcow2_cache_put(s->l2_table_cache, (void **) table);
} }
s->l1_table[l1_index] = old_l2_offset; s->l1_table[l1_index] = old_l2_offset;
if (l2_offset > 0) { if (l2_offset > 0) {
@ -619,7 +619,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
abort(); abort();
} }
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
bytes_available = (int64_t)c * s->cluster_size; bytes_available = (int64_t)c * s->cluster_size;
@ -637,7 +637,7 @@ out:
return type; return type;
fail: fail:
qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table); qcow2_cache_put(s->l2_table_cache, (void **)&l2_table);
return ret; return ret;
} }
@ -744,13 +744,13 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
* allocated. */ * allocated. */
cluster_offset = be64_to_cpu(l2_table[l2_index]); cluster_offset = be64_to_cpu(l2_table[l2_index]);
if (cluster_offset & L2E_OFFSET_MASK) { if (cluster_offset & L2E_OFFSET_MASK) {
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
return 0; return 0;
} }
cluster_offset = qcow2_alloc_bytes(bs, compressed_size); cluster_offset = qcow2_alloc_bytes(bs, compressed_size);
if (cluster_offset < 0) { if (cluster_offset < 0) {
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
return 0; return 0;
} }
@ -767,7 +767,7 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED); BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
l2_table[l2_index] = cpu_to_be64(cluster_offset); l2_table[l2_index] = cpu_to_be64(cluster_offset);
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
return cluster_offset; return cluster_offset;
} }
@ -956,7 +956,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
} }
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
/* /*
* If this was a COW, we need to decrease the refcount of the old cluster. * If this was a COW, we need to decrease the refcount of the old cluster.
@ -1174,7 +1174,7 @@ static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
/* Cleanup */ /* Cleanup */
out: out:
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
/* Only return a host offset if we actually made progress. Otherwise we /* Only return a host offset if we actually made progress. Otherwise we
* would make requirements for handle_alloc() that it can't fulfill */ * would make requirements for handle_alloc() that it can't fulfill */
@ -1333,7 +1333,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
keep_old_clusters = true; keep_old_clusters = true;
} }
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
if (!alloc_cluster_offset) { if (!alloc_cluster_offset) {
/* Allocate, if necessary at a given offset in the image file */ /* Allocate, if necessary at a given offset in the image file */
@ -1689,7 +1689,7 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
qcow2_free_any_clusters(bs, old_l2_entry, 1, type); qcow2_free_any_clusters(bs, old_l2_entry, 1, type);
} }
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
return nb_clusters; return nb_clusters;
} }
@ -1783,7 +1783,7 @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
} }
} }
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
return nb_clusters; return nb_clusters;
} }
@ -1986,7 +1986,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table); qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
qcow2_cache_depends_on_flush(s->l2_table_cache); qcow2_cache_depends_on_flush(s->l2_table_cache);
} }
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
} else { } else {
if (l2_dirty) { if (l2_dirty) {
ret = qcow2_pre_write_overlap_check(bs, ret = qcow2_pre_write_overlap_check(bs,
@ -2017,7 +2017,7 @@ fail:
if (!is_active_l1) { if (!is_active_l1) {
qemu_vfree(l2_table); qemu_vfree(l2_table);
} else { } else {
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
} }
} }
return ret; return ret;

View File

@ -277,7 +277,7 @@ int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
block_index = cluster_index & (s->refcount_block_size - 1); block_index = cluster_index & (s->refcount_block_size - 1);
*refcount = s->get_refcount(refcount_block, block_index); *refcount = s->get_refcount(refcount_block, block_index);
qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); qcow2_cache_put(s->refcount_block_cache, &refcount_block);
return 0; return 0;
} }
@ -449,7 +449,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
return -EAGAIN; return -EAGAIN;
} }
qcow2_cache_put(bs, s->refcount_block_cache, refcount_block); qcow2_cache_put(s->refcount_block_cache, refcount_block);
/* /*
* If we come here, we need to grow the refcount table. Again, a new * If we come here, we need to grow the refcount table. Again, a new
@ -501,7 +501,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
fail: fail:
if (*refcount_block != NULL) { if (*refcount_block != NULL) {
qcow2_cache_put(bs, s->refcount_block_cache, refcount_block); qcow2_cache_put(s->refcount_block_cache, refcount_block);
} }
return ret; return ret;
} }
@ -660,7 +660,7 @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset,
refblock_data); refblock_data);
} }
qcow2_cache_put(bs, s->refcount_block_cache, &refblock_data); qcow2_cache_put(s->refcount_block_cache, &refblock_data);
} }
assert(block_offset == table_offset); assert(block_offset == table_offset);
@ -836,7 +836,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
/* Load the refcount block and allocate it if needed */ /* Load the refcount block and allocate it if needed */
if (table_index != old_table_index) { if (table_index != old_table_index) {
if (refcount_block) { if (refcount_block) {
qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); qcow2_cache_put(s->refcount_block_cache, &refcount_block);
} }
ret = alloc_refcount_block(bs, cluster_index, &refcount_block); ret = alloc_refcount_block(bs, cluster_index, &refcount_block);
if (ret < 0) { if (ret < 0) {
@ -874,7 +874,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
table = qcow2_cache_is_table_offset(bs, s->refcount_block_cache, table = qcow2_cache_is_table_offset(bs, s->refcount_block_cache,
offset); offset);
if (table != NULL) { if (table != NULL) {
qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); qcow2_cache_put(s->refcount_block_cache, &refcount_block);
qcow2_cache_discard(bs, s->refcount_block_cache, table); qcow2_cache_discard(bs, s->refcount_block_cache, table);
} }
@ -897,7 +897,7 @@ fail:
/* Write last changed block to disk */ /* Write last changed block to disk */
if (refcount_block) { if (refcount_block) {
qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); qcow2_cache_put(s->refcount_block_cache, &refcount_block);
} }
/* /*
@ -1319,7 +1319,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
} }
} }
qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
if (addend != 0) { if (addend != 0) {
ret = qcow2_update_cluster_refcount(bs, l2_offset >> ret = qcow2_update_cluster_refcount(bs, l2_offset >>
@ -1347,7 +1347,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
ret = bdrv_flush(bs); ret = bdrv_flush(bs);
fail: fail:
if (l2_table) { if (l2_table) {
qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); qcow2_cache_put(s->l2_table_cache, (void **) &l2_table);
} }
s->cache_discards = false; s->cache_discards = false;
@ -2847,7 +2847,7 @@ static int walk_over_reftable(BlockDriverState *bs, uint64_t **new_reftable,
new_reftable_size, new_refblock, new_reftable_size, new_refblock,
new_refblock_empty, allocated, errp); new_refblock_empty, allocated, errp);
if (ret < 0) { if (ret < 0) {
qcow2_cache_put(bs, s->refcount_block_cache, &refblock); qcow2_cache_put(s->refcount_block_cache, &refblock);
return ret; return ret;
} }
@ -2860,7 +2860,7 @@ static int walk_over_reftable(BlockDriverState *bs, uint64_t **new_reftable,
if (new_refcount_bits < 64 && refcount >> new_refcount_bits) { if (new_refcount_bits < 64 && refcount >> new_refcount_bits) {
uint64_t offset; uint64_t offset;
qcow2_cache_put(bs, s->refcount_block_cache, &refblock); qcow2_cache_put(s->refcount_block_cache, &refblock);
offset = ((reftable_index << s->refcount_block_bits) offset = ((reftable_index << s->refcount_block_bits)
+ refblock_index) << s->cluster_bits; + refblock_index) << s->cluster_bits;
@ -2881,7 +2881,7 @@ static int walk_over_reftable(BlockDriverState *bs, uint64_t **new_reftable,
new_refblock_empty = new_refblock_empty && refcount == 0; new_refblock_empty = new_refblock_empty && refcount == 0;
} }
qcow2_cache_put(bs, s->refcount_block_cache, &refblock); qcow2_cache_put(s->refcount_block_cache, &refblock);
} else { } else {
/* No refblock means every refcount is 0 */ /* No refblock means every refcount is 0 */
for (refblock_index = 0; refblock_index < s->refcount_block_size; for (refblock_index = 0; refblock_index < s->refcount_block_size;
@ -3173,14 +3173,14 @@ static int qcow2_discard_refcount_block(BlockDriverState *bs,
offset_to_reftable_index(s, discard_block_offs), offset_to_reftable_index(s, discard_block_offs),
discard_block_offs, discard_block_offs,
s->get_refcount(refblock, block_index)); s->get_refcount(refblock, block_index));
qcow2_cache_put(bs, s->refcount_block_cache, &refblock); qcow2_cache_put(s->refcount_block_cache, &refblock);
return -EINVAL; return -EINVAL;
} }
s->set_refcount(refblock, block_index, 0); s->set_refcount(refblock, block_index, 0);
qcow2_cache_entry_mark_dirty(s->refcount_block_cache, refblock); qcow2_cache_entry_mark_dirty(s->refcount_block_cache, refblock);
qcow2_cache_put(bs, s->refcount_block_cache, &refblock); qcow2_cache_put(s->refcount_block_cache, &refblock);
if (cluster_index < s->free_cluster_index) { if (cluster_index < s->free_cluster_index) {
s->free_cluster_index = cluster_index; s->free_cluster_index = cluster_index;
@ -3233,7 +3233,7 @@ int qcow2_shrink_reftable(BlockDriverState *bs)
} else { } else {
unused_block = buffer_is_zero(refblock, s->cluster_size); unused_block = buffer_is_zero(refblock, s->cluster_size);
} }
qcow2_cache_put(bs, s->refcount_block_cache, &refblock); qcow2_cache_put(s->refcount_block_cache, &refblock);
reftable_tmp[i] = unused_block ? 0 : cpu_to_be64(s->refcount_table[i]); reftable_tmp[i] = unused_block ? 0 : cpu_to_be64(s->refcount_table[i]);
} }

View File

@ -653,7 +653,7 @@ int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
void **table); void **table);
int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
void **table); void **table);
void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); void qcow2_cache_put(Qcow2Cache *c, void **table);
void *qcow2_cache_is_table_offset(BlockDriverState *bs, Qcow2Cache *c, void *qcow2_cache_is_table_offset(BlockDriverState *bs, Qcow2Cache *c,
uint64_t offset); uint64_t offset);
void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, void *table); void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, void *table);