Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-01-2…
Browse files Browse the repository at this point in the history
…8' into staging

QAPI patches patches for 2021-01-28

# gpg: Signature made Thu 28 Jan 2021 07:10:21 GMT
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-qapi-2021-01-28:
  qapi: More complex uses of QAPI_LIST_APPEND
  qapi: Use QAPI_LIST_APPEND in trivial cases
  qapi: Introduce QAPI_LIST_APPEND
  qapi: A couple more QAPI_LIST_PREPEND() stragglers
  net: Clarify early exit condition

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Jan 28, 2021
2 parents 0bcd12f + 95b3a8c commit 7e7eb9f
Show file tree
Hide file tree
Showing 31 changed files with 270 additions and 554 deletions.
10 changes: 3 additions & 7 deletions backends/hostmem.c
Expand Up @@ -80,27 +80,23 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
{
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
uint16List *host_nodes = NULL;
uint16List **node = &host_nodes;
uint16List **tail = &host_nodes;
unsigned long value;

value = find_first_bit(backend->host_nodes, MAX_NODES);
if (value == MAX_NODES) {
goto ret;
}

*node = g_malloc0(sizeof(**node));
(*node)->value = value;
node = &(*node)->next;
QAPI_LIST_APPEND(tail, value);

do {
value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1);
if (value == MAX_NODES) {
break;
}

*node = g_malloc0(sizeof(**node));
(*node)->value = value;
node = &(*node)->next;
QAPI_LIST_APPEND(tail, value);
} while (true);

ret:
Expand Down
8 changes: 3 additions & 5 deletions block/dirty-bitmap.c
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
7 changes: 2 additions & 5 deletions block/export/export.c
Expand Up @@ -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),
Expand All @@ -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;
Expand Down
13 changes: 3 additions & 10 deletions block/gluster.c
Expand Up @@ -514,7 +514,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
{
QemuOpts *opts;
SocketAddress *gsconf = NULL;
SocketAddressList *curr = NULL;
SocketAddressList **tail;
QDict *backing_options = NULL;
Error *local_err = NULL;
char *str = NULL;
Expand Down Expand Up @@ -547,6 +547,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
}
gconf->path = g_strdup(ptr);
qemu_opts_del(opts);
tail = &gconf->server;

for (i = 0; i < num_servers; i++) {
str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", i);
Expand Down Expand Up @@ -655,15 +656,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
qemu_opts_del(opts);
}

if (gconf->server == NULL) {
gconf->server = g_new0(SocketAddressList, 1);
gconf->server->value = gsconf;
curr = gconf->server;
} else {
curr->next = g_new0(SocketAddressList, 1);
curr->next->value = gsconf;
curr = curr->next;
}
QAPI_LIST_APPEND(tail, gsconf);
gsconf = NULL;

qobject_unref(backing_options);
Expand Down
37 changes: 7 additions & 30 deletions block/qapi.c
Expand Up @@ -198,7 +198,7 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
{
int i, sn_count;
QEMUSnapshotInfo *sn_tab = NULL;
SnapshotInfoList *info_list, *cur_item = NULL, *head = NULL;
SnapshotInfoList *head = NULL, **tail = &head;
SnapshotInfo *info;

sn_count = bdrv_snapshot_list(bs, &sn_tab);
Expand Down Expand Up @@ -233,17 +233,7 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
info->icount = sn_tab[i].icount;
info->has_icount = sn_tab[i].icount != -1ULL;

info_list = g_new0(SnapshotInfoList, 1);
info_list->value = info;

/* XXX: waiting for the qapi to support qemu-queue.h types */
if (!cur_item) {
head = cur_item = info_list;
} else {
cur_item->next = info_list;
cur_item = info_list;
}

QAPI_LIST_APPEND(tail, info);
}

g_free(sn_tab);
Expand Down Expand Up @@ -418,17 +408,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;
}

Expand Down Expand Up @@ -636,26 +621,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;
Expand All @@ -680,10 +660,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);
}
}

