QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] qemu-img: add support for rate limit in qemu-img commit
@ 2020-10-18  6:33 Zhengui li
  2020-10-19 11:13 ` Alberto Garcia
  0 siblings, 1 reply; 2+ messages in thread
From: Zhengui li @ 2020-10-18  6:33 UTC (permalink / raw)
  To: pbonzini, stefanha, mreitz, kwolf
  Cc: xieyingtai, lizhengui, qemu-devel, qemu-block

From: Zhengui <lizhengui@huawei.com>

Currently, there is no rate limit for qemu-img commit. This may
cause the task of qemu-img commit to consume all the bandwidth
of the storage. This will affect the IO performance of other processes
and virtual machines under shared storage. So we add support for
offline rate limit in qemu-img commit to get better quality of sevice.

Signed-off-by: Zhengui <lizhengui@huawei.com>
---
 qemu-img-cmds.hx |  4 ++--
 qemu-img.c       | 13 +++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index b89c019..ed55b76 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -34,9 +34,9 @@ SRST
 ERST
 
 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] [-s speed] [-d] [-p] filename")
 SRST
-.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-d] [-p] FILENAME
+.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-s SPEED] [-d] [-p] FILENAME
 ERST
 
 DEF("compare", img_compare,
diff --git a/qemu-img.c b/qemu-img.c
index 2103507..74e4d64 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 = false;
     AioContext *aio_context;
+    int64_t rate_limit = 0;
 
     fmt = NULL;
     cache = 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 = getopt_long(argc, argv, ":f:ht:b:dpq",
+        c = getopt_long(argc, argv, ":f:ht:b:dpqs:",
                         long_options, NULL);
         if (c == -1) {
             break;
@@ -1026,6 +1027,14 @@ static int img_commit(int argc, char **argv)
         case 'q':
             quiet = true;
             break;
+        case 's': {
+            unsigned long long sval;
+            if (qemu_strtou64(optarg, NULL, 10, &sval)) {
+                error_report("rate limit parse failed");
+                return 1;
+            }
+            rate_limit = (int64_t)sval * 1024 * 1024;
+        }   break;
         case OPTION_OBJECT: {
             QemuOpts *opts;
             opts = qemu_opts_parse_noisily(&qemu_object_opts,
@@ -1099,7 +1108,7 @@ static int img_commit(int argc, char **argv)
 
     aio_context = 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_cb,
                         &cbi, false, &local_err);
     aio_context_release(aio_context);
-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] qemu-img: add support for rate limit in qemu-img commit
  2020-10-18  6:33 [PATCH] qemu-img: add support for rate limit in qemu-img commit Zhengui li
@ 2020-10-19 11:13 ` Alberto Garcia
  0 siblings, 0 replies; 2+ messages in thread
From: Alberto Garcia @ 2020-10-19 11:13 UTC (permalink / raw)
  To: Zhengui li, pbonzini, stefanha, mreitz, kwolf
  Cc: xieyingtai, lizhengui, qemu-devel, qemu-block

On Sun 18 Oct 2020 08:33:59 AM CEST, Zhengui li wrote:

Hello,

> diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
> index b89c019..ed55b76 100644
> --- a/qemu-img-cmds.hx
> +++ b/qemu-img-cmds.hx
> @@ -34,9 +34,9 @@ SRST
>  ERST
>  
>  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] [-s speed] [-d] [-p] filename")
>  SRST
> -.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-d] [-p] FILENAME
> +.. option:: commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b BASE] [-s SPEED] [-d] [-p] FILENAME
>  ERST

You should also update docs/tools/qemu-img.rst and explain what the new
parameter does.

> +        case 's': {
> +            unsigned long long sval;
> +            if (qemu_strtou64(optarg, NULL, 10, &sval)) {
> +                error_report("rate limit parse failed");
> +                return 1;
> +            }

You are using 'unsigned long long' here but qemu_strtou64() takes a
uint64_t.

> +            rate_limit = (int64_t)sval * 1024 * 1024;
> +        }   break;

And then you multiply that value by 1024*1024, which can overflow.

So I understand that the value received by 'qemu-img' is in megabytes?
Is there a reason for using that and not bytes?

qemu-img.c provides cvtnum() and cvtnum_full() which allow the user to
specify the units.

Berto


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-18  6:33 [PATCH] qemu-img: add support for rate limit in qemu-img commit Zhengui li
2020-10-19 11:13 ` Alberto Garcia

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git