From 181e28ba999c4134957f04183bad5c4dfc0e7062 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 28 Oct 2016 06:34:22 -0500 Subject: [PATCH] os: add fsck deep/shallow option deep==false checks just metadata, and deep==true will (eventually) check all data (and checksums) too. Signed-off-by: Sage Weil --- src/common/config_opts.h | 4 ++++ src/os/ObjectStore.h | 2 +- src/os/bluestore/BlueStore.cc | 24 +++++++++++++----------- src/os/bluestore/BlueStore.h | 5 +++-- src/os/kstore/KStore.cc | 4 ++-- src/os/kstore/KStore.h | 2 +- src/test/objectstore/store_test.cc | 8 +++++--- src/tools/ceph_objectstore_tool.cc | 15 ++++++++++++++- 8 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 4b1fa42d3cb..2cf5080d914 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -1009,8 +1009,11 @@ OPTION(bluestore_bitmapallocator_blocks_per_zone, OPT_INT, 1024) // must be powe OPTION(bluestore_bitmapallocator_span_size, OPT_INT, 1024) // must be power of 2 aligned, e.g., 512, 1024, 2048... OPTION(bluestore_rocksdb_options, OPT_STR, "compression=kNoCompression,max_write_buffer_number=4,min_write_buffer_number_to_merge=1,recycle_log_file_num=4,write_buffer_size=268435456") OPTION(bluestore_fsck_on_mount, OPT_BOOL, false) +OPTION(bluestore_fsck_on_mount_deep, OPT_BOOL, true) OPTION(bluestore_fsck_on_umount, OPT_BOOL, false) +OPTION(bluestore_fsck_on_umount_deep, OPT_BOOL, true) OPTION(bluestore_fsck_on_mkfs, OPT_BOOL, true) +OPTION(bluestore_fsck_on_mkfs_deep, OPT_BOOL, false) OPTION(bluestore_sync_submit_transaction, OPT_BOOL, true) // submit kv txn in queueing thread (not kv_sync_thread) OPTION(bluestore_sync_wal_apply, OPT_BOOL, true) // perform initial wal work synchronously (possibly in combination with aio so we only *queue* ios) OPTION(bluestore_wal_threads, OPT_INT, 4) @@ -1041,6 +1044,7 @@ OPTION(kstore_max_bytes, OPT_U64, 64*1024*1024) OPTION(kstore_backend, OPT_STR, "rocksdb") OPTION(kstore_rocksdb_options, OPT_STR, "compression=kNoCompression") OPTION(kstore_fsck_on_mount, OPT_BOOL, false) +OPTION(kstore_fsck_on_mount_deep, OPT_BOOL, true) OPTION(kstore_nid_prealloc, OPT_U64, 1024) OPTION(kstore_sync_transaction, OPT_BOOL, false) OPTION(kstore_sync_submit_transaction, OPT_BOOL, false) diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index c04e63eb625..67d0a73894f 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1879,7 +1879,7 @@ public: virtual bool test_mount_in_use() = 0; virtual int mount() = 0; virtual int umount() = 0; - virtual int fsck() { + virtual int fsck(bool deep) { return -EOPNOTSUPP; } diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index ca54224049e..53f3047b02a 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -3748,7 +3748,7 @@ int BlueStore::mkfs() if (r == 0) { dout(1) << __func__ << " already created" << dendl; if (g_conf->bluestore_fsck_on_mkfs) { - r = fsck(); + r = fsck(g_conf->bluestore_fsck_on_mkfs_deep); if (r < 0) { derr << __func__ << " fsck found fatal error: " << cpp_strerror(r) << dendl; @@ -3912,7 +3912,7 @@ int BlueStore::mkfs() if (r == 0 && g_conf->bluestore_fsck_on_mkfs) { - int rc = fsck(); + int rc = fsck(g_conf->bluestore_fsck_on_mkfs_deep); if (rc < 0) return rc; if (rc > 0) { @@ -3954,7 +3954,7 @@ int BlueStore::mount() } if (g_conf->bluestore_fsck_on_mount) { - int rc = fsck(); + int rc = fsck(g_conf->bluestore_fsck_on_mount_deep); if (rc < 0) return rc; if (rc > 0) { @@ -4085,7 +4085,7 @@ int BlueStore::umount() _close_path(); if (g_conf->bluestore_fsck_on_umount) { - int rc = fsck(); + int rc = fsck(g_conf->bluestore_fsck_on_umount_deep); if (rc < 0) return rc; if (rc > 0) { @@ -4115,7 +4115,8 @@ int BlueStore::_fsck_check_extents( const vector& extents, bool compressed, boost::dynamic_bitset<> &used_blocks, - store_statfs_t& expected_statfs) + store_statfs_t& expected_statfs, + bool deep) { dout(30) << __func__ << " oid " << oid << " extents " << extents << dendl; int errors = 0; @@ -4149,9 +4150,9 @@ int BlueStore::_fsck_check_extents( return errors; } -int BlueStore::fsck() +int BlueStore::fsck(bool deep) { - dout(1) << __func__ << " start" << dendl; + dout(1) << __func__ << (deep ? " (deep)" : " (shallow)") << " start" << dendl; int errors = 0; set used_nids; set used_omap_head; @@ -4421,7 +4422,8 @@ int BlueStore::fsck() errors += _fsck_check_extents(oid, blob.extents, blob.is_compressed(), used_blocks, - expected_statfs); + expected_statfs, + deep); } } // omap @@ -4472,9 +4474,9 @@ int BlueStore::fsck() extents.emplace_back(bluestore_pextent_t(r.first, r.second.length)); } errors += _fsck_check_extents(p->second.oids.front(), - extents, - p->second.compressed, - used_blocks, expected_statfs); + extents, + p->second.compressed, + used_blocks, expected_statfs, deep); sb_info.erase(p); } } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 12ad2d007a7..97542c0f6ee 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1581,7 +1581,8 @@ private: const vector& extents, bool compressed, boost::dynamic_bitset<> &used_blocks, - store_statfs_t& expected_statfs); + store_statfs_t& expected_statfs, + bool deep); void _buffer_cache_write( TransContext *txc, @@ -1625,7 +1626,7 @@ public: int umount() override; void _sync(); - int fsck() override; + int fsck(bool deep) override; void set_cache_shards(unsigned num) override; diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index c74f04d08aa..ed10be43fc1 100755 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -973,7 +973,7 @@ int KStore::mount() dout(1) << __func__ << " path " << path << dendl; if (g_conf->kstore_fsck_on_mount) { - int rc = fsck(); + int rc = fsck(g_conf->kstore_fsck_on_mount_deep); if (rc < 0) return rc; } @@ -1044,7 +1044,7 @@ int KStore::umount() return 0; } -int KStore::fsck() +int KStore::fsck(bool deep) { dout(1) << __func__ << dendl; int errors = 0; diff --git a/src/os/kstore/KStore.h b/src/os/kstore/KStore.h index eeccf972753..8bb76178347 100644 --- a/src/os/kstore/KStore.h +++ b/src/os/kstore/KStore.h @@ -416,7 +416,7 @@ public: int umount(); void _sync(); - int fsck(); + int fsck(bool deep) override; int validate_hobject_key(const hobject_t &obj) const override { diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index a293f0476f6..d615355fc3d 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -4066,13 +4066,13 @@ public: return status; } - void fsck() { + void fsck(bool deep) { Mutex::Locker locker(lock); EnterExit ee("fsck"); while (in_flight) cond.Wait(lock); store->umount(); - store->fsck(); + store->fsck(deep); store->mount(); } @@ -4250,7 +4250,9 @@ void doSyntheticTest(boost::scoped_ptr& store, boost::uniform_int<> true_false(0, 999); int val = true_false(rng); if (val > 998) { - test_obj.fsck(); + test_obj.fsck(true); + } else if (val > 997) { + test_obj.fsck(false); } else if (val > 970) { test_obj.scan(); } else if (val > 950) { diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 93ee8908157..c25b5218c41 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -2595,7 +2595,20 @@ int main(int argc, char **argv) } if (op == "fsck") { - int r = fs->fsck(); + int r = fs->fsck(false); + if (r < 0) { + cerr << "fsck failed: " << cpp_strerror(r) << std::endl; + myexit(1); + } + if (r > 0) { + cerr << "fsck found " << r << " errors" << std::endl; + myexit(1); + } + cout << "fsck found no errors" << std::endl; + exit(0); + } + if (op == "fsck-deep") { + int r = fs->fsck(true); if (r < 0) { cerr << "fsck failed: " << cpp_strerror(r) << std::endl; myexit(1); -- 2.39.5