Build fix: add a noop compat wrapper for posix_fadvise
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 18 Apr 2023 16:11:33 +0000 (12:11 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 18 Apr 2023 20:52:19 +0000 (16:52 -0400)
This allows building on platforms without posix_fadvise.

Change-Id: I13fd6404cd02eb8038a97693db27d9619246401d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
src/common/io-hint.cpp

index bd6f45d5d131b08440b1126535cc4e19675e8f62..7257cdeffeee83d722206679a05848924fd4843e 100644 (file)
@@ -315,7 +315,7 @@ AC_CHECK_FUNCS([ \
        mkdir munmap putenv realpath rmdir socket strchr strcspn strdup \
        strncasecmp strndup strnlen strpbrk strrchr strstr strtol strtoul \
        strtoull dirfd gethostbyname2 getipnodebyname epoll_create1 \
-       sched_getcpu sysconf sync_file_range getrandom
+       sched_getcpu sysconf sync_file_range getrandom posix_fadvise
 ])
 
 # Check for pthread_setname_np and pthread_getname_np
index 506f15de6b027114d6be1eabd6bfe85c092b8811..2bb924674c5202c1d4998c6cb78692aad0c6a012 100644 (file)
@@ -54,7 +54,7 @@ int flush_range_async(int fd, off_t offset, off_t nbytes)
 }
 } /* namespace */
 
-#else
+#else /* HAVE_SYNC_FILE_RANGE */
 
 namespace {
 /*
@@ -109,7 +109,44 @@ int flush_range_async(int fd, off_t offset, off_t nbytes)
        return flush_range(fd, offset, nbytes, MS_ASYNC);
 }
 } /* namespace */
-#endif
+#endif /* !HAVE_SYNC_FILE_RANGE */
+
+/*
+ * Use posix_fadvise when available.
+ */
+#ifdef HAVE_POSIX_FADVISE
+namespace {
+int hint_dont_need(int fd, off_t offset, off_t nbytes)
+{
+       const int ret = posix_fadvise(fd, offset, nbytes, POSIX_FADV_DONTNEED);
+       if (ret && ret != -ENOSYS) {
+               PERROR("Failed to mark region as DONTNEED with posix_fadvise: fd=%i, offset=%" PRIu64
+                      ", nbytes=%" PRIu64,
+                      fd,
+                      static_cast<uint64_t>(offset),
+                      static_cast<uint64_t>(nbytes));
+               errno = ret;
+       }
+
+       return ret;
+}
+} /* namespace */
+
+#else /* HAVE_POSIX_FADVISE */
+
+/*
+ * Generic noop compat for platforms wihtout posix_fadvise, this is acceptable
+ * since we are only giving a hint to the kernel.
+ */
+namespace {
+int hint_dont_need(int fd __attribute__((unused)),
+                  off_t offset __attribute__((unused)),
+                  off_t nbytes __attribute__((unused)))
+{
+       return 0;
+}
+} /* namespace */
+#endif /* !HAVE_POSIX_FADVISE */
 
 /*
  * Give a hint to the kernel that we won't need the data at the specified range
@@ -135,15 +172,7 @@ void lttng::io::hint_flush_range_dont_need_sync(int fd, off_t offset, off_t nbyt
         * defined. So it can be expected to lead to lower throughput in
         * streaming.
         */
-       const int ret = posix_fadvise(fd, offset, nbytes, POSIX_FADV_DONTNEED);
-       if (ret && ret != -ENOSYS) {
-               PERROR("Failed to mark region as DONTNEED with posix_fadvise: fd=%i, offset=%" PRIu64
-                      ", nbytes=%" PRIu64,
-                      fd,
-                      static_cast<uint64_t>(offset),
-                      static_cast<uint64_t>(nbytes));
-               errno = ret;
-       }
+       hint_dont_need(fd, offset, nbytes);
 }
 
 /*
This page took 0.026569 seconds and 4 git commands to generate.