bdev/raid: Extract check claim operation from add base bdev operation

When a raid bdev is constructed by JSON-RPC construct_raid_bdev,
information about config and slot can be passed to
raid_bdev_add_base_device() and raid_bdev_can_claim() doesn't have
to be called.

Hence extract raid_bdev_can_claim_bdev() from raid_bdev_add_base_device()
and put it to raid_bdev_examine().

Change-Id: I92e02bf3661cb97b691246f32198ba946810d96c
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/423618
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 10:13:38 +09:00 committed by Jim Harris
parent 3333ceb6af
commit 0a46f5c2aa
4 changed files with 24 additions and 28 deletions

View File

@ -1046,7 +1046,6 @@ static bool
raid_bdev_can_claim_bdev(const char *bdev_name, struct raid_bdev_config **_raid_cfg,
uint32_t *base_bdev_slot)
{
bool rv = false;
struct raid_bdev_config *raid_cfg;
uint32_t i;
@ -1060,13 +1059,12 @@ raid_bdev_can_claim_bdev(const char *bdev_name, struct raid_bdev_config **_raid_
if (!strcmp(bdev_name, raid_cfg->base_bdev[i].name)) {
*_raid_cfg = raid_cfg;
*base_bdev_slot = i;
rv = true;
break;;
return true;
}
}
}
return rv;
return false;
}
@ -1390,30 +1388,20 @@ raid_bdev_remove_base_bdev(void *ctx)
* the nvme base device to existing raid bdev or create a new raid bdev. It also claims
* the base device and keep the open descriptor.
* params:
* raid_cfg - pointer to raid bdev config
* bdev - pointer to base bdev
* base_bdev_slot - position to add base bdev
* returns:
* 0 - success
* non zero - failure
*/
int
raid_bdev_add_base_device(struct spdk_bdev *bdev)
raid_bdev_add_base_device(struct raid_bdev_config *raid_cfg, struct spdk_bdev *bdev,
uint32_t base_bdev_slot)
{
struct raid_bdev_config *raid_cfg = NULL;
struct raid_bdev *raid_bdev;
uint32_t base_bdev_slot;
bool can_claim;
int rc;
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "raid_bdev_examine %p\n", bdev);
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_cfg);
raid_bdev = raid_cfg->raid_bdev;
if (!raid_bdev) {
rc = raid_bdev_create(raid_cfg, &raid_bdev);
@ -1456,7 +1444,16 @@ raid_bdev_add_base_device(struct spdk_bdev *bdev)
static void
raid_bdev_examine(struct spdk_bdev *bdev)
{
raid_bdev_add_base_device(bdev);
struct raid_bdev_config *raid_cfg;
uint32_t base_bdev_slot;
if (raid_bdev_can_claim_bdev(bdev->name, &raid_cfg, &base_bdev_slot)) {
raid_bdev_add_base_device(raid_cfg, bdev, base_bdev_slot);
} else {
SPDK_DEBUGLOG(SPDK_LOG_BDEV_RAID, "bdev %s can't be claimed\n",
bdev->name);
}
spdk_bdev_module_examine_done(&g_raid_if);
}

View File

@ -216,7 +216,8 @@ 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_add_base_device(struct raid_bdev_config *raid_cfg, struct spdk_bdev *bdev,
uint32_t base_bdev_slot);
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

@ -311,7 +311,7 @@ spdk_rpc_construct_raid_bdev(struct spdk_jsonrpc_request *request,
* command. This might be because this base_bdev may already be claimed
* by some other module
*/
if (raid_bdev_add_base_device(base_bdev)) {
if (raid_bdev_add_base_device(raid_cfg, base_bdev, i)) {
check_and_remove_raid_bdev(raid_cfg);
raid_bdev_config_cleanup(raid_cfg);
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,

View File

@ -1932,6 +1932,9 @@ test_create_raid_from_config(void)
struct rpc_construct_raid_bdev req;
struct spdk_bdev *bdev;
struct rpc_destroy_raid_bdev destroy_req;
bool can_claim;
struct raid_bdev_config *raid_cfg;
uint32_t base_bdev_slot;
set_globals();
create_test_req(&req, "raid1", 0, true);
@ -1948,13 +1951,8 @@ test_create_raid_from_config(void)
raid_bdev_examine(bdev);
}
bdev = calloc(1, sizeof(struct spdk_bdev));
SPDK_CU_ASSERT_FATAL(bdev != NULL);
bdev->name = strdup("Invalid");
SPDK_CU_ASSERT_FATAL(bdev->name != NULL);
CU_ASSERT(raid_bdev_add_base_device(bdev) != 0);
free(bdev->name);
free(bdev);
can_claim = raid_bdev_can_claim_bdev("Invalid", &raid_cfg, &base_bdev_slot);
CU_ASSERT(can_claim == false);
verify_raid_config(&req, true);
verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);