From patchwork Sun Oct 15 01:01:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 825897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yF38q0JPrz9sRq for ; Sun, 15 Oct 2017 12:02:48 +1100 (AEDT) Received: from localhost ([::1]:55660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3XKF-0005Or-Pt for incoming@patchwork.ozlabs.org; Sat, 14 Oct 2017 21:02:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3XJI-0005CD-5o for qemu-devel@nongnu.org; Sat, 14 Oct 2017 21:01:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3XJG-00016P-Va for qemu-devel@nongnu.org; Sat, 14 Oct 2017 21:01:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59516) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e3XJC-0000mq-UF; Sat, 14 Oct 2017 21:01:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE28C5D689; Sun, 15 Oct 2017 01:01:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EE28C5D689 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com Received: from red.redhat.com (ovpn-122-223.rdu2.redhat.com [10.10.122.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1903960F85; Sun, 15 Oct 2017 01:01:36 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 14 Oct 2017 20:01:24 -0500 Message-Id: <20171015010131.12172-2-eblake@redhat.com> In-Reply-To: <20171015010131.12172-1-eblake@redhat.com> References: <20171015010131.12172-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 15 Oct 2017 01:01:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 1/8] nbd: Include error names in trace messages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Vladimir Sementsov-Ogievskiy --- 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 ""; } } + + +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 ""; + } +} 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)"