From 454ee6be5e056fecbe2d44259b63078d33fb092d Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Tue, 28 Feb 2023 08:16:13 +0100 Subject: [PATCH] bdev/crypto: merge IO-type specific callbacks All these callbacks look identical now, so there's little point in having three different functions doing the same thing. Signed-off-by: Konrad Sztyber Change-Id: I60d1426b5d2b20d924776699885e6a9dd176504a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17024 Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- module/bdev/crypto/vbdev_crypto.c | 35 ++----------------------- test/unit/lib/bdev/crypto.c/crypto_ut.c | 2 +- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/module/bdev/crypto/vbdev_crypto.c b/module/bdev/crypto/vbdev_crypto.c index d91f5f1f5..6f92de5fc 100644 --- a/module/bdev/crypto/vbdev_crypto.c +++ b/module/bdev/crypto/vbdev_crypto.c @@ -72,7 +72,6 @@ struct crypto_bdev_io { static void vbdev_crypto_queue_io(struct spdk_bdev_io *bdev_io, enum crypto_io_resubmit_state state); static void _complete_internal_io(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg); -static void _complete_internal_write(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg); static void vbdev_crypto_examine(struct spdk_bdev *bdev); static int vbdev_crypto_claim(const char *bdev_name); static void vbdev_crypto_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io); @@ -94,7 +93,7 @@ crypto_write(struct crypto_io_channel *crypto_ch, struct spdk_bdev_io *bdev_io) /* Write the encrypted data. */ rc = spdk_bdev_writev_blocks_ext(crypto_bdev->base_desc, crypto_ch->base_ch, &crypto_io->aux_buf_iov, 1, crypto_io->aux_offset_blocks, - crypto_io->aux_num_blocks, _complete_internal_write, + crypto_io->aux_num_blocks, _complete_internal_io, bdev_io, &opts); if (spdk_unlikely(rc != 0)) { if (rc == -ENOMEM) { @@ -166,9 +165,6 @@ crypto_encrypt(struct crypto_io_channel *crypto_ch, struct spdk_bdev_io *bdev_io crypto_write(crypto_ch, bdev_io); } -/* Completion callback for IO that were issued from this bdev other than read/write. - * They have their own for readability. - */ static void _complete_internal_io(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) { @@ -179,33 +175,6 @@ _complete_internal_io(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) spdk_bdev_free_io(bdev_io); } -/* Completion callback for writes that were issued from this bdev. */ -static void -_complete_internal_write(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) -{ - struct spdk_bdev_io *orig_io = cb_arg; - int status = success ? SPDK_BDEV_IO_STATUS_SUCCESS : SPDK_BDEV_IO_STATUS_FAILED; - - spdk_bdev_io_complete(orig_io, status); - spdk_bdev_free_io(bdev_io); -} - -/* Completion callback for reads that were issued from this bdev. */ -static void -_complete_internal_read(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) -{ - struct spdk_bdev_io *orig_io = cb_arg; - enum spdk_bdev_io_status status = SPDK_BDEV_IO_STATUS_SUCCESS; - - if (spdk_unlikely(!success)) { - SPDK_ERRLOG("Failed to read prior to decrypting!\n"); - status = SPDK_BDEV_IO_STATUS_FAILED; - } - - spdk_bdev_io_complete(orig_io, status); - spdk_bdev_free_io(bdev_io); -} - static void crypto_read(struct crypto_io_channel *crypto_ch, struct spdk_bdev_io *bdev_io); static void @@ -270,7 +239,7 @@ crypto_read(struct crypto_io_channel *crypto_ch, struct spdk_bdev_io *bdev_io) rc = spdk_bdev_readv_blocks_ext(crypto_bdev->base_desc, crypto_ch->base_ch, bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.num_blocks, - _complete_internal_read, bdev_io, &opts); + _complete_internal_io, bdev_io, &opts); if (rc != 0) { if (rc == -ENOMEM) { SPDK_DEBUGLOG(vbdev_crypto, "No memory, queue the IO.\n"); diff --git a/test/unit/lib/bdev/crypto.c/crypto_ut.c b/test/unit/lib/bdev/crypto.c/crypto_ut.c index 037c752b5..743bc66a1 100644 --- a/test/unit/lib/bdev/crypto.c/crypto_ut.c +++ b/test/unit/lib/bdev/crypto.c/crypto_ut.c @@ -426,7 +426,7 @@ test_crypto_op_complete(void) g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS; g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ; g_completion_called = false; - _complete_internal_read(NULL, true, g_bdev_io); + _complete_internal_io(NULL, true, g_bdev_io); CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS); CU_ASSERT(g_completion_called == true);