From patchwork Sat Jul 9 13:02:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 959572 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 p69D3J0J004277 for ; Sat, 9 Jul 2011 13:03:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753657Ab1GINDR (ORCPT ); Sat, 9 Jul 2011 09:03:17 -0400 Received: from filtteri1.pp.htv.fi ([213.243.153.184]:46682 "EHLO filtteri1.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753357Ab1GINDB (ORCPT ); Sat, 9 Jul 2011 09:03:01 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri1.pp.htv.fi (Postfix) with ESMTP id 7842E1FB023; Sat, 9 Jul 2011 16:03:00 +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 yd073-Tq19TG; 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 2F7475BC004; 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 4/9] kvm tools, qcow: Introduce qcow_disk_flush() Date: Sat, 9 Jul 2011 16:02:37 +0300 Message-Id: <1310216563-17503-5-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:39 +0000 (UTC) This patch introduces a QCOW specific qcow_disk_flush() in preparation for delaying QCOW metadata writeout until VIRTIO_BLK_T_FLUSH time. 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 | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/kvm/disk/qcow.c b/tools/kvm/disk/qcow.c index 939bc61..1a6a969 100644 --- a/tools/kvm/disk/qcow.c +++ b/tools/kvm/disk/qcow.c @@ -244,7 +244,7 @@ static ssize_t qcow_read_cluster(struct qcow *q, u64 offset, void *dst, u32 dst_ length = dst_len; mutex_lock(&q->mutex); - l2_table_offset = table->l1_table[l1_idx] & ~header->oflag_mask; + l2_table_offset = be64_to_cpu(table->l1_table[l1_idx]) & ~header->oflag_mask; if (!l2_table_offset) goto zero_cluster; @@ -400,7 +400,7 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src mutex_lock(&q->mutex); - l2t_off = table->l1_table[l1t_idx] & ~header->oflag_mask; + l2t_off = be64_to_cpu(table->l1_table[l1t_idx]) & ~header->oflag_mask; if (l2t_off) { /* read and cache l2 table */ l2t = qcow_read_l2_table(q, l2t_off); @@ -440,7 +440,7 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src } /* Update the in-core entry */ - table->l1_table[l1t_idx] = l2t_off; + table->l1_table[l1t_idx] = cpu_to_be64(l2t_off); } /* Capture the state of the consistent QCOW image */ @@ -520,6 +520,11 @@ static ssize_t qcow_nowrite_sector(struct disk_image *disk, u64 sector, void *sr return -1; } +static int qcow_disk_flush(struct disk_image *disk) +{ + return fsync(disk->fd); +} + static int qcow_disk_close(struct disk_image *disk) { struct qcow *q; @@ -546,6 +551,7 @@ static struct disk_image_operations qcow_disk_readonly_ops = { static struct disk_image_operations qcow_disk_ops = { .read_sector = qcow_read_sector, .write_sector = qcow_write_sector, + .flush = qcow_disk_flush, .close = qcow_disk_close, }; @@ -553,7 +559,6 @@ static int qcow_read_l1_table(struct qcow *q) { struct qcow_header *header = q->header; struct qcow_table *table = &q->table; - u64 i; table->table_size = header->l1_size; @@ -561,14 +566,7 @@ static int qcow_read_l1_table(struct qcow *q) if (!table->l1_table) return -1; - 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; + return pread_in_full(q->fd, table->l1_table, sizeof(u64) * table->table_size, header->l1_table_offset); } static void *qcow2_read_header(int fd)