mirror of https://github.com/xemu-project/xemu.git
qcow/qcow2: Use DIV_ROUND_UP
Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d). This patch is the result of coccinelle script scripts/coccinelle/round.cocci CC: qemu-block@nongnu.org Signed-off-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
969401fe76
commit
d737b78cc1
|
@ -868,8 +868,8 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = g_malloc0(BDRV_SECTOR_SIZE);
|
tmp = g_malloc0(BDRV_SECTOR_SIZE);
|
||||||
for (i = 0; i < ((sizeof(uint64_t)*l1_size + BDRV_SECTOR_SIZE - 1)/
|
for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE);
|
||||||
BDRV_SECTOR_SIZE); i++) {
|
i++) {
|
||||||
ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
|
ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
|
||||||
tmp, BDRV_SECTOR_SIZE, 0);
|
tmp, BDRV_SECTOR_SIZE, 0);
|
||||||
if (ret != BDRV_SECTOR_SIZE) {
|
if (ret != BDRV_SECTOR_SIZE) {
|
||||||
|
|
|
@ -1868,8 +1868,8 @@ int qcow2_expand_zero_clusters(BlockDriverState *bs,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < s->nb_snapshots; i++) {
|
for (i = 0; i < s->nb_snapshots; i++) {
|
||||||
int l1_sectors = (s->snapshots[i].l1_size * sizeof(uint64_t) +
|
int l1_sectors = DIV_ROUND_UP(s->snapshots[i].l1_size *
|
||||||
BDRV_SECTOR_SIZE - 1) / BDRV_SECTOR_SIZE;
|
sizeof(uint64_t), BDRV_SECTOR_SIZE);
|
||||||
|
|
||||||
l1_table = g_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE);
|
l1_table = g_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE);
|
||||||
|
|
||||||
|
|
|
@ -490,14 +490,12 @@ static int alloc_refcount_block(BlockDriverState *bs,
|
||||||
uint64_t table_clusters =
|
uint64_t table_clusters =
|
||||||
size_to_clusters(s, table_size * sizeof(uint64_t));
|
size_to_clusters(s, table_size * sizeof(uint64_t));
|
||||||
blocks_clusters = 1 +
|
blocks_clusters = 1 +
|
||||||
((table_clusters + s->refcount_block_size - 1)
|
DIV_ROUND_UP(table_clusters, s->refcount_block_size);
|
||||||
/ s->refcount_block_size);
|
|
||||||
uint64_t meta_clusters = table_clusters + blocks_clusters;
|
uint64_t meta_clusters = table_clusters + blocks_clusters;
|
||||||
|
|
||||||
last_table_size = table_size;
|
last_table_size = table_size;
|
||||||
table_size = next_refcount_table_size(s, blocks_used +
|
table_size = next_refcount_table_size(s, blocks_used +
|
||||||
((meta_clusters + s->refcount_block_size - 1)
|
DIV_ROUND_UP(meta_clusters, s->refcount_block_size));
|
||||||
/ s->refcount_block_size));
|
|
||||||
|
|
||||||
} while (last_table_size != table_size);
|
} while (last_table_size != table_size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue