]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: move c++ api into librados.hpp; more type cleanup
authorSage Weil <sage@newdream.net>
Thu, 8 Apr 2010 22:22:50 +0000 (15:22 -0700)
committerSage Weil <sage@newdream.net>
Thu, 8 Apr 2010 22:22:50 +0000 (15:22 -0700)
14 files changed:
src/Makefile.am
src/include/buffer.h
src/include/librados.h
src/include/librados.hpp [new file with mode: 0644]
src/librados.cc
src/messages/MGetPoolStats.h
src/mon/PGMonitor.cc
src/osdc/Objecter.cc
src/osdc/Objecter.h
src/rados.cc
src/radosacl.cc
src/rbdtool.cc
src/rgw/rgw_rados.cc
src/testradospp.cc

index 8c014615395ea343fec34e10f108b86e3da7055a..eaa9dbb83d56e2bf368e19eefd0e986eaf131259 100644 (file)
@@ -518,6 +518,7 @@ noinst_HEADERS = \
         include/interval_set.h\
         include/inttypes.h\
        include/librados.h\
+       include/librados.hpp\
         include/lru.h\
        include/msgr.h\
         include/nstring.h\
index 0f9f057e67e5ff55b361fe1f6dbd9b2517800d8b..5aeb0a44c327f61474b12259d1bfbd073dbaafaf 100644 (file)
@@ -15,6 +15,8 @@
 #ifndef __BUFFER_H
 #define __BUFFER_H
 
+#include <linux/types.h>
+
 #ifndef _XOPEN_SOURCE
 # define _XOPEN_SOURCE 600
 #endif
@@ -67,10 +69,10 @@ using std::string;
 #ifdef BUFFER_DEBUG
 #include "Spinlock.h"
 extern Spinlock buffer_lock;
-# define bdout { buffer_lock.lock(); cout
+# define bdout { buffer_lock.lock(); std::cout
 # define bendl std::endl; buffer_lock.unlock(); }
 #else
-# define bdout if (0) { cout
+# define bdout if (0) { std::cout
 # define bendl std::endl; }
 #endif
 
@@ -1206,7 +1208,7 @@ inline std::ostream& operator<<(std::ostream& out, const buffer::list& bl) {
   return out;
 }
 
-inline ostream& operator<<(ostream& out, buffer::error& e)
+inline std::ostream& operator<<(std::ostream& out, buffer::error& e)
 {
   return out << e.what();
 }
index cd8086bd19e91685fa71c9b9fd925ff88972df3a..18e4c7c691d172220c21a22cc1c5b73cef2edcf4 100644 (file)
@@ -85,83 +85,6 @@ int rados_aio_read(rados_pool_t pool, const char *oid, off_t off, char *buf, siz
 
 #ifdef __cplusplus
 }
-
-#include <stdbool.h>
-
-class RadosClient;
-
-class Rados
-{
-  RadosClient *client;
-public:
-  Rados();
-  ~Rados();
-  int initialize(int argc, const char *argv[]);
-  void shutdown();
-
-  int open_pool(const char *name, rados_pool_t *pool);
-  int close_pool(rados_pool_t pool);
-
-  void set_snap(rados_pool_t pool, __u64 seq);
-
-  int create(rados_pool_t pool, const std::string& oid, bool exclusive);
-
-  int write(rados_pool_t pool, const std::string& oid, off_t off, bufferlist& bl, size_t len);
-  int write_full(rados_pool_t pool, const std::string& oid, bufferlist& bl);
-  int read(rados_pool_t pool, const std::string& oid, off_t off, bufferlist& bl, size_t len);
-  int remove(rados_pool_t pool, const std::string& oid);
-
-  int getxattr(rados_pool_t pool, const std::string& oid, const char *name, bufferlist& bl);
-  int setxattr(rados_pool_t pool, const std::string& oid, const char *name, bufferlist& bl);
-  int getxattrs(rados_pool_t pool, const std::string& oid, map<std::string, bufferlist>& attrset);
-  int stat(rados_pool_t pool, const std::string& oid, __u64 *psize, time_t *pmtime);
-
-  int tmap_update(rados_pool_t pool, const std::string& oid, bufferlist& cmdbl);
-  
-  int exec(rados_pool_t pool, const std::string& oid, const char *cls, const char *method,
-          bufferlist& inbl, bufferlist& outbl);
-
-  struct ListCtx {
-    void *ctx;
-    ListCtx() : ctx(NULL) {}
-  };
-
-  int list(rados_pool_t pool, int max, std::list<std::string>& entries, Rados::ListCtx& ctx);
-  int list_pools(std::vector<std::string>& v);
-  int get_pool_stats(std::vector<std::string>& v,
-                    std::map<std::string,rados_pool_stat_t>& stats);
-  int get_fs_stats(rados_statfs_t& result);
-
-  int create_pool(const char *name, __u64 auid=0);
-  int delete_pool(const rados_pool_t& pool);
-  int change_pool_auid(const rados_pool_t& pool, __u64 auid);
-
-  int snap_create(const rados_pool_t pool, const char *snapname);
-  int snap_remove(const rados_pool_t pool, const char *snapname);
-  int snap_list(rados_pool_t pool, vector<rados_snap_t> *snaps);
-  int snap_get_name(rados_pool_t pool, rados_snap_t snap, std::string *name);
-  int snap_get_stamp(rados_pool_t pool, rados_snap_t snap, time_t *t);
-  int snap_lookup(rados_pool_t, const char *snapname, rados_snap_t *snapid);
-
-  // -- aio --
-  struct AioCompletion {
-    void *pc;
-    AioCompletion(void *_pc) : pc(_pc) {}
-    int set_callback(rados_callback_t cb, void *cba);
-    int wait_for_complete();
-    int wait_for_safe();
-    bool is_complete();
-    bool is_safe();
-    int get_return_value();
-    void release();
-  };
-
-  int aio_read(rados_pool_t pool, const std::string& oid, off_t off, bufferlist *pbl, size_t len,
-              AioCompletion **pc);
-  int aio_write(rados_pool_t pool, const std::string& oid, off_t off, const bufferlist& bl, size_t len,
-               AioCompletion **pc);
-
-};
 #endif
 
 #endif
