[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v7 17/39] block/throttle-groups: Make incref/decref
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v7 17/39] block/throttle-groups: Make incref/decref public |
Date: |
Mon, 19 Oct 2015 17:53:23 +0200 |
Throttle groups are not necessarily referenced by BDSs alone; a later
patch will essentially allow BBs to reference them, too. Make the
ref/unref functions public so that reference can be properly accounted
for.
Their interface is slightly adjusted in that they return and take a
ThrottleState pointer, respectively, instead of a ThrottleGroup pointer.
Functionally, they are equivalent, but since ThrottleGroup is not meant
to be used outside of block/throttle-groups.c, ThrottleState is easier
to handle.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
---
block/throttle-groups.c | 19 +++++++++++--------
include/block/throttle-groups.h | 3 +++
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index 1abc6fc..20cb216 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -76,9 +76,9 @@ static QTAILQ_HEAD(, ThrottleGroup) throttle_groups =
* created.
*
* @name: the name of the ThrottleGroup
- * @ret: the ThrottleGroup
+ * @ret: the ThrottleState member of the ThrottleGroup
*/
-static ThrottleGroup *throttle_group_incref(const char *name)
+ThrottleState *throttle_group_incref(const char *name)
{
ThrottleGroup *tg = NULL;
ThrottleGroup *iter;
@@ -108,7 +108,7 @@ static ThrottleGroup *throttle_group_incref(const char
*name)
qemu_mutex_unlock(&throttle_groups_lock);
- return tg;
+ return &tg->ts;
}
/* Decrease the reference count of a ThrottleGroup.
@@ -116,10 +116,12 @@ static ThrottleGroup *throttle_group_incref(const char
*name)
* When the reference count reaches zero the ThrottleGroup is
* destroyed.
*
- * @tg: The ThrottleGroup to unref
+ * @ts: The ThrottleGroup to unref, given by its ThrottleState member
*/
-static void throttle_group_unref(ThrottleGroup *tg)
+void throttle_group_unref(ThrottleState *ts)
{
+ ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
+
qemu_mutex_lock(&throttle_groups_lock);
if (--tg->refcount == 0) {
QTAILQ_REMOVE(&throttle_groups, tg, list);
@@ -401,7 +403,8 @@ static void write_timer_cb(void *opaque)
void throttle_group_register_bs(BlockDriverState *bs, const char *groupname)
{
int i;
- ThrottleGroup *tg = throttle_group_incref(groupname);
+ ThrottleState *ts = throttle_group_incref(groupname);
+ ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
int clock_type = QEMU_CLOCK_REALTIME;
if (qtest_enabled()) {
@@ -409,7 +412,7 @@ void throttle_group_register_bs(BlockDriverState *bs, const
char *groupname)
clock_type = QEMU_CLOCK_VIRTUAL;
}
- bs->throttle_state = &tg->ts;
+ bs->throttle_state = ts;
qemu_mutex_lock(&tg->lock);
/* If the ThrottleGroup is new set this BlockDriverState as the token */
@@ -461,7 +464,7 @@ void throttle_group_unregister_bs(BlockDriverState *bs)
throttle_timers_destroy(&bs->throttle_timers);
qemu_mutex_unlock(&tg->lock);
- throttle_group_unref(tg);
+ throttle_group_unref(&tg->ts);
bs->throttle_state = NULL;
}
diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h
index fab113f..f3b75b3 100644
--- a/include/block/throttle-groups.h
+++ b/include/block/throttle-groups.h
@@ -30,6 +30,9 @@
const char *throttle_group_get_name(BlockDriverState *bs);
+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);
--
2.6.1
- [Qemu-block] [PATCH v7 07/39] block: Make bdrv_is_inserted() recursive, (continued)
- [Qemu-block] [PATCH v7 07/39] block: Make bdrv_is_inserted() recursive, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 06/39] block: Add blk_is_available(), Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 08/39] block/raw_bsd: Drop raw_is_inserted(), Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 09/39] block: Invoke change media CB before NULLing drv, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 10/39] hw/block/fdc: Implement tray status, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 12/39] block: Fix BB AIOCB AioContext without BDS, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 11/39] hw/usb-storage: Check whether BB is inserted, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 14/39] block: Remove wr_highest_sector from BlockAcctStats, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 13/39] block: Move guest_block_size into BlockBackend, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 15/39] block: Move BlockAcctStats into BlockBackend, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 17/39] block/throttle-groups: Make incref/decref public,
Max Reitz <=
- [Qemu-block] [PATCH v7 18/39] block: Add BlockBackendRootState, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 16/39] block: Move I/O status and error actions into BB, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 19/39] block: Make some BB functions fall back to BBRS, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 21/39] block: Prepare remaining BB functions for NULL BDS, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 20/39] block: Fail requests to empty BlockBackend, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 22/39] block: Add blk_insert_bs(), Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 23/39] block: Prepare for NULL BDS, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 24/39] blockdev: Do not create BDS for empty drive, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 25/39] blockdev: Pull out blockdev option extraction, Max Reitz, 2015/10/19
- [Qemu-block] [PATCH v7 26/39] blockdev: Allow more options for BB-less BDS tree, Max Reitz, 2015/10/19