[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 13/41] qcow2: Update snapshot table information at o
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 13/41] qcow2: Update snapshot table information at once |
Date: |
Mon, 5 Dec 2011 15:20:50 +0100 |
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 <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
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
- [Qemu-devel] [PULL 00/41] Block patches, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 01/41] qcow2: Unlock during COW, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 08/41] block: add I/O throttling algorithm, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 07/41] CoQueue: introduce qemu_co_queue_wait_insert_head, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 05/41] block: Use bdrv functions to replace file operation in cow.c, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 04/41] xen_disk: remove dead code, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 06/41] block: add the blockio limits command line support, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 02/41] qcow2: avoid reentrant bdrv_read() in copy_sectors(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 03/41] qed: adjust the way to get nb_sectors, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 13/41] qcow2: Update snapshot table information at once,
Kevin Wolf <=
- [Qemu-devel] [PATCH 15/41] qcow2: Rework qcow2_snapshot_create error handling, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 10/41] block: Add coroutine_fn marker to coroutine functions, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 09/41] hmp/qmp: add block_set_io_throttle, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 12/41] qcow2: Return real error code in qcow2_write_snapshots, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 11/41] qcow2: Return real error code in qcow2_read_snapshots, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 14/41] qcow2: Cleanups and memleak fix in qcow2_snapshot_create, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 16/41] qcow2: Return real error in qcow2_snapshot_goto, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 19/41] qcow2: Fix error path in qcow2_snapshot_load_tmp, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 18/41] qcow2: Fix order in qcow2_snapshot_delete, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 17/41] qcow2: Fix order of refcount updates in qcow2_snapshot_goto, Kevin Wolf, 2011/12/05