From 5723a69ffc9c7bb3811d825c980abda336c92e5e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 21 Sep 2016 16:49:25 -0400 Subject: [PATCH] os/bluestore: add error injection This is used by the teuthology repair_test.py. Signed-off-by: Sage Weil --- src/common/config_opts.h | 1 + src/os/bluestore/BlueStore.cc | 21 +++++++++++++++++++- src/os/bluestore/BlueStore.h | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 470e1d4083c71..cd84e28eb4ddf 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -1018,6 +1018,7 @@ OPTION(bluestore_debug_small_allocations, OPT_INT, 0) OPTION(bluestore_debug_freelist, OPT_BOOL, false) OPTION(bluestore_debug_prefill, OPT_FLOAT, 0) OPTION(bluestore_debug_prefragment_max, OPT_INT, 1048576) +OPTION(bluestore_debug_inject_read_err, OPT_BOOL, false) OPTION(bluestore_inject_wal_apply_delay, OPT_FLOAT, 0) OPTION(bluestore_shard_finishers, OPT_BOOL, false) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 54c415115d68f..59387a1a88eb5 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2200,6 +2200,7 @@ BlueStore::BlueStore(CephContext *cct, const string& path) kv_sync_thread(this), kv_stop(false), logger(NULL), + debug_read_error_lock("BlueStore::debug_read_error_lock"), csum_type(bluestore_blob_t::CSUM_CRC32C), sync_wal_apply(cct->_conf->bluestore_sync_wal_apply) { @@ -4517,7 +4518,12 @@ int BlueStore::stat( c->cache->trim( g_conf->bluestore_onode_cache_size, g_conf->bluestore_buffer_cache_size); - return 0; + int r = 0; + if (_debug_mdata_eio(oid)) { + r = -EIO; + derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; + } + return r; } int BlueStore::read( @@ -4574,6 +4580,10 @@ int BlueStore::read( c->cache->trim( g_conf->bluestore_onode_cache_size, g_conf->bluestore_buffer_cache_size); + if (r == 0 && _debug_data_eio(oid)) { + r = -EIO; + derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; + } dout(10) << __func__ << " " << cid << " " << oid << " 0x" << std::hex << offset << "~" << length << std::dec << " = " << r << dendl; @@ -5020,6 +5030,10 @@ int BlueStore::getattr( c->cache->trim( g_conf->bluestore_onode_cache_size, g_conf->bluestore_buffer_cache_size); + if (r == 0 && _debug_mdata_eio(oid)) { + r = -EIO; + derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; + } dout(10) << __func__ << " " << c->cid << " " << oid << " " << name << " = " << r << dendl; return r; @@ -5064,6 +5078,10 @@ int BlueStore::getattrs( c->cache->trim( g_conf->bluestore_onode_cache_size, g_conf->bluestore_buffer_cache_size); + if (r == 0 && _debug_mdata_eio(oid)) { + r = -EIO; + derr << __func__ << " " << c->cid << " " << oid << " INJECT EIO" << dendl; + } dout(10) << __func__ << " " << c->cid << " " << oid << " = " << r << dendl; return r; @@ -7691,6 +7709,7 @@ int BlueStore::_do_remove( txc->t->rmkey(PREFIX_OBJ, s.key); } txc->t->rmkey(PREFIX_OBJ, o->key); + _debug_obj_on_delete(o->oid); return 0; } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index a734c023d7beb..6e3a0836e1ee2 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1324,6 +1324,10 @@ class BlueStore : public ObjectStore, std::mutex reap_lock; list removed_collections; + RWLock debug_read_error_lock; + set debug_data_error_objects; + set debug_mdata_error_objects; + int csum_type; uint64_t block_size; ///< block size of block device (power of 2) @@ -1663,6 +1667,38 @@ class BlueStore : public ObjectStore, TrackedOpRef op = TrackedOpRef(), ThreadPool::TPHandle *handle = NULL) override; + // error injection + void inject_data_error(const ghobject_t& o) override { + RWLock::WLocker l(debug_read_error_lock); + debug_data_error_objects.insert(o); + } + void inject_mdata_error(const ghobject_t& o) override { + RWLock::WLocker l(debug_read_error_lock); + debug_mdata_error_objects.insert(o); + } +private: + bool _debug_data_eio(const ghobject_t& o) { + if (!g_conf->bluestore_debug_inject_read_err) { + return false; + } + RWLock::RLocker l(debug_read_error_lock); + return debug_data_error_objects.count(o); + } + bool _debug_mdata_eio(const ghobject_t& o) { + if (!g_conf->bluestore_debug_inject_read_err) { + return false; + } + RWLock::RLocker l(debug_read_error_lock); + return debug_mdata_error_objects.count(o); + } + void _debug_obj_on_delete(const ghobject_t& o) { + if (g_conf->bluestore_debug_inject_read_err) { + RWLock::WLocker l(debug_read_error_lock); + debug_data_error_objects.erase(o); + debug_mdata_error_objects.erase(o); + } + } + private: // --------------------------------------------------------