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 <paul.e.luse@intel.com>
Change-Id: I00b00d8a83edfad51f3945c49764ae6442fb6f52
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477332
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
paul luse 2019-12-09 15:57:19 +00:00 committed by Tomasz Zawadzki
parent 5db021089d
commit 1a6878db61

View File

@ -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. */