bdev/raid: Use raid_cfg as a pointer to raid_bdev_config throughout
In bdev_raid.c and bdev_raid_rpc.c, to hold a pointer to raid_bdev_config, some have used raid_cfg and other have used raid_bdev_config. raid_bdev_config is the name of the struct and using the name of the struct as a pointer to it may cause any confusion. Change-Id: Ic87ff04d58ea46c30081aaae8d9cda5a53135be9 Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/422922 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Kunal Sablok <kunal.sablok@intel.com>
This commit is contained in:
parent
ab9661c990
commit
a74212733b
@ -789,7 +789,7 @@ static const struct spdk_bdev_fn_table g_raid_bdev_fn_table = {
|
||||
* brief:
|
||||
* raid_bdev_config_cleanup function is used to free memory for one raid_bdev in configuration
|
||||
* params:
|
||||
* raid_bdev_config - pointer to raid_bdev_config structure
|
||||
* raid_cfg - pointer to raid_bdev_config structure
|
||||
* returns:
|
||||
* none
|
||||
*/
|
||||
@ -840,11 +840,11 @@ raid_bdev_free(void)
|
||||
* strip_size - strip size in KB
|
||||
* num_base_bdevs - number of base bdevs.
|
||||
* raid_level - raid level, only raid level 0 is supported.
|
||||
* _raid_bdev_config - Pointer to newly added configuration
|
||||
* _raid_cfg - Pointer to newly added configuration
|
||||
*/
|
||||
int
|
||||
raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
|
||||
int raid_level, struct raid_bdev_config **_raid_bdev_config)
|
||||
int raid_level, struct raid_bdev_config **_raid_cfg)
|
||||
{
|
||||
struct raid_bdev_config *raid_cfg;
|
||||
|
||||
@ -883,7 +883,7 @@ raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
|
||||
TAILQ_INSERT_TAIL(&g_spdk_raid_config.raid_bdev_config_head, raid_cfg, link);
|
||||
g_spdk_raid_config.total_raid_bdev++;
|
||||
|
||||
*_raid_bdev_config = raid_cfg;
|
||||
*_raid_cfg = raid_cfg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -960,7 +960,7 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
|
||||
int i, num_base_bdevs;
|
||||
int raid_level;
|
||||
const char *base_bdev_name;
|
||||
struct raid_bdev_config *raid_bdev_config;
|
||||
struct raid_bdev_config *raid_cfg;
|
||||
int rc;
|
||||
|
||||
raid_name = spdk_conf_section_get_val(conf_section, "Name");
|
||||
@ -988,7 +988,7 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
|
||||
raid_level);
|
||||
|
||||
rc = raid_bdev_config_add(raid_name, strip_size, num_base_bdevs, raid_level,
|
||||
&raid_bdev_config);
|
||||
&raid_cfg);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to add raid bdev config\n");
|
||||
return rc;
|
||||
@ -1000,21 +1000,21 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
|
||||
break;
|
||||
}
|
||||
if (i >= num_base_bdevs) {
|
||||
raid_bdev_config_cleanup(raid_bdev_config);
|
||||
raid_bdev_config_cleanup(raid_cfg);
|
||||
SPDK_ERRLOG("Number of devices mentioned is more than count\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = raid_bdev_config_add_base_bdev(raid_bdev_config, base_bdev_name, i);
|
||||
rc = raid_bdev_config_add_base_bdev(raid_cfg, base_bdev_name, i);
|
||||
if (rc != 0) {
|
||||
raid_bdev_config_cleanup(raid_bdev_config);
|
||||
raid_bdev_config_cleanup(raid_cfg);
|
||||
SPDK_ERRLOG("Failed to add base bdev to raid bdev config\n");
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != raid_bdev_config->num_base_bdevs) {
|
||||
raid_bdev_config_cleanup(raid_bdev_config);
|
||||
if (i != raid_cfg->num_base_bdevs) {
|
||||
raid_bdev_config_cleanup(raid_cfg);
|
||||
SPDK_ERRLOG("Number of devices mentioned is less than count\n");
|
||||
return -1;
|
||||
}
|
||||
@ -1106,7 +1106,7 @@ raid_bdev_get_ctx_size(void)
|
||||
* claimed by raid bdev or not.
|
||||
* params:
|
||||
* bdev_name - represents base bdev name
|
||||
* raid_bdev_config - pointer to raid bdev config parsed from config file
|
||||
* _raid_cfg - pointer to raid bdev config parsed from config file
|
||||
* base_bdev_slot - if bdev can be claimed, it represents the base_bdev correct
|
||||
* slot. This field is only valid if return value of this function is true
|
||||
* returns:
|
||||
@ -1114,7 +1114,7 @@ raid_bdev_get_ctx_size(void)
|
||||
* false - if bdev can't be claimed
|
||||
*/
|
||||
static bool
|
||||
raid_bdev_can_claim_bdev(const char *bdev_name, struct raid_bdev_config **raid_bdev_config,
|
||||
raid_bdev_can_claim_bdev(const char *bdev_name, struct raid_bdev_config **_raid_cfg,
|
||||
uint32_t *base_bdev_slot)
|
||||
{
|
||||
bool rv = false;
|
||||
@ -1129,7 +1129,7 @@ raid_bdev_can_claim_bdev(const char *bdev_name, struct raid_bdev_config **raid_b
|
||||
* this base bdev should be inserted in raid bdev
|
||||
*/
|
||||
if (!strcmp(bdev_name, raid_cfg->base_bdev[i].bdev_name)) {
|
||||
*raid_bdev_config = raid_cfg;
|
||||
*_raid_cfg = raid_cfg;
|
||||
*base_bdev_slot = i;
|
||||
rv = true;
|
||||
break;;
|
||||
@ -1463,7 +1463,7 @@ raid_bdev_remove_base_bdev(void *ctx)
|
||||
int
|
||||
raid_bdev_add_base_device(struct spdk_bdev *bdev)
|
||||
{
|
||||
struct raid_bdev_config *raid_bdev_config = NULL;
|
||||
struct raid_bdev_config *raid_cfg = NULL;
|
||||
struct raid_bdev *raid_bdev;
|
||||
uint32_t base_bdev_slot;
|
||||
bool can_claim;
|
||||
@ -1471,22 +1471,22 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
|
||||
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_examine %p\n", bdev);
|
||||
|
||||
can_claim = raid_bdev_can_claim_bdev(bdev->name, &raid_bdev_config, &base_bdev_slot);
|
||||
can_claim = raid_bdev_can_claim_bdev(bdev->name, &raid_cfg, &base_bdev_slot);
|
||||
|
||||
if (!can_claim) {
|
||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "bdev %s can't be claimed\n", bdev->name);
|
||||
return -1;
|
||||
}
|
||||
assert(raid_bdev_config);
|
||||
assert(raid_cfg);
|
||||
|
||||
raid_bdev = raid_bdev_config->raid_bdev;
|
||||
raid_bdev = raid_cfg->raid_bdev;
|
||||
if (!raid_bdev) {
|
||||
rc = raid_bdev_create(raid_bdev_config, &raid_bdev);
|
||||
rc = raid_bdev_create(raid_cfg, &raid_bdev);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to create raid bdev for bdev '%s'\n", bdev->name);
|
||||
return -1;
|
||||
}
|
||||
raid_bdev_config->raid_bdev = raid_bdev;
|
||||
raid_cfg->raid_bdev = raid_bdev;
|
||||
}
|
||||
|
||||
rc = raid_bdev_alloc_base_bdev_resource(raid_bdev, bdev, base_bdev_slot);
|
||||
|
@ -218,7 +218,7 @@ extern struct raid_config g_spdk_raid_config;
|
||||
void raid_bdev_remove_base_bdev(void *ctx);
|
||||
int raid_bdev_add_base_device(struct spdk_bdev *bdev);
|
||||
int raid_bdev_config_add(const char *raid_name, int strip_size, int num_base_bdevs,
|
||||
int raid_level, struct raid_bdev_config **_raid_bdev_config);
|
||||
int raid_level, struct raid_bdev_config **_raid_cfg);
|
||||
int raid_bdev_config_add_base_bdev(struct raid_bdev_config *raid_cfg,
|
||||
const char *base_bdev_name, uint32_t slot);
|
||||
void raid_bdev_config_cleanup(struct raid_bdev_config *raid_cfg);
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
#define RPC_MAX_BASE_BDEVS 255
|
||||
|
||||
static void raid_bdev_config_destroy(struct raid_bdev_config *raid_bdev_config);
|
||||
static void raid_bdev_config_destroy(struct raid_bdev_config *raid_cfg);
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT("raidrpc", SPDK_LOG_RAID_RPC)
|
||||
|
||||
@ -249,12 +249,12 @@ static const struct spdk_json_object_decoder rpc_construct_raid_bdev_decoders[]
|
||||
* non NULL - raid present, returns raid_bdev
|
||||
*/
|
||||
static void
|
||||
check_and_remove_raid_bdev(struct raid_bdev_config *raid_bdev_config)
|
||||
check_and_remove_raid_bdev(struct raid_bdev_config *raid_cfg)
|
||||
{
|
||||
struct raid_bdev *raid_bdev;
|
||||
|
||||
/* Get the raid structured allocated if exists */
|
||||
raid_bdev = raid_bdev_config->raid_bdev;
|
||||
raid_bdev = raid_cfg->raid_bdev;
|
||||
if (raid_bdev == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -282,7 +282,7 @@ check_and_remove_raid_bdev(struct raid_bdev_config *raid_bdev_config)
|
||||
TAILQ_REMOVE(&g_spdk_raid_bdev_list, raid_bdev, link_global_list);
|
||||
free(raid_bdev->base_bdev_info);
|
||||
free(raid_bdev);
|
||||
raid_bdev_config->raid_bdev = NULL;
|
||||
raid_cfg->raid_bdev = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -301,7 +301,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_bdev_config;
|
||||
struct raid_bdev_config *raid_cfg;
|
||||
struct raid_bdev *raid_bdev;
|
||||
struct spdk_bdev *base_bdev;
|
||||
int rc;
|
||||
@ -337,7 +337,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
|
||||
}
|
||||
|
||||
rc = raid_bdev_config_add(req.name, req.strip_size, req.base_bdevs.num_base_bdevs, req.raid_level,
|
||||
&raid_bdev_config);
|
||||
&raid_cfg);
|
||||
if (rc != 0) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(-rc));
|
||||
free_rpc_construct_raid_bdev(&req);
|
||||
@ -345,21 +345,21 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
|
||||
rc = raid_bdev_config_add_base_bdev(raid_bdev_config, req.base_bdevs.base_bdevs[i], i);
|
||||
rc = raid_bdev_config_add_base_bdev(raid_cfg, req.base_bdevs.base_bdevs[i], i);
|
||||
if (rc != 0) {
|
||||
raid_bdev_config_cleanup(raid_bdev_config);
|
||||
raid_bdev_config_cleanup(raid_cfg);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(-rc));
|
||||
free_rpc_construct_raid_bdev(&req);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < raid_bdev_config->num_base_bdevs; i++) {
|
||||
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) {
|
||||
check_and_remove_raid_bdev(raid_bdev_config);
|
||||
raid_bdev_config_cleanup(raid_bdev_config);
|
||||
check_and_remove_raid_bdev(raid_cfg);
|
||||
raid_bdev_config_cleanup(raid_cfg);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "base bdev not found");
|
||||
free_rpc_construct_raid_bdev(&req);
|
||||
return;
|
||||
@ -371,8 +371,8 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
|
||||
* by some other module
|
||||
*/
|
||||
if (raid_bdev_add_base_device(base_bdev)) {
|
||||
check_and_remove_raid_bdev(raid_bdev_config);
|
||||
raid_bdev_config_cleanup(raid_bdev_config);
|
||||
check_and_remove_raid_bdev(raid_cfg);
|
||||
raid_bdev_config_cleanup(raid_cfg);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"base bdev can't be added because of either memory allocation failed or not able to claim");
|
||||
free_rpc_construct_raid_bdev(&req);
|
||||
@ -439,7 +439,8 @@ raid_bdev_config_destroy_check_raid_bdev_exists(void *arg)
|
||||
assert(raid_cfg != NULL);
|
||||
if (raid_cfg->raid_bdev != NULL) {
|
||||
/* If raid bdev still exists, schedule event and come back later */
|
||||
spdk_thread_send_msg(spdk_get_thread(), raid_bdev_config_destroy_check_raid_bdev_exists, raid_cfg);
|
||||
spdk_thread_send_msg(spdk_get_thread(), raid_bdev_config_destroy_check_raid_bdev_exists,
|
||||
raid_cfg);
|
||||
return;
|
||||
} else {
|
||||
/* If raid bdev does not exist now, go for raid bdev config cleanup */
|
||||
@ -464,7 +465,8 @@ raid_bdev_config_destroy(struct raid_bdev_config *raid_cfg)
|
||||
* If raid bdev exists for this config, wait for raid bdev to get
|
||||
* destroyed and come back later
|
||||
*/
|
||||
spdk_thread_send_msg(spdk_get_thread(), raid_bdev_config_destroy_check_raid_bdev_exists, raid_cfg);
|
||||
spdk_thread_send_msg(spdk_get_thread(), raid_bdev_config_destroy_check_raid_bdev_exists,
|
||||
raid_cfg);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -487,7 +489,7 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp
|
||||
{
|
||||
struct rpc_destroy_raid_bdev req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct raid_bdev_config *raid_bdev_config = NULL;
|
||||
struct raid_bdev_config *raid_cfg = NULL;
|
||||
struct spdk_bdev *base_bdev;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_destroy_raid_bdev_decoders,
|
||||
@ -499,13 +501,13 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp
|
||||
}
|
||||
|
||||
/* Find raid bdev config for this raid bdev */
|
||||
TAILQ_FOREACH(raid_bdev_config, &g_spdk_raid_config.raid_bdev_config_head, link) {
|
||||
if (strcmp(raid_bdev_config->name, req.name) == 0) {
|
||||
TAILQ_FOREACH(raid_cfg, &g_spdk_raid_config.raid_bdev_config_head, link) {
|
||||
if (strcmp(raid_cfg->name, req.name) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (raid_bdev_config == NULL) {
|
||||
if (raid_cfg == NULL) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"raid bdev name not found");
|
||||
free_rpc_destroy_raid_bdev(&req);
|
||||
@ -513,8 +515,8 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp
|
||||
}
|
||||
|
||||
/* Remove all the base bdevs from this raid bdev before destroying the raid bdev */
|
||||
for (uint32_t i = 0; i < raid_bdev_config->num_base_bdevs; i++) {
|
||||
base_bdev = spdk_bdev_get_by_name(raid_bdev_config->base_bdev[i].bdev_name);
|
||||
for (uint32_t i = 0; i < raid_cfg->num_base_bdevs; i++) {
|
||||
base_bdev = spdk_bdev_get_by_name(raid_cfg->base_bdev[i].bdev_name);
|
||||
if (base_bdev != NULL) {
|
||||
raid_bdev_remove_base_bdev(base_bdev);
|
||||
}
|
||||
@ -524,7 +526,7 @@ spdk_rpc_destroy_raid_bdev(struct spdk_jsonrpc_request *request, const struct sp
|
||||
* Call to destroy the raid bdev, but it will only destroy raid bdev if underlying
|
||||
* cleanup is done
|
||||
*/
|
||||
raid_bdev_config_destroy(raid_bdev_config);
|
||||
raid_bdev_config_destroy(raid_cfg);
|
||||
|
||||
free_rpc_destroy_raid_bdev(&req);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user