aboutsummaryrefslogtreecommitdiff
path: root/block/nbd.c
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2021-06-10 13:08:01 +0300
committerEric Blake <eblake@redhat.com>2021-06-18 12:21:22 -0500
commit91e0998f5ab88e575b5d1b9bc55e0d179b9224f1 (patch)
treea50c86169e03ef8fd622d4242e000827c289c11d /block/nbd.c
parenta71d597b989fd701b923f09b3c20ac4fcaa55e81 (diff)
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>
Diffstat (limited to 'block/nbd.c')
-rw-r--r--block/nbd.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/block/nbd.c b/block/nbd.c
index 5e7e238b47..5cfb749e08 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -122,15 +122,20 @@ static void nbd_clear_bdrvstate(BlockDriverState *bs)
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)
{
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 :
NBD_CLIENT_CONNECTING_NOWAIT;
}
} 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);
}
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
* 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);
}
@@ -499,7 +504,7 @@ static coroutine_fn void nbd_connection_entry(void *opaque)
nbd_co_reconnect_loop(s);
}
- if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
+ if (!nbd_client_connected(s)) {
continue;
}
@@ -578,7 +583,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
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;
goto err;
}
@@ -605,8 +610,7 @@ static int nbd_co_send_request(BlockDriverState *bs,
if (qiov) {
qio_channel_set_cork(s->ioc, true);
rc = nbd_send_request(s->ioc, request);
- if (qatomic_load_acquire(&s->state) == NBD_CLIENT_CONNECTED &&
- rc >= 0) {
+ if (nbd_client_connected(s) && rc >= 0) {
if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov,
NULL) < 0) {
rc = -EIO;
@@ -931,7 +935,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk(
s->requests[i].receiving = true;
qemu_coroutine_yield();
s->requests[i].receiving = false;
- if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
+ if (!nbd_client_connected(s)) {
error_setg(errp, "Connection closed");
return -EIO;
}
@@ -1090,7 +1094,7 @@ static bool nbd_reply_chunk_iter_receive(BDRVNBDState *s,
NBDReply local_reply;
NBDStructuredReplyChunk *chunk;
Error *local_err = NULL;
- if (qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
+ if (!nbd_client_connected(s)) {
error_setg(&local_err, "Connection closed");
nbd_iter_channel_error(iter, -EIO, &local_err);
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. */
- if (nbd_reply_is_simple(reply) ||
- qatomic_load_acquire(&s->state) != NBD_CLIENT_CONNECTED) {
+ if (nbd_reply_is_simple(reply) || !nbd_client_connected(s)) {
goto break_loop;
}