Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/ned14/llfio into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ned14 committed Feb 2, 2021
2 parents fc3aba2 + 33bf320 commit 46451d9
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 55 deletions.
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ include(QuickCppLibUtils)
include(QuickCppLibPolicies)

option(LLFIO_USE_EXPERIMENTAL_SG14_STATUS_CODE "Whether to use SG14 status_code for failure handling" OFF)
option(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST "Whether to build executables which are smoke tests that LLFIO is fully working. Used by various package managers such as vcpkg." OFF)
set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests")

ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/llfio/ntkernel-error-category/include" "https://github.com/ned14/ntkernel-error-category.git")

Expand Down Expand Up @@ -66,8 +68,6 @@ if(WIN32)
endif()
endif()

set(UNIT_TESTS_CXX_VERSION "latest" CACHE STRING "The version of C++ to use in the header-only unit tests")

# Make the standard static and shared libraries, and if supported by this compiler, C++ modules
# for both static and shared libraries as well. For the non-C++ module variants, makes the
# interface headers into precompiled headers. Only builds all of them if this is the topmost
Expand Down Expand Up @@ -161,7 +161,13 @@ if((MSVC AND MSVC_VERSION VERSION_GREATER_EQUAL 1923) OR APPLE)
endif()
endif()
# Set the library dependencies this library has
all_link_libraries(PUBLIC quickcpplib::hl outcome::hl Threads::Threads $<$<PLATFORM_ID:Linux>:rt>)
all_link_libraries(PUBLIC Threads::Threads $<$<PLATFORM_ID:Linux>:rt>)
if(TARGET outcome::hl)
all_link_libraries(PUBLIC outcome::hl)
endif()
if(TARGET quickcpplib::hl)
all_link_libraries(PUBLIC quickcpplib::hl)
endif()

# Set the system dependencies this library has
include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -390,6 +396,21 @@ if(NOT PROJECT_IS_DEPENDENCY)
endif()
endif()

if(LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST)
set(LLFIO_SMOKE_TESTS)
add_executable(llfio-dependency-smoke-test "test-packaging/example.cpp")
list(APPEND LLFIO_SMOKE_TESTS llfio-dependency-smoke-test)
foreach(target ${LLFIO_SMOKE_TESTS})
target_link_libraries(${target} PRIVATE llfio::dl)
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
add_test(NAME ${target} CONFIGURATIONS Debug Release RelWithDebInfo MinSizeRel
COMMAND $<TARGET_FILE:${target}> --reporter junit --out $<TARGET_FILE:${target}>.junit.xml
)
endforeach()
endif()

# Cache this library's auto scanned sources for later reuse
include(QuickCppLibCacheLibrarySources)

