#include "objclass/objclass.h"
#include <boost/bind.hpp>
#include <deque>
+#include <list>
#include <vector>
static librados::TestClassHandler *get_class_handler() {
return ret;
}
+extern "C" int rados_nobjects_list_open(rados_ioctx_t io,
+ rados_list_ctx_t *ctx) {
+ librados::TestIoCtxImpl *io_ctx =
+ reinterpret_cast<librados::TestIoCtxImpl*>(io);
+ librados::TestRadosClient *client = io_ctx->get_rados_client();
+
+ std::list<librados::TestRadosClient::Object> *list =
+ new std::list<librados::TestRadosClient::Object>();
+
+ client->object_list(io_ctx->get_id(), list);
+ list->push_front(librados::TestRadosClient::Object());
+ *ctx = reinterpret_cast<rados_list_ctx_t>(list);
+ return 0;
+}
+
+extern "C" int rados_nobjects_list_next(rados_list_ctx_t ctx,
+ const char **entry,
+ const char **key,
+ const char **nspace) {
+ std::list<librados::TestRadosClient::Object> *list =
+ reinterpret_cast<std::list<librados::TestRadosClient::Object> *>(ctx);
+ if (!list->empty()) {
+ list->pop_front();
+ }
+ if (list->empty()) {
+ return -ENOENT;
+ }
+
+ librados::TestRadosClient::Object &obj = list->front();
+ if (entry != NULL) {
+ *entry = obj.oid.c_str();
+ }
+ if (key != NULL) {
+ *key = obj.locator.c_str();
+ }
+ if (nspace != NULL) {
+ *nspace = obj.nspace.c_str();
+ }
+ return 0;
+}
+
+extern "C" void rados_nobjects_list_close(rados_list_ctx_t ctx) {
+ std::list<librados::TestRadosClient::Object> *list =
+ reinterpret_cast<std::list<librados::TestRadosClient::Object> *>(ctx);
+ delete list;
+}
+
extern "C" int rados_pool_create(rados_t cluster, const char *pool_name) {
librados::TestRadosClient *client =
reinterpret_cast<librados::TestRadosClient*>(cluster);
return new TestMemIoCtxImpl(*this, pool_id, pool_name, iter->second);
}
+void TestMemRadosClient::object_list(int64_t pool_id,
+ std::list<librados::TestRadosClient::Object> *list) {
+ list->clear();
+
+ for (Pools::iterator p_it = m_pools.begin(); p_it != m_pools.end(); ++p_it) {
+ Pool *pool = p_it->second;
+ if (pool->pool_id == pool_id) {
+ RWLock::RLocker l(pool->file_lock);
+ for (Files::iterator it = pool->files.begin();
+ it != pool->files.end(); ++it) {
+ Object obj;
+ obj.oid = it->first;
+ list->push_back(obj);
+ }
+ break;
+ }
+ }
+}
+
int TestMemRadosClient::pool_create(const std::string &pool_name) {
if (m_pools.find(pool_name) != m_pools.end()) {
return -EEXIST;
virtual TestIoCtxImpl *create_ioctx(int64_t pool_id,
const std::string &pool_name);
+ virtual void object_list(int64_t pool_id,
+ std::list<librados::TestRadosClient::Object> *list);
+
virtual int pool_create(const std::string &pool_name);
virtual int pool_delete(const std::string &pool_name);
virtual int pool_get_base_tier(int64_t pool_id, int64_t* base_tier);
#include "test/librados_test_stub/TestWatchNotify.h"
#include <boost/function.hpp>
#include <boost/functional/hash.hpp>
+#include <list>
#include <map>
#include <string>
#include <vector>
typedef boost::function<int()> AioFunction;
+ struct Object {
+ std::string oid;
+ std::string locator;
+ std::string nspace;
+ };
+
TestRadosClient(CephContext *cct);
void get();
const bufferlist &inbl,
bufferlist *outbl, std::string *outs);
+ virtual void object_list(int64_t pool_id,
+ std::list<librados::TestRadosClient::Object> *list) = 0;
+
virtual int pool_create(const std::string &pool_name) = 0;
virtual int pool_delete(const std::string &pool_name) = 0;
virtual int pool_get_base_tier(int64_t pool_id, int64_t* base_tier) = 0;
// find out what objects the parent image has generated
ASSERT_EQ(0, rbd_stat(parent, &p_info, sizeof(p_info)));
- ASSERT_EQ(0, rados_objects_list_open(ioctx, &list_ctx));
- while (rados_objects_list_next(list_ctx, &entry, NULL) != -ENOENT) {
+ ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx));
+ while (rados_nobjects_list_next(list_ctx, &entry, NULL, NULL) != -ENOENT) {
if (strstr(entry, p_info.block_name_prefix)) {
const char *block_name_suffix = entry + strlen(p_info.block_name_prefix) + 1;
obj_checker.insert(block_name_suffix);
}
}
- rados_objects_list_close(list_ctx);
+ rados_nobjects_list_close(list_ctx);
ASSERT_EQ(obj_checker.size(), write_tracker.size());
// create a snapshot, reopen as the parent we're interested in and protect it
printf("check whether child image has the same set of objects as parent\n");
ASSERT_EQ(0, rbd_open(ioctx, "child", &child, NULL));
ASSERT_EQ(0, rbd_stat(child, &c_info, sizeof(c_info)));
- ASSERT_EQ(0, rados_objects_list_open(ioctx, &list_ctx));
- while (rados_objects_list_next(list_ctx, &entry, NULL) != -ENOENT) {
+ ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx));
+ while (rados_nobjects_list_next(list_ctx, &entry, NULL, NULL) != -ENOENT) {
if (strstr(entry, c_info.block_name_prefix)) {
const char *block_name_suffix = entry + strlen(c_info.block_name_prefix) + 1;
set<string>::iterator it = obj_checker.find(block_name_suffix);
obj_checker.erase(it);
}
}
- rados_objects_list_close(list_ctx);
+ rados_nobjects_list_close(list_ctx);
ASSERT_TRUE(obj_checker.empty());
ASSERT_EQ(0, rbd_close(child));