From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com,
Michael Roth <mdroth@linux.vnet.ibm.com>,
qemu-block@nongnu.org, rjones@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com, Max Reitz <mreitz@redhat.com>
Subject: Re: [PATCH v5 02/12] qapi: Make QAPI_LIST_ADD() public
Date: Mon, 26 Oct 2020 15:25:18 +0100 [thread overview]
Message-ID: <87v9ex3vzl.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201023183652.478921-3-eblake@redhat.com> (Eric Blake's message of "Fri, 23 Oct 2020 13:36:42 -0500")
Eric Blake <eblake@redhat.com> writes:
> We have a useful macro for inserting at the front of any
> QAPI-generated list; move it from block.c to qapi/util.h so more
> places can use it, including one earlier place in block.c.
>
> Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> include/qapi/util.h | 8 ++++++++
> block.c | 15 +++------------
> 2 files changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/include/qapi/util.h b/include/qapi/util.h
> index 50201896c7a4..b6083055ce69 100644
> --- a/include/qapi/util.h
> +++ b/include/qapi/util.h
> @@ -30,4 +30,12 @@ int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
>
> int parse_qapi_name(const char *name, bool complete);
>
> +/* For any GenericList @list, insert @element at the front. */
> +#define QAPI_LIST_ADD(list, element) do { \
> + typeof(list) _tmp = g_new(typeof(*(list)), 1); \
g_new(typeof(*p), 1) is an rather roundabout way to say
g_malloc(sizeof(*p). Yes, it returns typeof(p) instead of void *, but
the chance of this catching mistakes here rounds to zero.
Not this patch's problem. Ignore me :)
> + _tmp->value = (element); \
> + _tmp->next = (list); \
> + (list) = _tmp; \
> +} while (0)
> +
> #endif
> diff --git a/block.c b/block.c
> index 430edf79bb10..45bd79299611 100644
> --- a/block.c
> +++ b/block.c
> @@ -39,6 +39,7 @@
> #include "qapi/qmp/qstring.h"
> #include "qapi/qobject-output-visitor.h"
> #include "qapi/qapi-visit-block-core.h"
> +#include "qapi/util.h"
> #include "sysemu/block-backend.h"
> #include "sysemu/sysemu.h"
> #include "qemu/notify.h"
> @@ -5211,7 +5212,7 @@ BlockDriverState *bdrv_find_node(const char *node_name)
> BlockDeviceInfoList *bdrv_named_nodes_list(bool flat,
> Error **errp)
> {
> - BlockDeviceInfoList *list, *entry;
> + BlockDeviceInfoList *list;
> BlockDriverState *bs;
>
> list = NULL;
> @@ -5221,22 +5222,12 @@ BlockDeviceInfoList *bdrv_named_nodes_list(bool flat,
> qapi_free_BlockDeviceInfoList(list);
> return NULL;
> }
> - entry = g_malloc0(sizeof(*entry));
> - entry->value = info;
> - entry->next = list;
> - list = entry;
> + QAPI_LIST_ADD(list, info);
> }
>
> return list;
> }
PATCH 12 has more. I wonder whether PATCH 12 should be squashed into
this one. You decide.
>
> -#define QAPI_LIST_ADD(list, element) do { \
> - typeof(list) _tmp = g_new(typeof(*(list)), 1); \
> - _tmp->value = (element); \
> - _tmp->next = (list); \
> - (list) = _tmp; \
> -} while (0)
> -
> typedef struct XDbgBlockGraphConstructor {
> XDbgBlockGraph *graph;
> GHashTable *graph_nodes;
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2020-10-26 14:26 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-23 18:36 [PATCH v5 00/12] Exposing backing-chain allocation over NBD Eric Blake
2020-10-23 18:36 ` [PATCH v5 01/12] qapi: Move GenericList to qapi/util.h Eric Blake
2020-10-24 9:06 ` Vladimir Sementsov-Ogievskiy
2020-10-26 14:18 ` Markus Armbruster
2020-10-26 14:22 ` Eric Blake
2020-10-23 18:36 ` [PATCH v5 02/12] qapi: Make QAPI_LIST_ADD() public Eric Blake
2020-10-24 9:10 ` Vladimir Sementsov-Ogievskiy
2020-10-26 14:25 ` Markus Armbruster [this message]
2020-10-26 14:37 ` Eric Blake
2020-10-26 14:38 ` Eric Blake
2020-10-23 18:36 ` [PATCH v5 03/12] nbd: Utilize QAPI_CLONE for type conversion Eric Blake
2020-10-24 9:17 ` Vladimir Sementsov-Ogievskiy
2020-10-26 14:41 ` Markus Armbruster
2020-10-23 18:36 ` [PATCH v5 04/12] nbd: Add new qemu:allocation-depth metadata context Eric Blake
2020-10-23 18:36 ` [PATCH v5 05/12] nbd: Add 'qemu-nbd -A' to expose allocation depth Eric Blake
2020-10-23 18:36 ` [PATCH v5 06/12] nbd: Update qapi to support exporting multiple bitmaps Eric Blake
2020-10-26 10:50 ` Peter Krempa
2020-10-26 13:06 ` Eric Blake
2020-10-23 18:36 ` [PATCH v5 07/12] nbd: Simplify qemu bitmap context name Eric Blake
2020-10-23 18:36 ` [PATCH v5 08/12] nbd: Refactor counting of metadata contexts Eric Blake
2020-10-23 18:36 ` [PATCH v5 09/12] nbd: Allow export of multiple bitmaps for one device Eric Blake
2020-10-23 18:36 ` [PATCH v5 10/12] block: Return depth level during bdrv_is_allocated_above Eric Blake
2020-10-24 9:49 ` Vladimir Sementsov-Ogievskiy
2020-10-26 12:26 ` Vladimir Sementsov-Ogievskiy
2020-10-23 18:36 ` [PATCH v5 11/12] nbd: Expose actual depth in qemu:allocation-depth Eric Blake
2020-10-24 9:59 ` Vladimir Sementsov-Ogievskiy
2020-10-26 12:31 ` Eric Blake
2020-10-23 18:36 ` [PATCH v5 12/12] qapi: Use QAPI_LIST_ADD() where possible Eric Blake
2020-10-23 20:23 ` Eric Blake
2020-10-23 18:44 ` [PATCH v5 00/12] Exposing backing-chain allocation over NBD Eric Blake
2020-10-26 14:54 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v9ex3vzl.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).