diff --git a/src/include/librados.hpp b/src/include/librados.hpp
new file mode 100644 (file)
index 0000000..9e60195
--- /dev/null
@@ -0,0 +1,117 @@
+#ifndef __LIBRADOS_HPP
+#define __LIBRADOS_HPP
+
+#include <stdbool.h>
+#include <linux/types.h>
+#include <string>
+#include <list>
+#include <map>
+#include <vector>
+#include "buffer.h"
+
+namespace librados {
+
+  using ceph::bufferlist;
+
+  typedef void *list_ctx_t;
+  typedef void *pool_t;
+  typedef __u64 snap_t;
+  typedef __u64 auid_t;
+
+  struct statfs_t {
+    __u64 kb, kb_used, kb_avail;
+    __u64 num_objects;
+  };
+
+  struct pool_stat_t {
+    __u64 num_bytes;    // in bytes
+    __u64 num_kb;       // in KB
+    __u64 num_objects;
+    __u64 num_object_clones;
+    __u64 num_object_copies;  // num_objects * num_replicas
+    __u64 num_objects_missing_on_primary;
+    __u64 num_objects_degraded;
+    __u64 num_rd, num_rd_kb, num_wr, num_wr_kb;
+  };
+
+  typedef void *completion_t;
+  typedef void (*callback_t)(completion_t cb, void *arg);
+
+
+class Rados
+{
+  void *client;
+public:
+  Rados();
+  ~Rados();
+  int initialize(int argc, const char *argv[]);
+  void shutdown();
+
+  int open_pool(const char *name, pool_t *pool);
+  int close_pool(pool_t pool);
+
+  void set_snap(pool_t pool, snap_t seq);
+
+  int create(pool_t pool, const std::string& oid, bool exclusive);
+
+  int write(pool_t pool, const std::string& oid, off_t off, bufferlist& bl, size_t len);
+  int write_full(pool_t pool, const std::string& oid, bufferlist& bl);
+  int read(pool_t pool, const std::string& oid, off_t off, bufferlist& bl, size_t len);
+  int remove(pool_t pool, const std::string& oid);
+
+  int getxattr(pool_t pool, const std::string& oid, const char *name, bufferlist& bl);
+  int setxattr(pool_t pool, const std::string& oid, const char *name, bufferlist& bl);
+  int getxattrs(pool_t pool, const std::string& oid, std::map<std::string, bufferlist>& attrset);
+  int stat(pool_t pool, const std::string& oid, __u64 *psize, time_t *pmtime);
+
+  int tmap_update(pool_t pool, const std::string& oid, bufferlist& cmdbl);
+  
+  int exec(pool_t pool, const std::string& oid, const char *cls, const char *method,
+          bufferlist& inbl, bufferlist& outbl);
+
+  struct ListCtx {
+    void *ctx;
+    ListCtx() : ctx(NULL) {}
+  };
+
+  int list(pool_t pool, int max, std::list<std::string>& entries, Rados::ListCtx& ctx);
+  int list_pools(std::list<std::string>& v);
+  int get_pool_stats(std::list<std::string>& v,
+                    std::map<std::string,pool_stat_t>& stats);
+  int get_fs_stats(statfs_t& result);
+
+  int create_pool(const char *name, __u64 auid=0);
+  int delete_pool(const pool_t& pool);
+  int change_pool_auid(const pool_t& pool, __u64 auid);
+
+  int snap_create(const pool_t pool, const char *snapname);
+  int snap_remove(const pool_t pool, const char *snapname);
+  int snap_list(pool_t pool, std::vector<snap_t> *snaps);
+  int snap_get_name(pool_t pool, snap_t snap, std::string *name);
+  int snap_get_stamp(pool_t pool, snap_t snap, time_t *t);
+  int snap_lookup(pool_t, const char *snapname, snap_t *snapid);
+
+  // -- aio --
+  struct AioCompletion {
+    void *pc;
+    AioCompletion(void *_pc) : pc(_pc) {}
+    int set_callback(callback_t cb, void *cba);
+    int wait_for_complete();
+    int wait_for_safe();
+    bool is_complete();
+    bool is_safe();
+    int get_return_value();
+    void release();
+  };
+
+  int aio_read(pool_t pool, const std::string& oid, off_t off, bufferlist *pbl, size_t len,
+              AioCompletion **pc);
+  int aio_write(pool_t pool, const std::string& oid, off_t off, const bufferlist& bl, size_t len,
+               AioCompletion **pc);
+
+};
+
+}
+
+#endif
+
index 44c217d9b363699fe3262bbb3db381ee3f646e37..f746dc83deac313b87bb8913260c9993f6096b0e 100644 (file)
@@ -38,6 +38,7 @@ using namespace std;
 #include "osdc/Objecter.h"
 
 #include "include/librados.h"
