From: Fam Zheng <famz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Max Reitz <mreitz@redhat.com>, Eric Blake <eblake@redhat.com>,
John Snow <jsnow@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] block: Fix dst total_sectors after copy offloading
Date: Wed, 4 Jul 2018 16:42:42 +0800 [thread overview]
Message-ID: <20180704084242.GA8621@lemon.usersys.redhat.com> (raw)
In-Reply-To: <20180704074453.GA4334@localhost.localdomain>
On Wed, 07/04 09:44, Kevin Wolf wrote:
> Am 04.07.2018 um 08:13 hat Fam Zheng geschrieben:
> > This was noticed by the new image fleecing tests case 222. The issue is
> > apparent and we should just do the same right things as in
> > bdrv_aligned_pwritev.
> >
> > Reported-by: John Snow <jsnow@redhat.com>
> > Signed-off-by: Fam Zheng <famz@redhat.com>
>
> > --- a/block/io.c
> > +++ b/block/io.c
> > @@ -2945,6 +2945,10 @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src,
> > dst, dst_offset,
> > bytes, flags);
> > }
> > + if (ret == 0) {
> > + int64_t end_sector = DIV_ROUND_UP(dst_offset + bytes, BDRV_SECTOR_SIZE);
> > + dst->bs->total_sectors = MAX(dst->bs->total_sectors, end_sector);
> > + }
>
> I think it's time to extract this stuff to a common function. I was
> already aware that a write request that extends the image isn't behaving
> exactly the same as bdrv_co_truncate(), and this one is bound to diverge
> from the other two instances as well.
>
> This is what bdrv_aligned_pwritev() does after the write:
>
> atomic_inc(&bs->write_gen);
> bdrv_set_dirty(bs, offset, bytes);
>
> stat64_max(&bs->wr_highest_offset, offset + bytes);
>
> if (ret >= 0) {
> bs->total_sectors = MAX(bs->total_sectors, end_sector);
> ret = 0;
> }
>
> Before the write, it also calls bs->before_write_notifiers.
>
> This is what bdrv_co_truncate() does after truncating the image:
>
> ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
> if (ret < 0) {
> error_setg_errno(errp, -ret, "Could not refresh total sector count");
> } else {
> offset = bs->total_sectors * BDRV_SECTOR_SIZE;
> }
> bdrv_dirty_bitmap_truncate(bs, offset);
> bdrv_parent_cb_resize(bs);
> atomic_inc(&bs->write_gen);
>
> This means that we probably have at least the following bugs in
> bdrv_co_copy_range_internal():
>
> 1. bs->write_gen is not increased, a following flush is ignored
> 2. Dirty bitmaps are not dirtied
> 3. Dirty bitmaps are not resized when extending the image
> 4. bs->wr_highest_offset is not adjusted correctly
> 5. bs->total_sectors is not resized (the bug this patch fixes)
> 6. The parent node isn't notified about an image size change
>
> Of these, 3. and 6. also seem to be bugs in bdrv_aligned_pwritev().
>
Indeed, great insight. I'll work on v2.
Fam
next prev parent reply other threads:[~2018-07-04 8:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-04 6:13 [Qemu-devel] [PATCH 0/2] block: Fix dst reading after tail copy offloading Fam Zheng
2018-07-04 6:13 ` [Qemu-devel] [PATCH 1/2] block: Fix dst total_sectors after " Fam Zheng
2018-07-04 7:44 ` Kevin Wolf
2018-07-04 8:42 ` Fam Zheng [this message]
2018-07-04 6:13 ` [Qemu-devel] [PATCH 2/2] block: Add copy offloading trace points Fam Zheng
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=20180704084242.GA8621@lemon.usersys.redhat.com \
--to=famz@redhat.com \
--cc=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=stefanha@redhat.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).