From: Igor Fedotov Date: Thu, 9 May 2019 16:23:30 +0000 (+0300) Subject: os/bluestore: protect BlueFS::FileReader::buf X-Git-Tag: v14.2.3~105^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8da82b04df64e91f64be6a1c41e788e7a8dad282;p=ceph.git os/bluestore: protect BlueFS::FileReader::buf 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 (cherry picked from commit 054355934a59bf4c08aa994fbab97a0f96cab31c) --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index d83569dd1b9..43368f7f70a 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -1358,10 +1358,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(len)); @@ -1378,6 +1378,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); @@ -1448,9 +1451,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; @@ -1470,6 +1476,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 diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 12c25ca2387..780b3d2475a 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -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),