From patchwork Sat Jul 9 13:02:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 959542 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p69D3J0G004277 for ; Sat, 9 Jul 2011 13:03:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753614Ab1GINDQ (ORCPT ); Sat, 9 Jul 2011 09:03:16 -0400 Received: from filtteri1.pp.htv.fi ([213.243.153.184]:46694 "EHLO filtteri1.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753452Ab1GINDE (ORCPT ); Sat, 9 Jul 2011 09:03:04 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri1.pp.htv.fi (Postfix) with ESMTP id 0398F1FB029; Sat, 9 Jul 2011 16:03:01 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp6.welho.com ([213.243.153.40]) by localhost (filtteri1.pp.htv.fi [213.243.153.184]) (amavisd-new, port 10024) with ESMTP id XzZV4gVZuDQU; Sat, 9 Jul 2011 16:03:00 +0300 (EEST) Received: from localhost.localdomain (cs181136138.pp.htv.fi [82.181.136.138]) by smtp6.welho.com (Postfix) with ESMTP id 98F0F5BC004; Sat, 9 Jul 2011 16:03:00 +0300 (EEST) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Asias He , Cyrill Gorcunov , Ingo Molnar , Prasad Joshi , Sasha Levin Subject: [PATCH 7/9] kvm tools, qcow: Use big endian order for L2 table entries Date: Sat, 9 Jul 2011 16:02:40 +0300 Message-Id: <1310216563-17503-8-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1310216563-17503-1-git-send-email-penberg@kernel.org> References: <1310216563-17503-1-git-send-email-penberg@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 09 Jul 2011 13:03:30 +0000 (UTC) Don't keep the in-memory array in CPU byte order to simplify delayed L2 table writeout. Cc: Asias He Cc: Cyrill Gorcunov Cc: Ingo Molnar Cc: Prasad Joshi Cc: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/disk/qcow.c | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tools/kvm/disk/qcow.c b/tools/kvm/disk/qcow.c index 35408ab..c851e7f 100644 --- a/tools/kvm/disk/qcow.c +++ b/tools/kvm/disk/qcow.c @@ -183,7 +183,6 @@ static struct qcow_l2_table *qcow_read_l2_table(struct qcow *q, u64 offset) struct qcow_header *header = q->header; struct qcow_l2_table *l2t; u64 size; - u64 i; size = 1 << header->l2_bits; @@ -205,10 +204,6 @@ static struct qcow_l2_table *qcow_read_l2_table(struct qcow *q, u64 offset) if (cache_table(q, l2t) < 0) goto error; - /* change cached table to CPU's byte-order */ - for (i = 0; i < size; i++) - be64_to_cpus(&l2t->table[i]); - return l2t; error: free(l2t); @@ -259,7 +254,7 @@ static ssize_t qcow_read_cluster(struct qcow *q, u64 offset, void *dst, u32 dst_ if (l2_idx >= l2_table_size) goto out_error; - clust_start = l2_table->table[l2_idx] & ~header->oflag_mask; + clust_start = be64_to_cpu(l2_table->table[l2_idx]) & ~header->oflag_mask; if (!clust_start) goto zero_cluster; @@ -437,7 +432,7 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src if (!f_sz) goto error; - clust_start = l2t->table[l2t_idx] & ~header->oflag_mask; + clust_start = be64_to_cpu(l2t->table[l2t_idx]) & ~header->oflag_mask; if (!clust_start) { clust_start = ALIGN(f_sz, clust_sz); update_meta = true; @@ -459,7 +454,7 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src } /* Update the cached level2 entry */ - l2t->table[l2t_idx] = clust_start; + l2t->table[l2t_idx] = cpu_to_be64(clust_start); } mutex_unlock(&q->mutex);