bdev/raid: Extract adding base bdevs from RPC and apply it to parse .INI config

Initialization of bdev modules don't have fixed ordering.
Hence both cases should succeed to create configured raid bdev
for .INI config file.

1. create raid bdev and then create base bdevs of it.
2. before creating raid bdev, create base bdevs of it.

To do this, factor out adding base bdevs to raid bdev
to a helper function raid_bdev_add_base_devices() first
and then apply it to construct_raid_bdev RPC and parse .INI
config file.

Change-Id: I4389fd4e7bd41296dfa9210bbe8b60348ee5bc9d
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/423769
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Kunal Sablok <kunal.sablok@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-08-31 15:27:29 +09:00 committed by Jim Harris
parent a3004632e2
commit 3f578219be
3 changed files with 62 additions and 28 deletions

View File

@ -874,6 +874,12 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
return rc;
}
rc = raid_bdev_add_base_devices(raid_cfg);
if (rc != 0) {
SPDK_ERRLOG("Failed to add any base bdev to raid bdev\n");
/* Config is not removed in this case. */
}
return 0;
}
@ -1333,7 +1339,7 @@ raid_bdev_remove_base_bdev(void *ctx)
* 0 - success
* non zero - failure
*/
int
static int
raid_bdev_add_base_device(struct raid_bdev_config *raid_cfg, struct spdk_bdev *bdev,
uint32_t base_bdev_slot)
{
@ -1365,6 +1371,52 @@ raid_bdev_add_base_device(struct raid_bdev_config *raid_cfg, struct spdk_bdev *b
return 0;
}
/*
* brief:
* iterate the raid bdev config and add base bdevs to the raid bdev that
* the config has. Skip nonexistent base bdev but stop iteration and
* return failure if adding base bdev fails.
* params:
* raid_cfg - pointer to raid bdev config
* returns:
* 0 - success
* non zero - failure
*/
int
raid_bdev_add_base_devices(struct raid_bdev_config *raid_cfg)
{
struct spdk_bdev *base_bdev;
uint8_t i;
int rc = 0, _rc;
for (i = 0; i < raid_cfg->num_base_bdevs; i++) {
/* Check if base_bdev exists already, if not fail the command */
base_bdev = spdk_bdev_get_by_name(raid_cfg->base_bdev[i].name);
if (base_bdev == NULL) {
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "base bdev %s doesn't exist now\n",
raid_cfg->base_bdev[i].name);
continue;
}
/*
* Try to add base_bdev to this raid bdev, if not able to add fail the
* command. This might be because this base_bdev may already be claimed
* by some other module
*/
_rc = raid_bdev_add_base_device(raid_cfg, base_bdev, i);
if (_rc != 0) {
SPDK_ERRLOG("Failed to add base bdev %s to RAID bdev %s: %s",
raid_cfg->base_bdev[i].name, raid_cfg->name,
spdk_strerror(-rc));
if (rc == 0) {
rc = _rc;
}
}
}
return rc;
}
/*
* brief:
* raid_bdev_examine function is the examine function call by the below layers

View File

@ -204,8 +204,7 @@ extern struct raid_config g_spdk_raid_config;
int raid_bdev_create(struct raid_bdev_config *raid_cfg);
void raid_bdev_remove_base_bdev(void *ctx);
int raid_bdev_add_base_device(struct raid_bdev_config *raid_cfg, struct spdk_bdev *bdev,
uint32_t base_bdev_slot);
int raid_bdev_add_base_devices(struct raid_bdev_config *raid_cfg);
void raid_bdev_free_base_bdev_resource(struct raid_bdev *raid_bdev, uint32_t slot);
void raid_bdev_cleanup(struct raid_bdev *raid_bdev);
int raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,

View File

@ -229,8 +229,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
struct rpc_construct_raid_bdev req = {};
struct spdk_json_write_ctx *w;
struct raid_bdev_config *raid_cfg;
struct spdk_bdev *base_bdev;
int rc, _rc;
int rc;
if (spdk_json_decode_object(params, rpc_construct_raid_bdev_decoders,
SPDK_COUNTOF(rpc_construct_raid_bdev_decoders),
@ -274,29 +273,13 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
return;
}
for (size_t i = 0; i < raid_cfg->num_base_bdevs; i++) {
/* Check if base_bdev exists already, if not fail the command */
base_bdev = spdk_bdev_get_by_name(req.base_bdevs.base_bdevs[i]);
if (base_bdev == NULL) {
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "base bdev %s doesn't exist now\n",
req.base_bdevs.base_bdevs[i]);
continue;
}
/*
* Try to add base_bdev to this raid bdev, if not able to add fail the
* command. This might be because this base_bdev may already be claimed
* by some other module
*/
_rc = raid_bdev_add_base_device(raid_cfg, base_bdev, i);
if (_rc != 0) {
SPDK_ERRLOG("Failed to add base bdev %s to RAID bdev %s: %s\n",
req.base_bdevs.base_bdevs[i], req.name,
spdk_strerror(-_rc));
if (rc == 0) {
rc = _rc;
}
}
rc = raid_bdev_add_base_devices(raid_cfg);
if (rc != 0) {
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;
}
if (rc != 0) {