From nobody Mon Feb 9 02:43:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603205574; cv=none; d=zohomail.com; s=zohoarc; b=ko0Z0MGNj2UD2qBKOQ5VFcZUZMCm71b+Vbu/Pu0w2OoQK4eYNT2zNgjXpgwxrFj6U1FAB1VQJUwRkj9D0pkcT6uCwCMi41NKnqwTt0eD/1eD7TY1F+uZUDPawifRChzZInvCKUqofrD8ckX8/qzcQG4AdnWRkXOj4cEJxssMpRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603205574; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IuKuBtS2iNWMWcfJVyWbJwyXvLFLmhH82Ez8vYbNxZQ=; b=KXRBv+v/Hjtn1a4o8MDrXKtqTbcsF1Q51BCrhCiFZkeEBE8H9GTb+a5dkdOTHH9VIk7N6+EjuXde5ZfFBpqx3o8kCHOsV2ehEdk9Bd/9xfu2azP30OjgftBNnH3Yl/ou1bWFEkjY1S2kxTXs9Zkc7st8qk6dnYnkfw3wJYavvak= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603205574279348.0906209084593; Tue, 20 Oct 2020 07:52:54 -0700 (PDT) Received: from localhost ([::1]:46510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUt0P-0003GC-IV for importer@patchew.org; Tue, 20 Oct 2020 10:52:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUsvo-00070E-Qr; Tue, 20 Oct 2020 10:48:08 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5195 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUsvm-00031H-Nb; Tue, 20 Oct 2020 10:48:08 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 314E3A4AB1BAD10B0ED8; Tue, 20 Oct 2020 22:47:59 +0800 (CST) Received: from DESKTOP-80C7KIU.china.huawei.com (10.174.187.210) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 20 Oct 2020 22:47:49 +0800 From: Zhengui li To: , , , Subject: [PATCH v3 1/2] qemu-img: add support for rate limit in qemu-img commit Date: Tue, 20 Oct 2020 14:47:43 +0000 Message-ID: <1603205264-17424-2-git-send-email-lizhengui@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1603205264-17424-1-git-send-email-lizhengui@huawei.com> References: <1603205264-17424-1-git-send-email-lizhengui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.210] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=lizhengui@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/20 09:15:07 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: xieyingtai@huawei.com, lizhengui@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zhengui add support for rate limit in qemu-img commit. Signed-off-by: Zhengui Reviewed-by: Alberto Garcia --- docs/tools/qemu-img.rst | 4 +++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 11 +++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index c35bd64..bcb11b0 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -349,7 +349,7 @@ Command description: state after (the attempt at) repairing it. That is, a successful ``-r al= l`` will yield the exit code 0, independently of the image state before. =20 -.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t C= ACHE] [-b BASE] [-d] [-p] FILENAME +.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t C= ACHE] [-b BASE] [-r RATE_LIMIT] [-d] [-p] FILENAME =20 Commit the changes recorded in *FILENAME* in its base image or backing f= ile. If the backing file is smaller than the snapshot, then the backing file = will be @@ -371,6 +371,8 @@ Command description: garbage data when read. For this reason, ``-b`` implies ``-d`` (so that the top image stays valid). =20 + The rate limit for the commit process is specified by ``-r``. + .. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2 =20 Check if two images have the same content. You can compare images with diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index b89c019..2a31806 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -34,9 +34,9 @@ SRST ERST =20 DEF("commit", img_commit, - "commit [--object objectdef] [--image-opts] [-q] [-f fmt] [-t cache] [= -b base] [-d] [-p] filename") + "commit [--object objectdef] [--image-opts] [-q] [-f fmt] [-t cache] [= -b base] [-r rate_limit] [-d] [-p] filename") SRST -.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t C= ACHE] [-b BASE] [-d] [-p] FILENAME +.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t C= ACHE] [-b BASE] [-r RATE_LIMIT] [-d] [-p] FILENAME ERST =20 DEF("compare", img_compare, diff --git a/qemu-img.c b/qemu-img.c index 2103507..3023abe 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -980,6 +980,7 @@ static int img_commit(int argc, char **argv) CommonBlockJobCBInfo cbi; bool image_opts =3D false; AioContext *aio_context; + int64_t rate_limit =3D 0; =20 fmt =3D NULL; cache =3D BDRV_DEFAULT_CACHE; @@ -991,7 +992,7 @@ static int img_commit(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:ht:b:dpq", + c =3D getopt_long(argc, argv, ":f:ht:b:dpqr:", long_options, NULL); if (c =3D=3D -1) { break; @@ -1026,6 +1027,12 @@ static int img_commit(int argc, char **argv) case 'q': quiet =3D true; break; + case 'r': + rate_limit =3D cvtnum("rate limit", optarg); + if (rate_limit < 0) { + return 1; + } + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -1099,7 +1106,7 @@ static int img_commit(int argc, char **argv) =20 aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - commit_active_start("commit", bs, base_bs, JOB_DEFAULT, 0, + commit_active_start("commit", bs, base_bs, JOB_DEFAULT, rate_limit, BLOCKDEV_ON_ERROR_REPORT, NULL, common_block_job_c= b, &cbi, false, &local_err); aio_context_release(aio_context); --=20 2.6.4.windows.1 From nobody Mon Feb 9 02:43:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603205541; cv=none; d=zohomail.com; s=zohoarc; b=UNXFkXpng7i/XNyQ/G9ZRQ/FXyYP5/lC+0F+Wv+CMaJ9G7MIwAhCJFbCO9tg8Q8aCjXRHqWbP7fztDbNGEtdR25h2azc+R1SwUqsqFxJC2p7yBhuvnKFD8bAtU4fEOLGTEiTrAmHFearQ1XMMExU8AEXLUDU5TuUi2VTQ+g+Kns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603205541; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PN+WOkaICFKIj8m18wy5K3ElY+DNDWEP0C3Zu1H3nh8=; b=gJEEJEcEiOAmy9doGsHQ39azoUTPElt/2NVdaR05hnkNj16GtNxIfWC9r2Ry2z+HKtryz/Q1Y8eps+v0M6MQS+C2phzDv7J+9zs1PP8g8ISNjZUjnuIZo5mk1cSMZ5voOa3B0DHRO4kA8/hS+fdmvIuXbTI3D/bCBrlRTDjFbS0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603205541778716.8451455657961; Tue, 20 Oct 2020 07:52:21 -0700 (PDT) Received: from localhost ([::1]:44808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUszs-0002aH-W0 for importer@patchew.org; Tue, 20 Oct 2020 10:52:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUsvm-0006uu-JP; Tue, 20 Oct 2020 10:48:06 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5194 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUsvk-00031F-7s; Tue, 20 Oct 2020 10:48:06 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 2AE623D2F05E011C6D58; Tue, 20 Oct 2020 22:47:59 +0800 (CST) Received: from DESKTOP-80C7KIU.china.huawei.com (10.174.187.210) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Tue, 20 Oct 2020 22:47:52 +0800 From: Zhengui li To: , , , Subject: [PATCH v3 2/2] qemu-img: add support for rate limit in qemu-img convert Date: Tue, 20 Oct 2020 14:47:44 +0000 Message-ID: <1603205264-17424-3-git-send-email-lizhengui@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1603205264-17424-1-git-send-email-lizhengui@huawei.com> References: <1603205264-17424-1-git-send-email-lizhengui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.210] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=lizhengui@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/20 09:15:07 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: xieyingtai@huawei.com, lizhengui@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zhengui add support for rate limit in qemu-img convert. Signed-off-by: Zhengui Reviewed-by: Alberto Garcia --- docs/tools/qemu-img.rst | 6 +++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 27 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index bcb11b0..b615aa8 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -188,6 +188,10 @@ Parameters to convert subcommand: allocated target image depending on the host support for getting allocat= ion information. =20 +.. option:: -r + + Rate limit for the convert process + .. option:: --salvage =20 Try to ignore I/O errors when reading. Unless in quiet mode (``-q``), e= rrors @@ -410,7 +414,7 @@ Command description: 4 Error on reading data =20 -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [= -t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l= SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES] [-W] FILENAME [FILENA= ME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [= -t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l= SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] = FILENAME [FILENAME2 [...]] OUTPUT_FILENAME =20 Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM* to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 2a31806..7eb489b 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -46,9 +46,9 @@ SRST ERST =20 DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [--= target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cach= e] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapsh= ot_param] [-S sparse_size] [-m num_coroutines] [-W] [--salvage] filename [f= ilename2 [...]] output_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [--= target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cach= e] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapsh= ot_param] [-S sparse_size] [-r rate_limit] [-m num_coroutines] [-W] [--salv= age] filename [filename2 [...]] output_filename") SRST -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [= -t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l= SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES] [-W] [--salvage] FILE= NAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [= -t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l= SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] = [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME ERST =20 DEF("create", img_create, diff --git a/qemu-img.c b/qemu-img.c index 3023abe..a968c74 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -50,6 +50,8 @@ #include "block/qapi.h" #include "crypto/init.h" #include "trace/control.h" +#include "qemu/throttle.h" +#include "block/throttle-groups.h" =20 #define QEMU_IMG_VERSION "qemu-img version " QEMU_FULL_VERSION \ "\n" QEMU_COPYRIGHT "\n" @@ -1669,6 +1671,7 @@ enum ImgConvertBlockStatus { }; =20 #define MAX_COROUTINES 16 +#define CONVERT_THROTTLE_GROUP "img_convert" =20 typedef struct ImgConvertState { BlockBackend **src; @@ -2184,6 +2187,17 @@ static int convert_copy_bitmaps(BlockDriverState *sr= c, BlockDriverState *dst) =20 #define MAX_BUF_SECTORS 32768 =20 +static void set_rate_limit(BlockBackend *blk, int64_t rate_limit) +{ + ThrottleConfig cfg; + + throttle_config_init(&cfg); + cfg.buckets[THROTTLE_BPS_WRITE].avg =3D rate_limit; + + blk_io_limits_enable(blk, CONVERT_THROTTLE_GROUP); + blk_set_io_limits(blk, &cfg); +} + static int img_convert(int argc, char **argv) { int c, bs_i, flags, src_flags =3D 0; @@ -2204,6 +2218,7 @@ static int img_convert(int argc, char **argv) bool force_share =3D false; bool explict_min_sparse =3D false; bool bitmaps =3D false; + int64_t rate_limit =3D 0; =20 ImgConvertState s =3D (ImgConvertState) { /* Need at least 4k of zeros for sparse detection */ @@ -2226,7 +2241,7 @@ static int img_convert(int argc, char **argv) {"bitmaps", no_argument, 0, OPTION_BITMAPS}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU", + c =3D getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WUr:", long_options, NULL); if (c =3D=3D -1) { break; @@ -2323,6 +2338,12 @@ static int img_convert(int argc, char **argv) case 'U': force_share =3D true; break; + case 'r': + rate_limit =3D cvtnum("rate limit", optarg); + if (rate_limit < 0) { + goto fail_getopt; + } + break; case OPTION_OBJECT: { QemuOpts *object_opts; object_opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -2712,6 +2733,10 @@ static int img_convert(int argc, char **argv) s.cluster_sectors =3D bdi.cluster_size / BDRV_SECTOR_SIZE; } =20 + if (rate_limit) { + set_rate_limit(s.target, rate_limit); + } + ret =3D convert_do_copy(&s); =20 /* Now copy the bitmaps */ --=20 2.6.4.windows.1