1 /* 2 * Data plane event loop 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * Copyright (c) 2009-2017 QEMU contributors 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 * THE SOFTWARE. 24 */ 25 26 #include "qemu/osdep.h" 27 #include "qapi/error.h" 28 #include "block/aio.h" 29 #include "block/thread-pool.h" 30 #include "block/graph-lock.h" 31 #include "qemu/main-loop.h" 32 #include "qemu/atomic.h" 33 #include "qemu/rcu_queue.h" 34 #include "block/raw-aio.h" 35 #include "qemu/coroutine_int.h" 36 #include "qemu/coroutine-tls.h" 37 #include "sysemu/cpu-timers.h" 38 #include "trace.h" 39 40 /***********************************************************/ 41 /* bottom halves (can be seen as timers which expire ASAP) */ 42 43 /* QEMUBH::flags values */ 44 enum { 45 /* Already enqueued and waiting for aio_bh_poll() */ 46 BH_PENDING = (1 << 0), 47 48 /* Invoke the callback */ 49 BH_SCHEDULED = (1 << 1), 50 51 /* Delete without invoking callback */ 52 BH_DELETED = (1 << 2), 53 54 /* Delete after invoking callback */ 55 BH_ONESHOT = (1 << 3), 56 57 /* Schedule periodically when the event loop is idle */ 58 BH_IDLE = (1 << 4), 59 }; 60 61 struct QEMUBH { 62 AioContext *ctx; 63 const char *name; 64 QEMUBHFunc *cb; 65 void *opaque; 66 QSLIST_ENTRY(QEMUBH) next; 67 unsigned flags; 68 }; 69 70 /* Called concurrently from any thread */ 71 static void aio_bh_enqueue(QEMUBH *bh, unsigned new_flags) 72 { 73 AioContext *ctx = bh->ctx; 74 unsigned old_flags; 75 76 /* 77 * Synchronizes with atomic_fetch_and() in aio_bh_dequeue(), ensuring that 78 * insertion starts after BH_PENDING is set. 79 */ 80 old_flags = qatomic_fetch_or(&bh->flags, BH_PENDING | new_flags); 81 82 if (!(old_flags & BH_PENDING)) { 83 /* 84 * At this point the bottom half becomes visible to aio_bh_poll(). 85 * This insertion thus synchronizes with QSLIST_MOVE_ATOMIC in 86 * aio_bh_poll(), ensuring that: 87 * 1. any writes needed by the callback are visible from the callback 88 * after aio_bh_dequeue() returns bh. 89 * 2. ctx is loaded before the callback has a chance to execute and bh 90 * could be freed. 91 */ 92 QSLIST_INSERT_HEAD_ATOMIC(&ctx->bh_list, bh, next); 93 } 94 95 aio_notify(ctx); 96 /* 97 * Workaround for record/replay. 98 * vCPU execution should be suspended when new BH is set. 99 * This is needed to avoid guest timeouts caused 100 * by the long cycles of the execution. 101 */ 102 icount_notify_exit(); 103 } 104 105 /* Only called from aio_bh_poll() and aio_ctx_finalize() */ 106 static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags) 107 { 108 QEMUBH *bh = QSLIST_FIRST_RCU(head); 109 110 if (!bh) { 111 return NULL; 112 } 113 114 QSLIST_REMOVE_HEAD(head, next); 115 116 /* 117 * Synchronizes with qatomic_fetch_or() in aio_bh_enqueue(), ensuring that 118 * the removal finishes before BH_PENDING is reset. 119 */ 120 *flags = qatomic_fetch_and(&bh->flags, 121 ~(BH_PENDING | BH_SCHEDULED | BH_IDLE)); 122 return bh; 123 } 124 125 void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, 126 void *opaque, const char *name) 127 { 128 QEMUBH *bh; 129 bh = g_new(QEMUBH, 1); 130 *bh = (QEMUBH){ 131 .ctx = ctx, 132 .cb = cb, 133 .opaque = opaque, 134 .name = name, 135 }; 136 aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT); 137 } 138 139 QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, 140 const char *name) 141 { 142 QEMUBH *bh; 143 bh = g_new(QEMUBH, 1); 144 *bh = (QEMUBH){ 145 .ctx = ctx, 146 .cb = cb, 147 .opaque = opaque, 148 .name = name, 149 }; 150 return bh; 151 } 152 153 void aio_bh_call(QEMUBH *bh) 154 { 155 bh->cb(bh->opaque); 156 } 157 158 /* Multiple occurrences of aio_bh_poll cannot be called concurrently. */ 159 int aio_bh_poll(AioContext *ctx) 160 { 161 BHListSlice slice; 162 BHListSlice *s; 163 int ret = 0; 164 165 /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue(). */ 166 QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list); 167 QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next); 168 169 while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) { 170 QEMUBH *bh; 171 unsigned flags; 172 173 bh = aio_bh_dequeue(&s->bh_list, &flags); 174 if (!bh) { 175 QSIMPLEQ_REMOVE_HEAD(&ctx->bh_slice_list, next); 176 continue; 177 } 178 179 if ((flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) { 180 /* Idle BHs don't count as progress */ 181 if (!(flags & BH_IDLE)) { 182 ret = 1; 183 } 184 aio_bh_call(bh); 185 } 186 if (flags & (BH_DELETED | BH_ONESHOT)) { 187 g_free(bh); 188 } 189 } 190 191 return ret; 192 } 193 194 void qemu_bh_schedule_idle(QEMUBH *bh) 195 { 196 aio_bh_enqueue(bh, BH_SCHEDULED | BH_IDLE); 197 } 198 199 void qemu_bh_schedule(QEMUBH *bh) 200 { 201 aio_bh_enqueue(bh, BH_SCHEDULED); 202 } 203 204 /* This func is async. 205 */ 206 void qemu_bh_cancel(QEMUBH *bh) 207 { 208 qatomic_and(&bh->flags, ~BH_SCHEDULED); 209 } 210 211 /* This func is async.The bottom half will do the delete action at the finial 212 * end. 213 */ 214 void qemu_bh_delete(QEMUBH *bh) 215 { 216 aio_bh_enqueue(bh, BH_DELETED); 217 } 218 219 static int64_t aio_compute_bh_timeout(BHList *head, int timeout) 220 { 221 QEMUBH *bh; 222 223 QSLIST_FOREACH_RCU(bh, head, next) { 224 if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) { 225 if (bh->flags & BH_IDLE) { 226 /* idle bottom halves will be polled at least 227 * every 10ms */ 228 timeout = 10000000; 229 } else { 230 /* non-idle bottom halves will be executed 231 * immediately */ 232 return 0; 233 } 234 } 235 } 236 237 return timeout; 238 } 239 240 int64_t 241 aio_compute_timeout(AioContext *ctx) 242 { 243 BHListSlice *s; 244 int64_t deadline; 245 int timeout = -1; 246 247 timeout = aio_compute_bh_timeout(&ctx->bh_list, timeout); 248 if (timeout == 0) { 249 return 0; 250 } 251 252 QSIMPLEQ_FOREACH(s, &ctx->bh_slice_list, next) { 253 timeout = aio_compute_bh_timeout(&s->bh_list, timeout); 254 if (timeout == 0) { 255 return 0; 256 } 257 } 258 259 deadline = timerlistgroup_deadline_ns(&ctx->tlg); 260 if (deadline == 0) { 261 return 0; 262 } else { 263 return qemu_soonest_timeout(timeout, deadline); 264 } 265 } 266 267 static gboolean 268 aio_ctx_prepare(GSource *source, gint *timeout) 269 { 270 AioContext *ctx = (AioContext *) source; 271 272 qatomic_set(&ctx->notify_me, qatomic_read(&ctx->notify_me) | 1); 273 274 /* 275 * Write ctx->notify_me before computing the timeout 276 * (reading bottom half flags, etc.). Pairs with 277 * smp_mb in aio_notify(). 278 */ 279 smp_mb(); 280 281 /* We assume there is no timeout already supplied */ 282 *timeout = qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)); 283 284 if (aio_prepare(ctx)) { 285 *timeout = 0; 286 } 287 288 return *timeout == 0; 289 } 290 291 static gboolean 292 aio_ctx_check(GSource *source) 293 { 294 AioContext *ctx = (AioContext *) source; 295 QEMUBH *bh; 296 BHListSlice *s; 297 298 /* Finish computing the timeout before clearing the flag. */ 299 qatomic_store_release(&ctx->notify_me, qatomic_read(&ctx->notify_me) & ~1); 300 aio_notify_accept(ctx); 301 302 QSLIST_FOREACH_RCU(bh, &ctx->bh_list, next) { 303 if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) { 304 return true; 305 } 306 } 307 308 QSIMPLEQ_FOREACH(s, &ctx->bh_slice_list, next) { 309 QSLIST_FOREACH_RCU(bh, &s->bh_list, next) { 310 if ((bh->flags & (BH_SCHEDULED | BH_DELETED)) == BH_SCHEDULED) { 311 return true; 312 } 313 } 314 } 315 return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0); 316 } 317 318 static gboolean 319 aio_ctx_dispatch(GSource *source, 320 GSourceFunc callback, 321 gpointer user_data) 322 { 323 AioContext *ctx = (AioContext *) source; 324 325 assert(callback == NULL); 326 aio_dispatch(ctx); 327 return true; 328 } 329 330 static void 331 aio_ctx_finalize(GSource *source) 332 { 333 AioContext *ctx = (AioContext *) source; 334 QEMUBH *bh; 335 unsigned flags; 336 337 thread_pool_free(ctx->thread_pool); 338 339 #ifdef CONFIG_LINUX_AIO 340 if (ctx->linux_aio) { 341 laio_detach_aio_context(ctx->linux_aio, ctx); 342 laio_cleanup(ctx->linux_aio); 343 ctx->linux_aio = NULL; 344 } 345 #endif 346 347 #ifdef CONFIG_LINUX_IO_URING 348 if (ctx->linux_io_uring) { 349 luring_detach_aio_context(ctx->linux_io_uring, ctx); 350 luring_cleanup(ctx->linux_io_uring); 351 ctx->linux_io_uring = NULL; 352 } 353 #endif 354 355 assert(QSLIST_EMPTY(&ctx->scheduled_coroutines)); 356 qemu_bh_delete(ctx->co_schedule_bh); 357 358 /* There must be no aio_bh_poll() calls going on */ 359 assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list)); 360 361 while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) { 362 /* 363 * qemu_bh_delete() must have been called on BHs in this AioContext. In 364 * many cases memory leaks, hangs, or inconsistent state occur when a 365 * BH is leaked because something still expects it to run. 366 * 367 * If you hit this, fix the lifecycle of the BH so that 368 * qemu_bh_delete() and any associated cleanup is called before the 369 * AioContext is finalized. 370 */ 371 if (unlikely(!(flags & BH_DELETED))) { 372 fprintf(stderr, "%s: BH '%s' leaked, aborting...\n", 373 __func__, bh->name); 374 abort(); 375 } 376 377 g_free(bh); 378 } 379 380 aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL, NULL); 381 event_notifier_cleanup(&ctx->notifier); 382 qemu_rec_mutex_destroy(&ctx->lock); 383 qemu_lockcnt_destroy(&ctx->list_lock); 384 timerlistgroup_deinit(&ctx->tlg); 385 unregister_aiocontext(ctx); 386 aio_context_destroy(ctx); 387 } 388 389 static GSourceFuncs aio_source_funcs = { 390 aio_ctx_prepare, 391 aio_ctx_check, 392 aio_ctx_dispatch, 393 aio_ctx_finalize 394 }; 395 396 GSource *aio_get_g_source(AioContext *ctx) 397 { 398 aio_context_use_g_source(ctx); 399 g_source_ref(&ctx->source); 400 return &ctx->source; 401 } 402 403 ThreadPool *aio_get_thread_pool(AioContext *ctx) 404 { 405 if (!ctx->thread_pool) { 406 ctx->thread_pool = thread_pool_new(ctx); 407 } 408 return ctx->thread_pool; 409 } 410 411 #ifdef CONFIG_LINUX_AIO 412 LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp) 413 { 414 if (!ctx->linux_aio) { 415 ctx->linux_aio = laio_init(errp); 416 if (ctx->linux_aio) { 417 laio_attach_aio_context(ctx->linux_aio, ctx); 418 } 419 } 420 return ctx->linux_aio; 421 } 422 423 LinuxAioState *aio_get_linux_aio(AioContext *ctx) 424 { 425 assert(ctx->linux_aio); 426 return ctx->linux_aio; 427 } 428 #endif 429 430 #ifdef CONFIG_LINUX_IO_URING 431 LuringState *aio_setup_linux_io_uring(AioContext *ctx, Error **errp) 432 { 433 if (ctx->linux_io_uring) { 434 return ctx->linux_io_uring; 435 } 436 437 ctx->linux_io_uring = luring_init(errp); 438 if (!ctx->linux_io_uring) { 439 return NULL; 440 } 441 442 luring_attach_aio_context(ctx->linux_io_uring, ctx); 443 return ctx->linux_io_uring; 444 } 445 446 LuringState *aio_get_linux_io_uring(AioContext *ctx) 447 { 448 assert(ctx->linux_io_uring); 449 return ctx->linux_io_uring; 450 } 451 #endif 452 453 void aio_notify(AioContext *ctx) 454 { 455 /* 456 * Write e.g. ctx->bh_list before writing ctx->notified. Pairs with 457 * smp_mb() in aio_notify_accept(). 458 */ 459 smp_wmb(); 460 qatomic_set(&ctx->notified, true); 461 462 /* 463 * Write ctx->notified (and also ctx->bh_list) before reading ctx->notify_me. 464 * Pairs with smp_mb() in aio_ctx_prepare or aio_poll. 465 */ 466 smp_mb(); 467 if (qatomic_read(&ctx->notify_me)) { 468 event_notifier_set(&ctx->notifier); 469 } 470 } 471 472 void aio_notify_accept(AioContext *ctx) 473 { 474 qatomic_set(&ctx->notified, false); 475 476 /* 477 * Write ctx->notified before reading e.g. bh->flags. Pairs with smp_wmb 478 * in aio_notify. 479 */ 480 smp_mb(); 481 } 482 483 static void aio_timerlist_notify(void *opaque, QEMUClockType type) 484 { 485 aio_notify(opaque); 486 } 487 488 static void aio_context_notifier_cb(EventNotifier *e) 489 { 490 AioContext *ctx = container_of(e, AioContext, notifier); 491 492 event_notifier_test_and_clear(&ctx->notifier); 493 } 494 495 /* Returns true if aio_notify() was called (e.g. a BH was scheduled) */ 496 static bool aio_context_notifier_poll(void *opaque) 497 { 498 EventNotifier *e = opaque; 499 AioContext *ctx = container_of(e, AioContext, notifier); 500 501 return qatomic_read(&ctx->notified); 502 } 503 504 static void aio_context_notifier_poll_ready(EventNotifier *e) 505 { 506 /* Do nothing, we just wanted to kick the event loop */ 507 } 508 509 static void co_schedule_bh_cb(void *opaque) 510 { 511 AioContext *ctx = opaque; 512 QSLIST_HEAD(, Coroutine) straight, reversed; 513 514 QSLIST_MOVE_ATOMIC(&reversed, &ctx->scheduled_coroutines); 515 QSLIST_INIT(&straight); 516 517 while (!QSLIST_EMPTY(&reversed)) { 518 Coroutine *co = QSLIST_FIRST(&reversed); 519 QSLIST_REMOVE_HEAD(&reversed, co_scheduled_next); 520 QSLIST_INSERT_HEAD(&straight, co, co_scheduled_next); 521 } 522 523 while (!QSLIST_EMPTY(&straight)) { 524 Coroutine *co = QSLIST_FIRST(&straight); 525 QSLIST_REMOVE_HEAD(&straight, co_scheduled_next); 526 trace_aio_co_schedule_bh_cb(ctx, co); 527 aio_context_acquire(ctx); 528 529 /* Protected by write barrier in qemu_aio_coroutine_enter */ 530 qatomic_set(&co->scheduled, NULL); 531 qemu_aio_coroutine_enter(ctx, co); 532 aio_context_release(ctx); 533 } 534 } 535 536 AioContext *aio_context_new(Error **errp) 537 { 538 int ret; 539 AioContext *ctx; 540 541 ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext)); 542 QSLIST_INIT(&ctx->bh_list); 543 QSIMPLEQ_INIT(&ctx->bh_slice_list); 544 aio_context_setup(ctx); 545 546 ret = event_notifier_init(&ctx->notifier, false); 547 if (ret < 0) { 548 error_setg_errno(errp, -ret, "Failed to initialize event notifier"); 549 goto fail; 550 } 551 g_source_set_can_recurse(&ctx->source, true); 552 qemu_lockcnt_init(&ctx->list_lock); 553 554 ctx->co_schedule_bh = aio_bh_new(ctx, co_schedule_bh_cb, ctx); 555 QSLIST_INIT(&ctx->scheduled_coroutines); 556 557 aio_set_event_notifier(ctx, &ctx->notifier, 558 false, 559 aio_context_notifier_cb, 560 aio_context_notifier_poll, 561 aio_context_notifier_poll_ready); 562 #ifdef CONFIG_LINUX_AIO 563 ctx->linux_aio = NULL; 564 #endif 565 566 #ifdef CONFIG_LINUX_IO_URING 567 ctx->linux_io_uring = NULL; 568 #endif 569 570 ctx->thread_pool = NULL; 571 qemu_rec_mutex_init(&ctx->lock); 572 timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx); 573 574 ctx->poll_ns = 0; 575 ctx->poll_max_ns = 0; 576 ctx->poll_grow = 0; 577 ctx->poll_shrink = 0; 578 579 ctx->aio_max_batch = 0; 580 581 ctx->thread_pool_min = 0; 582 ctx->thread_pool_max = THREAD_POOL_MAX_THREADS_DEFAULT; 583 584 register_aiocontext(ctx); 585 586 return ctx; 587 fail: 588 g_source_destroy(&ctx->source); 589 return NULL; 590 } 591 592 void aio_co_schedule(AioContext *ctx, Coroutine *co) 593 { 594 trace_aio_co_schedule(ctx, co); 595 const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL, 596 __func__); 597 598 if (scheduled) { 599 fprintf(stderr, 600 "%s: Co-routine was already scheduled in '%s'\n", 601 __func__, scheduled); 602 abort(); 603 } 604 605 /* The coroutine might run and release the last ctx reference before we 606 * invoke qemu_bh_schedule(). Take a reference to keep ctx alive until 607 * we're done. 608 */ 609 aio_context_ref(ctx); 610 611 QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines, 612 co, co_scheduled_next); 613 qemu_bh_schedule(ctx->co_schedule_bh); 614 615 aio_context_unref(ctx); 616 } 617 618 typedef struct AioCoRescheduleSelf { 619 Coroutine *co; 620 AioContext *new_ctx; 621 } AioCoRescheduleSelf; 622 623 static void aio_co_reschedule_self_bh(void *opaque) 624 { 625 AioCoRescheduleSelf *data = opaque; 626 aio_co_schedule(data->new_ctx, data->co); 627 } 628 629 void coroutine_fn aio_co_reschedule_self(AioContext *new_ctx) 630 { 631 AioContext *old_ctx = qemu_get_current_aio_context(); 632 633 if (old_ctx != new_ctx) { 634 AioCoRescheduleSelf data = { 635 .co = qemu_coroutine_self(), 636 .new_ctx = new_ctx, 637 }; 638 /* 639 * We can't directly schedule the coroutine in the target context 640 * because this would be racy: The other thread could try to enter the 641 * coroutine before it has yielded in this one. 642 */ 643 aio_bh_schedule_oneshot(old_ctx, aio_co_reschedule_self_bh, &data); 644 qemu_coroutine_yield(); 645 } 646 } 647 648 void aio_co_wake(Coroutine *co) 649 { 650 AioContext *ctx; 651 652 /* Read coroutine before co->ctx. Matches smp_wmb in 653 * qemu_coroutine_enter. 654 */ 655 smp_read_barrier_depends(); 656 ctx = qatomic_read(&co->ctx); 657 658 aio_co_enter(ctx, co); 659 } 660 661 void aio_co_enter(AioContext *ctx, Coroutine *co) 662 { 663 if (ctx != qemu_get_current_aio_context()) { 664 aio_co_schedule(ctx, co); 665 return; 666 } 667 668 if (qemu_in_coroutine()) { 669 Coroutine *self = qemu_coroutine_self(); 670 assert(self != co); 671 QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, co, co_queue_next); 672 } else { 673 aio_context_acquire(ctx); 674 qemu_aio_coroutine_enter(ctx, co); 675 aio_context_release(ctx); 676 } 677 } 678 679 void aio_context_ref(AioContext *ctx) 680 { 681 g_source_ref(&ctx->source); 682 } 683 684 void aio_context_unref(AioContext *ctx) 685 { 686 g_source_unref(&ctx->source); 687 } 688 689 void aio_context_acquire(AioContext *ctx) 690 { 691 qemu_rec_mutex_lock(&ctx->lock); 692 } 693 694 void aio_context_release(AioContext *ctx) 695 { 696 qemu_rec_mutex_unlock(&ctx->lock); 697 } 698 699 QEMU_DEFINE_STATIC_CO_TLS(AioContext *, my_aiocontext) 700 701 AioContext *qemu_get_current_aio_context(void) 702 { 703 AioContext *ctx = get_my_aiocontext(); 704 if (ctx) { 705 return ctx; 706 } 707 if (qemu_mutex_iothread_locked()) { 708 /* Possibly in a vCPU thread. */ 709 return qemu_get_aio_context(); 710 } 711 return NULL; 712 } 713 714 void qemu_set_current_aio_context(AioContext *ctx) 715 { 716 assert(!get_my_aiocontext()); 717 set_my_aiocontext(ctx); 718 } 719 720 void aio_context_set_thread_pool_params(AioContext *ctx, int64_t min, 721 int64_t max, Error **errp) 722 { 723 724 if (min > max || !max || min > INT_MAX || max > INT_MAX) { 725 error_setg(errp, "bad thread-pool-min/thread-pool-max values"); 726 return; 727 } 728 729 ctx->thread_pool_min = min; 730 ctx->thread_pool_max = max; 731 732 if (ctx->thread_pool) { 733 thread_pool_update_params(ctx->thread_pool, ctx); 734 } 735 } 736