69 lines · c
1//===- OnDiskCommon.h -------------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIB_CAS_ONDISKCOMMON_H10#define LLVM_LIB_CAS_ONDISKCOMMON_H11 12#include "llvm/Support/Error.h"13#include "llvm/Support/FileSystem.h"14#include <chrono>15#include <optional>16 17namespace llvm::cas::ondisk {18 19/// The version for all the ondisk database files. It needs to be bumped when20/// compatibility breaking changes are introduced.21constexpr StringLiteral CASFormatVersion = "v1";22 23/// Retrieves an overridden maximum mapping size for CAS files, if any,24/// speicified by LLVM_CAS_MAX_MAPPING_SIZE in the environment or set by25/// `setMaxMappingSize()`. If the value from environment is unreadable, returns26/// an error.27Expected<std::optional<uint64_t>> getOverriddenMaxMappingSize();28 29/// Set MaxMappingSize for ondisk CAS. This function is not thread-safe and30/// should be set before creaing any ondisk CAS and does not affect CAS already31/// created. Set value 0 to use default size.32LLVM_ABI_FOR_TEST void setMaxMappingSize(uint64_t Size);33 34/// Whether to use a small file mapping for ondisk databases created in \p Path.35///36/// For some file system that doesn't support sparse file, use a smaller file37/// mapping to avoid consuming too much disk space on creation.38bool useSmallMappingSize(const Twine &Path);39 40/// Thread-safe alternative to \c sys::fs::lockFile. This does not support all41/// the platforms that \c sys::fs::lockFile does, so keep it in the CAS library42/// for now.43std::error_code lockFileThreadSafe(int FD, llvm::sys::fs::LockKind Kind);44 45/// Thread-safe alternative to \c sys::fs::unlockFile. This does not support all46/// the platforms that \c sys::fs::lockFile does, so keep it in the CAS library47/// for now.48std::error_code unlockFileThreadSafe(int FD);49 50/// Thread-safe alternative to \c sys::fs::tryLockFile. This does not support51/// all the platforms that \c sys::fs::lockFile does, so keep it in the CAS52/// library for now.53std::error_code tryLockFileThreadSafe(54 int FD, std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),55 llvm::sys::fs::LockKind Kind = llvm::sys::fs::LockKind::Exclusive);56 57/// Allocate space for the file \p FD on disk, if the filesystem supports it.58///59/// On filesystems that support this operation, this ensures errors such as60/// \c std::errc::no_space_on_device are detected before we write data.61///62/// \returns the new size of the file, or an \c Error.63Expected<size_t> preallocateFileTail(int FD, size_t CurrentSize,64 size_t NewSize);65 66} // namespace llvm::cas::ondisk67 68#endif // LLVM_LIB_CAS_ONDISKCOMMON_H69