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
@ -188,6 +188,10 @@ Parameters to convert subcommand:
|
|||||||
allocated target image depending on the host support for getting allocation
|
allocated target image depending on the host support for getting allocation
|
||||||
information.
|
information.
|
||||||
|
|
||||||
|
.. option:: -r
|
||||||
|
|
||||||
|
Rate limit for the convert process
|
||||||
|
|
||||||
.. option:: --salvage
|
.. option:: --salvage
|
||||||
|
|
||||||
Try to ignore I/O errors when reading. Unless in quiet mode (``-q``), errors
|
Try to ignore I/O errors when reading. Unless in quiet mode (``-q``), errors
|
||||||
@ -410,7 +414,7 @@ Command description:
|
|||||||
4
|
4
|
||||||
Error on reading data
|
Error on reading data
|
||||||
|
|
||||||
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--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 [FILENAME2 [...]] OUTPUT_FILENAME
|
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--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
|
||||||
|
|
||||||
Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM*
|
Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM*
|
||||||
to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can
|
to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can
|
||||||
|
@ -46,9 +46,9 @@ SRST
|
|||||||
ERST
|
ERST
|
||||||
|
|
||||||
DEF("convert", img_convert,
|
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 cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename")
|
"convert [--object objectdef] [--image-opts] [--target-image-opts] [--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")
|
||||||
SRST
|
SRST
|
||||||
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--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] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME
|
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--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
|
ERST
|
||||||
|
|
||||||
DEF("create", img_create,
|
DEF("create", img_create,
|
||||||
|
27
qemu-img.c
27
qemu-img.c
@ -50,6 +50,8 @@
|
|||||||
#include "block/qapi.h"
|
#include "block/qapi.h"
|
||||||
#include "crypto/init.h"
|
#include "crypto/init.h"
|
||||||
#include "trace/control.h"
|
#include "trace/control.h"
|
||||||
|
#include "qemu/throttle.h"
|
||||||
|
#include "block/throttle-groups.h"
|
||||||
|
|
||||||
#define QEMU_IMG_VERSION "qemu-img version " QEMU_FULL_VERSION \
|
#define QEMU_IMG_VERSION "qemu-img version " QEMU_FULL_VERSION \
|
||||||
"\n" QEMU_COPYRIGHT "\n"
|
"\n" QEMU_COPYRIGHT "\n"
|
||||||
@ -1669,6 +1671,7 @@ enum ImgConvertBlockStatus {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_COROUTINES 16
|
#define MAX_COROUTINES 16
|
||||||
|
#define CONVERT_THROTTLE_GROUP "img_convert"
|
||||||
|
|
||||||
typedef struct ImgConvertState {
|
typedef struct ImgConvertState {
|
||||||
BlockBackend **src;
|
BlockBackend **src;
|
||||||
@ -2184,6 +2187,17 @@ static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst)
|
|||||||
|
|
||||||
#define MAX_BUF_SECTORS 32768
|
#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)
|
static int img_convert(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, bs_i, flags, src_flags = 0;
|
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 force_share = false;
|
||||||
bool explict_min_sparse = false;
|
bool explict_min_sparse = false;
|
||||||
bool bitmaps = false;
|
bool bitmaps = false;
|
||||||
|
int64_t rate_limit = 0;
|
||||||
|
|
||||||
ImgConvertState s = (ImgConvertState) {
|
ImgConvertState s = (ImgConvertState) {
|
||||||
/* Need at least 4k of zeros for sparse detection */
|
/* 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},
|
{"bitmaps", no_argument, 0, OPTION_BITMAPS},
|
||||||
{0, 0, 0, 0}
|
{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);
|
long_options, NULL);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -2323,6 +2338,12 @@ static int img_convert(int argc, char **argv)
|
|||||||
case 'U':
|
case 'U':
|
||||||
force_share = true;
|
force_share = true;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
rate_limit = cvtnum("rate limit", optarg);
|
||||||
|
if (rate_limit < 0) {
|
||||||
|
goto fail_getopt;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case OPTION_OBJECT: {
|
case OPTION_OBJECT: {
|
||||||
QemuOpts *object_opts;
|
QemuOpts *object_opts;
|
||||||
object_opts = qemu_opts_parse_noisily(&qemu_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;
|
s.cluster_sectors = bdi.cluster_size / BDRV_SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rate_limit) {
|
||||||
|
set_rate_limit(s.target, rate_limit);
|
||||||
|
}
|
||||||
|
|
||||||
ret = convert_do_copy(&s);
|
ret = convert_do_copy(&s);
|
||||||
|
|
||||||
/* Now copy the bitmaps */
|
/* Now copy the bitmaps */
|
||||||
|
Loading…
Reference in New Issue
Block a user