}
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;
}
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;
}
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) { }
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;
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;
}
}
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;
}
}
-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;
}
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,
dout(10) << __func__ << " done" << dendl;
}
-int KStore::statfs(struct statfs *buf)
+int KStore::statfs(struct store_statfs_t* buf)
{
return db->get_statfs(buf);
}
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);
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;
}
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;
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;
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;
}
snprintf(weight, sizeof(weight), "%.4lf",
MAX((double).00001,
- (double)(st.f_blocks * st.f_bsize) /
+ (double)(st.blocks * st.bsize) /
(double)(1ull << 40 /* TB */)));
}
}
}
}
+
+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;
+}
}
};
+/** 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