From: Stefan Hajnoczi <stefanha@gmail.com>
To: Jeff Cody <jcody@redhat.com>
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v6 08/20] block: vhdx - log parsing, replay, and flush support
Date: Tue, 1 Oct 2013 13:31:36 +0200 [thread overview]
Message-ID: <20131001113136.GA6035@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <88c4403314c6c58ac4fe672e252c5c4a3e4c61ca.1380141614.git.jcody@redhat.com>
On Wed, Sep 25, 2013 at 05:02:53PM -0400, Jeff Cody wrote:
> +static int vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s,
> + VHDXLogEntries *log, VHDXLogDescEntries **buffer)
> +{
> + int ret = 0;
> + uint32_t desc_sectors;
> + uint32_t sectors_read;
> + VHDXLogEntryHeader hdr;
> + VHDXLogDescEntries *desc_entries = NULL;
> + int i;
> +
> + assert(*buffer == NULL);
> +
> + ret = vhdx_log_peek_hdr(bs, log, &hdr);
> + if (ret < 0) {
> + goto exit;
> + }
> + vhdx_log_entry_hdr_le_import(&hdr);
> + if (vhdx_log_hdr_is_valid(log, &hdr, s) == false) {
> + ret = -EINVAL;
> + goto exit;
> + }
> +
> + desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count);
I don't see input validation for hdr.descriptor_count. It not exceed
log length.
> +static int vhdx_log_flush_desc(BlockDriverState *bs, VHDXLogDescriptor *desc,
> + VHDXLogDataSector *data)
> +{
> + int ret = 0;
> + uint64_t seq, file_offset;
> + uint32_t offset = 0;
> + void *buffer = NULL;
> + uint64_t count = 1;
> + int i;
> +
> + buffer = qemu_blockalign(bs, VHDX_LOG_SECTOR_SIZE);
> +
> + if (!memcmp(&desc->signature, "desc", 4)) {
> + /* data sector */
> + if (data == NULL) {
> + ret = -EFAULT;
> + goto exit;
> + }
> +
> + /* The sequence number of the data sector must match that
> + * in the descriptor */
> + seq = data->sequence_high;
> + seq <<= 32;
> + seq |= data->sequence_low & 0xffffffff;
> +
> + if (seq != desc->sequence_number) {
> + ret = -EINVAL;
> + goto exit;
> + }
> +
> + /* Each data sector is in total 4096 bytes, however the first
> + * 8 bytes, and last 4 bytes, are located in the descriptor */
> + memcpy(buffer, &desc->leading_bytes, 8);
> + offset += 8;
> +
> + memcpy(buffer+offset, data->data, 4084);
> + offset += 4084;
> +
> + memcpy(buffer+offset, &desc->trailing_bytes, 4);
> +
> + } else if (!memcmp(&desc->signature, "zero", 4)) {
> + /* write 'count' sectors of sector */
> + memset(buffer, 0, VHDX_LOG_SECTOR_SIZE);
> + count = desc->zero_length / VHDX_LOG_SECTOR_SIZE;
Zero descriptors also have a sequence number that should be checked.
> +/* Parse the replay log. Per the VHDX spec, if the log is present
> + * it must be replayed prior to opening the file, even read-only.
> + *
> + * If read-only, we must replay the log in RAM (or refuse to open
> + * a dirty VHDX file read-only */
read-only) <-- missing parenthesis
> @@ -794,10 +753,12 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
> uint32_t i;
> uint64_t signature;
> uint32_t data_blocks_cnt, bitmap_blocks_cnt;
> + bool log_flushed = false;
>
>
> s->bat = NULL;
> s->first_visible_write = true;
> + s->log.write = s->log.read = 0;
This is not really necessary since bs->opaque is zeroed before block.c
calls vhdx_open().
>
> qemu_co_mutex_init(&s->lock);
>
> @@ -821,20 +782,33 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
> goto fail;
> }
>
> - ret = vhdx_parse_log(bs, s);
> + ret = vhdx_open_region_tables(bs, s);
> if (ret) {
> goto fail;
> }
>
> - ret = vhdx_open_region_tables(bs, s);
> + ret = vhdx_parse_metadata(bs, s);
> if (ret) {
> goto fail;
> }
>
> - ret = vhdx_parse_metadata(bs, s);
> + ret = vhdx_parse_log(bs, s, &log_flushed);
> if (ret) {
> goto fail;
> }
Why replay the log *after* reading logged metadata? We could read stale
or corrupted values.
I guess there is a dependency here - the log replay code needs some
field that vhdx_open_region_tables() or vhdx_parse_metadata() load?
next prev parent reply other threads:[~2013-10-01 11:31 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 [this message]
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
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=20131001113136.GA6035@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--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).