diff options
m--------- | doc/html | 8 | ||||
-rw-r--r-- | include/boost/afio/revision.hpp | 6 | ||||
-rw-r--r-- | include/boost/afio/v2.0/algorithm/shared_fs_mutex/memory_map.hpp | 33 | ||||
m--------- | test/kerneltest | 0 | ||||
-rw-r--r-- | test/tests/shared_fs_mutex.cpp | 18 |
5 files changed, 45 insertions, 20 deletions
diff --git a/doc/html b/doc/html -Subproject d91b37b3e891e4186b9cc939b8ee6b9150301cb +Subproject 2b7cb5457a4ece7ad1eca9c25c69b8d5561b8c5 diff --git a/include/boost/afio/revision.hpp b/include/boost/afio/revision.hpp index b3bf7576..fa91a249 100644 --- a/include/boost/afio/revision.hpp +++ b/include/boost/afio/revision.hpp @@ -1,4 +1,4 @@ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define BOOST_AFIO_PREVIOUS_COMMIT_REF 667fd27321e10c19d303e13822c2866962dceade -#define BOOST_AFIO_PREVIOUS_COMMIT_DATE "2017-04-14 23:20:19 +00:00" -#define BOOST_AFIO_PREVIOUS_COMMIT_UNIQUE 667fd273 +#define BOOST_AFIO_PREVIOUS_COMMIT_REF 98726d1af36841eed1a280badabf4691a2232560 +#define BOOST_AFIO_PREVIOUS_COMMIT_DATE "2017-04-15 10:12:00 +00:00" +#define BOOST_AFIO_PREVIOUS_COMMIT_UNIQUE 98726d1a diff --git a/include/boost/afio/v2.0/algorithm/shared_fs_mutex/memory_map.hpp b/include/boost/afio/v2.0/algorithm/shared_fs_mutex/memory_map.hpp index 6648fe1b..781aa105 100644 --- a/include/boost/afio/v2.0/algorithm/shared_fs_mutex/memory_map.hpp +++ b/include/boost/afio/v2.0/algorithm/shared_fs_mutex/memory_map.hpp @@ -262,6 +262,13 @@ namespace algorithm mapinuse = std::move(mapinuse2); temph = std::move(_temph.get()); } + // Map the files into memory, being very careful that the lock file is only ever mapped read only + // as some OSs can get confused if you use non-mmaped writes on a region mapped for writing. + BOOST_OUTCOME_TRY(hsection, section_handle::section(ret, 0, section_handle::flag::read)); + BOOST_OUTCOME_TRY(temphsection, section_handle::section(temph, HashIndexSize)); + BOOST_OUTCOME_TRY(hmap, map_handle::map(hsection, 0, 0, section_handle::flag::read)); + BOOST_OUTCOME_TRY(temphmap, map_handle::map(temphsection, HashIndexSize)); + return memory_map(std::move(ret), std::move(temph), std::move(lockinuse.get()), std::move(mapinuse), std::move(hmap), std::move(temphmap), fallbacklock); } else { @@ -271,25 +278,29 @@ namespace algorithm temph = std::move(_temph); auto temppath(temph.path()); BOOST_OUTCOME_TRYV(temph.truncate(HashIndexSize)); -#ifdef __linux__ - // Linux appears to have a race where if you mmap for read straight after a fallocate, on read you get a SIGBUS - BOOST_OUTCOME_TRYV(temph.barrier()); -#endif + /* Linux appears to have a race where: + 1. This process creates a new file and fallocate's its maximum extent. + 2. Another process opens this file and mmaps it. + 3. The other process tries to read from the mmap, and gets a SIGBUS for its efforts. + + I tried writing zeros using write after the fallocate, but it appears not to help, so + for Linux compatibility we will have to mmap before publishing the path of the hash index. + */ + // Map the files into memory, being very careful that the lock file is only ever mapped read only + // as some OSs can get confused if you use non-mmaped writes on a region mapped for writing. + BOOST_OUTCOME_TRY(temphsection, section_handle::section(temph, HashIndexSize)); + BOOST_OUTCOME_TRY(temphmap, map_handle::map(temphsection, HashIndexSize)); // Write the path of my new hash index file and convert my lock to a shared one BOOST_OUTCOME_TRYV(ret.write(0, (const char *) temppath.c_str(), temppath.native().size() * sizeof(*temppath.c_str()))); + BOOST_OUTCOME_TRY(hsection, section_handle::section(ret, 0, section_handle::flag::read)); + BOOST_OUTCOME_TRY(hmap, map_handle::map(hsection, 0, 0, section_handle::flag::read)); // Convert exclusive whole file lock into lock in use BOOST_OUTCOME_TRY(mapinuse2, ret.lock(_mapinuseoffset, 1, false)); BOOST_OUTCOME_TRY(lockinuse2, ret.lock(_lockinuseoffset, 1, false)); mapinuse = std::move(mapinuse2); lockinuse = std::move(lockinuse2); + return memory_map(std::move(ret), std::move(temph), std::move(lockinuse.get()), std::move(mapinuse), std::move(hmap), std::move(temphmap), fallbacklock); } - // Map the files into memory, being very careful that the lock file is only ever mapped read only - // as some OSs can get confused if you use non-mmaped writes on a region mapped for writing. - BOOST_OUTCOME_TRY(hsection, section_handle::section(ret, 0, section_handle::flag::read)); - BOOST_OUTCOME_TRY(temphsection, section_handle::section(temph, HashIndexSize)); - BOOST_OUTCOME_TRY(hmap, map_handle::map(hsection, 0, 0, section_handle::flag::read)); - BOOST_OUTCOME_TRY(temphmap, map_handle::map(temphsection, HashIndexSize)); - return memory_map(std::move(ret), std::move(temph), std::move(lockinuse.get()), std::move(mapinuse), std::move(hmap), std::move(temphmap), fallbacklock); } BOOST_OUTCOME_CATCH_ALL_EXCEPTION_TO_RESULT } diff --git a/test/kerneltest b/test/kerneltest -Subproject e5651599c6e1bfe497fa79be9f94ba379438987 +Subproject b30ed05e2e51f0125b305ee6c31fe3b872dfa25 diff --git a/test/tests/shared_fs_mutex.cpp b/test/tests/shared_fs_mutex.cpp index 0d76557e..2ad383ad 100644 --- a/test/tests/shared_fs_mutex.cpp +++ b/test/tests/shared_fs_mutex.cpp @@ -137,7 +137,16 @@ struct child_workers ss2 = decltype(ss2)(); ss2 << ss1.str() << n << ss3.str(); std::vector<stl1z::filesystem::path::string_type> args{ss2.str()}; - workers.push_back(child_process::child_process::launch(child_process::current_process_path(), std::move(args), child_process::current_process_env(), true).get()); + auto newchild = child_process::child_process::launch(child_process::current_process_path(), std::move(args), child_process::current_process_env(), true); +#if 0 + if(!newchild) + { + fprintf(stderr, "Failed to launch new child process due to %s. Press Return to fatal exit.\n", newchild.error().message().c_str()); + getchar(); + abort(); + } +#endif + workers.push_back(std::move(newchild).get()); results[n].retcode = 0; } } @@ -201,7 +210,12 @@ struct child_workers if(results[n].results.back() == '\r') results[n].results.resize(results[n].results.size() - 1); } - results[n].retcode = child.wait().get(); +#ifdef NDEBUG + stl11::chrono::steady_clock::time_point deadline = stl11::chrono::steady_clock::now() + stl11::chrono::seconds(5); +#else + stl11::chrono::steady_clock::time_point deadline; +#endif + results[n].retcode = child.wait_until(deadline).get(); } } }; |