From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jeff Cody <jcody@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 23/36] block: vhdx - update log guid in header, and first write tracker
Date: Thu, 7 Nov 2013 14:12:31 +0100 [thread overview]
Message-ID: <1383829964-32364-24-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1383829964-32364-1-git-send-email-stefanha@redhat.com>
From: Jeff Cody <jcody@redhat.com>
Allow tracking of first file write in the VHDX image, as well as
the ability to update the GUID in the header. This is in preparation
for log support.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/vhdx.c | 30 ++++++++++++++++++++++++------
block/vhdx.h | 6 ++++++
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index 68663c6..241703a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -230,7 +230,7 @@ static int vhdx_probe(const uint8_t *buf, int buf_size, const char *filename)
* - non-current header is updated with largest sequence number
*/
static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s,
- bool generate_data_write_guid)
+ bool generate_data_write_guid, MSGUID *log_guid)
{
int ret = 0;
int hdr_idx = 0;
@@ -262,6 +262,11 @@ static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s,
vhdx_guid_generate(&inactive_header->data_write_guid);
}
+ /* update the log guid if present */
+ if (log_guid) {
+ inactive_header->log_guid = *log_guid;
+ }
+
/* the header checksum is not over just the packed size of VHDXHeader,
* but rather over the entire 'reserved' range for the header, which is
* 4KB (VHDX_HEADER_SIZE). */
@@ -294,16 +299,16 @@ exit:
* The VHDX spec calls for header updates to be performed twice, so that both
* the current and non-current header have valid info
*/
-static int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s,
- bool generate_data_write_guid)
+int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s,
+ bool generate_data_write_guid, MSGUID *log_guid)
{
int ret;
- ret = vhdx_update_header(bs, s, generate_data_write_guid);
+ ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
if (ret < 0) {
return ret;
}
- ret = vhdx_update_header(bs, s, generate_data_write_guid);
+ ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid);
return ret;
}
@@ -784,6 +789,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
s->bat = NULL;
+ s->first_visible_write = true;
qemu_co_mutex_init(&s->lock);
@@ -864,7 +870,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
}
if (flags & BDRV_O_RDWR) {
- ret = vhdx_update_headers(bs, s, false);
+ ret = vhdx_update_headers(bs, s, false, NULL);
if (ret < 0) {
goto fail;
}
@@ -1010,6 +1016,18 @@ exit:
+/* Per the spec, on the first write of guest-visible data to the file the
+ * data write guid must be updated in the header */
+int vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s)
+{
+ int ret = 0;
+ if (s->first_visible_write) {
+ s->first_visible_write = false;
+ ret = vhdx_update_headers(bs, s, true, NULL);
+ }
+ return ret;
+}
+
static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov)
{
diff --git a/block/vhdx.h b/block/vhdx.h
index 23028af..6c35737 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -361,6 +361,7 @@ typedef struct BDRVVHDXState {
VHDXBatEntry *bat;
uint64_t bat_offset;
+ bool first_visible_write;
MSGUID session_guid;
VHDXLogEntries log;
@@ -373,6 +374,9 @@ typedef struct BDRVVHDXState {
void vhdx_guid_generate(MSGUID *guid);
+int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, bool rw,
+ MSGUID *log_guid);
+
uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset);
uint32_t vhdx_checksum_calc(uint32_t crc, uint8_t *buf, size_t size,
int crc_offset);
@@ -402,4 +406,6 @@ void vhdx_log_data_le_export(VHDXLogDataSector *d);
void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr);
void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr);
+int vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s);
+
#endif
--
1.8.3.1
next prev parent reply other threads:[~2013-11-07 13:19 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-07 13:12 [Qemu-devel] [PULL for-1.7 00/36] Block patches Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 01/36] qapi: Fix comment for create-type to match code Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 02/36] qemu-iotests: Filter out actual image size in 067 Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 03/36] block/raw-posix: fix FreeBSD compilation Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 04/36] block: qemu-iotests, add quotes to $TEST_IMG usage io pattern tests Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 05/36] block: qemu-iotests, fix _make_test_img() to work with spaced pathnames Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 06/36] block: qemu-iotests, add quotes to $TEST_IMG.base usage in 017 Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 07/36] block: qemu-iotests, add quotes to $TEST_IMG usage in 019 Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 08/36] block: qemu-iotests, removes duplicate double quotes in 039 Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 09/36] block: qemu-iotests, add quotes to $TEST_IMG usage for 051 Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 10/36] block: qemu-iotests, add quotes to $TEST_IMG usage in 061 Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 11/36] blockdev: fix drive_init() opts and bs_opts leaks Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 12/36] libqtest: rename qmp() to qmp_discard_response() Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 13/36] libqtest: add qmp(fmt, ...) -> QDict* function Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 14/36] blockdev-test: add test case for drive_add duplicate IDs Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 15/36] qdev-monitor-test: add device_add leak test cases Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 16/36] block: Save errno before error_setg_errno Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 17/36] block/vpc: fix virtual size for images created with disk2vhd Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 18/36] block: vhdx - minor comments and typo correction Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 19/36] block: vhdx - add header update capability Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 20/36] block: vhdx code movement - VHDXMetadataEntries and BDRVVHDXState to header Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 21/36] block: vhdx - log support struct and defines Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 22/36] block: vhdx - break endian translation functions out Stefan Hajnoczi
2013-11-07 13:12 ` Stefan Hajnoczi [this message]
2013-11-07 13:12 ` [Qemu-devel] [PULL 24/36] block: vhdx code movement - move vhdx_close() above vhdx_open() Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 25/36] block: vhdx - log parsing, replay, and flush support Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 26/36] block: vhdx - add region overlap detection for image files Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 27/36] block: vhdx - add log write support Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 28/36] block: vhdx " Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 29/36] block: vhdx - remove BAT file offset bit shifting Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 30/36] block: vhdx - move more endian translations to vhdx-endian.c Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 31/36] block: vhdx - break out code operations to functions Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 32/36] block: vhdx - fix comment typos in header, fix incorrect struct fields Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 33/36] block: vhdx - add .bdrv_create() support Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 34/36] block: vhdx - update _make_test_img() to filter out vhdx options Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 35/36] block: qemu-iotests for vhdx, add write test support Stefan Hajnoczi
2013-11-07 13:12 ` [Qemu-devel] [PULL 36/36] block: vhdx qemu-iotest - log replay of data sector 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=1383829964-32364-24-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@amazon.com \
--cc=jcody@redhat.com \
--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).