]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librados_test_stub/TestMemRadosClient.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / test / librados_test_stub / TestMemRadosClient.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "test/librados_test_stub/TestMemRadosClient.h"
5#include "test/librados_test_stub/TestMemCluster.h"
6#include "test/librados_test_stub/TestMemIoCtxImpl.h"
7#include <errno.h>
8#include <sstream>
9
10namespace librados {
11
12TestMemRadosClient::TestMemRadosClient(CephContext *cct,
13 TestMemCluster *test_mem_cluster)
14 : TestRadosClient(cct, test_mem_cluster->get_watch_notify()),
15 m_mem_cluster(test_mem_cluster) {
16 m_mem_cluster->allocate_client(&m_nonce, &m_global_id);
17}
18
19TestMemRadosClient::~TestMemRadosClient() {
20 m_mem_cluster->deallocate_client(m_nonce);
21}
22
23TestIoCtxImpl *TestMemRadosClient::create_ioctx(int64_t pool_id,
24 const std::string &pool_name) {
25 return new TestMemIoCtxImpl(this, pool_id, pool_name,
26 m_mem_cluster->get_pool(pool_name));
27}
28
29void TestMemRadosClient::object_list(int64_t pool_id,
30 std::list<librados::TestRadosClient::Object> *list) {
31 list->clear();
32
33 auto pool = m_mem_cluster->get_pool(pool_id);
34 if (pool != nullptr) {
9f95a23c 35 std::shared_lock file_locker{pool->file_lock};
7c673cae
FG
36 for (auto &file_pair : pool->files) {
37 Object obj;
11fdf7f2 38 obj.oid = file_pair.first.name;
7c673cae
FG
39 list->push_back(obj);
40 }
41 }
42}
43
44int TestMemRadosClient::pool_create(const std::string &pool_name) {
45 if (is_blacklisted()) {
46 return -EBLACKLISTED;
47 }
48 return m_mem_cluster->pool_create(pool_name);
49}
50
51int TestMemRadosClient::pool_delete(const std::string &pool_name) {
52 if (is_blacklisted()) {
53 return -EBLACKLISTED;
54 }
55 return m_mem_cluster->pool_delete(pool_name);
56}
57
58int TestMemRadosClient::pool_get_base_tier(int64_t pool_id, int64_t* base_tier) {
59 // TODO
60 *base_tier = pool_id;
61 return 0;
62}
63
64int TestMemRadosClient::pool_list(std::list<std::pair<int64_t, std::string> >& v) {
65 return m_mem_cluster->pool_list(v);
66}
67
68int64_t TestMemRadosClient::pool_lookup(const std::string &pool_name) {
69 return m_mem_cluster->pool_lookup(pool_name);
70}
71
72int TestMemRadosClient::pool_reverse_lookup(int64_t id, std::string *name) {
73 return m_mem_cluster->pool_reverse_lookup(id, name);
74}
75
76int TestMemRadosClient::watch_flush() {
77 get_watch_notify()->flush(this);
78 return 0;
79}
80
81bool TestMemRadosClient::is_blacklisted() const {
82 return m_mem_cluster->is_blacklisted(m_nonce);
83}
84
85int TestMemRadosClient::blacklist_add(const std::string& client_address,
86 uint32_t expire_seconds) {
87 if (is_blacklisted()) {
88 return -EBLACKLISTED;
89 }
90
91 // extract the nonce to use as a unique key to the client
92 auto idx = client_address.find("/");
93 if (idx == std::string::npos || idx + 1 >= client_address.size()) {
94 return -EINVAL;
95 }
96
97 std::stringstream nonce_ss(client_address.substr(idx + 1));
98 uint32_t nonce;
99 nonce_ss >> nonce;
100 if (!nonce_ss) {
101 return -EINVAL;
102 }
103
104 m_mem_cluster->blacklist(nonce);
105 return 0;
106}
107
11fdf7f2
TL
108void TestMemRadosClient::transaction_start(const std::string& nspace,
109 const std::string &oid) {
110 m_mem_cluster->transaction_start({nspace, oid});
7c673cae
FG
111}
112
11fdf7f2
TL
113void TestMemRadosClient::transaction_finish(const std::string& nspace,
114 const std::string &oid) {
115 m_mem_cluster->transaction_finish({nspace, oid});
7c673cae
FG
116}
117
118} // namespace librados