block/nbd: use non-blocking io channel for nbd negotiation
No reason to use blocking channel for negotiation and we'll benefit in further reconnect feature, as qio_channel reads and writes will do qemu_coroutine_yield while waiting for io completion. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20190618114328.55249-3-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
962b7b3d4c
commit
a8e2bb6a76
16
block/nbd.c
16
block/nbd.c
@ -1175,6 +1175,7 @@ static int nbd_client_connect(BlockDriverState *bs,
|
|||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
|
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
|
||||||
|
AioContext *aio_context = bdrv_get_aio_context(bs);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1189,15 +1190,16 @@ static int nbd_client_connect(BlockDriverState *bs,
|
|||||||
|
|
||||||
/* NBD handshake */
|
/* NBD handshake */
|
||||||
trace_nbd_client_connect(export);
|
trace_nbd_client_connect(export);
|
||||||
qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL);
|
qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL);
|
||||||
|
qio_channel_attach_aio_context(QIO_CHANNEL(sioc), aio_context);
|
||||||
|
|
||||||
s->info.request_sizes = true;
|
s->info.request_sizes = true;
|
||||||
s->info.structured_reply = true;
|
s->info.structured_reply = true;
|
||||||
s->info.base_allocation = true;
|
s->info.base_allocation = true;
|
||||||
s->info.x_dirty_bitmap = g_strdup(x_dirty_bitmap);
|
s->info.x_dirty_bitmap = g_strdup(x_dirty_bitmap);
|
||||||
s->info.name = g_strdup(export ?: "");
|
s->info.name = g_strdup(export ?: "");
|
||||||
ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), tlscreds, hostname,
|
ret = nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), tlscreds,
|
||||||
&s->ioc, &s->info, errp);
|
hostname, &s->ioc, &s->info, errp);
|
||||||
g_free(s->info.x_dirty_bitmap);
|
g_free(s->info.x_dirty_bitmap);
|
||||||
g_free(s->info.name);
|
g_free(s->info.name);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -1231,18 +1233,14 @@ static int nbd_client_connect(BlockDriverState *bs,
|
|||||||
object_ref(OBJECT(s->ioc));
|
object_ref(OBJECT(s->ioc));
|
||||||
}
|
}
|
||||||
|
|
||||||
qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL);
|
|
||||||
qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs));
|
|
||||||
|
|
||||||
trace_nbd_client_connect_success(export);
|
trace_nbd_client_connect_success(export);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/*
|
/*
|
||||||
* We have connected, but must fail for other reasons. The
|
* We have connected, but must fail for other reasons.
|
||||||
* connection is still blocking; send NBD_CMD_DISC as a courtesy
|
* Send NBD_CMD_DISC as a courtesy to the server.
|
||||||
* to the server.
|
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
NBDRequest request = { .type = NBD_CMD_DISC };
|
NBDRequest request = { .type = NBD_CMD_DISC };
|
||||||
|
@ -304,7 +304,8 @@ struct NBDExportInfo {
|
|||||||
};
|
};
|
||||||
typedef struct NBDExportInfo NBDExportInfo;
|
typedef struct NBDExportInfo NBDExportInfo;
|
||||||
|
|
||||||
int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc,
|
||||||
|
QCryptoTLSCreds *tlscreds,
|
||||||
const char *hostname, QIOChannel **outioc,
|
const char *hostname, QIOChannel **outioc,
|
||||||
NBDExportInfo *info, Error **errp);
|
NBDExportInfo *info, Error **errp);
|
||||||
void nbd_free_export_list(NBDExportInfo *info, int count);
|
void nbd_free_export_list(NBDExportInfo *info, int count);
|
||||||
|
16
nbd/client.c
16
nbd/client.c
@ -867,7 +867,8 @@ static int nbd_list_meta_contexts(QIOChannel *ioc,
|
|||||||
* 2: server is newstyle, but lacks structured replies
|
* 2: server is newstyle, but lacks structured replies
|
||||||
* 3: server is newstyle and set up for structured replies
|
* 3: server is newstyle and set up for structured replies
|
||||||
*/
|
*/
|
||||||
static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
static int nbd_start_negotiate(AioContext *aio_context, QIOChannel *ioc,
|
||||||
|
QCryptoTLSCreds *tlscreds,
|
||||||
const char *hostname, QIOChannel **outioc,
|
const char *hostname, QIOChannel **outioc,
|
||||||
bool structured_reply, bool *zeroes,
|
bool structured_reply, bool *zeroes,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
@ -934,6 +935,10 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
ioc = *outioc;
|
ioc = *outioc;
|
||||||
|
if (aio_context) {
|
||||||
|
qio_channel_set_blocking(ioc, false, NULL);
|
||||||
|
qio_channel_attach_aio_context(ioc, aio_context);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error_setg(errp, "Server does not support STARTTLS");
|
error_setg(errp, "Server does not support STARTTLS");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -998,7 +1003,8 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *ioc, NBDExportInfo *info,
|
|||||||
* Returns: negative errno: failure talking to server
|
* Returns: negative errno: failure talking to server
|
||||||
* 0: server is connected
|
* 0: server is connected
|
||||||
*/
|
*/
|
||||||
int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc,
|
||||||
|
QCryptoTLSCreds *tlscreds,
|
||||||
const char *hostname, QIOChannel **outioc,
|
const char *hostname, QIOChannel **outioc,
|
||||||
NBDExportInfo *info, Error **errp)
|
NBDExportInfo *info, Error **errp)
|
||||||
{
|
{
|
||||||
@ -1009,7 +1015,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
|||||||
assert(info->name);
|
assert(info->name);
|
||||||
trace_nbd_receive_negotiate_name(info->name);
|
trace_nbd_receive_negotiate_name(info->name);
|
||||||
|
|
||||||
result = nbd_start_negotiate(ioc, tlscreds, hostname, outioc,
|
result = nbd_start_negotiate(aio_context, ioc, tlscreds, hostname, outioc,
|
||||||
info->structured_reply, &zeroes, errp);
|
info->structured_reply, &zeroes, errp);
|
||||||
|
|
||||||
info->structured_reply = false;
|
info->structured_reply = false;
|
||||||
@ -1129,8 +1135,8 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
|
|||||||
QIOChannel *sioc = NULL;
|
QIOChannel *sioc = NULL;
|
||||||
|
|
||||||
*info = NULL;
|
*info = NULL;
|
||||||
result = nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, NULL,
|
result = nbd_start_negotiate(NULL, ioc, tlscreds, hostname, &sioc, true,
|
||||||
errp);
|
NULL, errp);
|
||||||
if (tlscreds && sioc) {
|
if (tlscreds && sioc) {
|
||||||
ioc = sioc;
|
ioc = sioc;
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ static void *nbd_client_thread(void *arg)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = nbd_receive_negotiate(QIO_CHANNEL(sioc),
|
ret = nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc),
|
||||||
NULL, NULL, NULL, &info, &local_error);
|
NULL, NULL, NULL, &info, &local_error);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (local_error) {
|
if (local_error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user