From patchwork Fri Jan 17 10:34:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 11339285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 836FD109A for ; Fri, 17 Jan 2020 14:16:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 157C12083E for ; Fri, 17 Jan 2020 14:16:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="KpoKCehB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 157C12083E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isSQ0-0007gg-1s for patchwork-qemu-devel@patchwork.kernel.org; Fri, 17 Jan 2020 09:16:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56422) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isOyw-0005SY-0q for qemu-devel@nongnu.org; Fri, 17 Jan 2020 05:36:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isOyr-0006W0-MG for qemu-devel@nongnu.org; Fri, 17 Jan 2020 05:36:01 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57992) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1isOyr-0006UG-F2 for qemu-devel@nongnu.org; Fri, 17 Jan 2020 05:35:57 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00HAY3iO161391 for ; Fri, 17 Jan 2020 10:35:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2019-08-05; bh=549lWEneC6AQVgxJMNmbCEU/IPhzDWcy3LOeI993BkU=; b=KpoKCehBCSIPdGMfKU+L5gfv8Fh13Qn3o8WaXxRnc428wf/fosmLz9tX3ozyBSpgAYd/ nhHyzcvjKnJTvyqCX1uJroJZpBLg1QUR+N4cxmO0oqUDBtR54CPESTlTz+0p6CjjAmv0 j3eksxl/XJLXK/BMS4jPX0OF9A0V1ez8o+qZ3BSlsXsWLivKoWwn2CQPCRleP2POvPyK Ycs0zQggOfkLOTnkh2d/Cnaak5HJzpzW1hulaKpN+9jhRGALbu+f2gqDQdLEK/NNpeOO R2NJND1ou09WEFL/kaLmDvyAxdSJO7F/L/ZD2kshkZI3Nwm9Z7ubGOitrqk5H+EptJ7r Sw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2xf73u7vev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 17 Jan 2020 10:35:55 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00HAXRgr042775 for ; Fri, 17 Jan 2020 10:35:54 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2xjxm8nkgv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 17 Jan 2020 10:35:54 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00HAZrjS005660 for ; Fri, 17 Jan 2020 10:35:53 GMT Received: from disaster-area.hh.sledj.net (/81.149.164.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 17 Jan 2020 02:35:53 -0800 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 9f9f2f3a; Fri, 17 Jan 2020 10:35:51 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH] qemu-img: Add --target-is-zero to convert Date: Fri, 17 Jan 2020 10:34:35 +0000 Message-Id: <20200117103434.1363985-1-david.edmondson@oracle.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9502 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=877 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001170082 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9502 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=922 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001170082 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-Mailman-Approved-At: Fri, 17 Jan 2020 09:15:33 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Edmondson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this situation there is no requirement for qemu-img to wastefully zero out the entire device. Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled. --- qemu-img.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 95a24b9762..56ca727e8c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -70,6 +70,7 @@ enum { OPTION_PREALLOCATION = 265, OPTION_SHRINK = 266, OPTION_SALVAGE = 267, + OPTION_TARGET_IS_ZERO = 268, }; typedef enum OutputFormat { @@ -1593,6 +1594,7 @@ typedef struct ImgConvertState { bool copy_range; bool salvage; bool quiet; + bool target_is_zero; int min_sparse; int alignment; size_t cluster_sectors; @@ -1984,10 +1986,11 @@ static int convert_do_copy(ImgConvertState *s) int64_t sector_num = 0; /* Check whether we have zero initialisation or can get it efficiently */ - if (s->target_is_new && s->min_sparse && !s->target_has_backing) { + s->has_zero_init = s->target_is_zero; + + if (!s->has_zero_init && s->target_is_new && s->min_sparse && + !s->target_has_backing) { s->has_zero_init = bdrv_has_zero_init(blk_bs(s->target)); - } else { - s->has_zero_init = false; } if (!s->has_zero_init && !s->target_has_backing && @@ -2076,6 +2079,7 @@ static int img_convert(int argc, char **argv) .buf_sectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE, .wr_in_order = true, .num_coroutines = 8, + .target_is_zero = false, }; for(;;) { @@ -2086,6 +2090,7 @@ static int img_convert(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, {"salvage", no_argument, 0, OPTION_SALVAGE}, + {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU", @@ -2209,6 +2214,9 @@ static int img_convert(int argc, char **argv) case OPTION_TARGET_IMAGE_OPTS: tgt_image_opts = true; break; + case OPTION_TARGET_IS_ZERO: + s.target_is_zero = true; + break; } } @@ -2247,6 +2255,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.target_is_zero && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + } + s.src_num = argc - optind - 1; out_filename = s.src_num >= 1 ? argv[argc - 1] : NULL;