1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include "sysemu/block-backend.h"
27#include "block/throttle-groups.h"
28#include "qemu/throttle-options.h"
29#include "qemu/main-loop.h"
30#include "qemu/queue.h"
31#include "qemu/thread.h"
32#include "sysemu/qtest.h"
33#include "qapi/error.h"
34#include "qapi/qapi-visit-block-core.h"
35#include "qom/object.h"
36#include "qom/object_interfaces.h"
37
38static void throttle_group_obj_init(Object *obj);
39static void throttle_group_obj_complete(UserCreatable *obj, Error **errp);
40static void timer_cb(ThrottleGroupMember *tgm, bool is_write);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66struct ThrottleGroup {
67 Object parent_obj;
68
69
70 bool is_initialized;
71 char *name;
72
73 QemuMutex lock;
74 ThrottleState ts;
75 QLIST_HEAD(, ThrottleGroupMember) head;
76 ThrottleGroupMember *tokens[2];
77 bool any_timer_armed[2];
78 QEMUClockType clock_type;
79
80
81 QTAILQ_ENTRY(ThrottleGroup) list;
82};
83
84
85static QTAILQ_HEAD(, ThrottleGroup) throttle_groups =
86 QTAILQ_HEAD_INITIALIZER(throttle_groups);
87
88
89
90
91
92static ThrottleGroup *throttle_group_by_name(const char *name)
93{
94 ThrottleGroup *iter;
95
96
97 QTAILQ_FOREACH(iter, &throttle_groups, list) {
98 if (!g_strcmp0(name, iter->name)) {
99 return iter;
100 }
101 }
102
103 return NULL;
104}
105
106
107
108
109bool throttle_group_exists(const char *name)
110{
111 return throttle_group_by_name(name) != NULL;
112}
113
114
115
116
117
118
119
120
121
122
123
124
125ThrottleState *throttle_group_incref(const char *name)
126{
127 ThrottleGroup *tg = NULL;
128
129
130 tg = throttle_group_by_name(name);
131
132 if (tg) {
133 object_ref(OBJECT(tg));
134 } else {
135
136
137 tg = THROTTLE_GROUP(object_new(TYPE_THROTTLE_GROUP));
138 tg->name = g_strdup(name);
139 throttle_group_obj_complete(USER_CREATABLE(tg), &error_abort);
140 }
141
142 return &tg->ts;
143}
144
145
146
147
148
149
150
151
152
153
154
155void throttle_group_unref(ThrottleState *ts)
156{
157 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
158 object_unref(OBJECT(tg));
159}
160
161
162
163
164
165
166
167const char *throttle_group_get_name(ThrottleGroupMember *tgm)
168{
169 ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts);
170 return tg->name;
171}
172
173
174
175
176
177
178
179
180
181static ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *tgm)
182{
183 ThrottleState *ts = tgm->throttle_state;
184 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
185 ThrottleGroupMember *next = QLIST_NEXT(tgm, round_robin);
186
187 if (!next) {
188 next = QLIST_FIRST(&tg->head);
189 }
190
191 return next;
192}
193
194
195
196
197
198
199
200
201
202
203static inline bool tgm_has_pending_reqs(ThrottleGroupMember *tgm,
204 bool is_write)
205{
206 return tgm->pending_reqs[is_write];
207}
208
209
210
211
212
213
214
215
216
217
218
219static ThrottleGroupMember *next_throttle_token(ThrottleGroupMember *tgm,
220 bool is_write)
221{
222 ThrottleState *ts = tgm->throttle_state;
223 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
224 ThrottleGroupMember *token, *start;
225
226
227
228
229
230 if (tgm_has_pending_reqs(tgm, is_write) &&
231 qatomic_read(&tgm->io_limits_disabled)) {
232 return tgm;
233 }
234
235 start = token = tg->tokens[is_write];
236
237
238 token = throttle_group_next_tgm(token);
239 while (token != start && !tgm_has_pending_reqs(token, is_write)) {
240 token = throttle_group_next_tgm(token);
241 }
242
243
244
245
246
247 if (token == start && !tgm_has_pending_reqs(token, is_write)) {
248 token = tgm;
249 }
250
251
252 assert(token == tgm || tgm_has_pending_reqs(token, is_write));
253
254 return token;
255}
256
257
258
259
260
261
262
263
264
265
266
267static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm,
268 bool is_write)
269{
270 ThrottleState *ts = tgm->throttle_state;
271 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
272 ThrottleTimers *tt = &tgm->throttle_timers;
273 bool must_wait;
274
275 if (qatomic_read(&tgm->io_limits_disabled)) {
276 return false;
277 }
278
279
280 if (tg->any_timer_armed[is_write]) {
281 return true;
282 }
283
284 must_wait = throttle_schedule_timer(ts, tt, is_write);
285
286
287 if (must_wait) {
288 tg->tokens[is_write] = tgm;
289 tg->any_timer_armed[is_write] = true;
290 }
291
292 return must_wait;
293}
294
295
296
297
298
299
300
301static bool coroutine_fn throttle_group_co_restart_queue(ThrottleGroupMember *tgm,
302 bool is_write)
303{
304 bool ret;
305
306 qemu_co_mutex_lock(&tgm->throttled_reqs_lock);
307 ret = qemu_co_queue_next(&tgm->throttled_reqs[is_write]);
308 qemu_co_mutex_unlock(&tgm->throttled_reqs_lock);
309
310 return ret;
311}
312
313
314
315
316
317
318
319
320static void schedule_next_request(ThrottleGroupMember *tgm, bool is_write)
321{
322 ThrottleState *ts = tgm->throttle_state;
323 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
324 bool must_wait;
325 ThrottleGroupMember *token;
326
327
328 token = next_throttle_token(tgm, is_write);
329 if (!tgm_has_pending_reqs(token, is_write)) {
330 return;
331 }
332
333
334 must_wait = throttle_group_schedule_timer(token, is_write);
335
336
337 if (!must_wait) {
338
339 if (qemu_in_coroutine() &&
340 throttle_group_co_restart_queue(tgm, is_write)) {
341 token = tgm;
342 } else {
343 ThrottleTimers *tt = &token->throttle_timers;
344 int64_t now = qemu_clock_get_ns(tg->clock_type);
345 timer_mod(tt->timers[is_write], now);
346 tg->any_timer_armed[is_write] = true;
347 }
348 tg->tokens[is_write] = token;
349 }
350}
351
352
353
354
355
356
357
358
359
360void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,
361 int64_t bytes,
362 bool is_write)
363{
364 bool must_wait;
365 ThrottleGroupMember *token;
366 ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts);
367
368 assert(bytes >= 0);
369
370 qemu_mutex_lock(&tg->lock);
371
372
373 token = next_throttle_token(tgm, is_write);
374 must_wait = throttle_group_schedule_timer(token, is_write);
375
376
377 if (must_wait || tgm->pending_reqs[is_write]) {
378 tgm->pending_reqs[is_write]++;
379 qemu_mutex_unlock(&tg->lock);
380 qemu_co_mutex_lock(&tgm->throttled_reqs_lock);
381 qemu_co_queue_wait(&tgm->throttled_reqs[is_write],
382 &tgm->throttled_reqs_lock);
383 qemu_co_mutex_unlock(&tgm->throttled_reqs_lock);
384 qemu_mutex_lock(&tg->lock);
385 tgm->pending_reqs[is_write]--;
386 }
387
388
389 throttle_account(tgm->throttle_state, is_write, bytes);
390
391
392 schedule_next_request(tgm, is_write);
393
394 qemu_mutex_unlock(&tg->lock);
395}
396
397typedef struct {
398 ThrottleGroupMember *tgm;
399 bool is_write;
400} RestartData;
401
402static void coroutine_fn throttle_group_restart_queue_entry(void *opaque)
403{
404 RestartData *data = opaque;
405 ThrottleGroupMember *tgm = data->tgm;
406 ThrottleState *ts = tgm->throttle_state;
407 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
408 bool is_write = data->is_write;
409 bool empty_queue;
410
411 empty_queue = !throttle_group_co_restart_queue(tgm, is_write);
412
413
414
415 if (empty_queue) {
416 qemu_mutex_lock(&tg->lock);
417 schedule_next_request(tgm, is_write);
418 qemu_mutex_unlock(&tg->lock);
419 }
420
421 g_free(data);
422
423 qatomic_dec(&tgm->restart_pending);
424 aio_wait_kick();
425}
426
427static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write)
428{
429 Coroutine *co;
430 RestartData *rd = g_new0(RestartData, 1);
431
432 rd->tgm = tgm;
433 rd->is_write = is_write;
434
435
436
437
438 assert(!timer_pending(tgm->throttle_timers.timers[is_write]));
439
440 qatomic_inc(&tgm->restart_pending);
441
442 co = qemu_coroutine_create(throttle_group_restart_queue_entry, rd);
443 aio_co_enter(tgm->aio_context, co);
444}
445
446void throttle_group_restart_tgm(ThrottleGroupMember *tgm)
447{
448 int i;
449
450 if (tgm->throttle_state) {
451 for (i = 0; i < 2; i++) {
452 QEMUTimer *t = tgm->throttle_timers.timers[i];
453 if (timer_pending(t)) {
454
455 timer_del(t);
456 timer_cb(tgm, i);
457 } else {
458
459 throttle_group_restart_queue(tgm, i);
460 }
461 }
462 }
463}
464
465
466
467
468
469
470
471
472void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg)
473{
474 ThrottleState *ts = tgm->throttle_state;
475 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
476 qemu_mutex_lock(&tg->lock);
477 throttle_config(ts, tg->clock_type, cfg);
478 qemu_mutex_unlock(&tg->lock);
479
480 throttle_group_restart_tgm(tgm);
481}
482
483
484
485
486
487
488
489
490void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg)
491{
492 ThrottleState *ts = tgm->throttle_state;
493 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
494 qemu_mutex_lock(&tg->lock);
495 throttle_get_config(ts, cfg);
496 qemu_mutex_unlock(&tg->lock);
497}
498
499
500
501
502
503
504
505static void timer_cb(ThrottleGroupMember *tgm, bool is_write)
506{
507 ThrottleState *ts = tgm->throttle_state;
508 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
509
510
511 qemu_mutex_lock(&tg->lock);
512 tg->any_timer_armed[is_write] = false;
513 qemu_mutex_unlock(&tg->lock);
514
515
516 throttle_group_restart_queue(tgm, is_write);
517}
518
519static void read_timer_cb(void *opaque)
520{
521 timer_cb(opaque, false);
522}
523
524static void write_timer_cb(void *opaque)
525{
526 timer_cb(opaque, true);
527}
528
529
530
531
532
533
534
535
536
537
538
539
540void throttle_group_register_tgm(ThrottleGroupMember *tgm,
541 const char *groupname,
542 AioContext *ctx)
543{
544 int i;
545 ThrottleState *ts = throttle_group_incref(groupname);
546 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
547
548 tgm->throttle_state = ts;
549 tgm->aio_context = ctx;
550 qatomic_set(&tgm->restart_pending, 0);
551
552 QEMU_LOCK_GUARD(&tg->lock);
553
554 for (i = 0; i < 2; i++) {
555 if (!tg->tokens[i]) {
556 tg->tokens[i] = tgm;
557 }
558 }
559
560 QLIST_INSERT_HEAD(&tg->head, tgm, round_robin);
561
562 throttle_timers_init(&tgm->throttle_timers,
563 tgm->aio_context,
564 tg->clock_type,
565 read_timer_cb,
566 write_timer_cb,
567 tgm);
568 qemu_co_mutex_init(&tgm->throttled_reqs_lock);
569 qemu_co_queue_init(&tgm->throttled_reqs[0]);
570 qemu_co_queue_init(&tgm->throttled_reqs[1]);
571}
572
573
574
575
576
577
578
579
580
581
582
583void throttle_group_unregister_tgm(ThrottleGroupMember *tgm)
584{
585 ThrottleState *ts = tgm->throttle_state;
586 ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
587 ThrottleGroupMember *token;
588 int i;
589
590 if (!ts) {
591
592 return;
593 }
594
595
596 AIO_WAIT_WHILE(tgm->aio_context, qatomic_read(&tgm->restart_pending) > 0);
597
598 WITH_QEMU_LOCK_GUARD(&tg->lock) {
599 for (i = 0; i < 2; i++) {
600 assert(tgm->pending_reqs[i] == 0);
601 assert(qemu_co_queue_empty(&tgm->throttled_reqs[i]));
602 assert(!timer_pending(tgm->throttle_timers.timers[i]));
603 if (tg->tokens[i] == tgm) {
604 token = throttle_group_next_tgm(tgm);
605
606 if (token == tgm) {
607 token = NULL;
608 }
609 tg->tokens[i] = token;
610 }
611 }
612
613
614 QLIST_REMOVE(tgm, round_robin);
615 throttle_timers_destroy(&tgm->throttle_timers);
616 }
617
618 throttle_group_unref(&tg->ts);
619 tgm->throttle_state = NULL;
620}
621
622void throttle_group_attach_aio_context(ThrottleGroupMember *tgm,
623 AioContext *new_context)
624{
625 ThrottleTimers *tt = &tgm->throttle_timers;
626 throttle_timers_attach_aio_context(tt, new_context);
627 tgm->aio_context = new_context;
628}
629
630void throttle_group_detach_aio_context(ThrottleGroupMember *tgm)
631{
632 ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts);
633 ThrottleTimers *tt = &tgm->throttle_timers;
634 int i;
635
636
637 assert(tgm->pending_reqs[0] == 0 && tgm->pending_reqs[1] == 0);
638 assert(qemu_co_queue_empty(&tgm->throttled_reqs[0]));
639 assert(qemu_co_queue_empty(&tgm->throttled_reqs[1]));
640
641
642 WITH_QEMU_LOCK_GUARD(&tg->lock) {
643 for (i = 0; i < 2; i++) {
644 if (timer_pending(tt->timers[i])) {
645 tg->any_timer_armed[i] = false;
646 schedule_next_request(tgm, i);
647 }
648 }
649 }
650
651 throttle_timers_detach_aio_context(tt);
652 tgm->aio_context = NULL;
653}
654
655#undef THROTTLE_OPT_PREFIX
656#define THROTTLE_OPT_PREFIX "x-"
657
658
659typedef struct {
660 const char *name;
661 BucketType type;
662 enum {
663 AVG,
664 MAX,
665 BURST_LENGTH,
666 IOPS_SIZE,
667 } category;
668} ThrottleParamInfo;
669
670static ThrottleParamInfo properties[] = {
671 {
672 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL,
673 THROTTLE_OPS_TOTAL, AVG,
674 },
675 {
676 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX,
677 THROTTLE_OPS_TOTAL, MAX,
678 },
679 {
680 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX_LENGTH,
681 THROTTLE_OPS_TOTAL, BURST_LENGTH,
682 },
683 {
684 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ,
685 THROTTLE_OPS_READ, AVG,
686 },
687 {
688 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX,
689 THROTTLE_OPS_READ, MAX,
690 },
691 {
692 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX_LENGTH,
693 THROTTLE_OPS_READ, BURST_LENGTH,
694 },
695 {
696 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE,
697 THROTTLE_OPS_WRITE, AVG,
698 },
699 {
700 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX,
701 THROTTLE_OPS_WRITE, MAX,
702 },
703 {
704 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX_LENGTH,
705 THROTTLE_OPS_WRITE, BURST_LENGTH,
706 },
707 {
708 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL,
709 THROTTLE_BPS_TOTAL, AVG,
710 },
711 {
712 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX,
713 THROTTLE_BPS_TOTAL, MAX,
714 },
715 {
716 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX_LENGTH,
717 THROTTLE_BPS_TOTAL, BURST_LENGTH,
718 },
719 {
720 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ,
721 THROTTLE_BPS_READ, AVG,
722 },
723 {
724 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX,
725 THROTTLE_BPS_READ, MAX,
726 },
727 {
728 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX_LENGTH,
729 THROTTLE_BPS_READ, BURST_LENGTH,
730 },
731 {
732 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE,
733 THROTTLE_BPS_WRITE, AVG,
734 },
735 {
736 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX,
737 THROTTLE_BPS_WRITE, MAX,
738 },
739 {
740 THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX_LENGTH,
741 THROTTLE_BPS_WRITE, BURST_LENGTH,
742 },
743 {
744 THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_SIZE,
745 0, IOPS_SIZE,
746 }
747};
748
749
750
751static void throttle_group_obj_init(Object *obj)
752{
753 ThrottleGroup *tg = THROTTLE_GROUP(obj);
754
755 tg->clock_type = QEMU_CLOCK_REALTIME;
756 if (qtest_enabled()) {
757
758 tg->clock_type = QEMU_CLOCK_VIRTUAL;
759 }
760 tg->is_initialized = false;
761 qemu_mutex_init(&tg->lock);
762 throttle_init(&tg->ts);
763 QLIST_INIT(&tg->head);
764}
765
766
767
768static void throttle_group_obj_complete(UserCreatable *obj, Error **errp)
769{
770 ThrottleGroup *tg = THROTTLE_GROUP(obj);
771 ThrottleConfig cfg;
772
773
774 if (!tg->name && tg->parent_obj.parent) {
775 tg->name = g_strdup(object_get_canonical_path_component(OBJECT(obj)));
776 }
777
778 assert(tg->name);
779
780
781 if (throttle_group_exists(tg->name)) {
782 error_setg(errp, "A group with this name already exists");
783 return;
784 }
785
786
787 throttle_get_config(&tg->ts, &cfg);
788 if (!throttle_is_valid(&cfg, errp)) {
789 return;
790 }
791 throttle_config(&tg->ts, tg->clock_type, &cfg);
792 QTAILQ_INSERT_TAIL(&throttle_groups, tg, list);
793 tg->is_initialized = true;
794}
795
796
797
798static void throttle_group_obj_finalize(Object *obj)
799{
800 ThrottleGroup *tg = THROTTLE_GROUP(obj);
801 if (tg->is_initialized) {
802 QTAILQ_REMOVE(&throttle_groups, tg, list);
803 }
804 qemu_mutex_destroy(&tg->lock);
805 g_free(tg->name);
806}
807
808static void throttle_group_set(Object *obj, Visitor *v, const char * name,
809 void *opaque, Error **errp)
810
811{
812 ThrottleGroup *tg = THROTTLE_GROUP(obj);
813 ThrottleConfig *cfg;
814 ThrottleParamInfo *info = opaque;
815 int64_t value;
816
817
818
819
820
821 if (tg->is_initialized) {
822 error_setg(errp, "Property cannot be set after initialization");
823 return;
824 }
825
826 if (!visit_type_int64(v, name, &value, errp)) {
827 return;
828 }
829 if (value < 0) {
830 error_setg(errp, "Property values cannot be negative");
831 return;
832 }
833
834 cfg = &tg->ts.cfg;
835 switch (info->category) {
836 case AVG:
837 cfg->buckets[info->type].avg = value;
838 break;
839 case MAX:
840 cfg->buckets[info->type].max = value;
841 break;
842 case BURST_LENGTH:
843 if (value > UINT_MAX) {
844 error_setg(errp, "%s value must be in the" "range [0, %u]",
845 info->name, UINT_MAX);
846 return;
847 }
848 cfg->buckets[info->type].burst_length = value;
849 break;
850 case IOPS_SIZE:
851 cfg->op_size = value;
852 break;
853 }
854}
855
856static void throttle_group_get(Object *obj, Visitor *v, const char *name,
857 void *opaque, Error **errp)
858{
859 ThrottleGroup *tg = THROTTLE_GROUP(obj);
860 ThrottleConfig cfg;
861 ThrottleParamInfo *info = opaque;
862 int64_t value;
863
864 throttle_get_config(&tg->ts, &cfg);
865 switch (info->category) {
866 case AVG:
867 value = cfg.buckets[info->type].avg;
868 break;
869 case MAX:
870 value = cfg.buckets[info->type].max;
871 break;
872 case BURST_LENGTH:
873 value = cfg.buckets[info->type].burst_length;
874 break;
875 case IOPS_SIZE:
876 value = cfg.op_size;
877 break;
878 }
879
880 visit_type_int64(v, name, &value, errp);
881}
882
883static void throttle_group_set_limits(Object *obj, Visitor *v,
884 const char *name, void *opaque,
885 Error **errp)
886
887{
888 ThrottleGroup *tg = THROTTLE_GROUP(obj);
889 ThrottleConfig cfg;
890 ThrottleLimits *argp;
891 Error *local_err = NULL;
892
893 if (!visit_type_ThrottleLimits(v, name, &argp, errp)) {
894 return;
895 }
896 qemu_mutex_lock(&tg->lock);
897 throttle_get_config(&tg->ts, &cfg);
898 throttle_limits_to_config(argp, &cfg, &local_err);
899 if (local_err) {
900 goto unlock;
901 }
902 throttle_config(&tg->ts, tg->clock_type, &cfg);
903
904unlock:
905 qemu_mutex_unlock(&tg->lock);
906 qapi_free_ThrottleLimits(argp);
907 error_propagate(errp, local_err);
908 return;
909}
910
911static void throttle_group_get_limits(Object *obj, Visitor *v,
912 const char *name, void *opaque,
913 Error **errp)
914{
915 ThrottleGroup *tg = THROTTLE_GROUP(obj);
916 ThrottleConfig cfg;
917 ThrottleLimits arg = { 0 };
918 ThrottleLimits *argp = &arg;
919
920 qemu_mutex_lock(&tg->lock);
921 throttle_get_config(&tg->ts, &cfg);
922 qemu_mutex_unlock(&tg->lock);
923
924 throttle_config_to_limits(&cfg, argp);
925
926 visit_type_ThrottleLimits(v, name, &argp, errp);
927}
928
929static bool throttle_group_can_be_deleted(UserCreatable *uc)
930{
931 return OBJECT(uc)->ref == 1;
932}
933
934static void throttle_group_obj_class_init(ObjectClass *klass, void *class_data)
935{
936 size_t i = 0;
937 UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass);
938
939 ucc->complete = throttle_group_obj_complete;
940 ucc->can_be_deleted = throttle_group_can_be_deleted;
941
942
943 for (i = 0; i < sizeof(properties) / sizeof(ThrottleParamInfo); i++) {
944 object_class_property_add(klass,
945 properties[i].name,
946 "int",
947 throttle_group_get,
948 throttle_group_set,
949 NULL, &properties[i]);
950 }
951
952
953 object_class_property_add(klass,
954 "limits", "ThrottleLimits",
955 throttle_group_get_limits,
956 throttle_group_set_limits,
957 NULL, NULL);
958}
959
960static const TypeInfo throttle_group_info = {
961 .name = TYPE_THROTTLE_GROUP,
962 .parent = TYPE_OBJECT,
963 .class_init = throttle_group_obj_class_init,
964 .instance_size = sizeof(ThrottleGroup),
965 .instance_init = throttle_group_obj_init,
966 .instance_finalize = throttle_group_obj_finalize,
967 .interfaces = (InterfaceInfo[]) {
968 { TYPE_USER_CREATABLE },
969 { }
970 },
971};
972
973static void throttle_groups_init(void)
974{
975 type_register_static(&throttle_group_info);
976}
977
978type_init(throttle_groups_init);
979