bdevperf: Factoring out construct target operation into a function

Bdevperf have returned immediately if -ENOMEM, continued if failure
due to other reasons, and registered the created target otherwise.

So, keep this behavior by passing the reference to the pointer to
struct io_target, and check both return code and the value of the
reference.

And this refactoring will clarify the logic related with target
assigment to cores.

Change-Id: I24593f7b4523daf4395643bdc8886499c36ea3c7
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/443354
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-02-11 07:55:42 +09:00 committed by Changpeng Liu
parent da30cda946
commit fdf7e1bcb2

View File

@ -180,29 +180,25 @@ blockdev_heads_destroy(void)
free(g_coremap);
}
static void
bdevperf_construct_targets(void)
static int
bdevperf_construct_target(struct spdk_bdev *bdev, struct io_target **_target)
{
int index = 0;
struct spdk_bdev *bdev;
struct io_target *target;
size_t align;
int rc;
bdev = spdk_bdev_first_leaf();
while (bdev != NULL) {
*_target = NULL;
if (g_unmap && !spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) {
printf("Skipping %s because it does not support unmap\n", spdk_bdev_get_name(bdev));
bdev = spdk_bdev_next_leaf(bdev);
continue;
return 0;
}
target = malloc(sizeof(struct io_target));
if (!target) {
fprintf(stderr, "Unable to allocate memory for new target.\n");
/* Return immediately because all mallocs will presumably fail after this */
return;
return -ENOMEM;
}
target->name = strdup(spdk_bdev_get_name(bdev));
@ -210,7 +206,7 @@ bdevperf_construct_targets(void)
fprintf(stderr, "Unable to allocate memory for target name.\n");
free(target);
/* Return immediately because all mallocs will presumably fail after this */
return;
return -ENOMEM;
}
rc = spdk_bdev_open(bdev, true, NULL, NULL, &target->bdev_desc);
@ -218,15 +214,10 @@ bdevperf_construct_targets(void)
SPDK_ERRLOG("Could not open leaf bdev %s, error=%d\n", spdk_bdev_get_name(bdev), rc);
free(target->name);
free(target);
bdev = spdk_bdev_next_leaf(bdev);
continue;
return 0;
}
target->bdev = bdev;
/* Mapping each target to lcore */
index = g_target_count % spdk_env_get_core_count();
target->next = g_head[index];
target->lcore = g_coremap[index];
target->io_completed = 0;
target->current_queue_depth = 0;
target->offset_in_ios = 0;
@ -238,8 +229,7 @@ bdevperf_construct_targets(void)
spdk_bdev_close(target->bdev_desc);
free(target->name);
free(target);
bdev = spdk_bdev_next_leaf(bdev);
continue;
return 0;
}
target->size_in_ios = spdk_bdev_get_num_blocks(bdev) / target->io_size_blocks;
@ -255,9 +245,32 @@ bdevperf_construct_targets(void)
target->reset_timer = NULL;
TAILQ_INIT(&target->task_list);
*_target = target;
return 0;
}
static void
bdevperf_construct_targets(void)
{
int index = 0;
struct spdk_bdev *bdev;
struct io_target *target;
int rc;
bdev = spdk_bdev_first_leaf();
while (bdev != NULL) {
rc = bdevperf_construct_target(bdev, &target);
if (rc != 0) {
return;
}
if (target != NULL) {
/* Mapping each created target to lcore */
index = g_target_count % spdk_env_get_core_count();
target->next = g_head[index];
target->lcore = g_coremap[index];
g_head[index] = target;
g_target_count++;
}
bdev = spdk_bdev_next_leaf(bdev);
}
}