mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
qemu-img: add support for rate limit in qemu-img convert
add support for rate limit in qemu-img convert. Signed-off-by: Zhengui <lizhengui@huawei.com> Message-Id: <1603205264-17424-3-git-send-email-lizhengui@huawei.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
a0441b66e8
commit
0c8c4895a6
3 changed files with 33 additions and 4 deletions
27
qemu-img.c
27
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"
|
||||
|
||||
#define QEMU_IMG_VERSION "qemu-img version " QEMU_FULL_VERSION \
|
||||
"\n" QEMU_COPYRIGHT "\n"
|
||||
|
@ -1669,6 +1671,7 @@ enum ImgConvertBlockStatus {
|
|||
};
|
||||
|
||||
#define MAX_COROUTINES 16
|
||||
#define CONVERT_THROTTLE_GROUP "img_convert"
|
||||
|
||||
typedef struct ImgConvertState {
|
||||
BlockBackend **src;
|
||||
|
@ -2184,6 +2187,17 @@ static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst)
|
|||
|
||||
#define MAX_BUF_SECTORS 32768
|
||||
|
||||
static void set_rate_limit(BlockBackend *blk, int64_t rate_limit)
|
||||
{
|
||||
ThrottleConfig cfg;
|
||||
|
||||
throttle_config_init(&cfg);
|
||||
cfg.buckets[THROTTLE_BPS_WRITE].avg = 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 = 0;
|
||||
|
@ -2204,6 +2218,7 @@ static int img_convert(int argc, char **argv)
|
|||
bool force_share = false;
|
||||
bool explict_min_sparse = false;
|
||||
bool bitmaps = false;
|
||||
int64_t rate_limit = 0;
|
||||
|
||||
ImgConvertState s = (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 = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU",
|
||||
c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WUr:",
|
||||
long_options, NULL);
|
||||
if (c == -1) {
|
||||
break;
|
||||
|
@ -2323,6 +2338,12 @@ static int img_convert(int argc, char **argv)
|
|||
case 'U':
|
||||
force_share = true;
|
||||
break;
|
||||
case 'r':
|
||||
rate_limit = cvtnum("rate limit", optarg);
|
||||
if (rate_limit < 0) {
|
||||
goto fail_getopt;
|
||||
}
|
||||
break;
|
||||
case OPTION_OBJECT: {
|
||||
QemuOpts *object_opts;
|
||||
object_opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
||||
|
@ -2712,6 +2733,10 @@ static int img_convert(int argc, char **argv)
|
|||
s.cluster_sectors = bdi.cluster_size / BDRV_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
if (rate_limit) {
|
||||
set_rate_limit(s.target, rate_limit);
|
||||
}
|
||||
|
||||
ret = convert_do_copy(&s);
|
||||
|
||||
/* Now copy the bitmaps */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue