From patchwork Wed Apr 11 14:46:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Yuan X-Patchwork-Id: 151806 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7B094B7067 for ; Thu, 12 Apr 2012 00:46:53 +1000 (EST) Received: from localhost ([::1]:59514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHyos-0001kY-VZ for incoming@patchwork.ozlabs.org; Wed, 11 Apr 2012 10:46:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHyom-0001kC-VF for qemu-devel@nongnu.org; Wed, 11 Apr 2012 10:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SHyog-0007G8-2Z for qemu-devel@nongnu.org; Wed, 11 Apr 2012 10:46:44 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:55289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHyof-0007Fy-Q9 for qemu-devel@nongnu.org; Wed, 11 Apr 2012 10:46:37 -0400 Received: by dadz9 with SMTP id z9so1506217dad.33 for ; Wed, 11 Apr 2012 07:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Zd8y3e2RQFo7fzHnWkjqMpAnT8LlLrikSLwx7/Cei5I=; b=w/w1sZwNMTcr1A3XDsW/d2GRYEAFqMyQbn6BxBAjSvUVa+Vo5TQGDuA0gwy4RWF3JB yFZJOZek457YyDlI/QOX6mDvKpwddxZHUw3+0taP6gRVuC/1h0alv4fxrTv+2peY5Q0C Ndt80M3bd2ZFbCHniQlklWHx9Fr9DjeNlhfhhpwZ6KsMRi02aaIe4fnc4db7DR4eIve3 vSHUP/i2TMtwRfVyYNqLqeL38B+CaGbycj0vJhyYwS08hwVhLZxjZVwxRWQ0ZE97fUb4 5bom6duH+Z8EsE/1CazyZ3Sms4QwZoDmqzp9MyPCX0f0PdPoIxPxV9JHULA4H/x0HJLh z4sQ== Received: by 10.68.218.72 with SMTP id pe8mr38593049pbc.45.1334155595529; Wed, 11 Apr 2012 07:46:35 -0700 (PDT) Received: from taobao.localdomain ([183.157.111.209]) by mx.google.com with ESMTPS id ko12sm3058063pbb.52.2012.04.11.07.46.27 (version=SSLv3 cipher=OTHER); Wed, 11 Apr 2012 07:46:34 -0700 (PDT) From: Liu Yuan To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2012 22:46:26 +0800 Message-Id: <1334155586-4205-1-git-send-email-namei.unix@gmail.com> X-Mailer: git-send-email 1.7.8.2 In-Reply-To: <4F8578A4.5030201@redhat.com> References: <4F8578A4.5030201@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.46 Cc: kwolf@redhat.com, stefanha@gmail.com Subject: [Qemu-devel] [PATCH v2] qemu-img: let 'qemu-img convert' flush data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Liu Yuan The 'qemu-img convert -h' advertise that the default cache mode is 'writeback', while in fact it is 'unsafe'. This patch 1) fix the help manual and 2) let bdrv_close() call bdrv_flush() 3) explicitly calls bdrv_close() to flush the dirty bits. 3) is needed because some backend storage doesn't have a self-flush mechanism(for e.g., sheepdog), so we need to call bdrv_close() to make sure the image is really writen to the storage instead of hanging around writeback cache forever. Signed-off-by: Liu Yuan --- block.c | 1 + qemu-img.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index c0c90f0..1ee2bf0 100644 --- a/block.c +++ b/block.c @@ -812,6 +812,7 @@ unlink_and_fail: void bdrv_close(BlockDriverState *bs) { + bdrv_flush(bs); if (bs->drv) { if (bs->job) { block_job_cancel_sync(bs->job); diff --git a/qemu-img.c b/qemu-img.c index 6a61ca8..846f707 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -66,8 +66,8 @@ static void help(void) " 'filename' is a disk image filename\n" " 'fmt' is the disk image format. It is guessed automatically in most cases\n" " 'cache' is the cache mode used to write the output disk image, the valid\n" - " options are: 'none', 'writeback' (default), 'writethrough', 'directsync'\n" - " and 'unsafe'\n" + " options are: 'none', 'writeback', 'writethrough', 'directsync'\n" + " and 'unsafe' (default)\n" " 'size' is the disk image size in bytes. Optional suffixes\n" " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n" " and T (terabyte, 1024G) are supported. 'b' is ignored.\n" @@ -1036,6 +1036,9 @@ out: free_option_parameters(param); qemu_vfree(buf); if (out_bs) { + if (ret == 0) { + bdrv_close(out_bs); + } bdrv_delete(out_bs); } if (bs) {