diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 929c2c70d..075d99637 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -8,6 +8,7 @@ #include "spdk/bdev.h" +#include "spdk/accel.h" #include "spdk/config.h" #include "spdk/env.h" #include "spdk/thread.h" @@ -263,6 +264,9 @@ struct spdk_bdev_channel { /* The channel for the underlying device */ struct spdk_io_channel *channel; + /* Accel channel */ + struct spdk_io_channel *accel_channel; + /* Per io_device per thread data */ struct spdk_bdev_shared_resource *shared_resource; @@ -3277,6 +3281,7 @@ bdev_channel_destroy_resource(struct spdk_bdev_channel *ch) } spdk_put_io_channel(ch->channel); + spdk_put_io_channel(ch->accel_channel); shared_resource = ch->shared_resource; @@ -3494,6 +3499,12 @@ bdev_channel_create(void *io_device, void *ctx_buf) return -1; } + ch->accel_channel = spdk_accel_get_io_channel(); + if (!ch->accel_channel) { + spdk_put_io_channel(ch->channel); + return -1; + } + spdk_trace_record(TRACE_BDEV_IOCH_CREATE, 0, 0, 0, ch->bdev->name, spdk_thread_get_id(spdk_io_channel_get_thread(ch->channel))); @@ -3508,6 +3519,7 @@ bdev_channel_create(void *io_device, void *ctx_buf) mgmt_io_ch = spdk_get_io_channel(&g_bdev_mgr); if (!mgmt_io_ch) { spdk_put_io_channel(ch->channel); + spdk_put_io_channel(ch->accel_channel); return -1; } @@ -3524,6 +3536,7 @@ bdev_channel_create(void *io_device, void *ctx_buf) shared_resource = calloc(1, sizeof(*shared_resource)); if (shared_resource == NULL) { spdk_put_io_channel(ch->channel); + spdk_put_io_channel(ch->accel_channel); spdk_put_io_channel(mgmt_io_ch); return -1; } diff --git a/mk/spdk.lib_deps.mk b/mk/spdk.lib_deps.mk index 565536a92..2ddf7d0bc 100644 --- a/mk/spdk.lib_deps.mk +++ b/mk/spdk.lib_deps.mk @@ -59,7 +59,7 @@ DEPDIRS-net := log util $(JSON_LIBS) DEPDIRS-notify := log util $(JSON_LIBS) DEPDIRS-trace := log util $(JSON_LIBS) -DEPDIRS-bdev := log util thread $(JSON_LIBS) notify trace dma +DEPDIRS-bdev := accel log util thread $(JSON_LIBS) notify trace dma DEPDIRS-blobfs := log thread blob trace util DEPDIRS-event := log util thread $(JSON_LIBS) trace init DEPDIRS-init := jsonrpc json log rpc thread util diff --git a/test/unit/lib/bdev/bdev.c/bdev_ut.c b/test/unit/lib/bdev/bdev.c/bdev_ut.c index 593af8667..49ccf10c7 100644 --- a/test/unit/lib/bdev/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/bdev.c/bdev_ut.c @@ -24,6 +24,7 @@ DEFINE_STUB(spdk_memory_domain_get_dma_device_type, enum spdk_dma_device_type, static bool g_memory_domain_pull_data_called; static bool g_memory_domain_push_data_called; +static int g_accel_io_device; DEFINE_RETURN_MOCK(spdk_memory_domain_pull_data, int); int @@ -49,6 +50,12 @@ spdk_memory_domain_push_data(struct spdk_memory_domain *dst_domain, void *dst_do return 0; } +struct spdk_io_channel * +spdk_accel_get_io_channel(void) +{ + return spdk_get_io_channel(&g_accel_io_device); +} + int g_status; int g_count; enum spdk_bdev_event_type g_event_type1; @@ -66,14 +73,29 @@ spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io, } static int -null_init(void) +ut_accel_ch_create_cb(void *io_device, void *ctx) { return 0; } -static int -null_clean(void) +static void +ut_accel_ch_destroy_cb(void *io_device, void *ctx) { +} + +static int +ut_bdev_setup(void) +{ + spdk_io_device_register(&g_accel_io_device, ut_accel_ch_create_cb, + ut_accel_ch_destroy_cb, 0, NULL); + return 0; +} + +static int +ut_bdev_teardown(void) +{ + spdk_io_device_unregister(&g_accel_io_device, NULL); + return 0; } @@ -7012,7 +7034,7 @@ main(int argc, char **argv) CU_set_error_action(CUEA_ABORT); CU_initialize_registry(); - suite = CU_add_suite("bdev", null_init, null_clean); + suite = CU_add_suite("bdev", ut_bdev_setup, ut_bdev_teardown); CU_ADD_TEST(suite, bytes_to_blocks_test); CU_ADD_TEST(suite, num_blocks_test); diff --git a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c index e78716973..241673a11 100644 --- a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c @@ -50,6 +50,14 @@ spdk_memory_domain_push_data(struct spdk_memory_domain *dst_domain, void *dst_do return 0; } +static int g_accel_io_device; + +struct spdk_io_channel * +spdk_accel_get_io_channel(void) +{ + return spdk_get_io_channel(&g_accel_io_device); +} + struct ut_bdev { struct spdk_bdev bdev; void *io_target; @@ -73,6 +81,17 @@ int g_status = 0; int g_count = 0; struct spdk_histogram_data *g_histogram = NULL; +static int +ut_accel_ch_create_cb(void *io_device, void *ctx) +{ + return 0; +} + +static void +ut_accel_ch_destroy_cb(void *io_device, void *ctx) +{ +} + static int stub_create_ch(void *io_device, void *ctx_buf) { @@ -300,6 +319,8 @@ setup_test(void) spdk_bdev_initialize(bdev_init_cb, &done); spdk_io_device_register(&g_io_device, stub_create_ch, stub_destroy_ch, sizeof(struct ut_bdev_channel), NULL); + spdk_io_device_register(&g_accel_io_device, ut_accel_ch_create_cb, + ut_accel_ch_destroy_cb, 0, NULL); register_bdev(&g_bdev, "ut_bdev", &g_io_device); spdk_bdev_open_ext("ut_bdev", true, _bdev_event_cb, NULL, &g_desc); } @@ -320,6 +341,7 @@ teardown_test(void) unregister_bdev(&g_bdev); spdk_io_device_unregister(&g_io_device, NULL); spdk_bdev_finish(finish_cb, NULL); + spdk_io_device_unregister(&g_accel_io_device, NULL); spdk_iobuf_finish(finish_cb, NULL); poll_threads(); memset(&g_bdev, 0, sizeof(g_bdev)); @@ -2353,7 +2375,6 @@ bdev_init_wt_cb(void *done, int rc) { } - static int wrong_thread_setup(void) { @@ -2361,6 +2382,8 @@ wrong_thread_setup(void) allocate_threads(2); set_thread(0); + spdk_io_device_register(&g_accel_io_device, ut_accel_ch_create_cb, + ut_accel_ch_destroy_cb, 0, NULL); spdk_bdev_initialize(bdev_init_wt_cb, NULL); spdk_io_device_register(&g_io_device, stub_create_ch, stub_destroy_ch, sizeof(struct ut_bdev_channel), NULL); @@ -2388,6 +2411,7 @@ wrong_thread_teardown(void) } g_teardown_done = false; + spdk_io_device_unregister(&g_accel_io_device, NULL); free_threads(); free_cores(); diff --git a/test/unit/lib/bdev/part.c/part_ut.c b/test/unit/lib/bdev/part.c/part_ut.c index eb9ef6614..ec63bc6f2 100644 --- a/test/unit/lib/bdev/part.c/part_ut.c +++ b/test/unit/lib/bdev/part.c/part_ut.c @@ -26,6 +26,7 @@ struct bdev_ut_channel { static uint32_t g_part_ut_io_device; static struct bdev_ut_channel *g_bdev_ut_channel; +static int g_accel_io_device; DEFINE_STUB(spdk_notify_send, uint64_t, (const char *type, const char *ctx), 0); DEFINE_STUB(spdk_notify_type_register, struct spdk_notify_type *, (const char *type), NULL); @@ -58,6 +59,39 @@ spdk_memory_domain_push_data(struct spdk_memory_domain *dst_domain, void *dst_do return 0; } +struct spdk_io_channel * +spdk_accel_get_io_channel(void) +{ + return spdk_get_io_channel(&g_accel_io_device); +} + +static int +ut_accel_ch_create_cb(void *io_device, void *ctx) +{ + return 0; +} + +static void +ut_accel_ch_destroy_cb(void *io_device, void *ctx) +{ +} + +static int +ut_part_setup(void) +{ + spdk_io_device_register(&g_accel_io_device, ut_accel_ch_create_cb, + ut_accel_ch_destroy_cb, 0, NULL); + return 0; +} + +static int +ut_part_teardown(void) +{ + spdk_io_device_unregister(&g_accel_io_device, NULL); + + return 0; +} + static void _part_cleanup(struct spdk_bdev_part *part) { @@ -358,7 +392,7 @@ main(int argc, char **argv) CU_set_error_action(CUEA_ABORT); CU_initialize_registry(); - suite = CU_add_suite("bdev_part", NULL, NULL); + suite = CU_add_suite("bdev_part", ut_part_setup, ut_part_teardown); CU_ADD_TEST(suite, part_test); CU_ADD_TEST(suite, part_free_test);