From patchwork Thu Apr 20 08:38:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 9689901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6A6660383 for ; Thu, 20 Apr 2017 08:39:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D34A203C0 for ; Thu, 20 Apr 2017 08:39:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 906E0252D5; Thu, 20 Apr 2017 08:39:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 01694203C0 for ; Thu, 20 Apr 2017 08:39:35 +0000 (UTC) Received: from localhost ([::1]:52378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d17ck-0002PO-CP for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Apr 2017 04:39:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d17c9-0002PE-Kr for qemu-devel@nongnu.org; Thu, 20 Apr 2017 04:38:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d17c6-0006T8-GG for qemu-devel@nongnu.org; Thu, 20 Apr 2017 04:38:57 -0400 Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]:33086) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d17c6-0006T1-Ax; Thu, 20 Apr 2017 04:38:54 -0400 Received: by mail-io0-x242.google.com with SMTP id k87so13677161ioi.0; Thu, 20 Apr 2017 01:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=j24iAi0NmqVrfznrg7s8JozNORI4a3HHVWVcfq9/l/8=; b=ZYyxpbWSCepsAHiriBpACeKir+edwx8KvufwQgxcjOnS3JaiHiDMw7vvi3VQloJ8HI lP2y79MuRqcjd9ISwuawwKJRpIYHRapbL+8aKz48FCWrrpadjOCtzkvZSCTJdoRBMlQE 6viZvbMa6l6gKF/1ueMsTEvc0LHqQ0RYti8vGnbT7C0TvxST3ilGWHn7duTalODnKbVL xs8BHZKcUds8dH5elS5F2Kd32zZGUn1hW/64l7vxZycXpBcQObmJq1oxf+Y5iJ7b6sPJ /wsmDh4O/M0Lay97aiFo7BNXTlygRoVnLeJ9mZygyt7fDZZETfVYURpb9Z10oR7Hair1 6YXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=j24iAi0NmqVrfznrg7s8JozNORI4a3HHVWVcfq9/l/8=; b=IToqCtZGteGBvyGor4a08rXmRUvjyyN4qBZAk48AnA27153kKBk+gUEcB6tdvfa1o1 K7q9W/THTQZvl260Wq4UEA0NqQ0ZvCv/7zRsybgl7J7ojCcW2MkgRp3D8gBcvsX5ecp8 cweHyubJpF2qOHa+yMoiADiOYQOPdXfTcoMAs/b+BPUc1ft3YAokNtRqh6lcNmuFJSwg hDzjjQtLtGuw8QFjaYOnYZ7Sb9rw6swja+JDlAEAgVXt2BEaaJUh4UdTo5bc4Q3gWZwk GDzalZaOuKnA1T20FBO6L59BIVlmed64BeXrV5cAOP0vz5z2ohYd/8SxQ06s3OYIxjky qYwg== X-Gm-Message-State: AN3rC/47XnaTeDL8kNz4kpR9Six9e2y1z1sgwpj/Ty9fqSjRnQedPJDf hJAOTunh8UzcRQ== X-Received: by 10.98.129.193 with SMTP id t184mr6992258pfd.130.1492677533511; Thu, 20 Apr 2017 01:38:53 -0700 (PDT) Received: from localhost.localdomain ([119.28.70.25]) by smtp.gmail.com with ESMTPSA id w3sm8907949pfw.15.2017.04.20.01.38.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 01:38:53 -0700 (PDT) From: jemmy858585@gmail.com X-Google-Original-From: lidongchen@tencent.com To: qemu-devel@nongnu.org Date: Thu, 20 Apr 2017 16:38:46 +0800 Message-Id: <1492677526-4739-1-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::242 Subject: [Qemu-devel] [PATCH] qemu-img: use blk_co_pwrite_zeroes for zero sectors when compressed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Lidong Chen , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lidong Chen when the buffer is zero, blk_co_pwrite_zeroes is more effectively than blk_co_pwritev with BDRV_REQ_WRITE_COMPRESSED. this patch can reduces the time when converts the qcow2 image with lots of zero. Signed-off-by: Lidong Chen --- qemu-img.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b220cf7..0256539 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1675,13 +1675,20 @@ static int coroutine_fn convert_co_write(ImgConvertState *s, int64_t sector_num, * write if the buffer is completely zeroed and we're allowed to * keep the target sparse. */ if (s->compressed) { - if (s->has_zero_init && s->min_sparse && - buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)) - { - assert(!s->target_has_backing); - break; + if (buffer_is_zero(buf, n * BDRV_SECTOR_SIZE)) { + if (s->has_zero_init && s->min_sparse) { + assert(!s->target_has_backing); + break; + } else { + ret = blk_co_pwrite_zeroes(s->target, + sector_num << BDRV_SECTOR_BITS, + n << BDRV_SECTOR_BITS, 0); + if (ret < 0) { + return ret; + } + break; + } } - iov.iov_base = buf; iov.iov_len = n << BDRV_SECTOR_BITS; qemu_iovec_init_external(&qiov, &iov, 1);