]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/ObjectStore: Refactor ObjectStore::statfs method to return extended statistics
authorIgor Fedotov <ifedotov@mirantis.com>
Mon, 6 Jun 2016 14:43:39 +0000 (17:43 +0300)
committerIgor Fedotov <ifedotov@mirantis.com>
Wed, 8 Jun 2016 13:40:26 +0000 (16:40 +0300)
Signed-off-by: Igor Fedotov <ifedotov@mirantis.com>
14 files changed:
src/kv/KeyValueDB.h
src/os/FuseStore.cc
src/os/ObjectStore.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/filestore/FileStore.cc
src/os/filestore/FileStore.h
src/os/kstore/KStore.cc
src/os/kstore/KStore.h
src/os/memstore/MemStore.cc
src/os/memstore/MemStore.h
src/osd/OSD.cc
src/osd/osd_types.cc
src/osd/osd_types.h

index 92296f534dcba7ddef5a2268d86e76d44403f2e4..ab4d60a4775c4b9b4205fc0f56b75ee07c3fa639 100644 (file)
@@ -276,7 +276,7 @@ public:
   }
 
   virtual uint64_t get_estimated_size(std::map<std::string,uint64_t> &extra) = 0;
-  virtual int get_statfs(struct statfs *buf) {
+  virtual int get_statfs(struct store_statfs_t *buf) {
     return -EOPNOTSUPP;
   }
 
index 0849865af69ad156e7555140442540a2af07c06a..e9445476e92419399ed097b2f9691970ea18be90 100644 (file)
@@ -978,16 +978,14 @@ static int os_statfs(const char *path, struct statvfs *stbuf)
   fuse_context *fc = fuse_get_context();
   FuseStore *fs = static_cast<FuseStore*>(fc->private_data);
 
-  struct statfs s;
+  struct store_statfs_t s;
   int r = fs->store->statfs(&s);
   if (r < 0)
     return r;
-  stbuf->f_bsize = s.f_bsize;
-  stbuf->f_blocks = s.f_blocks;
-  stbuf->f_bfree = s.f_bfree;
-  stbuf->f_bavail = s.f_bavail;
-  stbuf->f_files = s.f_files;
-  stbuf->f_ffree = s.f_ffree;
+  stbuf->f_bsize = s.bsize;
+  stbuf->f_blocks = s.blocks;
+  stbuf->f_bavail = stbuf->f_bfree = s.available / s.blocks;
+
   return 0;
 }
 
index 841fdff04ceed863ff81f49d354e63cc90db573a..5ef56f70500c3731e28e8b8c4bada86c40ffae2a 100644 (file)
@@ -1892,7 +1892,7 @@ public:
     return false;   // assume a backend cannot, unless it says otherwise
   }
 
-  virtual int statfs(struct statfs *buf) = 0;
+  virtual int statfs(struct store_statfs_t *buf) = 0;
 
   virtual void collect_metadata(map<string,string> *pm) { }
 
index d374c0dcccdcbb7d5e8b1a57261a45587042d893..0eac105779422b823a9ba741175fbc64f078878e 100644 (file)
@@ -2880,7 +2880,7 @@ void BlueStore::_sync()
   dout(10) << __func__ << " done" << dendl;
 }
 
-int BlueStore::statfs(struct statfs *buf)
+int BlueStore::statfs(struct store_statfs_t *buf)
 {
   memset(buf, 0, sizeof(*buf));
   uint64_t bluefs_len = 0;
@@ -2888,13 +2888,13 @@ int BlueStore::statfs(struct statfs *buf)
       p != bluefs_extents.end(); p++)
     bluefs_len += p.get_len();
 
-  buf->f_blocks = bdev->get_size() / block_size;
-  buf->f_bsize = block_size;
-  buf->f_bfree = (alloc->get_free() - bluefs_len) / block_size;
-  buf->f_bavail = buf->f_bfree;
+  buf->reset();
 
-  dout(20) << __func__ << " free " << pretty_si_t(buf->f_bfree * buf->f_bsize)
-          << " / " << pretty_si_t(buf->f_blocks * buf->f_bsize) << dendl;
+  buf->blocks = bdev->get_size() / block_size;
+  buf->bsize = block_size;
+  buf->available = (alloc->get_free() - bluefs_len);
+
+  dout(20) << __func__ << *buf << dendl;
   return 0;
 }
 
