]> git.proxmox.com Git - mirror_qemu.git/blame - include/block/throttle-groups.h
block: Mark drain related functions GRAPH_RDLOCK
[mirror_qemu.git] / include / block / throttle-groups.h
CommitLineData
2ff1f2e3
AG
1/*
2 * QEMU block throttling group infrastructure
3 *
4 * Copyright (C) Nodalink, EURL. 2014
5 * Copyright (C) Igalia, S.L. 2015
6 *
7 * Authors:
8 * BenoƮt Canet <benoit.canet@nodalink.com>
9 * Alberto Garcia <berto@igalia.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 or
14 * (at your option) version 3 of the License.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 */
24
25#ifndef THROTTLE_GROUPS_H
26#define THROTTLE_GROUPS_H
27
e2c1c34f 28#include "qemu/coroutine.h"
2ff1f2e3 29#include "qemu/throttle.h"
db1015e9 30#include "qom/object.h"
2ff1f2e3 31
022cdc9f
MP
32/* The ThrottleGroupMember structure indicates membership in a ThrottleGroup
33 * and holds related data.
34 */
35
36typedef struct ThrottleGroupMember {
c61791fc 37 AioContext *aio_context;
022cdc9f
MP
38 /* throttled_reqs_lock protects the CoQueues for throttled requests. */
39 CoMutex throttled_reqs_lock;
3b2337ef 40 CoQueue throttled_reqs[THROTTLE_MAX];
022cdc9f
MP
41
42 /* Nonzero if the I/O limits are currently being ignored; generally
43 * it is zero. Accessed with atomic operations.
44 */
45 unsigned int io_limits_disabled;
46
bc19a0a6
SH
47 /* Number of pending throttle_group_restart_queue_entry() coroutines.
48 * Accessed with atomic operations.
49 */
50 unsigned int restart_pending;
51
022cdc9f
MP
52 /* The following fields are protected by the ThrottleGroup lock.
53 * See the ThrottleGroup documentation for details.
54 * throttle_state tells us if I/O limits are configured. */
55 ThrottleState *throttle_state;
56 ThrottleTimers throttle_timers;
3b2337ef 57 unsigned pending_reqs[THROTTLE_MAX];
022cdc9f
MP
58 QLIST_ENTRY(ThrottleGroupMember) round_robin;
59
60} ThrottleGroupMember;
61
432d889e 62#define TYPE_THROTTLE_GROUP "throttle-group"
8063396b 63OBJECT_DECLARE_SIMPLE_TYPE(ThrottleGroup, THROTTLE_GROUP)
432d889e 64
022cdc9f 65const char *throttle_group_get_name(ThrottleGroupMember *tgm);
2ff1f2e3 66
973f2ddf
HR
67ThrottleState *throttle_group_incref(const char *name);
68void throttle_group_unref(ThrottleState *ts);
69
022cdc9f
MP
70void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
71void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);
2ff1f2e3 72
022cdc9f 73void throttle_group_register_tgm(ThrottleGroupMember *tgm,
c61791fc
MP
74 const char *groupname,
75 AioContext *ctx);
022cdc9f
MP
76void throttle_group_unregister_tgm(ThrottleGroupMember *tgm);
77void throttle_group_restart_tgm(ThrottleGroupMember *tgm);
2ff1f2e3 78
022cdc9f 79void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,
801625e6 80 int64_t bytes,
3b2337ef 81 ThrottleDirection direction);
c61791fc
MP
82void throttle_group_attach_aio_context(ThrottleGroupMember *tgm,
83 AioContext *new_context);
84void throttle_group_detach_aio_context(ThrottleGroupMember *tgm);
d8e7d87e
MP
85/*
86 * throttle_group_exists() must be called under the global
87 * mutex.
88 */
89bool throttle_group_exists(const char *name);
76f4afb4 90
2ff1f2e3 91#endif