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:
parent
da30cda946
commit
fdf7e1bcb2
@ -180,29 +180,25 @@ blockdev_heads_destroy(void)
|
|||||||
free(g_coremap);
|
free(g_coremap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
bdevperf_construct_targets(void)
|
bdevperf_construct_target(struct spdk_bdev *bdev, struct io_target **_target)
|
||||||
{
|
{
|
||||||
int index = 0;
|
|
||||||
struct spdk_bdev *bdev;
|
|
||||||
struct io_target *target;
|
struct io_target *target;
|
||||||
size_t align;
|
size_t align;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
bdev = spdk_bdev_first_leaf();
|
*_target = NULL;
|
||||||
while (bdev != NULL) {
|
|
||||||
|
|
||||||
if (g_unmap && !spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) {
|
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));
|
printf("Skipping %s because it does not support unmap\n", spdk_bdev_get_name(bdev));
|
||||||
bdev = spdk_bdev_next_leaf(bdev);
|
return 0;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target = malloc(sizeof(struct io_target));
|
target = malloc(sizeof(struct io_target));
|
||||||
if (!target) {
|
if (!target) {
|
||||||
fprintf(stderr, "Unable to allocate memory for new target.\n");
|
fprintf(stderr, "Unable to allocate memory for new target.\n");
|
||||||
/* Return immediately because all mallocs will presumably fail after this */
|
/* Return immediately because all mallocs will presumably fail after this */
|
||||||
return;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
target->name = strdup(spdk_bdev_get_name(bdev));
|
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");
|
fprintf(stderr, "Unable to allocate memory for target name.\n");
|
||||||
free(target);
|
free(target);
|
||||||
/* Return immediately because all mallocs will presumably fail after this */
|
/* Return immediately because all mallocs will presumably fail after this */
|
||||||
return;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = spdk_bdev_open(bdev, true, NULL, NULL, &target->bdev_desc);
|
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);
|
SPDK_ERRLOG("Could not open leaf bdev %s, error=%d\n", spdk_bdev_get_name(bdev), rc);
|
||||||
free(target->name);
|
free(target->name);
|
||||||
free(target);
|
free(target);
|
||||||
bdev = spdk_bdev_next_leaf(bdev);
|
return 0;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target->bdev = bdev;
|
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->io_completed = 0;
|
||||||
target->current_queue_depth = 0;
|
target->current_queue_depth = 0;
|
||||||
target->offset_in_ios = 0;
|
target->offset_in_ios = 0;
|
||||||
@ -238,8 +229,7 @@ bdevperf_construct_targets(void)
|
|||||||
spdk_bdev_close(target->bdev_desc);
|
spdk_bdev_close(target->bdev_desc);
|
||||||
free(target->name);
|
free(target->name);
|
||||||
free(target);
|
free(target);
|
||||||
bdev = spdk_bdev_next_leaf(bdev);
|
return 0;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target->size_in_ios = spdk_bdev_get_num_blocks(bdev) / target->io_size_blocks;
|
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;
|
target->reset_timer = NULL;
|
||||||
TAILQ_INIT(&target->task_list);
|
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_head[index] = target;
|
||||||
g_target_count++;
|
g_target_count++;
|
||||||
|
}
|
||||||
bdev = spdk_bdev_next_leaf(bdev);
|
bdev = spdk_bdev_next_leaf(bdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user