]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: send all old bluefs IOContexts for reap by bdev
authorSage Weil <sage@redhat.com>
Mon, 4 Jan 2016 16:11:53 +0000 (11:11 -0500)
committerSage Weil <sage@redhat.com>
Fri, 8 Jan 2016 18:10:17 +0000 (13:10 -0500)
Doing it in the aio thread ensures that there isn't a use-after-free.
Note that this is only bluefs written files.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlockDevice.cc
src/os/bluestore/BlockDevice.h
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index 073a02cdc479950bb4d732758edb754a65660110..1d7656b49ee12b745dc39f2424ce159c5ecd1ad4 100644 (file)
@@ -45,6 +45,7 @@ BlockDevice::BlockDevice(aio_callback_t cb, void *cbpriv)
     size(0), block_size(0),
     fs(NULL), aio(false), dio(false),
     debug_lock("BlockDevice::debug_lock"),
+    ioc_reap_lock("BlockDevice::ioc_reap_lock"),
     aio_queue(g_conf->bdev_aio_max_queue_depth),
     aio_callback(cb),
     aio_callback_priv(cbpriv),
@@ -247,6 +248,15 @@ void BlockDevice::_aio_thread()
        }
       }
     }
+    if (ioc_reap_count.read()) {
+      Mutex::Locker l(ioc_reap_lock);
+      for (auto p : ioc_reap_queue) {
+       dout(20) << __func__ << " reap ioc " << p << dendl;
+       delete p;
+      }
+      ioc_reap_queue.clear();
+      ioc_reap_count.dec();
+    }
   }
   dout(10) << __func__ << " end" << dendl;
 }
@@ -477,3 +487,11 @@ int BlockDevice::invalidate_cache(uint64_t off, uint64_t len)
   }
   return r;
 }
+
+void BlockDevice::queue_reap_ioc(IOContext *ioc)
+{
+  Mutex::Locker l(ioc_reap_lock);
+  if (ioc_reap_count.read() == 0)
+    ioc_reap_count.inc();
+  ioc_reap_queue.push_back(ioc);
+}
index 83c55b50bee010c7850681db00e3825cf385a243..187a7f57fe59ed10153b4c6657b48d3a51450c74 100644 (file)
@@ -55,6 +55,10 @@ private:
   Mutex debug_lock;
   interval_set<uint64_t> debug_inflight;
 
+  Mutex ioc_reap_lock;
+  vector<IOContext*> ioc_reap_queue;
+  atomic_t ioc_reap_count;
+
   FS::aio_queue_t aio_queue;
   aio_callback_t aio_callback;
   void *aio_callback_priv;
@@ -101,6 +105,8 @@ public:
               IOContext *ioc);
   int flush();
 
+  void queue_reap_ioc(IOContext *ioc);
+
   // for managing buffered readers/writers
   int invalidate_cache(uint64_t off, uint64_t len);
   int open(string path);
index 159fd46a921abcc4d3d14c55049106ecbcaa34b8..2d24c283d49e215d568b120c46dddeddbba940e0 100644 (file)
@@ -256,11 +256,6 @@ void BlueFS::umount()
 
   _close_writer(log_writer);
   log_writer = NULL;
-  // manually clean up it's iocs
-  for (auto p : ioc_reap_queue) {
-    delete p;
-  }
-  ioc_reap_queue.clear();
 
   block_all.clear();
   _stop_alloc();
@@ -1147,8 +1142,6 @@ void BlueFS::sync_metadata()
   }
   dout(10) << __func__ << dendl;
   utime_t start = ceph_clock_now(NULL);
-  vector<IOContext*> iocv;
-  iocv.swap(ioc_reap_queue);
   for (auto p : alloc) {
     p->commit_start();
   }
@@ -1156,9 +1149,6 @@ void BlueFS::sync_metadata()
   for (auto p : alloc) {
     p->commit_finish();
   }
-  for (auto p : iocv) {
-    delete p;
-  }
   utime_t end = ceph_clock_now(NULL);
   utime_t dur = end - start;
   dout(10) << __func__ << " done in " << dur << dendl;
@@ -1244,12 +1234,8 @@ int BlueFS::open_for_write(
 void BlueFS::_close_writer(FileWriter *h)
 {
   dout(10) << __func__ << " " << h << dendl;
-  for (auto i : h->iocv) {
-    if (i->has_aios()) {
-      ioc_reap_queue.push_back(i);
-    } else {
-      delete i;
-    }
+  for (unsigned i=0; i<bdev.size(); ++i) {
+    bdev[i]->queue_reap_ioc(h->iocv[i]);
   }
   h->iocv.clear();
   delete h;
index 11d101c3e9c07bbcef6ac71f437ea9b1bac6387b..2ce5ec331b853e2fd843200daea13abc19b54e60 100644 (file)
@@ -180,8 +180,6 @@ private:
   vector<interval_set<uint64_t> > block_all;  ///< extents in bdev we own
   vector<Allocator*> alloc;                   ///< allocators for bdevs
 
-  vector<IOContext*> ioc_reap_queue;          ///< iocs from closed writers
-
   void _init_alloc();
   void _stop_alloc();