@@ -632,6 +632,8 @@ typedef struct TestBlockJob {
632
632
BlockDriverState * bs ;
633
633
int run_ret ;
634
634
int prepare_ret ;
635
+
636
+ /* Accessed with atomics */
635
637
bool running ;
636
638
bool should_complete ;
637
639
} TestBlockJob ;
@@ -667,10 +669,10 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
667
669
668
670
/* We are running the actual job code past the pause point in
669
671
* job_co_entry(). */
670
- s -> running = true;
672
+ qatomic_set ( & s -> running , true) ;
671
673
672
674
job_transition_to_ready (& s -> common .job );
673
- while (!s -> should_complete ) {
675
+ while (!qatomic_read ( & s -> should_complete ) ) {
674
676
/* Avoid job_sleep_ns() because it marks the job as !busy. We want to
675
677
* emulate some actual activity (probably some I/O) here so that drain
676
678
* has to wait for this activity to stop. */
@@ -685,7 +687,7 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
685
687
static void test_job_complete (Job * job , Error * * errp )
686
688
{
687
689
TestBlockJob * s = container_of (job , TestBlockJob , common .job );
688
- s -> should_complete = true;
690
+ qatomic_set ( & s -> should_complete , true) ;
689
691
}
690
692
691
693
BlockJobDriver test_job_driver = {
@@ -791,15 +793,15 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
791
793
/* job_co_entry() is run in the I/O thread, wait for the actual job
792
794
* code to start (we don't want to catch the job in the pause point in
793
795
* job_co_entry(). */
794
- while (!tjob -> running ) {
796
+ while (!qatomic_read ( & tjob -> running ) ) {
795
797
aio_poll (qemu_get_aio_context (), false);
796
798
}
797
799
}
798
800
799
801
WITH_JOB_LOCK_GUARD () {
800
802
g_assert_cmpint (job -> job .pause_count , = = , 0 );
801
803
g_assert_false (job -> job .paused );
802
- g_assert_true (tjob -> running );
804
+ g_assert_true (qatomic_read ( & tjob -> running ) );
803
805
g_assert_true (job -> job .busy ); /* We're in qemu_co_sleep_ns() */
804
806
}
805
807
@@ -825,7 +827,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
825
827
*
826
828
* paused is reset in the I/O thread, wait for it
827
829
*/
828
- while (job -> job . paused ) {
830
+ while (job_is_paused ( & job -> job ) ) {
829
831
aio_poll (qemu_get_aio_context (), false);
830
832
}
831
833
}
@@ -858,7 +860,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
858
860
*
859
861
* paused is reset in the I/O thread, wait for it
860
862
*/
861
- while (job -> job . paused ) {
863
+ while (job_is_paused ( & job -> job ) ) {
862
864
aio_poll (qemu_get_aio_context (), false);
863
865
}
864
866
}
@@ -1411,18 +1413,20 @@ static void test_set_aio_context(void)
1411
1413
1412
1414
typedef struct TestDropBackingBlockJob {
1413
1415
BlockJob common ;
1414
- bool should_complete ;
1415
1416
bool * did_complete ;
1416
1417
BlockDriverState * detach_also ;
1417
1418
BlockDriverState * bs ;
1419
+
1420
+ /* Accessed with atomics */
1421
+ bool should_complete ;
1418
1422
} TestDropBackingBlockJob ;
1419
1423
1420
1424
static int coroutine_fn test_drop_backing_job_run (Job * job , Error * * errp )
1421
1425
{
1422
1426
TestDropBackingBlockJob * s =
1423
1427
container_of (job , TestDropBackingBlockJob , common .job );
1424
1428
1425
- while (!s -> should_complete ) {
1429
+ while (!qatomic_read ( & s -> should_complete ) ) {
1426
1430
job_sleep_ns (job , 0 );
1427
1431
}
1428
1432
@@ -1541,7 +1545,7 @@ static void test_blockjob_commit_by_drained_end(void)
1541
1545
1542
1546
job_start (& job -> common .job );
1543
1547
1544
- job -> should_complete = true;
1548
+ qatomic_set ( & job -> should_complete , true) ;
1545
1549
bdrv_drained_begin (bs_child );
1546
1550
g_assert (!job_has_completed );
1547
1551
bdrv_drained_end (bs_child );
@@ -1557,15 +1561,17 @@ static void test_blockjob_commit_by_drained_end(void)
1557
1561
1558
1562
typedef struct TestSimpleBlockJob {
1559
1563
BlockJob common ;
1560
- bool should_complete ;
1561
1564
bool * did_complete ;
1565
+
1566
+ /* Accessed with atomics */
1567
+ bool should_complete ;
1562
1568
} TestSimpleBlockJob ;
1563
1569
1564
1570
static int coroutine_fn test_simple_job_run (Job * job , Error * * errp )
1565
1571
{
1566
1572
TestSimpleBlockJob * s = container_of (job , TestSimpleBlockJob , common .job );
1567
1573
1568
- while (!s -> should_complete ) {
1574
+ while (!qatomic_read ( & s -> should_complete ) ) {
1569
1575
job_sleep_ns (job , 0 );
1570
1576
}
1571
1577
@@ -1700,7 +1706,7 @@ static void test_drop_intermediate_poll(void)
1700
1706
job -> did_complete = & job_has_completed ;
1701
1707
1702
1708
job_start (& job -> common .job );
1703
- job -> should_complete = true;
1709
+ qatomic_set ( & job -> should_complete , true) ;
1704
1710
1705
1711
g_assert (!job_has_completed );
1706
1712
ret = bdrv_drop_intermediate (chain [1 ], chain [0 ], NULL , false);
0 commit comments