Expand Down
15 changes: 4 additions & 11 deletions block/qcow2-bitmap.c
Expand Up @@ -1061,7 +1061,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp)
static Qcow2BitmapInfoFlagsList *get_bitmap_info_flags(uint32_t flags)
{
Qcow2BitmapInfoFlagsList *list = NULL;
Qcow2BitmapInfoFlagsList **plist = &list;
Qcow2BitmapInfoFlagsList **tail = &list;
int i;

static const struct {
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions block/vmdk.c
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
13 changes: 5 additions & 8 deletions blockdev.c
Expand Up @@ -3725,28 +3725,25 @@ void qmp_x_blockdev_change(const char *parent, bool has_child,

BlockJobInfoList *qmp_query_block_jobs(Error **errp)
{
BlockJobInfoList *head = NULL, **p_next = &head;
BlockJobInfoList *head = NULL, **tail = &head;
BlockJob *job;

for (job = block_job_next(NULL); job; job = block_job_next(job)) {
BlockJobInfoList *elem;
BlockJobInfo *value;
AioContext *aio_context;

if (block_job_is_internal(job)) {
continue;
}
elem = g_new0(BlockJobInfoList, 1);
aio_context = blk_get_aio_context(job->blk);
aio_context_acquire(aio_context);
elem->value = block_job_query(job, errp);
value = block_job_query(job, errp);
aio_context_release(aio_context);
if (!elem->value) {
g_free(elem);
if (!value) {
qapi_free_BlockJobInfoList(head);
return NULL;
}
*p_next = elem;
p_next = &elem->next;
QAPI_LIST_APPEND(tail, value);
}

return head;
Expand Down
9 changes: 3 additions & 6 deletions crypto/block-luks.c
Expand Up @@ -1885,7 +1885,7 @@ static int qcrypto_block_luks_get_info(QCryptoBlock *block,
{
QCryptoBlockLUKS *luks = block->opaque;
QCryptoBlockInfoLUKSSlot *slot;
QCryptoBlockInfoLUKSSlotList *slots = NULL, **prev = &info->u.luks.slots;
QCryptoBlockInfoLUKSSlotList **tail = &info->u.luks.slots;
size_t i;

info->u.luks.cipher_alg = luks->cipher_alg;
Expand All @@ -1902,10 +1902,7 @@ static int qcrypto_block_luks_get_info(QCryptoBlock *block,
sizeof(luks->header.uuid));

for (i = 0; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS; i++) {
slots = g_new0(QCryptoBlockInfoLUKSSlotList, 1);
*prev = slots;

slots->value = slot = g_new0(QCryptoBlockInfoLUKSSlot, 1);
slot = g_new0(QCryptoBlockInfoLUKSSlot, 1);
slot->active = luks->header.key_slots[i].active ==
QCRYPTO_BLOCK_LUKS_KEY_SLOT_ENABLED;
slot->key_offset = luks->header.key_slots[i].key_offset_sector
Expand All @@ -1917,7 +1914,7 @@ static int qcrypto_block_luks_get_info(QCryptoBlock *block,
slot->stripes = luks->header.key_slots[i].stripes;
}

prev = &slots->next;
QAPI_LIST_APPEND(tail, slot);
}

return 0;
Expand Down
22 changes: 6 additions & 16 deletions dump/dump.c
Expand Up @@ -2030,39 +2030,29 @@ void qmp_dump_guest_memory(bool paging, const char *file,

DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
{
DumpGuestMemoryFormatList *item;
DumpGuestMemoryCapability *cap =
g_malloc0(sizeof(DumpGuestMemoryCapability));
DumpGuestMemoryFormatList **tail = &cap->formats;

/* elf is always available */
item = g_malloc0(sizeof(DumpGuestMemoryFormatList));
cap->formats = item;
item->value = DUMP_GUEST_MEMORY_FORMAT_ELF;
QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_ELF);

/* kdump-zlib is always available */
item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
item = item->next;
item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB);

/* add new item if kdump-lzo is available */
#ifdef CONFIG_LZO
item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
item = item->next;
item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO);
#endif

/* add new item if kdump-snappy is available */
#ifdef CONFIG_SNAPPY
item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
item = item->next;
item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY);
#endif

/* Windows dump is available only if target is x86_64 */
#ifdef TARGET_X86_64
item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
item = item->next;
item->value = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
QAPI_LIST_APPEND(tail, DUMP_GUEST_MEMORY_FORMAT_WIN_DMP);
#endif

return cap;
Expand Down

0 comments on commit 7e7eb9f

Please sign in to comment.