index 4da5b40b7901df166f39d3108e036c49ab16391d..a53ea05f8dcfb48003d6e8e941a8012439ee63fe 100644 (file)
@@ -1006,7 +1006,7 @@ public:
   }
 
 public:
-  int statfs(struct statfs *buf) override;
+  int statfs(struct store_statfs_t *buf) override;
 
   bool exists(const coll_t& cid, const ghobject_t& oid) override;
   bool exists(CollectionHandle &c, const ghobject_t& oid) override;
index 91a6b2596ea2c4591d6a290a66b393e14d2d96f5..e927adfd3e50a575c85c05f05adaeb97c9888fd9 100644 (file)
@@ -701,14 +701,21 @@ void FileStore::collect_metadata(map<string,string> *pm)
   }
 }
 
-int FileStore::statfs(struct statfs *buf)
+int FileStore::statfs(struct store_statfs_t *buf0)
 {
-  if (::statfs(basedir.c_str(), buf) < 0) {
+  struct statfs buf;
+  buf0->reset();
+  if (::statfs(basedir.c_str(), &buf) < 0) {
     int r = -errno;
     assert(!m_filestore_fail_eio || r != -EIO);
     assert(r != -ENOENT);
     return r;
   }
+  buf0->blocks = buf.f_blocks;
+  buf0->bsize = buf.f_bsize;
+
+  buf0->allocated = buf.f_bavail;
+
   return 0;
 }
 
index d56113e465b36236b5cf5e586e51ae0f0c08db4c..7bfc8bc60ce5fdd017c8c4d2bbf4b56156786553 100644 (file)
@@ -461,7 +461,7 @@ public:
 
   void collect_metadata(map<string,string> *pm);
 
-  int statfs(struct statfs *buf);
+  int statfs(struct store_statfs_t *buf) override;
 
   int _do_transactions(
     vector<Transaction> &tls, uint64_t op_seq,
index 972ee8e910bd29109d995a2bd4089fba466da31b..26dee754b89dd3857d37af8d12f2859ad7b74014 100644 (file)
@@ -1374,7 +1374,7 @@ void KStore::_sync()
   dout(10) << __func__ << " done" << dendl;
 }
 
-int KStore::statfs(struct statfs *buf)
+int KStore::statfs(struct store_statfs_t* buf)
 {
   return db->get_statfs(buf);
 }
index ffdecf47aa1cc5717e6493334802073ad7af3b86..534bc20e48f5bedc11bce0543c834a840383f7d4 100644 (file)
@@ -424,7 +424,7 @@ public:
     return 0;
   }
 
-  int statfs(struct statfs *buf);
+  int statfs(struct store_statfs_t *buf) override;
 
   using ObjectStore::exists;
   bool exists(const coll_t& cid, const ghobject_t& oid);
index eb06f18592d279be32fc8388f0b185bf4e636cc5..f96d472392854a0c1b66d1df92a3152e2f4cd907 100644 (file)
@@ -220,16 +220,17 @@ int MemStore::mkfs()
   return 0;
 }
 
-int MemStore::statfs(struct statfs *st)
+int MemStore::statfs(struct store_statfs_t *st)
 {
-  dout(10) << __func__ << dendl;
-  st->f_bsize = 4096;
+   dout(10) << __func__ << dendl;
+  st->reset();
+  st->bsize = 4096;
 
-  // Device size is a configured constant
-  st->f_blocks = g_conf->memstore_device_bytes / st->f_bsize;
+   // Device size is a configured constant
+  st->blocks = g_conf->memstore_device_bytes / st->bsize;
 
   dout(10) << __func__ << ": used_bytes: " << used_bytes << "/" << g_conf->memstore_device_bytes << dendl;
-  st->f_bfree = st->f_bavail = MAX((long(st->f_blocks) - long(used_bytes / st->f_bsize)), 0);
+  st->available = MAX((int64_t(st->blocks * st->bsize) - int64_t(used_bytes)), 0);
 
   return 0;
 }
index 545cae21a97d9009cc7be58b586250f3de3b2652..1759932e7fe840d7bb324bbe4eeadb98367c3df9 100644 (file)
@@ -386,7 +386,7 @@ public:
     return false;
   }
 
-  int statfs(struct statfs *buf);
+  int statfs(struct store_statfs_t *buf) override;
 
   bool exists(const coll_t& cid, const ghobject_t& oid) override;
   bool exists(CollectionHandle &c, const ghobject_t& oid) override;
