qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, qemu-devel@nongnu.org,
	mreitz@redhat.com, den@openvz.org, jsnow@redhat.com
Subject: Re: [PATCH 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area
Date: Wed, 9 Oct 2019 13:26:36 -0500	[thread overview]
Message-ID: <59fa171e-f885-620e-4dfd-e690e7906928@redhat.com> (raw)
In-Reply-To: <20190930151502.7829-10-vsementsov@virtuozzo.com>

On 9/30/19 10:15 AM, Vladimir Sementsov-Ogievskiy wrote:
> Use bdrv_dirty_bitmap_next_dirty_area for bitmap_to_extents. Since
> bdrv_dirty_bitmap_next_dirty_area is very accurate in its interface,
> we'll never exceed requested region with last chunk. So, we don't need
> dont_fragment, and bitmap_to_extents() interface becomes clean enough
> to not require any comment.

Comments are a useful style, even if functions seem trivial.

When req_one is in effect, we have to stop at the requested length. 
When req_one is not in effect, the NBD spec does not require us to stop 
until the next change in extent status, but also does not force us to 
continue past.  So this change is fine from the protocol standpoint.

> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>   nbd/server.c | 58 ++++++++++++++++------------------------------------
>   1 file changed, 18 insertions(+), 40 deletions(-)
> 
> diff --git a/nbd/server.c b/nbd/server.c
> index cc63d8ad21..edbdb1b6b6 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -2023,57 +2023,35 @@ static int nbd_co_send_block_status(NBDClient *client, uint64_t handle,
>       return nbd_co_send_extents(client, handle, ea, last, context_id, errp);
>   }
>   
> -/*
> - * Populate @ea from a dirty bitmap. Unless @dont_fragment, the
> - * final extent may exceed the original @length.
> - */

I would have kept the first sentence, and dropped only the second.

>   static void bitmap_to_extents(BdrvDirtyBitmap *bitmap,
>                                 uint64_t offset, uint64_t length,
> -                              NBDExtentArray *ea, bool dont_fragment)
> +                              NBDExtentArray *es)
>   {
> -    uint64_t begin = offset, end = offset;
> -    uint64_t overall_end = offset + length;
> -    BdrvDirtyBitmapIter *it;
> -    bool dirty;
> +    int64_t start, dirty_start, dirty_count;
> +    int64_t end = offset + length;
> +    bool full = false;
>   
>       bdrv_dirty_bitmap_lock(bitmap);

> +    for (start = offset;
> +         bdrv_dirty_bitmap_next_dirty_area(bitmap, start, end, INT32_MAX,
> +                                           &dirty_start, &dirty_count);
> +         start = dirty_start + dirty_count)
> +    {
> +        if ((nbd_extent_array_add(es, dirty_start - start, 0) < 0) ||
> +            (nbd_extent_array_add(es, dirty_count, NBD_STATE_DIRTY) < 0))

As long as bdrv_dirty_bitmap_next_dirty_area works correctly, this 
should work regardless of whether start is dirty or clean (if dirty, the 
first call will be a 0-length no-op).


> +        {
> +            full = true;
>               break;
>           }
> -        begin = end;
> -        dirty = next_dirty;
>       }
>   
> -    bdrv_dirty_iter_free(it);
> +    if (!full) {
> +        /* last non dirty extent */
> +        nbd_extent_array_add(es, end - start, 0);
> +    }

Losing the possibility of reporting beyond the end of the original 
request (when req_one is not in force) is not fatal (it might make some 
clients less efficient when walking the entire disk, but qemu as a 
client isn't currently taking advantage of NBD's permission to return 
extra length).

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


  reply	other threads:[~2019-10-09 20: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
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 [this message]
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=59fa171e-f885-620e-4dfd-e690e7906928@redhat.com \
    --to=eblake@redhat.com \
    --cc=den@openvz.org \
    --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).