From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com,
qemu-block@nongnu.org, rjones@redhat.com,
Max Reitz <mreitz@redhat.com>,
stefanha@redhat.com
Subject: Re: [PATCH v4 1/7] nbd: Utilize QAPI_CLONE for type conversion
Date: Fri, 23 Oct 2020 11:15:24 -0500 [thread overview]
Message-ID: <647e0bc9-b80b-cb68-f0e7-f132ab73bba0@redhat.com> (raw)
In-Reply-To: <20201009215533.1194742-2-eblake@redhat.com>
On 10/9/20 4:55 PM, Eric Blake wrote:
> Rather than open-coding the translation from the deprecated
> NbdServerAddOptions type to the preferred BlockExportOptionsNbd, it's
> better to utilize QAPI_CLONE_MEMBERS. This solves a couple of issues:
> first, if we do any more refactoring of the base type (which an
> upcoming patch plans to do), we don't have to revisit the open-coding.
> Second, our assignment to arg->name is fishy: the generated QAPI code
> currently does not visit it if arg->has_name is false, but if it DID
> visit it, we would have introduced a double-free situation when arg is
> finally freed.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> blockdev-nbd.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
v5 will fix this nasty bug:
> @@ -195,7 +197,8 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp)
> * the device name as a default here for compatibility.
> */
> if (!arg->has_name) {
> - arg->name = arg->device;
> + arg->has_name = true;
> + arg->name = g_steal_pointer(&arg->device);
> }
This causes assertion failures visible in at least iotest 149 and 192,
because arg->device was left NULL. Using g_strdup() instead fixes that.
>
> export_opts = g_new(BlockExportOptions, 1);
> @@ -205,15 +208,9 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp)
> .node_name = g_strdup(bdrv_get_node_name(bs)),
> .has_writable = arg->has_writable,
> .writable = arg->writable,
> - .u.nbd = {
> - .has_name = true,
> - .name = g_strdup(arg->name),
> - .has_description = arg->has_description,
> - .description = g_strdup(arg->description),
> - .has_bitmap = arg->has_bitmap,
> - .bitmap = g_strdup(arg->bitmap),
> - },
> };
> + QAPI_CLONE_MEMBERS(BlockExportOptionsNbd, &export_opts->u.nbd,
> + qapi_NbdServerAddOptions_base(arg));
>
> /*
> * nbd-server-add doesn't complain when a read-only device should be
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2020-10-23 16:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-09 21:55 [PATCH v4 0/7] Exposing backing-chain allocation over NBD Eric Blake
2020-10-09 21:55 ` [PATCH v4 1/7] nbd: Utilize QAPI_CLONE for type conversion Eric Blake
2020-10-14 11:15 ` Vladimir Sementsov-Ogievskiy
2020-10-23 16:15 ` Eric Blake [this message]
2020-10-09 21:55 ` [PATCH v4 2/7] nbd: Add new qemu:allocation-depth metadata context Eric Blake
2020-10-14 11:52 ` Vladimir Sementsov-Ogievskiy
2020-10-22 21:45 ` Eric Blake
2020-10-09 21:55 ` [PATCH v4 3/7] nbd: Add 'qemu-nbd -A' to expose allocation depth Eric Blake
2020-10-09 21:55 ` [PATCH v4 4/7] nbd: Update qapi to support exporting multiple bitmaps Eric Blake
2020-10-14 12:15 ` Vladimir Sementsov-Ogievskiy
2020-10-19 21:45 ` Eric Blake
2020-10-20 8:51 ` Markus Armbruster
2020-10-20 18:26 ` Eric Blake
2020-10-21 4:19 ` Markus Armbruster
2020-10-09 21:55 ` [PATCH v4 5/7] nbd: Simplify qemu bitmap context name Eric Blake
2020-10-14 12:21 ` Vladimir Sementsov-Ogievskiy
2020-10-09 21:55 ` [PATCH v4 6/7] nbd: Refactor counting of metadata contexts Eric Blake
2020-10-14 12:27 ` Vladimir Sementsov-Ogievskiy
2020-10-09 21:55 ` [PATCH v4 7/7] nbd: Allow export of multiple bitmaps for one device Eric Blake
2020-10-14 14:42 ` Vladimir Sementsov-Ogievskiy
2020-10-15 12:59 ` Eric Blake
[not found] ` <20201016152318.80889-1-eblake@redhat.com>
2020-10-27 15:33 ` [Libguestfs] [libnbd PATCH] info: Add support for new 'qemu-nbd -A' qemu:allocation-depth Eric Blake
2020-10-27 19:40 ` Richard W.M. Jones
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=647e0bc9-b80b-cb68-f0e7-f132ab73bba0@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.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).