From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: Hmreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com,
eblake@redhat.com, vsementsov@virtuozzo.com, den@openvz.org
Subject: [Qemu-devel] [PATCH 7/8] nbd/client: refactor nbd_receive_starttls
Date: Mon, 25 Sep 2017 16:58:00 +0300 [thread overview]
Message-ID: <20170925135801.144261-8-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20170925135801.144261-1-vsementsov@virtuozzo.com>
Split out nbd_receive_simple_option to be reused for structured reply
option.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
nbd/client.c | 64 ++++++++++++++++++++++++++++++++++++++++----------------
nbd/trace-events | 7 ++++---
2 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/nbd/client.c b/nbd/client.c
index cd5a2c80ac..51ae492e92 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -540,35 +540,63 @@ static int nbd_receive_query_exports(QIOChannel *ioc,
}
}
-static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
- QCryptoTLSCreds *tlscreds,
- const char *hostname, Error **errp)
+/* nbd_request_simple_option
+ * return 1 for successful negotiation,
+ * 0 if operation is unsupported,
+ * -1 with errp set for any other error
+ */
+static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
{
nbd_opt_reply reply;
- QIOChannelTLS *tioc;
- struct NBDTLSHandshakeData data = { 0 };
- trace_nbd_receive_starttls_request();
- if (nbd_send_option_request(ioc, NBD_OPT_STARTTLS, 0, NULL, errp) < 0) {
- return NULL;
+ trace_nbd_receive_simple_option_request(opt, nbd_opt_lookup(opt));
+ if (nbd_send_option_request(ioc, opt, 0, NULL, errp) < 0) {
+ return -1;
}
- trace_nbd_receive_starttls_reply();
- if (nbd_receive_option_reply(ioc, NBD_OPT_STARTTLS, &reply, errp) < 0) {
- return NULL;
+ trace_nbd_receive_simple_option_reply(opt, nbd_opt_lookup(opt));
+ if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
+ return -1;
}
- if (reply.type != NBD_REP_ACK) {
- error_setg(errp, "Server rejected request to start TLS %" PRIx32,
- reply.type);
+ if (reply.length != 0) {
+ error_setg(errp, "Option %d ('%s') response length is %" PRIu32
+ " (it should be zero)", opt, nbd_opt_lookup(opt),
+ reply.length);
nbd_send_opt_abort(ioc);
- return NULL;
+ return -1;
}
- if (reply.length != 0) {
- error_setg(errp, "Start TLS response was not zero %" PRIu32,
- reply.length);
+ if (reply.type == NBD_REP_ERR_UNSUP) {
+ return 1;
+ }
+
+ if (reply.type != NBD_REP_ACK) {
+ error_setg(errp, "Server rejected request for option %d (%s) "
+ "with reply %" PRIx32 " (%s)", opt, nbd_opt_lookup(opt),
+ reply.type, nbd_rep_lookup(reply.type));
nbd_send_opt_abort(ioc);
+ return -1;
+ }
+
+ trace_nbd_receive_simple_option_approved(opt, nbd_opt_lookup(opt));
+ return 0;
+}
+
+static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
+ QCryptoTLSCreds *tlscreds,
+ const char *hostname, Error **errp)
+{
+ int ret;
+ QIOChannelTLS *tioc;
+ struct NBDTLSHandshakeData data = { 0 };
+
+ ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp);
+ if (ret <= 0) {
+ if (ret == 0) {
+ error_setg(errp, "Server don't support STARTTLS option");
+ nbd_send_opt_abort(ioc);
+ }
return NULL;
}
diff --git a/nbd/trace-events b/nbd/trace-events
index 48a4f27682..ea44e6963f 100644
--- a/nbd/trace-events
+++ b/nbd/trace-events
@@ -9,9 +9,10 @@ nbd_opt_go_info_unknown(int info, const char *name) "Ignoring unknown info %d (%
nbd_opt_go_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t maximum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32
nbd_receive_query_exports_start(const char *wantname) "Querying export list for '%s'"
nbd_receive_query_exports_success(const char *wantname) "Found desired export name '%s'"
-nbd_receive_starttls_request(void) "Requesting TLS from server"
-nbd_receive_starttls_reply(void) "Getting TLS reply from server"
-nbd_receive_starttls_new_client(void) "TLS request approved, setting up TLS"
+nbd_receive_simple_option_request(int opt, const char *name) "Requesting option %d (%s) from server"
+nbd_receive_simple_option_reply(int opt, const char *name) "Getting reply for option %d (%s) from server"
+nbd_receive_simple_option_approved(int opt, const char *name) "Option %d (%s) approved"
+nbd_receive_starttls_new_client(void) "Setting up TLS"
nbd_receive_starttls_tls_handshake(void) "Starting TLS handshake"
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
--
2.11.1
next prev parent reply other threads:[~2017-09-25 13:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-25 13:57 [Qemu-devel] [PATCH 0/8] nbd minimal structured read Vladimir Sementsov-Ogievskiy
2017-09-25 13:57 ` [Qemu-devel] [PATCH 1/8] block/nbd-client: assert qiov len once in nbd_co_request Vladimir Sementsov-Ogievskiy
2017-09-25 21:58 ` Eric Blake
2017-09-25 13:57 ` [Qemu-devel] [PATCH 2/8] block/nbd-client: refactor nbd_co_receive_reply Vladimir Sementsov-Ogievskiy
2017-09-25 21:59 ` Eric Blake
2017-09-25 13:57 ` [Qemu-devel] [PATCH 3/8] nbd: rename NBD_REPLY_MAGIC to NBD_SIMPLE_REPLY_MAGIC Vladimir Sementsov-Ogievskiy
2017-09-25 13:57 ` [Qemu-devel] [PATCH 4/8] nbd-server: refactor simple reply sending Vladimir Sementsov-Ogievskiy
2017-09-25 13:57 ` [Qemu-devel] [PATCH 5/8] nbd: header constants indenting Vladimir Sementsov-Ogievskiy
2017-09-25 13:57 ` [Qemu-devel] [PATCH 6/8] nbd: Minimal structured read for server Vladimir Sementsov-Ogievskiy
2017-09-25 13:58 ` Vladimir Sementsov-Ogievskiy [this message]
2017-09-25 13:58 ` [Qemu-devel] [PATCH 8/8] nbd: Minimal structured read for client Vladimir Sementsov-Ogievskiy
2017-09-25 22:19 ` Eric Blake
2017-09-27 10:05 ` Vladimir Sementsov-Ogievskiy
2017-09-27 12:32 ` Vladimir Sementsov-Ogievskiy
2017-09-27 15:10 ` [Qemu-devel] [PATCH v1.1 DRAFT] " Vladimir Sementsov-Ogievskiy
2017-10-03 9:59 ` Vladimir Sementsov-Ogievskiy
2017-10-03 10:07 ` [Qemu-devel] [Qemu-block] [PATCH 8/8] " Paolo Bonzini
2017-10-03 12:26 ` Vladimir Sementsov-Ogievskiy
2017-10-03 14:05 ` Paolo Bonzini
2017-10-03 12:58 ` Vladimir Sementsov-Ogievskiy
2017-10-03 13:35 ` Vladimir Sementsov-Ogievskiy
2017-10-03 14:06 ` Paolo Bonzini
2017-10-05 9:59 ` Vladimir Sementsov-Ogievskiy
2017-10-05 10:02 ` Vladimir Sementsov-Ogievskiy
2017-10-05 10:36 ` Paolo Bonzini
2017-10-05 22:12 ` Eric Blake
2017-10-06 7:09 ` Vladimir Sementsov-Ogievskiy
2017-10-06 7:23 ` Vladimir Sementsov-Ogievskiy
2017-10-06 7:34 ` Vladimir Sementsov-Ogievskiy
2017-10-06 13:44 ` Eric Blake
2017-09-25 14:06 ` [Qemu-devel] [PATCH 0/8] nbd minimal structured read Vladimir Sementsov-Ogievskiy
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=20170925135801.144261-8-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=Hmreitz@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@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).