From patchwork Fri Apr 15 14:18:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Joshi X-Patchwork-Id: 710821 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3FEIw1I014188 for ; Fri, 15 Apr 2011 14:18:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756006Ab1DOOS4 (ORCPT ); Fri, 15 Apr 2011 10:18:56 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:42222 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753964Ab1DOOSv (ORCPT ); Fri, 15 Apr 2011 10:18:51 -0400 Received: by wwa36 with SMTP id 36so3269202wwa.1 for ; Fri, 15 Apr 2011 07:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=uE4vErkMTgJXueq7ZG/2fACb6dJbIEegqyETl3IwsYs=; b=aDTSlkWtQbIoj4ma9DM0faRJgXnSRXQ4WfEectbw4mNVd8k/OLnDs6YQSN7Y4QfGBD amzK9wqF0LWTVez1Kno8Pj4TzndBQgrji96dYlBRKxIxcFjeEf3P3KgOc5HlnwziMCNO pNiitx2SuGfbI0NMOuyWvwiBNJwGA6T/vqnKY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=sC3+98BBoWHRmB96TcpUtJonOF3nPbPMx46xswEcEVnvdpy19hj8keqahNI2g2U6Yq wEft7oVWpG+vW+EDfr6+fXcgiTQHCMxctZhbHLIInfsH8/EsGbkDiHiS0uOEkxNiL8sC xfjRLaIzrnHKEkuiZuT5ZMbNJ1LgGesCCFnJo= Received: by 10.227.202.15 with SMTP id fc15mr2114380wbb.214.1302877130631; Fri, 15 Apr 2011 07:18:50 -0700 (PDT) Received: from prasad-kvm.localdomain (pineapple.rdg.ac.uk [134.225.206.123]) by mx.google.com with ESMTPS id p5sm1651187wbg.11.2011.04.15.07.18.48 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 15 Apr 2011 07:18:50 -0700 (PDT) Received: by prasad-kvm.localdomain (Postfix, from userid 1000) id B6FC626E006D; Fri, 15 Apr 2011 15:18:59 +0100 (BST) From: Prasad Joshi To: prasadjoshi124@gmail.com Cc: mingo@elte.hu, kvm@vger.kernel.org, penberg@kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, levinsasha928@gmail.com, kwolf@redhat.com, stefanha@linux.vnet.ibm.com, chaitanyakulkarni15@gmail.com Subject: [PATCH 2/4] kvm tool: avoid byte-order conversion during each read operation Date: Fri, 15 Apr 2011 15:18:56 +0100 Message-Id: <1302877138-6695-2-git-send-email-prasadjoshi124@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1302877138-6695-1-git-send-email-prasadjoshi124@gmail.com> References: <1302877138-6695-1-git-send-email-prasadjoshi124@gmail.com> 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]); Fri, 15 Apr 2011 14:18:59 +0000 (UTC) Signed-off-by: Prasad Joshi --- tools/kvm/qcow.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/kvm/qcow.c b/tools/kvm/qcow.c index 219fd6b..243bfa8 100644 --- a/tools/kvm/qcow.c +++ b/tools/kvm/qcow.c @@ -58,7 +58,7 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst if (l1_idx >= q->table.table_size) goto out_error; - l2_table_offset = be64_to_cpu(q->table.l1_table[l1_idx]); + l2_table_offset = q->table.l1_table[l1_idx]; if (!l2_table_offset) goto zero_sector; @@ -128,16 +128,23 @@ struct disk_image_operations qcow1_disk_ops = { static int qcow_read_l1_table(struct qcow *q) { struct qcow1_header *header = q->header; + struct qcow_table *table = &q->table; + u64 i; - q->table.table_size = header->size / ((1 << header->l2_bits) * (1 << header->cluster_bits)); + table->table_size = header->size / ((1 << header->l2_bits) * + (1 << header->cluster_bits)); - q->table.l1_table = calloc(q->table.table_size, sizeof(uint64_t)); - if (!q->table.l1_table) + table->l1_table = calloc(table->table_size, sizeof(u64)); + if (!table->l1_table) return -1; - if (pread_in_full(q->fd, q->table.l1_table, sizeof(uint64_t) * q->table.table_size, header->l1_table_offset) < 0) + if (pread_in_full(q->fd, table->l1_table, sizeof(u64) * + table->table_size, header->l1_table_offset) < 0) return -1; + for (i = 0; i < table->table_size; i++) + be64_to_cpus(&table->l1_table[i]); + return 0; }