qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@gmail.com
Subject: [Qemu-devel] [PATCH v2 3/9] qcow2: Update snapshot table information at once
Date: Fri, 18 Nov 2011 19:28:59 +0100	[thread overview]
Message-ID: <1321640945-9827-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1321640945-9827-1-git-send-email-kwolf@redhat.com>

Failing in the middle wouldn't help with the integrity of the image, so
doing everything in a single request seems better.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2-snapshot.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index e91a286..1976df7 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -137,8 +137,10 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
     QCowSnapshot *sn;
     QCowSnapshotHeader h;
     int i, name_size, id_str_size, snapshots_size;
-    uint64_t data64;
-    uint32_t data32;
+    struct {
+        uint32_t nb_snapshots;
+        uint64_t snapshots_offset;
+    } QEMU_PACKED header_data;
     int64_t offset, snapshots_offset;
     int ret;
 
@@ -200,24 +202,20 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
     /*
      * Update the header to point to the new snapshot table. This requires the
      * new table and its refcounts to be stable on disk.
-     *
-     * FIXME This should be done with a single write
      */
     ret = bdrv_flush(bs);
     if (ret < 0) {
         goto fail;
     }
 
-    data64 = cpu_to_be64(snapshots_offset);
-    ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, snapshots_offset),
-                      &data64, sizeof(data64));
-    if (ret < 0) {
-        goto fail;
-    }
+    QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) !=
+        offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots));
+
+    header_data.nb_snapshots        = cpu_to_be32(s->nb_snapshots);
+    header_data.snapshots_offset    = cpu_to_be64(snapshots_offset);
 
-    data32 = cpu_to_be32(s->nb_snapshots);
     ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
-                           &data32, sizeof(data32));
+                           &header_data, sizeof(header_data));
     if (ret < 0) {
         goto fail;
     }
-- 
1.7.6.4

  parent reply	other threads:[~2011-11-18 18:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-18 18:28 [Qemu-devel] [PATCH v2 0/9] qcow2: Fix error paths for internal snapshots Kevin Wolf
2011-11-18 18:28 ` [Qemu-devel] [PATCH v2 1/9] qcow2: Return real error code in qcow2_read_snapshots Kevin Wolf
2011-11-18 18:28 ` [Qemu-devel] [PATCH v2 2/9] qcow2: Return real error code in qcow2_write_snapshots Kevin Wolf
2011-11-18 18:28 ` Kevin Wolf [this message]
2011-11-18 18:29 ` [Qemu-devel] [PATCH v2 4/9] qcow2: Cleanups and memleak fix in qcow2_snapshot_create Kevin Wolf
2011-11-18 18:29 ` [Qemu-devel] [PATCH v2 5/9] qcow2: Rework qcow2_snapshot_create error handling Kevin Wolf
2011-11-21 16:47   ` Stefan Hajnoczi
2011-11-22  9:14     ` Kevin Wolf
2011-11-22  9:45       ` Stefan Hajnoczi
2011-11-18 18:29 ` [Qemu-devel] [PATCH v2 6/9] qcow2: Return real error in qcow2_snapshot_goto Kevin Wolf
2011-11-18 18:29 ` [Qemu-devel] [PATCH v2 7/9] qcow2: Fix order of refcount updates " Kevin Wolf
2011-11-18 18:29 ` [Qemu-devel] [PATCH v2 8/9] qcow2: Fix order in qcow2_snapshot_delete Kevin Wolf
2011-11-18 18:29 ` [Qemu-devel] [PATCH v2 9/9] qcow2: Fix error path in qcow2_snapshot_load_tmp Kevin Wolf
2011-11-21 16:58 ` [Qemu-devel] [PATCH v2 0/9] qcow2: Fix error paths for internal snapshots Stefan Hajnoczi
2011-11-22 14:12   ` Kevin Wolf
2011-11-22 14:21     ` 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=1321640945-9827-4-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.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).