Skip to content

Commit

Permalink
Merge pull request #10970 from xiexingguo/xxg-wip-honour-alloweio-flag
Browse files Browse the repository at this point in the history
os/bluestore: honour allow-eio flag; use global compressor if possible

Reviewed-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Sep 6, 2016
2 parents 9a95536 + f6bea31 commit e6a39ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
38 changes: 28 additions & 10 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -3697,6 +3697,7 @@ int BlueStore::read(
}

out:
assert(allow_eio || r != -EIO);
c->cache->trim(
g_conf->bluestore_onode_cache_size,
g_conf->bluestore_buffer_cache_size);
Expand Down Expand Up @@ -3847,14 +3848,19 @@ int BlueStore::_do_read(
if (bptr->get_blob().has_flag(bluestore_blob_t::FLAG_COMPRESSED)) {
bufferlist compressed_bl, raw_bl;
IOContext ioc(NULL); // FIXME?
bptr->get_blob().map(
r = bptr->get_blob().map(
0, bptr->get_blob().get_ondisk_length(),
[&](uint64_t offset, uint64_t length) {
bufferlist t;
int r = bdev->read(offset, length, &t, &ioc, false);
assert(r == 0);
if (r < 0)
return r;
compressed_bl.claim_append(t);
return 0;
});
if (r < 0)
return r;

if (_verify_csum(o, &bptr->get_blob(), 0, compressed_bl) < 0) {
return -EIO;
}
Expand Down Expand Up @@ -3893,14 +3899,19 @@ int BlueStore::_do_read(
// read it
IOContext ioc(NULL); // FIXME?
bufferlist bl;
bptr->get_blob().map(r_off, r_len,
r = bptr->get_blob().map(r_off, r_len,
[&](uint64_t offset, uint64_t length) {
bufferlist t;
int r = bdev->read(offset, length, &t, &ioc, false);
assert(r == 0);
if (r < 0)
return r;
bl.claim_append(t);
return 0;
});
int r = _verify_csum(o, &bptr->get_blob(), r_off, bl);
if (r < 0)
return r;

r = _verify_csum(o, &bptr->get_blob(), r_off, bl);
if (r < 0) {
return -EIO;
}
Expand Down Expand Up @@ -3958,12 +3969,14 @@ int BlueStore::_verify_csum(OnodeRef& o,
if (r < 0) {
if (r == -1) {
vector<bluestore_pextent_t> pex;
blob->map(
int r = blob->map(
bad,
blob->get_csum_chunk_size(),
[&](uint64_t offset, uint64_t length) {
pex.emplace_back(bluestore_pextent_t(offset, length));
return 0;
});
assert(r == 0);
derr << __func__ << " bad " << blob->get_csum_type_string(blob->csum_type)
<< "/0x" << std::hex << blob->get_csum_chunk_size()
<< " checksum at blob offset 0x" << bad
Expand All @@ -3988,14 +4001,17 @@ int BlueStore::_decompress(bufferlist& source, bufferlist* result)
bluestore_compression_header_t chdr;
::decode(chdr, i);
string name = bluestore_blob_t::get_comp_alg_name(chdr.type);
CompressorRef compressor = Compressor::create(cct, name);
if (!compressor.get()) {
CompressorRef cp = compressor;
if (!cp || cp->get_type() != name)
cp = Compressor::create(cct, name);

if (!cp.get()) {
// if compressor isn't available - error, because cannot return
// decompressed data?
derr << __func__ << " can't load decompressor " << chdr.type << dendl;
r = -EIO;
} else {
r = compressor->decompress(i, chdr.length, *result);
r = cp->decompress(i, chdr.length, *result);
if (r < 0) {
derr << __func__ << " decompression failed with exit code " << r << dendl;
r = -EIO;
Expand Down Expand Up @@ -6167,11 +6183,13 @@ void BlueStore::_do_write_small(
_buffer_cache_write(txc, b, b_off, padded,
wctx->buffered ? 0 : Buffer::FLAG_NOCACHE);

b->get_blob().map(
int r = b->get_blob().map(
b_off, b_len,
[&](uint64_t offset, uint64_t length) {
op->extents.emplace_back(bluestore_pextent_t(offset, length));
return 0;
});
assert(r == 0);
if (b->get_blob().csum_type) {
txc->add_deferred_csum(o, blob, b_off, padded);
}
Expand Down
9 changes: 6 additions & 3 deletions src/os/bluestore/bluestore_types.h
Expand Up @@ -458,8 +458,8 @@ struct bluestore_blob_t {
uint64_t offset, uint64_t length, uint64_t min_alloc_size,
vector<bluestore_pextent_t> *r);

void map(uint64_t x_off, uint64_t x_len,
std::function<void(uint64_t,uint64_t)> f) const {
int map(uint64_t x_off, uint64_t x_len,
std::function<int(uint64_t,uint64_t)> f) const {
auto p = extents.begin();
assert(p != extents.end());
while (x_off >= p->length) {
Expand All @@ -470,11 +470,14 @@ struct bluestore_blob_t {
while (x_len > 0) {
assert(p != extents.end());
uint64_t l = MIN(p->length - x_off, x_len);
f(p->offset + x_off, l);
int r = f(p->offset + x_off, l);
if (r < 0)
return r;
x_off = 0;
x_len -= l;
++p;
}
return 0;
}
void map_bl(uint64_t x_off,
bufferlist& bl,
Expand Down

0 comments on commit e6a39ae

Please sign in to comment.