From patchwork Sat Jul 9 13:02:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 959582 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 p69D3J0K004277 for ; Sat, 9 Jul 2011 13:03:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753629Ab1GINDR (ORCPT ); Sat, 9 Jul 2011 09:03:17 -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 S1753351Ab1GINDD (ORCPT ); Sat, 9 Jul 2011 09:03:03 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri1.pp.htv.fi (Postfix) with ESMTP id B1E961FB027; 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 fVrvL98cC9ll; 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 5976E5BC005; 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 5/9] kvm tools, qcow: Delayed L1 table writeout Date: Sat, 9 Jul 2011 16:02:38 +0300 Message-Id: <1310216563-17503-6-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:41 +0000 (UTC) This patch moves L1 table writeout to qcow_disk_flush(). The rationale here is that while writes to clusters that don't have L2 table allocated on-disk are volatile until VIRTIO_BLK_T_FLUSH is issued, we never corrupt the disk image. 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 | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/kvm/disk/qcow.c b/tools/kvm/disk/qcow.c index 1a6a969..0fef92f 100644 --- a/tools/kvm/disk/qcow.c +++ b/tools/kvm/disk/qcow.c @@ -421,17 +421,6 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src if (!l2t_off) goto free_cache; - /* Metadata update: update on disk level 1 table */ - t = cpu_to_be64(l2t_off); - - if (qcow_pwrite_sync(q->fd, &t, sizeof(t), header->l1_table_offset + l1t_idx * sizeof(u64)) < 0) { - /* restore file to consistent state */ - if (ftruncate(q->fd, f_sz) < 0) - goto free_cache; - - goto free_cache; - } - if (cache_table(q, l2t) < 0) { if (ftruncate(q->fd, f_sz) < 0) goto free_cache; @@ -522,6 +511,19 @@ static ssize_t qcow_nowrite_sector(struct disk_image *disk, u64 sector, void *sr static int qcow_disk_flush(struct disk_image *disk) { + struct qcow *q = disk->priv; + struct qcow_header *header; + struct qcow_table *table; + + if (fdatasync(disk->fd) < 0) + return -1; + + header = q->header; + table = &q->table; + + if (pwrite_in_full(disk->fd, table->l1_table, table->table_size * sizeof(u64), header->l1_table_offset) < 0) + return -1; + return fsync(disk->fd); }