From: Sage Weil Date: Mon, 4 Jan 2016 18:42:51 +0000 (-0500) Subject: os/bluestore/BlueFS: read_random X-Git-Tag: v10.0.3~88^2~23 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9a67fbb3e213e2c9b2c18ec68502173fab6bea48;p=ceph.git os/bluestore/BlueFS: read_random Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 09320a22c47a..60032ffbe376 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -608,6 +608,51 @@ void BlueFS::_drop_link(FileRef file) } } +int BlueFS::_read_random( + FileReader *h, ///< [in] read from here + uint64_t off, ///< [in] offset + size_t len, ///< [in] this many bytes + char *out) ///< [out] optional: or copy it here +{ + dout(10) << __func__ << " h " << h << " " << off << "~" << len + << " from " << h->file->fnode << dendl; + + h->file->num_reading.inc(); + + if (!h->ignore_eof && + off + len > h->file->fnode.size) { + if (off > h->file->fnode.size) + len = 0; + else + len = h->file->fnode.size - off; + dout(20) << __func__ << " reaching (or past) eof, len clipped to " + << len << dendl; + } + + int ret = 0; + while (len > 0) { + uint64_t x_off = 0; + vector::iterator p = h->file->fnode.seek(off, &x_off); + uint64_t l = MIN(p->length - x_off, len); + if (!h->ignore_eof && + off + l > h->file->fnode.size) { + l = h->file->fnode.size - off; + } + dout(20) << __func__ << " read buffered " << x_off << "~" << l << " of " + << *p << dendl; + int r = bdev[p->bdev]->read_buffered(p->offset + x_off, l, out); + assert(r == 0); + off += l; + len -= l; + ret += l; + out += l; + } + + dout(20) << __func__ << " got " << ret << dendl; + h->file->num_reading.dec(); + return ret; +} + int BlueFS::_read( FileReader *h, ///< [in] read from here FileReaderBuffer *buf, ///< [in] reader state diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 5fb703964e8b..10d1ce000931 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -215,6 +215,11 @@ private: size_t len, ///< [in] this many bytes bufferlist *outbl, ///< [out] optional: reference the result here char *out); ///< [out] optional: or copy it here + int _read_random( + FileReader *h, ///< [in] read from here + uint64_t offset, ///< [in] offset + size_t len, ///< [in] this many bytes + char *out); ///< [out] optional: or copy it here void _invalidate_cache(FileRef f, uint64_t offset, uint64_t length); @@ -318,6 +323,13 @@ public: Mutex::Locker l(lock); return _read(h, buf, offset, len, outbl, out); } + int read_random(FileReader *h, uint64_t offset, size_t len, + char *out) { + // no need to hold the global lock here; we only touch h and + // h->file, and read vs write or delete is already protected (via + // atomics and asserts). + return _read_random(h, offset, len, out); + } void invalidate_cache(FileRef f, uint64_t offset, uint64_t len) { Mutex::Locker l(lock); _invalidate_cache(f, offset, len); diff --git a/src/os/bluestore/BlueRocksEnv.cc b/src/os/bluestore/BlueRocksEnv.cc index 857472fa9391..252bdbd12a40 100644 --- a/src/os/bluestore/BlueRocksEnv.cc +++ b/src/os/bluestore/BlueRocksEnv.cc @@ -91,9 +91,8 @@ class BlueRocksRandomAccessFile : public rocksdb::RandomAccessFile { // Safe for concurrent use by multiple threads. rocksdb::Status Read(uint64_t offset, size_t n, rocksdb::Slice* result, char* scratch) const { - BlueFS::FileReaderBuffer buf(4096); - int r = fs->read(h, &buf, offset, n, NULL, scratch); - assert (r >= 0); + int r = fs->read_random(h, offset, n, scratch); + assert(r >= 0); *result = rocksdb::Slice(scratch, r); return rocksdb::Status::OK(); } diff --git a/src/os/bluestore/bluefs_types.cc b/src/os/bluestore/bluefs_types.cc index 5994b4be21f5..8b8a326781aa 100644 --- a/src/os/bluestore/bluefs_types.cc +++ b/src/os/bluestore/bluefs_types.cc @@ -109,10 +109,10 @@ vector::iterator bluefs_fnode_t::seek( offset -= p->length; ++p; } else { - *x_off = offset; break; } } + *x_off = offset; return p; }