From 56a3267fe398aa782af717460332ea9360d73729 Mon Sep 17 00:00:00 2001
From: Ma Jianpeng <jianpeng.ma@intel.com>
Date: Mon, 25 Aug 2014 11:20:48 +0800
Subject: [PATCH] os/FileJournal: Before write_thread_entry exit, using fsync()
 to make sure all data to disk.

Commit(e870fd08ce) the aim is  make sure all aio data to disk when closing
journal. The fsync() can achieve the same effect. For aio+directio,
after io_submit, the content is in request-queue of block device.
Fsync() will send a flush request to wait all requests of block queue to
complete.

Signed-off-by: Ma Jianpeng <jianpeng.ma@intel.com>
---
 src/os/FileJournal.cc | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc
index d6ddc7f..1f3a09b 100644
--- a/src/os/FileJournal.cc
+++ b/src/os/FileJournal.cc
@@ -1125,9 +1125,7 @@ void FileJournal::write_thread_entry()
     }
     
 #ifdef HAVE_LIBAIO
-    //We hope write_finish_thread_entry return until the last aios complete
-    //when set write_stop. But it can't. So don't use aio mode when shutdown.
-    if (aio && !write_stop) {
+    if (aio) {
       Mutex::Locker locker(aio_lock);
       // should we back off to limit aios in flight?  try to do this
       // adaptively so that we submit larger aios once we have lots of
@@ -1178,7 +1176,7 @@ void FileJournal::write_thread_entry()
     }
 
 #ifdef HAVE_LIBAIO
-    if (aio && !write_stop)
+    if (aio)
       do_aio_write(bl);
     else
       do_write(bl);
@@ -1188,6 +1186,7 @@ void FileJournal::write_thread_entry()
     put_throttle(orig_ops, orig_bytes);
   }
 
+  fsync(fd);
   dout(10) << "write_thread_entry finish" << dendl;
 }
 
-- 
1.9.1

