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,84 +180,97 @@ blockdev_heads_destroy(void)
free(g_coremap);
}
static int
bdevperf_construct_target(struct spdk_bdev *bdev, struct io_target **_target)
{
struct io_target *target;
size_t align;
int rc;
*_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));
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 -ENOMEM;
}
target->name = strdup(spdk_bdev_get_name(bdev));
if (!target->name) {
fprintf(stderr, "Unable to allocate memory for target name.\n");
free(target);
/* Return immediately because all mallocs will presumably fail after this */
return -ENOMEM;
}
rc = spdk_bdev_open(bdev, true, NULL, NULL, &target->bdev_desc);
if (rc != 0) {
SPDK_ERRLOG("Could not open leaf bdev %s, error=%d\n", spdk_bdev_get_name(bdev), rc);
free(target->name);
free(target);
return 0;
}
target->bdev = bdev;
target->io_completed = 0;
target->current_queue_depth = 0;
target->offset_in_ios = 0;
target->io_size_blocks = g_io_size / spdk_bdev_get_block_size(bdev);
if (target->io_size_blocks == 0 ||
(g_io_size % spdk_bdev_get_block_size(bdev)) != 0) {
SPDK_ERRLOG("IO size (%d) is bigger than blocksize of bdev %s (%"PRIu32") or not a blocksize multiple\n",
g_io_size, spdk_bdev_get_name(bdev), spdk_bdev_get_block_size(bdev));
spdk_bdev_close(target->bdev_desc);
free(target->name);
free(target);
return 0;
}
target->size_in_ios = spdk_bdev_get_num_blocks(bdev) / target->io_size_blocks;
align = spdk_bdev_get_buf_align(bdev);
/*
* TODO: This should actually use the LCM of align and g_min_alignment, but
* it is fairly safe to assume all alignments are powers of two for now.
*/
g_min_alignment = spdk_max(g_min_alignment, align);
target->is_draining = false;
target->run_timer = NULL;
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;
size_t align;
int rc;
bdev = spdk_bdev_first_leaf();
while (bdev != 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;
}
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;
}
target->name = strdup(spdk_bdev_get_name(bdev));
if (!target->name) {
fprintf(stderr, "Unable to allocate memory for target name.\n");
free(target);
/* Return immediately because all mallocs will presumably fail after this */
return;
}
rc = spdk_bdev_open(bdev, true, NULL, NULL, &target->bdev_desc);
rc = bdevperf_construct_target(bdev, &target);
if (rc != 0) {
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;
}
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;
target->io_size_blocks = g_io_size / spdk_bdev_get_block_size(bdev);
if (target->io_size_blocks == 0 ||
(g_io_size % spdk_bdev_get_block_size(bdev)) != 0) {
SPDK_ERRLOG("IO size (%d) is bigger than blocksize of bdev %s (%"PRIu32") or not a blocksize multiple\n",
g_io_size, spdk_bdev_get_name(bdev), spdk_bdev_get_block_size(bdev));
spdk_bdev_close(target->bdev_desc);
free(target->name);
free(target);
bdev = spdk_bdev_next_leaf(bdev);
continue;
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++;
}
target->size_in_ios = spdk_bdev_get_num_blocks(bdev) / target->io_size_blocks;
align = spdk_bdev_get_buf_align(bdev);
/*
* TODO: This should actually use the LCM of align and g_min_alignment, but
* it is fairly safe to assume all alignments are powers of two for now.
*/
g_min_alignment = spdk_max(g_min_alignment, align);
target->is_draining = false;
target->run_timer = NULL;
target->reset_timer = NULL;
TAILQ_INIT(&target->task_list);
g_head[index] = target;
g_target_count++;
bdev = spdk_bdev_next_leaf(bdev);
}
}