From 9758af7d28b6de20214c22b9efad419963f6d4de Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 25 Feb 2011 13:39:35 -0800 Subject: [PATCH] testlibrbdpp: use new librbd api --- src/Makefile.am | 6 ++-- src/testlibrbdpp.cc | 68 +++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 27906f0cc30d0..2081e8c57b18e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -265,9 +265,9 @@ bin_PROGRAMS += rbd if WITH_DEBUG testlibrbd_SOURCES = testlibrbd.c testlibrbd_LDADD = librbd.la librados.la libcrush.la -lpthread -lm $(CRYPTOPP_LIBS) -#testlibrbdpp_SOURCES = testlibrbdpp.cc -#testlibrbdpp_LDADD = librbd.la librados.la libcrush.la -lpthread -lm $(CRYPTOPP_LIBS) -bin_PROGRAMS += testlibrbd +testlibrbdpp_SOURCES = testlibrbdpp.cc +testlibrbdpp_LDADD = librbd.la librados.la libcrush.la -lpthread -lm $(CRYPTOPP_LIBS) +bin_PROGRAMS += testlibrbd testlibrbdpp endif if WITH_RADOSGW diff --git a/src/testlibrbdpp.cc b/src/testlibrbdpp.cc index 0bad9bca1b2f8..7b52dff1a7cc3 100644 --- a/src/testlibrbdpp.cc +++ b/src/testlibrbdpp.cc @@ -40,22 +40,22 @@ librbd::RBD *rbd; void test_create_and_stat(librados::pool_t pool, const char *name, size_t size) { librbd::image_info_t info; - librbd::image_t image; + librbd::Image *image; int order = 0; assert(rbd->create(pool, name, size, &order) == 0); - assert(rbd->open(pool, name, &image, NULL) == 0); - assert(rbd->stat(image, info, sizeof(info)) == 0); + assert(rbd->open(pool, image, name, NULL) == 0); + assert(image->stat(info, sizeof(info)) == 0); cout << "image has size " << info.size << " and order " << info.order << endl; assert(info.size == size); assert(info.order == order); - assert(rbd->close(image) == 0); + delete image; } -void test_resize_and_stat(librbd::image_t image, size_t size) +void test_resize_and_stat(librbd::Image *image, size_t size) { librbd::image_info_t info; - assert(rbd->resize(image, size) == 0); - assert(rbd->stat(image, info, sizeof(info)) == 0); + assert(image->resize(size) == 0); + assert(image->stat(info, sizeof(info)) == 0); cout << "image has size " << info.size << " and order " << info.order << endl; assert(info.size == size); } @@ -95,19 +95,19 @@ void test_delete(librados::pool_t pool, const char *name) assert(rbd->remove(pool, name) == 0); } -void test_create_snap(librbd::image_t image, const char *name) +void test_create_snap(librbd::Image *image, const char *name) { - assert(rbd->snap_create(image, name) == 0); + assert(image->snap_create(name) == 0); } -void test_ls_snaps(librbd::image_t image, size_t num_expected, ...) +void test_ls_snaps(librbd::Image *image, size_t num_expected, ...) { int r; size_t i, j, expected_size; char *expected; va_list ap; vector snaps; - r = rbd->snap_list(image, snaps); + r = image->snap_list(snaps); assert(r >= 0); cout << "num snaps is: " << snaps.size() << endl << "expected: " << num_expected << endl; @@ -141,9 +141,9 @@ void test_ls_snaps(librbd::image_t image, size_t num_expected, ...) } } -void test_delete_snap(librbd::image_t image, const char *name) +void test_delete_snap(librbd::Image *image, const char *name) { - assert(rbd->snap_remove(image, name) == 0); + assert(image->snap_remove(name) == 0); } void simple_write_cb(librbd::completion_t cb, void *arg) @@ -156,39 +156,40 @@ void simple_read_cb(librbd::completion_t cb, void *arg) cout << "read completion cb called!" << endl; } -void aio_write_test_data(librbd::image_t image, const char *test_data, off_t off) +void aio_write_test_data(librbd::Image *image, const char *test_data, off_t off) { ceph::bufferlist bl; bl.append(test_data, strlen(test_data)); - librbd::RBD::AioCompletion *comp = rbd->aio_create_completion(NULL, (librbd::callback_t) simple_write_cb); + librbd::RBD::AioCompletion *comp = new librbd::RBD::AioCompletion(NULL, (librbd::callback_t) simple_write_cb); printf("created completion\n"); - rbd->aio_write(image, off, strlen(test_data), bl, comp); + image->aio_write(off, strlen(test_data), bl, comp); printf("started write\n"); comp->wait_for_complete(); int r = comp->get_return_value(); printf("return value is: %d\n", r); assert(r == 0); printf("finished write\n"); + comp->release(); delete comp; } -void write_test_data(librbd::image_t image, const char *test_data, off_t off) +void write_test_data(librbd::Image *image, const char *test_data, off_t off) { size_t written; size_t len = strlen(test_data); ceph::bufferlist bl; bl.append(test_data, len); - written = rbd->write(image, off, len, bl); + written = image->write(off, len, bl); assert(written >= 0); printf("wrote: %u\n", (unsigned int) written); } -void aio_read_test_data(librbd::image_t image, const char *expected, off_t off) +void aio_read_test_data(librbd::Image *image, const char *expected, off_t off) { - librbd::RBD::AioCompletion *comp = rbd->aio_create_completion(NULL, (librbd::callback_t) simple_read_cb); + librbd::RBD::AioCompletion *comp = new librbd::RBD::AioCompletion(NULL, (librbd::callback_t) simple_read_cb); ceph::bufferlist bl; printf("created completion\n"); - rbd->aio_read(image, off, strlen(expected), bl, comp); + image->aio_read(off, strlen(expected), bl, comp); printf("started read\n"); comp->wait_for_complete(); int r = comp->get_return_value(); @@ -196,23 +197,24 @@ void aio_read_test_data(librbd::image_t image, const char *expected, off_t off) assert(r == TEST_IO_SIZE - 1); assert(strncmp(expected, bl.c_str(), TEST_IO_SIZE - 1) == 0); printf("finished read\n"); + comp->release(); delete comp; } -void read_test_data(librbd::image_t image, const char *expected, off_t off) +void read_test_data(librbd::Image *image, const char *expected, off_t off) { size_t read, total_read = 0; size_t expected_len = strlen(expected); size_t len = expected_len; ceph::bufferlist bl; - read = rbd->read(image, off + total_read, len, bl); + read = image->read(off + total_read, len, bl); assert(read >= 0); printf("read: %u\n", (unsigned int) read); printf("read: %s\nexpected: %s\n", bl.c_str(), expected); assert(strncmp(bl.c_str(), expected, expected_len) == 0); } -void test_io(librados::pool_t pool, librbd::image_t image) +void test_io(librados::pool_t pool, librbd::Image *image) { char test_data[TEST_IO_SIZE]; int i; @@ -226,13 +228,13 @@ void test_io(librados::pool_t pool, librbd::image_t image) for (i = 0; i < 5; ++i) write_test_data(image, test_data, strlen(test_data) * i); - for (i = 0; i < 5; ++i) + for (i = 5; i < 10; ++i) aio_write_test_data(image, test_data, strlen(test_data) * i); for (i = 0; i < 5; ++i) read_test_data(image, test_data, strlen(test_data) * i); - for (i = 0; i < 5; ++i) + for (i = 5; i < 10; ++i) aio_read_test_data(image, test_data, strlen(test_data) * i); } @@ -241,13 +243,13 @@ int main(int argc, const char **argv) { librados::Rados rados; librados::pool_t pool; - librbd::image_t image; + librbd::Image *image; rbd = new librbd::RBD(); - assert(rados.init() == 0); - assert(rados.pool_open(TEST_POOL, &pool) == 0); + assert(rados.initialize(0, NULL) == 0); + assert(rados.open_pool(TEST_POOL, &pool) == 0); test_ls(pool, 0); test_create_and_stat(pool, TEST_IMAGE, MB_BYTES(1)); - assert(rbd->open(pool, TEST_IMAGE, &image, NULL) == 0); + assert(rbd->open(pool, image, TEST_IMAGE, NULL) == 0); test_ls(pool, 1, TEST_IMAGE); test_ls_snaps(image, 0); test_create_snap(image, TEST_SNAP); @@ -260,7 +262,7 @@ int main(int argc, const char **argv) test_ls_snaps(image, 1, TEST_SNAP "1", MB_BYTES(2)); test_delete_snap(image, TEST_SNAP "1"); test_ls_snaps(image, 0); - assert(rbd->close(image) == 0); + delete image; test_create_and_stat(pool, TEST_IMAGE "1", MB_BYTES(2)); test_ls(pool, 2, TEST_IMAGE, TEST_IMAGE "1"); test_delete(pool, TEST_IMAGE); @@ -268,7 +270,7 @@ int main(int argc, const char **argv) test_delete(pool, TEST_IMAGE "1"); test_ls(pool, 0); delete rbd; - rados.pool_close(pool); - rados.release(); + rados.close_pool(pool); + rados.shutdown(); return 0; } -- 2.39.5