X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftest%2Flibrados_test_stub%2FTestMemRadosClient.cc;fp=src%2Fceph%2Fsrc%2Ftest%2Flibrados_test_stub%2FTestMemRadosClient.cc;h=1962cc3b36290ac2a542f854540eef19d9a5c8ad;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/test/librados_test_stub/TestMemRadosClient.cc b/src/ceph/src/test/librados_test_stub/TestMemRadosClient.cc new file mode 100644 index 0000000..1962cc3 --- /dev/null +++ b/src/ceph/src/test/librados_test_stub/TestMemRadosClient.cc @@ -0,0 +1,116 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "test/librados_test_stub/TestMemRadosClient.h" +#include "test/librados_test_stub/TestMemCluster.h" +#include "test/librados_test_stub/TestMemIoCtxImpl.h" +#include +#include + +namespace librados { + +TestMemRadosClient::TestMemRadosClient(CephContext *cct, + TestMemCluster *test_mem_cluster) + : TestRadosClient(cct, test_mem_cluster->get_watch_notify()), + m_mem_cluster(test_mem_cluster) { + m_mem_cluster->allocate_client(&m_nonce, &m_global_id); +} + +TestMemRadosClient::~TestMemRadosClient() { + m_mem_cluster->deallocate_client(m_nonce); +} + +TestIoCtxImpl *TestMemRadosClient::create_ioctx(int64_t pool_id, + const std::string &pool_name) { + return new TestMemIoCtxImpl(this, pool_id, pool_name, + m_mem_cluster->get_pool(pool_name)); +} + +void TestMemRadosClient::object_list(int64_t pool_id, + std::list *list) { + list->clear(); + + auto pool = m_mem_cluster->get_pool(pool_id); + if (pool != nullptr) { + RWLock::RLocker file_locker(pool->file_lock); + for (auto &file_pair : pool->files) { + Object obj; + obj.oid = file_pair.first; + list->push_back(obj); + } + } +} + +int TestMemRadosClient::pool_create(const std::string &pool_name) { + if (is_blacklisted()) { + return -EBLACKLISTED; + } + return m_mem_cluster->pool_create(pool_name); +} + +int TestMemRadosClient::pool_delete(const std::string &pool_name) { + if (is_blacklisted()) { + return -EBLACKLISTED; + } + return m_mem_cluster->pool_delete(pool_name); +} + +int TestMemRadosClient::pool_get_base_tier(int64_t pool_id, int64_t* base_tier) { + // TODO + *base_tier = pool_id; + return 0; +} + +int TestMemRadosClient::pool_list(std::list >& v) { + return m_mem_cluster->pool_list(v); +} + +int64_t TestMemRadosClient::pool_lookup(const std::string &pool_name) { + return m_mem_cluster->pool_lookup(pool_name); +} + +int TestMemRadosClient::pool_reverse_lookup(int64_t id, std::string *name) { + return m_mem_cluster->pool_reverse_lookup(id, name); +} + +int TestMemRadosClient::watch_flush() { + get_watch_notify()->flush(this); + return 0; +} + +bool TestMemRadosClient::is_blacklisted() const { + return m_mem_cluster->is_blacklisted(m_nonce); +} + +int TestMemRadosClient::blacklist_add(const std::string& client_address, + uint32_t expire_seconds) { + if (is_blacklisted()) { + return -EBLACKLISTED; + } + + // extract the nonce to use as a unique key to the client + auto idx = client_address.find("/"); + if (idx == std::string::npos || idx + 1 >= client_address.size()) { + return -EINVAL; + } + + std::stringstream nonce_ss(client_address.substr(idx + 1)); + uint32_t nonce; + nonce_ss >> nonce; + if (!nonce_ss) { + return -EINVAL; + } + + m_mem_cluster->blacklist(nonce); + return 0; +} + +void TestMemRadosClient::transaction_start(const std::string &oid) { + m_mem_cluster->transaction_start(oid); +} + +void TestMemRadosClient::transaction_finish(const std::string &oid) { + m_mem_cluster->transaction_finish(oid); +} + +} // namespace librados