From: Jeff Cody <jcody@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 09/20] block: vhdx - add region overlap detection for image files
Date: Tue, 1 Oct 2013 09:49:15 -0400 [thread overview]
Message-ID: <20131001134915.GF10859@localhost.localdomain> (raw)
In-Reply-To: <20131001114218.GB6035@stefanha-thinkpad.redhat.com>
On Tue, Oct 01, 2013 at 01:42:18PM +0200, Stefan Hajnoczi wrote:
> On Wed, Sep 25, 2013 at 05:02:54PM -0400, Jeff Cody wrote:
> > +/* Check for region overlaps inside the VHDX image */
> > +static int vhdx_region_check(BDRVVHDXState *s, uint64_t start, uint64_t length)
> > +{
> > + int ret = 0;
> > + uint64_t end;
> > + VHDXRegionEntry *r;
> > +
> > + end = start + length;
> > + QLIST_FOREACH(r, &s->regions, entries) {
> > + if ((start >= r->start && start < r->end) ||
> > + (end > r->start && end <= r->end)) {
> > + ret = -EINVAL;
> > + goto exit;
> > + }
> > + }
> > +
> > +exit:
> > + return ret;
> > +}
>
> This check does not catch a region that spans existing regions:
>
> |----------------| new
> |-----| existing
>
> This will catch all cases:
>
> QLIST_FOREACH(r, &s->regions, entries) {
> if (!((start >= r->end) || (end <= r->start))) {
> return -EINVAL;
> }
> }
> return 0;
>
You are right, thanks.
> > @@ -451,6 +499,15 @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)
> > le32_to_cpus(&rt_entry.length);
> > le32_to_cpus(&rt_entry.data_bits);
> >
> > + /* check for region overlap between these entries, and any
> > + * other memory regions in the file */
> > + ret = vhdx_region_check(s, rt_entry.file_offset, rt_entry.length);
> > + if (ret < 0) {
> > + goto fail;
> > + }
> > +
> > + vhdx_region_register(s, rt_entry.file_offset, rt_entry.length);
> > +
> > /* see if we recognize the entry */
> > if (guid_eq(rt_entry.guid, bat_guid)) {
> > /* must be unique; if we have already found it this is invalid */
> > @@ -481,6 +538,12 @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)
> > goto fail;
> > }
> > }
> > +
> > + if (!bat_rt_found || !metadata_rt_found) {
> > + ret = -EINVAL;
> > + goto fail;
> > + }
> > +
> > ret = 0;
> >
> > fail:
>
> Another reason to avoid opening region tables before reading the
> journal: we'll add regions twice if the journal had to be flushed.
Yes, good point - I'll need to think of a good solution to this, if I
want to be able to check table overlaps prior to flushing the log.
Alternatively, just not worry about that and go ahead and flush the
log, and detect overlaps afterwards. Maybe we'd get lucky and the log
flush would fix the overlaps :)
next prev parent reply other threads:[~2013-10-01 13:49 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-25 21:02 [Qemu-devel] [PATCH v6 00/20] VHDX log replay and write support, .bdrv_create() Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 01/20] block: vhdx - minor comments and typo correction Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 02/20] block: vhdx - add header update capability Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 03/20] block: vhdx code movement - VHDXMetadataEntries and BDRVVHDXState to header Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 04/20] block: vhdx - log support struct and defines Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 05/20] block: vhdx - break endian translation functions out Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 06/20] block: vhdx - update log guid in header, and first write tracker Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 07/20] block: vhdx code movement - move vhdx_close() above vhdx_open() Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 08/20] block: vhdx - log parsing, replay, and flush support Jeff Cody
2013-10-01 11:31 ` Stefan Hajnoczi
2013-10-01 13:24 ` Jeff Cody
2013-10-02 8:57 ` Stefan Hajnoczi
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 09/20] block: vhdx - add region overlap detection for image files Jeff Cody
2013-10-01 11:42 ` Stefan Hajnoczi
2013-10-01 13:49 ` Jeff Cody [this message]
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 10/20] block: vhdx - add log write support Jeff Cody
2013-10-01 13:04 ` Stefan Hajnoczi
2013-10-01 13:26 ` Jeff Cody
2013-10-01 13:30 ` Stefan Hajnoczi
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 11/20] block: vhdx " Jeff Cody
2013-10-01 13:29 ` Stefan Hajnoczi
2013-10-01 13:55 ` Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 12/20] block: vhdx - remove BAT file offset bit shifting Jeff Cody
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 13/20] block: vhdx - move more endian translations to vhdx-endian.c Jeff Cody
2013-10-01 13:35 ` Stefan Hajnoczi
2013-09-25 21:02 ` [Qemu-devel] [PATCH v6 14/20] block: vhdx - break out code operations to functions Jeff Cody
2013-09-25 21:03 ` [Qemu-devel] [PATCH v6 15/20] block: vhdx - fix comment typos in header, fix incorrect struct fields Jeff Cody
2013-09-25 21:03 ` [Qemu-devel] [PATCH v6 16/20] block: vhdx - add .bdrv_create() support Jeff Cody
2013-09-25 21:03 ` [Qemu-devel] [PATCH v6 17/20] block: qemu-iotests - add basic ability to use binary sample images Jeff Cody
2013-09-25 21:03 ` [Qemu-devel] [PATCH v6 18/20] block: qemu-iotests for vhdx, read sample dynamic image Jeff Cody
2013-09-27 12:58 ` Jeff Cody
2013-09-25 21:03 ` [Qemu-devel] [PATCH v6 19/20] block: vhdx - update _make_test_img() to filter out vhdx options Jeff Cody
2013-09-25 21:03 ` [Qemu-devel] [PATCH v6 20/20] block: qemu-iotests for vhdx, add write test support Jeff Cody
2013-09-27 12:55 ` Jeff Cody
2013-10-01 13:41 ` [Qemu-devel] [PATCH v6 00/20] VHDX log replay and write support, .bdrv_create() Stefan Hajnoczi
2013-10-01 14:15 ` Jeff Cody
2013-10-02 9:03 ` Stefan Hajnoczi
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=20131001134915.GF10859@localhost.localdomain \
--to=jcody@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--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).