]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: adjust C++ aio completion creation api
authorSage Weil <sage@newdream.net>
Wed, 21 Apr 2010 21:23:52 +0000 (14:23 -0700)
committerSage Weil <sage@newdream.net>
Wed, 21 Apr 2010 21:24:26 +0000 (14:24 -0700)
src/include/librados.hpp
src/librados.cc
src/osdc/rados_bencher.h

index d2d5e3caca21e162d791b83677f0f8e5d3b3a9a8..91eb1028adae67d191f735206a7cba4b40664a29 100644 (file)
@@ -111,7 +111,8 @@ public:
               AioCompletion *c);
   int aio_write(pool_t pool, const std::string& oid, off_t off, const bufferlist& bl, size_t len,
                AioCompletion *c);
-  int create_completion(callback_t cb, void *cba, AioCompletion **pc);
+  AioCompletion *aio_create_completion();
+  AioCompletion *aio_create_completion(callback_t cb, void *cba);
 };
 
 }
index 9c8bca75ac737dbe1b7623b6bc62f23be39e4b2a..b544eef3dff6cecb457cbc9477d5c11de9e867df 100644 (file)
@@ -289,12 +289,13 @@ public:
   int aio_write(PoolCtx& pool, object_t oid, off_t off, const bufferlist& bl, size_t len,
                AioCompletion *c);
 
-  int create_completion(rados_callback_t cb, void *cba, AioCompletion **pc) {
-    *pc = new AioCompletion;
-    if (!pc)
-      return -ENOMEM;
-    (*pc)->set_callback(cb, cba);
-    return 0;
+  AioCompletion *aio_create_completion() {
+    return new AioCompletion;
+  }
+  AioCompletion *aio_create_completion(rados_callback_t cb, void *cba) {
+    AioCompletion *c = new AioCompletion;
+    c->set_callback(cb, cba);
+    return c;
   }
 };
 
@@ -1394,18 +1395,16 @@ int Rados::aio_write(rados_pool_t pool, const string& oid, off_t off, const buff
   return r;
 }
 
-int Rados::create_completion(callback_t cb, void *cba, AioCompletion **pc)
+Rados::AioCompletion *Rados::aio_create_completion()
 {
-  RadosClient::AioCompletion *c;
-  int r = ((RadosClient *)client)->create_completion(cb, cba, &c);
-  if (r < 0)
-    return r;
-
-  *pc = new AioCompletion(c);
-  if (!pc)
-    return -ENOMEM;
+  RadosClient::AioCompletion *c = ((RadosClient *)client)->aio_create_completion();
+  return new AioCompletion(c);
+}
 
-  return 0;
+Rados::AioCompletion *Rados::aio_create_completion(callback_t cb, void *cba)
+{
+  RadosClient::AioCompletion *c = ((RadosClient *)client)->aio_create_completion(cb, cba);
+  return new AioCompletion(c);
 }
 
 int Rados::AioCompletion::set_callback(rados_callback_t cb, void *cba)
@@ -1741,7 +1740,8 @@ extern "C" int rados_list_objects_next(rados_list_ctx_t listctx, const char **en
 
 extern "C" int rados_aio_create_completion(rados_callback_t cb, void *cba, rados_completion_t *pc)
 {
-  return radosp->create_completion(cb, cba, (RadosClient::AioCompletion **)pc);
+  *pc = radosp->aio_create_completion(cb, cba);
+  return 0;
 }
 
 extern "C" int rados_aio_wait_for_complete(rados_completion_t c)
index f855b9d9076f330f67846b23e22a0201a8a68594..49ca902e7b31980409c371c5654c402fbb3523c2 100644 (file)
@@ -145,6 +145,7 @@ int write_bench(Rados& rados, rados_pool_t pool,
   dataLock.Unlock();
   for (int i = 0; i<concurrentios; ++i) {
     start_times[i] = g_clock.now();
+    completions[i] = rados.aio_create_completion();
     r = rados.aio_write(pool, name[i], 0, *contents[i], data->object_size, completions[i]);
     if (r < 0) { //naughty, doesn't clean up heap
        dataLock.Unlock();
@@ -191,11 +192,13 @@ int write_bench(Rados& rados, rados_pool_t pool,
     --data->in_flight;
     dataLock.Unlock();
     completions[slot]->release();
+    completions[slot] = 0;
     timePassed = g_clock.now() - data->start_time;
     
     //write new stuff to rados, then delete old stuff
     //and save locations of new stuff for later deletion
     start_times[slot] = g_clock.now();
+    completions[slot] = rados.aio_create_completion();
     r = rados.aio_write(pool, newName, 0, *newContents, data->object_size, completions[slot]);
     if (r < 0) //naughty; doesn't clean up heap space.
       return r;
@@ -226,7 +229,8 @@ int write_bench(Rados& rados, rados_pool_t pool,
     data->avg_latency = total_latency / data->finished;
     --data->in_flight;
     dataLock.Unlock();
-    completions[slot]-> release();
+    completions[slot]->release();
+    completions[slot] = 0;
     delete[] name[slot];
     delete contents[slot];
   }
@@ -305,6 +309,7 @@ int seq_read_bench(Rados& rados, rados_pool_t pool, int seconds_to_run,
   //start initial reads
   for (int i = 0; i < concurrentios; ++i) {
     start_times[i] = g_clock.now();
+    completions[i] = rados.aio_create_completion();
     r = rados.aio_read(pool, name[i], 0, contents[i], data->object_size, completions[i]);
     if (r < 0) { //naughty, doesn't clean up heap -- oh, or handle the print thread!
       cerr << "r = " << r << std::endl;
@@ -347,11 +352,13 @@ int seq_read_bench(Rados& rados, rados_pool_t pool, int seconds_to_run,
     --data->in_flight;
     dataLock.Unlock();
     completions[slot]->release();
+    completions[slot] = 0;
     cur_contents = contents[slot];
 
     //start new read and check data if requested
     start_times[slot] = g_clock.now();
     contents[slot] = new bufferlist();
+    completions[slot] = rados.aio_create_completion();
     r = rados.aio_read(pool, newName, 0, contents[slot], data->object_size, completions[slot]);
     if (r < 0)
       return r;
@@ -390,6 +397,7 @@ int seq_read_bench(Rados& rados, rados_pool_t pool, int seconds_to_run,
     data->avg_latency = total_latency / data->finished;
     --data->in_flight;
     completions[slot]-> release();
+    completions[slot] = 0;
     snprintf(data->object_contents, data->object_size, "I'm the %dth object!", data->finished-1);
     dataLock.Unlock();
     if (memcmp(data->object_contents, contents[slot]->c_str(), data->object_size) != 0) {