/* * __posix_directory_sync -- * Flush a directory to ensure file creation is durable. */ static int __posix_directory_sync( WT_FILE_SYSTEM *file_system, WT_SESSION *wt_session, const char *path) { WT_DECL_RET; WT_SESSION_IMPL *session; int fd, tret; WT_UNUSED(file_system); session = (WT_SESSION_IMPL *)wt_session; WT_SYSCALL_RETRY(( (fd = open(path, O_RDONLY, 0444)) == -1 ? -1 : 0), ret); if (ret != 0) WT_RET_MSG(session, ret, "%s: directory-sync: open", path); ret = __posix_sync(session, fd, path, "directory-sync"); WT_SYSCALL(close(fd), tret); if (tret != 0) { __wt_err(session, tret, "%s: directory-sync: close", path); if (ret == 0) ret = tret; } return (ret); }
/* * __posix_file_sync -- * POSIX fsync. */ static int __posix_file_sync(WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session) { WT_FILE_HANDLE_POSIX *pfh; WT_SESSION_IMPL *session; session = (WT_SESSION_IMPL *)wt_session; pfh = (WT_FILE_HANDLE_POSIX *)file_handle; return ( __posix_sync(session, pfh->fd, file_handle->name, "handle-sync")); }
/* * __posix_directory_sync -- * Flush a directory to ensure file creation, remove or rename is durable. */ static int __posix_directory_sync(WT_SESSION_IMPL *session, const char *path) { WT_DECL_ITEM(tmp); WT_DECL_RET; int fd, tret; char *dir; WT_RET(__wt_scr_alloc(session, 0, &tmp)); WT_ERR(__wt_buf_setstr(session, tmp, path)); /* * This layer should never see a path that doesn't include a trailing * path separator, this code asserts that fact. */ dir = tmp->mem; strrchr(dir, '/')[1] = '\0'; fd = -1; /* -Wconditional-uninitialized */ WT_SYSCALL_RETRY(( (fd = open(dir, O_RDONLY, 0444)) == -1 ? -1 : 0), ret); if (ret != 0) WT_ERR_MSG(session, ret, "%s: directory-sync: open", dir); ret = __posix_sync(session, fd, dir, "directory-sync"); WT_SYSCALL(close(fd), tret); if (tret != 0) { __wt_err(session, tret, "%s: directory-sync: close", dir); if (ret == 0) ret = tret; } err: __wt_scr_free(session, &tmp); return (ret); }