From 4f5b735c5798ff01da11b48268267c73e200e67e Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Thu, 15 Sep 2022 10:05:56 +0200 Subject: [PATCH] librbd: no need to return format from ShutDownCryptoRequest luks::FlattenRequest was the only user of this interface. Signed-off-by: Ilya Dryomov --- src/librbd/crypto/FormatRequest.cc | 2 +- src/librbd/crypto/ShutDownCryptoRequest.cc | 15 ++++----------- src/librbd/crypto/ShutDownCryptoRequest.h | 14 ++++---------- src/test/librbd/crypto/test_mock_FormatRequest.cc | 6 ++---- .../crypto/test_mock_ShutDownCryptoRequest.cc | 5 +---- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/librbd/crypto/FormatRequest.cc b/src/librbd/crypto/FormatRequest.cc index c4a15790873..5e90bbb7632 100644 --- a/src/librbd/crypto/FormatRequest.cc +++ b/src/librbd/crypto/FormatRequest.cc @@ -54,7 +54,7 @@ void FormatRequest::send() { auto ctx = create_context_callback< FormatRequest, &FormatRequest::handle_shutdown_crypto>(this); - auto *req = ShutDownCryptoRequest::create(m_image_ctx, nullptr, ctx); + auto *req = ShutDownCryptoRequest::create(m_image_ctx, ctx); req->send(); } diff --git a/src/librbd/crypto/ShutDownCryptoRequest.cc b/src/librbd/crypto/ShutDownCryptoRequest.cc index 47613f83355..fb1e7747968 100644 --- a/src/librbd/crypto/ShutDownCryptoRequest.cc +++ b/src/librbd/crypto/ShutDownCryptoRequest.cc @@ -23,11 +23,9 @@ namespace crypto { using librbd::util::create_context_callback; template -ShutDownCryptoRequest::ShutDownCryptoRequest( - I* image_ctx, EncryptionFormat* format, - Context* on_finish) : m_image_ctx(image_ctx), m_format(format), - m_on_finish(on_finish) { -} +ShutDownCryptoRequest::ShutDownCryptoRequest(I* image_ctx, + Context* on_finish) + : m_image_ctx(image_ctx), m_on_finish(on_finish) {} template void ShutDownCryptoRequest::send() { @@ -97,12 +95,7 @@ void ShutDownCryptoRequest::finish(int r) { if (r == 0) { { std::unique_lock image_locker{m_image_ctx->image_lock}; - if (m_format != nullptr) { - *m_format = std::move(m_image_ctx->encryption_format); - m_format = nullptr; - } else { - m_image_ctx->encryption_format.reset(); - } + m_image_ctx->encryption_format.reset(); } if (m_image_ctx->parent != nullptr) { diff --git a/src/librbd/crypto/ShutDownCryptoRequest.h b/src/librbd/crypto/ShutDownCryptoRequest.h index e576e9c7748..27422857408 100644 --- a/src/librbd/crypto/ShutDownCryptoRequest.h +++ b/src/librbd/crypto/ShutDownCryptoRequest.h @@ -14,20 +14,15 @@ class ImageCtx; namespace crypto { -template class EncryptionFormat; - template class ShutDownCryptoRequest { public: - using EncryptionFormat = decltype(I::encryption_format); - - static ShutDownCryptoRequest* create( - I* image_ctx, EncryptionFormat* format, Context* on_finish) { - return new ShutDownCryptoRequest(image_ctx, format, on_finish); + static ShutDownCryptoRequest* create(I* image_ctx, Context* on_finish) { + return new ShutDownCryptoRequest(image_ctx, on_finish); } - ShutDownCryptoRequest( - I* image_ctx, EncryptionFormat* format, Context* on_finish); + ShutDownCryptoRequest(I* image_ctx, Context* on_finish); + void send(); void shut_down_object_dispatch(); void handle_shut_down_object_dispatch(int r); @@ -37,7 +32,6 @@ public: private: I* m_image_ctx; - EncryptionFormat* m_format; Context* m_on_finish; }; diff --git a/src/test/librbd/crypto/test_mock_FormatRequest.cc b/src/test/librbd/crypto/test_mock_FormatRequest.cc index 9cb0048fb3a..81b82429d7f 100644 --- a/src/test/librbd/crypto/test_mock_FormatRequest.cc +++ b/src/test/librbd/crypto/test_mock_FormatRequest.cc @@ -55,10 +55,8 @@ template <> struct ShutDownCryptoRequest { Context *on_finish = nullptr; static ShutDownCryptoRequest *s_instance; - static ShutDownCryptoRequest *create( - MockTestImageCtx *image_ctx, - std::unique_ptr* format, - Context *on_finish) { + static ShutDownCryptoRequest *create(MockTestImageCtx *image_ctx, + Context *on_finish) { ceph_assert(s_instance != nullptr); s_instance->on_finish = on_finish; return s_instance; diff --git a/src/test/librbd/crypto/test_mock_ShutDownCryptoRequest.cc b/src/test/librbd/crypto/test_mock_ShutDownCryptoRequest.cc index e6a837bb438..7df99b78ac9 100644 --- a/src/test/librbd/crypto/test_mock_ShutDownCryptoRequest.cc +++ b/src/test/librbd/crypto/test_mock_ShutDownCryptoRequest.cc @@ -38,7 +38,6 @@ struct TestMockShutDownCryptoRequest : public TestMockFixture { Context *on_finish = &finished_cond; MockShutDownCryptoRequest* mock_shutdown_crypto_request; MockEncryptionFormat* mock_encryption_format; - std::unique_ptr result_format; Context* shutdown_object_dispatch_context; Context* shutdown_image_dispatch_context; @@ -51,7 +50,7 @@ struct TestMockShutDownCryptoRequest : public TestMockFixture { mock_encryption_format = new MockEncryptionFormat(); mock_image_ctx->encryption_format.reset(mock_encryption_format); mock_shutdown_crypto_request = MockShutDownCryptoRequest::create( - mock_image_ctx, &result_format, on_finish); + mock_image_ctx, on_finish); } void TearDown() override { @@ -142,7 +141,6 @@ TEST_F(TestMockShutDownCryptoRequest, Success) { shutdown_image_dispatch_context->complete(0); ASSERT_EQ(0, finished_cond.wait()); ASSERT_EQ(nullptr, mock_image_ctx->encryption_format.get()); - ASSERT_EQ(mock_encryption_format, result_format.get()); } TEST_F(TestMockShutDownCryptoRequest, ShutdownParent) { @@ -169,7 +167,6 @@ TEST_F(TestMockShutDownCryptoRequest, ShutdownParent) { ASSERT_EQ(0, finished_cond.wait()); ASSERT_EQ(nullptr, mock_image_ctx->encryption_format.get()); ASSERT_EQ(nullptr, parent_image_ctx->encryption_format.get()); - ASSERT_EQ(mock_encryption_format, result_format.get()); delete parent_image_ctx; } -- 2.39.5