This is an automated email from the ASF dual-hosted git repository.
granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 2bf900d Improve preadv/pwritev with Xcode 12 and the OSX 11 SDK
2bf900d is described below
commit 2bf900dd26043edf026b59cba568503d33d8bd71
Author: Grant Henke <[email protected]>
AuthorDate: Thu Dec 10 08:10:10 2020 -0600
Improve preadv/pwritev with Xcode 12 and the OSX 11 SDK
This is a follow on to 0e2c288 which introduced version checks to handle
the introduction of preadv/pwritev in the OSX 11 SDK.
Instead of using a compile time macro to disable using the
preadv/pwritev simulations, this patch reverts to using them all the time
and adjusts the naming of the method to ensure there are no symbol
issues. This is important so that a binary compiled using the OSX 11 SDK
can run on a machine running OSX < 11. This scenario will frequently
occur on Xcode 12 given the OSX 11 SDK is installed by default and
chosen by default by CMake even though the machine is running OSX 10.
Change-Id: I90ba8f65b756c77c25dc776d0174b0d7b5678137
Reviewed-on: http://gerrit.cloudera.org:8080/16852
Tested-by: Kudu Jenkins
Reviewed-by: Bankim Bhavsar <[email protected]>
Reviewed-by: Alexey Serbin <[email protected]>
---
src/kudu/util/env_posix.cc | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index 4a83314..e35f968 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -249,10 +249,10 @@ int fallocate(int fd, int mode, off_t offset, off_t len) {
}
// Implementations for `preadv` and `pwritev` are available in the MacOSX11+
SDK.
-// We provide simulated implementations for older versions.
-#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED
< 110000
+// However, we still use the simulated implementations in order to support
older versions.
+
// Simulates Linux's preadv API on OS X.
-ssize_t preadv(int fd, const struct iovec* iovec, int count, off_t offset) {
+ssize_t preadvsim(int fd, const struct iovec* iovec, int count, off_t offset) {
ssize_t total_read_bytes = 0;
for (int i = 0; i < count; i++) {
ssize_t r;
@@ -270,7 +270,7 @@ ssize_t preadv(int fd, const struct iovec* iovec, int
count, off_t offset) {
}
// Simulates Linux's pwritev API on OS X.
-ssize_t pwritev(int fd, const struct iovec* iovec, int count, off_t offset) {
+ssize_t pwritevsim(int fd, const struct iovec* iovec, int count, off_t offset)
{
ssize_t total_written_bytes = 0;
for (int i = 0; i < count; i++) {
ssize_t r;
@@ -286,7 +286,6 @@ ssize_t pwritev(int fd, const struct iovec* iovec, int
count, off_t offset) {
}
return total_written_bytes;
}
-#endif
#endif
@@ -416,8 +415,11 @@ Status DoReadV(int fd, const string& filename, uint64_t
offset,
// Never request more than IOV_MAX in one request
size_t iov_count = std::min(iov_size - completed_iov,
static_cast<size_t>(IOV_MAX));
ssize_t r;
+#if defined(__APPLE__)
+ RETRY_ON_EINTR(r, preadvsim(fd, iov + completed_iov, iov_count,
cur_offset));
+#else
RETRY_ON_EINTR(r, preadv(fd, iov + completed_iov, iov_count, cur_offset));
-
+#endif
// Fake a short read for testing
if (PREDICT_FALSE(FLAGS_env_inject_short_read_bytes > 0 && rem ==
bytes_req)) {
DCHECK_LT(FLAGS_env_inject_short_read_bytes, r);
@@ -482,8 +484,11 @@ Status DoWriteV(int fd, const string& filename, uint64_t
offset, ArrayView<const
// Never request more than IOV_MAX in one request.
size_t iov_count = std::min(iov_size - completed_iov,
static_cast<size_t>(IOV_MAX));
ssize_t w;
+#if defined(__APPLE__)
+ RETRY_ON_EINTR(w, pwritevsim(fd, iov + completed_iov, iov_count,
cur_offset));
+#else
RETRY_ON_EINTR(w, pwritev(fd, iov + completed_iov, iov_count, cur_offset));
-
+#endif
// Fake a short write for testing.
if (PREDICT_FALSE(FLAGS_env_inject_short_write_bytes > 0 && rem ==
bytes_req)) {
DCHECK_LT(FLAGS_env_inject_short_write_bytes, w);