All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 07/31] block: Move I/O throttling configuration functions to BlockBackend
Date: Thu, 19 May 2016 17:21:45 +0200	[thread overview]
Message-ID: <1463671329-22655-8-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1463671329-22655-1-git-send-email-kwolf@redhat.com>

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c                         |  2 +-
 block/block-backend.c           | 43 +++++++++++++++++++++++++++++++++++++++--
 block/io.c                      | 41 ---------------------------------------
 block/qapi.c                    |  2 +-
 block/throttle-groups.c         | 12 ++++++------
 blockdev.c                      | 16 +++++++--------
 include/block/block.h           |  4 ----
 include/block/block_int.h       |  3 +--
 include/block/throttle-groups.h |  4 ++--
 include/sysemu/block-backend.h  |  5 +++++
 tests/test-throttle.c           | 16 ++++++---------
 11 files changed, 71 insertions(+), 77 deletions(-)

diff --git a/block.c b/block.c
index f723060..b5c02c4 100644
--- a/block.c
+++ b/block.c
@@ -2123,7 +2123,7 @@ static void bdrv_close(BlockDriverState *bs)
 
     /* Disable I/O limits and drain all pending throttled requests */
     if (bs->blk && blk_get_public(bs->blk)->throttle_state) {
-        bdrv_io_limits_disable(bs);
+        blk_io_limits_disable(bs->blk);
     }
 
     bdrv_drained_begin(bs); /* complete I/O */
diff --git a/block/block-backend.c b/block/block-backend.c
index 730b8a9..b9aaa60 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -442,7 +442,7 @@ void blk_remove_bs(BlockBackend *blk)
 
     blk_update_root_state(blk);
     if (blk->public.throttle_state) {
-        bdrv_io_limits_disable(blk->root->bs);
+        blk_io_limits_disable(blk);
     }
 
     blk->root->bs->blk = NULL;
@@ -1556,7 +1556,7 @@ void blk_apply_root_state(BlockBackend *blk, BlockDriverState *bs)
 {
     bs->detect_zeroes = blk->root_state.detect_zeroes;
     if (blk->root_state.throttle_group) {
-        bdrv_io_limits_enable(bs, blk->root_state.throttle_group);
+        blk_io_limits_enable(blk, blk->root_state.throttle_group);
     }
 }
 
@@ -1620,3 +1620,42 @@ int blk_flush_all(void)
 
     return result;
 }
+
+
+/* throttling disk I/O limits */
+void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg)
+{
+    throttle_group_config(blk, cfg);
+}
+
+void blk_io_limits_disable(BlockBackend *blk)
+{
+    assert(blk->public.throttle_state);
+    bdrv_no_throttling_begin(blk_bs(blk));
+    throttle_group_unregister_blk(blk);
+    bdrv_no_throttling_end(blk_bs(blk));
+}
+
+/* should be called before blk_set_io_limits if a limit is set */
+void blk_io_limits_enable(BlockBackend *blk, const char *group)
+{
+    assert(!blk->public.throttle_state);
+    throttle_group_register_blk(blk, group);
+}
+
+void blk_io_limits_update_group(BlockBackend *blk, const char *group)
+{
+    /* this BB is not part of any group */
+    if (!blk->public.throttle_state) {
+        return;
+    }
+
+    /* this BB is a part of the same group than the one we want */
+    if (!g_strcmp0(throttle_group_get_name(blk), group)) {
+        return;
+    }
+
+    /* need to change the group this bs belong to */
+    blk_io_limits_disable(blk);
+    blk_io_limits_enable(blk, group);
+}
diff --git a/block/io.c b/block/io.c
index cf2ac4c..1699f1e 100644
--- a/block/io.c
+++ b/block/io.c
@@ -46,13 +46,6 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque);
 static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
     int64_t sector_num, int nb_sectors, BdrvRequestFlags flags);
 
