@@ -1232,14 +1232,8 @@ static int nbd_client_connect(BlockDriverState *bs,
object_ref(OBJECT(s->ioc));
}
- /*
- * Now that we're connected, set the socket to be non-blocking and
- * kick the reply mechanism.
- */
qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL);
- s->connection_co = qemu_coroutine_create(nbd_connection_entry, s);
- bdrv_inc_in_flight(bs);
- nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs));
+ qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs));
trace_nbd_client_connect_success(export);
@@ -1270,14 +1264,24 @@ static int nbd_client_init(BlockDriverState *bs,
const char *x_dirty_bitmap,
Error **errp)
{
+ int ret;
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
s->bs = bs;
qemu_co_mutex_init(&s->send_mutex);
qemu_co_queue_init(&s->free_sema);
- return nbd_client_connect(bs, saddr, export, tlscreds, hostname,
- x_dirty_bitmap, errp);
+ ret = nbd_client_connect(bs, saddr, export, tlscreds, hostname,
+ x_dirty_bitmap, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
+ s->connection_co = qemu_coroutine_create(nbd_connection_entry, s);
+ bdrv_inc_in_flight(bs);
+ aio_co_schedule(bdrv_get_aio_context(bs), s->connection_co);
+
+ return 0;
}
static int nbd_parse_uri(const char *filename, QDict *options)