Skip to content

Commit

Permalink
os/bluestore: add error injection
Browse files Browse the repository at this point in the history
This is used by the teuthology repair_test.py.

Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Sep 21, 2016
1 parent 7ba8d71 commit 5723a69
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/common/config_opts.h
Expand Up @@ -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)

Expand Down
21 changes: 20 additions & 1 deletion src/os/bluestore/BlueStore.cc
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
36 changes: 36 additions & 0 deletions src/os/bluestore/BlueStore.h
Expand Up @@ -1324,6 +1324,10 @@ class BlueStore : public ObjectStore,
std::mutex reap_lock;
list<CollectionRef> removed_collections;

RWLock debug_read_error_lock;
set<ghobject_t, ghobject_t::BitwiseComparator> debug_data_error_objects;
set<ghobject_t, ghobject_t::BitwiseComparator> debug_mdata_error_objects;

int csum_type;

uint64_t block_size; ///< block size of block device (power of 2)
Expand Down Expand Up @@ -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:

// --------------------------------------------------------
Expand Down

0 comments on commit 5723a69

Please sign in to comment.