+#include "include/librados.hpp"
 
 #define RADOS_LIST_MAX_ENTRIES 1024
 #define DOUT_SUBSYS rados
@@ -104,10 +105,10 @@ public:
   }
 
   // snaps
-  int snap_list(PoolCtx *pool, vector<rados_snap_t> *snaps);
-  int snap_lookup(PoolCtx *pool, const char *name, rados_snap_t *snapid);
-  int snap_get_name(PoolCtx *pool, rados_snap_t snapid, std::string *s);
-  int snap_get_stamp(PoolCtx *pool, rados_snap_t snapid, time_t *t);
+  int snap_list(PoolCtx *pool, vector<__u64> *snaps);
+  int snap_lookup(PoolCtx *pool, const char *name, __u64 *snapid);
+  int snap_get_name(PoolCtx *pool, __u64 snapid, std::string *s);
+  int snap_get_stamp(PoolCtx *pool, __u64 snapid, time_t *t);
   int snap_create(const rados_pool_t pool, const char* snapname);
   int snap_remove(const rados_pool_t pool, const char* snapname);
 
@@ -126,13 +127,13 @@ public:
   int setxattr(PoolCtx& pool, const object_t& oid, const char *name, bufferlist& bl);
   int getxattrs(PoolCtx& pool, const object_t& oid, map<string, bufferlist>& attrset);
 
-  int list_pools(std::vector<string>& ls);
-  int get_pool_stats(std::vector<string>& ls, map<string,rados_pool_stat_t>& result);
-  int get_fs_stats( rados_statfs_t& result );
+  int list_pools(std::list<string>& ls);
+  int get_pool_stats(std::list<string>& ls, map<string,pool_stat_t>& result);
+  int get_fs_stats(ceph_statfs& result);
 
-  int create_pool(string& name, __u64 auid=0);
+  int create_pool(string& name, unsigned long long auid=0);
   int delete_pool(const rados_pool_t& pool);
-  int change_pool_auid(const rados_pool_t& pool, __u64 auid);
+  int change_pool_auid(const rados_pool_t& pool, unsigned long long auid);
 
   int list(PoolCtx& pool, int max_entries, std::list<object_t>& entries,
                        Objecter::ListContext *context);
@@ -422,7 +423,7 @@ bool RadosClient::_dispatch(Message *m)
   return true;
 }
 
