All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v2 6/9] block: vhdx - update log guid in header, and first write tracker
Date: Wed, 31 Jul 2013 23:23:51 -0400	[thread overview]
Message-ID: <a1228129c5be1851c269658d8b40db632fa198a1.1375325971.git.jcody@redhat.com> (raw)
In-Reply-To: <cover.1375325971.git.jcody@redhat.com>
In-Reply-To: <cover.1375325971.git.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>
---
 block/vhdx.c | 28 +++++++++++++++++++++++-----
 block/vhdx.h |  7 +++++--
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index 9802b74..0de4d6f 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -233,7 +233,8 @@ 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 rw)
+static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, bool rw,
+                              MSGUID *log_guid)
 {
     int ret = 0;
     int hdr_idx = 0;
@@ -266,6 +267,11 @@ static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, bool rw)
         vhdx_guid_generate(&inactive_header->data_write_guid);
     }
 
+    /* update the log guid if present */
+    if (log_guid) {
+        memcpy(&inactive_header->log_guid, log_guid, sizeof(MSGUID));
+    }
+
     /* 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). */
@@ -293,15 +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 rw)
+int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, bool rw,
+                        MSGUID *log_guid)
 {
     int ret;
 
-    ret = vhdx_update_header(bs, s, rw);
+    ret = vhdx_update_header(bs, s, rw, log_guid);
     if (ret < 0) {
         return ret;
     }
-    ret = vhdx_update_header(bs, s, rw);
+    ret = vhdx_update_header(bs, s, rw, log_guid);
     return ret;
 }
 
@@ -781,6 +788,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);
 
@@ -861,7 +869,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags)
     }
 
     if (flags & BDRV_O_RDWR) {
-        vhdx_update_headers(bs, s, false);
+        vhdx_update_headers(bs, s, false, NULL);
     }
 
     /* TODO: differencing files, write */
@@ -998,6 +1006,16 @@ 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 */
+void vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s)
+{
+    if (s->first_visible_write) {
+        s->first_visible_write = false;
+        vhdx_update_headers(bs, s, true, NULL);
+    }
+}
+
 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 5e0a1d3..cb3ce0e 100644
--- a/block/vhdx.h
+++ b/block/vhdx.h
@@ -366,6 +366,7 @@ typedef struct BDRVVHDXState {
     VHDXBatEntry *bat;
     uint64_t bat_offset;
 
+    bool first_visible_write;
     MSGUID session_guid;
 
     VHDXLogEntries log;
@@ -377,6 +378,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);
@@ -406,8 +410,7 @@ 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);
 
-
-
+void vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s);
 
 
 
-- 
1.8.1.4

  parent reply	other threads:[~2013-08-01  3:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01  3:23 [Qemu-devel] [PATCH v2 0/9] VHDX log replay and write support Jeff Cody
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 1/9] block: vhdx - minor comments and typo correction Jeff Cody
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 2/9] block: vhdx - add header update capability Jeff Cody
2013-08-01 13:44   ` Stefan Hajnoczi
2013-08-01 14:09     ` Jeff Cody
2013-08-07 14:42     ` Jeff Cody
2013-08-05 11:42   ` Kevin Wolf
2013-08-05 14:43     ` Jeff Cody
2013-08-05 14:45   ` Kevin Wolf
2013-08-05 14:57     ` Jeff Cody
2013-08-05 15:05   ` Kevin Wolf
2013-08-05 15:09     ` Jeff Cody
2013-08-06  8:34       ` Kevin Wolf
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 3/9] block: vhdx code movement - VHDXMetadataEntries and BDRVVHDXState to header Jeff Cody
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 4/9] block: vhdx - log support struct and defines Jeff Cody
2013-08-01 15:00   ` Stefan Hajnoczi
2013-08-01 15:51     ` Jeff Cody
2013-08-07 15:22   ` Kevin Wolf
2013-08-07 17:18     ` Jeff Cody
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 5/9] block: vhdx - break endian translation functions out Jeff Cody
2013-08-01 15:03   ` Stefan Hajnoczi
2013-08-01 15:14     ` Jeff Cody
2013-08-07 15:29   ` Kevin Wolf
2013-08-07 17:21     ` Jeff Cody
2013-08-01  3:23 ` Jeff Cody [this message]
2013-08-01 15:09   ` [Qemu-devel] [PATCH v2 6/9] block: vhdx - update log guid in header, and first write tracker Stefan Hajnoczi
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 7/9] block: vhdx - log parsing, replay, and flush support Jeff Cody
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 8/9] block: vhdx - add log write support Jeff Cody
2013-08-01  3:23 ` [Qemu-devel] [PATCH v2 9/9] block: vhdx " Jeff Cody

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=a1228129c5be1851c269658d8b40db632fa198a1.1375325971.git.jcody@redhat.com \
    --to=jcody@redhat.com \
    --cc=famz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.