]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
testlibrbdpp: use new librbd api
authorJosh Durgin <josh.durgin@dreamhost.com>
Fri, 25 Feb 2011 21:39:35 +0000 (13:39 -0800)
committerJosh Durgin <josh.durgin@dreamhost.com>
Fri, 25 Feb 2011 21:39:35 +0000 (13:39 -0800)
src/Makefile.am
src/testlibrbdpp.cc

index 27906f0cc30d0c9cbcf58d87452fb8ee5d7d3d7f..2081e8c57b18efcfbceaf8413b96ad903da19c6d 100644 (file)
@@ -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
index 0bad9bca1b2f8330e325e36dbae5b32ff644c347..7b52dff1a7cc3c3fdc0f2fb584b655262e5226dc 100644 (file)
@@ -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<librbd::snap_info_t> 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;
 }