summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/os_posix/os_fallocate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/os_posix/os_fallocate.c')
-rw-r--r--src/third_party/wiredtiger/src/os_posix/os_fallocate.c85
1 files changed, 46 insertions, 39 deletions
diff --git a/src/third_party/wiredtiger/src/os_posix/os_fallocate.c b/src/third_party/wiredtiger/src/os_posix/os_fallocate.c
index 9e5d9519900..111f6558816 100644
--- a/src/third_party/wiredtiger/src/os_posix/os_fallocate.c
+++ b/src/third_party/wiredtiger/src/os_posix/os_fallocate.c
@@ -18,8 +18,8 @@
* Linux fallocate call.
*/
static int
-__posix_std_fallocate(WT_FILE_HANDLE *file_handle,
- WT_SESSION *wt_session, wt_off_t offset, wt_off_t len)
+__posix_std_fallocate(
+ WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session, wt_off_t offset)
{
#if defined(HAVE_FALLOCATE)
WT_DECL_RET;
@@ -29,13 +29,12 @@ __posix_std_fallocate(WT_FILE_HANDLE *file_handle,
pfh = (WT_FILE_HANDLE_POSIX *)file_handle;
- WT_SYSCALL_RETRY(fallocate(pfh->fd, 0, offset, len), ret);
+ WT_SYSCALL_RETRY(fallocate(pfh->fd, 0, (wt_off_t)0, offset), ret);
return (ret);
#else
WT_UNUSED(file_handle);
WT_UNUSED(wt_session);
WT_UNUSED(offset);
- WT_UNUSED(len);
return (ENOTSUP);
#endif
}
@@ -45,8 +44,8 @@ __posix_std_fallocate(WT_FILE_HANDLE *file_handle,
* Linux fallocate call (system call version).
*/
static int
-__posix_sys_fallocate(WT_FILE_HANDLE *file_handle,
- WT_SESSION *wt_session, wt_off_t offset, wt_off_t len)
+__posix_sys_fallocate(
+ WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session, wt_off_t offset)
{
#if defined(__linux__) && defined(SYS_fallocate)
WT_DECL_RET;
@@ -62,13 +61,13 @@ __posix_sys_fallocate(WT_FILE_HANDLE *file_handle,
* Linux versions (RHEL 5.5), but not in the version of the C library.
* This allows it to work everywhere the kernel supports it.
*/
- WT_SYSCALL_RETRY(syscall(SYS_fallocate, pfh->fd, 0, offset, len), ret);
+ WT_SYSCALL_RETRY(
+ syscall(SYS_fallocate, pfh->fd, 0, (wt_off_t)0, offset), ret);
return (ret);
#else
WT_UNUSED(file_handle);
WT_UNUSED(wt_session);
WT_UNUSED(offset);
- WT_UNUSED(len);
return (ENOTSUP);
#endif
}
@@ -78,8 +77,8 @@ __posix_sys_fallocate(WT_FILE_HANDLE *file_handle,
* POSIX fallocate call.
*/
static int
-__posix_posix_fallocate(WT_FILE_HANDLE *file_handle,
- WT_SESSION *wt_session, wt_off_t offset, wt_off_t len)
+__posix_posix_fallocate(
+ WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session, wt_off_t offset)
{
#if defined(HAVE_POSIX_FALLOCATE)
WT_DECL_RET;
@@ -89,64 +88,72 @@ __posix_posix_fallocate(WT_FILE_HANDLE *file_handle,
pfh = (WT_FILE_HANDLE_POSIX *)file_handle;
- WT_SYSCALL_RETRY(posix_fallocate(pfh->fd, offset, len), ret);
+ WT_SYSCALL_RETRY(posix_fallocate(pfh->fd, (wt_off_t)0, offset), ret);
return (ret);
#else
WT_UNUSED(file_handle);
WT_UNUSED(wt_session);
WT_UNUSED(offset);
- WT_UNUSED(len);
return (ENOTSUP);
#endif
}
/*
- * __wt_posix_file_fallocate --
- * POSIX fallocate.
+ * __wt_posix_file_extend --
+ * Extend the file.
*/
int
-__wt_posix_file_fallocate(WT_FILE_HANDLE *file_handle,
- WT_SESSION *wt_session, wt_off_t offset, wt_off_t len)
+__wt_posix_file_extend(
+ WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session, wt_off_t offset)
{
/*
- * The first fallocate call: figure out what fallocate call this system
- * supports, if any.
+ * The first file extension call: figure out what this system has.
*
- * The function is configured as a locking fallocate call, so we know
- * we're single-threaded through here. Set the nolock function first,
- * then publish the NULL replacement to ensure the handle functions are
+ * This function is configured as a locking call, so we know we're
+ * single-threaded through here. Set the nolock function first, then
+ * publish the NULL replacement to ensure the handle functions are
* always correct.
*
- * We've seen Linux systems where posix_fallocate has corrupted
- * existing file data (even though that is explicitly disallowed
- * by POSIX). FreeBSD and Solaris support posix_fallocate, and
- * so far we've seen no problems leaving it unlocked. Check for
- * fallocate (and the system call version of fallocate) first to
- * avoid locking on Linux if at all possible.
+ * We've seen Linux systems where posix_fallocate has corrupted existing
+ * file data (even though that is explicitly disallowed by POSIX).
+ * FreeBSD and Solaris support posix_fallocate, and so far we've seen
+ * no problems leaving it unlocked. Check for fallocate (and the system
+ * call version of fallocate) first to avoid locking on Linux if at all
+ * possible.
*/
- if (__posix_std_fallocate(file_handle, wt_session, offset, len) == 0) {
- file_handle->fh_allocate_nolock = __posix_std_fallocate;
- WT_PUBLISH(file_handle->fh_allocate, NULL);
+ if (__posix_std_fallocate(file_handle, wt_session, offset) == 0) {
+ file_handle->fh_extend_nolock = __posix_std_fallocate;
+ WT_PUBLISH(file_handle->fh_extend, NULL);
return (0);
}
- if (__posix_sys_fallocate(file_handle, wt_session, offset, len) == 0) {
- file_handle->fh_allocate_nolock = __posix_sys_fallocate;
- WT_PUBLISH(file_handle->fh_allocate, NULL);
+ if (__posix_sys_fallocate(file_handle, wt_session, offset) == 0) {
+ file_handle->fh_extend_nolock = __posix_sys_fallocate;
+ WT_PUBLISH(file_handle->fh_extend, NULL);
return (0);
}
- if (__posix_posix_fallocate(
- file_handle, wt_session, offset, len) == 0) {
+ if (__posix_posix_fallocate(file_handle, wt_session, offset) == 0) {
#if defined(__linux__)
- file_handle->fh_allocate = __posix_posix_fallocate;
+ file_handle->fh_extend = __posix_posix_fallocate;
WT_WRITE_BARRIER();
#else
- file_handle->fh_allocate_nolock = __posix_posix_fallocate;
- WT_PUBLISH(file_handle->fh_allocate, NULL);
+ file_handle->fh_extend_nolock = __posix_posix_fallocate;
+ WT_PUBLISH(file_handle->fh_extend, NULL);
#endif
return (0);
}
- file_handle->fh_allocate = NULL;
+ /*
+ * Use the POSIX ftruncate call if there's nothing else, it can extend
+ * files. Note ftruncate requires locking.
+ */
+ if (file_handle->fh_truncate != NULL &&
+ file_handle->fh_truncate(file_handle, wt_session, offset) == 0) {
+ file_handle->fh_extend = file_handle->fh_truncate;
+ WT_WRITE_BARRIER();
+ return (0);
+ }
+
+ file_handle->fh_extend = NULL;
WT_WRITE_BARRIER();
return (ENOTSUP);
}