From b2dd6e7ec2aaad586b85823917df5590968b9962 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 9 Apr 2019 09:31:08 +0900 Subject: [PATCH] bdev/raid: Consolidate error paths in rpc_destroy/construct_raid_bdev() This is a preparation to add completion callback to the destroy_raid_bdev RPC. Change-Id: Ib58b7e6d8531c84ab5e4fce7a838e409e77a0de5 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/450571 Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- lib/bdev/raid/bdev_raid_rpc.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/bdev/raid/bdev_raid_rpc.c b/lib/bdev/raid/bdev_raid_rpc.c index d8156e9dc..5de2a2529 100644 --- a/lib/bdev/raid/bdev_raid_rpc.c +++ b/lib/bdev/raid/bdev_raid_rpc.c @@ -237,20 +237,17 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, &req)) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters"); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } if (req.strip_size == 0 && req.strip_size_kb == 0) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "strip size not specified"); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } else if (req.strip_size > 0 && req.strip_size_kb > 0) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "please use only one strip size option"); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } else if (req.strip_size > 0 && req.strip_size_kb == 0) { SPDK_ERRLOG("the rpc param strip_size is deprecated.\n"); req.strip_size_kb = req.strip_size; @@ -263,8 +260,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Failed to add RAID bdev config %s: %s", req.name, spdk_strerror(-rc)); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } for (size_t i = 0; i < req.base_bdevs.num_base_bdevs; i++) { @@ -275,8 +271,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, "Failed to add base bdev %s to RAID bdev config %s: %s", req.base_bdevs.base_bdevs[i], req.name, spdk_strerror(-rc)); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } } @@ -286,8 +281,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Failed to create RAID bdev %s: %s", req.name, spdk_strerror(-rc)); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } rc = raid_bdev_add_base_devices(raid_cfg); @@ -295,8 +289,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Failed to add any base bdev to RAID bdev %s: %s", req.name, spdk_strerror(-rc)); - free_rpc_construct_raid_bdev(&req); - return; + goto invalid; } free_rpc_construct_raid_bdev(&req); @@ -308,6 +301,10 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, spdk_json_write_bool(w, true); spdk_jsonrpc_end_result(request, w); + return; + +invalid: + free_rpc_construct_raid_bdev(&req); } SPDK_RPC_REGISTER("construct_raid_bdev", spdk_rpc_construct_raid_bdev, SPDK_RPC_RUNTIME) @@ -391,16 +388,14 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp &req)) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters"); - free_rpc_destroy_raid_bdev(&req); - return; + goto invalid; } raid_cfg = raid_bdev_config_find_by_name(req.name); if (raid_cfg == NULL) { spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "raid bdev %s is not found in config", req.name); - free_rpc_destroy_raid_bdev(&req); - return; + goto invalid; } /* Remove all the base bdevs from this raid bdev before destroying the raid bdev */ @@ -417,5 +412,9 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp spdk_json_write_bool(w, true); spdk_jsonrpc_end_result(request, w); + return; + +invalid: + free_rpc_destroy_raid_bdev(&req); } SPDK_RPC_REGISTER("destroy_raid_bdev", spdk_rpc_destroy_raid_bdev, SPDK_RPC_RUNTIME)