From c8e2b89cf6bc36a0ff29887b9e76cbbeceef9f8f Mon Sep 17 00:00:00 2001 From: Ma Jianpeng Date: Thu, 21 Aug 2014 15:49:44 +0800 Subject: [PATCH 1/2] os/FileJournal: Tune the judge logic for read_header. When reading journal-header, it should firstly check the result of pread and then do decoce operation. Signed-off-by: Ma Jianpeng --- src/os/FileJournal.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 330765566dc..2209fa29e9f 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -649,6 +649,13 @@ int FileJournal::read_header() buffer::ptr bp = buffer::create_page_aligned(block_size); bp.zero(); int r = ::pread(fd, bp.c_str(), bp.length(), 0); + + if (r < 0) { + int err = errno; + dout(0) << "read_header got " << cpp_strerror(err) << dendl; + return -err; + } + bl.push_back(bp); try { @@ -660,11 +667,6 @@ int FileJournal::read_header() return -EINVAL; } - if (r < 0) { - int err = errno; - dout(0) << "read_header got " << cpp_strerror(err) << dendl; - return -err; - } /* * Unfortunately we weren't initializing the flags field for new From a66a4931d5be9ee26c0983b3154fdbe37261a51c Mon Sep 17 00:00:00 2001 From: Ma Jianpeng Date: Thu, 21 Aug 2014 21:07:51 +0800 Subject: [PATCH 2/2] os/FileJournal: Only using aio then alloc the related resources. If define HAVE_LIBAIO, it alloc related resouces. But itt don't check whether using aio mode. Only using aio it alloc the related resources. Signed-off-by: Ma Jianpeng --- src/os/FileJournal.cc | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 2209fa29e9f..e54dedbed4c 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -103,12 +103,14 @@ int FileJournal::_open(bool forwrite, bool create) goto out_fd; #ifdef HAVE_LIBAIO - aio_ctx = 0; - ret = io_setup(128, &aio_ctx); - if (ret < 0) { - ret = errno; - derr << "FileJournal::_open: unable to setup io_context " << cpp_strerror(ret) << dendl; - goto out_fd; + if (aio) { + aio_ctx = 0; + ret = io_setup(128, &aio_ctx); + if (ret < 0) { + ret = errno; + derr << "FileJournal::_open: unable to setup io_context " << cpp_strerror(ret) << dendl; + goto out_fd; + } } #endif @@ -604,7 +606,8 @@ void FileJournal::start_writer() write_stop = false; write_thread.create(); #ifdef HAVE_LIBAIO - write_finish_thread.create(); + if (aio) + write_finish_thread.create(); #endif } @@ -613,19 +616,25 @@ void FileJournal::stop_writer() { Mutex::Locker l(write_lock); #ifdef HAVE_LIBAIO - Mutex::Locker q(aio_lock); + if (aio) + aio_lock.Lock(); #endif Mutex::Locker p(writeq_lock); write_stop = true; writeq_cond.Signal(); #ifdef HAVE_LIBAIO - aio_cond.Signal(); - write_finish_cond.Signal(); + if (aio) { + aio_cond.Signal(); + write_finish_cond.Signal(); + aio_lock.Unlock(); + } #endif } write_thread.join(); #ifdef HAVE_LIBAIO - write_finish_thread.join(); + if (aio) { + write_finish_thread.join(); + } #endif }