]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Added support for MStatfs to librados and Objecter.
authorGreg Farnum <gregf@hq.newdream.net>
Thu, 11 Jun 2009 21:51:12 +0000 (14:51 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Thu, 11 Jun 2009 22:50:34 +0000 (15:50 -0700)
src/include/librados.h
src/librados.cc
src/osdc/Objecter.cc
src/osdc/Objecter.h

index bb2c5a4e00a40f43c7d0f772b3e92a9bc14abbdf..c7a8aadf95254060834b0830e9106342b3dff964 100644 (file)
@@ -36,6 +36,20 @@ struct rados_pool_stat_t {
   long long unsigned num_objects_degraded;
 };
 
+struct ceph_stat_fs_t {
+  int f_bsize;
+  int f_frsize;
+  int f_blocks;
+  int f_bfree;
+  int f_bavail;
+  int f_files;
+  int f_ffree;
+  int f_favail;
+  int f_fsid;
+  int f_flag;
+  int f_namemax;
+};
+
 int rados_open_pool(const char *name, rados_pool_t *pool);
 int rados_close_pool(rados_pool_t pool);
 void rados_set_snap(rados_pool_t pool, rados_snap_t snap);
@@ -105,6 +119,7 @@ public:
   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(ceph_stat_fs_t& result);
 
   int snap_create(rados_pool_t pool, const char *snapname);
   int snap_remove(rados_pool_t pool, const char *snapname);
index 4dedf6a2a274094b34fbf5a12f9faff997c1fecd..82074a39d26224944abd88a902991615aa422a8e 100644 (file)
@@ -110,6 +110,7 @@ public:
 
   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( ceph_stat_fs_t& result );
 
   int list(PoolCtx& pool, int max_entries, std::list<object_t>& entries, RadosClient::PGLSOp& op);
 
@@ -385,7 +386,7 @@ int RadosClient::list_pools(std::vector<string>& v)
   return 0;
 }
 
