summaryrefslogtreecommitdiffstats
path: root/src/librbd/crypto/CryptoImageDispatch.cc
blob: 4d4c360dc5ef9280fd82d15d67be263539788375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "librbd/crypto/CryptoImageDispatch.h"

namespace librbd {
namespace crypto {

CryptoImageDispatch::CryptoImageDispatch(
        uint64_t data_offset) : m_data_offset(data_offset) {
}

void CryptoImageDispatch::remap_to_physical(io::Extents& image_extents,
                                            io::ImageArea area) {
  switch (area) {
  case io::ImageArea::DATA:
    for (auto& [off, _] : image_extents) {
      off += m_data_offset;
    }
    break;
  case io::ImageArea::CRYPTO_HEADER:
    // direct mapping
    break;
  default:
    ceph_abort();
  }
}

io::ImageArea CryptoImageDispatch::remap_to_logical(
    io::Extents& image_extents) {
  bool saw_data = false;
  bool saw_crypto_header = false;
  for (auto& [off, _] : image_extents) {
    if (off >= m_data_offset) {
      off -= m_data_offset;
      saw_data = true;
    } else {
      saw_crypto_header = true;
    }
  }
  if (saw_crypto_header) {
    ceph_assert(!saw_data);
    return io::ImageArea::CRYPTO_HEADER;
  }
  return io::ImageArea::DATA;
}

} // namespace crypto
} // namespace librbd