diff --git a/CMakeLists.txt b/CMakeLists.txt index 634acbd..cdf2578 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ endif() # add boost # set(BOOST_ROOT $ENV{BOOST_ROOT}) -find_package(Boost 1.55 COMPONENTS log log_setup thread system filesystem REQUIRED) +find_package(Boost 1.65 COMPONENTS log log_setup thread system filesystem REQUIRED) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIR}) diff --git a/include/nvmm/error_code.h b/include/nvmm/error_code.h index 0475fa4..53c6d1b 100644 --- a/include/nvmm/error_code.h +++ b/include/nvmm/error_code.h @@ -1,12 +1,12 @@ /* - * (c) Copyright 2016-2021 Hewlett Packard Enterprise Development Company LP. + * (c) Copyright 2016-2022 Hewlett Packard Enterprise Development Company LP. * * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the - * GNU Lesser General Public License Version 3, or (at your option) - * later with exceptions included below, or under the terms of the + * licenses. You may choose to be licensed under the terms of the + * GNU Lesser General Public License Version 3, or (at your option) + * later with exceptions included below, or under the terms of the * MIT license (Expat) available in COPYING file in the source tree. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,111 +28,113 @@ namespace nvmm { enum ErrorCode { - // general errors (0-) - NO_ERROR = 0, - NOT_YET_IMPLEMENTED, - BUG, - OUT_OF_MEMORY, - INVALID_ARGUMENTS, // one or more of the argument to the function is invalid - - // shelf file (20-) - SHELF_FILE_CREATE_FAILED = 20, - SHELF_FILE_DESTROY_FAILED, - SHELF_FILE_TRUNCATE_FAILED, - SHELF_FILE_OPEN_FAILED, - SHELF_FILE_CLOSE_FAILED, - SHELF_FILE_MAP_FAILED, - SHELF_FILE_FAM_ATOMIC_REGISTER_REGION_FAILED, - SHELF_FILE_UNMAP_FAILED, - SHELF_FILE_FOUND, - SHELF_FILE_NOT_FOUND, - SHELF_FILE_RENAME_FAILED = 30, - - SHELF_FILE_FORMAT_FAILED, - SHELF_FILE_CLEAR_FAILED, // clear the formatting - SHELF_FILE_VERIFY_FAILED, - SHELF_FILE_INVALID_FORMAT, - SHELF_FILE_RECOVER_FAILED, - SHELF_FILE_GET_PERM_FAILED, - SHELF_FILE_SET_PERM_FAILED, - - SHELF_FILE_OPENED, - SHELF_FILE_CLOSED, - - // pool (60-) - POOL_CREATE_FAILED = 60, - POOL_DESTROY_FAILED, - POOL_VERIFY_FAILED, - POOL_OPEN_FAILED, - POOL_CLOSE_FAILED, - POOL_MEMBERSHIP_FULL, - POOL_MEMBERSHIP_EMPTY, - POOL_INVALID_META_FILE, - POOL_INVALID_POOL_ID, - POOL_FOUND, - POOL_NOT_FOUND, - POOL_SHELF_FOUND, - POOL_SHELF_NOT_FOUND, - POOL_ADD_SHELF_FAILED, - POOL_REMOVE_SHELF_FAILED, - POOL_INCONSISTENCY_FOUND, - POOL_OPENED, - POOL_CLOSED, - - // membership (80-) - MEMBERSHIP_CREATE_FAILED = 80, - MEMBERSHIP_DESTROY_FAILED, - MEMBERSHIP_OPEN_FAILED, - - // Heap (100-) - HEAP_CREATE_FAILED = 100, - HEAP_DESTROY_FAILED, - HEAP_OPEN_FAILED, - HEAP_CLOSE_FAILED, - HEAP_ALLOC_FAILED, - HEAP_OPENED, - HEAP_CLOSED, - HEAP_RESIZE_FAILED, - HEAP_SET_PERMISSION_FAILED, - HEAP_GET_PERMISSION_FAILED, - HEAP_BUSY, // Some other metadata operation in progress - HEAP_NOT_OPEN, - HEAP_IS_OPEN, - - // Region (120-) - REGION_CREATE_FAILED = 120, - REGION_DESTROY_FAILED, - REGION_OPEN_FAILED, - REGION_CLOSE_FAILED, - REGION_MAP_FAILED, - REGION_UNMAP_FAILED, - REGION_OPENED, - REGION_CLOSED, - - // FreeLists (140-) - FREELISTS_CREATE_FAILED = 140, - FREELISTS_DESTROY_FAILED, - FREELISTS_OPEN_FAILED, - FREELISTS_PUT_FAILED, - FREELISTS_EMPTY, - - // Ownership (150-) - OWNERSHIP_CREATE_FAILED = 150, - OWNERSHIP_DESTROY_FAILED, - OWNERSHIP_OPEN_FAILED, - - // memory manager (200-) - ID_FOUND = 200, // this id is in use - ID_NOT_FOUND, // this id is available - ID_NOT_VALID, // This id is not valid - INVALID_PTR, - MAP_POINTER_FAILED, - - // shelf manager (250-) - SHELF_ID_NOT_FOUND = 250, - - // max return code - MAX_RETURN_CODE + // general errors (0-) + NO_ERROR = 0, + NOT_YET_IMPLEMENTED, + BUG, + OUT_OF_MEMORY, + INVALID_ARGUMENTS, // one or more of the argument to the function is invalid + + // shelf file (20-) + SHELF_FILE_CREATE_FAILED = 20, + SHELF_FILE_DESTROY_FAILED, + SHELF_FILE_TRUNCATE_FAILED, + SHELF_FILE_OPEN_FAILED, + SHELF_FILE_CLOSE_FAILED, + SHELF_FILE_MAP_FAILED, + SHELF_FILE_FAM_ATOMIC_REGISTER_REGION_FAILED, + SHELF_FILE_UNMAP_FAILED, + SHELF_FILE_FOUND, + SHELF_FILE_NOT_FOUND, + SHELF_FILE_RENAME_FAILED = 30, + + SHELF_FILE_FORMAT_FAILED, + SHELF_FILE_CLEAR_FAILED, // clear the formatting + SHELF_FILE_VERIFY_FAILED, + SHELF_FILE_INVALID_FORMAT, + SHELF_FILE_RECOVER_FAILED, + SHELF_FILE_GET_PERM_FAILED, + SHELF_FILE_SET_PERM_FAILED, + + SHELF_FILE_OPENED, + SHELF_FILE_CLOSED, + + // pool (60-) + POOL_CREATE_FAILED = 60, + POOL_DESTROY_FAILED, + POOL_VERIFY_FAILED, + POOL_OPEN_FAILED, + POOL_CLOSE_FAILED, + POOL_MEMBERSHIP_FULL, + POOL_MEMBERSHIP_EMPTY, + POOL_INVALID_META_FILE, + POOL_INVALID_POOL_ID, + POOL_FOUND, + POOL_NOT_FOUND, + POOL_SHELF_FOUND, + POOL_SHELF_NOT_FOUND, + POOL_ADD_SHELF_FAILED, + POOL_REMOVE_SHELF_FAILED, + POOL_INCONSISTENCY_FOUND, + POOL_OPENED, + POOL_CLOSED, + + // membership (80-) + MEMBERSHIP_CREATE_FAILED = 80, + MEMBERSHIP_DESTROY_FAILED, + MEMBERSHIP_OPEN_FAILED, + + // Heap (100-) + HEAP_CREATE_FAILED = 100, + HEAP_DESTROY_FAILED, + HEAP_OPEN_FAILED, + HEAP_CLOSE_FAILED, + HEAP_ALLOC_FAILED, + HEAP_OPENED, + HEAP_CLOSED, + HEAP_RESIZE_FAILED, + HEAP_SET_PERMISSION_FAILED, + HEAP_GET_PERMISSION_FAILED, + HEAP_BUSY, // Some other metadata operation in progress + HEAP_NOT_OPEN, + HEAP_IS_OPEN, + + // Region (120-) + REGION_CREATE_FAILED = 120, + REGION_DESTROY_FAILED, + REGION_OPEN_FAILED, + REGION_CLOSE_FAILED, + REGION_MAP_FAILED, + REGION_UNMAP_FAILED, + REGION_OPENED, + REGION_CLOSED, + + // FreeLists (140-) + FREELISTS_CREATE_FAILED = 140, + FREELISTS_DESTROY_FAILED, + FREELISTS_OPEN_FAILED, + FREELISTS_PUT_FAILED, + FREELISTS_EMPTY, + + // Ownership (150-) + OWNERSHIP_CREATE_FAILED = 150, + OWNERSHIP_DESTROY_FAILED, + OWNERSHIP_OPEN_FAILED, + + // memory manager (200-) + ID_FOUND = 200, // this id is in use + ID_NOT_FOUND, // this id is available + ID_NOT_VALID, // This id is not valid + INVALID_PTR, + MAP_POINTER_FAILED, + SHELF_BASE_DIR_CREATE_FAILED, + SHELF_BASE_PATH_DOES_NOT_EXIST, + + // shelf manager (250-) + SHELF_ID_NOT_FOUND = 250, + + // max return code + MAX_RETURN_CODE }; } // namespace nvmm diff --git a/include/nvmm/memory_manager.h b/include/nvmm/memory_manager.h index fe45696..9389477 100644 --- a/include/nvmm/memory_manager.h +++ b/include/nvmm/memory_manager.h @@ -1,12 +1,12 @@ /* - * (c) Copyright 2016-2021 Hewlett Packard Enterprise Development Company LP. + * (c) Copyright 2016-2022 Hewlett Packard Enterprise Development Company LP. * * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the - * GNU Lesser General Public License Version 3, or (at your option) - * later with exceptions included below, or under the terms of the + * licenses. You may choose to be licensed under the terms of the + * GNU Lesser General Public License Version 3, or (at your option) + * later with exceptions included below, or under the terms of the * MIT license (Expat) available in COPYING file in the source tree. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -50,7 +50,7 @@ namespace nvmm{ // this function is NOT thread-safe/process-safe // this function must run once and only once in both single-node and multi-node environments, // before the first call to GetInstance() -void StartNVMM(std::string base="", std::string user=""); +int StartNVMM(std::string base = "", std::string user = ""); // Delete all previous shelves, resetting both the memory manager and epoch manager // this function is NOT thread-safe/process-safe diff --git a/src/common/log.cc b/src/common/log.cc index ce9fa27..d0659c8 100644 --- a/src/common/log.cc +++ b/src/common/log.cc @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include @@ -82,7 +82,7 @@ void init_log(boost::log::trivial::severity_level level, std::string file_name) if (file_name.empty()) { // Add console output // We have to provide an empty deleter to avoid destroying the global stream object - boost::shared_ptr< std::ostream > stream(&std::clog, boost::empty_deleter()); + boost::shared_ptr< std::ostream > stream(&std::clog, boost::null_deleter()); sink->locked_backend()->add_stream(stream); } else { sink->locked_backend()->add_stream(boost::make_shared< std::ofstream >(file_name)); diff --git a/src/memory_manager.cc b/src/memory_manager.cc index 116437b..bf8ed6e 100644 --- a/src/memory_manager.cc +++ b/src/memory_manager.cc @@ -1,5 +1,5 @@ /* - * (c) Copyright 2016-2021 Hewlett Packard Enterprise Development Company LP. + * (c) Copyright 2016-2022 Hewlett Packard Enterprise Development Company LP. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the @@ -23,16 +23,17 @@ * */ -#include +#include +#include +#include // for O_RDWR #include -#include +#include #include #include -#include // for O_RDWR -#include // for PROT_READ, PROT_WRITE, MAP_SHARED -#include // for getpagesize() +#include #include -#include +#include // for PROT_READ, PROT_WRITE, MAP_SHARED +#include // for getpagesize() #include "nvmm/error_code.h" #include "nvmm/shelf_id.h" // for PoolId @@ -76,48 +77,73 @@ namespace nvmm { // memory manager and epoch manager // Config config in config.cc // ShelfManager in shelf_manager.h -void StartNVMM(std::string base, std::string user) { - if(!base.empty() || !user.empty()) - config=Config(base, user); - - if (boost::filesystem::exists(config.ShelfBase) == false) - { - if(boost::filesystem::create_directory(config.ShelfBase) == false) { - std::cout << "NVMM: failed to create shelf base dir at " << config.ShelfBase << std::endl; - } - } - - // Check if shelf base exists - boost::filesystem::path shelf_base_path = boost::filesystem::path(config.ShelfBase); - if (boost::filesystem::exists(shelf_base_path) == false) - { - LOG(fatal) << "NVMM: LFS/tmpfs does not exist?" << config.ShelfBase; - exit(1); - } - - // create a root shelf for MemoryManager if it does not exist - RootShelf root_shelf(config.RootShelfPath); - if(root_shelf.Exist() == false) - { - ErrorCode ret = root_shelf.Create(); - if (ret!=NO_ERROR && ret != SHELF_FILE_FOUND) - { - LOG(fatal) << "NVMM: Failed to create the root shelf file " << config.RootShelfPath; - exit(1); - } - } - - // create a epoch shelf for EpochManager if it does not exist - EpochShelf epoch_shelf(config.EpochShelfPath); - if(epoch_shelf.Exist() == false) - { - ErrorCode ret = epoch_shelf.Create(); - if (ret!=NO_ERROR && ret != SHELF_FILE_FOUND) - { - LOG(fatal) << "NVMM: Failed to create the epoch shelf file " << config.EpochShelfPath; - exit(1); +int StartNVMM(std::string base, std::string user) { + + if (!base.empty() || !user.empty()) + config = Config(base, user); + try { + if (boost::filesystem::exists(config.ShelfBase) == false) { + try { + if (boost::filesystem::create_directory(config.ShelfBase) == false) { + LOG(fatal) << "NVMM: failed to create shelf base dir at " + << config.ShelfBase << std::endl; + std::cout << "NVMM: failed to create shelf base dir at " + << config.ShelfBase << std::endl; + return SHELF_BASE_DIR_CREATE_FAILED; } - } + } catch (boost::filesystem::filesystem_error const &err) { + LOG(fatal) << "boost::filesystem::filesystem_error error code " + << err.code(); + return err.code().value(); + } + } + } catch (boost::filesystem::filesystem_error const &err) { + LOG(fatal) << "boost::filesystem::filesystem_error error code " + << err.code(); + return err.code().value(); + } + + // Check if shelf base exists + boost::filesystem::path shelf_base_path = + boost::filesystem::path(config.ShelfBase); + try { + if (boost::filesystem::exists(shelf_base_path) == false) { + LOG(fatal) << "NVMM: LFS/tmpfs does not exist?" << config.ShelfBase; + std::cout << "NVMM: LFS/tmpfs does not exist?" << std::endl; + return SHELF_BASE_PATH_DOES_NOT_EXIST; + } + } catch (boost::filesystem::filesystem_error const &err) { + LOG(fatal) << "boost::filesystem::filesystem_error Error code " + << err.code(); + return err.code().value(); + } + + // create a root shelf for MemoryManager if it does not exist + RootShelf root_shelf(config.RootShelfPath); + if (root_shelf.Exist() == false) { + ErrorCode ret = root_shelf.Create(); + if (ret != NO_ERROR && ret != SHELF_FILE_FOUND) { + LOG(fatal) << "NVMM: Failed to create the root shelf file: error code " + << ret << config.RootShelfPath; + std::cout << "NVMM: Failed to create the root shelf file: error code " + << ret << std::endl; + return SHELF_FILE_CREATE_FAILED; + } + } + + // create a epoch shelf for EpochManager if it does not exist + EpochShelf epoch_shelf(config.EpochShelfPath); + if (epoch_shelf.Exist() == false) { + ErrorCode ret = epoch_shelf.Create(); + if (ret != NO_ERROR && ret != SHELF_FILE_FOUND) { + LOG(fatal) << "NVMM: Failed to create the epoch shelf file: error code " + << ret << config.EpochShelfPath; + std::cout << "NVMM: Failed to create the epoch shelf file: error code " + << ret << std::endl; + return SHELF_FILE_CREATE_FAILED; + } + } + return 0; } void ResetNVMM(std::string base, std::string user) {