From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, nsoffer@redhat.com, rjones@redhat.com,
vsementsov@virtuozzo.com, qemu-block@nongnu.org,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 06/14] nbd/client: Move export name into NBDExportInfo
Date: Fri, 30 Nov 2018 16:03:35 -0600 [thread overview]
Message-ID: <20181130220344.3350618-7-eblake@redhat.com> (raw)
In-Reply-To: <20181130220344.3350618-1-eblake@redhat.com>
Refactor the 'name' parameter of nbd_receive_negotiate() from
being a separate parameter into being part of the in-out 'info'.
This also spills over to a simplification of nbd_opt_go().
The main driver for this refactoring is that an upcoming patch
would like to add support to qemu-nbd to list information about
all exports available on a server, where the name(s) will be
provided by the server instead of the client. But another benefit
is that we can now allow the client to explicitly specify the
empty export name "" even when connecting to an oldstyle server
(even if qemu is no longer such a server after commit 7f7dfe2a).
Signed-off-by: Eric Blake <eblake@redhat.com>
---
include/block/nbd.h | 8 ++++----
block/nbd-client.c | 5 +++--
nbd/client.c | 39 ++++++++++++++++++---------------------
qemu-nbd.c | 6 ++++--
nbd/trace-events | 2 +-
5 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 6a5bfe5d559..65feff8ba96 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -262,6 +262,7 @@ struct NBDExportInfo {
/* Set by client before nbd_receive_negotiate() */
bool request_sizes;
char *x_dirty_bitmap;
+ char *name; /* must be non-NULL */
/* In-out fields, set by client before nbd_receive_negotiate() and
* updated by server results during nbd_receive_negotiate() */
@@ -279,10 +280,9 @@ struct NBDExportInfo {
};
typedef struct NBDExportInfo NBDExportInfo;
-int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
- QCryptoTLSCreds *tlscreds, const char *hostname,
- QIOChannel **outioc, NBDExportInfo *info,
- Error **errp);
+int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
+ const char *hostname, QIOChannel **outioc,
+ NBDExportInfo *info, Error **errp);
int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info,
Error **errp);
int nbd_send_request(QIOChannel *ioc, NBDRequest *request);
diff --git a/block/nbd-client.c b/block/nbd-client.c
index fc5b7eda8ee..417971d8b05 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -984,10 +984,11 @@ int nbd_client_init(BlockDriverState *bs,
client->info.structured_reply = true;
client->info.base_allocation = true;
client->info.x_dirty_bitmap = g_strdup(x_dirty_bitmap);
- ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), export,
- tlscreds, hostname,
+ client->info.name = g_strdup(export ?: "");
+ ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), tlscreds, hostname,
&client->ioc, &client->info, errp);
g_free(client->info.x_dirty_bitmap);
+ g_free(client->info.name);
if (ret < 0) {
logout("Failed to negotiate with the NBD server\n");
return ret;
diff --git a/nbd/client.c b/nbd/client.c
index 17ee24492a4..b5818a99d21 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -320,15 +320,14 @@ static int nbd_receive_list(QIOChannel *ioc, const char *want, bool *match,
}
-/* Returns -1 if NBD_OPT_GO proves the export @wantname cannot be
+/* Returns -1 if NBD_OPT_GO proves the export @info->name cannot be
* used, 0 if NBD_OPT_GO is unsupported (fall back to NBD_OPT_LIST and
* NBD_OPT_EXPORT_NAME in that case), and > 0 if the export is good to
- * go (with @info populated). */
-static int nbd_opt_go(QIOChannel *ioc, const char *wantname,
- NBDExportInfo *info, Error **errp)
+ * go (with the rest of @info populated). */
+static int nbd_opt_go(QIOChannel *ioc, NBDExportInfo *info, Error **errp)
{
NBDOptionReply reply;
- uint32_t len = strlen(wantname);
+ uint32_t len = strlen(info->name);
uint16_t type;
int error;
char *buf;
@@ -338,10 +337,10 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname,
* flags still 0 is a witness of a broken server. */
info->flags = 0;
- trace_nbd_opt_go_start(wantname);
+ trace_nbd_opt_go_start(info->name);
buf = g_malloc(4 + len + 2 + 2 * info->request_sizes + 1);
stl_be_p(buf, len);
- memcpy(buf + 4, wantname, len);
+ memcpy(buf + 4, info->name, len);
/* At most one request, everything else up to server */
stw_be_p(buf + 4 + len, info->request_sizes);
if (info->request_sizes) {
@@ -726,10 +725,9 @@ static int nbd_negotiate_simple_meta_context(QIOChannel *ioc,
return 0;
}
-int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
- QCryptoTLSCreds *tlscreds, const char *hostname,
- QIOChannel **outioc, NBDExportInfo *info,
- Error **errp)
+int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
+ const char *hostname, QIOChannel **outioc,
+ NBDExportInfo *info, Error **errp)
{
uint64_t magic;
int rc;
@@ -739,6 +737,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
trace_nbd_receive_negotiate(tlscreds, hostname ? hostname : "<null>");
+ assert(info->name);
+ trace_nbd_receive_negotiate_name(info->name);
info->structured_reply = false;
info->base_allocation = false;
rc = -EINVAL;
@@ -807,10 +807,6 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
goto fail;
}
}
- if (!name) {
- trace_nbd_receive_negotiate_default_name();
- name = "";
- }
if (fixedNewStyle) {
int result;
@@ -826,7 +822,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
if (info->structured_reply && base_allocation) {
result = nbd_negotiate_simple_meta_context(
- ioc, name, info->x_dirty_bitmap ?: "base:allocation",
+ ioc, info->name,
+ info->x_dirty_bitmap ?: "base:allocation",
&info->meta_base_allocation_id, errp);
if (result < 0) {
goto fail;
@@ -839,7 +836,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
* TLS). If it is not available, fall back to
* NBD_OPT_LIST for nicer error messages about a missing
* export, then use NBD_OPT_EXPORT_NAME. */
- result = nbd_opt_go(ioc, name, info, errp);
+ result = nbd_opt_go(ioc, info, errp);
if (result < 0) {
goto fail;
}
@@ -852,12 +849,12 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
* query gives us better error reporting if the
* export name is not available.
*/
- if (nbd_receive_query_exports(ioc, name, errp) < 0) {
+ if (nbd_receive_query_exports(ioc, info->name, errp) < 0) {
goto fail;
}
}
/* write the export name request */
- if (nbd_send_option_request(ioc, NBD_OPT_EXPORT_NAME, -1, name,
+ if (nbd_send_option_request(ioc, NBD_OPT_EXPORT_NAME, -1, info->name,
errp) < 0) {
goto fail;
}
@@ -877,8 +874,8 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,
} else if (magic == NBD_CLIENT_MAGIC) {
uint32_t oldflags;
- if (name) {
- error_setg(errp, "Server does not support export names");
+ if (*info->name) {
+ error_setg(errp, "Server does not support non-empty export names");
goto fail;
}
if (tlscreds) {
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 866e64779f1..c57053a0795 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -263,7 +263,7 @@ static void *show_parts(void *arg)
static void *nbd_client_thread(void *arg)
{
char *device = arg;
- NBDExportInfo info = { .request_sizes = false, };
+ NBDExportInfo info = { .request_sizes = false, .name = g_strdup("") };
QIOChannelSocket *sioc;
int fd;
int ret;
@@ -278,7 +278,7 @@ static void *nbd_client_thread(void *arg)
goto out;
}
- ret = nbd_receive_negotiate(QIO_CHANNEL(sioc), NULL,
+ ret = nbd_receive_negotiate(QIO_CHANNEL(sioc),
NULL, NULL, NULL, &info, &local_error);
if (ret < 0) {
if (local_error) {
@@ -317,6 +317,7 @@ static void *nbd_client_thread(void *arg)
}
close(fd);
object_unref(OBJECT(sioc));
+ free(info.name);
kill(getpid(), SIGTERM);
return (void *) EXIT_SUCCESS;
@@ -325,6 +326,7 @@ out_fd:
out_socket:
object_unref(OBJECT(sioc));
out:
+ free(info.name);
kill(getpid(), SIGTERM);
return (void *) EXIT_FAILURE;
}
diff --git a/nbd/trace-events b/nbd/trace-events
index 5e1d4afe8e6..289337d0dc3 100644
--- a/nbd/trace-events
+++ b/nbd/trace-events
@@ -15,7 +15,7 @@ nbd_opt_meta_reply(const char *context, uint32_t id) "Received mapping of contex
nbd_receive_negotiate(void *tlscreds, const char *hostname) "Receiving negotiation tlscreds=%p hostname=%s"
nbd_receive_negotiate_magic(uint64_t magic) "Magic is 0x%" PRIx64
nbd_receive_negotiate_server_flags(uint32_t globalflags) "Global flags are 0x%" PRIx32
-nbd_receive_negotiate_default_name(void) "Using default NBD export name \"\""
+nbd_receive_negotiate_name(const char *name) "Requesting NBD export name \"%s\""
nbd_receive_negotiate_size_flags(uint64_t size, uint16_t flags) "Size is %" PRIu64 ", export flags 0x%" PRIx16
nbd_init_set_socket(void) "Setting NBD socket"
nbd_init_set_block_size(unsigned long block_size) "Setting block size to %lu"
--
2.17.2
next prev parent reply other threads:[~2018-11-30 22:04 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-30 22:03 [Qemu-devel] [PATCH for-4.0 00/14] nbd: add qemu-nbd --list Eric Blake
2018-11-30 22:03 ` [Qemu-devel] [PATCH 01/14] qemu-nbd: Use program name in error messages Eric Blake
2018-11-30 22:17 ` Richard W.M. Jones
2018-12-05 14:55 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 02/14] nbd/client: More consistent " Eric Blake
2018-11-30 22:20 ` Richard W.M. Jones
2018-12-05 15:03 ` Vladimir Sementsov-Ogievskiy
2018-12-10 22:03 ` Eric Blake
2018-11-30 22:03 ` [Qemu-devel] [PATCH 03/14] qemu-nbd: Fail earlier for -c/-d on non-linux Eric Blake
2018-11-30 22:23 ` Richard W.M. Jones
2018-12-05 15:20 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 04/14] qemu-nbd: Simplify --partition handling Eric Blake
2018-11-30 22:26 ` Richard W.M. Jones
2018-11-30 22:41 ` Eric Blake
2018-12-05 15:40 ` Vladimir Sementsov-Ogievskiy
2018-12-05 16:26 ` Eric Blake
2018-12-05 16:32 ` Eric Blake
2018-12-10 22:28 ` Eric Blake
2018-11-30 22:03 ` [Qemu-devel] [PATCH 05/14] nbd/client: Drop pointless buf variable Eric Blake
2018-11-30 22:30 ` Richard W.M. Jones
2018-11-30 22:54 ` Eric Blake
2018-12-05 15:59 ` Vladimir Sementsov-Ogievskiy
2018-12-05 16:29 ` Eric Blake
2018-12-05 16:38 ` Vladimir Sementsov-Ogievskiy
2018-12-05 16:49 ` Eric Blake
2018-11-30 22:03 ` Eric Blake [this message]
2018-11-30 22:34 ` [Qemu-devel] [PATCH 06/14] nbd/client: Move export name into NBDExportInfo Richard W.M. Jones
2018-12-05 17:26 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 07/14] nbd/client: Refactor nbd_negotiate_simple_meta_context() Eric Blake
2018-12-01 10:30 ` Richard W.M. Jones
2018-12-06 13:20 ` Vladimir Sementsov-Ogievskiy
2018-12-06 16:20 ` Eric Blake
2018-11-30 22:03 ` [Qemu-devel] [PATCH 08/14] nbd/client: Refactor nbd_receive_list() Eric Blake
2018-12-01 10:37 ` Richard W.M. Jones
2018-12-06 14:18 ` Vladimir Sementsov-Ogievskiy
2018-12-06 16:31 ` Eric Blake
2018-12-06 17:03 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 09/14] nbd/client: Refactor return of nbd_receive_negotiate() Eric Blake
2018-11-30 22:41 ` Richard W.M. Jones
2018-12-06 14:24 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 10/14] nbd/client: Split handshake into two functions Eric Blake
2018-12-01 10:41 ` Richard W.M. Jones
2018-12-06 15:16 ` Vladimir Sementsov-Ogievskiy
2018-12-06 17:06 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 11/14] nbd/client: Add nbd_receive_export_list() Eric Blake
2018-12-01 10:45 ` Richard W.M. Jones
2018-12-07 10:04 ` Vladimir Sementsov-Ogievskiy
2018-12-07 15:19 ` Eric Blake
2018-12-07 10:07 ` Vladimir Sementsov-Ogievskiy
2018-11-30 22:03 ` [Qemu-devel] [PATCH 12/14] nbd/client: Work around 3.0 bug for listing meta contexts Eric Blake
2018-12-07 11:21 ` Vladimir Sementsov-Ogievskiy
2018-12-07 15:21 ` Eric Blake
2018-11-30 22:03 ` [Qemu-devel] [PATCH 13/14] qemu-nbd: Add --list option Eric Blake
2018-12-01 10:58 ` Richard W.M. Jones
2018-12-07 12:48 ` Vladimir Sementsov-Ogievskiy
2018-12-07 15:36 ` Eric Blake
2018-12-07 16:49 ` Vladimir Sementsov-Ogievskiy
2018-12-07 16:49 ` Vladimir Sementsov-Ogievskiy
2018-12-07 16:59 ` Eric Blake
2018-11-30 22:03 ` [Qemu-devel] [PATCH 14/14] iotests: Enhance 223, 233 to cover 'qemu-nbd --list' Eric Blake
2018-12-01 11:04 ` Richard W.M. Jones
2018-12-07 13:08 ` Vladimir Sementsov-Ogievskiy
2018-12-01 7:42 ` [Qemu-devel] [PATCH for-4.0 00/14] nbd: add qemu-nbd --list Richard W.M. Jones
2018-12-01 13:57 ` Eric Blake
2018-12-01 15:00 ` 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=20181130220344.3350618-7-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--cc=vsementsov@virtuozzo.com \
/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).