diff options
author | Eric Blake <eblake@redhat.com> | 2021-01-13 16:10:12 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2021-01-28 08:08:45 +0100 |
commit | c3033fd372fdaf5b89190136a74b3d78880b85d6 (patch) | |
tree | 6c2464ae3f51b43702c448606acb3a6c21b6b634 /block | |
parent | dc13f40c6ba291e31d09053815c230ed88c8921f (diff) |
qapi: Use QAPI_LIST_APPEND in trivial cases
The easiest spots to use QAPI_LIST_APPEND are where we already have an
obvious pointer to the tail of a list. While at it, consistently use
the variable name 'tail' for that purpose.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210113221013.390592-5-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/dirty-bitmap.c | 8 | ||||
-rw-r--r-- | block/export/export.c | 7 | ||||
-rw-r--r-- | block/qapi.c | 23 | ||||
-rw-r--r-- | block/qcow2-bitmap.c | 15 | ||||
-rw-r--r-- | block/vmdk.c | 9 |
5 files changed, 17 insertions, 45 deletions
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index c01319b188..9b9cd71238 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -572,12 +572,12 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs) { BdrvDirtyBitmap *bm; BlockDirtyInfoList *list = NULL; - BlockDirtyInfoList **plist = &list; + BlockDirtyInfoList **tail = &list; bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { BlockDirtyInfo *info = g_new0(BlockDirtyInfo, 1); - BlockDirtyInfoList *entry = g_new0(BlockDirtyInfoList, 1); + info->count = bdrv_get_dirty_count(bm); info->granularity = bdrv_dirty_bitmap_granularity(bm); info->has_name = !!bm->name; @@ -588,9 +588,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs) info->persistent = bm->persistent; info->has_inconsistent = bm->inconsistent; info->inconsistent = bm->inconsistent; - entry->value = info; - *plist = entry; - plist = &entry->next; + QAPI_LIST_APPEND(tail, info); } bdrv_dirty_bitmaps_unlock(bs); diff --git a/block/export/export.c b/block/export/export.c index b716c1522c..fec7d9f738 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -342,11 +342,10 @@ void qmp_block_export_del(const char *id, BlockExportInfoList *qmp_query_block_exports(Error **errp) { - BlockExportInfoList *head = NULL, **p_next = &head; + BlockExportInfoList *head = NULL, **tail = &head; BlockExport *exp; QLIST_FOREACH(exp, &block_exports, next) { - BlockExportInfoList *entry = g_new0(BlockExportInfoList, 1); BlockExportInfo *info = g_new(BlockExportInfo, 1); *info = (BlockExportInfo) { .id = g_strdup(exp->id), @@ -355,9 +354,7 @@ BlockExportInfoList *qmp_query_block_exports(Error **errp) .shutting_down = !exp->user_owned, }; - entry->value = info; - *p_next = entry; - p_next = &entry->next; + QAPI_LIST_APPEND(tail, info); } return head; diff --git a/block/qapi.c b/block/qapi.c index 0ca206f559..3a1186fdcc 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -418,17 +418,12 @@ static uint64List *uint64_list(uint64_t *list, int size) { int i; uint64List *out_list = NULL; - uint64List **pout_list = &out_list; + uint64List **tail = &out_list; for (i = 0; i < size; i++) { - uint64List *entry = g_new(uint64List, 1); - entry->value = list[i]; - *pout_list = entry; - pout_list = &entry->next; + QAPI_LIST_APPEND(tail, list[i]); } - *pout_list = NULL; - return out_list; } @@ -636,26 +631,21 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes, bool query_nodes, Error **errp) { - BlockStatsList *head = NULL, **p_next = &head; + BlockStatsList *head = NULL, **tail = &head; BlockBackend *blk; BlockDriverState *bs; /* Just to be safe if query_nodes is not always initialized */ if (has_query_nodes && query_nodes) { for (bs = bdrv_next_node(NULL); bs; bs = bdrv_next_node(bs)) { - BlockStatsList *info = g_malloc0(sizeof(*info)); AioContext *ctx = bdrv_get_aio_context(bs); aio_context_acquire(ctx); - info->value = bdrv_query_bds_stats(bs, false); + QAPI_LIST_APPEND(tail, bdrv_query_bds_stats(bs, false)); aio_context_release(ctx); - - *p_next = info; - p_next = &info->next; } } else { for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) { - BlockStatsList *info; AioContext *ctx = blk_get_aio_context(blk); BlockStats *s; char *qdev; @@ -680,10 +670,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes, bdrv_query_blk_stats(s->stats, blk); aio_context_release(ctx); - info = g_malloc0(sizeof(*info)); - info->value = s; - *p_next = info; - p_next = &info->next; + QAPI_LIST_APPEND(tail, s); } } diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index d7a31a8ddc..5eef82fa55 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1061,7 +1061,7 @@ fail: static Qcow2BitmapInfoFlagsList *get_bitmap_info_flags(uint32_t flags) { Qcow2BitmapInfoFlagsList *list = NULL; - Qcow2BitmapInfoFlagsList **plist = &list; + Qcow2BitmapInfoFlagsList **tail = &list; int i; static const struct { @@ -1076,11 +1076,7 @@ static Qcow2BitmapInfoFlagsList *get_bitmap_info_flags(uint32_t flags) for (i = 0; i < map_size; ++i) { if (flags & map[i].bme) { - Qcow2BitmapInfoFlagsList *entry = - g_new0(Qcow2BitmapInfoFlagsList, 1); - entry->value = map[i].info; - *plist = entry; - plist = &entry->next; + QAPI_LIST_APPEND(tail, map[i].info); flags &= ~map[i].bme; } } @@ -1105,7 +1101,7 @@ Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(BlockDriverState *bs, Qcow2BitmapList *bm_list; Qcow2Bitmap *bm; Qcow2BitmapInfoList *list = NULL; - Qcow2BitmapInfoList **plist = &list; + Qcow2BitmapInfoList **tail = &list; if (s->nb_bitmaps == 0) { return NULL; @@ -1119,13 +1115,10 @@ Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(BlockDriverState *bs, QSIMPLEQ_FOREACH(bm, bm_list, entry) { Qcow2BitmapInfo *info = g_new0(Qcow2BitmapInfo, 1); - Qcow2BitmapInfoList *obj = g_new0(Qcow2BitmapInfoList, 1); info->granularity = 1U << bm->granularity_bits; info->name = g_strdup(bm->name); info->flags = get_bitmap_info_flags(bm->flags & ~BME_RESERVED_FLAGS); - obj->value = info; - *plist = obj; - plist = &obj->next; + QAPI_LIST_APPEND(tail, info); } bitmap_list_free(bm_list); diff --git a/block/vmdk.c b/block/vmdk.c index a00dc00eb4..4499f136bd 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2928,7 +2928,7 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs, int i; BDRVVmdkState *s = bs->opaque; ImageInfoSpecific *spec_info = g_new0(ImageInfoSpecific, 1); - ImageInfoList **next; + ImageInfoList **tail; *spec_info = (ImageInfoSpecific){ .type = IMAGE_INFO_SPECIFIC_KIND_VMDK, @@ -2943,12 +2943,9 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs, .parent_cid = s->parent_cid, }; - next = &spec_info->u.vmdk.data->extents; + tail = &spec_info->u.vmdk.data->extents; for (i = 0; i < s->num_extents; i++) { - *next = g_new0(ImageInfoList, 1); - (*next)->value = vmdk_get_extent_info(&s->extents[i]); - (*next)->next = NULL; - next = &(*next)->next; + QAPI_LIST_APPEND(tail, vmdk_get_extent_info(&s->extents[i])); } return spec_info; |