]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: move get_file_offset() into CryptoObjectDispatch
authorIlya Dryomov <idryomov@gmail.com>
Mon, 26 Sep 2022 10:57:16 +0000 (12:57 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Sun, 4 Dec 2022 17:19:19 +0000 (18:19 +0100)
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 <idryomov@gmail.com>
src/librbd/crypto/CryptoObjectDispatch.cc
src/librbd/io/Utils.cc
src/librbd/io/Utils.h
src/test/librbd/crypto/test_mock_CryptoObjectDispatch.cc

index 05c634abd3b09b040433bc5d724ad08313cb194b..6ba449099410f13a2dedf8f3269487c7198c60af 100644 (file)
@@ -26,6 +26,16 @@ namespace crypto {
 using librbd::util::create_context_callback;
 using librbd::util::data_object_name;
 
+template <typename I>
+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 <typename I>
 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<I>::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);
index f4cb42957e7aaa2ec544225859596cecb0cf30ac..6b9fa5dca170643b8db1ec07311f7ad829750995 100644 (file)
@@ -223,15 +223,6 @@ std::pair<uint64_t, ImageArea> raw_to_area_offset(const I& image_ctx,
   return {extents[0].first, area};
 }
 
-template <typename I>
-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<uint64_t, ImageArea>;
-template uint64_t librbd::io::util::get_file_offset(
-        librbd::ImageCtx *image_ctx, uint64_t object_no, uint64_t offset);
index f2096de842d707a331014ce3232bdda3c7aa61bf..04e8ba0e04a0ed2e2452a77fffbf054169b3c842 100644 (file)
@@ -72,10 +72,6 @@ template <typename ImageCtxT = librbd::ImageCtx>
 std::pair<uint64_t, ImageArea> raw_to_area_offset(const ImageCtxT& image_ctx,
                                                   uint64_t offset);
 
-template <typename ImageCtxT = librbd::ImageCtx>
-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);
 }
index 7ad4efa4e3459c624008c60ad1d6a9872af62a3d..38a1cbbdebcc6d1f8f3f0ffbf4825d8986031fd3 100644 (file)
@@ -55,12 +55,6 @@ CopyupRequest<librbd::MockImageCtx>* 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