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 "block/block.h"
27#include "block/blockjob_int.h"
28#include "sysemu/block-backend.h"
29#include "qapi/error.h"
30#include "qapi/qmp/qdict.h"
31#include "qemu/main-loop.h"
32#include "iothread.h"
33
34static int coroutine_fn bdrv_test_co_prwv(BlockDriverState *bs,
35 uint64_t offset, uint64_t bytes,
36 QEMUIOVector *qiov, int flags)
37{
38 return 0;
39}
40
41static int coroutine_fn bdrv_test_co_pdiscard(BlockDriverState *bs,
42 int64_t offset, int bytes)
43{
44 return 0;
45}
46
47static int coroutine_fn
48bdrv_test_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
49 PreallocMode prealloc, BdrvRequestFlags flags,
50 Error **errp)
51{
52 return 0;
53}
54
55static int coroutine_fn bdrv_test_co_block_status(BlockDriverState *bs,
56 bool want_zero,
57 int64_t offset, int64_t count,
58 int64_t *pnum, int64_t *map,
59 BlockDriverState **file)
60{
61 *pnum = count;
62 return 0;
63}
64
65static BlockDriver bdrv_test = {
66 .format_name = "test",
67 .instance_size = 1,
68
69 .bdrv_co_preadv = bdrv_test_co_prwv,
70 .bdrv_co_pwritev = bdrv_test_co_prwv,
71 .bdrv_co_pdiscard = bdrv_test_co_pdiscard,
72 .bdrv_co_truncate = bdrv_test_co_truncate,
73 .bdrv_co_block_status = bdrv_test_co_block_status,
74};
75
76static void test_sync_op_pread(BdrvChild *c)
77{
78 uint8_t buf[512];
79 int ret;
80
81
82 ret = bdrv_pread(c, 0, buf, sizeof(buf));
83 g_assert_cmpint(ret, ==, 512);
84
85
86 ret = bdrv_pread(c, -2, buf, sizeof(buf));
87 g_assert_cmpint(ret, ==, -EIO);
88}
89
90static void test_sync_op_pwrite(BdrvChild *c)
91{
92 uint8_t buf[512];
93 int ret;
94
95
96 ret = bdrv_pwrite(c, 0, buf, sizeof(buf));
97 g_assert_cmpint(ret, ==, 512);
98
99
100 ret = bdrv_pwrite(c, -2, buf, sizeof(buf));
101 g_assert_cmpint(ret, ==, -EIO);
102}
103
104static void test_sync_op_blk_pread(BlockBackend *blk)
105{
106 uint8_t buf[512];
107 int ret;
108
109
110 ret = blk_pread(blk, 0, buf, sizeof(buf));
111 g_assert_cmpint(ret, ==, 512);
112
113
114 ret = blk_pread(blk, -2, buf, sizeof(buf));
115 g_assert_cmpint(ret, ==, -EIO);
116}
117
118static void test_sync_op_blk_pwrite(BlockBackend *blk)
119{
120 uint8_t buf[512];
121 int ret;
122
123
124 ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0);
125 g_assert_cmpint(ret, ==, 512);
126
127
128 ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0);
129 g_assert_cmpint(ret, ==, -EIO);
130}
131
132static void test_sync_op_load_vmstate(BdrvChild *c)
133{
134 uint8_t buf[512];
135 int ret;
136
137
138 ret = bdrv_load_vmstate(c->bs, buf, 0, sizeof(buf));
139 g_assert_cmpint(ret, ==, -ENOTSUP);
140}
141
142static void test_sync_op_save_vmstate(BdrvChild *c)
143{
144 uint8_t buf[512];
145 int ret;
146
147
148 ret = bdrv_save_vmstate(c->bs, buf, 0, sizeof(buf));
149 g_assert_cmpint(ret, ==, -ENOTSUP);
150}
151
152static void test_sync_op_pdiscard(BdrvChild *c)
153{
154 int ret;
155
156
157 c->bs->open_flags |= BDRV_O_UNMAP;
158 ret = bdrv_pdiscard(c, 0, 512);
159 g_assert_cmpint(ret, ==, 0);
160
161
162 c->bs->open_flags &= ~BDRV_O_UNMAP;
163 ret = bdrv_pdiscard(c, 0, 512);
164 g_assert_cmpint(ret, ==, 0);
165
166
167 ret = bdrv_pdiscard(c, -2, 512);
168 g_assert_cmpint(ret, ==, -EIO);
169}
170
171static void test_sync_op_blk_pdiscard(BlockBackend *blk)
172{
173 int ret;
174
175
176 ret = blk_pdiscard(blk, 0, 512);
177 g_assert_cmpint(ret, ==, 0);
178
179
180 ret = blk_pdiscard(blk, -2, 512);
181 g_assert_cmpint(ret, ==, -EIO);
182}
183
184static void test_sync_op_truncate(BdrvChild *c)
185{
186 int ret;
187
188
189 ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
190 g_assert_cmpint(ret, ==, 0);
191
192
193 ret = bdrv_truncate(c, -2, false, PREALLOC_MODE_OFF, 0, NULL);
194 g_assert_cmpint(ret, ==, -EINVAL);
195
196
197 c->bs->read_only = true;
198 c->bs->open_flags &= ~BDRV_O_RDWR;
199
200 ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
201 g_assert_cmpint(ret, ==, -EACCES);
202
203 c->bs->read_only = false;
204 c->bs->open_flags |= BDRV_O_RDWR;
205}
206
207static void test_sync_op_block_status(BdrvChild *c)
208{
209 int ret;
210 int64_t n;
211
212
213 ret = bdrv_is_allocated(c->bs, 0, 65536, &n);
214 g_assert_cmpint(ret, ==, 0);
215
216
217 bdrv_test.bdrv_co_block_status = NULL;
218 ret = bdrv_is_allocated(c->bs, 0, 65536, &n);
219 g_assert_cmpint(ret, ==, 1);
220
221
222 ret = bdrv_is_allocated(c->bs, 0, 0, &n);
223 g_assert_cmpint(ret, ==, 0);
224
225
226 ret = bdrv_is_allocated(c->bs, 0x1000000, 0x1000000, &n);
227 g_assert_cmpint(ret, ==, 0);
228}
229
230static void test_sync_op_flush(BdrvChild *c)
231{
232 int ret;
233
234
235 ret = bdrv_flush(c->bs);
236 g_assert_cmpint(ret, ==, 0);
237
238
239 c->bs->read_only = true;
240 c->bs->open_flags &= ~BDRV_O_RDWR;
241
242 ret = bdrv_flush(c->bs);
243 g_assert_cmpint(ret, ==, 0);
244
245 c->bs->read_only = false;
246 c->bs->open_flags |= BDRV_O_RDWR;
247}
248
249static void test_sync_op_blk_flush(BlockBackend *blk)
250{
251 BlockDriverState *bs = blk_bs(blk);
252 int ret;
253
254
255 ret = blk_flush(blk);
256 g_assert_cmpint(ret, ==, 0);
257
258
259 bs->read_only = true;
260 bs->open_flags &= ~BDRV_O_RDWR;
261
262 ret = blk_flush(blk);
263 g_assert_cmpint(ret, ==, 0);
264
265 bs->read_only = false;
266 bs->open_flags |= BDRV_O_RDWR;
267}
268
269static void test_sync_op_check(BdrvChild *c)
270{
271 BdrvCheckResult result;
272 int ret;
273
274
275 ret = bdrv_check(c->bs, &result, 0);
276 g_assert_cmpint(ret, ==, -ENOTSUP);
277}
278
279static void test_sync_op_invalidate_cache(BdrvChild *c)
280{
281
282 bdrv_invalidate_cache(c->bs, NULL);
283}
284
285
286typedef struct SyncOpTest {
287 const char *name;
288 void (*fn)(BdrvChild *c);
289 void (*blkfn)(BlockBackend *blk);
290} SyncOpTest;
291
292const SyncOpTest sync_op_tests[] = {
293 {
294 .name = "/sync-op/pread",
295 .fn = test_sync_op_pread,
296 .blkfn = test_sync_op_blk_pread,
297 }, {
298 .name = "/sync-op/pwrite",
299 .fn = test_sync_op_pwrite,
300 .blkfn = test_sync_op_blk_pwrite,
301 }, {
302 .name = "/sync-op/load_vmstate",
303 .fn = test_sync_op_load_vmstate,
304 }, {
305 .name = "/sync-op/save_vmstate",
306 .fn = test_sync_op_save_vmstate,
307 }, {
308 .name = "/sync-op/pdiscard",
309 .fn = test_sync_op_pdiscard,
310 .blkfn = test_sync_op_blk_pdiscard,
311 }, {
312 .name = "/sync-op/truncate",
313 .fn = test_sync_op_truncate,
314 }, {
315 .name = "/sync-op/block_status",
316 .fn = test_sync_op_block_status,
317 }, {
318 .name = "/sync-op/flush",
319 .fn = test_sync_op_flush,
320 .blkfn = test_sync_op_blk_flush,
321 }, {
322 .name = "/sync-op/check",
323 .fn = test_sync_op_check,
324 }, {
325 .name = "/sync-op/invalidate_cache",
326 .fn = test_sync_op_invalidate_cache,
327 },
328};
329
330
331
332static void test_sync_op(const void *opaque)
333{
334 const SyncOpTest *t = opaque;
335 IOThread *iothread = iothread_new();
336 AioContext *ctx = iothread_get_aio_context(iothread);
337 BlockBackend *blk;
338 BlockDriverState *bs;
339 BdrvChild *c;
340
341 blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL);
342 bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
343 bs->total_sectors = 65536 / BDRV_SECTOR_SIZE;
344 blk_insert_bs(blk, bs, &error_abort);
345 c = QLIST_FIRST(&bs->parents);
346
347 blk_set_aio_context(blk, ctx, &error_abort);
348 aio_context_acquire(ctx);
349 t->fn(c);
350 if (t->blkfn) {
351 t->blkfn(blk);
352 }
353 blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort);
354 aio_context_release(ctx);
355
356 bdrv_unref(bs);
357 blk_unref(blk);
358}
359
360typedef struct TestBlockJob {
361 BlockJob common;
362 bool should_complete;
363 int n;
364} TestBlockJob;
365
366static int test_job_prepare(Job *job)
367{
368 g_assert(qemu_get_current_aio_context() == qemu_get_aio_context());
369 return 0;
370}
371
372static int coroutine_fn test_job_run(Job *job, Error **errp)
373{
374 TestBlockJob *s = container_of(job, TestBlockJob, common.job);
375
376 job_transition_to_ready(&s->common.job);
377 while (!s->should_complete) {
378 s->n++;
379 g_assert(qemu_get_current_aio_context() == job->aio_context);
380
381
382
383
384
385 qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000);
386
387 job_pause_point(&s->common.job);
388 }
389
390 g_assert(qemu_get_current_aio_context() == job->aio_context);
391 return 0;
392}
393
394static void test_job_complete(Job *job, Error **errp)
395{
396 TestBlockJob *s = container_of(job, TestBlockJob, common.job);
397 s->should_complete = true;
398}
399
400BlockJobDriver test_job_driver = {
401 .job_driver = {
402 .instance_size = sizeof(TestBlockJob),
403 .free = block_job_free,
404 .user_resume = block_job_user_resume,
405 .run = test_job_run,
406 .complete = test_job_complete,
407 .prepare = test_job_prepare,
408 },
409};
410
411static void test_attach_blockjob(void)
412{
413 IOThread *iothread = iothread_new();
414 AioContext *ctx = iothread_get_aio_context(iothread);
415 BlockBackend *blk;
416 BlockDriverState *bs;
417 TestBlockJob *tjob;
418
419 blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL);
420 bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
421 blk_insert_bs(blk, bs, &error_abort);
422
423 tjob = block_job_create("job0", &test_job_driver, NULL, bs,
424 0, BLK_PERM_ALL,
425 0, 0, NULL, NULL, &error_abort);
426 job_start(&tjob->common.job);
427
428 while (tjob->n == 0) {
429 aio_poll(qemu_get_aio_context(), false);
430 }
431
432 blk_set_aio_context(blk, ctx, &error_abort);
433
434 tjob->n = 0;
435 while (tjob->n == 0) {
436 aio_poll(qemu_get_aio_context(), false);
437 }
438
439 aio_context_acquire(ctx);
440 blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort);
441 aio_context_release(ctx);
442
443 tjob->n = 0;
444 while (tjob->n == 0) {
445 aio_poll(qemu_get_aio_context(), false);
446 }
447
448 blk_set_aio_context(blk, ctx, &error_abort);
449
450 tjob->n = 0;
451 while (tjob->n == 0) {
452 aio_poll(qemu_get_aio_context(), false);
453 }
454
455 aio_context_acquire(ctx);
456 job_complete_sync(&tjob->common.job, &error_abort);
457 blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort);
458 aio_context_release(ctx);
459
460 bdrv_unref(bs);
461 blk_unref(blk);
462}
463
464
465
466
467
468
469
470
471
472
473
474
475
476static void test_propagate_basic(void)
477{
478 IOThread *iothread = iothread_new();
479 AioContext *ctx = iothread_get_aio_context(iothread);
480 AioContext *main_ctx;
481 BlockBackend *blk;
482 BlockDriverState *bs_a, *bs_b, *bs_verify;
483 QDict *options;
484
485
486
487
488
489
490 blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE,
491 BLK_PERM_ALL);
492 bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort);
493 blk_insert_bs(blk, bs_a, &error_abort);
494
495
496 bs_b = bdrv_new_open_driver(&bdrv_test, "bs_b", BDRV_O_RDWR, &error_abort);
497
498
499 options = qdict_new();
500 qdict_put_str(options, "driver", "blkverify");
501 qdict_put_str(options, "test", "bs_a");
502 qdict_put_str(options, "raw", "bs_b");
503
504 bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
505
506
507 blk_set_aio_context(blk, ctx, &error_abort);
508 g_assert(blk_get_aio_context(blk) == ctx);
509 g_assert(bdrv_get_aio_context(bs_a) == ctx);
510 g_assert(bdrv_get_aio_context(bs_verify) == ctx);
511 g_assert(bdrv_get_aio_context(bs_b) == ctx);
512
513
514 main_ctx = qemu_get_aio_context();
515 aio_context_acquire(ctx);
516 blk_set_aio_context(blk, main_ctx, &error_abort);
517 aio_context_release(ctx);
518 g_assert(blk_get_aio_context(blk) == main_ctx);
519 g_assert(bdrv_get_aio_context(bs_a) == main_ctx);
520 g_assert(bdrv_get_aio_context(bs_verify) == main_ctx);
521 g_assert(bdrv_get_aio_context(bs_b) == main_ctx);
522
523 bdrv_unref(bs_verify);
524 bdrv_unref(bs_b);
525 bdrv_unref(bs_a);
526 blk_unref(blk);
527}
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542static void test_propagate_diamond(void)
543{
544 IOThread *iothread = iothread_new();
545 AioContext *ctx = iothread_get_aio_context(iothread);
546 AioContext *main_ctx;
547 BlockBackend *blk;
548 BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify;
549 QDict *options;
550
551
552 bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort);
553
554
555 options = qdict_new();
556 qdict_put_str(options, "driver", "raw");
557 qdict_put_str(options, "file", "bs_a");
558 qdict_put_str(options, "node-name", "bs_b");
559 bs_b = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
560
561 options = qdict_new();
562 qdict_put_str(options, "driver", "raw");
563 qdict_put_str(options, "file", "bs_a");
564 qdict_put_str(options, "node-name", "bs_c");
565 bs_c = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
566
567
568 options = qdict_new();
569 qdict_put_str(options, "driver", "blkverify");
570 qdict_put_str(options, "test", "bs_b");
571 qdict_put_str(options, "raw", "bs_c");
572
573 bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
574
575
576
577
578
579 blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL & ~BLK_PERM_RESIZE,
580 BLK_PERM_ALL);
581 blk_insert_bs(blk, bs_verify, &error_abort);
582
583
584 blk_set_aio_context(blk, ctx, &error_abort);
585 g_assert(blk_get_aio_context(blk) == ctx);
586 g_assert(bdrv_get_aio_context(bs_verify) == ctx);
587 g_assert(bdrv_get_aio_context(bs_a) == ctx);
588 g_assert(bdrv_get_aio_context(bs_b) == ctx);
589 g_assert(bdrv_get_aio_context(bs_c) == ctx);
590
591
592 main_ctx = qemu_get_aio_context();
593 aio_context_acquire(ctx);
594 blk_set_aio_context(blk, main_ctx, &error_abort);
595 aio_context_release(ctx);
596 g_assert(blk_get_aio_context(blk) == main_ctx);
597 g_assert(bdrv_get_aio_context(bs_verify) == main_ctx);
598 g_assert(bdrv_get_aio_context(bs_a) == main_ctx);
599 g_assert(bdrv_get_aio_context(bs_b) == main_ctx);
600 g_assert(bdrv_get_aio_context(bs_c) == main_ctx);
601
602 blk_unref(blk);
603 bdrv_unref(bs_verify);
604 bdrv_unref(bs_c);
605 bdrv_unref(bs_b);
606 bdrv_unref(bs_a);
607}
608
609static void test_propagate_mirror(void)
610{
611 IOThread *iothread = iothread_new();
612 AioContext *ctx = iothread_get_aio_context(iothread);
613 AioContext *main_ctx = qemu_get_aio_context();
614 BlockDriverState *src, *target, *filter;
615 BlockBackend *blk;
616 Job *job;
617 Error *local_err = NULL;
618
619
620 src = bdrv_new_open_driver(&bdrv_test, "src", BDRV_O_RDWR, &error_abort);
621 target = bdrv_new_open_driver(&bdrv_test, "target", BDRV_O_RDWR,
622 &error_abort);
623
624
625 mirror_start("job0", src, target, NULL, JOB_DEFAULT, 0, 0, 0,
626 MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, false,
627 BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
628 false, "filter_node", MIRROR_COPY_MODE_BACKGROUND,
629 &error_abort);
630 job = job_get("job0");
631 filter = bdrv_find_node("filter_node");
632
633
634 bdrv_try_set_aio_context(src, ctx, &error_abort);
635 g_assert(bdrv_get_aio_context(src) == ctx);
636 g_assert(bdrv_get_aio_context(target) == ctx);
637 g_assert(bdrv_get_aio_context(filter) == ctx);
638 g_assert(job->aio_context == ctx);
639
640
641 aio_context_acquire(ctx);
642 bdrv_try_set_aio_context(target, main_ctx, &error_abort);
643 aio_context_release(ctx);
644 g_assert(bdrv_get_aio_context(src) == main_ctx);
645 g_assert(bdrv_get_aio_context(target) == main_ctx);
646 g_assert(bdrv_get_aio_context(filter) == main_ctx);
647
648
649 blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
650 blk_insert_bs(blk, src, &error_abort);
651
652 bdrv_try_set_aio_context(target, ctx, &local_err);
653 error_free_or_abort(&local_err);
654
655 g_assert(blk_get_aio_context(blk) == main_ctx);
656 g_assert(bdrv_get_aio_context(src) == main_ctx);
657 g_assert(bdrv_get_aio_context(target) == main_ctx);
658 g_assert(bdrv_get_aio_context(filter) == main_ctx);
659
660
661 aio_context_acquire(ctx);
662 blk_set_allow_aio_context_change(blk, true);
663 bdrv_try_set_aio_context(target, ctx, &error_abort);
664 aio_context_release(ctx);
665
666 g_assert(blk_get_aio_context(blk) == ctx);
667 g_assert(bdrv_get_aio_context(src) == ctx);
668 g_assert(bdrv_get_aio_context(target) == ctx);
669 g_assert(bdrv_get_aio_context(filter) == ctx);
670
671 job_cancel_sync_all();
672
673 aio_context_acquire(ctx);
674 blk_set_aio_context(blk, main_ctx, &error_abort);
675 bdrv_try_set_aio_context(target, main_ctx, &error_abort);
676 aio_context_release(ctx);
677
678 blk_unref(blk);
679 bdrv_unref(src);
680 bdrv_unref(target);
681}
682
683static void test_attach_second_node(void)
684{
685 IOThread *iothread = iothread_new();
686 AioContext *ctx = iothread_get_aio_context(iothread);
687 AioContext *main_ctx = qemu_get_aio_context();
688 BlockBackend *blk;
689 BlockDriverState *bs, *filter;
690 QDict *options;
691
692 blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
693 bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
694 blk_insert_bs(blk, bs, &error_abort);
695
696 options = qdict_new();
697 qdict_put_str(options, "driver", "raw");
698 qdict_put_str(options, "file", "base");
699
700 filter = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
701 g_assert(blk_get_aio_context(blk) == ctx);
702 g_assert(bdrv_get_aio_context(bs) == ctx);
703 g_assert(bdrv_get_aio_context(filter) == ctx);
704
705 aio_context_acquire(ctx);
706 blk_set_aio_context(blk, main_ctx, &error_abort);
707 aio_context_release(ctx);
708 g_assert(blk_get_aio_context(blk) == main_ctx);
709 g_assert(bdrv_get_aio_context(bs) == main_ctx);
710 g_assert(bdrv_get_aio_context(filter) == main_ctx);
711
712 bdrv_unref(filter);
713 bdrv_unref(bs);
714 blk_unref(blk);
715}
716
717static void test_attach_preserve_blk_ctx(void)
718{
719 IOThread *iothread = iothread_new();
720 AioContext *ctx = iothread_get_aio_context(iothread);
721 BlockBackend *blk;
722 BlockDriverState *bs;
723
724 blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
725 bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
726 bs->total_sectors = 65536 / BDRV_SECTOR_SIZE;
727
728
729 blk_insert_bs(blk, bs, &error_abort);
730 g_assert(blk_get_aio_context(blk) == ctx);
731 g_assert(bdrv_get_aio_context(bs) == ctx);
732
733
734 aio_context_acquire(ctx);
735 blk_remove_bs(blk);
736 aio_context_release(ctx);
737 g_assert(blk_get_aio_context(blk) == ctx);
738 g_assert(bdrv_get_aio_context(bs) == qemu_get_aio_context());
739
740
741 blk_insert_bs(blk, bs, &error_abort);
742 g_assert(blk_get_aio_context(blk) == ctx);
743 g_assert(bdrv_get_aio_context(bs) == ctx);
744
745 aio_context_acquire(ctx);
746 blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort);
747 aio_context_release(ctx);
748 bdrv_unref(bs);
749 blk_unref(blk);
750}
751
752int main(int argc, char **argv)
753{
754 int i;
755
756 bdrv_init();
757 qemu_init_main_loop(&error_abort);
758
759 g_test_init(&argc, &argv, NULL);
760
761 for (i = 0; i < ARRAY_SIZE(sync_op_tests); i++) {
762 const SyncOpTest *t = &sync_op_tests[i];
763 g_test_add_data_func(t->name, t, test_sync_op);
764 }
765
766 g_test_add_func("/attach/blockjob", test_attach_blockjob);
767 g_test_add_func("/attach/second_node", test_attach_second_node);
768 g_test_add_func("/attach/preserve_blk_ctx", test_attach_preserve_blk_ctx);
769 g_test_add_func("/propagate/basic", test_propagate_basic);
770 g_test_add_func("/propagate/diamond", test_propagate_diamond);
771 g_test_add_func("/propagate/mirror", test_propagate_mirror);
772
773 return g_test_run();
774}
775