]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlueFS: read_random
authorSage Weil <sage@redhat.com>
Mon, 4 Jan 2016 18:42:51 +0000 (13:42 -0500)
committerSage Weil <sage@redhat.com>
Fri, 8 Jan 2016 18:10:18 +0000 (13:10 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h
src/os/bluestore/BlueRocksEnv.cc
src/os/bluestore/bluefs_types.cc

index 09320a22c47a2b1addec481842d6074a9a66aee7..60032ffbe376ab927db3e570954760fb4202313d 100644 (file)
@@ -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<bluefs_extent_t>::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
index 5fb703964e8b4d0ba464b5ba362c129262777a09..10d1ce000931ca2c4630c87da97829b26b9451b5 100644 (file)
@@ -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);
index 857472fa939180391e8d815144ddfb126d113fbf..252bdbd12a40c0dac2c8bfd53d1a3018a8af60a2 100644 (file)
@@ -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();
   }
index 5994b4be21f56b88dddb1f7a18f11c55ba4461f6..8b8a326781aab5cebd7f2e49f254622ae966b089 100644 (file)
@@ -109,10 +109,10 @@ vector<bluefs_extent_t>::iterator bluefs_fnode_t::seek(
       offset -= p->length;
       ++p;
     } else {
-      *x_off = offset;
       break;
     }
   }
+  *x_off = offset;
   return p;
 }