Skip to content

Commit

Permalink
librbd: move get_file_offset() into CryptoObjectDispatch
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
idryomov committed Dec 4, 2022
1 parent a54f1a2 commit 744379b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
17 changes: 12 additions & 5 deletions src/librbd/crypto/CryptoObjectDispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions src/librbd/io/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

4 changes: 0 additions & 4 deletions src/librbd/io/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 8 additions & 7 deletions src/test/librbd/crypto/test_mock_CryptoObjectDispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -795,5 +796,5 @@ TEST_F(TestMockCryptoCryptoObjectDispatch, PrepareCopyup) {
ASSERT_EQ(++it, snap2_result.end());
}

} // namespace io
} // namespace crypto
} // namespace librbd

0 comments on commit 744379b

Please sign in to comment.