From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH for-5.1 v2 1/2] block: Require aligned image size to avoid assertion failure
Date: Fri, 17 Jul 2020 13:32:43 +0200 [thread overview]
Message-ID: <20200717113243.GB4550@linux.fritz.box> (raw)
In-Reply-To: <7567943c-85e0-5c5b-b67e-3b915d5fa9de@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3112 bytes --]
Am 17.07.2020 um 13:02 hat Max Reitz geschrieben:
> On 16.07.20 16:26, Kevin Wolf wrote:
> > Unaligned requests will automatically be aligned to bl.request_alignment
> > and we can't extend write requests to access space beyond the end of the
> > image without resizing the image, so if we have the WRITE permission,
> > but not the RESIZE one, it's required that the image size is aligned.
> >
> > Failing to meet this requirement could cause assertion failures like
> > this if RESIZE permissions weren't requested:
> >
> > qemu-img: block/io.c:1910: bdrv_co_write_req_prepare: Assertion `end_sector <= bs->total_sectors || child->perm & BLK_PERM_RESIZE' failed.
> >
> > This was e.g. triggered by qemu-img converting to a target image with 4k
> > request alignment when the image was only aligned to 512 bytes, but not
> > to 4k.
> >
> > Turn this into a graceful error in bdrv_check_perm() so that WRITE
> > without RESIZE can only be taken if the image size is aligned. If a user
> > holds both permissions and drops only RESIZE, the function will return
> > an error, but bdrv_child_try_set_perm() will ignore the failure silently
> > if permissions are only requested to be relaxed and just keep both
> > permissions while returning success.
> >
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> > block.c | 16 ++++++++++++++++
> > 1 file changed, 16 insertions(+)
> >
> > diff --git a/block.c b/block.c
> > index 35a372df57..6371928edb 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -2025,6 +2025,22 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q,
> > return -EPERM;
> > }
> >
> > + /*
> > + * Unaligned requests will automatically be aligned to bl.request_alignment
> > + * and without RESIZE we can't extend requests to write to space beyond the
> > + * end of the image, so it's required that the image size is aligned.
> > + */
> > + if ((cumulative_perms & BLK_PERM_WRITE) &&
>
> What about WRITE_UNCHANGED? I think this would only matter with nodes
> that can have backing files (i.e., qcow2 in practice) because
> WRITE_UNCHANGED is only used by COR and block jobs doing something with
> a backing chain, so it shouldn’t matter in practice, but, well.
So basically just replacing the line with this?
if ((cumulative_perms & (BLK_PERM_WRITE | BDRV_PERM_WRITE_UNCHANGED)) &&
I can do that while applying if it is what you mean.
> So, either way:
>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
Thanks!
Kevin
> > + !(cumulative_perms & BLK_PERM_RESIZE))
> > + {
> > + if ((bs->total_sectors * BDRV_SECTOR_SIZE) % bs->bl.request_alignment) {
> > + error_setg(errp, "Cannot get 'write' permission without 'resize': "
> > + "Image size is not a multiple of request "
> > + "alignment");
> > + return -EPERM;
> > + }
> > + }
> > +
> > /* Check this node */
> > if (!drv) {
> > return 0;
> >
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-07-17 11:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-16 14:25 [PATCH for-5.1 v2 0/2] qemu-img convert: Fix abort with unaligned image size Kevin Wolf
2020-07-16 14:26 ` [PATCH for-5.1 v2 1/2] block: Require aligned image size to avoid assertion failure Kevin Wolf
2020-07-17 11:02 ` Max Reitz
2020-07-17 11:32 ` Kevin Wolf [this message]
2020-07-17 11:36 ` Max Reitz
2020-07-16 14:26 ` [PATCH for-5.1 v2 2/2] file-posix: Allow byte-aligned O_DIRECT with NFS Kevin Wolf
2020-07-17 11:15 ` 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=20200717113243.GB4550@linux.fritz.box \
--to=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).