]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/librados_test_stub/TestMemRadosClient.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "test/librados_test_stub/TestMemRadosClient.h"
5 #include "test/librados_test_stub/TestMemCluster.h"
6 #include "test/librados_test_stub/TestMemIoCtxImpl.h"
12 TestMemRadosClient::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
);
19 TestMemRadosClient::~TestMemRadosClient() {
20 m_mem_cluster
->deallocate_client(m_nonce
);
23 TestIoCtxImpl
*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
));
29 void TestMemRadosClient::object_list(int64_t pool_id
,
30 std::list
<librados::TestRadosClient::Object
> *list
) {
33 auto pool
= m_mem_cluster
->get_pool(pool_id
);
34 if (pool
!= nullptr) {
35 std::shared_lock file_locker
{pool
->file_lock
};
36 for (auto &file_pair
: pool
->files
) {
38 obj
.oid
= file_pair
.first
.name
;
44 int TestMemRadosClient::pool_create(const std::string
&pool_name
) {
45 if (is_blocklisted()) {
48 return m_mem_cluster
->pool_create(pool_name
);
51 int TestMemRadosClient::pool_delete(const std::string
&pool_name
) {
52 if (is_blocklisted()) {
55 return m_mem_cluster
->pool_delete(pool_name
);
58 int TestMemRadosClient::pool_get_base_tier(int64_t pool_id
, int64_t* base_tier
) {
64 int TestMemRadosClient::pool_list(std::list
<std::pair
<int64_t, std::string
> >& v
) {
65 return m_mem_cluster
->pool_list(v
);
68 int64_t TestMemRadosClient::pool_lookup(const std::string
&pool_name
) {
69 return m_mem_cluster
->pool_lookup(pool_name
);
72 int TestMemRadosClient::pool_reverse_lookup(int64_t id
, std::string
*name
) {
73 return m_mem_cluster
->pool_reverse_lookup(id
, name
);
76 int TestMemRadosClient::watch_flush() {
77 get_watch_notify()->flush(this);
81 bool TestMemRadosClient::is_blocklisted() const {
82 return m_mem_cluster
->is_blocklisted(m_nonce
);
85 int TestMemRadosClient::blocklist_add(const std::string
& client_address
,
86 uint32_t expire_seconds
) {
87 if (is_blocklisted()) {
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()) {
97 std::stringstream
nonce_ss(client_address
.substr(idx
+ 1));
104 m_mem_cluster
->blocklist(nonce
);
108 void TestMemRadosClient::transaction_start(const std::string
& nspace
,
109 const std::string
&oid
) {
110 m_mem_cluster
->transaction_start({nspace
, oid
});
113 void TestMemRadosClient::transaction_finish(const std::string
& nspace
,
114 const std::string
&oid
) {
115 m_mem_cluster
->transaction_finish({nspace
, oid
});
118 } // namespace librados