2 * Block node draining tests
4 * Copyright (c) 2017 Kevin Wolf <kwolf@redhat.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "block/block.h"
27 #include "block/blockjob_int.h"
28 #include "sysemu/block-backend.h"
29 #include "qapi/error.h"
32 static QemuEvent done_event
;
34 typedef struct BDRVTestState
{
36 AioContext
*bh_indirection_ctx
;
37 bool sleep_in_drain_begin
;
40 static void coroutine_fn
bdrv_test_co_drain_begin(BlockDriverState
*bs
)
42 BDRVTestState
*s
= bs
->opaque
;
44 if (s
->sleep_in_drain_begin
) {
45 qemu_co_sleep_ns(QEMU_CLOCK_REALTIME
, 100000);
49 static void coroutine_fn
bdrv_test_co_drain_end(BlockDriverState
*bs
)
51 BDRVTestState
*s
= bs
->opaque
;
55 static void bdrv_test_close(BlockDriverState
*bs
)
57 BDRVTestState
*s
= bs
->opaque
;
58 g_assert_cmpint(s
->drain_count
, >, 0);
61 static void co_reenter_bh(void *opaque
)
66 static int coroutine_fn
bdrv_test_co_preadv(BlockDriverState
*bs
,
67 uint64_t offset
, uint64_t bytes
,
68 QEMUIOVector
*qiov
, int flags
)
70 BDRVTestState
*s
= bs
->opaque
;
72 /* We want this request to stay until the polling loop in drain waits for
73 * it to complete. We need to sleep a while as bdrv_drain_invoke() comes
74 * first and polls its result, too, but it shouldn't accidentally complete
75 * this request yet. */
76 qemu_co_sleep_ns(QEMU_CLOCK_REALTIME
, 100000);
78 if (s
->bh_indirection_ctx
) {
79 aio_bh_schedule_oneshot(s
->bh_indirection_ctx
, co_reenter_bh
,
80 qemu_coroutine_self());
81 qemu_coroutine_yield();
87 static void bdrv_test_child_perm(BlockDriverState
*bs
, BdrvChild
*c
,
88 const BdrvChildRole
*role
,
89 BlockReopenQueue
*reopen_queue
,
90 uint64_t perm
, uint64_t shared
,
91 uint64_t *nperm
, uint64_t *nshared
)
93 /* bdrv_format_default_perms() accepts only these two, so disguise
94 * detach_by_driver_cb_role as one of them. */
95 if (role
!= &child_file
&& role
!= &child_backing
) {
99 bdrv_format_default_perms(bs
, c
, role
, reopen_queue
, perm
, shared
,
103 static BlockDriver bdrv_test
= {
104 .format_name
= "test",
105 .instance_size
= sizeof(BDRVTestState
),
107 .bdrv_close
= bdrv_test_close
,
108 .bdrv_co_preadv
= bdrv_test_co_preadv
,
110 .bdrv_co_drain_begin
= bdrv_test_co_drain_begin
,
111 .bdrv_co_drain_end
= bdrv_test_co_drain_end
,
113 .bdrv_child_perm
= bdrv_test_child_perm
,
116 static void aio_ret_cb(void *opaque
, int ret
)
118 int *aio_ret
= opaque
;
122 typedef struct CallInCoroutineData
{
125 } CallInCoroutineData
;
127 static coroutine_fn
void call_in_coroutine_entry(void *opaque
)
129 CallInCoroutineData
*data
= opaque
;
135 static void call_in_coroutine(void (*entry
)(void))
138 CallInCoroutineData data
= {
143 co
= qemu_coroutine_create(call_in_coroutine_entry
, &data
);
144 qemu_coroutine_enter(co
);
146 aio_poll(qemu_get_aio_context(), true);
157 static void do_drain_begin(enum drain_type drain_type
, BlockDriverState
*bs
)
159 switch (drain_type
) {
160 case BDRV_DRAIN_ALL
: bdrv_drain_all_begin(); break;
161 case BDRV_DRAIN
: bdrv_drained_begin(bs
); break;
162 case BDRV_SUBTREE_DRAIN
: bdrv_subtree_drained_begin(bs
); break;
163 default: g_assert_not_reached();
167 static void do_drain_end(enum drain_type drain_type
, BlockDriverState
*bs
)
169 switch (drain_type
) {
170 case BDRV_DRAIN_ALL
: bdrv_drain_all_end(); break;
171 case BDRV_DRAIN
: bdrv_drained_end(bs
); break;
172 case BDRV_SUBTREE_DRAIN
: bdrv_subtree_drained_end(bs
); break;
173 default: g_assert_not_reached();
177 static void test_drv_cb_common(enum drain_type drain_type
, bool recursive
)
180 BlockDriverState
*bs
, *backing
;
181 BDRVTestState
*s
, *backing_s
;
190 qemu_iovec_init_external(&qiov
, &iov
, 1);
192 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
193 bs
= bdrv_new_open_driver(&bdrv_test
, "test-node", BDRV_O_RDWR
,
196 blk_insert_bs(blk
, bs
, &error_abort
);
198 backing
= bdrv_new_open_driver(&bdrv_test
, "backing", 0, &error_abort
);
199 backing_s
= backing
->opaque
;
200 bdrv_set_backing_hd(bs
, backing
, &error_abort
);
202 /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */
203 g_assert_cmpint(s
->drain_count
, ==, 0);
204 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
206 do_drain_begin(drain_type
, bs
);
208 g_assert_cmpint(s
->drain_count
, ==, 1);
209 g_assert_cmpint(backing_s
->drain_count
, ==, !!recursive
);
211 do_drain_end(drain_type
, bs
);
213 g_assert_cmpint(s
->drain_count
, ==, 0);
214 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
216 /* Now do the same while a request is pending */
217 aio_ret
= -EINPROGRESS
;
218 acb
= blk_aio_preadv(blk
, 0, &qiov
, 0, aio_ret_cb
, &aio_ret
);
219 g_assert(acb
!= NULL
);
220 g_assert_cmpint(aio_ret
, ==, -EINPROGRESS
);
222 g_assert_cmpint(s
->drain_count
, ==, 0);
223 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
225 do_drain_begin(drain_type
, bs
);
227 g_assert_cmpint(aio_ret
, ==, 0);
228 g_assert_cmpint(s
->drain_count
, ==, 1);
229 g_assert_cmpint(backing_s
->drain_count
, ==, !!recursive
);
231 do_drain_end(drain_type
, bs
);
233 g_assert_cmpint(s
->drain_count
, ==, 0);
234 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
241 static void test_drv_cb_drain_all(void)
243 test_drv_cb_common(BDRV_DRAIN_ALL
, true);
246 static void test_drv_cb_drain(void)
248 test_drv_cb_common(BDRV_DRAIN
, false);
251 static void test_drv_cb_drain_subtree(void)
253 test_drv_cb_common(BDRV_SUBTREE_DRAIN
, true);
256 static void test_drv_cb_co_drain_all(void)
258 call_in_coroutine(test_drv_cb_drain_all
);
261 static void test_drv_cb_co_drain(void)
263 call_in_coroutine(test_drv_cb_drain
);
266 static void test_drv_cb_co_drain_subtree(void)
268 call_in_coroutine(test_drv_cb_drain_subtree
);
271 static void test_quiesce_common(enum drain_type drain_type
, bool recursive
)
274 BlockDriverState
*bs
, *backing
;
276 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
277 bs
= bdrv_new_open_driver(&bdrv_test
, "test-node", BDRV_O_RDWR
,
279 blk_insert_bs(blk
, bs
, &error_abort
);
281 backing
= bdrv_new_open_driver(&bdrv_test
, "backing", 0, &error_abort
);
282 bdrv_set_backing_hd(bs
, backing
, &error_abort
);
284 g_assert_cmpint(bs
->quiesce_counter
, ==, 0);
285 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
287 do_drain_begin(drain_type
, bs
);
289 g_assert_cmpint(bs
->quiesce_counter
, ==, 1);
290 g_assert_cmpint(backing
->quiesce_counter
, ==, !!recursive
);
292 do_drain_end(drain_type
, bs
);
294 g_assert_cmpint(bs
->quiesce_counter
, ==, 0);
295 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
302 static void test_quiesce_drain_all(void)
304 test_quiesce_common(BDRV_DRAIN_ALL
, true);
307 static void test_quiesce_drain(void)
309 test_quiesce_common(BDRV_DRAIN
, false);
312 static void test_quiesce_drain_subtree(void)
314 test_quiesce_common(BDRV_SUBTREE_DRAIN
, true);
317 static void test_quiesce_co_drain_all(void)
319 call_in_coroutine(test_quiesce_drain_all
);
322 static void test_quiesce_co_drain(void)
324 call_in_coroutine(test_quiesce_drain
);
327 static void test_quiesce_co_drain_subtree(void)
329 call_in_coroutine(test_quiesce_drain_subtree
);
332 static void test_nested(void)
335 BlockDriverState
*bs
, *backing
;
336 BDRVTestState
*s
, *backing_s
;
337 enum drain_type outer
, inner
;
339 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
340 bs
= bdrv_new_open_driver(&bdrv_test
, "test-node", BDRV_O_RDWR
,
343 blk_insert_bs(blk
, bs
, &error_abort
);
345 backing
= bdrv_new_open_driver(&bdrv_test
, "backing", 0, &error_abort
);
346 backing_s
= backing
->opaque
;
347 bdrv_set_backing_hd(bs
, backing
, &error_abort
);
349 for (outer
= 0; outer
< DRAIN_TYPE_MAX
; outer
++) {
350 for (inner
= 0; inner
< DRAIN_TYPE_MAX
; inner
++) {
351 int backing_quiesce
= (outer
!= BDRV_DRAIN
) +
352 (inner
!= BDRV_DRAIN
);
354 g_assert_cmpint(bs
->quiesce_counter
, ==, 0);
355 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
356 g_assert_cmpint(s
->drain_count
, ==, 0);
357 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
359 do_drain_begin(outer
, bs
);
360 do_drain_begin(inner
, bs
);
362 g_assert_cmpint(bs
->quiesce_counter
, ==, 2);
363 g_assert_cmpint(backing
->quiesce_counter
, ==, backing_quiesce
);
364 g_assert_cmpint(s
->drain_count
, ==, 2);
365 g_assert_cmpint(backing_s
->drain_count
, ==, backing_quiesce
);
367 do_drain_end(inner
, bs
);
368 do_drain_end(outer
, bs
);
370 g_assert_cmpint(bs
->quiesce_counter
, ==, 0);
371 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
372 g_assert_cmpint(s
->drain_count
, ==, 0);
373 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
382 static void test_multiparent(void)
384 BlockBackend
*blk_a
, *blk_b
;
385 BlockDriverState
*bs_a
, *bs_b
, *backing
;
386 BDRVTestState
*a_s
, *b_s
, *backing_s
;
388 blk_a
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
389 bs_a
= bdrv_new_open_driver(&bdrv_test
, "test-node-a", BDRV_O_RDWR
,
392 blk_insert_bs(blk_a
, bs_a
, &error_abort
);
394 blk_b
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
395 bs_b
= bdrv_new_open_driver(&bdrv_test
, "test-node-b", BDRV_O_RDWR
,
398 blk_insert_bs(blk_b
, bs_b
, &error_abort
);
400 backing
= bdrv_new_open_driver(&bdrv_test
, "backing", 0, &error_abort
);
401 backing_s
= backing
->opaque
;
402 bdrv_set_backing_hd(bs_a
, backing
, &error_abort
);
403 bdrv_set_backing_hd(bs_b
, backing
, &error_abort
);
405 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 0);
406 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 0);
407 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
408 g_assert_cmpint(a_s
->drain_count
, ==, 0);
409 g_assert_cmpint(b_s
->drain_count
, ==, 0);
410 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
412 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_a
);
414 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 1);
415 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 1);
416 g_assert_cmpint(backing
->quiesce_counter
, ==, 1);
417 g_assert_cmpint(a_s
->drain_count
, ==, 1);
418 g_assert_cmpint(b_s
->drain_count
, ==, 1);
419 g_assert_cmpint(backing_s
->drain_count
, ==, 1);
421 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_b
);
423 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 2);
424 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 2);
425 g_assert_cmpint(backing
->quiesce_counter
, ==, 2);
426 g_assert_cmpint(a_s
->drain_count
, ==, 2);
427 g_assert_cmpint(b_s
->drain_count
, ==, 2);
428 g_assert_cmpint(backing_s
->drain_count
, ==, 2);
430 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_b
);
432 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 1);
433 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 1);
434 g_assert_cmpint(backing
->quiesce_counter
, ==, 1);
435 g_assert_cmpint(a_s
->drain_count
, ==, 1);
436 g_assert_cmpint(b_s
->drain_count
, ==, 1);
437 g_assert_cmpint(backing_s
->drain_count
, ==, 1);
439 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_a
);
441 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 0);
442 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 0);
443 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
444 g_assert_cmpint(a_s
->drain_count
, ==, 0);
445 g_assert_cmpint(b_s
->drain_count
, ==, 0);
446 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
455 static void test_graph_change_drain_subtree(void)
457 BlockBackend
*blk_a
, *blk_b
;
458 BlockDriverState
*bs_a
, *bs_b
, *backing
;
459 BDRVTestState
*a_s
, *b_s
, *backing_s
;
461 blk_a
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
462 bs_a
= bdrv_new_open_driver(&bdrv_test
, "test-node-a", BDRV_O_RDWR
,
465 blk_insert_bs(blk_a
, bs_a
, &error_abort
);
467 blk_b
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
468 bs_b
= bdrv_new_open_driver(&bdrv_test
, "test-node-b", BDRV_O_RDWR
,
471 blk_insert_bs(blk_b
, bs_b
, &error_abort
);
473 backing
= bdrv_new_open_driver(&bdrv_test
, "backing", 0, &error_abort
);
474 backing_s
= backing
->opaque
;
475 bdrv_set_backing_hd(bs_a
, backing
, &error_abort
);
477 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 0);
478 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 0);
479 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
480 g_assert_cmpint(a_s
->drain_count
, ==, 0);
481 g_assert_cmpint(b_s
->drain_count
, ==, 0);
482 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
484 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_a
);
485 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_a
);
486 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_a
);
487 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_b
);
488 do_drain_begin(BDRV_SUBTREE_DRAIN
, bs_b
);
490 bdrv_set_backing_hd(bs_b
, backing
, &error_abort
);
491 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 5);
492 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 5);
493 g_assert_cmpint(backing
->quiesce_counter
, ==, 5);
494 g_assert_cmpint(a_s
->drain_count
, ==, 5);
495 g_assert_cmpint(b_s
->drain_count
, ==, 5);
496 g_assert_cmpint(backing_s
->drain_count
, ==, 5);
498 bdrv_set_backing_hd(bs_b
, NULL
, &error_abort
);
499 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 3);
500 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 2);
501 g_assert_cmpint(backing
->quiesce_counter
, ==, 3);
502 g_assert_cmpint(a_s
->drain_count
, ==, 3);
503 g_assert_cmpint(b_s
->drain_count
, ==, 2);
504 g_assert_cmpint(backing_s
->drain_count
, ==, 3);
506 bdrv_set_backing_hd(bs_b
, backing
, &error_abort
);
507 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 5);
508 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 5);
509 g_assert_cmpint(backing
->quiesce_counter
, ==, 5);
510 g_assert_cmpint(a_s
->drain_count
, ==, 5);
511 g_assert_cmpint(b_s
->drain_count
, ==, 5);
512 g_assert_cmpint(backing_s
->drain_count
, ==, 5);
514 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_b
);
515 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_b
);
516 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_a
);
517 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_a
);
518 do_drain_end(BDRV_SUBTREE_DRAIN
, bs_a
);
520 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 0);
521 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 0);
522 g_assert_cmpint(backing
->quiesce_counter
, ==, 0);
523 g_assert_cmpint(a_s
->drain_count
, ==, 0);
524 g_assert_cmpint(b_s
->drain_count
, ==, 0);
525 g_assert_cmpint(backing_s
->drain_count
, ==, 0);
534 static void test_graph_change_drain_all(void)
536 BlockBackend
*blk_a
, *blk_b
;
537 BlockDriverState
*bs_a
, *bs_b
;
538 BDRVTestState
*a_s
, *b_s
;
540 /* Create node A with a BlockBackend */
541 blk_a
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
542 bs_a
= bdrv_new_open_driver(&bdrv_test
, "test-node-a", BDRV_O_RDWR
,
545 blk_insert_bs(blk_a
, bs_a
, &error_abort
);
547 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 0);
548 g_assert_cmpint(a_s
->drain_count
, ==, 0);
550 /* Call bdrv_drain_all_begin() */
551 bdrv_drain_all_begin();
553 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 1);
554 g_assert_cmpint(a_s
->drain_count
, ==, 1);
556 /* Create node B with a BlockBackend */
557 blk_b
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
558 bs_b
= bdrv_new_open_driver(&bdrv_test
, "test-node-b", BDRV_O_RDWR
,
561 blk_insert_bs(blk_b
, bs_b
, &error_abort
);
563 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 1);
564 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 1);
565 g_assert_cmpint(a_s
->drain_count
, ==, 1);
566 g_assert_cmpint(b_s
->drain_count
, ==, 1);
568 /* Unref and finally delete node A */
571 g_assert_cmpint(bs_a
->quiesce_counter
, ==, 1);
572 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 1);
573 g_assert_cmpint(a_s
->drain_count
, ==, 1);
574 g_assert_cmpint(b_s
->drain_count
, ==, 1);
578 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 1);
579 g_assert_cmpint(b_s
->drain_count
, ==, 1);
581 /* End the drained section */
582 bdrv_drain_all_end();
584 g_assert_cmpint(bs_b
->quiesce_counter
, ==, 0);
585 g_assert_cmpint(b_s
->drain_count
, ==, 0);
591 struct test_iothread_data
{
592 BlockDriverState
*bs
;
593 enum drain_type drain_type
;
597 static void test_iothread_drain_entry(void *opaque
)
599 struct test_iothread_data
*data
= opaque
;
601 aio_context_acquire(bdrv_get_aio_context(data
->bs
));
602 do_drain_begin(data
->drain_type
, data
->bs
);
603 g_assert_cmpint(*data
->aio_ret
, ==, 0);
604 do_drain_end(data
->drain_type
, data
->bs
);
605 aio_context_release(bdrv_get_aio_context(data
->bs
));
607 qemu_event_set(&done_event
);
610 static void test_iothread_aio_cb(void *opaque
, int ret
)
612 int *aio_ret
= opaque
;
614 qemu_event_set(&done_event
);
618 * Starts an AIO request on a BDS that runs in the AioContext of iothread 1.
619 * The request involves a BH on iothread 2 before it can complete.
621 * @drain_thread = 0 means that do_drain_begin/end are called from the main
622 * thread, @drain_thread = 1 means that they are called from iothread 1. Drain
623 * for this BDS cannot be called from iothread 2 because only the main thread
624 * may do cross-AioContext polling.
626 static void test_iothread_common(enum drain_type drain_type
, int drain_thread
)
629 BlockDriverState
*bs
;
633 struct test_iothread_data data
;
635 IOThread
*a
= iothread_new();
636 IOThread
*b
= iothread_new();
637 AioContext
*ctx_a
= iothread_get_aio_context(a
);
638 AioContext
*ctx_b
= iothread_get_aio_context(b
);
645 qemu_iovec_init_external(&qiov
, &iov
, 1);
647 /* bdrv_drain_all() may only be called from the main loop thread */
648 if (drain_type
== BDRV_DRAIN_ALL
&& drain_thread
!= 0) {
652 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
653 bs
= bdrv_new_open_driver(&bdrv_test
, "test-node", BDRV_O_RDWR
,
656 blk_insert_bs(blk
, bs
, &error_abort
);
658 blk_set_aio_context(blk
, ctx_a
);
659 aio_context_acquire(ctx_a
);
661 s
->bh_indirection_ctx
= ctx_b
;
663 aio_ret
= -EINPROGRESS
;
664 if (drain_thread
== 0) {
665 acb
= blk_aio_preadv(blk
, 0, &qiov
, 0, test_iothread_aio_cb
, &aio_ret
);
667 acb
= blk_aio_preadv(blk
, 0, &qiov
, 0, aio_ret_cb
, &aio_ret
);
669 g_assert(acb
!= NULL
);
670 g_assert_cmpint(aio_ret
, ==, -EINPROGRESS
);
672 aio_context_release(ctx_a
);
674 data
= (struct test_iothread_data
) {
676 .drain_type
= drain_type
,
680 switch (drain_thread
) {
682 if (drain_type
!= BDRV_DRAIN_ALL
) {
683 aio_context_acquire(ctx_a
);
686 /* The request is running on the IOThread a. Draining its block device
687 * will make sure that it has completed as far as the BDS is concerned,
688 * but the drain in this thread can continue immediately after
689 * bdrv_dec_in_flight() and aio_ret might be assigned only slightly
691 qemu_event_reset(&done_event
);
692 do_drain_begin(drain_type
, bs
);
693 g_assert_cmpint(bs
->in_flight
, ==, 0);
695 if (drain_type
!= BDRV_DRAIN_ALL
) {
696 aio_context_release(ctx_a
);
698 qemu_event_wait(&done_event
);
699 if (drain_type
!= BDRV_DRAIN_ALL
) {
700 aio_context_acquire(ctx_a
);
703 g_assert_cmpint(aio_ret
, ==, 0);
704 do_drain_end(drain_type
, bs
);
706 if (drain_type
!= BDRV_DRAIN_ALL
) {
707 aio_context_release(ctx_a
);
711 qemu_event_reset(&done_event
);
712 aio_bh_schedule_oneshot(ctx_a
, test_iothread_drain_entry
, &data
);
713 qemu_event_wait(&done_event
);
716 g_assert_not_reached();
719 aio_context_acquire(ctx_a
);
720 blk_set_aio_context(blk
, qemu_get_aio_context());
721 aio_context_release(ctx_a
);
731 static void test_iothread_drain_all(void)
733 test_iothread_common(BDRV_DRAIN_ALL
, 0);
734 test_iothread_common(BDRV_DRAIN_ALL
, 1);
737 static void test_iothread_drain(void)
739 test_iothread_common(BDRV_DRAIN
, 0);
740 test_iothread_common(BDRV_DRAIN
, 1);
743 static void test_iothread_drain_subtree(void)
745 test_iothread_common(BDRV_SUBTREE_DRAIN
, 0);
746 test_iothread_common(BDRV_SUBTREE_DRAIN
, 1);
750 typedef struct TestBlockJob
{
752 bool should_complete
;
755 static int coroutine_fn
test_job_run(Job
*job
, Error
**errp
)
757 TestBlockJob
*s
= container_of(job
, TestBlockJob
, common
.job
);
759 job_transition_to_ready(&s
->common
.job
);
760 while (!s
->should_complete
) {
761 /* Avoid block_job_sleep_ns() because it marks the job as !busy. We
762 * want to emulate some actual activity (probably some I/O) here so
763 * that drain has to wait for this acitivity to stop. */
764 qemu_co_sleep_ns(QEMU_CLOCK_REALTIME
, 100000);
765 job_pause_point(&s
->common
.job
);
771 static void test_job_complete(Job
*job
, Error
**errp
)
773 TestBlockJob
*s
= container_of(job
, TestBlockJob
, common
.job
);
774 s
->should_complete
= true;
777 BlockJobDriver test_job_driver
= {
779 .instance_size
= sizeof(TestBlockJob
),
780 .free
= block_job_free
,
781 .user_resume
= block_job_user_resume
,
782 .drain
= block_job_drain
,
784 .complete
= test_job_complete
,
788 static void test_blockjob_common(enum drain_type drain_type
)
790 BlockBackend
*blk_src
, *blk_target
;
791 BlockDriverState
*src
, *target
;
795 src
= bdrv_new_open_driver(&bdrv_test
, "source", BDRV_O_RDWR
,
797 blk_src
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
798 blk_insert_bs(blk_src
, src
, &error_abort
);
800 target
= bdrv_new_open_driver(&bdrv_test
, "target", BDRV_O_RDWR
,
802 blk_target
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
803 blk_insert_bs(blk_target
, target
, &error_abort
);
805 job
= block_job_create("job0", &test_job_driver
, NULL
, src
, 0, BLK_PERM_ALL
,
806 0, 0, NULL
, NULL
, &error_abort
);
807 block_job_add_bdrv(job
, "target", target
, 0, BLK_PERM_ALL
, &error_abort
);
808 job_start(&job
->job
);
810 g_assert_cmpint(job
->job
.pause_count
, ==, 0);
811 g_assert_false(job
->job
.paused
);
812 g_assert_true(job
->job
.busy
); /* We're in job_sleep_ns() */
814 do_drain_begin(drain_type
, src
);
816 if (drain_type
== BDRV_DRAIN_ALL
) {
817 /* bdrv_drain_all() drains both src and target */
818 g_assert_cmpint(job
->job
.pause_count
, ==, 2);
820 g_assert_cmpint(job
->job
.pause_count
, ==, 1);
822 g_assert_true(job
->job
.paused
);
823 g_assert_false(job
->job
.busy
); /* The job is paused */
825 do_drain_end(drain_type
, src
);
827 g_assert_cmpint(job
->job
.pause_count
, ==, 0);
828 g_assert_false(job
->job
.paused
);
829 g_assert_true(job
->job
.busy
); /* We're in qemu_co_sleep_ns() */
831 do_drain_begin(drain_type
, target
);
833 if (drain_type
== BDRV_DRAIN_ALL
) {
834 /* bdrv_drain_all() drains both src and target */
835 g_assert_cmpint(job
->job
.pause_count
, ==, 2);
837 g_assert_cmpint(job
->job
.pause_count
, ==, 1);
839 g_assert_true(job
->job
.paused
);
840 g_assert_false(job
->job
.busy
); /* The job is paused */
842 do_drain_end(drain_type
, target
);
844 g_assert_cmpint(job
->job
.pause_count
, ==, 0);
845 g_assert_false(job
->job
.paused
);
846 g_assert_true(job
->job
.busy
); /* We're in job_sleep_ns() */
848 ret
= job_complete_sync(&job
->job
, &error_abort
);
849 g_assert_cmpint(ret
, ==, 0);
852 blk_unref(blk_target
);
857 static void test_blockjob_drain_all(void)
859 test_blockjob_common(BDRV_DRAIN_ALL
);
862 static void test_blockjob_drain(void)
864 test_blockjob_common(BDRV_DRAIN
);
867 static void test_blockjob_drain_subtree(void)
869 test_blockjob_common(BDRV_SUBTREE_DRAIN
);
873 typedef struct BDRVTestTopState
{
874 BdrvChild
*wait_child
;
877 static void bdrv_test_top_close(BlockDriverState
*bs
)
879 BdrvChild
*c
, *next_c
;
880 QLIST_FOREACH_SAFE(c
, &bs
->children
, next
, next_c
) {
881 bdrv_unref_child(bs
, c
);
885 static int coroutine_fn
bdrv_test_top_co_preadv(BlockDriverState
*bs
,
886 uint64_t offset
, uint64_t bytes
,
887 QEMUIOVector
*qiov
, int flags
)
889 BDRVTestTopState
*tts
= bs
->opaque
;
890 return bdrv_co_preadv(tts
->wait_child
, offset
, bytes
, qiov
, flags
);
893 static BlockDriver bdrv_test_top_driver
= {
894 .format_name
= "test_top_driver",
895 .instance_size
= sizeof(BDRVTestTopState
),
897 .bdrv_close
= bdrv_test_top_close
,
898 .bdrv_co_preadv
= bdrv_test_top_co_preadv
,
900 .bdrv_child_perm
= bdrv_format_default_perms
,
903 typedef struct TestCoDeleteByDrainData
{
905 bool detach_instead_of_delete
;
907 } TestCoDeleteByDrainData
;
909 static void coroutine_fn
test_co_delete_by_drain(void *opaque
)
911 TestCoDeleteByDrainData
*dbdd
= opaque
;
912 BlockBackend
*blk
= dbdd
->blk
;
913 BlockDriverState
*bs
= blk_bs(blk
);
914 BDRVTestTopState
*tts
= bs
->opaque
;
915 void *buffer
= g_malloc(65536);
922 qemu_iovec_init_external(&qiov
, &iov
, 1);
924 /* Pretend some internal write operation from parent to child.
925 * Important: We have to read from the child, not from the parent!
926 * Draining works by first propagating it all up the tree to the
927 * root and then waiting for drainage from root to the leaves
928 * (protocol nodes). If we have a request waiting on the root,
929 * everything will be drained before we go back down the tree, but
930 * we do not want that. We want to be in the middle of draining
931 * when this following requests returns. */
932 bdrv_co_preadv(tts
->wait_child
, 0, 65536, &qiov
, 0);
934 g_assert_cmpint(bs
->refcnt
, ==, 1);
936 if (!dbdd
->detach_instead_of_delete
) {
939 BdrvChild
*c
, *next_c
;
940 QLIST_FOREACH_SAFE(c
, &bs
->children
, next
, next_c
) {
941 bdrv_unref_child(bs
, c
);
950 * Test what happens when some BDS has some children, you drain one of
951 * them and this results in the BDS being deleted.
953 * If @detach_instead_of_delete is set, the BDS is not going to be
954 * deleted but will only detach all of its children.
956 static void do_test_delete_by_drain(bool detach_instead_of_delete
,
957 enum drain_type drain_type
)
960 BlockDriverState
*bs
, *child_bs
, *null_bs
;
961 BDRVTestTopState
*tts
;
962 TestCoDeleteByDrainData dbdd
;
965 bs
= bdrv_new_open_driver(&bdrv_test_top_driver
, "top", BDRV_O_RDWR
,
967 bs
->total_sectors
= 65536 >> BDRV_SECTOR_BITS
;
970 null_bs
= bdrv_open("null-co://", NULL
, NULL
, BDRV_O_RDWR
| BDRV_O_PROTOCOL
,
972 bdrv_attach_child(bs
, null_bs
, "null-child", &child_file
, &error_abort
);
974 /* This child will be the one to pass to requests through to, and
975 * it will stall until a drain occurs */
976 child_bs
= bdrv_new_open_driver(&bdrv_test
, "child", BDRV_O_RDWR
,
978 child_bs
->total_sectors
= 65536 >> BDRV_SECTOR_BITS
;
979 /* Takes our reference to child_bs */
980 tts
->wait_child
= bdrv_attach_child(bs
, child_bs
, "wait-child", &child_file
,
983 /* This child is just there to be deleted
984 * (for detach_instead_of_delete == true) */
985 null_bs
= bdrv_open("null-co://", NULL
, NULL
, BDRV_O_RDWR
| BDRV_O_PROTOCOL
,
987 bdrv_attach_child(bs
, null_bs
, "null-child", &child_file
, &error_abort
);
989 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
990 blk_insert_bs(blk
, bs
, &error_abort
);
992 /* Referenced by blk now */
995 g_assert_cmpint(bs
->refcnt
, ==, 1);
996 g_assert_cmpint(child_bs
->refcnt
, ==, 1);
997 g_assert_cmpint(null_bs
->refcnt
, ==, 1);
1000 dbdd
= (TestCoDeleteByDrainData
){
1002 .detach_instead_of_delete
= detach_instead_of_delete
,
1005 co
= qemu_coroutine_create(test_co_delete_by_drain
, &dbdd
);
1006 qemu_coroutine_enter(co
);
1008 /* Drain the child while the read operation is still pending.
1009 * This should result in the operation finishing and
1010 * test_co_delete_by_drain() resuming. Thus, @bs will be deleted
1011 * and the coroutine will exit while this drain operation is still
1013 switch (drain_type
) {
1016 bdrv_drain(child_bs
);
1017 bdrv_unref(child_bs
);
1019 case BDRV_SUBTREE_DRAIN
:
1020 /* Would have to ref/unref bs here for !detach_instead_of_delete, but
1021 * then the whole test becomes pointless because the graph changes
1022 * don't occur during the drain any more. */
1023 assert(detach_instead_of_delete
);
1024 bdrv_subtree_drained_begin(bs
);
1025 bdrv_subtree_drained_end(bs
);
1027 case BDRV_DRAIN_ALL
:
1028 bdrv_drain_all_begin();
1029 bdrv_drain_all_end();
1032 g_assert_not_reached();
1035 while (!dbdd
.done
) {
1036 aio_poll(qemu_get_aio_context(), true);
1039 if (detach_instead_of_delete
) {
1040 /* Here, the reference has not passed over to the coroutine,
1041 * so we have to delete the BB ourselves */
1046 static void test_delete_by_drain(void)
1048 do_test_delete_by_drain(false, BDRV_DRAIN
);
1051 static void test_detach_by_drain_all(void)
1053 do_test_delete_by_drain(true, BDRV_DRAIN_ALL
);
1056 static void test_detach_by_drain(void)
1058 do_test_delete_by_drain(true, BDRV_DRAIN
);
1061 static void test_detach_by_drain_subtree(void)
1063 do_test_delete_by_drain(true, BDRV_SUBTREE_DRAIN
);
1067 struct detach_by_parent_data
{
1068 BlockDriverState
*parent_b
;
1070 BlockDriverState
*c
;
1074 static struct detach_by_parent_data detach_by_parent_data
;
1076 static void detach_indirect_bh(void *opaque
)
1078 struct detach_by_parent_data
*data
= opaque
;
1080 bdrv_unref_child(data
->parent_b
, data
->child_b
);
1083 data
->child_c
= bdrv_attach_child(data
->parent_b
, data
->c
, "PB-C",
1084 &child_file
, &error_abort
);
1087 static void detach_by_parent_aio_cb(void *opaque
, int ret
)
1089 struct detach_by_parent_data
*data
= &detach_by_parent_data
;
1091 g_assert_cmpint(ret
, ==, 0);
1092 if (data
->by_parent_cb
) {
1093 detach_indirect_bh(data
);
1097 static void detach_by_driver_cb_drained_begin(BdrvChild
*child
)
1099 aio_bh_schedule_oneshot(qemu_get_current_aio_context(),
1100 detach_indirect_bh
, &detach_by_parent_data
);
1101 child_file
.drained_begin(child
);
1104 static BdrvChildRole detach_by_driver_cb_role
;
1113 * by_parent_cb == true: Test that parent callbacks don't poll
1115 * PA has a pending write request whose callback changes the child nodes of
1116 * PB: It removes B and adds C instead. The subtree of PB is drained, which
1117 * will indirectly drain the write request, too.
1119 * by_parent_cb == false: Test that bdrv_drain_invoke() doesn't poll
1121 * PA's BdrvChildRole has a .drained_begin callback that schedules a BH
1122 * that does the same graph change. If bdrv_drain_invoke() calls it, the
1123 * state is messed up, but if it is only polled in the single
1124 * BDRV_POLL_WHILE() at the end of the drain, this should work fine.
1126 static void test_detach_indirect(bool by_parent_cb
)
1129 BlockDriverState
*parent_a
, *parent_b
, *a
, *b
, *c
;
1130 BdrvChild
*child_a
, *child_b
;
1134 struct iovec iov
= {
1138 qemu_iovec_init_external(&qiov
, &iov
, 1);
1140 if (!by_parent_cb
) {
1141 detach_by_driver_cb_role
= child_file
;
1142 detach_by_driver_cb_role
.drained_begin
=
1143 detach_by_driver_cb_drained_begin
;
1146 /* Create all involved nodes */
1147 parent_a
= bdrv_new_open_driver(&bdrv_test
, "parent-a", BDRV_O_RDWR
,
1149 parent_b
= bdrv_new_open_driver(&bdrv_test
, "parent-b", 0,
1152 a
= bdrv_new_open_driver(&bdrv_test
, "a", BDRV_O_RDWR
, &error_abort
);
1153 b
= bdrv_new_open_driver(&bdrv_test
, "b", BDRV_O_RDWR
, &error_abort
);
1154 c
= bdrv_new_open_driver(&bdrv_test
, "c", BDRV_O_RDWR
, &error_abort
);
1156 /* blk is a BB for parent-a */
1157 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
1158 blk_insert_bs(blk
, parent_a
, &error_abort
);
1159 bdrv_unref(parent_a
);
1161 /* If we want to get bdrv_drain_invoke() to call aio_poll(), the driver
1162 * callback must not return immediately. */
1163 if (!by_parent_cb
) {
1164 BDRVTestState
*s
= parent_a
->opaque
;
1165 s
->sleep_in_drain_begin
= true;
1168 /* Set child relationships */
1171 child_b
= bdrv_attach_child(parent_b
, b
, "PB-B", &child_file
, &error_abort
);
1172 child_a
= bdrv_attach_child(parent_b
, a
, "PB-A", &child_backing
, &error_abort
);
1175 bdrv_attach_child(parent_a
, a
, "PA-A",
1176 by_parent_cb
? &child_file
: &detach_by_driver_cb_role
,
1179 g_assert_cmpint(parent_a
->refcnt
, ==, 1);
1180 g_assert_cmpint(parent_b
->refcnt
, ==, 1);
1181 g_assert_cmpint(a
->refcnt
, ==, 3);
1182 g_assert_cmpint(b
->refcnt
, ==, 2);
1183 g_assert_cmpint(c
->refcnt
, ==, 1);
1185 g_assert(QLIST_FIRST(&parent_b
->children
) == child_a
);
1186 g_assert(QLIST_NEXT(child_a
, next
) == child_b
);
1187 g_assert(QLIST_NEXT(child_b
, next
) == NULL
);
1189 /* Start the evil write request */
1190 detach_by_parent_data
= (struct detach_by_parent_data
) {
1191 .parent_b
= parent_b
,
1194 .by_parent_cb
= by_parent_cb
,
1196 acb
= blk_aio_preadv(blk
, 0, &qiov
, 0, detach_by_parent_aio_cb
, NULL
);
1197 g_assert(acb
!= NULL
);
1199 /* Drain and check the expected result */
1200 bdrv_subtree_drained_begin(parent_b
);
1202 g_assert(detach_by_parent_data
.child_c
!= NULL
);
1204 g_assert_cmpint(parent_a
->refcnt
, ==, 1);
1205 g_assert_cmpint(parent_b
->refcnt
, ==, 1);
1206 g_assert_cmpint(a
->refcnt
, ==, 3);
1207 g_assert_cmpint(b
->refcnt
, ==, 1);
1208 g_assert_cmpint(c
->refcnt
, ==, 2);
1210 g_assert(QLIST_FIRST(&parent_b
->children
) == detach_by_parent_data
.child_c
);
1211 g_assert(QLIST_NEXT(detach_by_parent_data
.child_c
, next
) == child_a
);
1212 g_assert(QLIST_NEXT(child_a
, next
) == NULL
);
1214 g_assert_cmpint(parent_a
->quiesce_counter
, ==, 1);
1215 g_assert_cmpint(parent_b
->quiesce_counter
, ==, 1);
1216 g_assert_cmpint(a
->quiesce_counter
, ==, 1);
1217 g_assert_cmpint(b
->quiesce_counter
, ==, 0);
1218 g_assert_cmpint(c
->quiesce_counter
, ==, 1);
1220 bdrv_subtree_drained_end(parent_b
);
1222 bdrv_unref(parent_b
);
1225 /* XXX Once bdrv_close() unref's children instead of just detaching them,
1226 * this won't be necessary any more. */
1231 g_assert_cmpint(a
->refcnt
, ==, 1);
1232 g_assert_cmpint(b
->refcnt
, ==, 1);
1233 g_assert_cmpint(c
->refcnt
, ==, 1);
1239 static void test_detach_by_parent_cb(void)
1241 test_detach_indirect(true);
1244 static void test_detach_by_driver_cb(void)
1246 test_detach_indirect(false);
1249 static void test_append_to_drained(void)
1252 BlockDriverState
*base
, *overlay
;
1253 BDRVTestState
*base_s
, *overlay_s
;
1255 blk
= blk_new(BLK_PERM_ALL
, BLK_PERM_ALL
);
1256 base
= bdrv_new_open_driver(&bdrv_test
, "base", BDRV_O_RDWR
, &error_abort
);
1257 base_s
= base
->opaque
;
1258 blk_insert_bs(blk
, base
, &error_abort
);
1260 overlay
= bdrv_new_open_driver(&bdrv_test
, "overlay", BDRV_O_RDWR
,
1262 overlay_s
= overlay
->opaque
;
1264 do_drain_begin(BDRV_DRAIN
, base
);
1265 g_assert_cmpint(base
->quiesce_counter
, ==, 1);
1266 g_assert_cmpint(base_s
->drain_count
, ==, 1);
1267 g_assert_cmpint(base
->in_flight
, ==, 0);
1269 /* Takes ownership of overlay, so we don't have to unref it later */
1270 bdrv_append(overlay
, base
, &error_abort
);
1271 g_assert_cmpint(base
->in_flight
, ==, 0);
1272 g_assert_cmpint(overlay
->in_flight
, ==, 0);
1274 g_assert_cmpint(base
->quiesce_counter
, ==, 1);
1275 g_assert_cmpint(base_s
->drain_count
, ==, 1);
1276 g_assert_cmpint(overlay
->quiesce_counter
, ==, 1);
1277 g_assert_cmpint(overlay_s
->drain_count
, ==, 1);
1279 do_drain_end(BDRV_DRAIN
, base
);
1281 g_assert_cmpint(base
->quiesce_counter
, ==, 0);
1282 g_assert_cmpint(base_s
->drain_count
, ==, 0);
1283 g_assert_cmpint(overlay
->quiesce_counter
, ==, 0);
1284 g_assert_cmpint(overlay_s
->drain_count
, ==, 0);
1290 int main(int argc
, char **argv
)
1295 qemu_init_main_loop(&error_abort
);
1297 g_test_init(&argc
, &argv
, NULL
);
1298 qemu_event_init(&done_event
, false);
1300 g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all
);
1301 g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain
);
1302 g_test_add_func("/bdrv-drain/driver-cb/drain_subtree",
1303 test_drv_cb_drain_subtree
);
1305 g_test_add_func("/bdrv-drain/driver-cb/co/drain_all",
1306 test_drv_cb_co_drain_all
);
1307 g_test_add_func("/bdrv-drain/driver-cb/co/drain", test_drv_cb_co_drain
);
1308 g_test_add_func("/bdrv-drain/driver-cb/co/drain_subtree",
1309 test_drv_cb_co_drain_subtree
);
1312 g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all
);
1313 g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain
);
1314 g_test_add_func("/bdrv-drain/quiesce/drain_subtree",
1315 test_quiesce_drain_subtree
);
1317 g_test_add_func("/bdrv-drain/quiesce/co/drain_all",
1318 test_quiesce_co_drain_all
);
1319 g_test_add_func("/bdrv-drain/quiesce/co/drain", test_quiesce_co_drain
);
1320 g_test_add_func("/bdrv-drain/quiesce/co/drain_subtree",
1321 test_quiesce_co_drain_subtree
);
1323 g_test_add_func("/bdrv-drain/nested", test_nested
);
1324 g_test_add_func("/bdrv-drain/multiparent", test_multiparent
);
1326 g_test_add_func("/bdrv-drain/graph-change/drain_subtree",
1327 test_graph_change_drain_subtree
);
1328 g_test_add_func("/bdrv-drain/graph-change/drain_all",
1329 test_graph_change_drain_all
);
1331 g_test_add_func("/bdrv-drain/iothread/drain_all", test_iothread_drain_all
);
1332 g_test_add_func("/bdrv-drain/iothread/drain", test_iothread_drain
);
1333 g_test_add_func("/bdrv-drain/iothread/drain_subtree",
1334 test_iothread_drain_subtree
);
1336 g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all
);
1337 g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain
);
1338 g_test_add_func("/bdrv-drain/blockjob/drain_subtree",
1339 test_blockjob_drain_subtree
);
1341 g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain
);
1342 g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_all
);
1343 g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain
);
1344 g_test_add_func("/bdrv-drain/detach/drain_subtree", test_detach_by_drain_subtree
);
1345 g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_cb
);
1346 g_test_add_func("/bdrv-drain/detach/driver_cb", test_detach_by_driver_cb
);
1348 g_test_add_func("/bdrv-drain/attach/drain", test_append_to_drained
);
1351 qemu_event_destroy(&done_event
);