Skip to content

Commit

Permalink
Fix some ugly error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacKhor committed Aug 9, 2024
1 parent 6f504b3 commit db504ff
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/bdev_lsvd_rpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ static const struct spdk_json_object_decoder rpc_create_lsvd_decoders[] = {
static void rpc_bdev_lsvd_create(spdk_jsonrpc_request *req_json,
const spdk_json_val *params)
{
spdk_json_write_ctx *w;
std::unique_ptr<rpc_create_lsvd, decltype([](auto p) {
free(p->image_name);
free(p->pool_name);
Expand All @@ -44,20 +43,22 @@ static void rpc_bdev_lsvd_create(spdk_jsonrpc_request *req_json,
auto rc = spdk_json_decode_object(params, rpc_create_lsvd_decoders,
SPDK_COUNTOF(rpc_create_lsvd_decoders),
req.get());
PR_GOTO_IF(rc != 0, fail, "spdk_json_decode_object failed");
if (rc != 0) {
spdk_jsonrpc_send_error_response(req_json, rc,
"Failed to parse rpc json");
return;
}

rc = bdev_lsvd_create(req->pool_name, req->image_name, req->config);
PR_GOTO_IF(rc != 0, fail, "failed to create lsvd bdev");
if (rc != 0) {
spdk_jsonrpc_send_error_response(req_json, rc,
"Failed to create lsvd bdev");
return;
}

w = spdk_jsonrpc_begin_result(req_json);
PR_GOTO_IF(w == nullptr, fail, "failed to create json result");
auto w = spdk_jsonrpc_begin_result(req_json);
spdk_json_write_bool(w, true);
spdk_jsonrpc_end_result(req_json, w);
return;

fail:
spdk_jsonrpc_send_error_response(req_json, rc,
"failed to create lsvd bdev");
}

SPDK_RPC_REGISTER("bdev_lsvd_create", rpc_bdev_lsvd_create, SPDK_RPC_RUNTIME)
Expand All @@ -67,7 +68,7 @@ struct rpc_delete_lsvd {
};

static const struct spdk_json_object_decoder rpc_delete_lsvd_decoders[] = {
{"image_name", offsetof(struct rpc_delete_lsvd, image_name),
{"image_name", offsetof(rpc_delete_lsvd, image_name),
spdk_json_decode_string, false},
};

Expand Down

0 comments on commit db504ff

Please sign in to comment.