]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/crypto/CryptoImageDispatch.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / crypto / CryptoImageDispatch.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "librbd/crypto/CryptoImageDispatch.h"
5
6 namespace librbd {
7 namespace crypto {
8
9 CryptoImageDispatch::CryptoImageDispatch(
10 uint64_t data_offset) : m_data_offset(data_offset) {
11 }
12
13 void CryptoImageDispatch::remap_to_physical(io::Extents& image_extents,
14 io::ImageArea area) {
15 switch (area) {
16 case io::ImageArea::DATA:
17 for (auto& [off, _] : image_extents) {
18 off += m_data_offset;
19 }
20 break;
21 case io::ImageArea::CRYPTO_HEADER:
22 // direct mapping
23 break;
24 default:
25 ceph_abort();
26 }
27 }
28
29 io::ImageArea CryptoImageDispatch::remap_to_logical(
30 io::Extents& image_extents) {
31 bool saw_data = false;
32 bool saw_crypto_header = false;
33 for (auto& [off, _] : image_extents) {
34 if (off >= m_data_offset) {
35 off -= m_data_offset;
36 saw_data = true;
37 } else {
38 saw_crypto_header = true;
39 }
40 }
41 if (saw_crypto_header) {
42 ceph_assert(!saw_data);
43 return io::ImageArea::CRYPTO_HEADER;
44 }
45 return io::ImageArea::DATA;
46 }
47
48 } // namespace crypto
49 } // namespace librbd