From patchwork Mon Nov 30 15:54:15 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B48FB6EF6 for ; Tue, 1 Dec 2009 02:56:01 +1100 (EST) Received: from localhost ([127.0.0.1]:47690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NF8bV-0003aX-TE for incoming@patchwork.ozlabs.org; Mon, 30 Nov 2009 10:55:57 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NF8b0-0003aN-JT for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:26 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NF8aw-0003Zd-3F for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:26 -0500 Received: from [199.232.76.173] (port=38950 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NF8av-0003ZS-T9 for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54162) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NF8av-00010e-J3 for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:21 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAUFtKAU024235 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 30 Nov 2009 10:55:20 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAUFtIkB029201; Mon, 30 Nov 2009 10:55:19 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 30 Nov 2009 16:54:15 +0100 Message-Id: <1259596455-14486-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] qemu-img: There is more than one host device driver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org I haven't heard yet of anyone using qemu-img to copy an image to a real floppy, but it's a valid use case. Signed-off-by: Kevin Wolf --- block/raw-posix.c | 4 ++++ block_int.h | 3 +++ qemu-img.c | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index f558976..3763d0c 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1014,6 +1014,7 @@ static BlockDriver bdrv_host_device = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, @@ -1110,6 +1111,7 @@ static BlockDriver bdrv_host_floppy = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, @@ -1192,6 +1194,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, @@ -1313,6 +1316,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, diff --git a/block_int.h b/block_int.h index 7ebe926..a7ac1f6 100644 --- a/block_int.h +++ b/block_int.h @@ -117,6 +117,9 @@ struct BlockDriver { /* Returns number of errors in image, -errno for internal errors */ int (*bdrv_check)(BlockDriverState* bs); + /* Set if newly created images are not guaranteed to contain only zeros */ + int no_zero_init; + struct BlockDriver *next; }; diff --git a/qemu-img.c b/qemu-img.c index 972843a..f19c644 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -743,7 +743,7 @@ static int img_convert(int argc, char **argv) if (n > bs_offset + bs_sectors - sector_num) n = bs_offset + bs_sectors - sector_num; - if (strcmp(drv->format_name, "host_device")) { + if (!drv->no_zero_init) { /* If the output image is being created as a copy on write image, assume that sectors which are unallocated in the input image are present in both the output's and input's base images (no @@ -776,7 +776,7 @@ static int img_convert(int argc, char **argv) If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ - if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg || + if (drv->no_zero_init || out_baseimg || is_allocated_sectors(buf1, n, &n1)) { if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) error("error while writing");