Fam Zheng e92f0e1910 block: Use bdrv_coroutine_enter to start I/O coroutines
BDRV_POLL_WHILE waits for the started I/O by releasing bs's ctx then polling
the main context, which relies on the yielded coroutine continuing on bs->ctx
before notifying qemu_aio_context with bdrv_wakeup().

Thus, using qemu_coroutine_enter to start I/O is wrong because if the coroutine
is entered from main loop, co->ctx will be qemu_aio_context, as a result of the
"release, poll, acquire" loop of BDRV_POLL_WHILE, race conditions happen when
both main thread and the iothread access the same BDS:

  main loop                                iothread
-----------------------------------------------------------------------
  blockdev_snapshot
    aio_context_acquire(bs->ctx)
                                           virtio_scsi_data_plane_handle_cmd
    bdrv_drained_begin(bs->ctx)
    bdrv_flush(bs)
      bdrv_co_flush(bs)                      aio_context_acquire(bs->ctx).enter
        ...
        qemu_coroutine_yield(co)
      BDRV_POLL_WHILE()
        aio_context_release(bs->ctx)
                                             aio_context_acquire(bs->ctx).return
                                               ...
                                                 aio_co_wake(co)
        aio_poll(qemu_aio_context)               ...
          co_schedule_bh_cb()                    ...
            qemu_coroutine_enter(co)             ...

              /* (A) bdrv_co_flush(bs)           /* (B) I/O on bs */
                      continues... */
                                             aio_context_release(bs->ctx)
        aio_context_acquire(bs->ctx)

Note that in above case, bdrv_drained_begin() doesn't do the "release,
poll, acquire" in BDRV_POLL_WHILE, because bs->in_flight == 0.

Fix this by using bdrv_coroutine_enter and enter coroutine in the right
context.

iotests 109 output is updated because the coroutine reenter flow during
mirror job complete is different (now through co_queue_wakeup, instead
of the unconditional qemu_coroutine_switch before), making the end job
len different.

Signed-off-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
2017-04-11 20:07:15 +08:00
..
2016-07-25 13:23:18 -05:00
2017-03-01 11:58:57 +04:00
2016-10-26 08:29:01 -07:00
2017-03-03 10:09:03 +00:00
2017-03-01 11:51:28 +04:00
2017-03-01 11:51:28 +04:00
2017-03-01 11:51:05 +04:00
2017-03-01 11:51:04 +04:00
2017-03-01 11:51:28 +04:00
2017-03-01 11:51:04 +04:00
2017-03-01 11:51:05 +04:00
2017-03-01 11:51:05 +04:00
2016-09-08 18:05:22 +04:00
2017-03-01 00:09:28 +04:00
2017-03-01 00:09:28 +04:00
2017-03-01 00:09:28 +04:00
2017-03-01 00:09:28 +04:00
2017-03-01 11:50:33 +04:00
2016-09-08 18:05:21 +04:00
2017-03-01 11:51:25 +04:00
2017-01-10 08:49:59 -08:00
2017-02-28 20:47:50 +01:00
2016-09-08 17:57:32 +04:00
2017-03-07 16:07:47 +01:00
2017-03-07 07:32:28 +00:00
2016-11-15 15:41:00 +00:00
2017-02-28 20:47:50 +01:00
2016-11-11 20:53:23 +08:00
2017-03-01 11:51:29 +04:00
2017-03-01 11:51:29 +04:00