Skip to content

Commit

Permalink
nbd/client-connection: add option for non-blocking connection attempt
Browse files Browse the repository at this point in the history
We'll need a possibility of non-blocking nbd_co_establish_connection(),
so that it returns immediately, and it returns success only if a
connections was previously established in background.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210610100802.5888-30-vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and ebblake committed Jun 15, 2021
1 parent eb45878 commit 729f341
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion block/nbd.c
Expand Up @@ -364,7 +364,7 @@ static int coroutine_fn nbd_co_do_establish_connection(BlockDriverState *bs,

assert(!s->ioc);

s->ioc = nbd_co_establish_connection(s->conn, &s->info, errp);
s->ioc = nbd_co_establish_connection(s->conn, &s->info, true, errp);
if (!s->ioc) {
return -ECONNREFUSED;
}
Expand Down
2 changes: 1 addition & 1 deletion include/block/nbd.h
Expand Up @@ -420,7 +420,7 @@ void nbd_client_connection_release(NBDClientConnection *conn);

QIOChannel *coroutine_fn
nbd_co_establish_connection(NBDClientConnection *conn, NBDExportInfo *info,
Error **errp);
bool blocking, Error **errp);

void coroutine_fn nbd_co_establish_connection_cancel(NBDClientConnection *conn);

Expand Down
8 changes: 7 additions & 1 deletion nbd/client-connection.c
Expand Up @@ -266,6 +266,8 @@ void nbd_client_connection_release(NBDClientConnection *conn)
* otherwise the thread is not running, so start a thread and wait for
* completion
*
* If @blocking is false, don't wait for the thread, return immediately.
*
* If @info is not NULL, also do nbd-negotiation after successful connection.
* In this case info is used only as out parameter, and is fully initialized by
* nbd_co_establish_connection(). "IN" fields of info as well as related only to
Expand All @@ -274,7 +276,7 @@ void nbd_client_connection_release(NBDClientConnection *conn)
*/
QIOChannel *coroutine_fn
nbd_co_establish_connection(NBDClientConnection *conn, NBDExportInfo *info,
Error **errp)
bool blocking, Error **errp)
{
QIOChannel *ioc;
QemuThread thread;
Expand Down Expand Up @@ -314,6 +316,10 @@ nbd_co_establish_connection(NBDClientConnection *conn, NBDExportInfo *info,
connect_thread_func, conn, QEMU_THREAD_DETACHED);
}

if (!blocking) {
return NULL;
}

conn->wait_co = qemu_coroutine_self();
}

Expand Down

0 comments on commit 729f341

Please sign in to comment.