-int RadosClient::list_pools(std::vector<string>& v)
+int RadosClient::list_pools(std::list<string>& v)
 {
   Mutex::Locker l(lock);
   for (map<int,pg_pool_t>::const_iterator p = osdmap.get_pools().begin(); 
@@ -432,7 +433,7 @@ int RadosClient::list_pools(std::vector<string>& v)
   return 0;
 }
 
-int RadosClient::get_pool_stats(std::vector<string>& pools, map<string,rados_pool_stat_t>& result)
+int RadosClient::get_pool_stats(std::list<string>& pools, map<string,pool_stat_t>& result)
 {
   map<string,pool_stat_t> r;
   Mutex mylock("RadosClient::get_pool_stats::mylock");
@@ -448,29 +449,11 @@ int RadosClient::get_pool_stats(std::vector<string>& pools, map<string,rados_poo
     cond.Wait(mylock);
   mylock.Unlock();
 
-  for (map<string,pool_stat_t>::iterator p = r.begin();
-       p != r.end();
-       p++) {
-    rados_pool_stat_t& v = result[p->first];
-    v.num_kb = p->second.num_kb;
-    v.num_bytes = p->second.num_bytes;
-    v.num_objects = p->second.num_objects;
-    v.num_object_clones = p->second.num_object_clones;
-    v.num_object_copies = p->second.num_object_copies;
-    v.num_objects_missing_on_primary = p->second.num_objects_missing_on_primary;
-    v.num_objects_degraded = p->second.num_objects_degraded;
-    v.num_rd = p->second.num_rd;
-    v.num_rd_kb = p->second.num_rd_kb;
-    v.num_wr = p->second.num_wr;
-    v.num_wr_kb = p->second.num_wr_kb;
-  }
-
   return 0;
 }
 
-int RadosClient::get_fs_stats( rados_statfs_t& result ) {
-  ceph_statfs stats;
-
+int RadosClient::get_fs_stats(ceph_statfs& stats)
+{
   Mutex mylock ("RadosClient::get_fs_stats::mylock");
   Cond cond;
   bool done;
@@ -482,10 +465,6 @@ int RadosClient::get_fs_stats( rados_statfs_t& result ) {
   while (!done) cond.Wait(mylock);
   mylock.Unlock();
 
-  result.kb = stats.kb;
-  result.kb_used = stats.kb_used;
-  result.kb_avail = stats.kb_avail;
-  result.num_objects = stats.num_objects;
   return 0;
 }
 
@@ -534,7 +513,7 @@ int RadosClient::snap_remove( const rados_pool_t pool, const char *snapName)
   return reply;
 }
 
-int RadosClient::create_pool(string& name, __u64 auid)
+int RadosClient::create_pool(string& name, unsigned long long auid)
 {
   int reply;
 
@@ -579,7 +558,7 @@ int RadosClient::delete_pool(const rados_pool_t& pool)
  * auid: the auid you wish the pool to have.
  * Returns: 0 on success, or -ERROR# on failure.
  */
-int RadosClient::change_pool_auid(const rados_pool_t& pool, __u64 auid)
+int RadosClient::change_pool_auid(const rados_pool_t& pool, unsigned long long auid)
 {
   int reply;
 
@@ -600,7 +579,7 @@ int RadosClient::change_pool_auid(const rados_pool_t& pool, __u64 auid)
   return reply;
 }
 
-int RadosClient::snap_list(PoolCtx *pool, vector<rados_snap_t> *snaps)
+int RadosClient::snap_list(PoolCtx *pool, vector<__u64> *snaps)
 {
   Mutex::Locker l(lock);
   const pg_pool_t *pi = objecter->osdmap->get_pg_pool(pool->poolid);
@@ -611,7 +590,7 @@ int RadosClient::snap_list(PoolCtx *pool, vector<rados_snap_t> *snaps)
   return 0;
 }
 
-int RadosClient::snap_lookup(PoolCtx *pool, const char *name, rados_snap_t *snapid)
+int RadosClient::snap_lookup(PoolCtx *pool, const char *name, __u64 *snapid)
 {
   Mutex::Locker l(lock);
   const pg_pool_t *pi = objecter->osdmap->get_pg_pool(pool->poolid);
@@ -626,7 +605,7 @@ int RadosClient::snap_lookup(PoolCtx *pool, const char *name, rados_snap_t *snap
   return -ENOENT;
 }
 
-int RadosClient::snap_get_name(PoolCtx *pool, rados_snap_t snapid, std::string *s)
+int RadosClient::snap_get_name(PoolCtx *pool, __u64 snapid, std::string *s)
 {
   Mutex::Locker l(lock);
   const pg_pool_t *pi = objecter->osdmap->get_pg_pool(pool->poolid);
@@ -637,7 +616,7 @@ int RadosClient::snap_get_name(PoolCtx *pool, rados_snap_t snapid, std::string *
   return 0;
 }
 
-int RadosClient::snap_get_stamp(PoolCtx *pool, rados_snap_t snapid, time_t *t)
+int RadosClient::snap_get_stamp(PoolCtx *pool, __u64 snapid, time_t *t)
 {
   Mutex::Locker l(lock);
   const pg_pool_t *pi = objecter->osdmap->get_pg_pool(pool->poolid);
@@ -1100,6 +1079,8 @@ int RadosClient::getxattrs(PoolCtx& pool, const object_t& oid, map<std::string,
 
 // ---------------------------------------------
 
+namespace librados {
+
 Rados::Rados() : client(NULL)
 {
 }
@@ -1107,7 +1088,7 @@ Rados::Rados() : client(NULL)
 Rados::~Rados()
 {
   if (client)
-    delete client;
+    delete (RadosClient *)client;
   client = NULL;
 }
 
@@ -1124,26 +1105,44 @@ int Rados::initialize(int argc, const char *argv[])
   if (g_conf.clock_tare) g_clock.tare();
 
   client = new RadosClient();
-  return client->init() ? 0 : -1;
+  return ((RadosClient *)client)->init() ? 0 : -1;
 }
 
 void Rados::shutdown()
 {
-  client->shutdown();
+  ((RadosClient *)client)->shutdown();
 }
 
-int Rados::list_pools(std::vector<string>& v)
+int Rados::list_pools(std::list<string>& v)
 {
   if (!client)
     return -EINVAL;
-  return client->list_pools(v);
+  return ((RadosClient *)client)->list_pools(v);
 }
 
-int Rados::get_pool_stats(std::vector<string>& v, std::map<string,rados_pool_stat_t>& result)
+int Rados::get_pool_stats(std::list<string>& v, std::map<string,pool_stat_t>& result)
 {
   if (!client)
     return -EINVAL;
-  return client->get_pool_stats(v, result);
+  map<string,::pool_stat_t> rawresult;
+  int r = ((RadosClient *)client)->get_pool_stats(v, rawresult);
+  for (map<string,::pool_stat_t>::iterator p = rawresult.begin();
+       p != rawresult.end();
+       p++) {
+    pool_stat_t& v = result[p->first];
+    v.num_kb = p->second.num_kb;
+    v.num_bytes = p->second.num_bytes;
+    v.num_objects = p->second.num_objects;
+    v.num_object_clones = p->second.num_object_clones;
+    v.num_object_copies = p->second.num_object_copies;
+    v.num_objects_missing_on_primary = p->second.num_objects_missing_on_primary;
+    v.num_objects_degraded = p->second.num_objects_degraded;
+    v.num_rd = p->second.num_rd;
+    v.num_rd_kb = p->second.num_rd_kb;
+    v.num_wr = p->second.num_wr;
+    v.num_wr_kb = p->second.num_wr_kb;
+  }
+  return r;
 }
 
 int Rados::create_pool(const char *name, __u64 auid)
@@ -1151,24 +1150,32 @@ int Rados::create_pool(const char *name, __u64 auid)
   string str(name);
   if (!client)
     return -EINVAL;
-  return client->create_pool(str, auid);
+  return ((RadosClient *)client)->create_pool(str, auid);
 }
 
 int Rados::delete_pool(const rados_pool_t& pool)
 {
   if (!client) return -EINVAL;
-  return client->delete_pool(pool);
+  return ((RadosClient *)client)->delete_pool(pool);
 }
 
 int Rados::change_pool_auid(const rados_pool_t& pool, __u64 auid)
 {
   if (!client) return -EINVAL;
-  return client->change_pool_auid(pool, auid);
+  return ((RadosClient *)client)->change_pool_auid(pool, auid);
 }
 
-int Rados::get_fs_stats(rados_statfs_t& result) {
-  if(!client) return -EINVAL;
-  return client->get_fs_stats(result);
+int Rados::get_fs_stats(statfs_t& result)
+{
+  if (!client)
+    return -EINVAL;
+  ceph_statfs stats;
+  int r = ((RadosClient *)client)->get_fs_stats(stats);
+  result.kb = stats.kb;
+  result.kb_used = stats.kb_used;
+  result.kb_avail = stats.kb_avail;
+  result.num_objects = stats.num_objects;
+  return r;
 }
 
 int Rados::list(rados_pool_t pool, int max, std::list<string>& entries, Rados::ListCtx& ctx)
@@ -1185,7 +1192,7 @@ int Rados::list(rados_pool_t pool, int max, std::list<string>& entries, Rados::L
 
   op = (Objecter::ListContext *) ctx.ctx;
   std::list<object_t> e;
-  int r = client->list(*(RadosClient::PoolCtx *)pool, max, e, op);
+  int r = ((RadosClient *)client)->list(*(RadosClient::PoolCtx *)pool, max, e, op);
   while (!e.empty()) {
     entries.push_back(e.front().name.c_str());
     e.pop_front();
@@ -1198,7 +1205,7 @@ int Rados::create(rados_pool_t pool, const string& o, bool exclusive)
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->create(*(RadosClient::PoolCtx *)pool, oid, exclusive);
+  return ((RadosClient *)client)->create(*(RadosClient::PoolCtx *)pool, oid, exclusive);
 }
 
 int Rados::write(rados_pool_t pool, const string& o, off_t off, bufferlist& bl, size_t len)
@@ -1206,7 +1213,7 @@ int Rados::write(rados_pool_t pool, const string& o, off_t off, bufferlist& bl,
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->write(*(RadosClient::PoolCtx *)pool, oid, off, bl, len);
+  return ((RadosClient *)client)->write(*(RadosClient::PoolCtx *)pool, oid, off, bl, len);
 }
 
 int Rados::write_full(rados_pool_t pool, const string& o, bufferlist& bl)
@@ -1214,7 +1221,7 @@ int Rados::write_full(rados_pool_t pool, const string& o, bufferlist& bl)
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->write_full(*(RadosClient::PoolCtx *)pool, oid, bl);
+  return ((RadosClient *)client)->write_full(*(RadosClient::PoolCtx *)pool, oid, bl);
 }
 
 int Rados::remove(rados_pool_t pool, const string& o)
@@ -1222,7 +1229,7 @@ int Rados::remove(rados_pool_t pool, const string& o)
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->remove(*(RadosClient::PoolCtx *)pool, oid);
+  return ((RadosClient *)client)->remove(*(RadosClient::PoolCtx *)pool, oid);
 }
 
 int Rados::read(rados_pool_t pool, const string& o, off_t off, bufferlist& bl, size_t len)
@@ -1230,7 +1237,7 @@ int Rados::read(rados_pool_t pool, const string& o, off_t off, bufferlist& bl, s
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->read(*(RadosClient::PoolCtx *)pool, oid, off, bl, len);
+  return ((RadosClient *)client)->read(*(RadosClient::PoolCtx *)pool, oid, off, bl, len);
 }
 
 int Rados::getxattr(rados_pool_t pool, const string& o, const char *name, bufferlist& bl)
@@ -1238,7 +1245,7 @@ int Rados::getxattr(rados_pool_t pool, const string& o, const char *name, buffer
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->getxattr(*(RadosClient::PoolCtx *)pool, oid, name, bl);
+  return ((RadosClient *)client)->getxattr(*(RadosClient::PoolCtx *)pool, oid, name, bl);
 }
 
 int Rados::getxattrs(rados_pool_t pool, const string& o, map<std::string, bufferlist>& attrset)
@@ -1246,7 +1253,7 @@ int Rados::getxattrs(rados_pool_t pool, const string& o, map<std::string, buffer
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->getxattrs(*(RadosClient::PoolCtx *)pool, oid, attrset);
+  return ((RadosClient *)client)->getxattrs(*(RadosClient::PoolCtx *)pool, oid, attrset);
 }
 
 int Rados::setxattr(rados_pool_t pool, const string& o, const char *name, bufferlist& bl)
@@ -1254,7 +1261,7 @@ int Rados::setxattr(rados_pool_t pool, const string& o, const char *name, buffer
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->setxattr(*(RadosClient::PoolCtx *)pool, oid, name, bl);
+  return ((RadosClient *)client)->setxattr(*(RadosClient::PoolCtx *)pool, oid, name, bl);
 }
 
 int Rados::stat(rados_pool_t pool, const string& o, __u64 *psize, time_t *pmtime)
@@ -1262,7 +1269,7 @@ int Rados::stat(rados_pool_t pool, const string& o, __u64 *psize, time_t *pmtime
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->stat(*(RadosClient::PoolCtx *)pool, oid, psize, pmtime);
+  return ((RadosClient *)client)->stat(*(RadosClient::PoolCtx *)pool, oid, psize, pmtime);
 }
 
 int Rados::tmap_update(rados_pool_t pool, const string& o, bufferlist& cmdbl)
@@ -1270,7 +1277,7 @@ int Rados::tmap_update(rados_pool_t pool, const string& o, bufferlist& cmdbl)
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->tmap_update(*(RadosClient::PoolCtx *)pool, oid, cmdbl);
+  return ((RadosClient *)client)->tmap_update(*(RadosClient::PoolCtx *)pool, oid, cmdbl);
 }
 int Rados::exec(rados_pool_t pool, const string& o, const char *cls, const char *method,
                bufferlist& inbl, bufferlist& outbl)
@@ -1278,12 +1285,12 @@ int Rados::exec(rados_pool_t pool, const string& o, const char *cls, const char
   if (!client)
     return -EINVAL;
   object_t oid(o);
-  return client->exec(*(RadosClient::PoolCtx *)pool, oid, cls, method, inbl, outbl);
+  return ((RadosClient *)client)->exec(*(RadosClient::PoolCtx *)pool, oid, cls, method, inbl, outbl);
 }
 
 int Rados::open_pool(const char *name, rados_pool_t *pool)
 {
-  int poolid = client->lookup_pool(name);
+  int poolid = ((RadosClient *)client)->lookup_pool(name);
   if (poolid >= 0) {
     RadosClient::PoolCtx *ctx = new RadosClient::PoolCtx(poolid, CEPH_NOSNAP);
     if (!ctx)
@@ -1306,16 +1313,16 @@ int Rados::close_pool(rados_pool_t pool)
 
 int Rados::snap_create(const rados_pool_t pool, const char *snapname) {
   if (!client) return -EINVAL;
-  return client->snap_create(pool, snapname);
+  return ((RadosClient *)client)->snap_create(pool, snapname);
 }
 
 int Rados::snap_remove(const rados_pool_t pool, const char *snapname) {
   if (!client) return -EINVAL;
-  return client->snap_remove(pool, snapname);
+  return ((RadosClient *)client)->snap_remove(pool, snapname);
 }
 
 
-void Rados::set_snap(rados_pool_t pool, __u64 seq)
+void Rados::set_snap(rados_pool_t pool, snap_t seq)
 {
   if (!client)
     return;
@@ -1323,35 +1330,35 @@ void Rados::set_snap(rados_pool_t pool, __u64 seq)
   ctx->set_snap(seq);
 }
 
-int Rados::snap_list(rados_pool_t pool, vector<rados_snap_t> *snaps)
+int Rados::snap_list(rados_pool_t pool, vector<snap_t> *snaps)
 {
   if (!client)
     return -EINVAL;
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
-  return client->snap_list(ctx, snaps);
+  return ((RadosClient *)client)->snap_list(ctx, snaps);
 }
 
-int Rados::snap_lookup(rados_pool_t pool, const char *name, rados_snap_t *snapid)
+int Rados::snap_lookup(rados_pool_t pool, const char *name, snap_t *snapid)
 {
   if (!client)
     return -EINVAL;
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
-  return client->snap_lookup(ctx, name, snapid);
+  return ((RadosClient *)client)->snap_lookup(ctx, name, snapid);
 }
 
-int Rados::snap_get_name(rados_pool_t pool, rados_snap_t snapid, std::string *s)
+int Rados::snap_get_name(rados_pool_t pool, snap_t snapid, std::string *s)
 {
   if (!client)
     return -EINVAL;
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
-  return client->snap_get_name(ctx, snapid, s);
+  return ((RadosClient *)client)->snap_get_name(ctx, snapid, s);
 }
-int Rados::snap_get_stamp(rados_pool_t pool, rados_snap_t snapid, time_t *t)
+int Rados::snap_get_stamp(rados_pool_t pool, snap_t snapid, time_t *t)
 {
   if (!client)
     return -EINVAL;
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
-  return client->snap_get_stamp(ctx, snapid, t);
+  return ((RadosClient *)client)->snap_get_stamp(ctx, snapid, t);
 }
 
 // AIO
@@ -1360,7 +1367,7 @@ int Rados::aio_read(rados_pool_t pool, const string& oid, off_t off, bufferlist
 {
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
   RadosClient::AioCompletion *c;
-  int r = client->aio_read(*ctx, oid, off, pbl, len, &c);
+  int r = ((RadosClient *)client)->aio_read(*ctx, oid, off, pbl, len, &c);
   if (r >= 0) {
     *pc = new AioCompletion((void *)c);
   }
@@ -1372,7 +1379,7 @@ int Rados::aio_write(rados_pool_t pool, const string& oid, off_t off, const buff
 {
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
   RadosClient::AioCompletion *c;
-  int r = client->aio_write(*ctx, oid, off, bl, len, &c);
+  int r = ((RadosClient *)client)->aio_write(*ctx, oid, off, bl, len, &c);
   if (r >= 0) {
     *pc = new AioCompletion((void *)c);
   }
@@ -1415,6 +1422,8 @@ void Rados::AioCompletion::release()
   c->put();
 }
 
+}
+
 // ---------------------------------------------
 
 static void __rados_init(int argc, const char *argv[])
@@ -1566,7 +1575,7 @@ extern "C" int rados_snap_remove(const rados_pool_t pool, const char *snapname)
 extern "C" int rados_snap_list(rados_pool_t pool, rados_snap_t *snaps, int maxlen)
 {
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
-  vector<rados_snap_t> snapvec;
+  vector<__u64> snapvec;
   int r = radosp->snap_list(ctx, &snapvec);
   if (r < 0)
     return r;
@@ -1581,7 +1590,7 @@ extern "C" int rados_snap_list(rados_pool_t pool, rados_snap_t *snaps, int maxle
 extern "C" int rados_snap_lookup(rados_pool_t pool, const char *name, rados_snap_t *id)
 {
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
-  return radosp->snap_lookup(ctx, name, id);
+  return radosp->snap_lookup(ctx, name, (__u64 *)id);
 }
 
 extern "C" int rados_snap_get_name(rados_pool_t pool, rados_snap_t id, char *name, int maxlen)
@@ -1766,3 +1775,4 @@ extern "C" int rados_aio_write(rados_pool_t pool, const char *o,
   bl.append(buf, len);
   return radosp->aio_write(*ctx, oid, off, bl, len, (RadosClient::AioCompletion**)completion);
 }
+
index f0a6e8060155e7e31981ae0720d34735567f3153..b0d72ef7dac7f893b96d8251ee23c9b6b875c73d 100644 (file)
 class MGetPoolStats : public PaxosServiceMessage {
 public:
   ceph_fsid_t fsid;
-  vector<string> pools;
+  list<string> pools;
 
   MGetPoolStats() : PaxosServiceMessage(MSG_GETPOOLSTATS, 0) {}
-  MGetPoolStats(const ceph_fsid_t& f, tid_t t, vector<string>& ls, version_t l) :
+  MGetPoolStats(const ceph_fsid_t& f, tid_t t, list<string>& ls, version_t l) :
     PaxosServiceMessage(MSG_GETPOOLSTATS, l),
     fsid(f), pools(ls) {
     set_tid(t);
index 1af1c41123d2e7d4a71ba67bc53c7042eb067fd7..844398b75dc09598aa1adb74831a0ecf1b738c64 100644 (file)
@@ -237,7 +237,7 @@ bool PGMonitor::preprocess_getpoolstats(MGetPoolStats *m)
   
   reply = new MGetPoolStatsReply(m->fsid, m->get_tid(), paxos->get_version());
 
-  for (vector<string>::iterator p = m->pools.begin();
+  for (list<string>::iterator p = m->pools.begin();
        p != m->pools.end();
        p++) {
     int poolid = mon->osdmon()->osdmap.lookup_pg_pool_name(p->c_str());
index 74b21cd8c13d2423ceb70c8a0426ed499ada0e21..f5adc2e91f92157754f17770117130243356c3a4 100644 (file)
@@ -781,7 +781,7 @@ void Objecter::handle_pool_op_reply(MPoolOpReply *m) {
 
 // pool stats
 
-void Objecter::get_pool_stats(vector<string>& pools, map<string,pool_stat_t> *result,
+void Objecter::get_pool_stats(list<string>& pools, map<string,pool_stat_t> *result,
                              Context *onfinish)
 {
   dout(10) << "get_pool_stats " << pools << dendl;
index b887ef3174a0f08a94e67b8348d77c74e243cce6..b5996611c9ec6a3d05e16c9e714b255970329080 100644 (file)
@@ -319,7 +319,7 @@ public:
   
   struct PoolStatOp {
     tid_t tid;
-    vector<string> pools;
+    list<string> pools;
 
     map<string,pool_stat_t> *pool_stats;
     Context *onfinish;
@@ -685,7 +685,7 @@ private:
   void poolstat_submit(PoolStatOp *op);
 public:
   void handle_get_pool_stats_reply(MGetPoolStatsReply *m);
-  void get_pool_stats(vector<string>& pools, map<string,pool_stat_t> *result,
+  void get_pool_stats(list<string>& pools, map<string,pool_stat_t> *result,
                      Context *onfinish);
 
   // ---------------------------
index faffe5c8c248927c1c9c466d0e87897506666c15..66ac2b4a87d74706c918b1f2b3c69bbfa242e618 100644 (file)
  */
 
 #include "include/types.h"
+
+#include "include/librados.hpp"
+using namespace librados;
+
 #include "osdc/rados_bencher.h"
-#include "include/librados.h"
 
 #include "config.h"
 #include "common/common_init.h"
@@ -91,7 +94,7 @@ int main(int argc, const char **argv)
   int op_size = 1 << 22;
 
   const char *snapname = 0;
-  rados_snap_t snapid = CEPH_NOSNAP;
+  snap_t snapid = CEPH_NOSNAP;
 
   FOR_EACH_ARG(args) {
     if (CONF_ARG_EQ("pool", 'p')) {
@@ -127,7 +130,7 @@ int main(int argc, const char **argv)
   char buf[80];
 
   // open pool?
-  rados_pool_t p;
+  pool_t p;
   if (pool) {
     ret = rados.open_pool(pool, &p);
     if (ret < 0) {
@@ -157,34 +160,34 @@ int main(int argc, const char **argv)
 
   // list pools?
   if (strcmp(nargs[0], "lspools") == 0) {
-    vector<string> vec;
+    list<string> vec;
     rados.list_pools(vec);
-    for (vector<string>::iterator i = vec.begin(); i != vec.end(); ++i)
+    for (list<string>::iterator i = vec.begin(); i != vec.end(); ++i)
       cout << *i << std::endl;
   }
   else if (strcmp(nargs[0], "df") == 0) {
     // pools
-    vector<string> vec;
+    list<string> vec;
     rados.list_pools(vec);
     
-    map<string,rados_pool_stat_t> stats;
+    map<string,pool_stat_t> stats;
     rados.get_pool_stats(vec, stats);
 
     printf("%-15s %12s %12s %12s %12s %12s %12s %12s %12s\n",
           "pool name", "KB", "objects", "clones", "degraded", "rd", "rd KB", "wr", "wr KB");
-    for (map<string,rados_pool_stat_t>::iterator i = stats.begin(); i != stats.end(); ++i) {
+    for (map<string,pool_stat_t>::iterator i = stats.begin(); i != stats.end(); ++i) {
       printf("%-15s %12lld %12lld %12lld %12lld %12lld %12lld %12lld %12lld\n",
             i->first.c_str(),
-            i->second.num_kb,
-            i->second.num_objects,
-            i->second.num_object_clones,
-            i->second.num_objects_degraded,
-            i->second.num_rd, i->second.num_rd_kb,
-            i->second.num_wr, i->second.num_wr_kb);
+            (long long)i->second.num_kb,
+            (long long)i->second.num_objects,
+            (long long)i->second.num_object_clones,
+            (long long)i->second.num_objects_degraded,
+            (long long)i->second.num_rd, (long long)i->second.num_rd_kb,
+            (long long)i->second.num_wr, (long long)i->second.num_wr_kb);
     }
 
     // total
-    rados_statfs_t tstats;
+    statfs_t tstats;
     rados.get_fs_stats(tstats);
     printf("  total used    %12lld %12lld\n", (long long unsigned)tstats.kb_used,
           (long long unsigned)tstats.num_objects);
@@ -320,9 +323,9 @@ int main(int argc, const char **argv)
     if (!pool || nargs.size() != 1)
       usage();
 
-    vector<rados_snap_t> snaps;
+    vector<snap_t> snaps;
     rados.snap_list(p, &snaps);
-    for (vector<rados_snap_t>::iterator i = snaps.begin();
+    for (vector<snap_t>::iterator i = snaps.begin();
         i != snaps.end();
         i++) {
       string s;
index 608fc5d21be2287e35c55ae47ce8cb9c229b7d45..f7e396cdbd131538e98910d2752226afb839770e 100644 (file)
@@ -13,7 +13,8 @@
  */
 
 #include "include/types.h"
-#include "include/librados.h"
+#include "include/librados.hpp"
+using namespace librados;
 
 #include <iostream>
 
@@ -138,7 +139,7 @@ int main(int argc, const char **argv)
 
   const char *oid = "bar";
 
-  rados_pool_t pool;
+  pool_t pool;
   int r = rados.open_pool("data", &pool);
   cout << "open pool result = " << r << " pool = " << pool << std::endl;
 
index e992862f8e7541ad91715a1552c6777027525ca8..d6b24ba12203842273270bb120b1d988ef8bab1f 100644 (file)
@@ -15,7 +15,8 @@
 #include "config.h"
 
 #include "common/common_init.h"
-#include "include/librados.h"
+#include "include/librados.hpp"
+using namespace librados;
 #include "include/byteorder.h"
 
 
@@ -113,7 +114,7 @@ int main(int argc, const char **argv)
   md_oid += RBD_SUFFIX;
   string dir_oid = RBD_DIRECTORY;
 
-  rados_pool_t pool;
+  pool_t pool;
 
   int r = rados.open_pool(poolname, &pool);
   if (r < 0) {
index 788722f3cfd76d7b1575c4a81cb3ccbd89ed8cc8..bd8920cc1c1261126042ed637d05f21e20420977 100644 (file)
@@ -4,7 +4,8 @@
 #include "rgw_access.h"
 #include "rgw_rados.h"
 
-#include "include/librados.h"
+#include "include/librados.hpp"
+using namespace librados;
 
 #include <string>
 #include <iostream>
@@ -14,7 +15,7 @@
 
 using namespace std;
 
-static Rados *rados = NULL;
+Rados *rados = NULL;
 
 #define ROOT_BUCKET ".rgw" //keep this synced to rgw_user.cc::root_bucket!
 
@@ -60,8 +61,8 @@ int RGWRados::open_root_pool(rados_pool_t *pool)
 
 class RGWRadosListState {
 public:
-  vector<string> list;
-  unsigned int pos;
+  std::list<string> list;
+  std::list<string>::iterator pos;
   RGWRadosListState() : pos(0) {}
 };
 
@@ -98,14 +99,13 @@ int RGWRados::list_buckets_next(std::string& id, RGWObjEnt& obj, RGWAccessHandle
 {
   RGWRadosListState *state = (RGWRadosListState *)*handle;
 
-  if (state->pos == state->list.size()) {
+  if (state->pos == state->list.end()) {
     delete state;
     return -ENOENT;
   }
 
-
-
-  obj.name = state->list[state->pos++];
+  obj.name = *state->pos;
+  state->pos++;
 
   /* FIXME: should read mtime/size vals for bucket */
 
index 968ca79a3c9d1b52340fc119e5b4323239edd34e..4905c8f33db5d56efeecfff6e5b2a6cad39a195b 100644 (file)
@@ -13,7 +13,9 @@
  */
 
 #include "include/types.h"
-#include "include/librados.h"
+#include "include/librados.hpp"
+
+using namespace librados;
 
 #include <iostream>
 
@@ -50,7 +52,7 @@ int main(int argc, const char **argv)
 
   const char *oid = "bar";
 
-  rados_pool_t pool;
+  pool_t pool;
 
   int r = rados.open_pool("data", &pool);
   cout << "open pool result = " << r << " pool = " << pool << std::endl;