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>
This commit is contained in:
Eric Blake 2021-01-13 16:10:12 -06:00 committed by Markus Armbruster
parent dc13f40c6b
commit c3033fd372
20 changed files with 96 additions and 222 deletions

View file

@ -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);
}
}