json_config: fix error message for loading failures

resp->error is usually a JSON object, but it was printed as
a string. For objects, resp->len was the number of fields in
this object, definitely not a length of the string to print.
There was usually just 3 characters printed with no newline.

To print this object we should stringify it using our json_write
library, so that's this patch does.

Before:
json_config.c: 192:rpc_client_poller: *ERROR*: error response: {"co
(missing newline at the end)

After:
[2020-06-19 13:33:57.060869] json_config.c: 220:rpc_client_poller:
*ERROR*: error response:
{
  "code": -32601,
  "message": "Method not found"
}
[2020-06-19 13:33:57.061067] app.c: 714:spdk_app_stop: *WARNING*:
spdk_app_stop'd on non-zero

Change-Id: I5d7aeba2b972782f18b8da0141ed4bfd79833f80
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2971
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Darek Stojaczyk 2020-06-19 13:36:01 +02:00 committed by Tomasz Zawadzki
parent f53bf7676c
commit 1befc43b2d

View File

@ -158,6 +158,25 @@ rpc_client_check_timeout(struct load_json_config_ctx *ctx)
return 0; return 0;
} }
struct json_write_buf {
char data[1024];
unsigned cur_off;
};
static int
json_write_stdout(void *cb_ctx, const void *data, size_t size)
{
struct json_write_buf *buf = cb_ctx;
size_t rc;
rc = snprintf(buf->data + buf->cur_off, sizeof(buf->data) - buf->cur_off,
"%s", (const char *)data);
if (rc > 0) {
buf->cur_off += rc;
}
return rc == size ? 0 : -1;
}
static int static int
rpc_client_poller(void *arg) rpc_client_poller(void *arg)
{ {
@ -189,7 +208,17 @@ rpc_client_poller(void *arg)
assert(resp); assert(resp);
if (resp->error) { if (resp->error) {
SPDK_ERRLOG("error response: %.*s", (int)resp->error->len, (char *)resp->error->start); struct json_write_buf buf = {};
struct spdk_json_write_ctx *w = spdk_json_write_begin(json_write_stdout,
&buf, SPDK_JSON_PARSE_FLAG_DECODE_IN_PLACE);
if (w == NULL) {
SPDK_ERRLOG("error response: (?)\n");
} else {
spdk_json_write_val(w, resp->error);
spdk_json_write_end(w);
SPDK_ERRLOG("error response: \n%s\n", buf.data);
}
} }
if (resp->error && ctx->stop_on_error) { if (resp->error && ctx->stop_on_error) {