From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
"qemu-block@nongnu.org" <qemu-block@nongnu.org>
Cc: "kwolf@redhat.com" <kwolf@redhat.com>,
"fam@euphon.net" <fam@euphon.net>,
Denis Lunev <den@virtuozzo.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"mreitz@redhat.com" <mreitz@redhat.com>,
"jsnow@redhat.com" <jsnow@redhat.com>
Subject: Re: [PATCH 08/10] nbd/server: introduce NBDExtentArray
Date: Fri, 18 Oct 2019 11:34:48 -0500 [thread overview]
Message-ID: <39449490-8cea-0387-6840-96bc06af55b2@redhat.com> (raw)
In-Reply-To: <ffee3ef7-d931-bcac-be82-2ae3533aa981@virtuozzo.com>
On 10/18/19 11:07 AM, Vladimir Sementsov-Ogievskiy wrote:
>>> static int nbd_co_send_extents(NBDClient *client, uint64_t handle,
>>> - NBDExtent *extents, unsigned int nb_extents,
>>> - uint64_t length, bool last,
>>> - uint32_t context_id, Error **errp)
>>> + NBDExtentArray *ea,
>>> + bool last, uint32_t context_id, Error **errp)
>>> {
>>> NBDStructuredMeta chunk;
>>> -
>>> + size_t len = ea->count * sizeof(ea->extents[0]);
>>> + g_autofree NBDExtent *extents = g_memdup(ea->extents, len);
>>
>> Why do we need memdup here? What's wrong with modifying ea->extents in place?...
>
> To not make ea to be IN-OUT parameter.. I don't like functions with side effects.
> It will break the code if at some point we call nbd_co_send_extents twice on same
> ea object.
>
> What is the true way? To not memdup, nbd_co_send_extents should consume the whole
> ea object..
>
> Seems, g_autoptr attribute can't be used for function parameter, gcc complains:
> nbd/server.c:1983:32: error: ‘cleanup’ attribute ignored [-Werror=attributes]
> 1983 | g_autoptr(NBDExtentArray) ea,
> | ^~~~~~~~~
>
> so, is it better
> to call nbd_co_send_external(... g_steal_pointer(&ea) ...)
>
> and than in nbd_co_send_external do
>
> g_autoptr(NBDExtentArray) local_ea = ea;
> NBDExtent *extents = local_ea->extents;
>
> ?
>
No, that makes it worse. It's that much more confusing to track who is
allocating what and where it gets cleaned up.
I personally don't see the need to avoid jumping through hoops to avoid
an in-out parameter (if we're going to rework code later, we'll notice
that we documented how things are supposed to be used), but if in-out
parameters bother you, then the approach you used, even with an extra
memdup(), is the simplest way to maintain, even if it is not the most
efficient.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2019-10-18 16:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 15:14 [PATCH 00/10] Further bitmaps improvements Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 01/10] hbitmap: introduce HBITMAP_MAX_ORIG_SIZE Vladimir Sementsov-Ogievskiy
2019-10-09 15:34 ` Eric Blake
2019-10-09 16:04 ` Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 02/10] hbitmap: move hbitmap_iter_next_word to hbitmap.c Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 03/10] hbitmap: unpublish hbitmap_iter_skip_words Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 04/10] hbitmap: drop meta bitmaps as they are unused Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 05/10] block/dirty-bitmap: switch _next_dirty_area and _next_zero to int64_t Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 06/10] block/dirty-bitmap: add _next_dirty API Vladimir Sementsov-Ogievskiy
2019-09-30 15:14 ` [PATCH 07/10] block/dirty-bitmap: improve _next_dirty_area API Vladimir Sementsov-Ogievskiy
2019-09-30 15:15 ` [PATCH 08/10] nbd/server: introduce NBDExtentArray Vladimir Sementsov-Ogievskiy
2019-10-09 17:02 ` Eric Blake
2019-10-18 16:07 ` Vladimir Sementsov-Ogievskiy
2019-10-18 16:34 ` Eric Blake [this message]
2019-09-30 15:15 ` [PATCH 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Vladimir Sementsov-Ogievskiy
2019-10-09 18:26 ` Eric Blake
2019-09-30 15:15 ` [PATCH 10/10] block/qcow2-bitmap: use bdrv_dirty_bitmap_next_dirty Vladimir Sementsov-Ogievskiy
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=39449490-8cea-0387-6840-96bc06af55b2@redhat.com \
--to=eblake@redhat.com \
--cc=den@virtuozzo.com \
--cc=fam@euphon.net \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--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).