summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2013-06-19 19:29:15 -0400
committerTad Marshall <tad@10gen.com>2013-06-19 19:29:15 -0400
commit69d7632211e20d05f564e67e0cb9fd98929e5d5a (patch)
tree0e78f855add95c3421eb004b8f3787a99ae20fda /src
parent8706a021d8edcd747623bb2b2605995e2c57b76d (diff)
downloadmongo-69d7632211e20d05f564e67e0cb9fd98929e5d5a.tar.gz
SERVER-7404 Link to posix_fadvise at runtime for Solaris
For the Solaris/SmartOS build, do not make direct calls to posix_fadvise, which is present in Solaris 11 but not in Solaris 10. Instead, see if it is available in a loaded library (which will be libc.so.1) at runtime and either call it or call an emulation. The emulation is a no-op.
Diffstat (limited to 'src')
-rw-r--r--src/SConscript.client1
-rw-r--r--src/mongo/db/extsort.cpp1
-rw-r--r--src/mongo/platform/SConscript1
-rw-r--r--src/mongo/platform/posix_fadvise.cpp56
-rw-r--r--src/mongo/platform/posix_fadvise.h41
-rw-r--r--src/mongo/tools/tool.cpp10
-rw-r--r--src/mongo/util/file_allocator.cpp9
-rw-r--r--src/mongo/util/log.cpp1
-rw-r--r--src/mongo/util/logfile.cpp14
9 files changed, 121 insertions, 13 deletions
diff --git a/src/SConscript.client b/src/SConscript.client
index a7e20eb002a..7f543723b1b 100644
--- a/src/SConscript.client
+++ b/src/SConscript.client
@@ -51,6 +51,7 @@ clientSourceBasic = [
'mongo/db/namespace.cpp',
'mongo/db/dbmessage.cpp',
'mongo/pch.cpp',
+ 'mongo/platform/posix_fadvise.cpp',
'mongo/platform/process_id.cpp',
'mongo/platform/random.cpp',
'mongo/util/assert_util.cpp',
diff --git a/src/mongo/db/extsort.cpp b/src/mongo/db/extsort.cpp
index b71f34ac8ff..d2d2a4906a0 100644
--- a/src/mongo/db/extsort.cpp
+++ b/src/mongo/db/extsort.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/kill_current_op.h"
#include "mongo/db/namespace-inl.h"
+#include "mongo/platform/posix_fadvise.h"
#include "mongo/util/file.h"
#if MONGO_USE_NEW_SORTER
diff --git a/src/mongo/platform/SConscript b/src/mongo/platform/SConscript
index 0c668a4e436..4a81a31d9cb 100644
--- a/src/mongo/platform/SConscript
+++ b/src/mongo/platform/SConscript
@@ -3,6 +3,7 @@
Import("env")
env.Library('platform', [
+ 'posix_fadvise.cpp',
'process_id.cpp',
'random.cpp',
'strcasestr.cpp',
diff --git a/src/mongo/platform/posix_fadvise.cpp b/src/mongo/platform/posix_fadvise.cpp
new file mode 100644
index 00000000000..3053b02fbec
--- /dev/null
+++ b/src/mongo/platform/posix_fadvise.cpp
@@ -0,0 +1,56 @@
+/* Copyright 2013 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if defined(__sunos__)
+
+#include "mongo/platform/posix_fadvise.h"
+
+#include <dlfcn.h>
+
+#include "mongo/base/init.h"
+#include "mongo/base/status.h"
+
+namespace mongo {
+namespace pal {
+
+ int posix_fadvise_emulation(int fd, off_t offset, off_t len, int advice) {
+ return 0;
+ }
+
+ typedef int (*PosixFadviseFunc)(int fd, off_t offset, off_t len, int advice);
+ static PosixFadviseFunc posix_fadvise_switcher = mongo::pal::posix_fadvise_emulation;
+
+ int posix_fadvise(int fd, off_t offset, off_t len, int advice) {
+ return posix_fadvise_switcher(fd, offset, len, advice);
+ }
+
+} // namespace pal
+
+ // 'posix_fadvise()' on Solaris will call the emulation if the symbol is not found
+ //
+ MONGO_INITIALIZER_GENERAL(SolarisPosixFadvise,
+ MONGO_NO_PREREQUISITES,
+ ("default"))(InitializerContext* context) {
+ void* functionAddress = dlsym(RTLD_DEFAULT, "posix_fadvise");
+ if (functionAddress != NULL) {
+ mongo::pal::posix_fadvise_switcher =
+ reinterpret_cast<mongo::pal::PosixFadviseFunc>(functionAddress);
+ }
+ return Status::OK();
+ }
+
+} // namespace mongo
+
+#endif // #if defined(__sunos__)
diff --git a/src/mongo/platform/posix_fadvise.h b/src/mongo/platform/posix_fadvise.h
new file mode 100644
index 00000000000..117b6b917f4
--- /dev/null
+++ b/src/mongo/platform/posix_fadvise.h
@@ -0,0 +1,41 @@
+/* Copyright 2013 10gen Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#if !defined(_WIN32)
+
+#include <fcntl.h>
+
+#if defined(__sunos__)
+
+#include <sys/types.h>
+
+namespace mongo {
+ namespace pal {
+ int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+ } // namespace pal
+ using pal::posix_fadvise;
+} // namespace mongo
+
+#elif defined(POSIX_FADV_DONTNEED)
+
+namespace mongo {
+ using ::posix_fadvise;
+} // namespace mongo
+
+#endif
+
+#endif
diff --git a/src/mongo/tools/tool.cpp b/src/mongo/tools/tool.cpp
index b54db1675ac..ed94e860cc9 100644
--- a/src/mongo/tools/tool.cpp
+++ b/src/mongo/tools/tool.cpp
@@ -18,23 +18,23 @@
#include "mongo/tools/tool.h"
+#include <boost/filesystem/operations.hpp>
#include <fstream>
#include <iostream>
#include "pcrecpp.h"
+#include "mongo/client/dbclient_rs.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_manager_global.h"
#include "mongo/db/auth/authz_manager_external_state_mock.h"
+#include "mongo/db/json.h"
#include "mongo/db/namespace_details.h"
+#include "mongo/platform/posix_fadvise.h"
#include "mongo/util/file_allocator.h"
#include "mongo/util/password.h"
#include "mongo/util/version.h"
-#include "mongo/client/dbclient_rs.h"
-#include "mongo/db/json.h"
-
-#include <boost/filesystem/operations.hpp>
using namespace std;
using namespace mongo;
@@ -494,7 +494,7 @@ namespace mongo {
return 0;
}
-#if !defined(__sunos__) && defined(POSIX_FADV_SEQUENTIAL)
+#ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise(fileno(file), 0, fileLength, POSIX_FADV_SEQUENTIAL);
#endif
diff --git a/src/mongo/util/file_allocator.cpp b/src/mongo/util/file_allocator.cpp
index 07a962b42a2..e59bce6934b 100644
--- a/src/mongo/util/file_allocator.cpp
+++ b/src/mongo/util/file_allocator.cpp
@@ -16,11 +16,13 @@
*/
#include "mongo/pch.h"
+
#include "mongo/util/file_allocator.h"
+
#include <boost/thread.hpp>
#include <boost/filesystem/operations.hpp>
-#include <fcntl.h>
#include <errno.h>
+#include <fcntl.h>
#if defined(__freebsd__) || defined(__openbsd__)
# include <sys/stat.h>
@@ -34,10 +36,11 @@
# include <io.h>
#endif
-#include "mongo/util/time_support.h"
-#include "mongo/util/timer.h"
+#include "mongo/platform/posix_fadvise.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/paths.h"
+#include "mongo/util/time_support.h"
+#include "mongo/util/timer.h"
using namespace mongoutils;
diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp
index 00845d07da1..9ed7c224f6e 100644
--- a/src/mongo/util/log.cpp
+++ b/src/mongo/util/log.cpp
@@ -18,6 +18,7 @@
#include "mongo/pch.h"
+#include "mongo/platform/posix_fadvise.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/concurrency/threadlocal.h"
#include "mongo/util/stacktrace.h"
diff --git a/src/mongo/util/logfile.cpp b/src/mongo/util/logfile.cpp
index d3fcde359ce..9ab57deac3a 100644
--- a/src/mongo/util/logfile.cpp
+++ b/src/mongo/util/logfile.cpp
@@ -16,12 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "pch.h"
-#include "logfile.h"
-#include "text.h"
-#include "mongoutils/str.h"
-#include "mongo/util/startup_test.h"
+#include "mongo/pch.h"
+
+#include "mongo/util/logfile.h"
+
+#include "mongo/platform/posix_fadvise.h"
#include "mongo/util/mmap.h"
+#include "mongo/util/mongoutils/str.h"
+#include "mongo/util/startup_test.h"
+#include "mongo/util/text.h"
+
using namespace mongoutils;