From patchwork Sat Jul 9 13:02:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 959592 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 p69D3J0L004277 for ; Sat, 9 Jul 2011 13:03:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753543Ab1GINDO (ORCPT ); Sat, 9 Jul 2011 09:03:14 -0400 Received: from filtteri1.pp.htv.fi ([213.243.153.184]:46693 "EHLO filtteri1.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752802Ab1GINDE (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 3D62B1FB02A; 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 olUhQ0uKvyOR; 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 DB5905BC006; 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 9/9] kvm tools, qcow: Flush only dirty L2 tables Date: Sat, 9 Jul 2011 16:02:42 +0300 Message-Id: <1310216563-17503-10-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:46 +0000 (UTC) This patch improves qcow_l2_cache_write() to only flush dirty L2 tables. 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 ++++++++++- tools/kvm/include/kvm/qcow.h | 1 + 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/tools/kvm/disk/qcow.c b/tools/kvm/disk/qcow.c index b71762f..13c8bea 100644 --- a/tools/kvm/disk/qcow.c +++ b/tools/kvm/disk/qcow.c @@ -93,9 +93,17 @@ static int qcow_l2_cache_write(struct qcow *q, struct qcow_l2_table *c) struct qcow_header *header = q->header; u64 size; + if (!c->dirty) + return 0; + size = 1 << header->l2_bits; - return pwrite_in_full(q->fd, c->table, size * sizeof(u64), c->offset); + if (pwrite_in_full(q->fd, c->table, size * sizeof(u64), c->offset) < 0) + return -1; + + c->dirty = 0; + + return 0; } static int cache_table(struct qcow *q, struct qcow_l2_table *c) @@ -447,6 +455,7 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src if (!clust_start) { clust_start = ALIGN(f_sz, clust_sz); l2t->table[l2t_idx] = cpu_to_be64(clust_start); + l2t->dirty = 1; } mutex_unlock(&q->mutex); diff --git a/tools/kvm/include/kvm/qcow.h b/tools/kvm/include/kvm/qcow.h index d44c64a..650d3c2 100644 --- a/tools/kvm/include/kvm/qcow.h +++ b/tools/kvm/include/kvm/qcow.h @@ -27,6 +27,7 @@ struct qcow_l2_table { u64 offset; struct rb_node node; struct list_head list; + u8 dirty; u64 table[]; };