From: "Richard W.M. Jones" <rjones@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, vsementsov@yandex-team.ru,
eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com
Subject: [PATCH nbd 1/4] nbd: Add multi-conn option
Date: Thu, 9 Mar 2023 11:39:43 +0000 [thread overview]
Message-ID: <20230309113946.1528247-2-rjones@redhat.com> (raw)
In-Reply-To: <20230309113946.1528247-1-rjones@redhat.com>
Add multi-conn option to the NBD client. This commit just adds the
option, it is not functional.
Setting this to a value > 1 permits multiple connections to the NBD
server; a typical value might be 4. The default is 1, meaning only a
single connection is made. If the NBD server does not advertise that
it is safe for multi-conn then this setting is forced to 1.
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
block/nbd.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/block/nbd.c b/block/nbd.c
index bf2894ad5c..5ffae0b798 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -49,6 +49,7 @@
#define EN_OPTSTR ":exportname="
#define MAX_NBD_REQUESTS 16
+#define MAX_MULTI_CONN 16
#define HANDLE_TO_INDEX(bs, handle) ((handle) ^ (uint64_t)(intptr_t)(bs))
#define INDEX_TO_HANDLE(bs, index) ((index) ^ (uint64_t)(intptr_t)(bs))
@@ -98,6 +99,7 @@ typedef struct BDRVNBDState {
/* Connection parameters */
uint32_t reconnect_delay;
uint32_t open_timeout;
+ uint32_t multi_conn;
SocketAddress *saddr;
char *export;
char *tlscredsid;
@@ -1803,6 +1805,15 @@ static QemuOptsList nbd_runtime_opts = {
"attempts until successful or until @open-timeout seconds "
"have elapsed. Default 0",
},
+ {
+ .name = "multi-conn",
+ .type = QEMU_OPT_NUMBER,
+ .help = "If > 1 permit up to this number of connections to the "
+ "server. The server must also advertise multi-conn "
+ "support. If <= 1, only a single connection is made "
+ "to the server even if the server advertises multi-conn. "
+ "Default 1",
+ },
{ /* end of list */ }
},
};
@@ -1858,6 +1869,10 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
s->reconnect_delay = qemu_opt_get_number(opts, "reconnect-delay", 0);
s->open_timeout = qemu_opt_get_number(opts, "open-timeout", 0);
+ s->multi_conn = qemu_opt_get_number(opts, "multi-conn", 1);
+ if (s->multi_conn > MAX_MULTI_CONN) {
+ s->multi_conn = MAX_MULTI_CONN;
+ }
ret = 0;
@@ -1912,6 +1927,15 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
nbd_client_connection_enable_retry(s->conn);
+ /*
+ * We set s->multi_conn in nbd_process_options above, but now that
+ * we have connected if the server doesn't advertise that it is
+ * safe for multi-conn, force it to 1.
+ */
+ if (!(s->info.flags & NBD_FLAG_CAN_MULTI_CONN)) {
+ s->multi_conn = 1;
+ }
+
return 0;
fail:
--
2.39.2
next prev parent reply other threads:[~2023-03-09 11:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 11:39 [PATCH nbd 0/4] Enable multi-conn NBD [for discussion only] Richard W.M. Jones
2023-03-09 11:39 ` Richard W.M. Jones [this message]
2023-03-10 22:17 ` [PATCH nbd 1/4] nbd: Add multi-conn option Eric Blake
2023-03-10 22:29 ` Richard W.M. Jones
2023-03-09 11:39 ` [PATCH nbd 2/4] nbd: Split out block device state from underlying NBD connections Richard W.M. Jones
2023-03-14 12:13 ` Eric Blake
2023-03-09 11:39 ` [PATCH nbd 3/4] nbd: Open multiple NBD connections if multi-conn is set Richard W.M. Jones
2023-03-09 11:39 ` [PATCH nbd 4/4] nbd: Enable multi-conn using round-robin Richard W.M. Jones
2023-03-10 17:43 ` [PATCH nbd 0/4] Enable multi-conn NBD [for discussion only] Vladimir Sementsov-Ogievskiy
2023-03-10 19:04 ` Eric Blake
2023-03-10 19:19 ` Richard W.M. Jones
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=20230309113946.1528247-2-rjones@redhat.com \
--to=rjones@redhat.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/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).