]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: protect BlueFS::FileReader::buf 27782/head
authorIgor Fedotov <ifedotov@suse.com>
Thu, 9 May 2019 16:23:30 +0000 (19:23 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Thu, 9 May 2019 16:26:29 +0000 (19:26 +0300)
Now this buffer might be accessed from BlueRocksRandomAccessFile
which is intended for multi-threading access. Hence we need a
proper protection for the buffer.

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index 35d6c3bafca00089c9d95d2148d534741d0af78f..d8587c8d2cb8a559c4833862be4fd2abe67b7bc6 100644 (file)
@@ -1378,10 +1378,10 @@ int BlueFS::_read_random(
   logger->inc(l_bluefs_read_random_count, 1);
   logger->inc(l_bluefs_read_random_bytes, len);
 
-
+  std::shared_lock s_lock(h->lock);
   while (len > 0) {
     if (off < buf->bl_off || off >= buf->get_buf_end()) {
-
+      s_lock.unlock();
       uint64_t x_off = 0;
       auto p = h->file->fnode.seek(off, &x_off);
       uint64_t l = std::min(p->length - x_off, static_cast<uint64_t>(len));
@@ -1398,6 +1398,9 @@ int BlueFS::_read_random(
 
       logger->inc(l_bluefs_read_random_disk_count, 1);
       logger->inc(l_bluefs_read_random_disk_bytes, l);
+      if (len > 0) {
+       s_lock.lock();
+      }
     } else {
       auto left = buf->get_buf_remaining(off);
       int r = std::min(len, left);
@@ -1468,9 +1471,12 @@ int BlueFS::_read(
     outbl->clear();
 
   int ret = 0;
+  std::shared_lock s_lock(h->lock);
   while (len > 0) {
     size_t left;
     if (off < buf->bl_off || off >= buf->get_buf_end()) {
+      s_lock.unlock();
+      std::unique_lock u_lock(h->lock);
       buf->bl.clear();
       buf->bl_off = off & super.block_mask();
       uint64_t x_off = 0;
@@ -1490,6 +1496,8 @@ int BlueFS::_read(
       int r = bdev[p->bdev]->read(p->offset + x_off, l, &buf->bl, ioc[p->bdev],
                                  cct->_conf->bluefs_buffered_io);
       ceph_assert(r == 0);
+      u_lock.unlock();
+      s_lock.lock();
     }
     left = buf->get_buf_remaining(off);
     dout(20) << __func__ << " left 0x" << std::hex << left
index 12c25ca238737481176f562f8f25386193d41283..780b3d2475a54bc4bee93d4482f790bf03de4d72 100644 (file)
@@ -231,6 +231,11 @@ public:
     bool random;
     bool ignore_eof;        ///< used when reading our log file
 
+    ceph::shared_mutex lock {
+     ceph::make_shared_mutex(std::string(), false, false, false)
+    };
+
+
     FileReader(FileRef f, uint64_t mpf, bool rand, bool ie)
       : file(f),
        buf(mpf),