summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Habkost <ehabkost@redhat.com>2009-09-09 17:29:07 -0300
committerEduardo Habkost <ehabkost@redhat.com>2009-09-09 18:02:08 -0300
commitd340f30fe6f2af6179ebba0aaf641f8645db4e87 (patch)
tree1b47623ae5cb0db80ba2519ce0f44e815b5b49be
parent1d6b5705a80c58e92bbb82c015c2b3fc173881ca (diff)
alloc_cluster_link_l2: Write complete sectors
Message-id: <1252527484-19604-5-git-send-email-ehabkost@redhat.com> RH-Author: Eduardo Habkost <ehabkost@redhat.com> Patchwork-id: 3384 O-Subject: [PATCH 4/5] alloc_cluster_link_l2: Write complete sectors Bugzilla: Author: Kevin Wolf <kwolf@redhat.com> Bugzilla: 520693 RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Andrea Arcangeli <aarcange@redhat.com> RH-Acked-by: Gleb Natapov <gleb@redhat.com> When updating the L2 tables in alloc_cluster_link_l2(), write complete sectors instead of updating single entries. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- qemu/block-qcow2.c | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block-qcow2.c | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
-rw-r--r--qemu/block-qcow2.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
index 9c8212bf..50561f15 100644
--- a/qemu/block-qcow2.c
+++ b/qemu/block-qcow2.c
@@ -1005,6 +1005,28 @@ typedef struct QCowL2Meta
int nb_clusters;
} QCowL2Meta;
+/*
+ * Write L2 table updates to disk, writing whole sectors to avoid a
+ * read-modify-write in bdrv_pwrite
+ */
+#define L2_ENTRIES_PER_SECTOR (512 / 8)
+static int write_l2_entries(BDRVQcowState *s, uint64_t *l2_table,
+ uint64_t l2_offset, int l2_index, int num)
+{
+ int l2_start_index = l2_index & ~(L1_ENTRIES_PER_SECTOR - 1);
+ int start_offset = (8 * l2_index) & ~511;
+ int end_offset = (8 * (l2_index + num) + 511) & ~511;
+ size_t len = end_offset - start_offset;
+
+ if (bdrv_pwrite(s->hd, l2_offset + start_offset, &l2_table[l2_start_index],
+ len) != len)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
QCowL2Meta *m)
{
@@ -1053,10 +1075,10 @@ static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
(i << s->cluster_bits)) | QCOW_OFLAG_COPIED);
}
- if (bdrv_pwrite(s->hd, l2_offset + l2_index * sizeof(uint64_t),
- l2_table + l2_index, m->nb_clusters * sizeof(uint64_t)) !=
- m->nb_clusters * sizeof(uint64_t))
+ if (write_l2_entries(s, l2_table, l2_offset, l2_index, m->nb_clusters) < 0) {
+ ret = -1;
goto err;
+ }
for (i = 0; i < j; i++)
free_any_clusters(bs, be64_to_cpu(old_cluster[i]) & ~QCOW_OFLAG_COPIED,