From 485c4b13460078906ed57895a834464d50a8bf34 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 21 Aug 2018 10:29:31 +0900 Subject: [PATCH] bdev/raid: Factor out RAID parameter check of JSON RPC and config file RAID parameter check operation of JSON RPC and config file are duplicated now. This refactoring is one of small preparation to extend RAID bdev to other RAID levels. Change-Id: I88527bc9bd0b3a3392aba7d0008a53d518027bfa Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/422797 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Kunal Sablok Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/bdev/raid/bdev_raid.c | 29 +++++++++++++++++------------ lib/bdev/raid/bdev_raid_rpc.c | 13 ------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/lib/bdev/raid/bdev_raid.c b/lib/bdev/raid/bdev_raid.c index 7ebbfb288..09229312a 100644 --- a/lib/bdev/raid/bdev_raid.c +++ b/lib/bdev/raid/bdev_raid.c @@ -853,6 +853,22 @@ raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs, } } + if (spdk_u32_is_pow2(strip_size) == false) { + SPDK_ERRLOG("Invalid strip size %d\n", strip_size); + return -EINVAL; + } + + if (num_base_bdevs <= 0) { + SPDK_ERRLOG("Invalid base device count %d\n", num_base_bdevs); + return -EINVAL; + } + + if (raid_level != 0) { + SPDK_ERRLOG("invalid raid level %d, only raid level 0 is supported\n", + raid_level); + return -EINVAL; + } + raid_cfg = calloc(1, sizeof(*raid_cfg)); if (raid_cfg == NULL) { SPDK_ERRLOG("unable to allocate memory\n"); @@ -965,21 +981,10 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section) SPDK_ERRLOG("raid_name %s is null\n", raid_name); return -1; } + strip_size = spdk_conf_section_get_intval(conf_section, "StripSize"); - if (spdk_u32_is_pow2(strip_size) == false) { - SPDK_ERRLOG("Invalid strip size %d\n", strip_size); - return -1; - } num_base_bdevs = spdk_conf_section_get_intval(conf_section, "NumDevices"); - if (num_base_bdevs <= 0) { - SPDK_ERRLOG("Invalid base device count %d\n", num_base_bdevs); - return -1; - } raid_level = spdk_conf_section_get_intval(conf_section, "RaidLevel"); - if (raid_level != 0) { - SPDK_ERRLOG("invalid raid level %d, only raid level 0 is supported\n", raid_level); - return -1; - } SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "%s %d %d %d\n", raid_name, strip_size, num_base_bdevs, raid_level); diff --git a/lib/bdev/raid/bdev_raid_rpc.c b/lib/bdev/raid/bdev_raid_rpc.c index 6e4585c26..f9d0a25ad 100644 --- a/lib/bdev/raid/bdev_raid_rpc.c +++ b/lib/bdev/raid/bdev_raid_rpc.c @@ -323,19 +323,6 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request, return; } - /* Fail the command if input raid level is other than 0 */ - if (req.raid_level != 0) { - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "invalid raid level"); - free_rpc_construct_raid_bdev(&req); - return; - } - - if (spdk_u32_is_pow2(req.strip_size) == false) { - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "invalid strip size"); - free_rpc_construct_raid_bdev(&req); - return; - } - rc = raid_bdev_config_add(req.name, req.strip_size, req.base_bdevs.num_base_bdevs, req.raid_level, &raid_cfg); if (rc != 0) {