From nobody Fri Dec 19 06:56:58 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 15091013782191008.4607200533724; Fri, 27 Oct 2017 03:49:38 -0700 (PDT) Received: from localhost ([::1]:56582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e82Cf-0007nR-T1 for importer@patchew.org; Fri, 27 Oct 2017 06:49:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e824W-0001MT-73 for qemu-devel@nongnu.org; Fri, 27 Oct 2017 06:41:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e824T-0005ff-2N for qemu-devel@nongnu.org; Fri, 27 Oct 2017 06:41:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e824Q-0005c8-44; Fri, 27 Oct 2017 06:40:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 373D661462; Fri, 27 Oct 2017 10:40:57 +0000 (UTC) Received: from red.redhat.com (ovpn-120-166.rdu2.redhat.com [10.10.120.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC5A15C549; Fri, 27 Oct 2017 10:40:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 373D661462 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 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 27 Oct 2017 12:40:33 +0200 Message-Id: <20171027104037.8319-9-eblake@redhat.com> In-Reply-To: <20171027104037.8319-1-eblake@redhat.com> References: <20171027104037.8319-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 27 Oct 2017 10:40:57 +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 v6 08/12] 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 --- v6: add R-b 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 5d6d9a2ddd..ea9fe9970f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1295,24 +1295,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 @@ -1413,6 +1414,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) { @@ -1529,14 +1531,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, @@ -1547,6 +1552,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