From nobody Thu Dec 18 08:07:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508452313788512.8938697304792; Thu, 19 Oct 2017 15:31:53 -0700 (PDT) Received: from localhost ([::1]:51446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5JLq-0000fQ-KC for importer@patchew.org; Thu, 19 Oct 2017 18:31:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5JHH-0005G7-Se for qemu-devel@nongnu.org; Thu, 19 Oct 2017 18:27:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5JHG-0004L5-AJ for qemu-devel@nongnu.org; Thu, 19 Oct 2017 18:26:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42508) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e5JHA-00048j-3t; Thu, 19 Oct 2017 18:26:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 241DD80484; Thu, 19 Oct 2017 22:26:51 +0000 (UTC) Received: from red.redhat.com (ovpn-121-90.rdu2.redhat.com [10.10.121.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56AE3648A5; Thu, 19 Oct 2017 22:26:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 241DD80484 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 19 Oct 2017 17:26:33 -0500 Message-Id: <20171019222637.17890-8-eblake@redhat.com> In-Reply-To: <20171019222637.17890-1-eblake@redhat.com> References: <20171019222637.17890-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 19 Oct 2017 22:26:51 +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 v5 07/11] nbd/server: Include human-readable message in structured errors 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: pbonzini@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The NBD spec permits including a human-readable error string if structured replies are in force, so we might as well send the client the message that we logged on any error. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- v5: allow NULL msg, cast away const for ease of use [Vladimir]; send correct length over the wire --- nbd/server.c | 20 +++++++++++++------- nbd/trace-events | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 9be93c4a52..e39d83fb69 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1280,24 +1280,25 @@ static int coroutine_fn nbd_co_send_structured_read= (NBDClient *client, static int coroutine_fn nbd_co_send_structured_error(NBDClient *client, uint64_t handle, uint32_t error, + const char *msg, Error **errp) { NBDStructuredError chunk; int nbd_err =3D system_errno_to_nbd_errno(error); struct iovec iov[] =3D { {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, - /* FIXME: Support human-readable error message */ + {.iov_base =3D (char *)msg, .iov_len =3D msg ? strlen(msg) : 0}, }; assert(nbd_err); trace_nbd_co_send_structured_error(handle, nbd_err, - nbd_err_lookup(nbd_err)); + nbd_err_lookup(nbd_err), msg ? msg = : ""); set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_ERROR, hand= le, - sizeof(chunk) - sizeof(chunk.h)); + sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len); stl_be_p(&chunk.error, nbd_err); - stw_be_p(&chunk.message_length, 0); + stw_be_p(&chunk.message_length, iov[1].iov_len); - return nbd_co_send_iov(client, iov, 1, errp); + return nbd_co_send_iov(client, iov, 1 + !!iov[1].iov_len, errp); } /* nbd_co_receive_request @@ -1398,6 +1399,7 @@ static coroutine_fn void nbd_trip(void *opaque) int flags; int reply_data_len =3D 0; Error *local_err =3D NULL; + char *msg =3D NULL; trace_nbd_trip(); if (client->closing) { @@ -1514,14 +1516,17 @@ reply: if (local_err) { /* If we get here, local_err was not a fatal error, and should be = sent * to the client. */ + assert(ret < 0); + msg =3D g_strdup(error_get_pretty(local_err)); error_report_err(local_err); local_err =3D NULL; } - if (client->structured_reply && request.type =3D=3D NBD_CMD_READ) { + if (client->structured_reply && + (ret < 0 || request.type =3D=3D NBD_CMD_READ)) { if (ret < 0) { ret =3D nbd_co_send_structured_error(req->client, request.hand= le, - -ret, &local_err); + -ret, msg, &local_err); } else { ret =3D nbd_co_send_structured_read(req->client, request.handl= e, request.from, req->data, @@ -1532,6 +1537,7 @@ reply: ret < 0 ? -ret : 0, req->data, reply_data_len, &local_e= rr); } + g_free(msg); if (ret < 0) { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; diff --git a/nbd/trace-events b/nbd/trace-events index 6894f8bbb4..52150bd738 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -57,7 +57,7 @@ nbd_blk_aio_attached(const char *name, void *ctx) "Export= %s: Attaching clients nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" nbd_co_send_simple_reply(uint64_t handle, uint32_t error, const char *errn= ame, int len) "Send simple reply: handle =3D %" PRIu64 ", error =3D %" PRIu= 32 " (%s), len =3D %d" nbd_co_send_structured_read(uint64_t handle, uint64_t offset, void *data, = size_t size) "Send structured read data reply: handle =3D %" PRIu64 ", offs= et =3D %" PRIu64 ", data =3D %p, len =3D %zu" -nbd_co_send_structured_error(uint64_t handle, int err, const char *errname= ) "Send structured error reply: handle =3D %" PRIu64 ", error =3D %d (%s)" +nbd_co_send_structured_error(uint64_t handle, int err, const char *errname= , const char *msg) "Send structured error reply: handle =3D %" PRIu64 ", er= ror =3D %d (%s), msg =3D '%s'" nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const c= har *name) "Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16 " (%s= )" nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Pa= yload received: handle =3D %" PRIu64 ", len =3D %" PRIu32 nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s= )" --=20 2.13.6