summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_mirror/PoolMetaCache.cc
blob: 261802a55c53483ce5b9c449effa8df1f895ad0b (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "common/debug.h"
#include "common/dout.h"
#include "tools/rbd_mirror/PoolMetaCache.h"
#include <shared_mutex>

#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rbd_mirror
#undef dout_prefix
#define dout_prefix *_dout << "rbd::mirror::PoolMetaCache: " \
                           << this << " " << __func__ << ": "

namespace rbd {
namespace mirror {

int PoolMetaCache::get_local_pool_meta(
    int64_t pool_id,
    LocalPoolMeta* local_pool_meta) const {
  dout(15) << "pool_id=" << pool_id << dendl;

  std::shared_lock locker{m_lock};
  auto it = m_local_pool_metas.find(pool_id);
  if (it == m_local_pool_metas.end()) {
    return -ENOENT;
  }

  *local_pool_meta = it->second;
  return 0;
}

void PoolMetaCache::set_local_pool_meta(
    int64_t pool_id,
    const LocalPoolMeta& local_pool_meta) {
  dout(15) << "pool_id=" << pool_id << ", "
           << "local_pool_meta=" << local_pool_meta << dendl;

  std::unique_lock locker(m_lock);
  m_local_pool_metas[pool_id] = local_pool_meta;
}

void PoolMetaCache::remove_local_pool_meta(int64_t pool_id) {
  dout(15) << "pool_id=" << pool_id << dendl;

  std::unique_lock locker(m_lock);
  m_local_pool_metas.erase(pool_id);
}

int PoolMetaCache::get_remote_pool_meta(
    int64_t pool_id,
    RemotePoolMeta* remote_pool_meta) const {
  dout(15) << "pool_id=" << pool_id << dendl;

  std::shared_lock locker{m_lock};
  auto it = m_remote_pool_metas.find(pool_id);
  if (it == m_remote_pool_metas.end()) {
    return -ENOENT;
  }

  *remote_pool_meta = it->second;
  return 0;
}

void PoolMetaCache::set_remote_pool_meta(
    int64_t pool_id,
    const RemotePoolMeta& remote_pool_meta) {
  dout(15) << "pool_id=" << pool_id << ", "
           << "remote_pool_meta=" << remote_pool_meta << dendl;

  std::unique_lock locker(m_lock);
  m_remote_pool_metas[pool_id] = remote_pool_meta;
}

void PoolMetaCache::remove_remote_pool_meta(int64_t pool_id) {
  dout(15) << "pool_id=" << pool_id << dendl;

  std::unique_lock locker(m_lock);
  m_remote_pool_metas.erase(pool_id);
}

} // namespace mirror
} // namespace rbd