From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MGV25-0001Ri-EZ for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MGV20-0001Gr-7B for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:44 -0400 Received: from [199.232.76.173] (port=53237 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MGV1z-0001GO-Vp for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:40 -0400 Received: from mx20.gnu.org ([199.232.41.8]:27874) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MGV1z-0000kf-Ff for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:39 -0400 Received: from mx2.redhat.com ([66.187.237.31]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MGV1y-0003tR-KI for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:32:38 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5G9WbOf003937 for ; Tue, 16 Jun 2009 05:32:37 -0400 From: Kevin Wolf Date: Tue, 16 Jun 2009 11:31:29 +0200 Message-Id: <1245144690-27805-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1245144690-27805-1-git-send-email-kwolf@redhat.com> References: <1245144690-27805-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] alloc_cluster_link_l2: Write complete sectors List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf When updating the L2 tables in alloc_cluster_link_l2(), write complete sectors instead of updating single entries. Signed-off-by: Kevin Wolf --- 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