@@ -216,7 +216,7 @@ static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_table,
continue;
}
- qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_ALWAYS);
+ qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_TYPE_ALWAYS);
bitmap_table[i] = 0;
}
}
@@ -271,7 +271,7 @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb)
clear_bitmap_table(bs, bitmap_table, tb->size);
qcow2_free_clusters(bs, tb->offset, tb->size * BME_TABLE_ENTRY_SIZE,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
g_free(bitmap_table);
tb->offset = 0;
@@ -818,7 +818,7 @@ fail:
g_free(dir);
if (!in_place && dir_offset > 0) {
- qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_OTHER);
+ qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_TYPE_OTHER);
}
return ret;
@@ -921,14 +921,14 @@ static int update_ext_header_and_dir(BlockDriverState *bs,
}
if (old_size > 0) {
- qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_OTHER);
+ qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_TYPE_OTHER);
}
return 0;
fail:
if (new_offset > 0) {
- qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_OTHER);
+ qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_TYPE_OTHER);
}
s->bitmap_directory_offset = old_offset;
@@ -1424,7 +1424,7 @@ fail:
if (tb_offset > 0) {
qcow2_free_clusters(bs, tb_offset, tb_size * sizeof(tb[0]),
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
}
g_free(tb);
@@ -67,7 +67,7 @@ int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs,
continue;
}
qcow2_free_clusters(bs, s->l1_table[i] & L1E_OFFSET_MASK,
- s->cluster_size, QCOW2_DISCARD_ALWAYS);
+ s->cluster_size, QCOW2_DISCARD_TYPE_ALWAYS);
s->l1_table[i] = 0;
}
return 0;
@@ -184,12 +184,12 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
old_l1_size = s->l1_size;
s->l1_size = new_l1_size;
qcow2_free_clusters(bs, old_l1_table_offset, old_l1_size * L1E_SIZE,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
return 0;
fail:
qemu_vfree(new_l1_table);
qcow2_free_clusters(bs, new_l1_table_offset, new_l1_size2,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
return ret;
}
@@ -373,7 +373,7 @@ fail:
s->l1_table[l1_index] = old_l2_offset;
if (l2_offset > 0) {
qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(s),
- QCOW2_DISCARD_ALWAYS);
+ QCOW2_DISCARD_TYPE_ALWAYS);
}
return ret;
}
@@ -792,7 +792,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
/* Then decrease the refcount of the old table */
if (l2_offset) {
qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(s),
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
}
/* Get the offset of the newly-allocated l2 table */
@@ -1113,7 +1113,7 @@ int coroutine_fn qcow2_alloc_cluster_link_l2(BlockDriverState *bs,
*/
if (!m->keep_old_clusters && j != 0) {
for (i = 0; i < j; i++) {
- qcow2_free_any_cluster(bs, old_cluster[i], QCOW2_DISCARD_NEVER);
+ qcow2_free_any_cluster(bs, old_cluster[i], QCOW2_DISCARD_TYPE_NEVER);
}
}
@@ -1133,7 +1133,7 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
if (!has_data_file(bs) && !m->keep_old_clusters) {
qcow2_free_clusters(bs, m->alloc_offset,
m->nb_clusters << s->cluster_bits,
- QCOW2_DISCARD_NEVER);
+ QCOW2_DISCARD_TYPE_NEVER);
}
}
@@ -2057,7 +2057,7 @@ static int zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
/* Then decrease the refcount */
if (unmap) {
- qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_REQUEST);
+ qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_TYPE_REQUEST);
}
}
@@ -2144,7 +2144,7 @@ int coroutine_fn qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset,
if (s->qcow_version < 3) {
if (!bs->backing) {
return qcow2_cluster_discard(bs, offset, bytes,
- QCOW2_DISCARD_REQUEST, false);
+ QCOW2_DISCARD_TYPE_REQUEST, false);
}
return -ENOTSUP;
}
@@ -2312,10 +2312,10 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
ret = qcow2_update_cluster_refcount(
bs, offset >> s->cluster_bits,
refcount_diff(1, l2_refcount), false,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
if (ret < 0) {
qcow2_free_clusters(bs, offset, s->cluster_size,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
goto fail;
}
}
@@ -2331,7 +2331,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
l2_offset, l2_index);
if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
qcow2_free_clusters(bs, offset, s->cluster_size,
- QCOW2_DISCARD_ALWAYS);
+ QCOW2_DISCARD_TYPE_ALWAYS);
}
ret = -EIO;
goto fail;
@@ -2342,7 +2342,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
if (ret < 0) {
if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
qcow2_free_clusters(bs, offset, s->cluster_size,
- QCOW2_DISCARD_ALWAYS);
+ QCOW2_DISCARD_TYPE_ALWAYS);
}
goto fail;
}
@@ -2352,7 +2352,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
if (ret < 0) {
if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
qcow2_free_clusters(bs, offset, s->cluster_size,
- QCOW2_DISCARD_ALWAYS);
+ QCOW2_DISCARD_TYPE_ALWAYS);
}
goto fail;
}
@@ -405,7 +405,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
/* Described somewhere else. This can recurse at most twice before we
* arrive at a block that describes itself. */
ret = update_refcount(bs, new_block, s->cluster_size, 1, false,
- QCOW2_DISCARD_NEVER);
+ QCOW2_DISCARD_TYPE_NEVER);
if (ret < 0) {
goto fail;
}
@@ -723,7 +723,7 @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset,
/* Free old table. */
qcow2_free_clusters(bs, old_table_offset,
old_table_size * REFTABLE_ENTRY_SIZE,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
return end_offset;
@@ -927,7 +927,7 @@ fail:
if (ret < 0) {
int dummy;
dummy = update_refcount(bs, offset, cluster_offset - offset, addend,
- !decrease, QCOW2_DISCARD_NEVER);
+ !decrease, QCOW2_DISCARD_TYPE_NEVER);
(void)dummy;
}
@@ -1020,7 +1020,7 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size)
return offset;
}
- ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
+ ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_TYPE_NEVER);
} while (ret == -EAGAIN);
if (ret < 0) {
@@ -1057,7 +1057,7 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
/* And then allocate them */
ret = update_refcount(bs, offset, i << s->cluster_bits, 1, false,
- QCOW2_DISCARD_NEVER);
+ QCOW2_DISCARD_TYPE_NEVER);
} while (ret == -EAGAIN);
if (ret < 0) {
@@ -1122,7 +1122,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
}
assert(offset);
- ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
+ ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_TYPE_NEVER);
if (ret < 0) {
offset = 0;
}
@@ -1331,7 +1331,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
ret = update_refcount(
bs, coffset, csize,
abs(addend), addend < 0,
- QCOW2_DISCARD_SNAPSHOT);
+ QCOW2_DISCARD_TYPE_SNAPSHOT);
if (ret < 0) {
goto fail;
}
@@ -1360,7 +1360,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
if (addend != 0) {
ret = qcow2_update_cluster_refcount(
bs, cluster_index, abs(addend), addend < 0,
- QCOW2_DISCARD_SNAPSHOT);
+ QCOW2_DISCARD_TYPE_SNAPSHOT);
if (ret < 0) {
goto fail;
}
@@ -1402,7 +1402,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
ret = qcow2_update_cluster_refcount(bs, l2_offset >>
s->cluster_bits,
abs(addend), addend < 0,
- QCOW2_DISCARD_SNAPSHOT);
+ QCOW2_DISCARD_TYPE_SNAPSHOT);
if (ret < 0) {
goto fail;
}
@@ -2346,7 +2346,7 @@ static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
ret = update_refcount(bs, i << s->cluster_bits, 1,
refcount_diff(refcount1, refcount2),
refcount1 > refcount2,
- QCOW2_DISCARD_ALWAYS);
+ QCOW2_DISCARD_TYPE_ALWAYS);
if (ret >= 0) {
(*num_fixed)++;
continue;
@@ -3412,7 +3412,7 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
qcow2_free_clusters(
bs, new_reftable_offset,
allocated_reftable_size * REFTABLE_ENTRY_SIZE,
- QCOW2_DISCARD_NEVER);
+ QCOW2_DISCARD_TYPE_NEVER);
}
new_reftable_offset = qcow2_alloc_clusters(bs, new_reftable_size *
@@ -3525,7 +3525,7 @@ done:
uint64_t offset = new_reftable[i] & REFT_OFFSET_MASK;
if (offset) {
qcow2_free_clusters(bs, offset, s->cluster_size,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
}
}
g_free(new_reftable);
@@ -3533,7 +3533,7 @@ done:
if (new_reftable_offset > 0) {
qcow2_free_clusters(bs, new_reftable_offset,
new_reftable_size * REFTABLE_ENTRY_SIZE,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
}
}
@@ -413,7 +413,7 @@ int qcow2_write_snapshots(BlockDriverState *bs)
/* free the old snapshot table */
qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size,
- QCOW2_DISCARD_SNAPSHOT);
+ QCOW2_DISCARD_TYPE_SNAPSHOT);
s->snapshots_offset = snapshots_offset;
s->snapshots_size = snapshots_size;
return 0;
@@ -421,7 +421,7 @@ int qcow2_write_snapshots(BlockDriverState *bs)
fail:
if (snapshots_offset > 0) {
qcow2_free_clusters(bs, snapshots_offset, snapshots_size,
- QCOW2_DISCARD_ALWAYS);
+ QCOW2_DISCARD_TYPE_ALWAYS);
}
return ret;
}
@@ -737,7 +737,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
* hurts by causing expensive COW for the next snapshot. */
qcow2_cluster_discard(bs, qcow2_vm_state_offset(s),
ROUND_UP(sn->vm_state_size, s->cluster_size),
- QCOW2_DISCARD_NEVER, false);
+ QCOW2_DISCARD_TYPE_NEVER, false);
#ifdef DEBUG_ALLOC
{
@@ -964,7 +964,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs,
return ret;
}
qcow2_free_clusters(bs, sn.l1_table_offset, sn.l1_size * L1E_SIZE,
- QCOW2_DISCARD_SNAPSHOT);
+ QCOW2_DISCARD_TYPE_SNAPSHOT);
/* must update the copied flag on the current cluster offsets */
ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
@@ -967,7 +967,7 @@ typedef struct Qcow2ReopenState {
int l2_slice_size; /* Number of entries in a slice of the L2 table */
bool use_lazy_refcounts;
int overlap_check;
- bool discard_passthrough[QCOW2_DISCARD_MAX];
+ bool discard_passthrough[QCOW2_DISCARD_TYPE__MAX];
uint64_t cache_clean_interval;
QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime options */
} Qcow2ReopenState;
@@ -1129,14 +1129,14 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
overlap_check_template & (1 << i)) << i;
}
- r->discard_passthrough[QCOW2_DISCARD_NEVER] = false;
- r->discard_passthrough[QCOW2_DISCARD_ALWAYS] = true;
- r->discard_passthrough[QCOW2_DISCARD_REQUEST] =
+ r->discard_passthrough[QCOW2_DISCARD_TYPE_NEVER] = false;
+ r->discard_passthrough[QCOW2_DISCARD_TYPE_ALWAYS] = true;
+ r->discard_passthrough[QCOW2_DISCARD_TYPE_REQUEST] =
qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_REQUEST,
flags & BDRV_O_UNMAP);
- r->discard_passthrough[QCOW2_DISCARD_SNAPSHOT] =
+ r->discard_passthrough[QCOW2_DISCARD_TYPE_SNAPSHOT] =
qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_SNAPSHOT, true);
- r->discard_passthrough[QCOW2_DISCARD_OTHER] =
+ r->discard_passthrough[QCOW2_DISCARD_TYPE_OTHER] =
qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false);
switch (s->crypt_method_header) {
@@ -1215,7 +1215,7 @@ static void qcow2_update_options_commit(BlockDriverState *bs,
s->overlap_check = r->overlap_check;
s->use_lazy_refcounts = r->use_lazy_refcounts;
- for (i = 0; i < QCOW2_DISCARD_MAX; i++) {
+ for (i = 0; i < QCOW2_DISCARD_TYPE__MAX; i++) {
s->discard_passthrough[i] = r->discard_passthrough[i];
}
@@ -4052,7 +4052,7 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
}
qemu_co_mutex_lock(&s->lock);
- ret = qcow2_cluster_discard(bs, offset, bytes, QCOW2_DISCARD_REQUEST,
+ ret = qcow2_cluster_discard(bs, offset, bytes, QCOW2_DISCARD_TYPE_REQUEST,
false);
qemu_co_mutex_unlock(&s->lock);
return ret;
@@ -4266,7 +4266,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
ret = qcow2_cluster_discard(bs, ROUND_UP(offset, s->cluster_size),
old_length - ROUND_UP(offset,
s->cluster_size),
- QCOW2_DISCARD_ALWAYS, true);
+ QCOW2_DISCARD_TYPE_ALWAYS, true);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to discard cropped clusters");
goto fail;
@@ -4463,7 +4463,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
error_prepend(errp, "Failed to resize underlying file: ");
qcow2_free_clusters(bs, allocation_start,
nb_new_data_clusters * s->cluster_size,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
goto fail;
}
@@ -4498,7 +4498,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
error_setg_errno(errp, -ret, "Failed to update L2 tables");
qcow2_free_clusters(bs, host_offset,
nb_new_data_clusters * s->cluster_size,
- QCOW2_DISCARD_OTHER);
+ QCOW2_DISCARD_TYPE_OTHER);
goto fail;
}
@@ -4950,12 +4950,12 @@ static int qcow2_make_empty(BlockDriverState *bs)
end_offset = bs->total_sectors * BDRV_SECTOR_SIZE;
for (offset = 0; offset < end_offset; offset += step) {
/* As this function is generally used after committing an external
- * snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
+ * snapshot, QCOW2_DISCARD_TYPE_SNAPSHOT seems appropriate. Also, the
* default action for this kind of discard is to pass the discard,
* which will ideally result in an actually smaller image file, as
* is probably desired. */
ret = qcow2_cluster_discard(bs, offset, MIN(step, end_offset - offset),
- QCOW2_DISCARD_SNAPSHOT, true);
+ QCOW2_DISCARD_TYPE_SNAPSHOT, true);
if (ret < 0) {
break;
}
@@ -288,12 +288,12 @@ enum {
};
enum qcow2_discard_type {
- QCOW2_DISCARD_NEVER = 0,
- QCOW2_DISCARD_ALWAYS,
- QCOW2_DISCARD_REQUEST,
- QCOW2_DISCARD_SNAPSHOT,
- QCOW2_DISCARD_OTHER,
- QCOW2_DISCARD_MAX
+ QCOW2_DISCARD_TYPE_NEVER = 0,
+ QCOW2_DISCARD_TYPE_ALWAYS,
+ QCOW2_DISCARD_TYPE_REQUEST,
+ QCOW2_DISCARD_TYPE_SNAPSHOT,
+ QCOW2_DISCARD_TYPE_OTHER,
+ QCOW2_DISCARD_TYPE__MAX
};
typedef struct Qcow2Feature {
@@ -383,7 +383,7 @@ typedef struct BDRVQcow2State {
Qcow2GetRefcountFunc *get_refcount;
Qcow2SetRefcountFunc *set_refcount;
- bool discard_passthrough[QCOW2_DISCARD_MAX];
+ bool discard_passthrough[QCOW2_DISCARD_TYPE__MAX];
int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
bool signaled_corruption;
In order to QAPI'fy Qcow2DiscardType in the next commit, rename its definitions to a QAPI-ready format. Mechanical change doing: $ sed -i -e 's/QCOW2_DISCARD_/QCOW2_DISCARD_TYPE_/g' \ $(git grep -l QCOW2_DISCARD_) $ sed -i -e 's/QCOW2_DISCARD_TYPE_MAX/QCOW2_DISCARD_TYPE__MAX/g' \ $(git grep -l QCOW2_DISCARD_TYPE_MAX) Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- block/qcow2-bitmap.c | 12 ++++++------ block/qcow2-cluster.c | 28 ++++++++++++++-------------- block/qcow2-refcount.c | 26 +++++++++++++------------- block/qcow2-snapshot.c | 8 ++++---- block/qcow2.c | 26 +++++++++++++------------- block/qcow2.h | 14 +++++++------- 6 files changed, 57 insertions(+), 57 deletions(-)