Skip to content

Commit a0441b6

Browse files
lizhenguikevmw
authored andcommitted
qemu-img: add support for rate limit in qemu-img commit
add support for rate limit in qemu-img commit. Signed-off-by: Zhengui <[email protected]> Message-Id: <[email protected]> Reviewed-by: Alberto Garcia <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent d55450d commit a0441b6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

docs/tools/qemu-img.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ Command description:
349349
state after (the attempt at) repairing it. That is, a successful ``-r all``
350350
will yield the exit code 0, independently of the image state before.
351351

352-
.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-d] [-p] FILENAME
352+
.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-r RATE_LIMIT] [-d] [-p] FILENAME
353353

354354
Commit the changes recorded in *FILENAME* in its base image or backing file.
355355
If the backing file is smaller than the snapshot, then the backing file will be
@@ -371,6 +371,8 @@ Command description:
371371
garbage data when read. For this reason, ``-b`` implies ``-d`` (so that
372372
the top image stays valid).
373373

374+
The rate limit for the commit process is specified by ``-r``.
375+
374376
.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2
375377

376378
Check if two images have the same content. You can compare images with

qemu-img-cmds.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ SRST
3434
ERST
3535

3636
DEF("commit", img_commit,
37-
"commit [--object objectdef] [--image-opts] [-q] [-f fmt] [-t cache] [-b base] [-d] [-p] filename")
37+
"commit [--object objectdef] [--image-opts] [-q] [-f fmt] [-t cache] [-b base] [-r rate_limit] [-d] [-p] filename")
3838
SRST
39-
.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-d] [-p] FILENAME
39+
.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-r RATE_LIMIT] [-d] [-p] FILENAME
4040
ERST
4141

4242
DEF("compare", img_compare,

qemu-img.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ static int img_commit(int argc, char **argv)
980980
CommonBlockJobCBInfo cbi;
981981
bool image_opts = false;
982982
AioContext *aio_context;
983+
int64_t rate_limit = 0;
983984

984985
fmt = NULL;
985986
cache = BDRV_DEFAULT_CACHE;
@@ -991,7 +992,7 @@ static int img_commit(int argc, char **argv)
991992
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
992993
{0, 0, 0, 0}
993994
};
994-
c = getopt_long(argc, argv, ":f:ht:b:dpq",
995+
c = getopt_long(argc, argv, ":f:ht:b:dpqr:",
995996
long_options, NULL);
996997
if (c == -1) {
997998
break;
@@ -1026,6 +1027,12 @@ static int img_commit(int argc, char **argv)
10261027
case 'q':
10271028
quiet = true;
10281029
break;
1030+
case 'r':
1031+
rate_limit = cvtnum("rate limit", optarg);
1032+
if (rate_limit < 0) {
1033+
return 1;
1034+
}
1035+
break;
10291036
case OPTION_OBJECT: {
10301037
QemuOpts *opts;
10311038
opts = qemu_opts_parse_noisily(&qemu_object_opts,
@@ -1099,7 +1106,7 @@ static int img_commit(int argc, char **argv)
10991106

11001107
aio_context = bdrv_get_aio_context(bs);
11011108
aio_context_acquire(aio_context);
1102-
commit_active_start("commit", bs, base_bs, JOB_DEFAULT, 0,
1109+
commit_active_start("commit", bs, base_bs, JOB_DEFAULT, rate_limit,
11031110
BLOCKDEV_ON_ERROR_REPORT, NULL, common_block_job_cb,
11041111
&cbi, false, &local_err);
11051112
aio_context_release(aio_context);

0 commit comments

Comments
 (0)