From: Jason Dillaman Date: Tue, 20 Jan 2015 17:12:43 +0000 (-0500) Subject: test: add rados_nobjects_list_xyz functions to librados test stub X-Git-Tag: v0.93~197^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e9170335a2176dd00e73c004b3a89b9eabd0ba7f;p=ceph.git test: add rados_nobjects_list_xyz functions to librados test stub The new RBD copy-on-read unit test case uses these RADOS functions to verify that the CoR operation was successful. This implements these functions in the librados_test_stub library. Signed-off-by: Jason Dillaman --- diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 0fb46da67289..57f1a62d0095 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -15,6 +15,7 @@ #include "objclass/objclass.h" #include #include +#include #include static librados::TestClassHandler *get_class_handler() { @@ -207,6 +208,53 @@ extern "C" int rados_mon_command(rados_t cluster, const char **cmd, return ret; } +extern "C" int rados_nobjects_list_open(rados_ioctx_t io, + rados_list_ctx_t *ctx) { + librados::TestIoCtxImpl *io_ctx = + reinterpret_cast(io); + librados::TestRadosClient *client = io_ctx->get_rados_client(); + + std::list *list = + new std::list(); + + client->object_list(io_ctx->get_id(), list); + list->push_front(librados::TestRadosClient::Object()); + *ctx = reinterpret_cast(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 *list = + reinterpret_cast *>(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 *list = + reinterpret_cast *>(ctx); + delete list; +} + extern "C" int rados_pool_create(rados_t cluster, const char *pool_name) { librados::TestRadosClient *client = reinterpret_cast(cluster); diff --git a/src/test/librados_test_stub/TestMemRadosClient.cc b/src/test/librados_test_stub/TestMemRadosClient.cc index bb6034f2a02a..a225702adabc 100644 --- a/src/test/librados_test_stub/TestMemRadosClient.cc +++ b/src/test/librados_test_stub/TestMemRadosClient.cc @@ -44,6 +44,25 @@ TestIoCtxImpl *TestMemRadosClient::create_ioctx(int64_t pool_id, return new TestMemIoCtxImpl(*this, pool_id, pool_name, iter->second); } +void TestMemRadosClient::object_list(int64_t pool_id, + std::list *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; diff --git a/src/test/librados_test_stub/TestMemRadosClient.h b/src/test/librados_test_stub/TestMemRadosClient.h index 418415d4a5eb..5031d8c4ce87 100644 --- a/src/test/librados_test_stub/TestMemRadosClient.h +++ b/src/test/librados_test_stub/TestMemRadosClient.h @@ -68,6 +68,9 @@ public: virtual TestIoCtxImpl *create_ioctx(int64_t pool_id, const std::string &pool_name); + virtual void object_list(int64_t pool_id, + std::list *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); diff --git a/src/test/librados_test_stub/TestRadosClient.h b/src/test/librados_test_stub/TestRadosClient.h index 8174d656872a..bfccad6d9981 100644 --- a/src/test/librados_test_stub/TestRadosClient.h +++ b/src/test/librados_test_stub/TestRadosClient.h @@ -11,6 +11,7 @@ #include "test/librados_test_stub/TestWatchNotify.h" #include #include +#include #include #include #include @@ -26,6 +27,12 @@ public: typedef boost::function AioFunction; + struct Object { + std::string oid; + std::string locator; + std::string nspace; + }; + TestRadosClient(CephContext *cct); void get(); @@ -46,6 +53,9 @@ public: const bufferlist &inbl, bufferlist *outbl, std::string *outs); + virtual void object_list(int64_t pool_id, + std::list *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; diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 4723fe102757..5fbbbd673836 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -1464,14 +1464,14 @@ TEST_F(TestLibRBD, TestCoR) // 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 @@ -1514,8 +1514,8 @@ TEST_F(TestLibRBD, TestCoR) 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::iterator it = obj_checker.find(block_name_suffix); @@ -1523,7 +1523,7 @@ TEST_F(TestLibRBD, TestCoR) 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));