Commit 485c4b13 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Ben Walker
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/422797


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarKunal Sablok <kunal.sablok@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 88a1643d
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -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);
+0 −13
Original line number Diff line number Diff line
@@ -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) {