test/bdevio: add function to create target from single bdev

Adding ability to create targets from single bdev,
will allow to create set of targets (not all) to run tests.

Idea is for bdevio to no longer run tests on all bdevs and
shutdown right after. Rather await RPC for configuring bdevs
then start test suite on select targets via RPC.
This is first patch in that direction.

Change-Id: I8645a3c22150e8611ff8a59f740e2ebf4edb4c1f
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/454622
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Tomasz Zawadzki 2019-05-15 08:29:55 -04:00 committed by Jim Harris
parent 1cb299addc
commit 84429e7bbb

View File

@ -101,42 +101,54 @@ __get_io_channel(void *arg1, void *arg2)
wake_ut_thread();
}
static int
bdevio_construct_target(struct spdk_bdev *bdev)
{
struct io_target *target;
int rc;
uint64_t num_blocks = spdk_bdev_get_num_blocks(bdev);
uint32_t block_size = spdk_bdev_get_block_size(bdev);
target = malloc(sizeof(struct io_target));
if (target == NULL) {
return -ENOMEM;
}
rc = spdk_bdev_open(bdev, true, NULL, NULL, &target->bdev_desc);
if (rc != 0) {
free(target);
SPDK_ERRLOG("Could not open leaf bdev %s, error=%d\n", spdk_bdev_get_name(bdev), rc);
return rc;
}
printf(" %s: %" PRIu64 " blocks of %" PRIu32 " bytes (%" PRIu64 " MiB)\n",
spdk_bdev_get_name(bdev),
num_blocks, block_size,
(num_blocks * block_size + 1024 * 1024 - 1) / (1024 * 1024));
target->bdev = bdev;
target->next = g_io_targets;
execute_spdk_function(__get_io_channel, target, NULL);
g_io_targets = target;
return 0;
}
static int
bdevio_construct_targets(void)
{
struct spdk_bdev *bdev;
struct io_target *target;
int rc;
printf("I/O targets:\n");
bdev = spdk_bdev_first_leaf();
while (bdev != NULL) {
uint64_t num_blocks = spdk_bdev_get_num_blocks(bdev);
uint32_t block_size = spdk_bdev_get_block_size(bdev);
target = malloc(sizeof(struct io_target));
if (target == NULL) {
return -ENOMEM;
}
rc = spdk_bdev_open(bdev, true, NULL, NULL, &target->bdev_desc);
if (rc != 0) {
free(target);
SPDK_ERRLOG("Could not open leaf bdev %s, error=%d\n", spdk_bdev_get_name(bdev), rc);
rc = bdevio_construct_target(bdev);
if (rc < 0) {
SPDK_ERRLOG("Could not construct bdev %s, error=%d\n", spdk_bdev_get_name(bdev), rc);
return rc;
}
printf(" %s: %" PRIu64 " blocks of %" PRIu32 " bytes (%" PRIu64 " MiB)\n",
spdk_bdev_get_name(bdev),
num_blocks, block_size,
(num_blocks * block_size + 1024 * 1024 - 1) / (1024 * 1024));
target->bdev = bdev;
target->next = g_io_targets;
execute_spdk_function(__get_io_channel, target, NULL);
g_io_targets = target;
bdev = spdk_bdev_next_leaf(bdev);
}