From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: armbru@redhat.com, mreitz@redhat.com, kwolf@redhat.com,
pbonzini@redhat.com, eblake@redhat.com, vsementsov@virtuozzo.com,
den@openvz.org
Subject: [Qemu-devel] [PATCH v3 09/11] block/nbd: add cmdline and qapi parameters for nbd reconnect
Date: Sat, 9 Jun 2018 18:32:15 +0300 [thread overview]
Message-ID: <20180609153217.19683-10-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20180609153217.19683-1-vsementsov@virtuozzo.com>
Add two parameters:
reconnect-attempts, which defines maximum number of reconnects, after
which:
- open will fail
- block operations will fail
Note: on open, we actually have reconnect-attempts+1 connection
attempts, the first one is not REconnect.
reconnect-timeout, timeout in nanoseconds between reconnects.
Realization of these options is in the following patch.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
qapi/block-core.json | 12 +++++++++++-
block/nbd-client.h | 2 ++
block/nbd-client.c | 13 +++++++++++++
block/nbd.c | 22 +++++++++++++++++++++-
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 4b1de474a9..4abba9d38e 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3356,12 +3356,22 @@
#
# @tls-creds: TLS credentials ID
#
+# @reconnect-attempts: number of connection attempts on disconnect.
+# Must be >= 0. Default is 0. On nbd disk open, there would
+# be maximum of @reconnect-attempts + 1 total tries to
+# connect
+#
+# @reconnect-timeout: timeout between reconnect attempts in nanoseconds. Default
+# is 1000000000 (one second)
+#
# Since: 2.9
##
{ 'struct': 'BlockdevOptionsNbd',
'data': { 'server': 'SocketAddress',
'*export': 'str',
- '*tls-creds': 'str' } }
+ '*tls-creds': 'str',
+ '*reconnect-attempts': 'uint64',
+ '*reconnect-timeout': 'uint64' } }
##
# @BlockdevOptionsRaw:
diff --git a/block/nbd-client.h b/block/nbd-client.h
index f6c8052573..2561e1ea42 100644
--- a/block/nbd-client.h
+++ b/block/nbd-client.h
@@ -56,6 +56,8 @@ int nbd_client_init(BlockDriverState *bs,
const char *export_name,
QCryptoTLSCreds *tlscreds,
const char *hostname,
+ uint64_t reconnect_attempts,
+ uint64_t reconnect_timeout,
Error **errp);
void nbd_client_close(BlockDriverState *bs);
diff --git a/block/nbd-client.c b/block/nbd-client.c
index 44ac4ebc31..f22ed7f404 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -86,6 +86,8 @@ typedef struct NBDConnection {
const char *export;
QCryptoTLSCreds *tlscreds;
const char *hostname;
+ uint64_t reconnect_attempts;
+ uint64_t reconnect_timeout;
} NBDConnection;
static coroutine_fn void nbd_connection_entry(void *opaque)
@@ -96,6 +98,13 @@ static coroutine_fn void nbd_connection_entry(void *opaque)
int ret = 0;
Error *local_err = NULL;
+ if (con->reconnect_attempts != 0) {
+ error_setg(&s->connect_err, "Reconnect is not supported yet");
+ s->connect_status = -EINVAL;
+ nbd_channel_error(s, s->connect_status);
+ return;
+ }
+
s->connect_status = nbd_client_connect(con->bs, con->saddr,
con->export, con->tlscreds,
con->hostname, &s->connect_err);
@@ -1106,6 +1115,8 @@ int nbd_client_init(BlockDriverState *bs,
const char *export,
QCryptoTLSCreds *tlscreds,
const char *hostname,
+ uint64_t reconnect_attempts,
+ uint64_t reconnect_timeout,
Error **errp)
{
NBDClientSession *client = nbd_get_client_session(bs);
@@ -1116,6 +1127,8 @@ int nbd_client_init(BlockDriverState *bs,
con->export = export;
con->tlscreds = tlscreds;
con->hostname = hostname;
+ con->reconnect_attempts = reconnect_attempts;
+ con->reconnect_timeout = reconnect_timeout;
qemu_co_mutex_init(&client->send_mutex);
qemu_co_queue_init(&client->free_sema);
diff --git a/block/nbd.c b/block/nbd.c
index a851b8cd68..8c81d4a151 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -364,6 +364,20 @@ static QemuOptsList nbd_runtime_opts = {
.type = QEMU_OPT_STRING,
.help = "ID of the TLS credentials to use",
},
+ {
+ .name = "reconnect-attempts",
+ .type = QEMU_OPT_NUMBER,
+ .help = "Number of connection attempts on disconnect. "
+ "Must be >= 0. Default is 0. On nbd disk open, there would "
+ "be maximum of @reconnect-attempts + 1 total tries to "
+ "connect",
+ },
+ {
+ .name = "reconnect-timeout",
+ .type = QEMU_OPT_NUMBER,
+ .help = "Timeout between reconnect attempts in nanoseconds. "
+ "Default is 1000000000 (one second)",
+ },
{ /* end of list */ }
},
};
@@ -376,6 +390,8 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
Error *local_err = NULL;
QCryptoTLSCreds *tlscreds = NULL;
const char *hostname = NULL;
+ uint64_t reconnect_attempts;
+ uint64_t reconnect_timeout;
int ret = -EINVAL;
opts = qemu_opts_create(&nbd_runtime_opts, NULL, 0, &error_abort);
@@ -413,8 +429,12 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
hostname = s->saddr->u.inet.host;
}
+ reconnect_attempts = qemu_opt_get_number(opts, "reconnect-attempts", 0);
+ reconnect_timeout = qemu_opt_get_number(opts, "reconnect-timeout",
+ 1000000000L);
/* NBD handshake */
- ret = nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname, errp);
+ ret = nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname,
+ reconnect_attempts, reconnect_timeout, errp);
error:
if (tlscreds) {
--
2.11.1
next prev parent reply other threads:[~2018-06-09 15:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-09 15:32 [Qemu-devel] [PATCH v3 00/11] NBD reconnect Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 01/11] block/nbd-client: split channel errors from export errors Vladimir Sementsov-Ogievskiy
2018-07-20 20:14 ` Eric Blake
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 02/11] block/nbd: move connection code from block/nbd to block/nbd-client Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 03/11] block/nbd-client: split connection from initialization Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 04/11] block/nbd-client: fix nbd_reply_chunk_iter_receive Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 05/11] block/nbd-client: don't check ioc Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 06/11] block/nbd-client: move from quit to state Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 07/11] block/nbd-client: rename read_reply_co to connection_co Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 08/11] block/nbd-client: move connecting " Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` Vladimir Sementsov-Ogievskiy [this message]
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 10/11] block/nbd-client: nbd reconnect Vladimir Sementsov-Ogievskiy
2018-06-12 12:47 ` Vladimir Sementsov-Ogievskiy
2018-06-12 14:51 ` Vladimir Sementsov-Ogievskiy
2018-06-09 15:32 ` [Qemu-devel] [PATCH v3 11/11] iotests: test " Vladimir Sementsov-Ogievskiy
2018-07-03 13:46 ` [Qemu-devel] [PATCH v3 00/11] NBD reconnect Vladimir Sementsov-Ogievskiy
2018-07-03 16:31 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180609153217.19683-10-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).