From: Ilya Dryomov Date: Mon, 26 Sep 2022 10:57:16 +0000 (+0200) Subject: librbd: move get_file_offset() into CryptoObjectDispatch X-Git-Tag: v18.1.0~754^2~20 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=744379b8c60e23f3034d1a8ee94fb641809d791a;p=ceph.git librbd: move get_file_offset() into CryptoObjectDispatch This method doesn't propagate area. Since its only user is CryptoObjectDispatch which is now applied only to DATA area, move get_file_offset() there to avoid misuse in the future. Signed-off-by: Ilya Dryomov --- diff --git a/src/librbd/crypto/CryptoObjectDispatch.cc b/src/librbd/crypto/CryptoObjectDispatch.cc index 05c634abd3b0..6ba449099410 100644 --- a/src/librbd/crypto/CryptoObjectDispatch.cc +++ b/src/librbd/crypto/CryptoObjectDispatch.cc @@ -26,6 +26,16 @@ namespace crypto { using librbd::util::create_context_callback; using librbd::util::data_object_name; +template +uint64_t get_file_offset(I* image_ctx, uint64_t object_no, + uint64_t object_off) { + auto off = io::util::raw_to_area_offset( + *image_ctx, Striper::get_file_offset(image_ctx->cct, &image_ctx->layout, + object_no, object_off)); + ceph_assert(off.second == io::ImageArea::DATA); + return off.first; +} + template struct C_AlignedObjectReadRequest : public Context { I* image_ctx; @@ -79,9 +89,7 @@ struct C_AlignedObjectReadRequest : public Context { r = 0; for (auto& extent: *extents) { auto crypto_ret = crypto->decrypt_aligned_extent( - extent, - io::util::get_file_offset( - image_ctx, object_no, extent.offset)); + extent, get_file_offset(image_ctx, object_no, extent.offset)); if (crypto_ret != 0) { ceph_assert(crypto_ret < 0); r = crypto_ret; @@ -494,8 +502,7 @@ bool CryptoObjectDispatch::write( if (m_crypto->is_aligned(object_off, data.length())) { auto r = m_crypto->encrypt( - &data, - io::util::get_file_offset(m_image_ctx, object_no, object_off)); + &data, get_file_offset(m_image_ctx, object_no, object_off)); *dispatch_result = r == 0 ? io::DISPATCH_RESULT_CONTINUE : io::DISPATCH_RESULT_COMPLETE; on_dispatched->complete(r); diff --git a/src/librbd/io/Utils.cc b/src/librbd/io/Utils.cc index f4cb42957e7a..6b9fa5dca170 100644 --- a/src/librbd/io/Utils.cc +++ b/src/librbd/io/Utils.cc @@ -223,15 +223,6 @@ std::pair raw_to_area_offset(const I& image_ctx, return {extents[0].first, area}; } -template -uint64_t get_file_offset(I* image_ctx, uint64_t object_no, uint64_t offset) { - auto off = Striper::get_file_offset(image_ctx->cct, &image_ctx->layout, - object_no, offset); - Extents extents = {{off, 0}}; - image_ctx->io_image_dispatcher->remap_to_logical(extents); - return extents[0].first; -} - } // namespace util } // namespace io } // namespace librbd @@ -256,6 +247,3 @@ template uint64_t librbd::io::util::area_to_raw_offset( template auto librbd::io::util::raw_to_area_offset( const librbd::ImageCtx& image_ctx, uint64_t offset) -> std::pair; -template uint64_t librbd::io::util::get_file_offset( - librbd::ImageCtx *image_ctx, uint64_t object_no, uint64_t offset); - diff --git a/src/librbd/io/Utils.h b/src/librbd/io/Utils.h index f2096de842d7..04e8ba0e04a0 100644 --- a/src/librbd/io/Utils.h +++ b/src/librbd/io/Utils.h @@ -72,10 +72,6 @@ template std::pair raw_to_area_offset(const ImageCtxT& image_ctx, uint64_t offset); -template -uint64_t get_file_offset(ImageCtxT *image_ctx, uint64_t object_no, - uint64_t offset); - inline ObjectDispatchLayer get_previous_layer(ObjectDispatchLayer layer) { return (ObjectDispatchLayer)(((int)layer) - 1); } diff --git a/src/test/librbd/crypto/test_mock_CryptoObjectDispatch.cc b/src/test/librbd/crypto/test_mock_CryptoObjectDispatch.cc index 7ad4efa4e345..38a1cbbdebcc 100644 --- a/src/test/librbd/crypto/test_mock_CryptoObjectDispatch.cc +++ b/src/test/librbd/crypto/test_mock_CryptoObjectDispatch.cc @@ -55,12 +55,6 @@ CopyupRequest* CopyupRequest< namespace util { -template <> uint64_t get_file_offset( - MockImageCtx *image_ctx, uint64_t object_no, uint64_t offset) { - return Striper::get_file_offset(image_ctx->cct, &image_ctx->layout, - object_no, offset); -} - namespace { struct Mock { @@ -98,6 +92,13 @@ template <> void read_parent( namespace librbd { namespace crypto { +template <> +uint64_t get_file_offset(MockImageCtx *image_ctx, uint64_t object_no, + uint64_t offset) { + return Striper::get_file_offset(image_ctx->cct, &image_ctx->layout, + object_no, offset); +} + using ::testing::_; using ::testing::ElementsAre; using ::testing::Invoke; @@ -795,5 +796,5 @@ TEST_F(TestMockCryptoCryptoObjectDispatch, PrepareCopyup) { ASSERT_EQ(++it, snap2_result.end()); } -} // namespace io +} // namespace crypto } // namespace librbd