From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 2/3] alloc_cluster_link_l2: Write complete sectors
Date: Tue, 16 Jun 2009 11:31:29 +0200 [thread overview]
Message-ID: <1245144690-27805-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1245144690-27805-1-git-send-email-kwolf@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>
---
block/qcow2-cluster.c | 28 +++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 1c70693..d349655 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -578,6 +578,28 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
return cluster_offset;
}
+/*
+ * 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;
+}
+
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,
QCowL2Meta *m)
{
@@ -625,10 +647,10 @@ int qcow2_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++)
qcow2_free_any_clusters(bs,
--
1.6.0.6
next prev parent reply other threads:[~2009-06-16 9:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-16 9:31 [Qemu-devel] [PATCH 0/3] qcow2: Write complete sectors Kevin Wolf
2009-06-16 9:31 ` [Qemu-devel] [PATCH 1/3] l2_allocate: " Kevin Wolf
2009-06-16 9:31 ` Kevin Wolf [this message]
2009-06-16 9:31 ` [Qemu-devel] [PATCH 3/3] update_refcount: " Kevin Wolf
2009-06-16 10:03 ` [Qemu-devel] [PATCH 0/3] qcow2: " Dor Laor
2009-06-16 10:15 ` Kevin Wolf
2009-06-16 10:06 ` Avi Kivity
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=1245144690-27805-3-git-send-email-kwolf@redhat.com \
--to=kwolf@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).