Expand Down
4 changes: 3 additions & 1 deletion cmake/QuickCppLibBootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ foreach(item ${CMAKE_MODULE_PATH})
set(quickcpplib_done ON)
endif()
endforeach()
if(DEFINED quickcpplib_DIR)
if(NOT quickcpplib_done AND quickcpplib_DIR)
find_package(quickcpplib QUIET CONFIG)
if(quickcpplib_FOUND)
if(EXISTS "${quickcpplib_DIR}/share/cmakelib")
Expand All @@ -53,6 +53,8 @@ if(NOT quickcpplib_done)
set(CTEST_QUICKCPPLIB_SCRIPTS "${CMAKE_SOURCE_DIR}/../quickcpplib/scripts")
# Copy latest version of myself into end user
file(COPY "${CTEST_QUICKCPPLIB_SCRIPTS}/../cmake/QuickCppLibBootstrap.cmake" DESTINATION "${CMAKE_SOURCE_DIR}/cmake/")
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib/repo/cmakelib")
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib")
elseif(CMAKE_BINARY_DIR)
# Place into root binary directory, same place as where find_quickcpplib_library() puts dependencies.
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_BINARY_DIR}/quickcpplib")
Expand Down
6 changes: 3 additions & 3 deletions include/llfio/revision.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define LLFIO_PREVIOUS_COMMIT_REF 48ee8bae656cb5d53f38feb462caa53e1128b76d
#define LLFIO_PREVIOUS_COMMIT_DATE "2021-01-27 20:37:58 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 48ee8bae
#define LLFIO_PREVIOUS_COMMIT_REF 669e0b45bbc60cf4d46a72559710d428f2863740
#define LLFIO_PREVIOUS_COMMIT_DATE "2021-02-02 11:20:42 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 669e0b45
4 changes: 2 additions & 2 deletions include/llfio/v2.0/detail/impl/fast_random_file_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ fast_random_file_handle::io_result<fast_random_file_handle::buffers_type> fast_r
}
if(p == &blk)
{
memcpy(buffer.data() + i, ((const char *) p) + thisblockoffset, thisblocklen);
memcpy(buffer.data() + i, ((const char *) p) + thisblockoffset, (size_type) thisblocklen);
}
reqs.offset += thisblocklen;
i += thisblocklen;
i += (size_type) thisblocklen;
togo -= thisblocklen;
if(togo == 0)
{
Expand Down
10 changes: 5 additions & 5 deletions include/llfio/v2.0/detail/impl/windows/file_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ result<file_handle::extent_pair> file_handle::clone_extents_to(file_handle::exte
extent.length = mycurrentlength - extent.offset;
}
LLFIO_DEADLINE_TO_SLEEP_INIT(d);
const extent_type blocksize = utils::file_buffer_default_size();
const size_type blocksize = utils::file_buffer_default_size();
byte *buffer = nullptr;
auto unbufferh = make_scope_exit([&]() noexcept {
if(buffer != nullptr)
Expand Down Expand Up @@ -663,7 +663,7 @@ result<file_handle::extent_pair> file_handle::clone_extents_to(file_handle::exte
for(extent_type thisoffset = 0; thisoffset < item.src.length; thisoffset += blocksize)
{
bool done = false;
const auto thisblock = std::min(blocksize, item.src.length - thisoffset);
const auto thisblock = std::min((extent_type) blocksize, item.src.length - thisoffset);
if(duplicate_extents && item.op == workitem::clone_extents)
{
typedef struct _DUPLICATE_EXTENTS_DATA
Expand Down Expand Up @@ -713,7 +713,7 @@ result<file_handle::extent_pair> file_handle::clone_extents_to(file_handle::exte
buffer = utils::page_allocator<byte>().allocate(blocksize);
}
deadline nd;
buffer_type b(buffer, thisblock);
buffer_type b(buffer, (size_type) thisblock);
LLFIO_DEADLINE_TO_PARTIAL_DEADLINE(nd, d);
OUTCOME_TRY(auto readed, read({{&b, 1}, item.src.offset + thisoffset}, nd));
buffer_dirty = true;
Expand Down Expand Up @@ -807,10 +807,10 @@ result<file_handle::extent_pair> file_handle::clone_extents_to(file_handle::exte
buffer = utils::page_allocator<byte>().allocate(blocksize);
}
deadline nd;
const_buffer_type cb(buffer, thisblock);
const_buffer_type cb(buffer, (size_type) thisblock);
if(buffer_dirty)
{
memset(buffer, 0, thisblock);
memset(buffer, 0, (size_type) thisblock);
buffer_dirty = false;
}
LLFIO_DEADLINE_TO_PARTIAL_DEADLINE(nd, d);
Expand Down
12 changes: 6 additions & 6 deletions include/llfio/v2.0/detail/impl/windows/map_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static inline result<void> win32_maps_apply(byte *addr, size_t bytes, win32_map_
/* mbi.RegionSize will be that from mbi.BaseAddress to end of a reserved region,
so clamp to region size originally requested.
*/
OUTCOME_TRY(f(reinterpret_cast<byte *>(mbi.BaseAddress), std::min(mbi.RegionSize, bytes)));
OUTCOME_TRY(f(reinterpret_cast<byte *>(mbi.BaseAddress), std::min((size_t) mbi.RegionSize, bytes)));
}
addr += mbi.RegionSize;
if(mbi.RegionSize < bytes)
Expand Down Expand Up @@ -597,13 +597,13 @@ map_handle::io_result<map_handle::const_buffers_type> map_handle::_do_barrier(ma
// If nvram and not syncing metadata, use lightweight barrier
if(kind <= barrier_kind::wait_data_only && is_nvram())
{
auto synced = nvram_barrier({addr, bytes});
auto synced = nvram_barrier({addr, (size_type) bytes});
if(synced.size() >= bytes)
{
return {reqs.buffers};
}
}
OUTCOME_TRYV(win32_maps_apply(addr, bytes, win32_map_sought::committed, [](byte *addr, size_t bytes) -> result<void> {
OUTCOME_TRYV(win32_maps_apply(addr, (size_type) bytes, win32_map_sought::committed, [](byte *addr, size_t bytes) -> result<void> {
if(FlushViewOfFile(addr, static_cast<SIZE_T>(bytes)) == 0)
{
return win32_error();
Expand Down Expand Up @@ -684,7 +684,7 @@ result<map_handle> map_handle::map(section_handle &section, size_type bytes, ext
ret.value()._addr = static_cast<byte *>(addr);
ret.value()._offset = offset;
ret.value()._reservation = _bytes;
ret.value()._length = section.length().value() - offset;
ret.value()._length = (size_type) (section.length().value() - offset);
ret.value()._pagesize = pagesize;
// Make my handle borrow the native handle of my backing storage
ret.value()._v.h = section.backing_native_handle().h;
Expand Down Expand Up @@ -754,7 +754,7 @@ result<map_handle::size_type> map_handle::truncate(size_type newsize, bool /* un
// If newsize isn't exactly a previous extension, this will fail, same as for the VirtualAlloc case
OUTCOME_TRY(win32_release_file_allocations(_addr + newsize, _reservation - newsize));
_reservation = newsize;
_length = (length - _offset < newsize) ? (length - _offset) : newsize; // length of backing, not reservation
_length = (size_type)((length - _offset < newsize) ? (length - _offset) : newsize); // length of backing, not reservation
return _reservation;
}
// Try to map an additional part of the section directly after this map
Expand All @@ -772,7 +772,7 @@ result<map_handle::size_type> map_handle::truncate(size_type newsize, bool /* un
return ntkernel_error(ntstat);
}
_reservation += _bytes;
_length = (length - _offset < newsize) ? (length - _offset) : newsize; // length of backing, not reservation
_length = (size_type)((length - _offset < newsize) ? (length - _offset) : newsize); // length of backing, not reservation
return _reservation;
}

Expand Down
14 changes: 7 additions & 7 deletions include/llfio/v2.0/detail/impl/windows/mapped_file_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ result<mapped_file_handle::size_type> mapped_file_handle::reserve(size_type rese
}
if(reservation == 0)
{
reservation = length;
reservation = (size_type) length;
}
if(!_sh.is_valid())
{
Expand All @@ -66,7 +66,7 @@ result<mapped_file_handle::size_type> mapped_file_handle::reserve(size_type rese
}
else if(map_size > length)
{
map_size = length;
map_size = (size_type) length;
}
OUTCOME_TRYV(_mh.close());
OUTCOME_TRY(auto &&mh, map_handle::map(_sh, map_size, 0, mapflags));
Expand Down Expand Up @@ -117,7 +117,7 @@ result<mapped_file_handle::extent_type> mapped_file_handle::truncate(extent_type
OUTCOME_TRY(auto &&ret, file_handle::truncate(newsize));
if(newsize > _reservation)
{
_reservation = newsize;
_reservation = (size_type) newsize;
}
// Reserve now we have resized, it'll create a new section for the new size
OUTCOME_TRYV(reserve(_reservation));
Expand Down Expand Up @@ -149,13 +149,13 @@ result<mapped_file_handle::extent_type> mapped_file_handle::truncate(extent_type
// Have we exceeded the reservation? If so, reserve a new reservation which will recreate the map.
if(newsize > _reservation)
{
OUTCOME_TRY(auto &&ret, reserve(newsize));
OUTCOME_TRY(auto &&ret, reserve((size_type) newsize));
return ret;
}
size = newsize;
}
// Adjust the map to reflect the new size of the section
_mh._length = size;
_mh._length = (size_type) size;
return newsize;
}

Expand Down Expand Up @@ -183,13 +183,13 @@ result<mapped_file_handle::extent_type> mapped_file_handle::update_map() noexcep
if(size >= length)
{
// Section is already the same size as the file, or is as big as it can go
_mh._length = length;
_mh._length = (size_type) length;
return length;
}
// Nobody appears to have extended the section to match the file yet
OUTCOME_TRYV(_sh.truncate(length));
// Adjust the map to reflect the new size of the section
_mh._length = length;
_mh._length = (size_type) length;
return length;
}

Expand Down
53 changes: 25 additions & 28 deletions test-packaging/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,34 @@ Distributed under the Boost Software License, Version 1.0.

#include <llfio.hpp>

#include <vector>
#include <iostream>

int main()
{
//! [file_entire_file1]
namespace llfio = LLFIO_V2_NAMESPACE;

// Open the file for read
llfio::file_handle fh = llfio::file( //
{}, // path_handle to base directory
"foo" // path_view to path fragment relative to base directory
// default mode is read only
// default creation is open existing
// default caching is all
// default flags is none
).value(); // If failed, throw a filesystem_error exception

// Make a vector sized the current maximum extent of the file
std::vector<llfio::byte> buffer(fh.maximum_extent().value());

// Synchronous scatter read from file
llfio::file_handle::size_type bytesread = llfio::read(
fh, // handle to read from
0, // offset
{{ buffer.data(), buffer.size() }} // Single scatter buffer of the vector
// default deadline is infinite
).value(); // If failed, throw a filesystem_error exception

// In case of racy truncation of file by third party to new length, adjust buffer to
// bytes actually read
buffer.resize(bytesread);
//! [file_entire_file1]
return 0;
auto r = []() -> llfio::result<int> {
OUTCOME_TRY(auto fh, llfio::file_handle::temp_file());
static const char *buffers[] = { "He", "llo", " world" };
OUTCOME_TRY(fh.write(0, { { (const llfio::byte *) buffers[0], 2 }, { (const llfio::byte *) buffers[1], 3 }, { (const llfio::byte *) buffers[2], 6 } } ));
llfio::byte buffer[64];
OUTCOME_TRY(auto read, fh.read(0, { {buffer, sizeof(buffer)} }));
if(read != 11)
{
std::cerr << "FAILURE: Did not read 11 bytes!" << std::endl;
return 1;
}
if(0 != memcmp(buffer, "Hello world", 11))
{
std::cerr << "FAILURE: Did not read what was written!" << std::endl;
return 1;
}
return 0;
}();
if(!r)
{
std::cerr << "ERROR: " << r.error().message().c_str() << std::endl;
return 1;
}
return r.value();
}

0 comments on commit 46451d9

Please sign in to comment.