-/* throttling disk I/O limits */
-void bdrv_set_io_limits(BlockDriverState *bs,
-                        ThrottleConfig *cfg)
-{
-    throttle_group_config(bs, cfg);
-}
-
 void bdrv_no_throttling_begin(BlockDriverState *bs)
 {
     if (!bs->blk) {
@@ -77,40 +70,6 @@ void bdrv_no_throttling_end(BlockDriverState *bs)
     --blkp->io_limits_disabled;
 }
 
-void bdrv_io_limits_disable(BlockDriverState *bs)
-{
-    assert(blk_get_public(bs->blk)->throttle_state);
-    bdrv_no_throttling_begin(bs);
-    throttle_group_unregister_blk(bs->blk);
-    bdrv_no_throttling_end(bs);
-}
-
-/* should be called before bdrv_set_io_limits if a limit is set */
-void bdrv_io_limits_enable(BlockDriverState *bs, const char *group)
-{
-    BlockBackendPublic *blkp = blk_get_public(bs->blk);
-
-    assert(!blkp->throttle_state);
-    throttle_group_register_blk(bs->blk, group);
-}
-
-void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group)
-{
-    /* this bs is not part of any group */
-    if (!blk_get_public(bs->blk)->throttle_state) {
-        return;
-    }
-
-    /* this bs is a part of the same group than the one we want */
-    if (!g_strcmp0(throttle_group_get_name(bs->blk), group)) {
-        return;
-    }
-
-    /* need to change the group this bs belong to */
-    bdrv_io_limits_disable(bs);
-    bdrv_io_limits_enable(bs, group);
-}
-
 void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
 {
     BlockDriver *drv = bs->drv;
diff --git a/block/qapi.c b/block/qapi.c
index 1e4bb8a..b0d8d6b 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -70,7 +70,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
     if (bs->blk && blk_get_public(bs->blk)->throttle_state) {
         ThrottleConfig cfg;
 
-        throttle_group_get_config(bs, &cfg);
+        throttle_group_get_config(bs->blk, &cfg);
 
         info->bps     = cfg.buckets[THROTTLE_BPS_TOTAL].avg;
         info->bps_rd  = cfg.buckets[THROTTLE_BPS_READ].avg;
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index 3db8cf7..59545e2 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -337,12 +337,12 @@ void throttle_group_restart_blk(BlockBackend *blk)
  * to throttle_config(), but guarantees atomicity within the
  * throttling group.
  *
- * @bs:  a BlockDriverState that is member of the group
+ * @blk: a BlockBackend that is a member of the group
  * @cfg: the configuration to set
  */
-void throttle_group_config(BlockDriverState *bs, ThrottleConfig *cfg)
+void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg)
 {
-    BlockBackendPublic *blkp = blk_get_public(bs->blk);
+    BlockBackendPublic *blkp = blk_get_public(blk);
     ThrottleTimers *tt = &blkp->throttle_timers;
     ThrottleState *ts = blkp->throttle_state;
     ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
@@ -365,12 +365,12 @@ void throttle_group_config(BlockDriverState *bs, ThrottleConfig *cfg)
  * throttle_get_config(), but guarantees atomicity within the
  * throttling group.
  *
- * @bs:  a BlockDriverState that is member of the group
+ * @blk: a BlockBackend that is a member of the group
  * @cfg: the configuration will be written here
  */
-void throttle_group_get_config(BlockDriverState *bs, ThrottleConfig *cfg)
+void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg)
 {
-    BlockBackendPublic *blkp = blk_get_public(bs->blk);
+    BlockBackendPublic *blkp = blk_get_public(blk);
     ThrottleState *ts = blkp->throttle_state;
     ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
     qemu_mutex_lock(&tg->lock);
diff --git a/blockdev.c b/blockdev.c
index 3211a40..89768ab 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -616,8 +616,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
             if (!throttling_group) {
                 throttling_group = blk_name(blk);
             }
-            bdrv_io_limits_enable(bs, throttling_group);
-            bdrv_set_io_limits(bs, &cfg);
+            blk_io_limits_enable(blk, throttling_group);
+            blk_set_io_limits(blk, &cfg);
         }
 
         if (bdrv_key_required(bs)) {
@@ -2726,16 +2726,16 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
     if (throttle_enabled(&cfg)) {
         /* Enable I/O limits if they're not enabled yet, otherwise
          * just update the throttling group. */
-        if (!blk_get_public(bs->blk)->throttle_state) {
-            bdrv_io_limits_enable(bs, has_group ? group : device);
+        if (!blk_get_public(blk)->throttle_state) {
+            blk_io_limits_enable(blk, has_group ? group : device);
         } else if (has_group) {
-            bdrv_io_limits_update_group(bs, group);
+            blk_io_limits_update_group(blk, group);
         }
         /* Set the new throttling configuration */
-        bdrv_set_io_limits(bs, &cfg);
-    } else if (blk_get_public(bs->blk)->throttle_state) {
+        blk_set_io_limits(blk, &cfg);
+    } else if (blk_get_public(blk)->throttle_state) {
         /* If all throttling settings are set to 0, disable I/O limits */
-        bdrv_io_limits_disable(bs);
+        blk_io_limits_disable(blk);
     }
 
 out:
diff --git a/include/block/block.h b/include/block/block.h
index b210832..2c5c280 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -187,10 +187,6 @@ void bdrv_stats_print(Monitor *mon, const QObject *data);
 void bdrv_info_stats(Monitor *mon, QObject **ret_data);
 
 /* disk I/O throttling */
-void bdrv_io_limits_enable(BlockDriverState *bs, const char *group);
-void bdrv_io_limits_disable(BlockDriverState *bs);
-void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group);
-
 void bdrv_init(void);
 void bdrv_init_with_whitelist(void);
 bool bdrv_uses_whitelist(void);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 2bbc2c0..1218857 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -525,8 +525,7 @@ int get_tmp_filename(char *filename, int size);
 BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,
                             const char *filename);
 
-void bdrv_set_io_limits(BlockDriverState *bs,
-                        ThrottleConfig *cfg);
+bool bdrv_start_throttled_reqs(BlockDriverState *bs);
 
 
 /**
diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h
index ac42248..d983d34 100644
--- a/include/block/throttle-groups.h
+++ b/include/block/throttle-groups.h
@@ -33,8 +33,8 @@ const char *throttle_group_get_name(BlockBackend *blk);
 ThrottleState *throttle_group_incref(const char *name);
 void throttle_group_unref(ThrottleState *ts);
 
-void throttle_group_config(BlockDriverState *bs, ThrottleConfig *cfg);
-void throttle_group_get_config(BlockDriverState *bs, ThrottleConfig *cfg);
+void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg);
+void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg);
 
 void throttle_group_register_blk(BlockBackend *blk, const char *groupname);
 void throttle_group_unregister_blk(BlockBackend *blk);
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 08d27a8..dd9c8ca 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -212,4 +212,9 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
                                   BlockCompletionFunc *cb,
                                   void *opaque, int ret);
 
+void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg);
+void blk_io_limits_disable(BlockBackend *blk);
+void blk_io_limits_enable(BlockBackend *blk, const char *group);
+void blk_io_limits_update_group(BlockBackend *blk, const char *group);
+
 #endif
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
index a020068..5ec966c 100644
--- a/tests/test-throttle.c
+++ b/tests/test-throttle.c
@@ -577,15 +577,11 @@ static void test_groups(void)
     ThrottleConfig cfg1, cfg2;
     BlockBackend *blk1, *blk2, *blk3;
     BlockBackendPublic *blkp1, *blkp2, *blkp3;
-    BlockDriverState *bdrv1, *bdrv3;
 
     blk1 = blk_new_with_bs(&error_abort);
     blk2 = blk_new_with_bs(&error_abort);
     blk3 = blk_new_with_bs(&error_abort);
 
-    bdrv1 = blk_bs(blk1);
-    bdrv3 = blk_bs(blk3);
-
     blkp1 = blk_get_public(blk1);
     blkp2 = blk_get_public(blk2);
     blkp3 = blk_get_public(blk3);
@@ -612,20 +608,20 @@ static void test_groups(void)
     cfg1.buckets[THROTTLE_BPS_WRITE].avg = 285000;
     cfg1.buckets[THROTTLE_OPS_READ].avg  = 20000;
     cfg1.buckets[THROTTLE_OPS_WRITE].avg = 12000;
-    throttle_group_config(bdrv1, &cfg1);
+    throttle_group_config(blk1, &cfg1);
 
-    throttle_group_get_config(bdrv1, &cfg1);
-    throttle_group_get_config(bdrv3, &cfg2);
+    throttle_group_get_config(blk1, &cfg1);
+    throttle_group_get_config(blk3, &cfg2);
     g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1)));
 
     cfg2.buckets[THROTTLE_BPS_READ].avg  = 4547;
     cfg2.buckets[THROTTLE_BPS_WRITE].avg = 1349;
     cfg2.buckets[THROTTLE_OPS_READ].avg  = 123;
     cfg2.buckets[THROTTLE_OPS_WRITE].avg = 86;
-    throttle_group_config(bdrv3, &cfg1);
+    throttle_group_config(blk3, &cfg1);
 
-    throttle_group_get_config(bdrv1, &cfg1);
-    throttle_group_get_config(bdrv3, &cfg2);
+    throttle_group_get_config(blk1, &cfg1);
+    throttle_group_get_config(blk3, &cfg2);
     g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1)));
 
     throttle_group_unregister_blk(blk1);
-- 
1.8.3.1

  parent reply	other threads:[~2016-05-19 15:22 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-19 15:21 [Qemu-devel] [PULL 00/31] Block layer patches Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 01/31] block: Make sure throttled BDSes always have a BB Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 02/31] block: Introduce BlockBackendPublic Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 03/31] block: throttle-groups: Use BlockBackend pointers internally Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 04/31] block: Convert throttle_group_get_name() to BlockBackend Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 05/31] block: Move throttling fields from BDS to BB Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 06/31] block: Move actual I/O throttling to BlockBackend Kevin Wolf
2016-05-19 15:21 ` Kevin Wolf [this message]
2016-05-19 15:21 ` [Qemu-devel] [PULL 08/31] block: Introduce BdrvChild.opaque Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 09/31] block: Drain throttling queue with BdrvChild callback Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 10/31] block/io: Quiesce parents between drained_begin/end Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 11/31] block: Decouple throttling from BlockDriverState Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 12/31] block: Remove bdrv_move_feature_fields() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 13/31] Revert "block: Forbid I/O throttling on nodes with multiple parents for 2.6" Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 14/31] block: Don't check throttled reqs in bdrv_requests_pending() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 15/31] block: Use BdrvChild callbacks for change_media/resize Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 16/31] block: User BdrvChild callback for device name Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 17/31] blockjob: Don't set iostatus of target Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 18/31] blockjob: Don't touch BDS iostatus Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 19/31] block: Remove bdrv_aio_multiwrite() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 20/31] block: Add bdrv_has_blk() Kevin Wolf
2016-05-19 15:21 ` [Qemu-devel] [PULL 21/31] block: Avoid bs->blk in bdrv_next() Kevin Wolf
2016-05-20  7:54   ` Paolo Bonzini
2016-05-20  8:05     ` Kevin Wolf
2016-05-20  8:10       ` Kevin Wolf
2016-05-20  9:39         ` Paolo Bonzini
2016-05-20 10:26           ` Kevin Wolf
2016-05-20 10:46             ` Paolo Bonzini
2016-05-19 15:22 ` [Qemu-devel] [PULL 22/31] block: Don't return throttling info in query-named-block-nodes Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 23/31] block: Remove BlockDriverState.blk Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 24/31] block: Propagate AioContext change to all children Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 25/31] qcow2: fix condition in is_zero_cluster Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 26/31] qcow2: Fix write_zeroes with partially allocated backing file cluster Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 27/31] qemu-iotests: Some more write_zeroes tests Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 28/31] block: clarify error message for qmp-eject Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 29/31] qemu-io: Fix recent UI updates Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 30/31] qemu-iotests: Simplify 109 with unaligned qemu-img compare Kevin Wolf
2016-05-19 15:22 ` [Qemu-devel] [PULL 31/31] qemu-iotests: Fix regression in 136 on aio_read invalid Kevin Wolf
2016-05-19 16:40 ` [Qemu-devel] [PULL 00/31] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463671329-22655-8-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.