From 1a6878db61895e3bdf5178f5a139b3e1070261f9 Mon Sep 17 00:00:00 2001 From: paul luse Date: Mon, 9 Dec 2019 15:57:19 +0000 Subject: [PATCH] module/crypto: break out device/qp code into helper function Mainly to make it way easier to write the UT in the next patch in the series. Signed-off-by: paul luse Change-Id: I00b00d8a83edfad51f3945c49764ae6442fb6f52 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477332 Tested-by: SPDK CI Jenkins Community-CI: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- module/bdev/crypto/vbdev_crypto.c | 41 +++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/module/bdev/crypto/vbdev_crypto.c b/module/bdev/crypto/vbdev_crypto.c index b2530f048..2ad36dfcf 100644 --- a/module/bdev/crypto/vbdev_crypto.c +++ b/module/bdev/crypto/vbdev_crypto.c @@ -1237,23 +1237,11 @@ vbdev_crypto_config_json(struct spdk_json_write_ctx *w) return 0; } -/* We provide this callback for the SPDK channel code to create a channel using - * the channel struct we provided in our module get_io_channel() entry point. Here - * we get and save off an underlying base channel of the device below us so that - * we can communicate with the base bdev on a per channel basis. We also register the - * poller used to complete crypto operations from the device. - */ -static int -crypto_bdev_ch_create_cb(void *io_device, void *ctx_buf) +/* Helper function for the channel creation callback. */ +static void +_assign_device_qp(struct vbdev_crypto *crypto_bdev, struct device_qp *device_qp, + struct crypto_io_channel *crypto_ch) { - struct crypto_io_channel *crypto_ch = ctx_buf; - struct vbdev_crypto *crypto_bdev = io_device; - struct device_qp *device_qp; - - crypto_ch->base_ch = spdk_bdev_get_io_channel(crypto_bdev->base_desc); - crypto_ch->poller = spdk_poller_register(crypto_dev_poller, crypto_ch, 0); - crypto_ch->device_qp = NULL; - pthread_mutex_lock(&g_device_qp_lock); if (strcmp(crypto_bdev->drv_name, QAT) == 0) { TAILQ_FOREACH(device_qp, &g_device_qp_qat, link) { @@ -1273,6 +1261,27 @@ crypto_bdev_ch_create_cb(void *io_device, void *ctx_buf) } } pthread_mutex_unlock(&g_device_qp_lock); +} + +/* We provide this callback for the SPDK channel code to create a channel using + * the channel struct we provided in our module get_io_channel() entry point. Here + * we get and save off an underlying base channel of the device below us so that + * we can communicate with the base bdev on a per channel basis. We also register the + * poller used to complete crypto operations from the device. + */ +static int +crypto_bdev_ch_create_cb(void *io_device, void *ctx_buf) +{ + struct crypto_io_channel *crypto_ch = ctx_buf; + struct vbdev_crypto *crypto_bdev = io_device; + struct device_qp *device_qp = NULL; + + crypto_ch->base_ch = spdk_bdev_get_io_channel(crypto_bdev->base_desc); + crypto_ch->poller = spdk_poller_register(crypto_dev_poller, crypto_ch, 0); + crypto_ch->device_qp = NULL; + + /* Assign a device/qp combination that is unique per channel per PMD. */ + _assign_device_qp(crypto_bdev, device_qp, crypto_ch); assert(crypto_ch->device_qp); /* We use this queue to track outstanding IO in our layer. */