From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org
Cc: kwolf@redhat.com, jsnow@redhat.com, qemu-devel@nongnu.org,
mreitz@redhat.com
Subject: Re: [PATCH v4 08/10] nbd/server: introduce NBDExtentArray
Date: Wed, 26 Feb 2020 09:06:04 -0600 [thread overview]
Message-ID: <6396ff32-16a3-62fe-1001-fde8b5a4f431@redhat.com> (raw)
In-Reply-To: <20200205112041.6003-9-vsementsov@virtuozzo.com>
On 2/5/20 5:20 AM, Vladimir Sementsov-Ogievskiy wrote:
> Introduce NBDExtentArray class, to handle extents list creation in more
> controlled way and with fewer OUT parameters in functions.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> nbd/server.c | 210 +++++++++++++++++++++++++++++----------------------
> 1 file changed, 118 insertions(+), 92 deletions(-)
>
> +
> +/* Further modifications of the array after conversion are abandoned */
> +static void nbd_extent_array_convert_to_be(NBDExtentArray *ea)
> +{
> + int i;
> +
> + assert(!ea->converted_to_be);
Comment is stale - further modifications after conversion are a bug that
aborts the program, not abandoned.
> /*
> - * Populate @extents from block status. Update @bytes to be the actual
> - * length encoded (which may be smaller than the original), and update
> - * @nb_extents to the number of extents used.
> - *
> - * Returns zero on success and -errno on bdrv_block_status_above failure.
> + * Add extent to NBDExtentArray. If extent can't be added (no available space),
> + * return -1.
> + * For safety, when returning -1 for the first time, .can_add is set to false,
> + * further call to nbd_extent_array_add() will crash.
s/further call/so further calls/
> + * (to avoid the situation, when after failing to add an extent (returned -1),
> + * user miss this failure and add another extent, which is successfully added
> + * (array is full, but new extent may be squashed into the last one), then we
> + * have invalid array with skipped extent)
Long comment with nested (). I'm not sure it adds much value, I think
it can safely be dropped. But if it is kept, I suggest:
(this ensures that after a failure, no further extents can accidentally
change the bounds of the last extent in the array)
> */
> -static int blockstatus_to_extents(BlockDriverState *bs, uint64_t offset,
> - uint64_t *bytes, NBDExtent *extents,
> - unsigned int *nb_extents)
> +static int nbd_extent_array_add(NBDExtentArray *ea,
> + uint32_t length, uint32_t flags)
> {
> - uint64_t remaining_bytes = *bytes;
> - NBDExtent *extent = extents, *extents_end = extents + *nb_extents;
> - bool first_extent = true;
> + assert(ea->can_add);
> +
> + if (!length) {
> + return 0;
> + }
> +
> + /* Extend previous extent if flags are the same */
> + if (ea->count > 0 && flags == ea->extents[ea->count - 1].flags) {
> + uint64_t sum = (uint64_t)length + ea->extents[ea->count - 1].length;
> +
> + if (sum <= UINT32_MAX) {
> + ea->extents[ea->count - 1].length = sum;
> + ea->total_length += length;
> + return 0;
> + }
> + }
> +
> + if (ea->count >= ea->nb_alloc) {
> + ea->can_add = false;
> + return -1;
> + }
> +
> + ea->total_length += length;
> + ea->extents[ea->count] = (NBDExtent) {.length = length, .flags = flags};
> + ea->count++;
>
> - assert(*nb_extents);
> - while (remaining_bytes) {
> + return 0;
> +}
Looks like you properly addressed my concerns from v3.
Comment changes are trivial, so you can add:
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2020-02-26 15:07 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-05 11:20 [PATCH v4 00/10] Further bitmaps improvements Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 01/10] hbitmap: assert that we don't create bitmap larger than INT64_MAX Vladimir Sementsov-Ogievskiy
2020-02-05 15:14 ` Eric Blake
2020-02-05 11:20 ` [PATCH v4 02/10] hbitmap: move hbitmap_iter_next_word to hbitmap.c Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 03/10] hbitmap: unpublish hbitmap_iter_skip_words Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 04/10] hbitmap: drop meta bitmaps as they are unused Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 05/10] block/dirty-bitmap: switch _next_dirty_area and _next_zero to int64_t Vladimir Sementsov-Ogievskiy
2020-02-26 12:39 ` Max Reitz
2020-02-05 11:20 ` [PATCH v4 06/10] block/dirty-bitmap: add _next_dirty API Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 07/10] block/dirty-bitmap: improve _next_dirty_area API Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 08/10] nbd/server: introduce NBDExtentArray Vladimir Sementsov-Ogievskiy
2020-02-26 15:06 ` Eric Blake [this message]
2020-02-27 12:46 ` Vladimir Sementsov-Ogievskiy
2020-02-27 13:21 ` Eric Blake
2020-03-06 7:44 ` Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Vladimir Sementsov-Ogievskiy
2020-02-05 11:20 ` [PATCH v4 10/10] block/qcow2-bitmap: use bdrv_dirty_bitmap_next_dirty Vladimir Sementsov-Ogievskiy
2020-02-26 9:27 ` [PATCH v4 00/10] Further bitmaps improvements Vladimir Sementsov-Ogievskiy
2020-02-26 13:13 ` Max Reitz
2020-03-06 7:45 ` Vladimir Sementsov-Ogievskiy
2020-03-10 17:17 ` Max Reitz
2020-03-11 6:17 ` Vladimir Sementsov-Ogievskiy
2020-03-11 9:55 ` Max Reitz
2020-03-11 13:58 ` Vladimir Sementsov-Ogievskiy
2020-03-11 17:03 ` John Snow
2020-03-12 5:59 ` Vladimir Sementsov-Ogievskiy
2020-03-12 16:33 ` John Snow
2020-03-12 20:41 ` John Snow
2020-03-13 6:43 ` 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=6396ff32-16a3-62fe-1001-fde8b5a4f431@redhat.com \
--to=eblake@redhat.com \
--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).