bdev/raid: Use descriptive error code for failure of config operation

Change-Id: I2c34e666fbdcfe5640a87398601f0b819c78a36f
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/423615
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Kunal Sablok <kunal.sablok@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-08-28 09:56:22 +09:00 committed by Jim Harris
parent 636b9d597c
commit 2c608684ff

View File

@ -96,7 +96,7 @@ raid_bdev_create_cb(void *io_device, void *ctx_buf)
sizeof(struct spdk_io_channel *)); sizeof(struct spdk_io_channel *));
if (!raid_ch->base_channel) { if (!raid_ch->base_channel) {
SPDK_ERRLOG("Unable to allocate base bdevs io channel\n"); SPDK_ERRLOG("Unable to allocate base bdevs io channel\n");
return -1; return -ENOMEM;
} }
for (uint32_t i = 0; i < raid_bdev->num_base_bdevs; i++) { for (uint32_t i = 0; i < raid_bdev->num_base_bdevs; i++) {
/* /*
@ -112,7 +112,7 @@ raid_bdev_create_cb(void *io_device, void *ctx_buf)
} }
free(raid_ch->base_channel); free(raid_ch->base_channel);
SPDK_ERRLOG("Unable to create io channel for base bdev\n"); SPDK_ERRLOG("Unable to create io channel for base bdev\n");
return -1; return -ENOMEM;
} }
} }
@ -906,7 +906,7 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
raid_name = spdk_conf_section_get_val(conf_section, "Name"); raid_name = spdk_conf_section_get_val(conf_section, "Name");
if (raid_name == NULL) { if (raid_name == NULL) {
SPDK_ERRLOG("raid_name %s is null\n", raid_name); SPDK_ERRLOG("raid_name %s is null\n", raid_name);
return -1; return -EINVAL;
} }
strip_size = spdk_conf_section_get_intval(conf_section, "StripSize"); strip_size = spdk_conf_section_get_intval(conf_section, "StripSize");
@ -931,7 +931,7 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
if (i >= num_base_bdevs) { if (i >= num_base_bdevs) {
raid_bdev_config_cleanup(raid_cfg); raid_bdev_config_cleanup(raid_cfg);
SPDK_ERRLOG("Number of devices mentioned is more than count\n"); SPDK_ERRLOG("Number of devices mentioned is more than count\n");
return -1; return -EINVAL;
} }
rc = raid_bdev_config_add_base_bdev(raid_cfg, base_bdev_name, i); rc = raid_bdev_config_add_base_bdev(raid_cfg, base_bdev_name, i);
@ -945,7 +945,7 @@ raid_bdev_parse_raid(struct spdk_conf_section *conf_section)
if (i != raid_cfg->num_base_bdevs) { if (i != raid_cfg->num_base_bdevs) {
raid_bdev_config_cleanup(raid_cfg); raid_bdev_config_cleanup(raid_cfg);
SPDK_ERRLOG("Number of devices mentioned is less than count\n"); SPDK_ERRLOG("Number of devices mentioned is less than count\n");
return -1; return -EINVAL;
} }
return 0; return 0;
@ -1172,16 +1172,19 @@ raid_bdev_alloc_base_bdev_resource(struct raid_bdev *raid_bdev, struct spdk_bdev
uint32_t base_bdev_slot) uint32_t base_bdev_slot)
{ {
struct spdk_bdev_desc *desc; struct spdk_bdev_desc *desc;
int rc;
if (spdk_bdev_open(bdev, true, raid_bdev_remove_base_bdev, bdev, &desc)) { rc = spdk_bdev_open(bdev, true, raid_bdev_remove_base_bdev, bdev, &desc);
if (rc != 0) {
SPDK_ERRLOG("Unable to create desc on bdev '%s'\n", bdev->name); SPDK_ERRLOG("Unable to create desc on bdev '%s'\n", bdev->name);
return -1; return rc;
} }
if (spdk_bdev_module_claim_bdev(bdev, NULL, &g_raid_if)) { rc = spdk_bdev_module_claim_bdev(bdev, NULL, &g_raid_if);
if (rc != 0) {
SPDK_ERRLOG("Unable to claim this bdev as it is already claimed\n"); SPDK_ERRLOG("Unable to claim this bdev as it is already claimed\n");
spdk_bdev_close(desc); spdk_bdev_close(desc);
return -1; return rc;
} }
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "bdev %s is claimed\n", bdev->name); SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "bdev %s is claimed\n", bdev->name);
@ -1214,6 +1217,7 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
uint32_t blocklen; uint32_t blocklen;
uint64_t min_blockcnt; uint64_t min_blockcnt;
struct spdk_bdev *raid_bdev_gen; struct spdk_bdev *raid_bdev_gen;
int rc = 0;
blocklen = raid_bdev->base_bdev_info[0].bdev->blocklen; blocklen = raid_bdev->base_bdev_info[0].bdev->blocklen;
min_blockcnt = raid_bdev->base_bdev_info[0].bdev->blockcnt; min_blockcnt = raid_bdev->base_bdev_info[0].bdev->blockcnt;
@ -1230,6 +1234,7 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
* have same blocklen * have same blocklen
*/ */
SPDK_ERRLOG("Blocklen of various bdevs not matching\n"); SPDK_ERRLOG("Blocklen of various bdevs not matching\n");
rc = -EINVAL;
goto offline; goto offline;
} }
} }
@ -1238,6 +1243,7 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
raid_bdev_gen->name = strdup(raid_bdev->config->name); raid_bdev_gen->name = strdup(raid_bdev->config->name);
if (!raid_bdev_gen->name) { if (!raid_bdev_gen->name) {
SPDK_ERRLOG("Unable to allocate name for raid\n"); SPDK_ERRLOG("Unable to allocate name for raid\n");
rc = -ENOMEM;
goto offline; goto offline;
} }
raid_bdev_gen->product_name = "Pooled Device"; raid_bdev_gen->product_name = "Pooled Device";
@ -1268,7 +1274,8 @@ raid_bdev_configure(struct raid_bdev *raid_bdev)
raid_bdev->state = RAID_BDEV_STATE_ONLINE; raid_bdev->state = RAID_BDEV_STATE_ONLINE;
spdk_io_device_register(raid_bdev, raid_bdev_create_cb, raid_bdev_destroy_cb, spdk_io_device_register(raid_bdev, raid_bdev_create_cb, raid_bdev_destroy_cb,
sizeof(struct raid_bdev_io_channel)); sizeof(struct raid_bdev_io_channel));
if (spdk_bdev_register(raid_bdev_gen)) { rc = spdk_bdev_register(raid_bdev_gen);
if (rc != 0) {
/* /*
* If failed to register raid bdev to bdev layer, make raid bdev offline * If failed to register raid bdev to bdev layer, make raid bdev offline
* and add to offline list * and add to offline list
@ -1290,7 +1297,7 @@ offline:
raid_bdev->state = RAID_BDEV_STATE_OFFLINE; raid_bdev->state = RAID_BDEV_STATE_OFFLINE;
TAILQ_REMOVE(&g_spdk_raid_bdev_configuring_list, raid_bdev, state_link); TAILQ_REMOVE(&g_spdk_raid_bdev_configuring_list, raid_bdev, state_link);
TAILQ_INSERT_TAIL(&g_spdk_raid_bdev_offline_list, raid_bdev, state_link); TAILQ_INSERT_TAIL(&g_spdk_raid_bdev_offline_list, raid_bdev, state_link);
return -1; return rc;
} }
/* /*
@ -1412,7 +1419,7 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
rc = raid_bdev_create(raid_cfg, &raid_bdev); rc = raid_bdev_create(raid_cfg, &raid_bdev);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Failed to create raid bdev for bdev '%s'\n", bdev->name); SPDK_ERRLOG("Failed to create raid bdev for bdev '%s'\n", bdev->name);
return -1; return rc;
} }
raid_cfg->raid_bdev = raid_bdev; raid_cfg->raid_bdev = raid_bdev;
} }
@ -1421,7 +1428,7 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Failed to allocate resource for bdev '%s'\n", bdev->name); SPDK_ERRLOG("Failed to allocate resource for bdev '%s'\n", bdev->name);
raid_bdev_cleanup(raid_bdev); raid_bdev_cleanup(raid_bdev);
return -1; return rc;
} }
assert(raid_bdev->num_base_bdevs_discovered <= raid_bdev->num_base_bdevs); assert(raid_bdev->num_base_bdevs_discovered <= raid_bdev->num_base_bdevs);
@ -1430,7 +1437,7 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
rc = raid_bdev_configure(raid_bdev); rc = raid_bdev_configure(raid_bdev);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Failed to configure raid bdev\n"); SPDK_ERRLOG("Failed to configure raid bdev\n");
return -1; return rc;
} }
} }