From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, vsementsov@virtuozzo.com,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v4 1/8] nbd: Include error names in trace messages
Date: Sat, 14 Oct 2017 20:01:24 -0500 [thread overview]
Message-ID: <20171015010131.12172-2-eblake@redhat.com> (raw)
In-Reply-To: <20171015010131.12172-1-eblake@redhat.com>
NBD errors were originally sent over the wire based on Linux errno
values; but not all the world is Linux, and not all platforms share
the same values. Since a number isn't very easy to decipher on all
platforms, update the trace messages to include the name of NBD
errors being sent/received over the wire. Tweak the trace messages
to be at the point where we are using the NBD error, not the
translation to the host errno values.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
nbd/nbd-internal.h | 1 +
nbd/client.c | 3 ++-
nbd/common.c | 23 +++++++++++++++++++++++
nbd/server.c | 3 ++-
nbd/trace-events | 4 ++--
5 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
index 11a130d050..4bfe5be884 100644
--- a/nbd/nbd-internal.h
+++ b/nbd/nbd-internal.h
@@ -126,6 +126,7 @@ const char *nbd_opt_lookup(uint32_t opt);
const char *nbd_rep_lookup(uint32_t rep);
const char *nbd_info_lookup(uint16_t info);
const char *nbd_cmd_lookup(uint16_t info);
+const char *nbd_err_lookup(int err);
int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);
diff --git a/nbd/client.c b/nbd/client.c
index cd5a2c80ac..59d7c9d49f 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -940,6 +940,8 @@ int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
reply->error = ldl_be_p(buf + 4);
reply->handle = ldq_be_p(buf + 8);
+ trace_nbd_receive_reply(magic, reply->error, nbd_err_lookup(reply->error),
+ reply->handle);
reply->error = nbd_errno_to_system_errno(reply->error);
if (reply->error == ESHUTDOWN) {
@@ -947,7 +949,6 @@ int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
error_setg(errp, "server shutting down");
return -EINVAL;
}
- trace_nbd_receive_reply(magic, reply->error, reply->handle);
if (magic != NBD_SIMPLE_REPLY_MAGIC) {
error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic);
diff --git a/nbd/common.c b/nbd/common.c
index 59a5316be9..7456021f7e 100644
--- a/nbd/common.c
+++ b/nbd/common.c
@@ -148,3 +148,26 @@ const char *nbd_cmd_lookup(uint16_t cmd)
return "<unknown>";
}
}
+
+
+const char *nbd_err_lookup(int err)
+{
+ switch (err) {
+ case NBD_SUCCESS:
+ return "success";
+ case NBD_EPERM:
+ return "EPERM";
+ case NBD_EIO:
+ return "EIO";
+ case NBD_ENOMEM:
+ return "ENOMEM";
+ case NBD_EINVAL:
+ return "EINVAL";
+ case NBD_ENOSPC:
+ return "ENOSPC";
+ case NBD_ESHUTDOWN:
+ return "ESHUTDOWN";
+ default:
+ return "<unknown>";
+ }
+}
diff --git a/nbd/server.c b/nbd/server.c
index 3df3548d6d..459e00c553 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1227,7 +1227,8 @@ static int nbd_co_send_simple_reply(NBDClient *client,
{.iov_base = data, .iov_len = len}
};
- trace_nbd_co_send_simple_reply(handle, nbd_err, len);
+ trace_nbd_co_send_simple_reply(handle, nbd_err, nbd_err_lookup(nbd_err),
+ len);
set_be_simple_reply(&reply, nbd_err, handle);
return nbd_co_send_iov(client, iov, len ? 2 : 1, errp);
diff --git a/nbd/trace-events b/nbd/trace-events
index e27614f050..9a72f458b2 100644
--- a/nbd/trace-events
+++ b/nbd/trace-events
@@ -29,7 +29,7 @@ nbd_client_loop_ret(int ret, const char *error) "NBD loop returned %d: %s"
nbd_client_clear_queue(void) "Clearing NBD queue"
nbd_client_clear_socket(void) "Clearing NBD socket"
nbd_send_request(uint64_t from, uint32_t len, uint64_t handle, uint16_t flags, uint16_t type, const char *name) "Sending request to server: { .from = %" PRIu64", .len = %" PRIu32 ", .handle = %" PRIu64 ", .flags = 0x%" PRIx16 ", .type = %" PRIu16 " (%s) }"
-nbd_receive_reply(uint32_t magic, int32_t error, uint64_t handle) "Got reply: { magic = 0x%" PRIx32 ", .error = % " PRId32 ", handle = %" PRIu64" }"
+nbd_receive_reply(uint32_t magic, int32_t error, const char *errname, uint64_t handle) "Got reply: { magic = 0x%" PRIx32 ", .error = % " PRId32 " (%s), handle = %" PRIu64" }"
# nbd/server.c
nbd_negotiate_send_rep_len(uint32_t opt, const char *optname, uint32_t type, const char *typename, uint32_t len) "Reply opt=0x%" PRIx32 " (%s), type=0x%" PRIx32 " (%s), len=%" PRIu32
@@ -53,7 +53,7 @@ nbd_negotiate_success(void) "Negotiation succeeded"
nbd_receive_request(uint32_t magic, uint16_t flags, uint16_t type, uint64_t from, uint32_t len) "Got request: { magic = 0x%" PRIx32 ", .flags = 0x%" PRIx16 ", .type = 0x%" PRIx16 ", from = %" PRIu64 ", len = %" PRIu32 " }"
nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching clients to AIO context %p\n"
nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clients from AIO context %p\n"
-nbd_co_send_simple_reply(uint64_t handle, uint32_t error, int len) "Send simple reply: handle = %" PRIu64 ", error = %" PRIu32 ", len = %d"
+nbd_co_send_simple_reply(uint64_t handle, uint32_t error, const char *errname, int len) "Send simple reply: handle = %" PRIu64 ", error = %" PRIu32 " (%s), len = %d"
nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const char *name) "Decoding type: handle = %" PRIu64 ", type = %" PRIu16 " (%s)"
nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Payload received: handle = %" PRIu64 ", len = %" PRIu32
nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s)"
--
2.13.6
next prev parent reply other threads:[~2017-10-15 1:01 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-15 1:01 [Qemu-devel] [PATCH v4 0/8] nbd mimimal structured read Eric Blake
2017-10-15 1:01 ` Eric Blake [this message]
2017-10-16 8:30 ` [Qemu-devel] [PATCH v4 1/8] nbd: Include error names in trace messages Vladimir Sementsov-Ogievskiy
2017-10-16 18:05 ` Eric Blake
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 2/8] nbd: Move nbd_errno_to_system_errno() to public header Eric Blake
2017-10-16 8:33 ` Vladimir Sementsov-Ogievskiy
2017-10-16 12:12 ` Eric Blake
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 3/8] nbd: Expose constants and structs for structured read Eric Blake
2017-10-16 8:49 ` Vladimir Sementsov-Ogievskiy
2017-10-16 12:15 ` Eric Blake
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 4/8] nbd: Minimal structured read for server Eric Blake
2017-10-16 9:49 ` Vladimir Sementsov-Ogievskiy
2017-10-16 12:18 ` Eric Blake
2017-10-16 15:41 ` Eric Blake
2017-10-16 19:29 ` Eric Blake
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 5/8] nbd/server: Include human-readable message in structured errors Eric Blake
2017-10-16 10:59 ` Vladimir Sementsov-Ogievskiy
2017-10-16 12:26 ` Eric Blake
2017-10-19 21:39 ` Eric Blake
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 6/8] nbd/client: refactor nbd_receive_starttls Eric Blake
2017-10-16 11:09 ` Vladimir Sementsov-Ogievskiy
2017-10-19 19:31 ` Eric Blake
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 7/8] nbd/client: prepare nbd_receive_reply for structured reply Eric Blake
2017-10-16 11:28 ` Vladimir Sementsov-Ogievskiy
2017-10-15 1:01 ` [Qemu-devel] [PATCH v4 8/8] nbd: Move nbd_read() to common header Eric Blake
2017-10-16 11:31 ` Vladimir Sementsov-Ogievskiy
2017-10-17 12:57 ` [Qemu-devel] [PATCH v4 RFC 9/8] nbd: Minimal structured read for client Vladimir Sementsov-Ogievskiy
2017-10-17 21:17 ` Eric Blake
2017-10-19 20:46 ` Eric Blake
2017-10-19 19:06 ` Eric Blake
2017-10-19 19:47 ` 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=20171015010131.12172-2-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--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).