From ad3d2e542f0b4a981f5e422708755f2bd0554d99 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Wed, 6 Dec 2017 20:01:41 +0300 Subject: [PATCH] os: extend ObjectStore interface with per-pool statistics access method Signed-off-by: Igor Fedotov --- src/os/ObjectStore.h | 1 + src/os/bluestore/BlueStore.cc | 46 +++++++++++++++++++++++++---------- src/os/bluestore/BlueStore.h | 1 + src/os/filestore/FileStore.cc | 4 +++ src/os/filestore/FileStore.h | 1 + src/os/kstore/KStore.cc | 6 ++++- src/os/kstore/KStore.h | 1 + src/os/memstore/MemStore.cc | 5 ++++ src/os/memstore/MemStore.h | 1 + 9 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 9810c9630aa..7cb53adf448 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1551,6 +1551,7 @@ public: } virtual int statfs(struct store_statfs_t *buf) = 0; + virtual int pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) = 0; virtual void collect_metadata(map *pm) { } diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 960b668c526..1494af6f2bf 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7608,6 +7608,14 @@ int BlueStore::statfs(struct store_statfs_t *buf) if (shared_available > 0) { bfree += shared_available; } + // include dedicated db, too, if that isn't the shared device. + if (bluefs_shared_bdev != BlueFS::BDEV_DB) { + buf->total += bluefs->get_total(BlueFS::BDEV_DB); + } + // call any non-omap bluefs space "internal metadata" + buf->internal_metadata = + std::max(bluefs->get_used(), (uint64_t)cct->_conf->bluestore_bluefs_min) + - buf->omap_allocated; } { @@ -7629,23 +7637,34 @@ int BlueStore::statfs(struct store_statfs_t *buf) buf->allocated = thin_total - thin_avail; } else { - buf->total = bdev->get_size(); + buf->total += bdev->get_size(); } - buf->available += bfree; + buf->available = bfree; - if (bluefs) { - // include dedicated db, too, if that isn't the shared device. - if (bluefs_shared_bdev != BlueFS::BDEV_DB) { - buf->total += bluefs->get_total(BlueFS::BDEV_DB); - } + dout(20) << __func__ << " " << *buf << dendl; + return 0; +} - // call any non-omap bluefs space "internal metadata" - buf->internal_metadata = - std::max(bluefs->get_used(), (uint64_t)cct->_conf->bluestore_bluefs_min) - - buf->omap_allocated; +int BlueStore::pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) +{ + dout(20) << __func__ << " pool " << pool_id<< dendl; + if (!per_pool_stat_collection) { + dout(20) << __func__ << " not supported in a legacy mode " << dendl; + return -ENOTSUP; } + buf->reset(); - dout(20) << __func__ << " " << *buf << dendl; + { + std::lock_guard l(vstatfs_lock); + auto& pool_stat = osd_pools[pool_id]; + buf->allocated = pool_stat.allocated(); + buf->data_stored = pool_stat.stored(); + buf->data_compressed = pool_stat.compressed(); + buf->data_compressed_original = pool_stat.compressed_original(); + buf->data_compressed_allocated = pool_stat.compressed_allocated(); + } + + dout(20) << __func__ << *buf << dendl; return 0; } @@ -10472,7 +10491,6 @@ void BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) for (vector::iterator p = i.colls.begin(); p != i.colls.end(); ++p, ++j) { cvec[j] = _get_collection(*p); - } vector ovec(i.objects.size()); @@ -10488,6 +10506,7 @@ void BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) // collection operations CollectionRef &c = cvec[op->cid]; + // initialize osd_pool_id and do a smoke test that all collections belong // to the same pool spg_t pgid; @@ -10496,6 +10515,7 @@ void BlueStore::_txc_add_transaction(TransContext *txc, Transaction *t) txc->osd_pool_id == (int64_t)pgid.pool()); txc->osd_pool_id = (int64_t)pgid.pool(); } + switch (op->op) { case Transaction::OP_RMCOLL: { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 511da1390a3..4f89ceeae76 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2410,6 +2410,7 @@ public: public: int statfs(struct store_statfs_t *buf) override; + int pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) override; void collect_metadata(map *pm) override; diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index bb32cc33fcb..211b26fc09f 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -778,6 +778,10 @@ int FileStore::statfs(struct store_statfs_t *buf0) return 0; } +int FileStore::pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) +{ + return -ENOTSUP; +} void FileStore::new_journal() { diff --git a/src/os/filestore/FileStore.h b/src/os/filestore/FileStore.h index 50343607c7f..0687fcd5c50 100644 --- a/src/os/filestore/FileStore.h +++ b/src/os/filestore/FileStore.h @@ -518,6 +518,7 @@ public: int get_devices(set *ls) override; int statfs(struct store_statfs_t *buf) override; + int pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) override; int _do_transactions( vector &tls, uint64_t op_seq, diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index 616ca1b6a25..39071f481d3 100644 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -1099,7 +1099,6 @@ int KStore::statfs(struct store_statfs_t* buf0) return 0; } - ObjectStore::CollectionHandle KStore::open_collection(const coll_t& cid) { return _get_collection(cid); @@ -1113,6 +1112,11 @@ ObjectStore::CollectionHandle KStore::create_new_collection(const coll_t& cid) return c; } +int KStore::pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) +{ + return -ENOTSUP; +} + // --------------- // cache diff --git a/src/os/kstore/KStore.h b/src/os/kstore/KStore.h index 3ac7d2dd88e..01abaa0b375 100644 --- a/src/os/kstore/KStore.h +++ b/src/os/kstore/KStore.h @@ -440,6 +440,7 @@ public: db->get_statistics(f); } int statfs(struct store_statfs_t *buf) override; + int pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) override; CollectionHandle open_collection(const coll_t& c) override; CollectionHandle create_new_collection(const coll_t& c) override; diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index f3a7e39abbb..d37f7c7ef61 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -231,6 +231,11 @@ int MemStore::statfs(struct store_statfs_t *st) return 0; } +int MemStore::pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) +{ + return -ENOTSUP; +} + objectstore_perf_stat_t MemStore::get_cur_stats() { // fixme diff --git a/src/os/memstore/MemStore.h b/src/os/memstore/MemStore.h index 5c716138ec1..77b2a32c6e7 100644 --- a/src/os/memstore/MemStore.h +++ b/src/os/memstore/MemStore.h @@ -291,6 +291,7 @@ public: } int statfs(struct store_statfs_t *buf) override; + int pool_statfs(uint64_t pool_id, struct store_statfs_t *buf) override; bool exists(CollectionHandle &c, const ghobject_t& oid) override; int stat(CollectionHandle &c, const ghobject_t& oid, -- 2.39.5