index 1d49665a49b9817ad12cf23e981298bd1ffb070f..968356dfb7f9bc8c891496df566943e710770200 100644 (file)
@@ -767,16 +767,16 @@ void OSDService::update_osd_stat(vector<int>& hb_peers)
   osd->op_tracker.get_age_ms_histogram(&osd_stat.op_queue_age_hist);
 
   // fill in osd stats too
-  struct statfs stbuf;
+  struct store_statfs_t stbuf;
   int r = osd->store->statfs(&stbuf);
   if (r < 0) {
     derr << "statfs() failed: " << cpp_strerror(r) << dendl;
     return;
   }
 
-  uint64_t bytes = stbuf.f_blocks * stbuf.f_bsize;
-  uint64_t used = (stbuf.f_blocks - stbuf.f_bfree) * stbuf.f_bsize;
-  uint64_t avail = stbuf.f_bavail * stbuf.f_bsize;
+  uint64_t bytes = stbuf.blocks * stbuf.bsize;
+  uint64_t used = bytes - stbuf.available;
+  uint64_t avail = stbuf.available;
 
   osd_stat.kb = bytes >> 10;
   osd_stat.kb_used = used >> 10;
@@ -2791,7 +2791,7 @@ int OSD::update_crush_location()
   if (g_conf->osd_crush_initial_weight >= 0) {
     snprintf(weight, sizeof(weight), "%.4lf", g_conf->osd_crush_initial_weight);
   } else {
-    struct statfs st;
+    struct store_statfs_t st;
     int r = store->statfs(&st);
     if (r < 0) {
       derr << "statfs: " << cpp_strerror(r) << dendl;
@@ -2799,7 +2799,7 @@ int OSD::update_crush_location()
     }
     snprintf(weight, sizeof(weight), "%.4lf",
             MAX((double).00001,
-                (double)(st.f_blocks * st.f_bsize) /
+                (double)(st.blocks * st.bsize) /
                 (double)(1ull << 40 /* TB */)));
   }
 
index 3871fccffb868424654fb3ff44a911404841ffc3..0fc62f8143268eec2e0abfef03e5a1062c970419 100644 (file)
@@ -5578,3 +5578,33 @@ void OSDOp::merge_osd_op_vector_out_data(vector<OSDOp>& ops, bufferlist& out)
     }
   }
 }
+
+void store_statfs_t::dump(Formatter *f) const
+{
+  f->dump_int("available", available);
+
+  f->dump_int("blocks", blocks);
+  f->dump_int("bsize", bsize);
+
+  f->dump_int("allocated", allocated);
+  f->dump_int("stored", stored);
+  f->dump_int("compressed", compressed);
+  f->dump_int("compressed_allocated", compressed_allocated);
+  f->dump_int("compressed_original", compressed_original);
+}
+
+ostream& operator<<(ostream& out, const store_statfs_t &s)
+{
+  out << std::hex
+      << " store_statfs(0x" << s.blocks
+      << "*0x"  << s.bsize
+      << "/0x"  << s.available
+      << ", stored 0x" << s.stored
+      << "/0x"  << s.allocated
+      << ", compress 0x" << s.compressed
+      << "/0x"  << s.compressed_allocated
+      << "/0x"  << s.compressed_original
+      << std::dec
+      << ")";
+  return out;
+}
index 28c56c911bb0f0e66291bd6f4f5c0895f9fc2f23..fc274a3e175aa084109c2cda89487e92246a6aad 100644 (file)
@@ -4311,4 +4311,28 @@ struct PromoteCounter {
   }
 };
 
+/** store_statfs_t
++* ObjectStore full statfs information
++*/
+struct store_statfs_t
+{
+  uint64_t available = 0;              // Free blocks available
+
+  uint64_t blocks = 0;                 // Total data blocks
+  uint32_t bsize = 0;                  // Optimal transfer block size
+
+  int64_t allocated = 0;               // Bytes allocated by the store
+  int64_t stored = 0;                  // Bytes actually stored by the user
+  int64_t compressed = 0;              // Bytes stored after compression
+  int64_t compressed_allocated = 0;    // Bytes allocated for compressed data
+  int64_t compressed_original = 0;     // Bytes that were successfully compressed
+
+  void reset() {
+    *this = store_statfs_t();
+  }
+
+  void dump(Formatter *f) const;
+};
+ostream &operator<<(ostream &lhs, const store_statfs_t &rhs);
+
 #endif