From: Fam Zheng <famz@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, Jeff Cody <jcody@redhat.com>,
Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/3] mirror: Don't extend the last sub-chunk
Date: Wed, 20 Apr 2016 09:13:08 +0800 [thread overview]
Message-ID: <20160420011308.GB8684@ad-mail.usersys.redhat.com> (raw)
In-Reply-To: <57169629.2090404@redhat.com>
On Tue, 04/19 22:33, Max Reitz wrote:
> On 19.04.2016 12:09, Fam Zheng wrote:
> > The last sub-chunk is rounded up to the copy granularity in the target
> > image, resulting in a larger size than the source.
> >
> > Add a function to clip the copied sectors to the end.
> >
> > This undoes the "wrong" changes to tests/qemu-iotests/109.out in
> > e5b43573e28. The remaining two offset changes are okay.
> >
> > Reported-by: Kevin Wolf <kwolf@redhat.com>
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > block/mirror.c | 10 ++++++++++
> > tests/qemu-iotests/109.out | 44 ++++++++++++++++++++++----------------------
> > 2 files changed, 32 insertions(+), 22 deletions(-)
> >
> > diff --git a/block/mirror.c b/block/mirror.c
> > index c2cfc1a..b6387f1 100644
> > --- a/block/mirror.c
> > +++ b/block/mirror.c
> > @@ -205,6 +205,14 @@ static inline void mirror_wait_for_io(MirrorBlockJob *s)
> > s->waiting_for_io = false;
> > }
> >
> > +static inline void mirror_clip_sectors(MirrorBlockJob *s,
> > + int64_t sector_num,
> > + int *nb_sectors)
> > +{
> > + *nb_sectors = MIN(*nb_sectors,
> > + s->bdev_length / BDRV_SECTOR_SIZE - sector_num);
> > +}
> > +
> > /* Submit async read while handling COW.
> > * Returns: nb_sectors if no alignment is necessary, or
> > * (new_end - sector_num) if tail is rounded up or down due to
> > @@ -240,6 +248,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,
> > mirror_wait_for_io(s);
> > }
> >
> > + mirror_clip_sectors(s, sector_num, &nb_sectors);
> > /* Allocate a MirrorOp that is used as an AIO callback. */
> > op = g_new(MirrorOp, 1);
> > op->s = s;
>
> I think you want to adjust the ret value, too. It doesn't really matter
> in practice (the caller just overshoots the end of the image instead of
> getting precisely to its end), but I wouldn't rely on this.
>
> > @@ -276,6 +285,7 @@ static void mirror_do_zero_or_discard(MirrorBlockJob *s,
> > {
> > MirrorOp *op;
> >
> > + mirror_clip_sectors(s, sector_num, &nb_sectors);
> > /* Allocate a MirrorOp that is used as an AIO callback. The qiov is zeroed
> > * so the freeing in mirror_iteration_done is nop. */
> > op = g_new0(MirrorOp, 1);
>
> I think it would be best to just pull out the mirror_clip_sectors() from
> these functions and put it above the "switch (mirror_method)" in
> mirror_iteration().
>
> We'd just have to make sure that mirror_cow_align() will not increase
> nb_sectors such that it points beyond the image end. It can do that,
> because and image's size does not need to be aligned to its cluster
> size. But just putting a mirror_clip_sectors() below the
> bdrv_round_to_clusters() call in mirror_cow_align() should fix that.
>
> Then you wouldn't need to worry about fixing the ret value in
> mirror_do_read().
Sounds good, will do this.
Thanks,
Fam
next prev parent reply other threads:[~2016-04-20 1:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-19 10:09 [Qemu-devel] [PATCH 0/3] block: Fix drive-mirror with image size unaligned with granularity Fam Zheng
2016-04-19 10:09 ` [Qemu-devel] [PATCH 1/3] mirror: Don't extend the last sub-chunk Fam Zheng
2016-04-19 20:33 ` Max Reitz
2016-04-20 1:13 ` Fam Zheng [this message]
2016-04-19 10:09 ` [Qemu-devel] [PATCH 2/3] iotests: Add iotests.image_size Fam Zheng
2016-04-19 20:56 ` Max Reitz
2016-04-19 10:09 ` [Qemu-devel] [PATCH 3/3] iotests: Test case for drive-mirror with unaligned image size Fam Zheng
2016-04-19 21:00 ` Max Reitz
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=20160420011308.GB8684@ad-mail.usersys.redhat.com \
--to=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).