From 41fcfcec530513e102614d4fc3fb7fc0afa1a56a Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 14 Feb 2012 11:14:27 +0100 Subject: [PATCH 62/99] Convert the block layer to g_malloc RH-Author: Kevin Wolf Message-id: <1329218101-24213-63-git-send-email-kwolf@redhat.com> Patchwork-id: 37255 O-Subject: [RHEL-6.3 qemu-kvm PATCH v2 62/96] Convert the block layer to g_malloc Bugzilla: 783950 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Laszlo Ersek Bugzilla: 783950 Most parts of the block layer will have been touched after this patch series, so the chances are not too bad that we'll have pulled in every commit that we want and that uses qemu_malloc. Everything new will use g_malloc, so use that in order to avoid conflicts. For other parts of qemu this may look different and doing this change could do more harm than it provides benefit, so I'll leave them alone for now. We can still convert them later if it turns out to be useful. The upstream patch that did the qemu_malloc -> g_malloc conversion for the whole tree is 7267c0947d7e8ae5dff7bafd932c3bc285f43e5c, but this one is done from scratch in order to catch everything even if it deviates from upstream. Signed-off-by: Kevin Wolf --- block.c | 34 +++++++++++++++++----------------- block/blkdebug.c | 4 ++-- block/bochs.c | 4 ++-- block/cloop.c | 6 +++--- block/curl.c | 10 +++++----- block/dmg.c | 14 +++++++------- block/parallels.c | 6 +++--- block/qcow.c | 36 ++++++++++++++++++------------------ block/qcow2-cache.c | 8 ++++---- block/qcow2-cluster.c | 12 ++++++------ block/qcow2-refcount.c | 34 +++++++++++++++++----------------- block/qcow2-snapshot.c | 34 +++++++++++++++++----------------- block/qcow2.c | 46 +++++++++++++++++++++++----------------------- block/qed-check.c | 4 ++-- block/qed-cluster.c | 4 ++-- block/qed-gencb.c | 4 ++-- block/qed-l2-cache.c | 6 +++--- block/qed.c | 12 ++++++------ block/raw.c | 2 +- block/vdi.c | 16 ++++++++-------- block/vmdk.c | 24 ++++++++++++------------ block/vpc.c | 8 ++++---- block/vvfat.c | 30 +++++++++++++++--------------- 23 files changed, 179 insertions(+), 179 deletions(-) Signed-off-by: Michal Novotny --- block.c | 34 +++++++++++++++++----------------- block/blkdebug.c | 4 ++-- block/bochs.c | 4 ++-- block/cloop.c | 6 +++--- block/curl.c | 10 +++++----- block/dmg.c | 14 +++++++------- block/parallels.c | 6 +++--- block/qcow.c | 36 ++++++++++++++++++------------------ block/qcow2-cache.c | 8 ++++---- block/qcow2-cluster.c | 12 ++++++------ block/qcow2-refcount.c | 34 +++++++++++++++++----------------- block/qcow2-snapshot.c | 34 +++++++++++++++++----------------- block/qcow2.c | 46 +++++++++++++++++++++++----------------------- block/qed-check.c | 4 ++-- block/qed-cluster.c | 4 ++-- block/qed-gencb.c | 4 ++-- block/qed-l2-cache.c | 6 +++--- block/qed.c | 12 ++++++------ block/raw.c | 2 +- block/vdi.c | 16 ++++++++-------- block/vmdk.c | 24 ++++++++++++------------ block/vpc.c | 8 ++++---- block/vvfat.c | 30 +++++++++++++++--------------- 23 files changed, 179 insertions(+), 179 deletions(-) diff --git a/block.c b/block.c index 91972ef..274e973 100644 --- a/block.c +++ b/block.c @@ -183,7 +183,7 @@ BlockDriverState *bdrv_new(const char *device_name) { BlockDriverState *bs; - bs = qemu_mallocz(sizeof(BlockDriverState)); + bs = g_malloc0(sizeof(BlockDriverState)); pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); if (device_name[0] != '\0') { QTAILQ_INSERT_TAIL(&bdrv_states, bs, list); @@ -455,7 +455,7 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, } bs->drv = drv; - bs->opaque = qemu_mallocz(drv->instance_size); + bs->opaque = g_malloc0(drv->instance_size); /* * Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a @@ -512,7 +512,7 @@ free_and_fail: bdrv_delete(bs->file); bs->file = NULL; } - qemu_free(bs->opaque); + g_free(bs->opaque); bs->opaque = NULL; bs->drv = NULL; return ret; @@ -673,7 +673,7 @@ void bdrv_close(BlockDriverState *bs) bdrv_delete(bs->backing_hd); } bs->drv->bdrv_close(bs); - qemu_free(bs->opaque); + g_free(bs->opaque); #ifdef _WIN32 if (bs->is_temporary) { unlink(bs->filename); @@ -722,7 +722,7 @@ void bdrv_delete(BlockDriverState *bs) } assert(bs != bs_snapshots); - qemu_free(bs); + g_free(bs); } int bdrv_attach_dev(BlockDriverState *bs, void *dev) @@ -883,7 +883,7 @@ int bdrv_commit(BlockDriverState *bs) } total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; - buf = qemu_malloc(COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); + buf = g_malloc(COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); for (sector = 0; sector < total_sectors; sector += n) { if (drv->bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n)) { @@ -913,7 +913,7 @@ int bdrv_commit(BlockDriverState *bs) bdrv_flush(bs->backing_hd); ro_cleanup: - qemu_free(buf); + g_free(buf); if (ro) { /* re-open as RO */ @@ -2178,7 +2178,7 @@ static void block_complete_cb(void *opaque, int ret) set_dirty_bitmap(b->bs, b->sector_num, b->nb_sectors, 1); } b->cb(b->opaque, ret); - qemu_free(b); + g_free(b); } static BlockCompleteData *blk_dirty_cb_alloc(BlockDriverState *bs, @@ -2187,7 +2187,7 @@ static BlockCompleteData *blk_dirty_cb_alloc(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque) { - BlockCompleteData *blkdata = qemu_mallocz(sizeof(BlockCompleteData)); + BlockCompleteData *blkdata = g_malloc0(sizeof(BlockCompleteData)); blkdata->bs = bs; blkdata->cb = cb; @@ -2293,7 +2293,7 @@ static void multiwrite_user_cb(MultiwriteCB *mcb) if (mcb->callbacks[i].free_qiov) { qemu_iovec_destroy(mcb->callbacks[i].free_qiov); } - qemu_free(mcb->callbacks[i].free_qiov); + g_free(mcb->callbacks[i].free_qiov); qemu_vfree(mcb->callbacks[i].free_buf); } } @@ -2311,7 +2311,7 @@ static void multiwrite_cb(void *opaque, int ret) mcb->num_requests--; if (mcb->num_requests == 0) { multiwrite_user_cb(mcb); - qemu_free(mcb); + g_free(mcb); } } @@ -2371,7 +2371,7 @@ static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs, if (merge) { size_t size; - QEMUIOVector *qiov = qemu_mallocz(sizeof(*qiov)); + QEMUIOVector *qiov = g_malloc0(sizeof(*qiov)); qemu_iovec_init(qiov, reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1); @@ -2440,7 +2440,7 @@ int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs) } // Create MultiwriteCB structure - mcb = qemu_mallocz(sizeof(*mcb) + num_reqs * sizeof(*mcb->callbacks)); + mcb = g_malloc0(sizeof(*mcb) + num_reqs * sizeof(*mcb->callbacks)); mcb->num_requests = 0; mcb->num_callbacks = num_reqs; @@ -2505,7 +2505,7 @@ fail: for (i = 0; i < mcb->num_callbacks; i++) { reqs[i].error = -EIO; } - qemu_free(mcb); + g_free(mcb); return -1; } @@ -2821,7 +2821,7 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs, acb = pool->free_aiocb; pool->free_aiocb = acb->next; } else { - acb = qemu_mallocz(pool->aiocb_size); + acb = g_malloc0(pool->aiocb_size); acb->pool = pool; } acb->bs = bs; @@ -3006,11 +3006,11 @@ void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable) BDRV_SECTORS_PER_DIRTY_CHUNK * 8 - 1; bitmap_size /= BDRV_SECTORS_PER_DIRTY_CHUNK * 8; - bs->dirty_bitmap = qemu_mallocz(bitmap_size); + bs->dirty_bitmap = g_malloc0(bitmap_size); } } else { if (bs->dirty_bitmap) { - qemu_free(bs->dirty_bitmap); + g_free(bs->dirty_bitmap); bs->dirty_bitmap = NULL; } } diff --git a/block/blkdebug.c b/block/blkdebug.c index ac6c36d..a84acbc 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -214,7 +214,7 @@ static int add_rule(QemuOpts *opts, void *opaque) } /* Set attributes common for all actions */ - rule = qemu_mallocz(sizeof(*rule)); + rule = g_malloc0(sizeof(*rule)); *rule = (struct BlkdebugRule) { .event = event, .action = d->action, @@ -387,7 +387,7 @@ static void blkdebug_close(BlockDriverState *bs) for (i = 0; i < BLKDBG_EVENT_MAX; i++) { QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) { QLIST_REMOVE(rule, next); - qemu_free(rule); + g_free(rule); } } } diff --git a/block/bochs.c b/block/bochs.c index 5fe2fa3..3c2f8d1 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -136,7 +136,7 @@ static int bochs_open(BlockDriverState *bs, int flags) } s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog); - s->catalog_bitmap = qemu_malloc(s->catalog_size * 4); + s->catalog_bitmap = g_malloc(s->catalog_size * 4); if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap, s->catalog_size * 4) != s->catalog_size * 4) goto fail; @@ -210,7 +210,7 @@ static int bochs_read(BlockDriverState *bs, int64_t sector_num, static void bochs_close(BlockDriverState *bs) { BDRVBochsState *s = bs->opaque; - qemu_free(s->catalog_bitmap); + g_free(s->catalog_bitmap); } static BlockDriver bdrv_bochs = { diff --git a/block/cloop.c b/block/cloop.c index fe015c4..8cff9f2 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -70,7 +70,7 @@ static int cloop_open(BlockDriverState *bs, int flags) /* read offsets */ offsets_size = s->n_blocks * sizeof(uint64_t); - s->offsets = qemu_malloc(offsets_size); + s->offsets = g_malloc(offsets_size); if (bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size) < offsets_size) { goto cloop_close; @@ -85,8 +85,8 @@ static int cloop_open(BlockDriverState *bs, int flags) } /* initialize zlib engine */ - s->compressed_block = qemu_malloc(max_compressed_block_size+1); - s->uncompressed_block = qemu_malloc(s->block_size); + s->compressed_block = g_malloc(max_compressed_block_size+1); + s->uncompressed_block = g_malloc(s->block_size); if(inflateInit(&s->zstream) != Z_OK) goto cloop_close; s->current_block=s->n_blocks; diff --git a/block/curl.c b/block/curl.c index 2d52590..bf636da 100644 --- a/block/curl.c +++ b/block/curl.c @@ -310,7 +310,7 @@ static int curl_open(BlockDriverState *bs, const char *filename, int flags) static int inited = 0; - file = qemu_strdup(filename); + file = g_strdup(filename); s->readahead_size = READ_AHEAD_SIZE; /* Parse a trailing ":readahead=#:" param, if present. */ @@ -390,7 +390,7 @@ out: curl_easy_cleanup(state->curl); state->curl = NULL; out_noclean: - qemu_free(file); + g_free(file); return -EINVAL; } @@ -444,11 +444,11 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs, state->buf_off = 0; if (state->orig_buf) - qemu_free(state->orig_buf); + g_free(state->orig_buf); state->buf_start = start; state->buf_len = acb->end + s->readahead_size; end = MIN(start + state->buf_len, s->len) - 1; - state->orig_buf = qemu_malloc(state->buf_len); + state->orig_buf = g_malloc(state->buf_len); state->acb[0] = acb; snprintf(state->range, 127, "%zd-%zd", start, end); @@ -476,7 +476,7 @@ static void curl_close(BlockDriverState *bs) s->states[i].curl = NULL; } if (s->states[i].orig_buf) { - qemu_free(s->states[i].orig_buf); + g_free(s->states[i].orig_buf); s->states[i].orig_buf = NULL; } } diff --git a/block/dmg.c b/block/dmg.c index a3c815b..64c3cce 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -127,11 +127,11 @@ static int dmg_open(BlockDriverState *bs, int flags) chunk_count = (count-204)/40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); - s->types = qemu_realloc(s->types, new_size/2); - s->offsets = qemu_realloc(s->offsets, new_size); - s->lengths = qemu_realloc(s->lengths, new_size); - s->sectors = qemu_realloc(s->sectors, new_size); - s->sectorcounts = qemu_realloc(s->sectorcounts, new_size); + s->types = g_realloc(s->types, new_size/2); + s->offsets = g_realloc(s->offsets, new_size); + s->lengths = g_realloc(s->lengths, new_size); + s->sectors = g_realloc(s->sectors, new_size); + s->sectorcounts = g_realloc(s->sectorcounts, new_size); for(i=s->n_chunks;in_chunks+chunk_count;i++) { s->types[i] = read_uint32(bs, offset); @@ -170,8 +170,8 @@ static int dmg_open(BlockDriverState *bs, int flags) } /* initialize zlib engine */ - s->compressed_chunk = qemu_malloc(max_compressed_size+1); - s->uncompressed_chunk = qemu_malloc(512*max_sectors_per_chunk); + s->compressed_chunk = g_malloc(max_compressed_size+1); + s->uncompressed_chunk = g_malloc(512*max_sectors_per_chunk); if(inflateInit(&s->zstream) != Z_OK) goto fail; diff --git a/block/parallels.c b/block/parallels.c index 35a14aa..37d151d 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -88,7 +88,7 @@ static int parallels_open(BlockDriverState *bs, int flags) s->tracks = le32_to_cpu(ph.tracks); s->catalog_size = le32_to_cpu(ph.catalog_entries); - s->catalog_bitmap = qemu_malloc(s->catalog_size * 4); + s->catalog_bitmap = g_malloc(s->catalog_size * 4); if (bdrv_pread(bs->file, 64, s->catalog_bitmap, s->catalog_size * 4) != s->catalog_size * 4) goto fail; @@ -98,7 +98,7 @@ static int parallels_open(BlockDriverState *bs, int flags) return 0; fail: if (s->catalog_bitmap) - qemu_free(s->catalog_bitmap); + g_free(s->catalog_bitmap); return -1; } @@ -137,7 +137,7 @@ static int parallels_read(BlockDriverState *bs, int64_t sector_num, static void parallels_close(BlockDriverState *bs) { BDRVParallelsState *s = bs->opaque; - qemu_free(s->catalog_bitmap); + g_free(s->catalog_bitmap); } static BlockDriver bdrv_parallels = { diff --git a/block/qcow.c b/block/qcow.c index 713c1f5..738958f 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -129,7 +129,7 @@ static int qcow_open(BlockDriverState *bs, int flags) s->l1_size = (header.size + (1LL << shift) - 1) >> shift; s->l1_table_offset = header.l1_table_offset; - s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); + s->l1_table = g_malloc(s->l1_size * sizeof(uint64_t)); if (!s->l1_table) goto fail; if (bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) != @@ -139,13 +139,13 @@ static int qcow_open(BlockDriverState *bs, int flags) be64_to_cpus(&s->l1_table[i]); } /* alloc L2 cache */ - s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); + s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); if (!s->l2_cache) goto fail; - s->cluster_cache = qemu_malloc(s->cluster_size); + s->cluster_cache = g_malloc(s->cluster_size); if (!s->cluster_cache) goto fail; - s->cluster_data = qemu_malloc(s->cluster_size); + s->cluster_data = g_malloc(s->cluster_size); if (!s->cluster_data) goto fail; s->cluster_cache_offset = -1; @@ -164,10 +164,10 @@ static int qcow_open(BlockDriverState *bs, int flags) return 0; fail: - qemu_free(s->l1_table); - qemu_free(s->l2_cache); - qemu_free(s->cluster_cache); - qemu_free(s->cluster_data); + g_free(s->l1_table); + g_free(s->l2_cache); + g_free(s->cluster_cache); + g_free(s->cluster_data); return -1; } @@ -669,7 +669,7 @@ static int qcow_aio_write_cb(QCowAIOCB *acb) } if (s->crypt_method) { if (!acb->cluster_data) { - acb->cluster_data = qemu_mallocz(s->cluster_size); + acb->cluster_data = g_malloc0(s->cluster_size); } encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf, acb->n, 1, &s->aes_encrypt_key); @@ -719,10 +719,10 @@ static int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, static void qcow_close(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; - qemu_free(s->l1_table); - qemu_free(s->l2_cache); - qemu_free(s->cluster_cache); - qemu_free(s->cluster_data); + g_free(s->l1_table); + g_free(s->l2_cache); + g_free(s->cluster_cache); + g_free(s->cluster_data); } static int qcow_create(const char *filename, QEMUOptionParameter *options) @@ -849,7 +849,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, if (nb_sectors != s->cluster_sectors) return -EINVAL; - out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); + out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); if (!out_buf) return -1; @@ -859,7 +859,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY); if (ret != 0) { - qemu_free(out_buf); + g_free(out_buf); return -1; } @@ -870,7 +870,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, ret = deflate(&strm, Z_FINISH); if (ret != Z_STREAM_END && ret != Z_OK) { - qemu_free(out_buf); + g_free(out_buf); deflateEnd(&strm); return -1; } @@ -886,12 +886,12 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, out_len, 0, 0); cluster_offset &= s->cluster_offset_mask; if (bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len) != out_len) { - qemu_free(out_buf); + g_free(out_buf); return -1; } } - qemu_free(out_buf); + g_free(out_buf); return 0; } diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index adba912..10ebd7e 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -49,9 +49,9 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables, Qcow2Cache *c; int i; - c = qemu_mallocz(sizeof(*c)); + c = g_malloc0(sizeof(*c)); c->size = num_tables; - c->entries = qemu_mallocz(sizeof(*c->entries) * num_tables); + c->entries = g_malloc0(sizeof(*c->entries) * num_tables); c->writethrough = writethrough; for (i = 0; i < c->size; i++) { @@ -70,8 +70,8 @@ int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c) qemu_vfree(c->entries[i].table); } - qemu_free(c->entries); - qemu_free(c); + g_free(c->entries); + g_free(c); return 0; } diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f3ed1ec..0d3ac58 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -50,14 +50,14 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) #endif new_l1_size2 = sizeof(uint64_t) * new_l1_size; - new_l1_table = qemu_mallocz(align_offset(new_l1_size2, 512)); + new_l1_table = g_malloc0(align_offset(new_l1_size2, 512)); memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t)); /* write new table (align to cluster) */ BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ALLOC_TABLE); new_l1_table_offset = qcow2_alloc_clusters(bs, new_l1_size2); if (new_l1_table_offset < 0) { - qemu_free(new_l1_table); + g_free(new_l1_table); return new_l1_table_offset; } @@ -83,14 +83,14 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) if (ret < 0) { goto fail; } - qemu_free(s->l1_table); + g_free(s->l1_table); 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; return 0; fail: - qemu_free(new_l1_table); + g_free(new_l1_table); qcow2_free_clusters(bs, new_l1_table_offset, new_l1_size2); return ret; } @@ -605,7 +605,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) if (m->nb_clusters == 0) return 0; - old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t)); + old_cluster = g_malloc(m->nb_clusters * sizeof(uint64_t)); /* copy content of unmodified sectors */ start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9; @@ -676,7 +676,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) ret = 0; err: - qemu_free(old_cluster); + g_free(old_cluster); return ret; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index e126129..b79736e 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -41,7 +41,7 @@ int qcow2_refcount_init(BlockDriverState *bs) int ret, refcount_table_size2, i; refcount_table_size2 = s->refcount_table_size * sizeof(uint64_t); - s->refcount_table = qemu_malloc(refcount_table_size2); + s->refcount_table = g_malloc(refcount_table_size2); if (s->refcount_table_size > 0) { BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD); ret = bdrv_pread(bs->file, s->refcount_table_offset, @@ -59,7 +59,7 @@ int qcow2_refcount_init(BlockDriverState *bs) void qcow2_refcount_close(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; - qemu_free(s->refcount_table); + g_free(s->refcount_table); } @@ -323,8 +323,8 @@ static int alloc_refcount_block(BlockDriverState *bs, uint64_t meta_offset = (blocks_used * refcount_block_clusters) * s->cluster_size; uint64_t table_offset = meta_offset + blocks_clusters * s->cluster_size; - uint16_t *new_blocks = qemu_mallocz(blocks_clusters * s->cluster_size); - uint64_t *new_table = qemu_mallocz(table_size * sizeof(uint64_t)); + uint16_t *new_blocks = g_malloc0(blocks_clusters * s->cluster_size); + uint64_t *new_table = g_malloc0(table_size * sizeof(uint64_t)); assert(meta_offset >= (s->free_cluster_index * s->cluster_size)); @@ -349,7 +349,7 @@ static int alloc_refcount_block(BlockDriverState *bs, BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS); ret = bdrv_pwrite_sync(bs->file, meta_offset, new_blocks, blocks_clusters * s->cluster_size); - qemu_free(new_blocks); + g_free(new_blocks); if (ret < 0) { goto fail_table; } @@ -385,7 +385,7 @@ static int alloc_refcount_block(BlockDriverState *bs, uint64_t old_table_offset = s->refcount_table_offset; uint64_t old_table_size = s->refcount_table_size; - qemu_free(s->refcount_table); + g_free(s->refcount_table); s->refcount_table = new_table; s->refcount_table_size = table_size; s->refcount_table_offset = table_offset; @@ -403,7 +403,7 @@ static int alloc_refcount_block(BlockDriverState *bs, return new_block; fail_table: - qemu_free(new_table); + g_free(new_table); fail_block: if (*refcount_block != NULL) { qcow2_cache_put(bs, s->refcount_block_cache, (void**) refcount_block); @@ -720,7 +720,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l1_allocated = 0; if (l1_table_offset != s->l1_table_offset) { if (l1_size2 != 0) { - l1_table = qemu_mallocz(align_offset(l1_size2, 512)); + l1_table = g_malloc0(align_offset(l1_size2, 512)); } else { l1_table = NULL; } @@ -847,7 +847,7 @@ fail: be64_to_cpus(&l1_table[i]); } if (l1_allocated) - qemu_free(l1_table); + g_free(l1_table); return ret; } @@ -921,7 +921,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, /* Read L2 table from disk */ l2_size = s->l2_size * sizeof(uint64_t); - l2_table = qemu_malloc(l2_size); + l2_table = g_malloc(l2_size); if (bdrv_pread(bs->file, l2_offset, l2_table, l2_size) != l2_size) goto fail; @@ -979,12 +979,12 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, } } - qemu_free(l2_table); + g_free(l2_table); return 0; fail: fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n"); - qemu_free(l2_table); + g_free(l2_table); return -EIO; } @@ -1017,7 +1017,7 @@ static int check_refcounts_l1(BlockDriverState *bs, if (l1_size2 == 0) { l1_table = NULL; } else { - l1_table = qemu_malloc(l1_size2); + l1_table = g_malloc(l1_size2); if (bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2) != l1_size2) goto fail; @@ -1065,13 +1065,13 @@ static int check_refcounts_l1(BlockDriverState *bs, } } } - qemu_free(l1_table); + g_free(l1_table); return 0; fail: fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n"); res->check_errors++; - qemu_free(l1_table); + g_free(l1_table); return -EIO; } @@ -1092,7 +1092,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) size = bdrv_getlength(bs->file); nb_clusters = size_to_clusters(s, size); - refcount_table = qemu_mallocz(nb_clusters * sizeof(uint16_t)); + refcount_table = g_malloc0(nb_clusters * sizeof(uint16_t)); /* header */ inc_refcounts(bs, res, refcount_table, nb_clusters, @@ -1178,7 +1178,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res) ret = 0; fail: - qemu_free(refcount_table); + g_free(refcount_table); return ret; } diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index a398835..7d1f0e2 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -52,10 +52,10 @@ void qcow2_free_snapshots(BlockDriverState *bs) int i; for(i = 0; i < s->nb_snapshots; i++) { - qemu_free(s->snapshots[i].name); - qemu_free(s->snapshots[i].id_str); + g_free(s->snapshots[i].name); + g_free(s->snapshots[i].id_str); } - qemu_free(s->snapshots); + g_free(s->snapshots); s->snapshots = NULL; s->nb_snapshots = 0; } @@ -76,7 +76,7 @@ int qcow2_read_snapshots(BlockDriverState *bs) } offset = s->snapshots_offset; - s->snapshots = qemu_mallocz(s->nb_snapshots * sizeof(QCowSnapshot)); + s->snapshots = g_malloc0(s->nb_snapshots * sizeof(QCowSnapshot)); for(i = 0; i < s->nb_snapshots; i++) { offset = align_offset(offset, 8); if (bdrv_pread(bs->file, offset, &h, sizeof(h)) != sizeof(h)) @@ -96,13 +96,13 @@ int qcow2_read_snapshots(BlockDriverState *bs) offset += extra_data_size; - sn->id_str = qemu_malloc(id_str_size + 1); + sn->id_str = g_malloc(id_str_size + 1); if (bdrv_pread(bs->file, offset, sn->id_str, id_str_size) != id_str_size) goto fail; offset += id_str_size; sn->id_str[id_str_size] = '\0'; - sn->name = qemu_malloc(name_size + 1); + sn->name = g_malloc(name_size + 1); if (bdrv_pread(bs->file, offset, sn->name, name_size) != name_size) goto fail; offset += name_size; @@ -252,10 +252,10 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) if (find_snapshot_by_id(bs, sn_info->id_str) >= 0) return -ENOENT; - sn->id_str = qemu_strdup(sn_info->id_str); + sn->id_str = g_strdup(sn_info->id_str); if (!sn->id_str) goto fail; - sn->name = qemu_strdup(sn_info->name); + sn->name = g_strdup(sn_info->name); if (!sn->name) goto fail; sn->vm_state_size = sn_info->vm_state_size; @@ -278,7 +278,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) sn->l1_size = s->l1_size; if (s->l1_size != 0) { - l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); + l1_table = g_malloc(s->l1_size * sizeof(uint64_t)); } else { l1_table = NULL; } @@ -289,13 +289,13 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) if (bdrv_pwrite_sync(bs->file, sn->l1_table_offset, l1_table, s->l1_size * sizeof(uint64_t)) < 0) goto fail; - qemu_free(l1_table); + g_free(l1_table); l1_table = NULL; - snapshots1 = qemu_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot)); + snapshots1 = g_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot)); if (s->snapshots) { memcpy(snapshots1, s->snapshots, s->nb_snapshots * sizeof(QCowSnapshot)); - qemu_free(s->snapshots); + g_free(s->snapshots); } s->snapshots = snapshots1; s->snapshots[s->nb_snapshots++] = *sn; @@ -307,8 +307,8 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) #endif return 0; fail: - qemu_free(sn->name); - qemu_free(l1_table); + g_free(sn->name); + g_free(l1_table); return -1; } @@ -380,8 +380,8 @@ int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id) return ret; qcow2_free_clusters(bs, sn->l1_table_offset, sn->l1_size * sizeof(uint64_t)); - qemu_free(sn->id_str); - qemu_free(sn->name); + g_free(sn->id_str); + g_free(sn->name); memmove(sn, sn + 1, (s->nb_snapshots - snapshot_index - 1) * sizeof(*sn)); s->nb_snapshots--; ret = qcow2_write_snapshots(bs); @@ -407,7 +407,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) return s->nb_snapshots; } - sn_tab = qemu_mallocz(s->nb_snapshots * sizeof(QEMUSnapshotInfo)); + sn_tab = g_malloc0(s->nb_snapshots * sizeof(QEMUSnapshotInfo)); for(i = 0; i < s->nb_snapshots; i++) { sn_info = sn_tab + i; sn = s->snapshots + i; diff --git a/block/qcow2.c b/block/qcow2.c index 61fc405..2e08ae8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -218,7 +218,7 @@ static int qcow2_open(BlockDriverState *bs, int flags) } s->l1_table_offset = header.l1_table_offset; if (s->l1_size > 0) { - s->l1_table = qemu_mallocz( + s->l1_table = g_malloc0( align_offset(s->l1_size * sizeof(uint64_t), 512)); ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)); @@ -236,9 +236,9 @@ static int qcow2_open(BlockDriverState *bs, int flags) s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE, writethrough); - s->cluster_cache = qemu_malloc(s->cluster_size); + s->cluster_cache = g_malloc(s->cluster_size); /* one more sector for decompressed data alignment */ - s->cluster_data = qemu_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + s->cluster_data = g_malloc(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); s->cluster_cache_offset = -1; @@ -289,12 +289,12 @@ static int qcow2_open(BlockDriverState *bs, int flags) fail: qcow2_free_snapshots(bs); qcow2_refcount_close(bs); - qemu_free(s->l1_table); + g_free(s->l1_table); if (s->l2_table_cache) { qcow2_cache_destroy(bs, s->l2_table_cache); } - qemu_free(s->cluster_cache); - qemu_free(s->cluster_data); + g_free(s->cluster_cache); + g_free(s->cluster_data); return ret; } @@ -492,7 +492,7 @@ static int qcow2_aio_read_cb(QCowAIOCB *acb) */ if (!acb->cluster_data) { acb->cluster_data = - qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); + g_malloc0(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); } assert(acb->cur_nr_sectors <= @@ -623,7 +623,7 @@ static int qcow2_aio_write_cb(QCowAIOCB *acb) if (s->crypt_method) { if (!acb->cluster_data) { - acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS * + acb->cluster_data = g_malloc0(QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); } @@ -677,7 +677,7 @@ static int qcow2_co_writev(BlockDriverState *bs, static void qcow2_close(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; - qemu_free(s->l1_table); + g_free(s->l1_table); qcow2_cache_flush(bs, s->l2_table_cache); qcow2_cache_flush(bs, s->refcount_block_cache); @@ -685,8 +685,8 @@ static void qcow2_close(BlockDriverState *bs) qcow2_cache_destroy(bs, s->l2_table_cache); qcow2_cache_destroy(bs, s->refcount_block_cache); - qemu_free(s->cluster_cache); - qemu_free(s->cluster_data); + g_free(s->cluster_cache); + g_free(s->cluster_data); qcow2_refcount_close(bs); } @@ -860,7 +860,7 @@ static int preallocate(BlockDriverState *bs, enum prealloc_mode mode) /* Then write zeros to the cluster data, if requested */ if (mode == PREALLOC_FULL) { - void *buf = qemu_mallocz(IO_BUF_SIZE); + void *buf = g_malloc0(IO_BUF_SIZE); nb_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; offset = 0; @@ -869,7 +869,7 @@ static int preallocate(BlockDriverState *bs, enum prealloc_mode mode) num = MIN(nb_sectors, IO_BUF_SIZE / BDRV_SECTOR_SIZE); ret = bdrv_write(bs, offset >> BDRV_SECTOR_BITS, buf, num); if (ret < 0) { - qemu_free(buf); + g_free(buf); return ret; } @@ -877,7 +877,7 @@ static int preallocate(BlockDriverState *bs, enum prealloc_mode mode) offset += num << 9; } - qemu_free(buf); + g_free(buf); } /* @@ -1026,7 +1026,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, } while (ref_clusters != old_ref_clusters); - s->refcount_table = qemu_mallocz(reftable_clusters * s->cluster_size); + s->refcount_table = g_malloc0(reftable_clusters * s->cluster_size); s->refcount_table_offset = offset; header.refcount_table_offset = cpu_to_be64(offset); @@ -1039,7 +1039,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, offset += s->cluster_size; } - s->refcount_block = qemu_mallocz(ref_clusters * s->cluster_size); + s->refcount_block = g_malloc0(ref_clusters * s->cluster_size); /* update refcounts */ qcow2_create_refcount_update(s, 0, header_size); @@ -1115,8 +1115,8 @@ static int qcow2_create2(const char *filename, int64_t total_size, ret = 0; exit: - qemu_free(s->refcount_table); - qemu_free(s->refcount_block); + g_free(s->refcount_table); + g_free(s->refcount_block); cret = close(fd); if (ret == 0 && cret < 0) @@ -1233,7 +1233,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, if (nb_sectors != s->cluster_sectors) return -EINVAL; - out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); + out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); /* best compression, small window, no zlib header */ memset(&strm, 0, sizeof(strm)); @@ -1241,7 +1241,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY); if (ret != 0) { - qemu_free(out_buf); + g_free(out_buf); return -1; } @@ -1252,7 +1252,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, ret = deflate(&strm, Z_FINISH); if (ret != Z_STREAM_END && ret != Z_OK) { - qemu_free(out_buf); + g_free(out_buf); deflateEnd(&strm); return -1; } @@ -1271,12 +1271,12 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, cluster_offset &= s->cluster_offset_mask; BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED); if (bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len) != out_len) { - qemu_free(out_buf); + g_free(out_buf); return -1; } } - qemu_free(out_buf); + g_free(out_buf); return 0; } diff --git a/block/qed-check.c b/block/qed-check.c index 22cd07f..e4a49ce 100644 --- a/block/qed-check.c +++ b/block/qed-check.c @@ -197,7 +197,7 @@ int qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix) }; int ret; - check.used_clusters = qemu_mallocz(((check.nclusters + 31) / 32) * + check.used_clusters = g_malloc0(((check.nclusters + 31) / 32) * sizeof(check.used_clusters[0])); ret = qed_check_l1_table(&check, s->l1_table); @@ -206,6 +206,6 @@ int qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix) qed_check_for_leaks(&check); } - qemu_free(check.used_clusters); + g_free(check.used_clusters); return ret; } diff --git a/block/qed-cluster.c b/block/qed-cluster.c index 3e19ad1..f64b2af 100644 --- a/block/qed-cluster.c +++ b/block/qed-cluster.c @@ -108,7 +108,7 @@ static void qed_find_cluster_cb(void *opaque, int ret) out: find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len); - qemu_free(find_cluster_cb); + g_free(find_cluster_cb); } /** @@ -152,7 +152,7 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, return; } - find_cluster_cb = qemu_malloc(sizeof(*find_cluster_cb)); + find_cluster_cb = g_malloc(sizeof(*find_cluster_cb)); find_cluster_cb->s = s; find_cluster_cb->pos = pos; find_cluster_cb->len = len; diff --git a/block/qed-gencb.c b/block/qed-gencb.c index 1513dc6..7d7ac1f 100644 --- a/block/qed-gencb.c +++ b/block/qed-gencb.c @@ -15,7 +15,7 @@ void *gencb_alloc(size_t len, BlockDriverCompletionFunc *cb, void *opaque) { - GenericCB *gencb = qemu_malloc(len); + GenericCB *gencb = g_malloc(len); gencb->cb = cb; gencb->opaque = opaque; return gencb; @@ -27,6 +27,6 @@ void gencb_complete(void *opaque, int ret) BlockDriverCompletionFunc *cb = gencb->cb; void *user_opaque = gencb->opaque; - qemu_free(gencb); + g_free(gencb); cb(user_opaque, ret); } diff --git a/block/qed-l2-cache.c b/block/qed-l2-cache.c index 57518a4..02b81a2 100644 --- a/block/qed-l2-cache.c +++ b/block/qed-l2-cache.c @@ -74,7 +74,7 @@ void qed_free_l2_cache(L2TableCache *l2_cache) QTAILQ_FOREACH_SAFE(entry, &l2_cache->entries, node, next_entry) { qemu_vfree(entry->table); - qemu_free(entry); + g_free(entry); } } @@ -89,7 +89,7 @@ CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l2_cache) { CachedL2Table *entry; - entry = qemu_mallocz(sizeof(*entry)); + entry = g_malloc0(sizeof(*entry)); entry->ref++; trace_qed_alloc_l2_cache_entry(l2_cache, entry); @@ -111,7 +111,7 @@ void qed_unref_l2_cache_entry(CachedL2Table *entry) trace_qed_unref_l2_cache_entry(entry, entry->ref); if (entry->ref == 0) { qemu_vfree(entry->table); - qemu_free(entry); + g_free(entry); } } diff --git a/block/qed.c b/block/qed.c index 6a7faa3..c644717 100644 --- a/block/qed.c +++ b/block/qed.c @@ -588,7 +588,7 @@ static int qed_create(const char *filename, uint32_t cluster_size, goto out; } - l1_table = qemu_mallocz(l1_size); + l1_table = g_malloc0(l1_size); ret = bdrv_pwrite(bs, header.l1_table_offset, l1_table, l1_size); if (ret < 0) { goto out; @@ -596,7 +596,7 @@ static int qed_create(const char *filename, uint32_t cluster_size, ret = 0; /* success */ out: - qemu_free(l1_table); + g_free(l1_table); bdrv_delete(bs); return ret; } @@ -1451,7 +1451,7 @@ static void qed_aio_copy_backing_cb(void *opaque, int ret) qemu_iovec_destroy(©_backing_data->qiov); qemu_vfree(copy_backing_data->buffer); - qemu_free(copy_backing_data); + g_free(copy_backing_data); } static void qed_copy_backing_find_cluster_cb(void *opaque, int ret, @@ -1528,7 +1528,7 @@ static BlockDriverAIOCB *bdrv_qed_aio_copy_backing(BlockDriverState *bs, uint64_t start_cluster; QEMUIOVector *qiov; - copy_backing_data = qemu_mallocz(sizeof(*copy_backing_data)); + copy_backing_data = g_malloc0(sizeof(*copy_backing_data)); copy_backing_data->cb = cb; copy_backing_data->opaque = opaque; @@ -1656,7 +1656,7 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs, } /* Prepare new header */ - buffer = qemu_malloc(buffer_len); + buffer = g_malloc(buffer_len); qed_header_cpu_to_le(&new_header, &le_header); memcpy(buffer, &le_header, sizeof(le_header)); @@ -1667,7 +1667,7 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs, /* Write new header */ ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len); - qemu_free(buffer); + g_free(buffer); if (ret == 0) { memcpy(&s->header, &new_header, sizeof(new_header)); } diff --git a/block/raw.c b/block/raw.c index fe46729..63cf2d3 100644 --- a/block/raw.c +++ b/block/raw.c @@ -124,7 +124,7 @@ static int raw_has_zero_init(BlockDriverState *bs) static BlockDriver bdrv_raw = { .format_name = "raw", - /* It's really 0, but we need to make qemu_malloc() happy */ + /* It's really 0, but we need to make g_malloc() happy */ .instance_size = 1, .bdrv_open = raw_open, diff --git a/block/vdi.c b/block/vdi.c index 3b1d195..31e279e 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -300,7 +300,7 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res) uint32_t *bmap; logout("\n"); - bmap = qemu_malloc(s->header.blocks_in_image * sizeof(uint32_t)); + bmap = g_malloc(s->header.blocks_in_image * sizeof(uint32_t)); memset(bmap, 0xff, s->header.blocks_in_image * sizeof(uint32_t)); /* Check block map and value of blocks_allocated. */ @@ -330,7 +330,7 @@ static int vdi_check(BlockDriverState *bs, BdrvCheckResult *res) res->corruptions++; } - qemu_free(bmap); + g_free(bmap); return 0; } @@ -432,7 +432,7 @@ static int vdi_open(BlockDriverState *bs, int flags) bmap_size = header.blocks_in_image * sizeof(uint32_t); bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE; - s->bmap = qemu_malloc(bmap_size * SECTOR_SIZE); + s->bmap = g_malloc(bmap_size * SECTOR_SIZE); if (bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) < 0) { goto fail_free_bmap; } @@ -440,7 +440,7 @@ static int vdi_open(BlockDriverState *bs, int flags) return 0; fail_free_bmap: - qemu_free(s->bmap); + g_free(s->bmap); fail: return -1; @@ -671,7 +671,7 @@ static void vdi_aio_write_cb(void *opaque, int ret) uint64_t offset; uint32_t bmap_first; uint32_t bmap_last; - qemu_free(acb->block_buffer); + g_free(acb->block_buffer); acb->block_buffer = NULL; bmap_first = acb->bmap_first; bmap_last = acb->bmap_last; @@ -726,7 +726,7 @@ static void vdi_aio_write_cb(void *opaque, int ret) (uint64_t)bmap_entry * s->block_sectors; block = acb->block_buffer; if (block == NULL) { - block = qemu_mallocz(s->block_size); + block = g_malloc0(s->block_size); acb->block_buffer = block; acb->bmap_first = block_index; assert(!acb->header_modified); @@ -854,7 +854,7 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) result = -errno; } - bmap = (uint32_t *)qemu_mallocz(bmap_size); + bmap = (uint32_t *)g_malloc0(bmap_size); for (i = 0; i < blocks; i++) { if (image_type == VDI_TYPE_STATIC) { bmap[i] = i; @@ -865,7 +865,7 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) if (write(fd, bmap, bmap_size) < 0) { result = -errno; } - qemu_free(bmap); + g_free(bmap); if (image_type == VDI_TYPE_STATIC) { if (ftruncate(fd, sizeof(header) + bmap_size + blocks * block_size)) { result = -errno; diff --git a/block/vmdk.c b/block/vmdk.c index d658639..e2cfcad 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -287,7 +287,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) gd_size = gde_entries * sizeof(uint32_t); /* write RGD */ - rgd_buf = qemu_malloc(gd_size); + rgd_buf = g_malloc(gd_size); if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) { ret = -errno; goto fail_rgd; @@ -306,7 +306,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) } /* write GD */ - gd_buf = qemu_malloc(gd_size); + gd_buf = g_malloc(gd_size); if (lseek(p_fd, gd_offset, SEEK_SET) == -1) { ret = -errno; goto fail_gd; @@ -326,9 +326,9 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) ret = 0; fail_gd: - qemu_free(gd_buf); + g_free(gd_buf); fail_rgd: - qemu_free(rgd_buf); + g_free(rgd_buf); fail: close(p_fd); close(snp_fd); @@ -408,7 +408,7 @@ static int vmdk_open(BlockDriverState *bs, int flags) /* read the L1 table */ l1_size = s->l1_size * sizeof(uint32_t); - s->l1_table = qemu_malloc(l1_size); + s->l1_table = g_malloc(l1_size); if (bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, l1_size) != l1_size) goto fail; for(i = 0; i < s->l1_size; i++) { @@ -416,7 +416,7 @@ static int vmdk_open(BlockDriverState *bs, int flags) } if (s->l1_backup_table_offset) { - s->l1_backup_table = qemu_malloc(l1_size); + s->l1_backup_table = g_malloc(l1_size); if (bdrv_pread(bs->file, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size) goto fail; for(i = 0; i < s->l1_size; i++) { @@ -424,12 +424,12 @@ static int vmdk_open(BlockDriverState *bs, int flags) } } - s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t)); + s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t)); return 0; fail: - qemu_free(s->l1_backup_table); - qemu_free(s->l1_table); - qemu_free(s->l2_cache); + g_free(s->l1_backup_table); + g_free(s->l1_table); + g_free(s->l2_cache); return -1; } @@ -819,8 +819,8 @@ static void vmdk_close(BlockDriverState *bs) { BDRVVmdkState *s = bs->opaque; - qemu_free(s->l1_table); - qemu_free(s->l2_cache); + g_free(s->l1_table); + g_free(s->l2_cache); } static int vmdk_flush(BlockDriverState *bs) diff --git a/block/vpc.c b/block/vpc.c index 86a7271..d9f5e6e 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -190,7 +190,7 @@ static int vpc_open(BlockDriverState *bs, int flags) s->bitmap_size = ((s->block_size / (8 * 512)) + 511) & ~511; s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries); - s->pagetable = qemu_malloc(s->max_table_entries * 4); + s->pagetable = g_malloc(s->max_table_entries * 4); s->bat_offset = be64_to_cpu(dyndisk_header->table_offset); if (bdrv_pread(bs->file, s->bat_offset, s->pagetable, @@ -214,7 +214,7 @@ static int vpc_open(BlockDriverState *bs, int flags) s->last_bitmap_offset = (int64_t) -1; #ifdef CACHE - s->pageentry_u8 = qemu_malloc(512); + s->pageentry_u8 = g_malloc(512); s->pageentry_u32 = s->pageentry_u8; s->pageentry_u16 = s->pageentry_u8; s->last_pagetable = -1; @@ -581,9 +581,9 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options) static void vpc_close(BlockDriverState *bs) { BDRVVPCState *s = bs->opaque; - qemu_free(s->pagetable); + g_free(s->pagetable); #ifdef CACHE - qemu_free(s->pageentry_u8); + g_free(s->pageentry_u8); #endif } diff --git a/block/vvfat.c b/block/vvfat.c index a117a6c..1d88070 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -101,7 +101,7 @@ static inline int array_ensure_allocated(array_t* array, int index) { if((index + 1) * array->item_size > array->size) { int new_size = (index + 32) * array->item_size; - array->pointer = qemu_realloc(array->pointer, new_size); + array->pointer = g_realloc(array->pointer, new_size); if (!array->pointer) return -1; array->size = new_size; @@ -127,7 +127,7 @@ static inline void* array_get_next(array_t* array) { static inline void* array_insert(array_t* array,unsigned int index,unsigned int count) { if((array->next+count)*array->item_size>array->size) { int increment=count*array->item_size; - array->pointer=qemu_realloc(array->pointer,array->size+increment); + array->pointer=g_realloc(array->pointer,array->size+increment); if(!array->pointer) return NULL; array->size+=increment; @@ -159,7 +159,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun is=array->item_size; from=array->pointer+index_from*is; to=array->pointer+index_to*is; - buf=qemu_malloc(is*count); + buf=g_malloc(is*count); memcpy(buf,from,is*count); if(index_tod_name); if(stat(buffer,&st)<0) { @@ -849,7 +849,7 @@ static int init_directories(BDRVVVFATState* s, memset(&(s->first_sectors[0]),0,0x40*0x200); s->cluster_size=s->sectors_per_cluster*0x200; - s->cluster_buffer=qemu_malloc(s->cluster_size); + s->cluster_buffer=g_malloc(s->cluster_size); /* * The formula: sc = spf+1+spf*spc*(512*8/fat_type), @@ -883,7 +883,7 @@ static int init_directories(BDRVVVFATState* s, mapping->dir_index = 0; mapping->info.dir.parent_mapping_index = -1; mapping->first_mapping_index = -1; - mapping->path = qemu_strdup(dirname); + mapping->path = g_strdup(dirname); i = strlen(mapping->path); if (i > 0 && mapping->path[i - 1] == '/') mapping->path[i - 1] = '\0'; @@ -1633,10 +1633,10 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, /* rename */ if (strcmp(basename, basename2)) - schedule_rename(s, cluster_num, qemu_strdup(path)); + schedule_rename(s, cluster_num, g_strdup(path)); } else if (is_file(direntry)) /* new file */ - schedule_new_file(s, qemu_strdup(path), cluster_num); + schedule_new_file(s, g_strdup(path), cluster_num); else { assert(0); return 0; @@ -1730,7 +1730,7 @@ static int check_directory_consistency(BDRVVVFATState *s, int cluster_num, const char* path) { int ret = 0; - unsigned char* cluster = qemu_malloc(s->cluster_size); + unsigned char* cluster = g_malloc(s->cluster_size); direntry_t* direntries = (direntry_t*)cluster; mapping_t* mapping = find_mapping_for_cluster(s, cluster_num); @@ -1753,10 +1753,10 @@ static int check_directory_consistency(BDRVVVFATState *s, mapping->mode &= ~MODE_DELETED; if (strcmp(basename, basename2)) - schedule_rename(s, cluster_num, qemu_strdup(path)); + schedule_rename(s, cluster_num, g_strdup(path)); } else /* new directory */ - schedule_mkdir(s, cluster_num, qemu_strdup(path)); + schedule_mkdir(s, cluster_num, g_strdup(path)); lfn_init(&lfn); do { @@ -1871,7 +1871,7 @@ DLOG(checkpoint()); */ if (s->fat2 == NULL) { int size = 0x200 * s->sectors_per_fat; - s->fat2 = qemu_malloc(size); + s->fat2 = g_malloc(size); memcpy(s->fat2, s->fat.pointer, size); } check = vvfat_read(s->bs, @@ -2213,7 +2213,7 @@ static int commit_one_file(BDRVVVFATState* s, uint32_t first_cluster = c; mapping_t* mapping = find_mapping_for_cluster(s, c); uint32_t size = filesize_of_direntry(direntry); - char* cluster = qemu_malloc(s->cluster_size); + char* cluster = g_malloc(s->cluster_size); uint32_t i; int fd = 0; @@ -2379,7 +2379,7 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s) mapping_t* m = find_mapping_for_cluster(s, begin_of_direntry(d)); int l = strlen(m->path); - char* new_path = qemu_malloc(l + diff + 1); + char* new_path = g_malloc(l + diff + 1); assert(!strncmp(m->path, mapping->path, l2)); @@ -2781,7 +2781,7 @@ static int enable_write_target(BDRVVVFATState *s) array_init(&(s->commits), sizeof(commit_t)); - s->qcow_filename = qemu_malloc(1024); + s->qcow_filename = g_malloc(1024); get_tmp_filename(s->qcow_filename, 1024); bdrv_qcow = bdrv_find_format("qcow"); -- 1.7.7.5