mirror of https://github.com/xemu-project/xemu.git
nbd/server: Include human-readable message in structured errors
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 <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20171027104037.8319-9-eblake@redhat.com>
This commit is contained in:
parent
5c54e7fa71
commit
a57f6dea02
20
nbd/server.c
20
nbd/server.c
|
@ -1296,24 +1296,25 @@ static int coroutine_fn nbd_co_send_structured_read(NBDClient *client,
|
||||||
static int coroutine_fn nbd_co_send_structured_error(NBDClient *client,
|
static int coroutine_fn nbd_co_send_structured_error(NBDClient *client,
|
||||||
uint64_t handle,
|
uint64_t handle,
|
||||||
uint32_t error,
|
uint32_t error,
|
||||||
|
const char *msg,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
NBDStructuredError chunk;
|
NBDStructuredError chunk;
|
||||||
int nbd_err = system_errno_to_nbd_errno(error);
|
int nbd_err = system_errno_to_nbd_errno(error);
|
||||||
struct iovec iov[] = {
|
struct iovec iov[] = {
|
||||||
{.iov_base = &chunk, .iov_len = sizeof(chunk)},
|
{.iov_base = &chunk, .iov_len = sizeof(chunk)},
|
||||||
/* FIXME: Support human-readable error message */
|
{.iov_base = (char *)msg, .iov_len = msg ? strlen(msg) : 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(nbd_err);
|
assert(nbd_err);
|
||||||
trace_nbd_co_send_structured_error(handle, 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, handle,
|
set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_ERROR, handle,
|
||||||
sizeof(chunk) - sizeof(chunk.h));
|
sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len);
|
||||||
stl_be_p(&chunk.error, nbd_err);
|
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
|
/* nbd_co_receive_request
|
||||||
|
@ -1414,6 +1415,7 @@ static coroutine_fn void nbd_trip(void *opaque)
|
||||||
int flags;
|
int flags;
|
||||||
int reply_data_len = 0;
|
int reply_data_len = 0;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
char *msg = NULL;
|
||||||
|
|
||||||
trace_nbd_trip();
|
trace_nbd_trip();
|
||||||
if (client->closing) {
|
if (client->closing) {
|
||||||
|
@ -1530,14 +1532,17 @@ reply:
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
/* If we get here, local_err was not a fatal error, and should be sent
|
/* If we get here, local_err was not a fatal error, and should be sent
|
||||||
* to the client. */
|
* to the client. */
|
||||||
|
assert(ret < 0);
|
||||||
|
msg = g_strdup(error_get_pretty(local_err));
|
||||||
error_report_err(local_err);
|
error_report_err(local_err);
|
||||||
local_err = NULL;
|
local_err = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->structured_reply && request.type == NBD_CMD_READ) {
|
if (client->structured_reply &&
|
||||||
|
(ret < 0 || request.type == NBD_CMD_READ)) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret = nbd_co_send_structured_error(req->client, request.handle,
|
ret = nbd_co_send_structured_error(req->client, request.handle,
|
||||||
-ret, &local_err);
|
-ret, msg, &local_err);
|
||||||
} else {
|
} else {
|
||||||
ret = nbd_co_send_structured_read(req->client, request.handle,
|
ret = nbd_co_send_structured_read(req->client, request.handle,
|
||||||
request.from, req->data,
|
request.from, req->data,
|
||||||
|
@ -1548,6 +1553,7 @@ reply:
|
||||||
ret < 0 ? -ret : 0,
|
ret < 0 ? -ret : 0,
|
||||||
req->data, reply_data_len, &local_err);
|
req->data, reply_data_len, &local_err);
|
||||||
}
|
}
|
||||||
|
g_free(msg);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_prepend(&local_err, "Failed to send reply: ");
|
error_prepend(&local_err, "Failed to send reply: ");
|
||||||
goto disconnect;
|
goto disconnect;
|
||||||
|
|
|
@ -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 clients from 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, const char *errname, int len) "Send simple reply: handle = %" PRIu64 ", error = %" PRIu32 " (%s), 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_send_structured_read(uint64_t handle, uint64_t offset, void *data, size_t size) "Send structured read data reply: handle = %" PRIu64 ", offset = %" PRIu64 ", data = %p, len = %zu"
|
nbd_co_send_structured_read(uint64_t handle, uint64_t offset, void *data, size_t size) "Send structured read data reply: handle = %" PRIu64 ", offset = %" PRIu64 ", data = %p, len = %zu"
|
||||||
nbd_co_send_structured_error(uint64_t handle, int err, const char *errname) "Send structured error reply: handle = %" PRIu64 ", error = %d (%s)"
|
nbd_co_send_structured_error(uint64_t handle, int err, const char *errname, const char *msg) "Send structured error reply: handle = %" PRIu64 ", error = %d (%s), msg = '%s'"
|
||||||
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_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_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)"
|
nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s)"
|
||||||
|
|
Loading…
Reference in New Issue