From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MGVFU-0005dj-T1 for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:46:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MGVFP-0005cw-Rl for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:46:35 -0400 Received: from [199.232.76.173] (port=50213 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MGVFP-0005ct-Ji for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:46:31 -0400 Received: from mx2.redhat.com ([66.187.237.31]:44460) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MGVFO-00016f-TD for qemu-devel@nongnu.org; Tue, 16 Jun 2009 05:46:31 -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 n5G9WbOq003933 for ; Tue, 16 Jun 2009 05:32:37 -0400 From: Kevin Wolf Date: Tue, 16 Jun 2009 11:31:28 +0200 Message-Id: <1245144690-27805-2-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 1/3] l2_allocate: 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 modifying the L1 table, l2_allocate() needs to write complete sectors instead of single entries. The L1 table is already in memory, reading it from disk in the block layer to align the request is wasted performance. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 33 ++++++++++++++++++++++++++++----- 1 files changed, 28 insertions(+), 5 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 99215fa..1c70693 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -171,6 +171,31 @@ static uint64_t *l2_load(BlockDriverState *bs, uint64_t l2_offset) } /* + * Writes one sector of the L1 table to the disk (can't update single entries + * and we really don't want bdrv_pread to perform a read-modify-write) + */ +#define L1_ENTRIES_PER_SECTOR (512 / 8) +static int write_l1_entry(BDRVQcowState *s, int l1_index) +{ + uint64_t buf[L1_ENTRIES_PER_SECTOR]; + int l1_start_index; + int i; + + l1_start_index = l1_index & ~(L1_ENTRIES_PER_SECTOR - 1); + for (i = 0; i < L1_ENTRIES_PER_SECTOR; i++) { + buf[i] = cpu_to_be64(s->l1_table[l1_start_index + i]); + } + + if (bdrv_pwrite(s->hd, s->l1_table_offset + 8 * l1_start_index, + buf, sizeof(buf)) != sizeof(buf)) + { + return -1; + } + + return 0; +} + +/* * l2_allocate * * Allocate a new l2 entry in the file. If l1_index points to an already @@ -184,7 +209,7 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index) { BDRVQcowState *s = bs->opaque; int min_index; - uint64_t old_l2_offset, tmp; + uint64_t old_l2_offset; uint64_t *l2_table, l2_offset; old_l2_offset = s->l1_table[l1_index]; @@ -196,11 +221,9 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index) /* update the L1 entry */ s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED; - - tmp = cpu_to_be64(l2_offset | QCOW_OFLAG_COPIED); - if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp), - &tmp, sizeof(tmp)) != sizeof(tmp)) + if (write_l1_entry(s, l1_index) < 0) { return NULL; + } /* allocate a new entry in the l2 cache */ -- 1.6.0.6