-int RadosClient::get_pool_stats(std::vector<string>& v, map<string,rados_pool_stat_t>& result)
+int RadosClient::get_pool_stats(std::vector<string>& pools, map<string,rados_pool_stat_t>& result)
 {
   map<string,pool_stat_t> r;
   Mutex mylock("RadosClient::get_pool_stats::mylock");
@@ -393,7 +394,7 @@ int RadosClient::get_pool_stats(std::vector<string>& v, map<string,rados_pool_st
   bool done;
 
   lock.Lock();
-  objecter->get_pool_stats(v, &r, new C_SafeCond(&mylock, &cond, &done));
+  objecter->get_pool_stats(pools, &r, new C_SafeCond(&mylock, &cond, &done));
   lock.Unlock();
   
   mylock.Lock();
@@ -417,6 +418,33 @@ int RadosClient::get_pool_stats(std::vector<string>& v, map<string,rados_pool_st
   return 0;
 }
 
+int RadosClient::get_fs_stats( ceph_stat_fs_t& result ) {
+  ceph_statfs stats;
+
+  Mutex mylock ("RadosClient::get_fs_stats::mylock");
+  Cond cond;
+  bool done;
+  lock.Lock();
+  objecter->get_fs_stats(stats, new C_SafeCond(&mylock, &cond, &done));
+  lock.Unlock();
+
+  mylock.Lock();
+  while (!done) cond.Wait(mylock);
+  mylock.Unlock();
+
+  result.f_bsize = 4096;
+  result.f_frsize = 4096;
+  result.f_blocks = stats.f_total / 4 ;
+  result.f_bfree = stats.f_free / 4;
+  result.f_bavail = stats.f_avail / 4;
+  result.f_files = stats.f_objects / 4;
+  result.f_ffree = -1;
+  result.f_favail = -1;
+  result.f_fsid = -1;
+  result.f_flag = 0;
+  result.f_namemax = 1024;
+  return 0;
+}
 
 
 // SNAPS
@@ -781,6 +809,11 @@ int Rados::get_pool_stats(std::vector<string>& v, std::map<string,rados_pool_sta
   return client->get_pool_stats(v, result);
 }
 
+int Rados::get_fs_stats(ceph_stat_fs_t& result) {
+  if(!client) return -EINVAL;
+  return client->get_fs_stats(result);
+}
+
 int Rados::list(rados_pool_t pool, int max, std::list<object_t>& entries, Rados::ListCtx& ctx)
 {
   if (!client)
index afa7d4192db85616e0937c019801d1fd2bdabbc0..3fedb3a4b3c9e95ab5652f0df038c16307a7d8d7 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "messages/MGetPoolStats.h"
 #include "messages/MGetPoolStatsReply.h"
+#include "messages/MStatfs.h"
+#include "messages/MStatfsReply.h"
 
 #include "messages/MOSDFailure.h"
 
@@ -70,6 +72,10 @@ void Objecter::dispatch(Message *m)
     handle_get_pool_stats_reply((MGetPoolStatsReply*)m);
     break;
 
+  case CEPH_MSG_STATFS_REPLY:
+    handle_fs_stats_reply((MStatfsReply*)m);
+    break;
+
   default:
     dout(1) << "don't know message type " << m->get_type() << dendl;
     assert(0);
@@ -672,10 +678,43 @@ void Objecter::handle_get_pool_stats_reply(MGetPoolStatsReply *m)
 }
 
 
+void Objecter::get_fs_stats(ceph_statfs& result, Context *onfinish) {
+  dout(10) << "get_fs_stats" << dendl;
+
+  StatfsOp *op = new StatfsOp;
+  op->tid = ++last_tid;
+  op->stats = &result;
+  op->onfinish = onfinish;
+  op_statfs[op->tid] = op;
 
+  fs_stats_submit(op);
+}
 
+void Objecter::fs_stats_submit(StatfsOp *op) {
+  dout(10) << "fs_stats_submit" << op->tid << dendl;
+  MStatfs *m = new MStatfs(monmap->fsid, op->tid);
+  int mon = monmap->pick_mon();
+  messenger->send_message(m, monmap->get_inst(mon));
+}
 
+void Objecter::handle_fs_stats_reply(MStatfsReply *m) {
+  dout(10) << "handle_fs_stats_reply " << *m << dendl;
+  tid_t tid = m->h.tid;
 
+  if (op_statfs.count(tid)) {
+    StatfsOp *op = op_statfs[tid];
+    dout(10) << "have request " << tid << " at " << op << dendl;
+    op->stats = &(m->h.st);
+    op->onfinish->finish(0);
+    delete op->onfinish;
+    op_statfs.erase(tid);
+    delete op;
+  } else {
+    dout(10) << "unknown request " << tid << dendl;
+  }
+  dout(10) << "done" << dendl;
+  delete m;
+}
 
 
 // scatter/gather
index 1177091da91fb74b91816bd4fc93c8a3047c35cb..caec25e9739491b4ed2a5e30ff0047375862b9b6 100644 (file)
@@ -36,6 +36,7 @@ class MonMap;
 class Message;
 
 class MGetPoolStatsReply;
+class MStatfsReply;
 
 // -----------------------------------------
 
@@ -273,13 +274,19 @@ class Objecter {
     map<string,pool_stat_t> *pool_stats;
     Context *onfinish;
   };
-  
+
+  struct StatfsOp {
+    tid_t tid;
+    ceph_statfs *stats;
+    Context *onfinish;
+  };
 
  private:
   // pending ops
   hash_map<tid_t,ReadOp*>   op_read;
   hash_map<tid_t,ModifyOp*> op_modify;
   map<tid_t,PoolStatOp*>    op_poolstat;
+  map<tid_t,StatfsOp*>      op_statfs;
 
   /**
    * track pending ops by pg
@@ -462,6 +469,13 @@ public:
   void get_pool_stats(vector<string>& pools, map<string,pool_stat_t> *result,
                      Context *onfinish);
 
+  // ---------------------------
+  // df stats
+private:
+  void fs_stats_submit(StatfsOp *op);
+public:
+  void handle_fs_stats_reply(MStatfsReply *m);
+  void get_fs_stats(ceph_statfs& result, Context *onfinish);
 
   // ---------------------------
   // some scatter/gather hackery