block/nbd: add nbd_client_connected() helper
We already have two similar helpers for other state. Let's add another one for convenience. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20210610100802.5888-32-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
a71d597b98
commit
91e0998f5a
25
block/nbd.c
25
block/nbd.c
@ -122,15 +122,20 @@ static void nbd_clear_bdrvstate(BlockDriverState *bs)
|
|||||||
s->x_dirty_bitmap = NULL;
|
s->x_dirty_bitmap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool nbd_client_connected(BDRVNBDState *s)
|
||||||
|
{
|
||||||
|
return qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
static void nbd_channel_error(BDRVNBDState *s, int ret)
|
static void nbd_channel_error(BDRVNBDState *s, int ret)
|
||||||
{
|
{
|
||||||
if (ret == -EIO) {
|
if (ret == -EIO) {
|
||||||
if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) {
|
if (nbd_client_connected(s)) {
|
||||||
s->state = s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT :
|
s->state = s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT :
|
||||||
NBD_CLIENT_CONNECTING_NOWAIT;
|
NBD_CLIENT_CONNECTING_NOWAIT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) {
|
if (nbd_client_connected(s)) {
|
||||||
qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
|
qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
|
||||||
}
|
}
|
||||||
s->state = NBD_CLIENT_QUIT;
|
s->state = NBD_CLIENT_QUIT;
|
||||||
@ -228,7 +233,7 @@ static void nbd_client_attach_aio_context(BlockDriverState *bs,
|
|||||||
* s->connection_co is either yielded from nbd_receive_reply or from
|
* s->connection_co is either yielded from nbd_receive_reply or from
|
||||||
* nbd_co_reconnect_loop()
|
* nbd_co_reconnect_loop()
|
||||||
*/
|
*/
|
||||||
if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED) {
|
if (nbd_client_connected(s)) {
|
||||||
qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context);
|
qio_channel_attach_aio_context(QIO_CHANNEL(s->ioc), new_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +504,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque)
|
|||||||
nbd_co_reconnect_loop(s);
|
nbd_co_reconnect_loop(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
|
if (!nbd_client_connected(s)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,7 +583,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
|||||||
qemu_co_queue_wait(&s->free_sema, &s->send_mutex);
|
qemu_co_queue_wait(&s->free_sema, &s->send_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
|
if (!nbd_client_connected(s)) {
|
||||||
rc = -EIO;
|
rc = -EIO;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -605,8 +610,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
|
|||||||
if (qiov) {
|
if (qiov) {
|
||||||
qio_channel_set_cork(s->ioc, true);
|
qio_channel_set_cork(s->ioc, true);
|
||||||
rc = nbd_send_request(s->ioc, request);
|
rc = nbd_send_request(s->ioc, request);
|
||||||
if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED &&
|
if (nbd_client_connected(s) && rc >= 0) {
|
||||||
rc >= 0) {
|
|
||||||
if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov,
|
if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov,
|
||||||
NULL) < 0) {
|
NULL) < 0) {
|
||||||
rc = -EIO;
|
rc = -EIO;
|
||||||
@ -931,7 +935,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk(
|
|||||||
s->requests[i].receiving = true;
|
s->requests[i].receiving = true;
|
||||||
qemu_coroutine_yield();
|
qemu_coroutine_yield();
|
||||||
s->requests[i].receiving = false;
|
s->requests[i].receiving = false;
|
||||||
if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
|
if (!nbd_client_connected(s)) {
|
||||||
error_setg(errp, "Connection closed");
|
error_setg(errp, "Connection closed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
@ -1090,7 +1094,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s,
|
|||||||
NBDReply local_reply;
|
NBDReply local_reply;
|
||||||
NBDStructuredReplyChunk *chunk;
|
NBDStructuredReplyChunk *chunk;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
|
if (!nbd_client_connected(s)) {
|
||||||
error_setg(&local_err, "Connection closed");
|
error_setg(&local_err, "Connection closed");
|
||||||
nbd_iter_channel_error(iter, -EIO, &local_err);
|
nbd_iter_channel_error(iter, -EIO, &local_err);
|
||||||
goto break_loop;
|
goto break_loop;
|
||||||
@ -1115,8 +1119,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply. */
|
/* Do not execute the body of NBD_FOREACH_REPLY_CHUNK for simple reply. */
|
||||||
if (nbd_reply_is_simple(reply) ||
|
if (nbd_reply_is_simple(reply) || !nbd_client_connected(s)) {
|
||||||
qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
|
|
||||||
goto break_loop;
|
goto break_loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user