From 06757f59ac9ef0354a822a45600bbe922ec68d0b Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 21 Sep 2020 18:36:04 +0200 Subject: [PATCH 01/15] Using different syntax for daemon program options for clang-format --- src/daemon/daemon.cpp | 45 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index f8cd9d935..999a44a41 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -412,27 +412,30 @@ int main(int argc, const char* argv[]) { // Define arg parsing po::options_description desc("Allowed options"); - desc.add_options() - ("help,h", "Help message") - ("mountdir,m", po::value()->required(), "Virtual mounting directory where GekkoFS is available.") - ("rootdir,r", po::value()->required(), - "Local data directory where GekkoFS data for this daemon is stored.") - ("metadir,i", po::value(), - "Metadata directory where GekkoFS' RocksDB data directory is located. If not set, rootdir is used.") - ("listen,l", po::value(), "Address or interface to bind the daemon to. Default: local hostname.\n" - "When used with ofi+verbs the FI_VERBS_IFACE environment variable is set accordingly " - "which associates the verbs device with the network interface. In case FI_VERBS_IFACE " - "is already defined, the argument is ignored. Default 'ib'.") - ("hosts-file,H", po::value(), - "Shared file used by deamons to register their " - "endpoints. (default './gkfs_hosts.txt')") - ("rpc-protocol,P", po::value(), "Used RPC protocol for inter-node communication.\n" - "Available: {ofi+sockets, ofi+verbs, ofi+psm2} for TCP, Infiniband, " - "and Omni-Path, respectively. (Default ofi+sockets)\n" - "Libfabric must have enabled support verbs or psm2.") - ("auto-sm", "Enables intra-node communication (IPCs) via the `na+sm` (shared memory) protocol, " - "instead of using the RPC protocol. (Default off)") - ("version", "Print version and exit."); + desc.add_options()("help,h", "Help message"); + desc.add_options()("mountdir,m", po::value()->required(), + "Virtual mounting directory where GekkoFS is available."); + desc.add_options()("rootdir,r", po::value()->required(), + "Local data directory where GekkoFS data for this daemon is stored."); + desc.add_options()( + "metadir,i", po::value(), + "Metadata directory where GekkoFS' RocksDB data directory is located. If not set, rootdir is used."); + desc.add_options()("listen,l", po::value(), + "Address or interface to bind the daemon to. Default: local hostname.\n" + "When used with ofi+verbs the FI_VERBS_IFACE environment variable is set accordingly " + "which associates the verbs device with the network interface. In case FI_VERBS_IFACE " + "is already defined, the argument is ignored. Default 'ib'."); + desc.add_options()("hosts-file,H", po::value(), + "Shared file used by deamons to register their " + "endpoints. (default './gkfs_hosts.txt')"); + desc.add_options()("rpc-protocol,P", po::value(), + "Used RPC protocol for inter-node communication.\n" + "Available: {ofi+sockets, ofi+verbs, ofi+psm2} for TCP, Infiniband, " + "and Omni-Path, respectively. (Default ofi+sockets)\n" + "Libfabric must have enabled support verbs or psm2."); + desc.add_options()("auto-sm", "Enables intra-node communication (IPCs) via the `na+sm` (shared memory) protocol, " + "instead of using the RPC protocol. (Default off)"); + desc.add_options()("version", "Print version and exit."); po::variables_map vm{}; po::store(po::parse_command_line(argc, argv, desc), vm); -- GitLab From d931fef0e8e90ad2ed0680d7f9f1b8c7b6c9d5f6 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 28 Sep 2020 18:08:02 +0200 Subject: [PATCH 02/15] Disable clang-format for syscall code due to special formatting --- include/client/syscalls/args.hpp | 5 +++++ include/client/syscalls/decoder.hpp | 5 +++++ include/client/syscalls/detail/syscall_info.h | 5 +++++ include/client/syscalls/rets.hpp | 5 +++++ include/client/syscalls/syscall.hpp | 5 +++++ src/client/syscalls/detail/syscall_info.c | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/include/client/syscalls/args.hpp b/include/client/syscalls/args.hpp index 2576cd0e4..1a5d7c238 100644 --- a/include/client/syscalls/args.hpp +++ b/include/client/syscalls/args.hpp @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT */ +// This file uses special C formatting for a better overview +// clang-format off + #ifndef GKFS_SYSCALLS_ARGS_HPP #define GKFS_SYSCALLS_ARGS_HPP @@ -722,3 +725,5 @@ format_arg_to(FmtBuffer& buffer, } // namespace gkfs #endif // GKFS_SYSCALLS_ARGS_HPP + +// clang-format on \ No newline at end of file diff --git a/include/client/syscalls/decoder.hpp b/include/client/syscalls/decoder.hpp index 475136652..aa981a96e 100644 --- a/include/client/syscalls/decoder.hpp +++ b/include/client/syscalls/decoder.hpp @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT */ +// This file uses special C formatting for a better overview +// clang-format off + #ifndef GKFS_SYSCALLS_DECODER_HPP #define GKFS_SYSCALLS_DECODER_HPP @@ -108,3 +111,5 @@ decode(FmtBuffer& buffer, } // namespace gkfs #endif // GKFS_SYSCALLS_DECODER_HPP + +// clang-format on \ No newline at end of file diff --git a/include/client/syscalls/detail/syscall_info.h b/include/client/syscalls/detail/syscall_info.h index 3969a4cd9..16608c9aa 100644 --- a/include/client/syscalls/detail/syscall_info.h +++ b/include/client/syscalls/detail/syscall_info.h @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT */ +// This file uses special C formatting for a better overview +// clang-format off + #ifndef SYSCALLS_DETAIL_SYSCALL_INFO_H #define SYSCALLS_DETAIL_SYSCALL_INFO_H @@ -83,3 +86,5 @@ syscall_never_returns(long); #endif // __cplusplus #endif // SYSCALLS_DETAIL_SYSCALL_INFO_H + +// clang-format on \ No newline at end of file diff --git a/include/client/syscalls/rets.hpp b/include/client/syscalls/rets.hpp index c9d0dadba..0767ec36d 100644 --- a/include/client/syscalls/rets.hpp +++ b/include/client/syscalls/rets.hpp @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT */ +// This file uses special C formatting for a better overview +// clang-format off + #ifndef GKFS_SYSCALLS_RETS_HPP #define GKFS_SYSCALLS_RETS_HPP @@ -134,3 +137,5 @@ format_dec_ret_to(FmtBuffer& buffer, } // namespace gkfs #endif // GKFS_SYSCALLS_RETS_HPP + +// clang-format on \ No newline at end of file diff --git a/include/client/syscalls/syscall.hpp b/include/client/syscalls/syscall.hpp index 353249fa8..b7fd79ac3 100644 --- a/include/client/syscalls/syscall.hpp +++ b/include/client/syscalls/syscall.hpp @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT */ +// This file uses special C formatting for a better overview +// clang-format off + #ifndef GKFS_SYSCALL_HPP #define GKFS_SYSCALL_HPP @@ -214,3 +217,5 @@ error_code(long result) { } // namespace gkfs #endif // GKFS_SYSCALL_HPP + +// clang-format on \ No newline at end of file diff --git a/src/client/syscalls/detail/syscall_info.c b/src/client/syscalls/detail/syscall_info.c index b4449704b..7b0d348f6 100644 --- a/src/client/syscalls/detail/syscall_info.c +++ b/src/client/syscalls/detail/syscall_info.c @@ -11,6 +11,9 @@ SPDX-License-Identifier: MIT */ +// This file uses special C formatting for a better overview +// clang-format off + #define _GNU_SOURCE #include #include @@ -925,3 +928,5 @@ syscall_never_returns(long syscall_number) { #undef S_RET #undef SYSCALL_BY_NAME #undef ARRAY_SIZE + +// clang-format on \ No newline at end of file -- GitLab From 5db506beac5047ce05d1754dfca449c21ecad6e3 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Thu, 24 Sep 2020 18:05:42 +0200 Subject: [PATCH 03/15] Adding clang-format dot config file --- .clang-format | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..803dd1a82 --- /dev/null +++ b/.clang-format @@ -0,0 +1,74 @@ +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveMacros: true +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Inline +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: false +# To be discussed. I am happy with 120, but I also use a 1440p resolution. +ColumnLimit: 120 +CompactNamespaces: false +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: true +FixNamespaceComments: true +# IncludeBlocks? TODO +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++14 +TabWidth: 4 +UseTab: Never -- GitLab From 6e5e5bd485013a1b3fb915ebe9854f449bcfc3f2 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Thu, 24 Sep 2020 16:22:51 +0200 Subject: [PATCH 04/15] Disable clang-format for *in files --- include/global/cmake_configure.hpp.in | 6 +++--- include/version.hpp.in | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/global/cmake_configure.hpp.in b/include/global/cmake_configure.hpp.in index 0a810132e..811f643be 100644 --- a/include/global/cmake_configure.hpp.in +++ b/include/global/cmake_configure.hpp.in @@ -10,11 +10,11 @@ SPDX-License-Identifier: MIT */ - +// clang-format off #ifndef GKFS_CMAKE_CONFIGURE_HPP #define GKFS_CMAKE_CONFIGURE_HPP #cmakedefine01 CREATE_CHECK_PARENTS #cmakedefine01 LOG_SYSCALLS - -#endif //FS_CMAKE_CONFIGURE_H +#endif // FS_CMAKE_CONFIGURE_H +// clang-format on diff --git a/include/version.hpp.in b/include/version.hpp.in index 736479937..6d5172540 100644 --- a/include/version.hpp.in +++ b/include/version.hpp.in @@ -10,6 +10,7 @@ SPDX-License-Identifier: MIT */ +// clang-format off #ifndef __GKFS_VERSION_HPP #define __GKFS_VERSION_HPP @@ -19,3 +20,4 @@ #define GKFS_VERSION_STRING "@GKFS_VERSION_STRING@" #endif /* __GKFS_VERSION_HPP */ +// clang-format on \ No newline at end of file -- GitLab From ea32b591aa0c7c960728769a3e54f2af02c3b02e Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Thu, 24 Sep 2020 16:28:44 +0200 Subject: [PATCH 05/15] Changing clang-format to new values as per discussion --- .clang-format | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.clang-format b/.clang-format index 803dd1a82..627ce3cfb 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,7 @@ AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveMacros: true -AlignEscapedNewlines: Right +AlignEscapedNewlines: Left AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: false @@ -55,12 +55,12 @@ ReflowComments: true SortIncludes: false SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: false +SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements +SpaceBeforeParens: Never SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 -- GitLab From afd9cb7007d37e8a907acac48711004d9bce557d Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Thu, 24 Sep 2020 17:54:03 +0200 Subject: [PATCH 06/15] clang-format: Limiting column limit to 80 --- .clang-format | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.clang-format b/.clang-format index 627ce3cfb..59e3566c0 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,7 @@ AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveMacros: true -AlignEscapedNewlines: Left +AlignEscapedNewlines: Right AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: false @@ -37,8 +37,7 @@ BreakBeforeTernaryOperators: true BreakConstructorInitializers: BeforeColon BreakInheritanceList: BeforeColon BreakStringLiterals: false -# To be discussed. I am happy with 120, but I also use a 1440p resolution. -ColumnLimit: 120 +ColumnLimit: 80 CompactNamespaces: false ContinuationIndentWidth: 8 Cpp11BracedListStyle: true -- GitLab From 5615c4aa3d3e8a998f99d11c4e5d79b980367496 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 28 Sep 2020 17:57:37 +0200 Subject: [PATCH 07/15] clang-format: AlwaysBreakAfterReturnType enabled --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 59e3566c0..5e60fd08d 100644 --- a/.clang-format +++ b/.clang-format @@ -15,7 +15,7 @@ AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: Inline AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterReturnType: None +AlwaysBreakAfterReturnType: All AlwaysBreakTemplateDeclarations: Yes BreakBeforeBraces: Custom BraceWrapping: -- GitLab From ff6d942385ecd987b6682aef8349b7da085001f5 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 28 Sep 2020 18:27:55 +0200 Subject: [PATCH 08/15] Hand formatting syscall code --- include/client/syscalls/args.hpp | 139 ++- include/client/syscalls/decoder.hpp | 26 +- include/client/syscalls/errno.hpp | 1066 ++++++++++----------- include/client/syscalls/syscall.hpp | 39 +- src/client/syscalls/detail/syscall_info.c | 31 +- 5 files changed, 632 insertions(+), 669 deletions(-) diff --git a/include/client/syscalls/args.hpp b/include/client/syscalls/args.hpp index 1a5d7c238..c706addd4 100644 --- a/include/client/syscalls/args.hpp +++ b/include/client/syscalls/args.hpp @@ -76,7 +76,7 @@ static constexpr auto generic = type::generic; /** An argument value with an optional size */ struct printable_arg { - const char * const name; + const char* const name; const long value; boost::optional size; }; @@ -84,9 +84,7 @@ struct printable_arg { /** All arg formatters must follow this prototype */ template -using formatter = - std::add_pointer_t; - +using formatter = std::add_pointer_t; /** forward declare formatters */ @@ -108,7 +106,7 @@ format_open_flags_to(FmtBuffer& buffer, const printable_arg& parg); template inline void format_octal_mode_to(FmtBuffer& buffer, const printable_arg& parg); -template inline void +template inline void format_ptr_arg_to(FmtBuffer& buffer, const printable_arg& parg); template inline void @@ -164,7 +162,7 @@ std::array, arg_type_max> formatters = { /** An argument descriptor */ struct desc { - arg::type type_; + arg::type type_; const char* name_; arg::type @@ -209,13 +207,11 @@ typedef struct { template static void -format_flag(FmtBuffer& buffer, - long flag, - FlagDescriptorArray&& desc) { +format_flag(FmtBuffer& buffer, long flag, FlagDescriptorArray&& desc) { // we assume that if a flag value is zero, its printable // name will always be at position 0 in the array - if(flag == 0 && desc[0].flag_ == 0) { + if(flag == 0 && desc[0].flag_ == 0) { fmt::format_to(buffer, "{}", desc[0].name_); return; } @@ -237,62 +233,59 @@ format_flag(FmtBuffer& buffer, template static void -format_flag_set(FmtBuffer& buffer, - long flags, - FlagDescriptorArray&& desc) { +format_flag_set(FmtBuffer& buffer, long flags, FlagDescriptorArray&& desc) { // we assume that if a flag value is zero, its printable // name will always be at position 0 in the array - if(flags == 0 && desc[0].flag_ == 0) { + if(flags == 0 && desc[0].flag_ == 0) { fmt::format_to(buffer, "{}", desc[0].name_); return; } std::size_t i = 0; - const auto buffer_start = buffer.size(); + const auto buffer_start = buffer.size(); - while(flags != 0 && i < desc.size()) { + while(flags != 0 && i < desc.size()) { - if(desc[i].name_ == nullptr) { + if(desc[i].name_ == nullptr) { ++i; - continue; + continue; } if((flags & desc[i].flag_) != 0) { - fmt::format_to(buffer, "{}{}", - buffer.size() != buffer_start ? "|" : "", - desc[i].name_); + fmt::format_to(buffer, "{}{}", + buffer.size() != buffer_start ? "|" : "", + desc[i].name_); flags &= ~desc[i].flag_; } ++i; } - if(flags != 0) { - if(buffer.size() != buffer_start) { + if(flags != 0) { + if(buffer.size() != buffer_start) { fmt::format_to(buffer, "|"); } fmt::format_to(buffer, "{:#x}", flags); return; - } + } - if(buffer_start == buffer.size()) { + if(buffer_start == buffer.size()) { fmt::format_to(buffer, "0x0"); } } -/** +/** * format_whence_arg_to - format a 'whence' argument * * Format a 'whence' argument from the lseek() syscall, modifying the provided * buffer by appending to it a string representation of the form: - * name = formatted_val + * name = formatted_val */ -template +template inline void -format_whence_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_whence_arg_to(FmtBuffer& buffer, const printable_arg& parg) { /* Names for lseek() whence arg */ const auto flag_names = @@ -307,16 +300,15 @@ format_whence_arg_to(FmtBuffer& buffer, } -/** +/** * format_mmap_prot_arg_to - format a 'prot' argument * * Format a 'prot' argument (such as those passed to mmap()) * and append the resulting string to the provided buffer. */ -template +template inline void -format_mmap_prot_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_mmap_prot_arg_to(FmtBuffer& buffer, const printable_arg& parg) { /* Names for mmap() prot arg */ const auto flag_names = @@ -333,16 +325,15 @@ format_mmap_prot_arg_to(FmtBuffer& buffer, } -/** +/** * format_mmap_flags_arg_to - format a 'flags' argument * * Format a 'flags' argument (such as those passed to mmap()) * and append the resulting string to the provided buffer. */ -template +template inline void -format_mmap_flags_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_mmap_flags_arg_to(FmtBuffer& buffer, const printable_arg& parg) { /* Names for mmap() flags arg */ const auto flag_names = @@ -374,16 +365,15 @@ format_mmap_flags_arg_to(FmtBuffer& buffer, return; } -/** +/** * format_clone_flags_arg_to - format a 'flags' argument * * Format a 'flags' argument (such as those passed to clone()) * and append the resulting string to the provided buffer. */ -template +template inline void -format_clone_flags_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_clone_flags_arg_to(FmtBuffer& buffer, const printable_arg& parg) { /* Names for clone() flags arg */ const auto flag_names = @@ -416,7 +406,7 @@ format_clone_flags_arg_to(FmtBuffer& buffer, fmt::format_to(buffer, "{}=", parg.name); - // the low byte in clone flags contains the number of the termination + // the low byte in clone flags contains the number of the termination // signal sent to the parent when the child dies format_flag_set(buffer, parg.value & ~0x11l, flag_names); @@ -427,7 +417,7 @@ format_clone_flags_arg_to(FmtBuffer& buffer, return; } -/** +/** * format_signum_arg_to - format a 'signum' argument * * Format a 'signum' argument (such as those passed to rt_sigaction()) @@ -435,8 +425,7 @@ format_clone_flags_arg_to(FmtBuffer& buffer, */ template inline void -format_signum_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_signum_arg_to(FmtBuffer& buffer, const printable_arg& parg) { /* Names for signum args */ const auto flag_names = @@ -482,7 +471,7 @@ format_signum_arg_to(FmtBuffer& buffer, } -/** +/** * format_sigproc_how_arg_to - format a 'sigproc how' argument * * Format a 'sigproc how' argument (such as those passed to sigprocmask()) @@ -490,8 +479,7 @@ format_signum_arg_to(FmtBuffer& buffer, */ template inline void -format_sigproc_how_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_sigproc_how_arg_to(FmtBuffer& buffer, const printable_arg& parg) { /* Names for sigproc how args */ const auto flag_names = @@ -513,13 +501,12 @@ format_sigproc_how_arg_to(FmtBuffer& buffer, */ template inline void -format_none_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_none_arg_to(FmtBuffer& buffer, const printable_arg& parg) { fmt::format_to(buffer, "void"); } -/** +/** * format_fd_arg_to - format a 'fd' argument * * Format a 'fd' argument (such as those passed to read()) @@ -527,13 +514,12 @@ format_none_arg_to(FmtBuffer& buffer, */ template inline void -format_fd_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_fd_arg_to(FmtBuffer& buffer, const printable_arg& parg) { fmt::format_to(buffer, "{}={}", parg.name, static_cast(parg.value)); } -/** +/** * format_atfd_arg_to - format a 'at_fd' argument * * Format a 'at_fd' argument (such as those passed to openat()) @@ -541,8 +527,7 @@ format_fd_arg_to(FmtBuffer& buffer, */ template inline void -format_atfd_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_atfd_arg_to(FmtBuffer& buffer, const printable_arg& parg) { if(static_cast(parg.value) == AT_FDCWD) { fmt::format_to(buffer, "{}=AT_FDCWD", parg.name); @@ -553,7 +538,7 @@ format_atfd_arg_to(FmtBuffer& buffer, } -/** +/** * format_cstr_arg_to - format a 'cstr' argument * * Format a 'cstr' argument (i.e. a null-terminated C string) @@ -561,11 +546,10 @@ format_atfd_arg_to(FmtBuffer& buffer, */ template inline void -format_cstr_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_cstr_arg_to(FmtBuffer& buffer, const printable_arg& parg) { if(LIKELY(reinterpret_cast(parg.value) != nullptr)) { - fmt::format_to(buffer, "{}=\"{}\"", parg.name, + fmt::format_to(buffer, "{}=\"{}\"", parg.name, reinterpret_cast(parg.value)); return; } @@ -629,9 +613,9 @@ format_open_flags_to(FmtBuffer& buffer, // // See O_TMPFILE' definition in fcntl-linux.h : // #define __O_TMPFILE (020000000 | __O_DIRECTORY) - if ((flags & O_TMPFILE) == O_TMPFILE) { + if((flags & O_TMPFILE) == O_TMPFILE) { format_flag(buffer, O_TMPFILE, flag_names); - flags &= ~O_TMPFILE; + flags &= ~O_TMPFILE; } #endif // !O_TMPFILE @@ -641,7 +625,7 @@ format_open_flags_to(FmtBuffer& buffer, } } -/** +/** * format_octal_mode_to - format a 'mode' argument * * Format a 'mode' argument (such as those passed to open()) and append the @@ -649,12 +633,11 @@ format_open_flags_to(FmtBuffer& buffer, */ template inline void -format_octal_mode_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_octal_mode_to(FmtBuffer& buffer, const printable_arg& parg) { fmt::format_to(buffer, "{}={:#04o}", parg.name, parg.value); } -/** +/** * format_ptr_arg_to - format a 'ptr' argument * * Format a 'ptr' argument (i.e. a C pointer) @@ -662,11 +645,10 @@ format_octal_mode_to(FmtBuffer& buffer, */ template inline void -format_ptr_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_ptr_arg_to(FmtBuffer& buffer, const printable_arg& parg) { if(LIKELY(reinterpret_cast(parg.value) != nullptr)) { - fmt::format_to(buffer, "{}={}", parg.name, + fmt::format_to(buffer, "{}={}", parg.name, reinterpret_cast(parg.value)); return; } @@ -675,7 +657,7 @@ format_ptr_arg_to(FmtBuffer& buffer, } -/** +/** * format_dec_arg_to - format a 'dec' argument * * Format a 'dec' argument (i.e. an integer of unknwon size) @@ -683,13 +665,12 @@ format_ptr_arg_to(FmtBuffer& buffer, */ template inline void -format_dec_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_dec_arg_to(FmtBuffer& buffer, const printable_arg& parg) { fmt::format_to(buffer, "{}={}", parg.name, parg.value); } -/** +/** * format_dec32_arg_to - format a 'dec32' argument * * Format a 'dec32' argument (i.e. a 32-bit integer) @@ -697,22 +678,20 @@ format_dec_arg_to(FmtBuffer& buffer, */ template inline void -format_dec32_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_dec32_arg_to(FmtBuffer& buffer, const printable_arg& parg) { fmt::format_to(buffer, "{}={}", parg.name, static_cast(parg.value)); } -/** +/** * format_arg_to - format an arbitrary argument * - * Format an arbitrary argument and append the resulting + * Format an arbitrary argument and append the resulting * string to the provided buffer. */ template inline void -format_arg_to(FmtBuffer& buffer, - const printable_arg& parg) { +format_arg_to(FmtBuffer& buffer, const printable_arg& parg) { fmt::format_to(buffer, "{}={:#x}", parg.name, parg.value); } diff --git a/include/client/syscalls/decoder.hpp b/include/client/syscalls/decoder.hpp index aa981a96e..d75491ca0 100644 --- a/include/client/syscalls/decoder.hpp +++ b/include/client/syscalls/decoder.hpp @@ -11,9 +11,6 @@ SPDX-License-Identifier: MIT */ -// This file uses special C formatting for a better overview -// clang-format off - #ifndef GKFS_SYSCALLS_DECODER_HPP #define GKFS_SYSCALLS_DECODER_HPP @@ -28,8 +25,7 @@ namespace detail { /** a RAII saver/restorer of errno values */ struct errno_saver { - errno_saver(int errnum) : - saved_errno_(errnum) { } + errno_saver(int errnum) : saved_errno_(errnum) {} ~errno_saver() { errno = saved_errno_; @@ -42,8 +38,7 @@ struct errno_saver { template inline void -decode(FmtBuffer& buffer, - const long syscall_number, +decode(FmtBuffer& buffer, const long syscall_number, const long argv[MAX_ARGS]) { detail::errno_saver _(errno); @@ -67,9 +62,7 @@ decode(FmtBuffer& buffer, template inline void -decode(FmtBuffer& buffer, - const long syscall_number, - const long argv[MAX_ARGS], +decode(FmtBuffer& buffer, const long syscall_number, const long argv[MAX_ARGS], const long result) { detail::errno_saver _(errno); @@ -93,23 +86,18 @@ decode(FmtBuffer& buffer, return; } - if(error_code(result) != 0) { - fmt::format_to(buffer, ") = {} {} ({})", - static_cast(-1), - errno_name(-result), - errno_message(-result)); + if(error_code(result) != 0) { + fmt::format_to(buffer, ") = {} {} ({})", static_cast(-1), + errno_name(-result), errno_message(-result)); return; } fmt::format_to(buffer, ") = "); const auto& ret = sc.return_type(); ret.formatter()(buffer, result); - } } // namespace syscall } // namespace gkfs -#endif // GKFS_SYSCALLS_DECODER_HPP - -// clang-format on \ No newline at end of file +#endif // GKFS_SYSCALLS_DECODER_HPP \ No newline at end of file diff --git a/include/client/syscalls/errno.hpp b/include/client/syscalls/errno.hpp index 4a1ae650e..31ee96af7 100644 --- a/include/client/syscalls/errno.hpp +++ b/include/client/syscalls/errno.hpp @@ -21,540 +21,540 @@ namespace gkfs { namespace syscall { static const std::array errno_names = { - /* [ 0] = */ NULL, - /* [ 1] = */ "EPERM", - /* [ 2] = */ "ENOENT", - /* [ 3] = */ "ESRCH", - /* [ 4] = */ "EINTR", - /* [ 5] = */ "EIO", - /* [ 6] = */ "ENXIO", - /* [ 7] = */ "E2BIG", - /* [ 8] = */ "ENOEXEC", - /* [ 9] = */ "EBADF", - /* [ 10] = */ "ECHILD", - /* [ 11] = */ "EAGAIN", - /* [ 12] = */ "ENOMEM", - /* [ 13] = */ "EACCES", - /* [ 14] = */ "EFAULT", - /* [ 15] = */ "ENOTBLK", - /* [ 16] = */ "EBUSY", - /* [ 17] = */ "EEXIST", - /* [ 18] = */ "EXDEV", - /* [ 19] = */ "ENODEV", - /* [ 20] = */ "ENOTDIR", - /* [ 21] = */ "EISDIR", - /* [ 22] = */ "EINVAL", - /* [ 23] = */ "ENFILE", - /* [ 24] = */ "EMFILE", - /* [ 25] = */ "ENOTTY", - /* [ 26] = */ "ETXTBSY", - /* [ 27] = */ "EFBIG", - /* [ 28] = */ "ENOSPC", - /* [ 29] = */ "ESPIPE", - /* [ 30] = */ "EROFS", - /* [ 31] = */ "EMLINK", - /* [ 32] = */ "EPIPE", - /* [ 33] = */ "EDOM", - /* [ 34] = */ "ERANGE", - /* [ 35] = */ "EDEADLK", - /* [ 36] = */ "ENAMETOOLONG", - /* [ 37] = */ "ENOLCK", - /* [ 38] = */ "ENOSYS", - /* [ 39] = */ "ENOTEMPTY", - /* [ 40] = */ "ELOOP", - /* [ 41] = */ NULL, - /* [ 42] = */ "ENOMSG", - /* [ 43] = */ "EIDRM", - /* [ 44] = */ "ECHRNG", - /* [ 45] = */ "EL2NSYNC", - /* [ 46] = */ "EL3HLT", - /* [ 47] = */ "EL3RST", - /* [ 48] = */ "ELNRNG", - /* [ 49] = */ "EUNATCH", - /* [ 50] = */ "ENOCSI", - /* [ 51] = */ "EL2HLT", - /* [ 52] = */ "EBADE", - /* [ 53] = */ "EBADR", - /* [ 54] = */ "EXFULL", - /* [ 55] = */ "ENOANO", - /* [ 56] = */ "EBADRQC", - /* [ 57] = */ "EBADSLT", - /* [ 58] = */ NULL, - /* [ 59] = */ "EBFONT", - /* [ 60] = */ "ENOSTR", - /* [ 61] = */ "ENODATA", - /* [ 62] = */ "ETIME", - /* [ 63] = */ "ENOSR", - /* [ 64] = */ "ENONET", - /* [ 65] = */ "ENOPKG", - /* [ 66] = */ "EREMOTE", - /* [ 67] = */ "ENOLINK", - /* [ 68] = */ "EADV", - /* [ 69] = */ "ESRMNT", - /* [ 70] = */ "ECOMM", - /* [ 71] = */ "EPROTO", - /* [ 72] = */ "EMULTIHOP", - /* [ 73] = */ "EDOTDOT", - /* [ 74] = */ "EBADMSG", - /* [ 75] = */ "EOVERFLOW", - /* [ 76] = */ "ENOTUNIQ", - /* [ 77] = */ "EBADFD", - /* [ 78] = */ "EREMCHG", - /* [ 79] = */ "ELIBACC", - /* [ 80] = */ "ELIBBAD", - /* [ 81] = */ "ELIBSCN", - /* [ 82] = */ "ELIBMAX", - /* [ 83] = */ "ELIBEXEC", - /* [ 84] = */ "EILSEQ", - /* [ 85] = */ "ERESTART", - /* [ 86] = */ "ESTRPIPE", - /* [ 87] = */ "EUSERS", - /* [ 88] = */ "ENOTSOCK", - /* [ 89] = */ "EDESTADDRREQ", - /* [ 90] = */ "EMSGSIZE", - /* [ 91] = */ "EPROTOTYPE", - /* [ 92] = */ "ENOPROTOOPT", - /* [ 93] = */ "EPROTONOSUPPORT", - /* [ 94] = */ "ESOCKTNOSUPPORT", - /* [ 95] = */ "EOPNOTSUPP", - /* [ 96] = */ "EPFNOSUPPORT", - /* [ 97] = */ "EAFNOSUPPORT", - /* [ 98] = */ "EADDRINUSE", - /* [ 99] = */ "EADDRNOTAVAIL", - /* [100] = */ "ENETDOWN", - /* [101] = */ "ENETUNREACH", - /* [102] = */ "ENETRESET", - /* [103] = */ "ECONNABORTED", - /* [104] = */ "ECONNRESET", - /* [105] = */ "ENOBUFS", - /* [106] = */ "EISCONN", - /* [107] = */ "ENOTCONN", - /* [108] = */ "ESHUTDOWN", - /* [109] = */ "ETOOMANYREFS", - /* [110] = */ "ETIMEDOUT", - /* [111] = */ "ECONNREFUSED", - /* [112] = */ "EHOSTDOWN", - /* [113] = */ "EHOSTUNREACH", - /* [114] = */ "EALREADY", - /* [115] = */ "EINPROGRESS", - /* [116] = */ "ESTALE", - /* [117] = */ "EUCLEAN", - /* [118] = */ "ENOTNAM", - /* [119] = */ "ENAVAIL", - /* [120] = */ "EISNAM", - /* [121] = */ "EREMOTEIO", - /* [122] = */ "EDQUOT", - /* [123] = */ "ENOMEDIUM", - /* [124] = */ "EMEDIUMTYPE", - /* [125] = */ "ECANCELED", - /* [126] = */ "ENOKEY", - /* [127] = */ "EKEYEXPIRED", - /* [128] = */ "EKEYREVOKED", - /* [129] = */ "EKEYREJECTED", - /* [130] = */ "EOWNERDEAD", - /* [131] = */ "ENOTRECOVERABLE", - /* [132] = */ "ERFKILL", - /* [133] = */ "EHWPOISON", - /* [134] = */ NULL, - /* [135] = */ NULL, - /* [136] = */ NULL, - /* [137] = */ NULL, - /* [138] = */ NULL, - /* [139] = */ NULL, - /* [140] = */ NULL, - /* [141] = */ NULL, - /* [142] = */ NULL, - /* [143] = */ NULL, - /* [144] = */ NULL, - /* [145] = */ NULL, - /* [146] = */ NULL, - /* [147] = */ NULL, - /* [148] = */ NULL, - /* [149] = */ NULL, - /* [150] = */ NULL, - /* [151] = */ NULL, - /* [152] = */ NULL, - /* [153] = */ NULL, - /* [154] = */ NULL, - /* [155] = */ NULL, - /* [156] = */ NULL, - /* [157] = */ NULL, - /* [158] = */ NULL, - /* [159] = */ NULL, - /* [160] = */ NULL, - /* [161] = */ NULL, - /* [162] = */ NULL, - /* [163] = */ NULL, - /* [164] = */ NULL, - /* [165] = */ NULL, - /* [166] = */ NULL, - /* [167] = */ NULL, - /* [168] = */ NULL, - /* [169] = */ NULL, - /* [170] = */ NULL, - /* [171] = */ NULL, - /* [172] = */ NULL, - /* [173] = */ NULL, - /* [174] = */ NULL, - /* [175] = */ NULL, - /* [176] = */ NULL, - /* [177] = */ NULL, - /* [178] = */ NULL, - /* [179] = */ NULL, - /* [180] = */ NULL, - /* [181] = */ NULL, - /* [182] = */ NULL, - /* [183] = */ NULL, - /* [184] = */ NULL, - /* [185] = */ NULL, - /* [186] = */ NULL, - /* [187] = */ NULL, - /* [188] = */ NULL, - /* [189] = */ NULL, - /* [190] = */ NULL, - /* [191] = */ NULL, - /* [192] = */ NULL, - /* [193] = */ NULL, - /* [194] = */ NULL, - /* [195] = */ NULL, - /* [196] = */ NULL, - /* [197] = */ NULL, - /* [198] = */ NULL, - /* [199] = */ NULL, - /* [200] = */ NULL, - /* [201] = */ NULL, - /* [202] = */ NULL, - /* [203] = */ NULL, - /* [204] = */ NULL, - /* [205] = */ NULL, - /* [206] = */ NULL, - /* [207] = */ NULL, - /* [208] = */ NULL, - /* [209] = */ NULL, - /* [210] = */ NULL, - /* [211] = */ NULL, - /* [212] = */ NULL, - /* [213] = */ NULL, - /* [214] = */ NULL, - /* [215] = */ NULL, - /* [216] = */ NULL, - /* [217] = */ NULL, - /* [218] = */ NULL, - /* [219] = */ NULL, - /* [220] = */ NULL, - /* [221] = */ NULL, - /* [222] = */ NULL, - /* [223] = */ NULL, - /* [224] = */ NULL, - /* [225] = */ NULL, - /* [226] = */ NULL, - /* [227] = */ NULL, - /* [228] = */ NULL, - /* [229] = */ NULL, - /* [230] = */ NULL, - /* [231] = */ NULL, - /* [232] = */ NULL, - /* [233] = */ NULL, - /* [234] = */ NULL, - /* [235] = */ NULL, - /* [236] = */ NULL, - /* [237] = */ NULL, - /* [238] = */ NULL, - /* [239] = */ NULL, - /* [240] = */ NULL, - /* [241] = */ NULL, - /* [242] = */ NULL, - /* [243] = */ NULL, - /* [244] = */ NULL, - /* [245] = */ NULL, - /* [246] = */ NULL, - /* [247] = */ NULL, - /* [248] = */ NULL, - /* [249] = */ NULL, - /* [250] = */ NULL, - /* [251] = */ NULL, - /* [252] = */ NULL, - /* [253] = */ NULL, - /* [254] = */ NULL, - /* [255] = */ NULL, - /* [256] = */ NULL, - /* [257] = */ NULL, - /* [258] = */ NULL, - /* [259] = */ NULL, - /* [260] = */ NULL, - /* [261] = */ NULL, - /* [262] = */ NULL, - /* [263] = */ NULL, - /* [264] = */ NULL, - /* [265] = */ NULL, - /* [266] = */ NULL, - /* [267] = */ NULL, - /* [268] = */ NULL, - /* [269] = */ NULL, - /* [270] = */ NULL, - /* [271] = */ NULL, - /* [272] = */ NULL, - /* [273] = */ NULL, - /* [274] = */ NULL, - /* [275] = */ NULL, - /* [276] = */ NULL, - /* [277] = */ NULL, - /* [278] = */ NULL, - /* [279] = */ NULL, - /* [280] = */ NULL, - /* [281] = */ NULL, - /* [282] = */ NULL, - /* [283] = */ NULL, - /* [284] = */ NULL, - /* [285] = */ NULL, - /* [286] = */ NULL, - /* [287] = */ NULL, - /* [288] = */ NULL, - /* [289] = */ NULL, - /* [290] = */ NULL, - /* [291] = */ NULL, - /* [292] = */ NULL, - /* [293] = */ NULL, - /* [294] = */ NULL, - /* [295] = */ NULL, - /* [296] = */ NULL, - /* [297] = */ NULL, - /* [298] = */ NULL, - /* [299] = */ NULL, - /* [300] = */ NULL, - /* [301] = */ NULL, - /* [302] = */ NULL, - /* [303] = */ NULL, - /* [304] = */ NULL, - /* [305] = */ NULL, - /* [306] = */ NULL, - /* [307] = */ NULL, - /* [308] = */ NULL, - /* [309] = */ NULL, - /* [310] = */ NULL, - /* [311] = */ NULL, - /* [312] = */ NULL, - /* [313] = */ NULL, - /* [314] = */ NULL, - /* [315] = */ NULL, - /* [316] = */ NULL, - /* [317] = */ NULL, - /* [318] = */ NULL, - /* [319] = */ NULL, - /* [320] = */ NULL, - /* [321] = */ NULL, - /* [322] = */ NULL, - /* [323] = */ NULL, - /* [324] = */ NULL, - /* [325] = */ NULL, - /* [326] = */ NULL, - /* [327] = */ NULL, - /* [328] = */ NULL, - /* [329] = */ NULL, - /* [330] = */ NULL, - /* [331] = */ NULL, - /* [332] = */ NULL, - /* [333] = */ NULL, - /* [334] = */ NULL, - /* [335] = */ NULL, - /* [336] = */ NULL, - /* [337] = */ NULL, - /* [338] = */ NULL, - /* [339] = */ NULL, - /* [340] = */ NULL, - /* [341] = */ NULL, - /* [342] = */ NULL, - /* [343] = */ NULL, - /* [344] = */ NULL, - /* [345] = */ NULL, - /* [346] = */ NULL, - /* [347] = */ NULL, - /* [348] = */ NULL, - /* [349] = */ NULL, - /* [350] = */ NULL, - /* [351] = */ NULL, - /* [352] = */ NULL, - /* [353] = */ NULL, - /* [354] = */ NULL, - /* [355] = */ NULL, - /* [356] = */ NULL, - /* [357] = */ NULL, - /* [358] = */ NULL, - /* [359] = */ NULL, - /* [360] = */ NULL, - /* [361] = */ NULL, - /* [362] = */ NULL, - /* [363] = */ NULL, - /* [364] = */ NULL, - /* [365] = */ NULL, - /* [366] = */ NULL, - /* [367] = */ NULL, - /* [368] = */ NULL, - /* [369] = */ NULL, - /* [370] = */ NULL, - /* [371] = */ NULL, - /* [372] = */ NULL, - /* [373] = */ NULL, - /* [374] = */ NULL, - /* [375] = */ NULL, - /* [376] = */ NULL, - /* [377] = */ NULL, - /* [378] = */ NULL, - /* [379] = */ NULL, - /* [380] = */ NULL, - /* [381] = */ NULL, - /* [382] = */ NULL, - /* [383] = */ NULL, - /* [384] = */ NULL, - /* [385] = */ NULL, - /* [386] = */ NULL, - /* [387] = */ NULL, - /* [388] = */ NULL, - /* [389] = */ NULL, - /* [390] = */ NULL, - /* [391] = */ NULL, - /* [392] = */ NULL, - /* [393] = */ NULL, - /* [394] = */ NULL, - /* [395] = */ NULL, - /* [396] = */ NULL, - /* [397] = */ NULL, - /* [398] = */ NULL, - /* [399] = */ NULL, - /* [400] = */ NULL, - /* [401] = */ NULL, - /* [402] = */ NULL, - /* [403] = */ NULL, - /* [404] = */ NULL, - /* [405] = */ NULL, - /* [406] = */ NULL, - /* [407] = */ NULL, - /* [408] = */ NULL, - /* [409] = */ NULL, - /* [410] = */ NULL, - /* [411] = */ NULL, - /* [412] = */ NULL, - /* [413] = */ NULL, - /* [414] = */ NULL, - /* [415] = */ NULL, - /* [416] = */ NULL, - /* [417] = */ NULL, - /* [418] = */ NULL, - /* [419] = */ NULL, - /* [420] = */ NULL, - /* [421] = */ NULL, - /* [422] = */ NULL, - /* [423] = */ NULL, - /* [424] = */ NULL, - /* [425] = */ NULL, - /* [426] = */ NULL, - /* [427] = */ NULL, - /* [428] = */ NULL, - /* [429] = */ NULL, - /* [430] = */ NULL, - /* [431] = */ NULL, - /* [432] = */ NULL, - /* [433] = */ NULL, - /* [434] = */ NULL, - /* [435] = */ NULL, - /* [436] = */ NULL, - /* [437] = */ NULL, - /* [438] = */ NULL, - /* [439] = */ NULL, - /* [440] = */ NULL, - /* [441] = */ NULL, - /* [442] = */ NULL, - /* [443] = */ NULL, - /* [444] = */ NULL, - /* [445] = */ NULL, - /* [446] = */ NULL, - /* [447] = */ NULL, - /* [448] = */ NULL, - /* [449] = */ NULL, - /* [450] = */ NULL, - /* [451] = */ NULL, - /* [452] = */ NULL, - /* [453] = */ NULL, - /* [454] = */ NULL, - /* [455] = */ NULL, - /* [456] = */ NULL, - /* [457] = */ NULL, - /* [458] = */ NULL, - /* [459] = */ NULL, - /* [460] = */ NULL, - /* [461] = */ NULL, - /* [462] = */ NULL, - /* [463] = */ NULL, - /* [464] = */ NULL, - /* [465] = */ NULL, - /* [466] = */ NULL, - /* [467] = */ NULL, - /* [468] = */ NULL, - /* [469] = */ NULL, - /* [470] = */ NULL, - /* [471] = */ NULL, - /* [472] = */ NULL, - /* [473] = */ NULL, - /* [474] = */ NULL, - /* [475] = */ NULL, - /* [476] = */ NULL, - /* [477] = */ NULL, - /* [478] = */ NULL, - /* [479] = */ NULL, - /* [480] = */ NULL, - /* [481] = */ NULL, - /* [482] = */ NULL, - /* [483] = */ NULL, - /* [484] = */ NULL, - /* [485] = */ NULL, - /* [486] = */ NULL, - /* [487] = */ NULL, - /* [488] = */ NULL, - /* [489] = */ NULL, - /* [490] = */ NULL, - /* [491] = */ NULL, - /* [492] = */ NULL, - /* [493] = */ NULL, - /* [494] = */ NULL, - /* [495] = */ NULL, - /* [496] = */ NULL, - /* [497] = */ NULL, - /* [498] = */ NULL, - /* [499] = */ NULL, - /* [500] = */ NULL, - /* [501] = */ NULL, - /* [502] = */ NULL, - /* [503] = */ NULL, - /* [504] = */ NULL, - /* [505] = */ NULL, - /* [506] = */ NULL, - /* [507] = */ NULL, - /* [508] = */ NULL, - /* [509] = */ NULL, - /* [510] = */ NULL, - /* [511] = */ NULL, - /* [512] = */ "ERESTARTSYS", - /* [513] = */ "ERESTARTNOINTR", - /* [514] = */ "ERESTARTNOHAND", - /* [515] = */ "ENOIOCTLCMD", - /* [516] = */ "ERESTART_RESTARTBLOCK", - /* [517] = */ "EPROBE_DEFER", - /* [518] = */ "EOPENSTALE", - /* [519] = */ NULL, - /* [520] = */ NULL, - /* [521] = */ "EBADHANDLE", - /* [522] = */ "ENOTSYNC", - /* [523] = */ "EBADCOOKIE", - /* [524] = */ "ENOTSUPP", - /* [525] = */ "ETOOSMALL", - /* [526] = */ "ESERVERFAULT", - /* [527] = */ "EBADTYPE", - /* [528] = */ "EJUKEBOX", - /* [529] = */ "EIOCBQUEUED", - /* [530] = */ "ERECALLCONFLICT", + /* [ 0] = */ NULL, + /* [ 1] = */ "EPERM", + /* [ 2] = */ "ENOENT", + /* [ 3] = */ "ESRCH", + /* [ 4] = */ "EINTR", + /* [ 5] = */ "EIO", + /* [ 6] = */ "ENXIO", + /* [ 7] = */ "E2BIG", + /* [ 8] = */ "ENOEXEC", + /* [ 9] = */ "EBADF", + /* [ 10] = */ "ECHILD", + /* [ 11] = */ "EAGAIN", + /* [ 12] = */ "ENOMEM", + /* [ 13] = */ "EACCES", + /* [ 14] = */ "EFAULT", + /* [ 15] = */ "ENOTBLK", + /* [ 16] = */ "EBUSY", + /* [ 17] = */ "EEXIST", + /* [ 18] = */ "EXDEV", + /* [ 19] = */ "ENODEV", + /* [ 20] = */ "ENOTDIR", + /* [ 21] = */ "EISDIR", + /* [ 22] = */ "EINVAL", + /* [ 23] = */ "ENFILE", + /* [ 24] = */ "EMFILE", + /* [ 25] = */ "ENOTTY", + /* [ 26] = */ "ETXTBSY", + /* [ 27] = */ "EFBIG", + /* [ 28] = */ "ENOSPC", + /* [ 29] = */ "ESPIPE", + /* [ 30] = */ "EROFS", + /* [ 31] = */ "EMLINK", + /* [ 32] = */ "EPIPE", + /* [ 33] = */ "EDOM", + /* [ 34] = */ "ERANGE", + /* [ 35] = */ "EDEADLK", + /* [ 36] = */ "ENAMETOOLONG", + /* [ 37] = */ "ENOLCK", + /* [ 38] = */ "ENOSYS", + /* [ 39] = */ "ENOTEMPTY", + /* [ 40] = */ "ELOOP", + /* [ 41] = */ NULL, + /* [ 42] = */ "ENOMSG", + /* [ 43] = */ "EIDRM", + /* [ 44] = */ "ECHRNG", + /* [ 45] = */ "EL2NSYNC", + /* [ 46] = */ "EL3HLT", + /* [ 47] = */ "EL3RST", + /* [ 48] = */ "ELNRNG", + /* [ 49] = */ "EUNATCH", + /* [ 50] = */ "ENOCSI", + /* [ 51] = */ "EL2HLT", + /* [ 52] = */ "EBADE", + /* [ 53] = */ "EBADR", + /* [ 54] = */ "EXFULL", + /* [ 55] = */ "ENOANO", + /* [ 56] = */ "EBADRQC", + /* [ 57] = */ "EBADSLT", + /* [ 58] = */ NULL, + /* [ 59] = */ "EBFONT", + /* [ 60] = */ "ENOSTR", + /* [ 61] = */ "ENODATA", + /* [ 62] = */ "ETIME", + /* [ 63] = */ "ENOSR", + /* [ 64] = */ "ENONET", + /* [ 65] = */ "ENOPKG", + /* [ 66] = */ "EREMOTE", + /* [ 67] = */ "ENOLINK", + /* [ 68] = */ "EADV", + /* [ 69] = */ "ESRMNT", + /* [ 70] = */ "ECOMM", + /* [ 71] = */ "EPROTO", + /* [ 72] = */ "EMULTIHOP", + /* [ 73] = */ "EDOTDOT", + /* [ 74] = */ "EBADMSG", + /* [ 75] = */ "EOVERFLOW", + /* [ 76] = */ "ENOTUNIQ", + /* [ 77] = */ "EBADFD", + /* [ 78] = */ "EREMCHG", + /* [ 79] = */ "ELIBACC", + /* [ 80] = */ "ELIBBAD", + /* [ 81] = */ "ELIBSCN", + /* [ 82] = */ "ELIBMAX", + /* [ 83] = */ "ELIBEXEC", + /* [ 84] = */ "EILSEQ", + /* [ 85] = */ "ERESTART", + /* [ 86] = */ "ESTRPIPE", + /* [ 87] = */ "EUSERS", + /* [ 88] = */ "ENOTSOCK", + /* [ 89] = */ "EDESTADDRREQ", + /* [ 90] = */ "EMSGSIZE", + /* [ 91] = */ "EPROTOTYPE", + /* [ 92] = */ "ENOPROTOOPT", + /* [ 93] = */ "EPROTONOSUPPORT", + /* [ 94] = */ "ESOCKTNOSUPPORT", + /* [ 95] = */ "EOPNOTSUPP", + /* [ 96] = */ "EPFNOSUPPORT", + /* [ 97] = */ "EAFNOSUPPORT", + /* [ 98] = */ "EADDRINUSE", + /* [ 99] = */ "EADDRNOTAVAIL", + /* [100] = */ "ENETDOWN", + /* [101] = */ "ENETUNREACH", + /* [102] = */ "ENETRESET", + /* [103] = */ "ECONNABORTED", + /* [104] = */ "ECONNRESET", + /* [105] = */ "ENOBUFS", + /* [106] = */ "EISCONN", + /* [107] = */ "ENOTCONN", + /* [108] = */ "ESHUTDOWN", + /* [109] = */ "ETOOMANYREFS", + /* [110] = */ "ETIMEDOUT", + /* [111] = */ "ECONNREFUSED", + /* [112] = */ "EHOSTDOWN", + /* [113] = */ "EHOSTUNREACH", + /* [114] = */ "EALREADY", + /* [115] = */ "EINPROGRESS", + /* [116] = */ "ESTALE", + /* [117] = */ "EUCLEAN", + /* [118] = */ "ENOTNAM", + /* [119] = */ "ENAVAIL", + /* [120] = */ "EISNAM", + /* [121] = */ "EREMOTEIO", + /* [122] = */ "EDQUOT", + /* [123] = */ "ENOMEDIUM", + /* [124] = */ "EMEDIUMTYPE", + /* [125] = */ "ECANCELED", + /* [126] = */ "ENOKEY", + /* [127] = */ "EKEYEXPIRED", + /* [128] = */ "EKEYREVOKED", + /* [129] = */ "EKEYREJECTED", + /* [130] = */ "EOWNERDEAD", + /* [131] = */ "ENOTRECOVERABLE", + /* [132] = */ "ERFKILL", + /* [133] = */ "EHWPOISON", + /* [134] = */ NULL, + /* [135] = */ NULL, + /* [136] = */ NULL, + /* [137] = */ NULL, + /* [138] = */ NULL, + /* [139] = */ NULL, + /* [140] = */ NULL, + /* [141] = */ NULL, + /* [142] = */ NULL, + /* [143] = */ NULL, + /* [144] = */ NULL, + /* [145] = */ NULL, + /* [146] = */ NULL, + /* [147] = */ NULL, + /* [148] = */ NULL, + /* [149] = */ NULL, + /* [150] = */ NULL, + /* [151] = */ NULL, + /* [152] = */ NULL, + /* [153] = */ NULL, + /* [154] = */ NULL, + /* [155] = */ NULL, + /* [156] = */ NULL, + /* [157] = */ NULL, + /* [158] = */ NULL, + /* [159] = */ NULL, + /* [160] = */ NULL, + /* [161] = */ NULL, + /* [162] = */ NULL, + /* [163] = */ NULL, + /* [164] = */ NULL, + /* [165] = */ NULL, + /* [166] = */ NULL, + /* [167] = */ NULL, + /* [168] = */ NULL, + /* [169] = */ NULL, + /* [170] = */ NULL, + /* [171] = */ NULL, + /* [172] = */ NULL, + /* [173] = */ NULL, + /* [174] = */ NULL, + /* [175] = */ NULL, + /* [176] = */ NULL, + /* [177] = */ NULL, + /* [178] = */ NULL, + /* [179] = */ NULL, + /* [180] = */ NULL, + /* [181] = */ NULL, + /* [182] = */ NULL, + /* [183] = */ NULL, + /* [184] = */ NULL, + /* [185] = */ NULL, + /* [186] = */ NULL, + /* [187] = */ NULL, + /* [188] = */ NULL, + /* [189] = */ NULL, + /* [190] = */ NULL, + /* [191] = */ NULL, + /* [192] = */ NULL, + /* [193] = */ NULL, + /* [194] = */ NULL, + /* [195] = */ NULL, + /* [196] = */ NULL, + /* [197] = */ NULL, + /* [198] = */ NULL, + /* [199] = */ NULL, + /* [200] = */ NULL, + /* [201] = */ NULL, + /* [202] = */ NULL, + /* [203] = */ NULL, + /* [204] = */ NULL, + /* [205] = */ NULL, + /* [206] = */ NULL, + /* [207] = */ NULL, + /* [208] = */ NULL, + /* [209] = */ NULL, + /* [210] = */ NULL, + /* [211] = */ NULL, + /* [212] = */ NULL, + /* [213] = */ NULL, + /* [214] = */ NULL, + /* [215] = */ NULL, + /* [216] = */ NULL, + /* [217] = */ NULL, + /* [218] = */ NULL, + /* [219] = */ NULL, + /* [220] = */ NULL, + /* [221] = */ NULL, + /* [222] = */ NULL, + /* [223] = */ NULL, + /* [224] = */ NULL, + /* [225] = */ NULL, + /* [226] = */ NULL, + /* [227] = */ NULL, + /* [228] = */ NULL, + /* [229] = */ NULL, + /* [230] = */ NULL, + /* [231] = */ NULL, + /* [232] = */ NULL, + /* [233] = */ NULL, + /* [234] = */ NULL, + /* [235] = */ NULL, + /* [236] = */ NULL, + /* [237] = */ NULL, + /* [238] = */ NULL, + /* [239] = */ NULL, + /* [240] = */ NULL, + /* [241] = */ NULL, + /* [242] = */ NULL, + /* [243] = */ NULL, + /* [244] = */ NULL, + /* [245] = */ NULL, + /* [246] = */ NULL, + /* [247] = */ NULL, + /* [248] = */ NULL, + /* [249] = */ NULL, + /* [250] = */ NULL, + /* [251] = */ NULL, + /* [252] = */ NULL, + /* [253] = */ NULL, + /* [254] = */ NULL, + /* [255] = */ NULL, + /* [256] = */ NULL, + /* [257] = */ NULL, + /* [258] = */ NULL, + /* [259] = */ NULL, + /* [260] = */ NULL, + /* [261] = */ NULL, + /* [262] = */ NULL, + /* [263] = */ NULL, + /* [264] = */ NULL, + /* [265] = */ NULL, + /* [266] = */ NULL, + /* [267] = */ NULL, + /* [268] = */ NULL, + /* [269] = */ NULL, + /* [270] = */ NULL, + /* [271] = */ NULL, + /* [272] = */ NULL, + /* [273] = */ NULL, + /* [274] = */ NULL, + /* [275] = */ NULL, + /* [276] = */ NULL, + /* [277] = */ NULL, + /* [278] = */ NULL, + /* [279] = */ NULL, + /* [280] = */ NULL, + /* [281] = */ NULL, + /* [282] = */ NULL, + /* [283] = */ NULL, + /* [284] = */ NULL, + /* [285] = */ NULL, + /* [286] = */ NULL, + /* [287] = */ NULL, + /* [288] = */ NULL, + /* [289] = */ NULL, + /* [290] = */ NULL, + /* [291] = */ NULL, + /* [292] = */ NULL, + /* [293] = */ NULL, + /* [294] = */ NULL, + /* [295] = */ NULL, + /* [296] = */ NULL, + /* [297] = */ NULL, + /* [298] = */ NULL, + /* [299] = */ NULL, + /* [300] = */ NULL, + /* [301] = */ NULL, + /* [302] = */ NULL, + /* [303] = */ NULL, + /* [304] = */ NULL, + /* [305] = */ NULL, + /* [306] = */ NULL, + /* [307] = */ NULL, + /* [308] = */ NULL, + /* [309] = */ NULL, + /* [310] = */ NULL, + /* [311] = */ NULL, + /* [312] = */ NULL, + /* [313] = */ NULL, + /* [314] = */ NULL, + /* [315] = */ NULL, + /* [316] = */ NULL, + /* [317] = */ NULL, + /* [318] = */ NULL, + /* [319] = */ NULL, + /* [320] = */ NULL, + /* [321] = */ NULL, + /* [322] = */ NULL, + /* [323] = */ NULL, + /* [324] = */ NULL, + /* [325] = */ NULL, + /* [326] = */ NULL, + /* [327] = */ NULL, + /* [328] = */ NULL, + /* [329] = */ NULL, + /* [330] = */ NULL, + /* [331] = */ NULL, + /* [332] = */ NULL, + /* [333] = */ NULL, + /* [334] = */ NULL, + /* [335] = */ NULL, + /* [336] = */ NULL, + /* [337] = */ NULL, + /* [338] = */ NULL, + /* [339] = */ NULL, + /* [340] = */ NULL, + /* [341] = */ NULL, + /* [342] = */ NULL, + /* [343] = */ NULL, + /* [344] = */ NULL, + /* [345] = */ NULL, + /* [346] = */ NULL, + /* [347] = */ NULL, + /* [348] = */ NULL, + /* [349] = */ NULL, + /* [350] = */ NULL, + /* [351] = */ NULL, + /* [352] = */ NULL, + /* [353] = */ NULL, + /* [354] = */ NULL, + /* [355] = */ NULL, + /* [356] = */ NULL, + /* [357] = */ NULL, + /* [358] = */ NULL, + /* [359] = */ NULL, + /* [360] = */ NULL, + /* [361] = */ NULL, + /* [362] = */ NULL, + /* [363] = */ NULL, + /* [364] = */ NULL, + /* [365] = */ NULL, + /* [366] = */ NULL, + /* [367] = */ NULL, + /* [368] = */ NULL, + /* [369] = */ NULL, + /* [370] = */ NULL, + /* [371] = */ NULL, + /* [372] = */ NULL, + /* [373] = */ NULL, + /* [374] = */ NULL, + /* [375] = */ NULL, + /* [376] = */ NULL, + /* [377] = */ NULL, + /* [378] = */ NULL, + /* [379] = */ NULL, + /* [380] = */ NULL, + /* [381] = */ NULL, + /* [382] = */ NULL, + /* [383] = */ NULL, + /* [384] = */ NULL, + /* [385] = */ NULL, + /* [386] = */ NULL, + /* [387] = */ NULL, + /* [388] = */ NULL, + /* [389] = */ NULL, + /* [390] = */ NULL, + /* [391] = */ NULL, + /* [392] = */ NULL, + /* [393] = */ NULL, + /* [394] = */ NULL, + /* [395] = */ NULL, + /* [396] = */ NULL, + /* [397] = */ NULL, + /* [398] = */ NULL, + /* [399] = */ NULL, + /* [400] = */ NULL, + /* [401] = */ NULL, + /* [402] = */ NULL, + /* [403] = */ NULL, + /* [404] = */ NULL, + /* [405] = */ NULL, + /* [406] = */ NULL, + /* [407] = */ NULL, + /* [408] = */ NULL, + /* [409] = */ NULL, + /* [410] = */ NULL, + /* [411] = */ NULL, + /* [412] = */ NULL, + /* [413] = */ NULL, + /* [414] = */ NULL, + /* [415] = */ NULL, + /* [416] = */ NULL, + /* [417] = */ NULL, + /* [418] = */ NULL, + /* [419] = */ NULL, + /* [420] = */ NULL, + /* [421] = */ NULL, + /* [422] = */ NULL, + /* [423] = */ NULL, + /* [424] = */ NULL, + /* [425] = */ NULL, + /* [426] = */ NULL, + /* [427] = */ NULL, + /* [428] = */ NULL, + /* [429] = */ NULL, + /* [430] = */ NULL, + /* [431] = */ NULL, + /* [432] = */ NULL, + /* [433] = */ NULL, + /* [434] = */ NULL, + /* [435] = */ NULL, + /* [436] = */ NULL, + /* [437] = */ NULL, + /* [438] = */ NULL, + /* [439] = */ NULL, + /* [440] = */ NULL, + /* [441] = */ NULL, + /* [442] = */ NULL, + /* [443] = */ NULL, + /* [444] = */ NULL, + /* [445] = */ NULL, + /* [446] = */ NULL, + /* [447] = */ NULL, + /* [448] = */ NULL, + /* [449] = */ NULL, + /* [450] = */ NULL, + /* [451] = */ NULL, + /* [452] = */ NULL, + /* [453] = */ NULL, + /* [454] = */ NULL, + /* [455] = */ NULL, + /* [456] = */ NULL, + /* [457] = */ NULL, + /* [458] = */ NULL, + /* [459] = */ NULL, + /* [460] = */ NULL, + /* [461] = */ NULL, + /* [462] = */ NULL, + /* [463] = */ NULL, + /* [464] = */ NULL, + /* [465] = */ NULL, + /* [466] = */ NULL, + /* [467] = */ NULL, + /* [468] = */ NULL, + /* [469] = */ NULL, + /* [470] = */ NULL, + /* [471] = */ NULL, + /* [472] = */ NULL, + /* [473] = */ NULL, + /* [474] = */ NULL, + /* [475] = */ NULL, + /* [476] = */ NULL, + /* [477] = */ NULL, + /* [478] = */ NULL, + /* [479] = */ NULL, + /* [480] = */ NULL, + /* [481] = */ NULL, + /* [482] = */ NULL, + /* [483] = */ NULL, + /* [484] = */ NULL, + /* [485] = */ NULL, + /* [486] = */ NULL, + /* [487] = */ NULL, + /* [488] = */ NULL, + /* [489] = */ NULL, + /* [490] = */ NULL, + /* [491] = */ NULL, + /* [492] = */ NULL, + /* [493] = */ NULL, + /* [494] = */ NULL, + /* [495] = */ NULL, + /* [496] = */ NULL, + /* [497] = */ NULL, + /* [498] = */ NULL, + /* [499] = */ NULL, + /* [500] = */ NULL, + /* [501] = */ NULL, + /* [502] = */ NULL, + /* [503] = */ NULL, + /* [504] = */ NULL, + /* [505] = */ NULL, + /* [506] = */ NULL, + /* [507] = */ NULL, + /* [508] = */ NULL, + /* [509] = */ NULL, + /* [510] = */ NULL, + /* [511] = */ NULL, + /* [512] = */ "ERESTARTSYS", + /* [513] = */ "ERESTARTNOINTR", + /* [514] = */ "ERESTARTNOHAND", + /* [515] = */ "ENOIOCTLCMD", + /* [516] = */ "ERESTART_RESTARTBLOCK", + /* [517] = */ "EPROBE_DEFER", + /* [518] = */ "EOPENSTALE", + /* [519] = */ NULL, + /* [520] = */ NULL, + /* [521] = */ "EBADHANDLE", + /* [522] = */ "ENOTSYNC", + /* [523] = */ "EBADCOOKIE", + /* [524] = */ "ENOTSUPP", + /* [525] = */ "ETOOSMALL", + /* [526] = */ "ESERVERFAULT", + /* [527] = */ "EBADTYPE", + /* [528] = */ "EJUKEBOX", + /* [529] = */ "EIOCBQUEUED", + /* [530] = */ "ERECALLCONFLICT", }; -static inline std::string +static inline std::string errno_name(int errno_value) { const auto name = errno_names.at(errno_value); @@ -575,7 +575,7 @@ errno_message(int errno_value) { return std::string{msg}; } -} // namespace syscalls +} // namespace syscall } // namespace gkfs #endif // GKFS_SYSCALLS_ERRNO_HPP diff --git a/include/client/syscalls/syscall.hpp b/include/client/syscalls/syscall.hpp index b7fd79ac3..ed67dae53 100644 --- a/include/client/syscalls/syscall.hpp +++ b/include/client/syscalls/syscall.hpp @@ -71,8 +71,7 @@ lookup_by_number(const long syscall_number) { } static inline descriptor -lookup_by_number(const long syscall_number, - const long argv[MAX_ARGS]) { +lookup_by_number(const long syscall_number, const long argv[MAX_ARGS]) { const auto* info = ::get_syscall_info(syscall_number, argv); return *reinterpret_cast(info); } @@ -128,38 +127,38 @@ enum class info : int { inline constexpr info -operator&(info t1, info t2) { - return info(static_cast(t1) & static_cast(t2)); +operator&(info t1, info t2) { + return info(static_cast(t1) & static_cast(t2)); } inline constexpr info -operator|(info t1, info t2) { - return info(static_cast(t1) | static_cast(t2)); +operator|(info t1, info t2) { + return info(static_cast(t1) | static_cast(t2)); } inline constexpr info -operator^(info t1, info t2) { - return info(static_cast(t1) ^ static_cast(t2)); +operator^(info t1, info t2) { + return info(static_cast(t1) ^ static_cast(t2)); } inline constexpr info -operator~(info t1) { - return info(~static_cast(t1)); +operator~(info t1) { + return info(~static_cast(t1)); } inline const info& -operator|=(info& t1, info t2) { - return t1 = t1 | t2; +operator|=(info& t1, info t2) { + return t1 = t1 | t2; } inline const info& -operator&=(info& t1, info t2) { - return t1 = t1 & t2; +operator&=(info& t1, info t2) { + return t1 = t1 & t2; } inline const info& -operator^=(info& t1, info t2) { - return t1 = t1 ^ t2; +operator^=(info& t1, info t2) { + return t1 = t1 ^ t2; } @@ -191,7 +190,7 @@ target(syscall::info info) { return info & target_mask; } -static constexpr bool +static constexpr bool is_handled_by_kernel(syscall::info info) { return (info & target_mask) == to_kernel; } @@ -207,10 +206,10 @@ execution_is_pending(syscall::info info) { */ static inline int error_code(long result) { - if (result < 0 && result >= -0x1000) - return (int)-result; + if(result < 0 && result >= -0x1000) + return (int) -result; - return 0; + return 0; } } // namespace syscall diff --git a/src/client/syscalls/detail/syscall_info.c b/src/client/syscalls/detail/syscall_info.c index 7b0d348f6..f4101237f 100644 --- a/src/client/syscalls/detail/syscall_info.c +++ b/src/client/syscalls/detail/syscall_info.c @@ -480,17 +480,16 @@ requires_mode_arg(int flags) { #include -/** - * get_syscall_info - Return a syscall descriptor +/** + * get_syscall_info - Return a syscall descriptor * - * This function returns a pointer to a syscall_info structure that + * This function returns a pointer to a syscall_info structure that * appropriately describes the system call identified by 'syscall_number'. */ -const struct syscall_info * -get_syscall_info(const long syscall_number, - const long* argv) { +const struct syscall_info* +get_syscall_info(const long syscall_number, const long* argv) { - if(syscall_number < 0 || + if(syscall_number < 0 || syscall_number >= (long) ARRAY_SIZE(syscall_table)) { return &unknown_syscall; } @@ -515,8 +514,8 @@ get_syscall_info(const long syscall_number, } struct named_syscall_entry { - const char * s_name; - const struct syscall_info * s_info; + const char* s_name; + const struct syscall_info* s_info; }; #define SYSCALL_BY_NAME(id) \ @@ -891,18 +890,18 @@ const struct named_syscall_entry syscalls_by_name[] = { }; static int -compare_named_entries(const void *k, const void *e) { +compare_named_entries(const void* k, const void* e) { const char* name = (const char*) k; struct named_syscall_entry* entry = (struct named_syscall_entry*) e; return strcmp(name, entry->s_name); } -const struct syscall_info * +const struct syscall_info* get_syscall_info_by_name(const char* syscall_name) { - struct named_syscall_entry* res = - bsearch(syscall_name, &syscalls_by_name[0], ARRAY_SIZE(syscalls_by_name), - sizeof(struct named_syscall_entry), compare_named_entries); + struct named_syscall_entry* res = bsearch( + syscall_name, &syscalls_by_name[0], ARRAY_SIZE(syscalls_by_name), + sizeof(struct named_syscall_entry), compare_named_entries); if(res == NULL) { return &unknown_syscall; @@ -911,8 +910,7 @@ get_syscall_info_by_name(const char* syscall_name) { return res->s_info; } -#define RETURN_TYPE(scinfo) \ - (scinfo)->s_return_type.r_type +#define RETURN_TYPE(scinfo) (scinfo)->s_return_type.r_type bool syscall_never_returns(long syscall_number) { @@ -920,7 +918,6 @@ syscall_never_returns(long syscall_number) { } - #undef SYSCALL #undef S_NOARGS #undef S_UARG -- GitLab From 7151a8d46ec96291c0a35ff46ebb61a687c72dff Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Fri, 6 Nov 2020 18:16:50 +0100 Subject: [PATCH 09/15] Using clang-format config for version 10 --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 5e60fd08d..e04649874 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,7 @@ AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveMacros: true AlignEscapedNewlines: Right -AlignOperands: Align +AlignOperands: true AlignTrailingComments: true AllowAllArgumentsOnNextLine: false AllowAllConstructorInitializersOnNextLine: false -- GitLab From 2d50febca284ce9c057c40991bcc4bb985b84e83 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Fri, 6 Nov 2020 18:19:06 +0100 Subject: [PATCH 10/15] Adding clang-format to docker image --- docker/debian_build_env.docker | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docker/debian_build_env.docker b/docker/debian_build_env.docker index 743e10d22..db8bc6ca1 100644 --- a/docker/debian_build_env.docker +++ b/docker/debian_build_env.docker @@ -41,8 +41,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3-dev \ python3-venv \ expect \ + # clang 10 deps + lsb-release \ + wget \ + software-properties-common \ + gnupg2 \ +# add clang-10 repos +&& wget https://apt.llvm.org/llvm.sh -P /tmp && chmod +x /tmp/llvm.sh && /tmp/llvm.sh 10 \ +# install clang-format +&& apt-get update && apt-get install -y --no-install-recommends clang-format-10 \ # Clean apt cache to reduce image layer size -&& rm -rf /var/lib/apt/lists/* +&& rm -rf /var/lib/apt/lists/* && rm /tmp/llvm.sh \ +# Clean apt caches of packages +&& apt-get clean && apt-get autoclean ## COPY scripts/dl_dep.sh $SCRIPTS_PATH/ ## COPY scripts/compile_dep.sh $SCRIPTS_PATH/ -- GitLab From 4d2e18c0aa3ec2d5e38999a63ac162111a825f72 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 9 Nov 2020 16:08:21 +0100 Subject: [PATCH 11/15] Adding script to check if code is formatted --- scripts/check_format.sh | 103 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 scripts/check_format.sh diff --git a/scripts/check_format.sh b/scripts/check_format.sh new file mode 100644 index 000000000..66a9eb288 --- /dev/null +++ b/scripts/check_format.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +PROJECT_SRC="$(pwd)/src" +PROJECT_INCLUDE="$(pwd)/include" +RUN_FORMAT=false + +usage_short() { + echo " +usage: check_format.sh [-h] [-s ] [-i ] + " +} + +help_msg() { + + usage_short + echo " +This script checks if the code is formatted correctly by the rules set in .clang-format + +optional arguments: + -h, --help shows this help message and exits + -s , --src + path to the src/ directory of the project + (default: 'pwd/src') + -i , --include + path to the include/ directory of the project + (default: 'pwd/include') + -r, --run_format run clang-formatter before formatting check + DISCLAIMER: FILES ARE MODIFIED IN PLACE! +" +} + +POSITIONAL=() +while [[ $# -gt 0 ]]; do + key="$1" + + case ${key} in + -s | --src) + PROJECT_SRC="$(readlink -mn "${2}")" + shift # past argument + shift # past value + ;; + -i | --include) + PROJECT_INCLUDE="$(readlink -mn "${2}")" + shift # past argument + shift # past value + ;; + -r | --run_format) + RUN_FORMAT=true + shift # past argument + ;; + -h | --help) + help_msg + exit + ;; + *) # unknown option + POSITIONAL+=("$1") # save it in an array for later + shift # past argument + ;; + esac +done +set -- "${POSITIONAL[@]}" # restore positional parameters + +FAIL=false + +echo "* Source directory: $PROJECT_SRC" +if [[ ! -d "$PROJECT_SRC" ]]; then + echo "*** ERR: $PROJECT_SRC does not exist." + exit 1 +fi +echo "* Include directory: $PROJECT_INCLUDE" +if [[ ! -d "$PROJECT_INCLUDE" ]]; then + echo "*** ERR: $PROJECT_INCLUDE does not exist." + exit 1 +fi +echo "* Checking for unformatted files ..." +if [[ "$RUN_FORMAT" == true ]]; then + echo "*** Running clang-format on all files and formatting them in place." + echo "* The following files and number of lines were formatted:" +else + echo "* The following files and number of lines need to be formatted:" +fi +echo "------------------------------------------" +while IFS= read -r -d '' FILE; do + UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <(clang-format -style=file "$FILE") | wc -l) + if ((UNFORMATTED_LINES > 0)); then + if [[ "$RUN_FORMAT" == true ]]; then + echo "*** Reformatting $UNFORMATTED_LINES lines in '$FILE'" + clang-format -i -style=file "$FILE" + else + echo -n "$FILE " + echo "$UNFORMATTED_LINES" + FAIL=true + fi + fi +done < <(find "$PROJECT_SRC" "$PROJECT_INCLUDE" -type f \( -name "*.cpp" -o -name "*.hpp" \) -print0) + +echo "------------------------------------------" +if [[ "$FAIL" == true ]]; then + echo "* Format check failed! Format your code with 'clang-format -style=file' or pass '-r' to reformat files in place." + exit 1 +fi + +echo "* Format check successful." -- GitLab From 27f06a252c82cbf70f42b1a11cf0ee2ef9f8f9fb Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 9 Nov 2020 17:15:25 +0100 Subject: [PATCH 12/15] Adding clang-format binary path arg to check_format.sh --- scripts/check_format.sh | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 66a9eb288..d58c045b7 100644 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -3,10 +3,11 @@ PROJECT_SRC="$(pwd)/src" PROJECT_INCLUDE="$(pwd)/include" RUN_FORMAT=false +CLANG_FORMAT_BIN="" usage_short() { echo " -usage: check_format.sh [-h] [-s ] [-i ] +usage: check_format.sh [-h] [-s ] [-i ] [-c ] [--run_format] " } @@ -24,6 +25,9 @@ optional arguments: -i , --include path to the include/ directory of the project (default: 'pwd/include') + -c , --clang_format_path + path to clang-format binary + (default: looks for 'clang-format' or 'clang-format-10') -r, --run_format run clang-formatter before formatting check DISCLAIMER: FILES ARE MODIFIED IN PLACE! " @@ -44,6 +48,15 @@ while [[ $# -gt 0 ]]; do shift # past argument shift # past value ;; + -c | --clang_format_path) + CLANG_FORMAT_BIN="$(readlink -mn "${2}")" + if [[ ! -x $CLANG_FORMAT_BIN ]]; then + echo "*** ERR: clang-format path $CLANG_FORMAT_BIN is not an executable! Exiting ..." + exit 1 + fi + shift # past argument + shift # past value + ;; -r | --run_format) RUN_FORMAT=true shift # past argument @@ -60,6 +73,19 @@ while [[ $# -gt 0 ]]; do done set -- "${POSITIONAL[@]}" # restore positional parameters +# check for clang-format executable if it hasn't been set by the user +if [[ -z $CLANG_FORMAT_BIN ]]; then + CLANG_FORMAT_BIN=$(command -v clang-format) + if [[ -z $CLANG_FORMAT_BIN ]]; then + CLANG_FORMAT_BIN=$(command -v clang-format-10) + # if it still doesn't exist exit + if [[ -z $CLANG_FORMAT_BIN ]]; then + echo "*** ERR: clang-format not found! Exiting ..." + exit 1 + fi + fi +fi + FAIL=false echo "* Source directory: $PROJECT_SRC" @@ -81,11 +107,11 @@ else fi echo "------------------------------------------" while IFS= read -r -d '' FILE; do - UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <(clang-format -style=file "$FILE") | wc -l) + UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <($CLANG_FORMAT_BIN -style=file "$FILE") | wc -l) if ((UNFORMATTED_LINES > 0)); then if [[ "$RUN_FORMAT" == true ]]; then echo "*** Reformatting $UNFORMATTED_LINES lines in '$FILE'" - clang-format -i -style=file "$FILE" + $CLANG_FORMAT_BIN -i -style=file "$FILE" else echo -n "$FILE " echo "$UNFORMATTED_LINES" -- GitLab From bca345a5113d1d6e76b3049d156f891c11beb8c5 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 9 Nov 2020 16:51:54 +0100 Subject: [PATCH 13/15] Adding clang-format check to CI squash --- .gitlab-ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 62ed47b31..ded3e3ee5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ stages: + - check format - download deps - build deps - build @@ -25,6 +26,12 @@ variables: image: gekkofs/gekkofs:build_env-0.8.0 +check format: + stage: check format + script: + - chmod +x ${CI_PROJECT_DIR}/scripts/check_format.sh + - ${CI_PROJECT_DIR}/scripts/check_format.sh -s "${CI_PROJECT_DIR}/src" -i "${CI_PROJECT_DIR}/src" + compile dependencies: stage: build deps cache: -- GitLab From 32275ea9ceceb5de4de6d074660ea1b8ffdca02d Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 9 Nov 2020 17:18:12 +0100 Subject: [PATCH 14/15] File mode changes of check_format.sh --- .gitlab-ci.yml | 1 - scripts/check_format.sh | 0 2 files changed, 1 deletion(-) mode change 100644 => 100755 scripts/check_format.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ded3e3ee5..73badb0a6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,7 +29,6 @@ image: gekkofs/gekkofs:build_env-0.8.0 check format: stage: check format script: - - chmod +x ${CI_PROJECT_DIR}/scripts/check_format.sh - ${CI_PROJECT_DIR}/scripts/check_format.sh -s "${CI_PROJECT_DIR}/src" -i "${CI_PROJECT_DIR}/src" compile dependencies: diff --git a/scripts/check_format.sh b/scripts/check_format.sh old mode 100644 new mode 100755 -- GitLab From 615c1434ca5b19e198bb198ef7f0d487ca4e7f47 Mon Sep 17 00:00:00 2001 From: Marc Vef Date: Mon, 9 Nov 2020 17:19:28 +0100 Subject: [PATCH 15/15] Reformatting complete code base with clang-format --- include/client/env.hpp | 13 +- include/client/gkfs_functions.hpp | 109 ++- include/client/hooks.hpp | 125 ++- include/client/intercept.hpp | 20 +- include/client/logging.hpp | 392 ++++---- include/client/make_array.hpp | 12 +- include/client/open_dir.hpp | 18 +- include/client/open_file_map.hpp | 81 +- include/client/path.hpp | 27 +- include/client/preload.hpp | 11 +- include/client/preload_context.hpp | 116 ++- include/client/preload_util.hpp | 30 +- include/client/rpc/forward_data.hpp | 21 +- include/client/rpc/forward_management.hpp | 5 +- include/client/rpc/forward_metadata.hpp | 38 +- include/client/rpc/rpc_types.hpp | 886 ++++++++---------- include/config.hpp | 15 +- include/daemon/backend/data/chunk_storage.hpp | 42 +- include/daemon/backend/data/data_module.hpp | 20 +- include/daemon/backend/data/file_handle.hpp | 35 +- include/daemon/backend/exceptions.hpp | 6 +- include/daemon/backend/metadata/db.hpp | 36 +- include/daemon/backend/metadata/merge.hpp | 55 +- include/daemon/classes/fs_data.hpp | 102 +- include/daemon/classes/rpc_data.hpp | 37 +- include/daemon/daemon.hpp | 6 +- include/daemon/env.hpp | 2 - include/daemon/handler/rpc_defs.hpp | 2 +- include/daemon/handler/rpc_util.hpp | 60 +- include/daemon/ops/data.hpp | 82 +- include/daemon/ops/metadentry.hpp | 26 +- include/daemon/scheduler/agios.hpp | 18 +- include/daemon/util.hpp | 12 +- include/global/chunk_calc_util.hpp | 42 +- include/global/env_util.hpp | 3 +- include/global/global_defs.hpp | 5 +- include/global/log_util.hpp | 14 +- include/global/metadata.hpp | 80 +- include/global/path_util.hpp | 26 +- include/global/rpc/distributor.hpp | 56 +- include/global/rpc/rpc_types.hpp | 143 +-- include/global/rpc/rpc_util.hpp | 11 +- src/client/gkfs_functions.cpp | 403 ++++---- src/client/hooks.cpp | 492 +++++----- src/client/intercept.cpp | 634 ++++++------- src/client/logging.cpp | 225 +++-- src/client/open_dir.cpp | 25 +- src/client/open_file_map.cpp | 121 ++- src/client/path.cpp | 159 ++-- src/client/preload.cpp | 111 ++- src/client/preload_context.cpp | 173 ++-- src/client/preload_util.cpp | 148 +-- src/client/rpc/forward_data.cpp | 203 ++-- src/client/rpc/forward_management.cpp | 16 +- src/client/rpc/forward_metadata.cpp | 319 ++++--- src/client/rpc/rpc_types.cpp | 4 +- src/daemon/backend/data/chunk_storage.cpp | 219 +++-- src/daemon/backend/data/data_module.cpp | 6 +- src/daemon/backend/metadata/db.cpp | 80 +- src/daemon/backend/metadata/merge.cpp | 98 +- src/daemon/classes/fs_data.cpp | 99 +- src/daemon/classes/rpc_data.cpp | 24 +- src/daemon/daemon.cpp | 330 ++++--- src/daemon/handler/srv_data.cpp | 383 +++++--- src/daemon/handler/srv_management.cpp | 16 +- src/daemon/handler/srv_metadata.cpp | 324 ++++--- src/daemon/ops/data.cpp | 285 +++--- src/daemon/ops/metadentry.cpp | 50 +- src/daemon/scheduler/agios.cpp | 3 +- src/daemon/util.cpp | 24 +- src/global/env_util.cpp | 3 +- src/global/log_util.cpp | 40 +- src/global/metadata.cpp | 110 ++- src/global/path_util.cpp | 66 +- src/global/rpc/distributor.cpp | 70 +- src/global/rpc/rpc_util.cpp | 42 +- 76 files changed, 4514 insertions(+), 3631 deletions(-) diff --git a/include/client/env.hpp b/include/client/env.hpp index 0555371f7..4034dff51 100644 --- a/include/client/env.hpp +++ b/include/client/env.hpp @@ -22,17 +22,17 @@ namespace gkfs { namespace env { -static constexpr auto LOG = ADD_PREFIX("LOG"); +static constexpr auto LOG = ADD_PREFIX("LOG"); #ifdef GKFS_DEBUG_BUILD static constexpr auto LOG_DEBUG_VERBOSITY = ADD_PREFIX("LOG_DEBUG_VERBOSITY"); -static constexpr auto LOG_SYSCALL_FILTER = ADD_PREFIX("LOG_SYSCALL_FILTER"); +static constexpr auto LOG_SYSCALL_FILTER = ADD_PREFIX("LOG_SYSCALL_FILTER"); #endif -static constexpr auto LOG_OUTPUT = ADD_PREFIX("LOG_OUTPUT"); -static constexpr auto LOG_OUTPUT_TRUNC = ADD_PREFIX("LOG_OUTPUT_TRUNC"); -static constexpr auto CWD = ADD_PREFIX("CWD"); -static constexpr auto HOSTS_FILE = ADD_PREFIX("HOSTS_FILE"); +static constexpr auto LOG_OUTPUT = ADD_PREFIX("LOG_OUTPUT"); +static constexpr auto LOG_OUTPUT_TRUNC = ADD_PREFIX("LOG_OUTPUT_TRUNC"); +static constexpr auto CWD = ADD_PREFIX("CWD"); +static constexpr auto HOSTS_FILE = ADD_PREFIX("HOSTS_FILE"); #ifdef GKFS_ENABLE_FORWARDING static constexpr auto FORWARDING_MAP_FILE = ADD_PREFIX("FORWARDING_MAP_FILE"); #endif @@ -43,4 +43,3 @@ static constexpr auto FORWARDING_MAP_FILE = ADD_PREFIX("FORWARDING_MAP_FILE"); #undef ADD_PREFIX #endif // GKFS_CLIENT_ENV - diff --git a/include/client/gkfs_functions.hpp b/include/client/gkfs_functions.hpp index 295281fbe..f7ffa87d7 100644 --- a/include/client/gkfs_functions.hpp +++ b/include/client/gkfs_functions.hpp @@ -25,83 +25,116 @@ struct linux_dirent64; namespace gkfs { namespace syscall { -int gkfs_open(const std::string& path, mode_t mode, int flags); +int +gkfs_open(const std::string& path, mode_t mode, int flags); -int gkfs_create(const std::string& path, mode_t mode); +int +gkfs_create(const std::string& path, mode_t mode); -int gkfs_remove(const std::string& path); +int +gkfs_remove(const std::string& path); // Implementation of access, -// Follow links is true by default -int gkfs_access(const std::string& path, int mask, bool follow_links = true); +// Follow links is true by default +int +gkfs_access(const std::string& path, int mask, bool follow_links = true); -// Implementation of stat, -// Follow links is true by default -int gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = true); +// Implementation of stat, +// Follow links is true by default +int +gkfs_stat(const std::string& path, struct stat* buf, bool follow_links = true); -// Implementation of statx, it uses the normal stat and maps the information to the statx structure -// Follow links is true by default +// Implementation of statx, it uses the normal stat and maps the information to +// the statx structure Follow links is true by default #ifdef STATX_TYPE -int gkfs_statx(int dirfd, const std::string& path, int flags, unsigned int mask, struct statx* buf, - bool follow_links = true); +int +gkfs_statx(int dirfd, const std::string& path, int flags, unsigned int mask, + struct statx* buf, bool follow_links = true); #endif -int gkfs_statfs(struct statfs* buf); +int +gkfs_statfs(struct statfs* buf); -int gkfs_statvfs(struct statvfs* buf); +int +gkfs_statvfs(struct statvfs* buf); -off64_t gkfs_lseek(unsigned int fd, off64_t offset, unsigned int whence); +off64_t +gkfs_lseek(unsigned int fd, off64_t offset, unsigned int whence); -off64_t gkfs_lseek(std::shared_ptr gkfs_fd, off64_t offset, unsigned int whence); +off64_t +gkfs_lseek(std::shared_ptr gkfs_fd, off64_t offset, + unsigned int whence); -int gkfs_truncate(const std::string& path, off_t offset); +int +gkfs_truncate(const std::string& path, off_t offset); -int gkfs_truncate(const std::string& path, off_t old_size, off_t new_size); +int +gkfs_truncate(const std::string& path, off_t old_size, off_t new_size); -int gkfs_dup(int oldfd); +int +gkfs_dup(int oldfd); -int gkfs_dup2(int oldfd, int newfd); +int +gkfs_dup2(int oldfd, int newfd); #ifdef HAS_SYMLINKS -int gkfs_mk_symlink(const std::string& path, const std::string& target_path); +int +gkfs_mk_symlink(const std::string& path, const std::string& target_path); -int gkfs_readlink(const std::string& path, char* buf, int bufsize); +int +gkfs_readlink(const std::string& path, char* buf, int bufsize); #endif -ssize_t gkfs_pwrite(std::shared_ptr file, - const char* buf, size_t count, off64_t offset); +ssize_t +gkfs_pwrite(std::shared_ptr file, const char* buf, + size_t count, off64_t offset); -ssize_t gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset); +ssize_t +gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset); -ssize_t gkfs_write(int fd, const void* buf, size_t count); +ssize_t +gkfs_write(int fd, const void* buf, size_t count); -ssize_t gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset); +ssize_t +gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset); -ssize_t gkfs_writev(int fd, const struct iovec* iov, int iovcnt); +ssize_t +gkfs_writev(int fd, const struct iovec* iov, int iovcnt); -ssize_t gkfs_pread(std::shared_ptr file, char* buf, size_t count, off64_t offset); +ssize_t +gkfs_pread(std::shared_ptr file, char* buf, + size_t count, off64_t offset); -ssize_t gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset); +ssize_t +gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset); -ssize_t gkfs_read(int fd, void* buf, size_t count); +ssize_t +gkfs_read(int fd, void* buf, size_t count); -ssize_t gkfs_readv(int fd, const struct iovec* iov, int iovcnt); +ssize_t +gkfs_readv(int fd, const struct iovec* iov, int iovcnt); -ssize_t gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset); +ssize_t +gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset); -int gkfs_opendir(const std::string& path); +int +gkfs_opendir(const std::string& path); -int gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count); +int +gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count); -int gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, unsigned int count); +int +gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, + unsigned int count); -int gkfs_rmdir(const std::string& path); +int +gkfs_rmdir(const std::string& path); } // namespace syscall } // namespace gkfs -#endif //GEKKOFS_GKFS_FUNCTIONS_HPP +#endif // GEKKOFS_GKFS_FUNCTIONS_HPP diff --git a/include/client/hooks.hpp b/include/client/hooks.hpp index 9fd959082..ca3ffdeee 100644 --- a/include/client/hooks.hpp +++ b/include/client/hooks.hpp @@ -24,88 +24,129 @@ struct linux_dirent64; namespace gkfs { namespace hook { -int hook_openat(int dirfd, const char* cpath, int flags, mode_t mode); +int +hook_openat(int dirfd, const char* cpath, int flags, mode_t mode); -int hook_close(int fd); +int +hook_close(int fd); -int hook_stat(const char* path, struct stat* buf); +int +hook_stat(const char* path, struct stat* buf); #ifdef STATX_TYPE -int hook_statx(int dirfd, const char* path, int flags, unsigned int mask,struct statx* buf); +int +hook_statx(int dirfd, const char* path, int flags, unsigned int mask, + struct statx* buf); #endif -int hook_lstat(const char* path, struct stat* buf); +int +hook_lstat(const char* path, struct stat* buf); -int hook_fstat(unsigned int fd, struct stat* buf); +int +hook_fstat(unsigned int fd, struct stat* buf); -int hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags); +int +hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags); -int hook_read(unsigned int fd, void* buf, size_t count); +int +hook_read(unsigned int fd, void* buf, size_t count); -int hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos); +int +hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos); -int hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt); +int +hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt); -int hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, - unsigned long pos_l, unsigned long pos_h); +int +hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, + unsigned long pos_l, unsigned long pos_h); -int hook_write(unsigned int fd, const char* buf, size_t count); +int +hook_write(unsigned int fd, const char* buf, size_t count); -int hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos); +int +hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos); -int hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt); +int +hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt); -int hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, - unsigned long pos_l, unsigned long pos_h); +int +hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, + unsigned long pos_l, unsigned long pos_h); -int hook_unlinkat(int dirfd, const char* cpath, int flags); +int +hook_unlinkat(int dirfd, const char* cpath, int flags); -int hook_symlinkat(const char* oldname, int newdfd, const char* newname); +int +hook_symlinkat(const char* oldname, int newdfd, const char* newname); -int hook_access(const char* path, int mask); +int +hook_access(const char* path, int mask); -int hook_faccessat(int dirfd, const char* cpath, int mode); +int +hook_faccessat(int dirfd, const char* cpath, int mode); -off_t hook_lseek(unsigned int fd, off_t offset, unsigned int whence); +off_t +hook_lseek(unsigned int fd, off_t offset, unsigned int whence); -int hook_truncate(const char* path, long length); +int +hook_truncate(const char* path, long length); -int hook_ftruncate(unsigned int fd, unsigned long length); +int +hook_ftruncate(unsigned int fd, unsigned long length); -int hook_dup(unsigned int fd); +int +hook_dup(unsigned int fd); -int hook_dup2(unsigned int oldfd, unsigned int newfd); +int +hook_dup2(unsigned int oldfd, unsigned int newfd); -int hook_dup3(unsigned int oldfd, unsigned int newfd, int flags); +int +hook_dup3(unsigned int oldfd, unsigned int newfd, int flags); -int hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count); +int +hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count); -int hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, unsigned int count); +int +hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, + unsigned int count); -int hook_mkdirat(int dirfd, const char* cpath, mode_t mode); +int +hook_mkdirat(int dirfd, const char* cpath, mode_t mode); -int hook_fchmodat(int dirfd, const char* path, mode_t mode); +int +hook_fchmodat(int dirfd, const char* path, mode_t mode); -int hook_fchmod(unsigned int dirfd, mode_t mode); +int +hook_fchmod(unsigned int dirfd, mode_t mode); -int hook_chdir(const char* path); +int +hook_chdir(const char* path); -int hook_fchdir(unsigned int fd); +int +hook_fchdir(unsigned int fd); -int hook_getcwd(char* buf, unsigned long size); +int +hook_getcwd(char* buf, unsigned long size); -int hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz); +int +hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz); -int hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg); +int +hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg); -int hook_renameat(int olddfd, const char* oldname, int newdfd, const char* newname, - unsigned int flags); +int +hook_renameat(int olddfd, const char* oldname, int newdfd, const char* newname, + unsigned int flags); -int hook_statfs(const char* path, struct statfs* buf); +int +hook_statfs(const char* path, struct statfs* buf); -int hook_fstatfs(unsigned int fd, struct statfs* buf); +int +hook_fstatfs(unsigned int fd, struct statfs* buf); -int hook_fsync(unsigned int fd); +int +hook_fsync(unsigned int fd); } // namespace hook } // namespace gkfs diff --git a/include/client/intercept.hpp b/include/client/intercept.hpp index 4174b9829..4565a8ccf 100644 --- a/include/client/intercept.hpp +++ b/include/client/intercept.hpp @@ -18,22 +18,22 @@ namespace gkfs { namespace preload { int -internal_hook_guard_wrapper(long syscall_number, - long arg0, long arg1, long arg2, - long arg3, long arg4, long arg5, +internal_hook_guard_wrapper(long syscall_number, long arg0, long arg1, + long arg2, long arg3, long arg4, long arg5, long* syscall_return_value); int -hook_guard_wrapper(long syscall_number, - long arg0, long arg1, long arg2, - long arg3, long arg4, long arg5, - long* syscall_return_value); +hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, + long arg3, long arg4, long arg5, long* syscall_return_value); -void start_self_interception(); +void +start_self_interception(); -void start_interception(); +void +start_interception(); -void stop_interception(); +void +stop_interception(); } // namespace preload } // namespace gkfs diff --git a/include/client/logging.hpp b/include/client/logging.hpp index 06e7587e0..174d9db84 100644 --- a/include/client/logging.hpp +++ b/include/client/logging.hpp @@ -33,102 +33,91 @@ namespace gkfs { namespace log { enum class log_level : short { - print_syscalls = 1 << 0, + print_syscalls = 1 << 0, print_syscalls_entry = 1 << 1, - print_info = 1 << 2, - print_critical = 1 << 3, - print_errors = 1 << 4, - print_warnings = 1 << 5, - print_hermes = 1 << 6, - print_mercury = 1 << 7, - print_debug = 1 << 8, + print_info = 1 << 2, + print_critical = 1 << 3, + print_errors = 1 << 4, + print_warnings = 1 << 5, + print_hermes = 1 << 6, + print_mercury = 1 << 7, + print_debug = 1 << 8, // for internal use - print_none = 0, - print_all = print_syscalls | print_syscalls_entry | print_info | - print_critical | print_errors | print_warnings | - print_hermes | print_mercury | print_debug, - print_most = print_all & ~print_syscalls_entry, - print_help = 1 << 10 + print_none = 0, + print_all = print_syscalls | print_syscalls_entry | print_info | + print_critical | print_errors | print_warnings | print_hermes | + print_mercury | print_debug, + print_most = print_all & ~print_syscalls_entry, + print_help = 1 << 10 }; inline constexpr log_level -operator&(log_level l1, log_level l2) { - return log_level(static_cast(l1) & - static_cast(l2)); +operator&(log_level l1, log_level l2) { + return log_level(static_cast(l1) & static_cast(l2)); } inline constexpr log_level -operator|(log_level l1, log_level l2) { - return log_level(static_cast(l1) | - static_cast(l2)); +operator|(log_level l1, log_level l2) { + return log_level(static_cast(l1) | static_cast(l2)); } inline constexpr log_level -operator^(log_level l1, log_level l2) { - return log_level(static_cast(l1) ^ - static_cast(l2)); +operator^(log_level l1, log_level l2) { + return log_level(static_cast(l1) ^ static_cast(l2)); } inline constexpr log_level -operator~(log_level l1) { - return log_level(~static_cast(l1)); +operator~(log_level l1) { + return log_level(~static_cast(l1)); } -inline constexpr bool +inline constexpr bool operator!(log_level dm) { - return static_cast(dm) == 0; + return static_cast(dm) == 0; } inline const log_level& -operator|=(log_level& l1, log_level l2) { - return l1 = l1 | l2; +operator|=(log_level& l1, log_level l2) { + return l1 = l1 | l2; } inline const log_level& -operator&=(log_level& l1, log_level l2) { - return l1 = l1 & l2; +operator&=(log_level& l1, log_level l2) { + return l1 = l1 & l2; } inline const log_level& -operator^=(log_level& l1, log_level l2) { - return l1 = l1 ^ l2; +operator^=(log_level& l1, log_level l2) { + return l1 = l1 ^ l2; } -static const auto constexpr syscall = log_level::print_syscalls; +static const auto constexpr syscall = log_level::print_syscalls; static const auto constexpr syscall_at_entry = log_level::print_syscalls_entry; -static const auto constexpr info = log_level::print_info; -static const auto constexpr critical = log_level::print_critical; -static const auto constexpr error = log_level::print_errors; -static const auto constexpr warning = log_level::print_warnings; -static const auto constexpr hermes = log_level::print_hermes; -static const auto constexpr mercury = log_level::print_mercury; -static const auto constexpr debug = log_level::print_debug; -static const auto constexpr none = log_level::print_none; -static const auto constexpr most = log_level::print_most; -static const auto constexpr all = log_level::print_all; -static const auto constexpr help = log_level::print_help; - -static const auto constexpr level_names = - util::make_array( +static const auto constexpr info = log_level::print_info; +static const auto constexpr critical = log_level::print_critical; +static const auto constexpr error = log_level::print_errors; +static const auto constexpr warning = log_level::print_warnings; +static const auto constexpr hermes = log_level::print_hermes; +static const auto constexpr mercury = log_level::print_mercury; +static const auto constexpr debug = log_level::print_debug; +static const auto constexpr none = log_level::print_none; +static const auto constexpr most = log_level::print_most; +static const auto constexpr all = log_level::print_all; +static const auto constexpr help = log_level::print_help; + +static const auto constexpr level_names = util::make_array( "syscall", "syscall", // sycall_entry uses the same name as syscall - "info", - "critical", - "error", - "warning", - "hermes", - "mercury", - "debug" -); + "info", "critical", "error", "warning", "hermes", "mercury", "debug"); inline constexpr auto lookup_level_name(log_level l) { assert(l != log::none && l != log::help); - // since all log levels are powers of 2, we can find a name + // since all log levels are powers of 2, we can find a name // very efficiently by counting the number of trailing 0-bits in l const auto i = __builtin_ctz(static_cast(l)); assert(i >= 0 && static_cast(i) < level_names.size()); @@ -144,15 +133,13 @@ namespace detail { template static inline void -log_buffer(std::FILE* fp, - Buffer&& buffer) { +log_buffer(std::FILE* fp, Buffer&& buffer) { log_buffer(::fileno(fp), std::forward(buffer)); } template static inline void -log_buffer(int fd, - Buffer&& buffer) { +log_buffer(int fd, Buffer&& buffer) { if(fd < 0) { throw std::runtime_error("Invalid file descriptor"); @@ -162,9 +149,7 @@ log_buffer(int fd, } static inline void -log_buffer(int fd, - const void* buffer, - std::size_t length) { +log_buffer(int fd, const void* buffer, std::size_t length) { if(fd < 0) { throw std::runtime_error("Invalid file descriptor"); } @@ -174,19 +159,19 @@ log_buffer(int fd, /** * format_timestamp_to - safely format a timestamp for logging messages - * - * This function produes a timestamp that can be used to prefix logging + * + * This function produes a timestamp that can be used to prefix logging * messages. Since we are actively intercepting system calls, the formatting - * MUST NOT rely on internal system calls, otherwise we risk recursively - * calling ourselves for each syscall generated. Also, we cannot rely on - * the C formatting functions asctime, ctime, gmtime, localtime, mktime, - * asctime_r, ctime_r, gmtime_r, localtime_r, since they acquire a - * non-reentrant lock to determine the caller's timezone (yes, the assumedly + * MUST NOT rely on internal system calls, otherwise we risk recursively + * calling ourselves for each syscall generated. Also, we cannot rely on + * the C formatting functions asctime, ctime, gmtime, localtime, mktime, + * asctime_r, ctime_r, gmtime_r, localtime_r, since they acquire a + * non-reentrant lock to determine the caller's timezone (yes, the assumedly * reentrant *_r versions of the functions exhibit this problem as well, * see https://sourceware.org/bugzilla/show_bug.cgi?id=16145). To solve this - * issue and still get readable timestamps, we determine and cache the + * issue and still get readable timestamps, we determine and cache the * timezone when the logger is created so that the lock is only held once, by - * one thread exactly, and we pass it as an argument whenever we need to + * one thread exactly, and we pass it as an argument whenever we need to * format a timestamp. If no timezone is provided, we just format the epoch. * * NOTE: we use the date C++ library to query the timezone database and @@ -195,7 +180,7 @@ log_buffer(int fd, template static inline void format_timestamp_to(Buffer&& buffer, - const date::time_zone * const timezone = nullptr) { + const date::time_zone* const timezone = nullptr) { struct ::timeval tv; @@ -206,8 +191,8 @@ format_timestamp_to(Buffer&& buffer, } date::sys_time now{ - std::chrono::seconds{tv.tv_sec} + - std::chrono::microseconds{tv.tv_usec}}; + std::chrono::seconds{tv.tv_sec} + + std::chrono::microseconds{tv.tv_usec}}; if(!timezone) { fmt::format_to(buffer, "[{}] ", now.time_since_epoch().count()); @@ -215,13 +200,12 @@ format_timestamp_to(Buffer&& buffer, } fmt::format_to(buffer, "[{}] ", - date::zoned_time{timezone, now}); + date::zoned_time{timezone, now}); } template static inline void -format_syscall_info_to(Buffer&& buffer, - gkfs::syscall::info info) { +format_syscall_info_to(Buffer&& buffer, gkfs::syscall::info info) { const auto ttid = syscall_no_intercept(SYS_gettid); fmt::format_to(buffer, "[{}] [syscall] ", ttid); @@ -264,29 +248,25 @@ enum { max_buffer_size = LIBGKFS_LOG_MESSAGE_SIZE }; struct static_buffer : public fmt::basic_memory_buffer { protected: - void grow(std::size_t size) override final; + void + grow(std::size_t size) override final; }; struct logger { - logger(const std::string& opts, - const std::string& path, - bool trunc + logger(const std::string& opts, const std::string& path, bool trunc #ifdef GKFS_DEBUG_BUILD , - const std::string& filter, - int verbosity + const std::string& filter, int verbosity #endif - ); + ); ~logger(); template inline void - log(log_level level, - const char * const func, - const int lineno, + log(log_level level, const char* const func, const int lineno, Args&&... args) { if(!(level & log_mask_)) { @@ -295,9 +275,8 @@ struct logger { static_buffer buffer; detail::format_timestamp_to(buffer, timezone_); - fmt::format_to(buffer, "[{}] [{}] ", - ::syscall_no_intercept(SYS_gettid), - lookup_level_name(level)); + fmt::format_to(buffer, "[{}] [{}] ", ::syscall_no_intercept(SYS_gettid), + lookup_level_name(level)); if(!!(level & log::debug)) { fmt::format_to(buffer, "<{}():{}> ", func, lineno); @@ -308,16 +287,14 @@ struct logger { detail::log_buffer(log_fd_, buffer); } - inline int - log(log_level level, - const char *fmt, - va_list ap) { + inline int + log(log_level level, const char* fmt, va_list ap) { if(!(level & log_mask_)) { return 0; } - // we use buffer views to compose the logging messages to + // we use buffer views to compose the logging messages to // avoid copying buffers as much as possible struct buffer_view { const void* addr; @@ -325,28 +302,24 @@ struct logger { }; // helper lambda to print an iterable of buffer_views - const auto log_buffer_views = - [this](const auto& buffers) { + const auto log_buffer_views = [this](const auto& buffers) { + std::size_t n = 0; - std::size_t n = 0; - - for(const auto& bv : buffers) { - if(bv.addr != nullptr) { - detail::log_buffer(log_fd_, bv.addr, bv.size); - n += bv.size; - } + for(const auto& bv : buffers) { + if(bv.addr != nullptr) { + detail::log_buffer(log_fd_, bv.addr, bv.size); + n += bv.size; } + } - return n; - }; - + return n; + }; static_buffer prefix; detail::format_timestamp_to(prefix); - fmt::format_to(prefix, "[{}] [{}] ", - ::syscall_no_intercept(SYS_gettid), - lookup_level_name(level)); + fmt::format_to(prefix, "[{}] [{}] ", ::syscall_no_intercept(SYS_gettid), + lookup_level_name(level)); char buffer[max_buffer_size]; const int n = vsnprintf(buffer, sizeof(buffer), fmt, ap); @@ -357,9 +330,10 @@ struct logger { int m = 0; const char* addr = buffer; const char* p = nullptr; - while((p = std::strstr(addr, "\n")) != nullptr) { + while((p = std::strstr(addr, "\n")) != nullptr) { buffers[0] = buffer_view{prefix.data(), prefix.size()}; - buffers[1] = buffer_view{addr, static_cast(p - addr) + 1}; + buffers[1] = + buffer_view{addr, static_cast(p - addr) + 1}; m += log_buffer_views(buffers); addr = p + 1; @@ -367,9 +341,10 @@ struct logger { } // original line might not end with (or include) '\n' - if(buffer[n-1] != '\n') { + if(buffer[n - 1] != '\n') { buffers[0] = buffer_view{prefix.data(), prefix.size()}; - buffers[1] = buffer_view{addr, static_cast(&buffer[n] - addr)}; + buffers[1] = buffer_view{ + addr, static_cast(&buffer[n] - addr)}; buffers[2] = buffer_view{"\n", 1}; m += log_buffer_views(buffers); @@ -399,12 +374,11 @@ struct logger { } void - log_syscall(syscall::info info, - const long syscall_number, - const long args[6], - boost::optional result = boost::none); + log_syscall(syscall::info info, const long syscall_number, + const long args[6], boost::optional result = boost::none); - static std::shared_ptr& global_logger() { + static std::shared_ptr& + global_logger() { static std::shared_ptr s_global_logger; return s_global_logger; } @@ -417,32 +391,31 @@ struct logger { int debug_verbosity_; #endif - const date::time_zone * timezone_; + const date::time_zone* timezone_; }; -// the following static functions can be used to interact +// the following static functions can be used to interact // with a globally registered logger instance template -static inline void +static inline void create_global_logger(Args&&... args) { auto foo = std::make_shared(std::forward(args)...); logger::global_logger() = foo; - } -static inline void +static inline void register_global_logger(logger&& lg) { logger::global_logger() = std::make_shared(std::move(lg)); } -static inline std::shared_ptr& +static inline std::shared_ptr& get_global_logger() { return logger::global_logger(); } -static inline void +static inline void destroy_global_logger() { logger::global_logger().reset(); } @@ -456,10 +429,11 @@ static_buffer::grow(std::size_t size) { logger->log_mask_ &= ~(syscall | syscall_at_entry); } - std::fprintf(stderr, -"FATAL: message too long for gkfs::log::static_buffer, increase the size of\n" -"LIBGKFS_LOG_MESSAGE_SIZE in CMake or reduce the length of the offending " -"message.\n"); + std::fprintf( + stderr, + "FATAL: message too long for gkfs::log::static_buffer, increase the size of\n" + "LIBGKFS_LOG_MESSAGE_SIZE in CMake or reduce the length of the offending " + "message.\n"); abort(); } @@ -470,78 +444,106 @@ static_buffer::grow(std::size_t size) { #ifndef GKFS_ENABLE_LOGGING -#define LOG_INFO(...) do {} while(0); -#define LOG_WARNING(...) do {} while(0); -#define LOG_ERROR(...) do {} while(0); -#define LOG_CRITICAL(...) do {} while(0); -#define LOG_HERMES(...) do {} while(0); -#define LOG_MERCURY(...) do {} while(0); -#define LOG_SYSCALL(...) do {} while(0); -#define LOG_DEBUG(...) do {} while(0); +#define LOG_INFO(...) \ + do { \ + } while(0); +#define LOG_WARNING(...) \ + do { \ + } while(0); +#define LOG_ERROR(...) \ + do { \ + } while(0); +#define LOG_CRITICAL(...) \ + do { \ + } while(0); +#define LOG_HERMES(...) \ + do { \ + } while(0); +#define LOG_MERCURY(...) \ + do { \ + } while(0); +#define LOG_SYSCALL(...) \ + do { \ + } while(0); +#define LOG_DEBUG(...) \ + do { \ + } while(0); #else // !GKFS_ENABLE_LOGGING -#define LOG_INFO(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::info, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); - -#define LOG_WARNING(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::warning, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); - -#define LOG_ERROR(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::error, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); - -#define LOG_CRITICAL(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::critical, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); - -#define LOG_HERMES(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::hermes, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); - -#define LOG_MERCURY(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::mercury, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); +#define LOG_INFO(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::info, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); + +#define LOG_WARNING(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::warning, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); + +#define LOG_ERROR(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::error, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); + +#define LOG_CRITICAL(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::critical, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); + +#define LOG_HERMES(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::hermes, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); + +#define LOG_MERCURY(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::mercury, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); #ifdef GKFS_DEBUG_BUILD -#define LOG_SYSCALL(...) do { \ -if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log_syscall(__VA_ARGS__); \ - } \ -} while(0); - -#define LOG_DEBUG(...) do { \ - if(gkfs::log::get_global_logger()) { \ - gkfs::log::get_global_logger()->log( \ - gkfs::log::debug, __func__, __LINE__, __VA_ARGS__); \ - } \ -} while(0); +#define LOG_SYSCALL(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log_syscall(__VA_ARGS__); \ + } \ + } while(0); + +#define LOG_DEBUG(...) \ + do { \ + if(gkfs::log::get_global_logger()) { \ + gkfs::log::get_global_logger()->log(gkfs::log::debug, __func__, \ + __LINE__, __VA_ARGS__); \ + } \ + } while(0); #else // ! GKFS_DEBUG_BUILD -#define LOG_SYSCALL(...) do {} while(0); -#define LOG_DEBUG(...) do {} while(0); +#define LOG_SYSCALL(...) \ + do { \ + } while(0); +#define LOG_DEBUG(...) \ + do { \ + } while(0); #endif // ! GKFS_DEBUG_BUILD #endif // !GKFS_ENABLE_LOGGING diff --git a/include/client/make_array.hpp b/include/client/make_array.hpp index 60f308270..5a596b69e 100644 --- a/include/client/make_array.hpp +++ b/include/client/make_array.hpp @@ -17,15 +17,13 @@ namespace gkfs { namespace util { -template -constexpr auto make_array(T&& ... values) -> -std::array< - typename std::decay< - typename std::common_type::type>::type, +template +constexpr auto +make_array(T&&... values) -> std::array< + typename std::decay::type>::type, sizeof...(T)> { return std::array< - typename std::decay< - typename std::common_type::type>::type, + typename std::decay::type>::type, sizeof...(T)>{std::forward(values)...}; } diff --git a/include/client/open_dir.hpp b/include/client/open_dir.hpp index e8111631b..c782cb72f 100644 --- a/include/client/open_dir.hpp +++ b/include/client/open_dir.hpp @@ -27,12 +27,15 @@ class DirEntry { private: std::string name_; FileType type_; + public: DirEntry(const std::string& name, FileType type); - const std::string& name(); + const std::string& + name(); - FileType type(); + FileType + type(); }; class OpenDir : public OpenFile { @@ -43,14 +46,17 @@ private: public: explicit OpenDir(const std::string& path); - void add(const std::string& name, const FileType& type); + void + add(const std::string& name, const FileType& type); - const DirEntry& getdent(unsigned int pos); + const DirEntry& + getdent(unsigned int pos); - size_t size(); + size_t + size(); }; } // namespace filemap } // namespace gkfs -#endif //GEKKOFS_OPEN_DIR_HPP +#endif // GEKKOFS_OPEN_DIR_HPP diff --git a/include/client/open_file_map.hpp b/include/client/open_file_map.hpp index 5199d2e60..b9623c414 100644 --- a/include/client/open_file_map.hpp +++ b/include/client/open_file_map.hpp @@ -38,41 +38,48 @@ enum class OpenFile_flags { flag_count // this is purely used as a size variable of this enum class }; -enum class FileType { - regular, - directory -}; +enum class FileType { regular, directory }; class OpenFile { protected: FileType type_; std::string path_; - std::array(OpenFile_flags::flag_count)> flags_ = {{false}}; + std::array(OpenFile_flags::flag_count)> flags_ = { + {false}}; unsigned long pos_; std::mutex pos_mutex_; std::mutex flag_mutex_; public: - // multiple threads may want to update the file position if fd has been duplicated by dup() + // multiple threads may want to update the file position if fd has been + // duplicated by dup() - OpenFile(const std::string& path, int flags, FileType type = FileType::regular); + OpenFile(const std::string& path, int flags, + FileType type = FileType::regular); ~OpenFile() = default; // getter/setter - std::string path() const; + std::string + path() const; - void path(const std::string& path_); + void + path(const std::string& path_); - unsigned long pos(); + unsigned long + pos(); - void pos(unsigned long pos_); + void + pos(unsigned long pos_); - bool get_flag(OpenFile_flags flag); + bool + get_flag(OpenFile_flags flag); - void set_flag(OpenFile_flags flag, bool value); + void + set_flag(OpenFile_flags flag, bool value); - FileType type() const; + FileType + type() const; }; @@ -82,15 +89,21 @@ private: std::map> files_; std::recursive_mutex files_mutex_; - int safe_generate_fd_idx_(); + int + safe_generate_fd_idx_(); /* - * TODO: Setting our file descriptor index to a specific value is dangerous because we might clash with the kernel. - * E.g., if we would passthrough and not intercept and the kernel assigns a file descriptor but we will later use - * the same fd value, we will intercept calls that were supposed to be going to the kernel. This works the other way around too. - * To mitigate this issue, we set the initial fd number to a high value. We "hope" that we do not clash but this is no permanent solution. - * Note: This solution will probably work well already for many cases because kernel fd values are reused, unlike to ours. - * The only case where we will clash with the kernel is, if one process has more than 100000 files open at the same time. + * TODO: Setting our file descriptor index to a specific value is dangerous + * because we might clash with the kernel. E.g., if we would passthrough and + * not intercept and the kernel assigns a file descriptor but we will later + * use the same fd value, we will intercept calls that were supposed to be + * going to the kernel. This works the other way around too. To mitigate + * this issue, we set the initial fd number to a high value. We "hope" that + * we do not clash but this is no permanent solution. Note: This solution + * will probably work well already for many cases because kernel fd values + * are reused, unlike to ours. The only case where we will clash with the + * kernel is, if one process has more than 100000 files open at the same + * time. */ int fd_idx; std::mutex fd_idx_mutex; @@ -99,26 +112,34 @@ private: public: OpenFileMap(); - std::shared_ptr get(int fd); + std::shared_ptr + get(int fd); - std::shared_ptr get_dir(int dirfd); + std::shared_ptr + get_dir(int dirfd); - bool exist(int fd); + bool + exist(int fd); int add(std::shared_ptr); - bool remove(int fd); + bool + remove(int fd); - int dup(int oldfd); + int + dup(int oldfd); - int dup2(int oldfd, int newfd); + int + dup2(int oldfd, int newfd); - int generate_fd_idx(); + int + generate_fd_idx(); - int get_fd_idx(); + int + get_fd_idx(); }; } // namespace filemap } // namespace gkfs -#endif //GEKKOFS_OPEN_FILE_MAP_HPP +#endif // GEKKOFS_OPEN_FILE_MAP_HPP diff --git a/include/client/path.hpp b/include/client/path.hpp index ad603d4c1..47e161e65 100644 --- a/include/client/path.hpp +++ b/include/client/path.hpp @@ -17,22 +17,31 @@ namespace gkfs { namespace path { -unsigned int match_components(const std::string& path, unsigned int& path_components, - const std::vector& components); +unsigned int +match_components(const std::string& path, unsigned int& path_components, + const std::vector& components); -bool resolve(const std::string& path, std::string& resolved, bool resolve_last_link = true); +bool +resolve(const std::string& path, std::string& resolved, + bool resolve_last_link = true); -std::string get_sys_cwd(); +std::string +get_sys_cwd(); -void set_sys_cwd(const std::string& path); +void +set_sys_cwd(const std::string& path); -void set_env_cwd(const std::string& path); +void +set_env_cwd(const std::string& path); -void unset_env_cwd(); +void +unset_env_cwd(); -void init_cwd(); +void +init_cwd(); -void set_cwd(const std::string& path, bool internal); +void +set_cwd(const std::string& path, bool internal); } // namespace path } // namespace gkfs diff --git a/include/client/preload.hpp b/include/client/preload.hpp index a6e0e7a8c..5d1a89892 100644 --- a/include/client/preload.hpp +++ b/include/client/preload.hpp @@ -21,13 +21,16 @@ #define CTX gkfs::preload::PreloadContext::getInstance() namespace gkfs { namespace preload { -void init_ld_env_if_needed(); +void +init_ld_env_if_needed(); } // namespace preload } // namespace gkfs -void init_preload() __attribute__((constructor)); +void +init_preload() __attribute__((constructor)); -void destroy_preload() __attribute__((destructor)); +void +destroy_preload() __attribute__((destructor)); -#endif //IOINTERCEPT_PRELOAD_HPP +#endif // IOINTERCEPT_PRELOAD_HPP diff --git a/include/client/preload_context.hpp b/include/client/preload_context.hpp index 07e873a0a..c79dbcd61 100644 --- a/include/client/preload_context.hpp +++ b/include/client/preload_context.hpp @@ -51,15 +51,9 @@ struct FsConfig { gid_t gid; std::string rootdir; - }; -enum class RelativizeStatus { - internal, - external, - fd_unknown, - fd_not_a_dir -}; +enum class RelativizeStatus { internal, external, fd_unknown, fd_not_a_dir }; /** * Singleton class of the client context with all relevant global data @@ -94,84 +88,116 @@ private: std::bitset protected_fds_; public: - static PreloadContext* getInstance() { + static PreloadContext* + getInstance() { static PreloadContext instance; return &instance; } PreloadContext(PreloadContext const&) = delete; - void operator=(PreloadContext const&) = delete; + void + operator=(PreloadContext const&) = delete; - void init_logging(); + void + init_logging(); - void mountdir(const std::string& path); + void + mountdir(const std::string& path); - const std::string& mountdir() const; + const std::string& + mountdir() const; - const std::vector& mountdir_components() const; + const std::vector& + mountdir_components() const; - void cwd(const std::string& path); + void + cwd(const std::string& path); - const std::string& cwd() const; + const std::string& + cwd() const; - const std::vector& hosts() const; + const std::vector& + hosts() const; - void hosts(const std::vector& addrs); + void + hosts(const std::vector& addrs); - void clear_hosts(); + void + clear_hosts(); - uint64_t local_host_id() const; + uint64_t + local_host_id() const; - void local_host_id(uint64_t id); + void + local_host_id(uint64_t id); - uint64_t fwd_host_id() const; + uint64_t + fwd_host_id() const; - void fwd_host_id(uint64_t id); + void + fwd_host_id(uint64_t id); - const std::string& rpc_protocol() const; + const std::string& + rpc_protocol() const; - void rpc_protocol(const std::string& rpc_protocol); + void + rpc_protocol(const std::string& rpc_protocol); - bool auto_sm() const; + bool + auto_sm() const; - void auto_sm(bool auto_sm); + void + auto_sm(bool auto_sm); - RelativizeStatus relativize_fd_path(int dirfd, - const char* raw_path, - std::string& relative_path, - bool resolve_last_link = true) const; + RelativizeStatus + relativize_fd_path(int dirfd, const char* raw_path, + std::string& relative_path, + bool resolve_last_link = true) const; - bool relativize_path(const char* raw_path, std::string& relative_path, bool resolve_last_link = true) const; + bool + relativize_path(const char* raw_path, std::string& relative_path, + bool resolve_last_link = true) const; - const std::shared_ptr& file_map() const; + const std::shared_ptr& + file_map() const; - void distributor(std::shared_ptr distributor); + void + distributor(std::shared_ptr distributor); - std::shared_ptr distributor() const; + std::shared_ptr + distributor() const; - const std::shared_ptr& fs_conf() const; + const std::shared_ptr& + fs_conf() const; - void enable_interception(); + void + enable_interception(); - void disable_interception(); + void + disable_interception(); - bool interception_enabled() const; + bool + interception_enabled() const; - int register_internal_fd(int fd); + int + register_internal_fd(int fd); - void unregister_internal_fd(int fd); + void + unregister_internal_fd(int fd); - bool is_internal_fd(int fd) const; + bool + is_internal_fd(int fd) const; - void protect_user_fds(); + void + protect_user_fds(); - void unprotect_user_fds(); + void + unprotect_user_fds(); }; } // namespace preload } // namespace gkfs -#endif //GEKKOFS_PRELOAD_CTX_HPP - +#endif // GEKKOFS_PRELOAD_CTX_HPP diff --git a/include/client/preload_util.hpp b/include/client/preload_util.hpp index 592b1ede8..0636878d4 100644 --- a/include/client/preload_util.hpp +++ b/include/client/preload_util.hpp @@ -43,31 +43,41 @@ struct MetadentryUpdateFlags { } // namespace gkfs // Hermes instance -namespace hermes { class async_engine; } +namespace hermes { +class async_engine; +} extern std::unique_ptr ld_network_service; // function definitions namespace gkfs { namespace util { -template -constexpr typename std::underlying_type::type to_underlying(E e) { +template +constexpr typename std::underlying_type::type +to_underlying(E e) { return static_cast::type>(e); } -std::shared_ptr get_metadata(const std::string& path, bool follow_links = false); +std::shared_ptr +get_metadata(const std::string& path, bool follow_links = false); -int metadata_to_stat(const std::string& path, const gkfs::metadata::Metadata& md, struct stat& attr); +int +metadata_to_stat(const std::string& path, const gkfs::metadata::Metadata& md, + struct stat& attr); -void load_hosts(); +void +load_hosts(); -void load_forwarding_map(); +void +load_forwarding_map(); -std::vector> read_hosts_file(); +std::vector> +read_hosts_file(); -void connect_to_hosts(const std::vector>& hosts); +void +connect_to_hosts(const std::vector>& hosts); } // namespace util } // namespace gkfs -#endif //GEKKOFS_PRELOAD_UTIL_HPP +#endif // GEKKOFS_PRELOAD_UTIL_HPP diff --git a/include/client/rpc/forward_data.hpp b/include/client/rpc/forward_data.hpp index 253f16647..005ea00d4 100644 --- a/include/client/rpc/forward_data.hpp +++ b/include/client/rpc/forward_data.hpp @@ -24,18 +24,25 @@ struct ChunkStat { unsigned long chunk_free; }; -// TODO once we have LEAF, remove all the error code returns and throw them as an exception. +// TODO once we have LEAF, remove all the error code returns and throw them as +// an exception. -std::pair forward_write(const std::string& path, const void* buf, bool append_flag, off64_t in_offset, - size_t write_size, int64_t updated_metadentry_size); +std::pair +forward_write(const std::string& path, const void* buf, bool append_flag, + off64_t in_offset, size_t write_size, + int64_t updated_metadentry_size); -std::pair forward_read(const std::string& path, void* buf, off64_t offset, size_t read_size); +std::pair +forward_read(const std::string& path, void* buf, off64_t offset, + size_t read_size); -int forward_truncate(const std::string& path, size_t current_size, size_t new_size); +int +forward_truncate(const std::string& path, size_t current_size, size_t new_size); -std::pair forward_get_chunk_stat(); +std::pair +forward_get_chunk_stat(); } // namespace rpc } // namespace gkfs -#endif //GEKKOFS_CLIENT_FORWARD_DATA_HPP +#endif // GEKKOFS_CLIENT_FORWARD_DATA_HPP diff --git a/include/client/rpc/forward_management.hpp b/include/client/rpc/forward_management.hpp index a25bed442..539f55cb8 100644 --- a/include/client/rpc/forward_management.hpp +++ b/include/client/rpc/forward_management.hpp @@ -18,9 +18,10 @@ namespace gkfs { namespace rpc { -bool forward_get_fs_config(); +bool +forward_get_fs_config(); } // namespace rpc } // namespace gkfs -#endif //GEKKOFS_CLIENT_FORWARD_MNGMNT_HPP +#endif // GEKKOFS_CLIENT_FORWARD_MNGMNT_HPP diff --git a/include/client/rpc/forward_metadata.hpp b/include/client/rpc/forward_metadata.hpp index e8c119d91..2cbfbdb50 100644 --- a/include/client/rpc/forward_metadata.hpp +++ b/include/client/rpc/forward_metadata.hpp @@ -27,33 +27,45 @@ namespace metadata { struct MetadentryUpdateFlags; class Metadata; -} +} // namespace metadata -// TODO once we have LEAF, remove all the error code returns and throw them as an exception. +// TODO once we have LEAF, remove all the error code returns and throw them as +// an exception. namespace rpc { -int forward_create(const std::string& path, mode_t mode); +int +forward_create(const std::string& path, mode_t mode); -int forward_stat(const std::string& path, std::string& attr); +int +forward_stat(const std::string& path, std::string& attr); -int forward_remove(const std::string& path, bool remove_metadentry_only, ssize_t size); +int +forward_remove(const std::string& path, bool remove_metadentry_only, + ssize_t size); -int forward_decr_size(const std::string& path, size_t length); +int +forward_decr_size(const std::string& path, size_t length); -int forward_update_metadentry(const std::string& path, const gkfs::metadata::Metadata& md, - const gkfs::metadata::MetadentryUpdateFlags& md_flags); +int +forward_update_metadentry( + const std::string& path, const gkfs::metadata::Metadata& md, + const gkfs::metadata::MetadentryUpdateFlags& md_flags); std::pair -forward_update_metadentry_size(const std::string& path, size_t size, off64_t offset, bool append_flag); +forward_update_metadentry_size(const std::string& path, size_t size, + off64_t offset, bool append_flag); -std::pair forward_get_metadentry_size(const std::string& path); +std::pair +forward_get_metadentry_size(const std::string& path); -std::pair> forward_get_dirents(const std::string& path); +std::pair> +forward_get_dirents(const std::string& path); #ifdef HAS_SYMLINKS -int forward_mk_symlink(const std::string& path, const std::string& target_path); +int +forward_mk_symlink(const std::string& path, const std::string& target_path); #endif @@ -61,4 +73,4 @@ int forward_mk_symlink(const std::string& path, const std::string& target_path); } // namespace rpc } // namespace gkfs -#endif //GEKKOFS_CLIENT_FORWARD_METADATA_HPP +#endif // GEKKOFS_CLIENT_FORWARD_METADATA_HPP diff --git a/include/client/rpc/rpc_types.hpp b/include/client/rpc/rpc_types.hpp index edfac30e3..ec4b2448c 100644 --- a/include/client/rpc/rpc_types.hpp +++ b/include/client/rpc/rpc_types.hpp @@ -26,8 +26,7 @@ #include #ifndef HG_GEN_PROC_NAME -#define HG_GEN_PROC_NAME(struct_type_name) \ - hg_proc_ ## struct_type_name +#define HG_GEN_PROC_NAME(struct_type_name) hg_proc_##struct_type_name #endif @@ -37,8 +36,7 @@ namespace hermes { namespace detail { -struct hg_void_t { -}; +struct hg_void_t {}; static HG_INLINE hg_return_t hg_proc_void_t(hg_proc_t proc, void* data) { @@ -48,8 +46,8 @@ hg_proc_void_t(hg_proc_t proc, void* data) { return HG_SUCCESS; } -} -} // namespace hermes::detail +} // namespace detail +} // namespace hermes namespace gkfs { namespace rpc { @@ -95,8 +93,9 @@ struct fs_config { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: input() {} @@ -105,71 +104,57 @@ struct fs_config { input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; - explicit - input(const hermes::detail::hg_void_t& other) {} + explicit input(const hermes::detail::hg_void_t& other) {} - explicit - operator hermes::detail::hg_void_t() { + explicit operator hermes::detail::hg_void_t() { return {}; } }; class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_mountdir(), - m_rootdir(), - m_atime_state(), - m_mtime_state(), - m_ctime_state(), - m_link_cnt_state(), - m_blocks_state(), - m_uid(), - m_gid() {} - - output(const std::string& mountdir, - const std::string& rootdir, - bool atime_state, - bool mtime_state, - bool ctime_state, - bool link_cnt_state, - bool blocks_state, - uint32_t uid, - uint32_t gid) : - m_mountdir(mountdir), - m_rootdir(rootdir), - m_atime_state(atime_state), - m_mtime_state(mtime_state), - m_ctime_state(ctime_state), - m_link_cnt_state(link_cnt_state), - m_blocks_state(blocks_state), - m_uid(uid), - m_gid(gid) {} + output() + : m_mountdir(), m_rootdir(), m_atime_state(), m_mtime_state(), + m_ctime_state(), m_link_cnt_state(), m_blocks_state(), m_uid(), + m_gid() {} + + output(const std::string& mountdir, const std::string& rootdir, + bool atime_state, bool mtime_state, bool ctime_state, + bool link_cnt_state, bool blocks_state, uint32_t uid, + uint32_t gid) + : m_mountdir(mountdir), m_rootdir(rootdir), + m_atime_state(atime_state), m_mtime_state(mtime_state), + m_ctime_state(ctime_state), m_link_cnt_state(link_cnt_state), + m_blocks_state(blocks_state), m_uid(uid), m_gid(gid) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_config_out_t& out) { + explicit output(const rpc_config_out_t& out) { - if (out.mountdir != nullptr) { + if(out.mountdir != nullptr) { m_mountdir = out.mountdir; } - if (out.rootdir != nullptr) { + if(out.rootdir != nullptr) { m_rootdir = out.rootdir; } @@ -282,22 +267,23 @@ struct create { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - uint32_t mode) : - m_path(path), - m_mode(mode) {} + input(const std::string& path, uint32_t mode) + : m_path(path), m_mode(mode) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -309,13 +295,10 @@ struct create { return m_mode; } - explicit - input(const rpc_mk_node_in_t& other) : - m_path(other.path), - m_mode(other.mode) {} + explicit input(const rpc_mk_node_in_t& other) + : m_path(other.path), m_mode(other.mode) {} - explicit - operator rpc_mk_node_in_t() { + explicit operator rpc_mk_node_in_t() { return {m_path.c_str(), m_mode}; } @@ -326,26 +309,26 @@ struct create { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err() {} + output() : m_err() {} - output(int32_t err) : - m_err(err) {} + output(int32_t err) : m_err(err) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_err_out_t& out) { + explicit output(const rpc_err_out_t& out) { m_err = out.err; } @@ -400,32 +383,31 @@ struct stat { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path) : - m_path(path) {} + input(const std::string& path) : m_path(path) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { return m_path; } - explicit - input(const rpc_path_only_in_t& other) : - m_path(other.path) {} + explicit input(const rpc_path_only_in_t& other) : m_path(other.path) {} - explicit - operator rpc_path_only_in_t() { + explicit operator rpc_path_only_in_t() { return {m_path.c_str()}; } @@ -435,31 +417,30 @@ struct stat { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_db_val() {} + output() : m_err(), m_db_val() {} - output(int32_t err, const std::string& db_val) : - m_err(err), - m_db_val(db_val) {} + output(int32_t err, const std::string& db_val) + : m_err(err), m_db_val(db_val) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_stat_out_t& out) { + explicit output(const rpc_stat_out_t& out) { m_err = out.err; - if (out.db_val != nullptr) { + if(out.db_val != nullptr) { m_db_val = out.db_val; } } @@ -521,32 +502,31 @@ struct remove { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path) : - m_path(path) {} + input(const std::string& path) : m_path(path) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { return m_path; } - explicit - input(const rpc_rm_node_in_t& other) : - m_path(other.path) {} + explicit input(const rpc_rm_node_in_t& other) : m_path(other.path) {} - explicit - operator rpc_rm_node_in_t() { + explicit operator rpc_rm_node_in_t() { return {m_path.c_str()}; } @@ -556,26 +536,26 @@ struct remove { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err() {} + output() : m_err() {} - output(int32_t err) : - m_err(err) {} + output(int32_t err) : m_err(err) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_err_out_t& out) { + explicit output(const rpc_err_out_t& out) { m_err = out.err; } @@ -630,21 +610,23 @@ struct decr_size { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, uint64_t length) : - m_path(path), - m_length(length) {} + input(const std::string& path, uint64_t length) + : m_path(path), m_length(length) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -656,13 +638,10 @@ struct decr_size { return m_length; } - explicit - input(const rpc_trunc_in_t& other) : - m_path(other.path), - m_length(other.length) {} + explicit input(const rpc_trunc_in_t& other) + : m_path(other.path), m_length(other.length) {} - explicit - operator rpc_trunc_in_t() { + explicit operator rpc_trunc_in_t() { return {m_path.c_str(), m_length}; } @@ -673,26 +652,26 @@ struct decr_size { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err() {} + output() : m_err() {} - output(int32_t err) : - m_err(err) {} + output(int32_t err) : m_err(err) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_err_out_t& out) { + explicit output(const rpc_err_out_t& out) { m_err = out.err; } @@ -747,52 +726,32 @@ struct update_metadentry { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - uint64_t nlink, - uint32_t mode, - uint32_t uid, - uint32_t gid, - int64_t size, - int64_t blocks, - int64_t atime, - int64_t mtime, - int64_t ctime, - bool nlink_flag, - bool mode_flag, - bool size_flag, - bool block_flag, - bool atime_flag, - bool mtime_flag, - bool ctime_flag) : - m_path(path), - m_nlink(nlink), - m_mode(mode), - m_uid(uid), - m_gid(gid), - m_size(size), - m_blocks(blocks), - m_atime(atime), - m_mtime(mtime), - m_ctime(ctime), - m_nlink_flag(nlink_flag), - m_mode_flag(mode_flag), - m_size_flag(size_flag), - m_block_flag(block_flag), - m_atime_flag(atime_flag), - m_mtime_flag(mtime_flag), - m_ctime_flag(ctime_flag) {} + input(const std::string& path, uint64_t nlink, uint32_t mode, + uint32_t uid, uint32_t gid, int64_t size, int64_t blocks, + int64_t atime, int64_t mtime, int64_t ctime, bool nlink_flag, + bool mode_flag, bool size_flag, bool block_flag, bool atime_flag, + bool mtime_flag, bool ctime_flag) + : m_path(path), m_nlink(nlink), m_mode(mode), m_uid(uid), + m_gid(gid), m_size(size), m_blocks(blocks), m_atime(atime), + m_mtime(mtime), m_ctime(ctime), m_nlink_flag(nlink_flag), + m_mode_flag(mode_flag), m_size_flag(size_flag), + m_block_flag(block_flag), m_atime_flag(atime_flag), + m_mtime_flag(mtime_flag), m_ctime_flag(ctime_flag) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -879,44 +838,21 @@ struct update_metadentry { return m_ctime_flag; } - explicit - input(const rpc_update_metadentry_in_t& other) : - m_path(other.path), - m_nlink(other.nlink), - m_mode(other.mode), - m_uid(other.uid), - m_gid(other.gid), - m_size(other.size), - m_blocks(other.blocks), - m_atime(other.atime), - m_mtime(other.mtime), - m_ctime(other.ctime), - m_nlink_flag(other.nlink_flag), - m_mode_flag(other.mode_flag), - m_size_flag(other.size_flag), - m_block_flag(other.block_flag), - m_atime_flag(other.atime_flag), - m_mtime_flag(other.mtime_flag), - m_ctime_flag(other.ctime_flag) {} - - explicit - operator rpc_update_metadentry_in_t() { - return {m_path.c_str(), - m_nlink, - m_mode, - m_uid, - m_gid, - m_size, - m_blocks, - m_atime, - m_mtime, - m_ctime, - m_nlink_flag, - m_mode_flag, - m_size_flag, - m_block_flag, - m_atime_flag, - m_mtime_flag, + explicit input(const rpc_update_metadentry_in_t& other) + : m_path(other.path), m_nlink(other.nlink), m_mode(other.mode), + m_uid(other.uid), m_gid(other.gid), m_size(other.size), + m_blocks(other.blocks), m_atime(other.atime), + m_mtime(other.mtime), m_ctime(other.ctime), + m_nlink_flag(other.nlink_flag), m_mode_flag(other.mode_flag), + m_size_flag(other.size_flag), m_block_flag(other.block_flag), + m_atime_flag(other.atime_flag), m_mtime_flag(other.mtime_flag), + m_ctime_flag(other.ctime_flag) {} + + explicit operator rpc_update_metadentry_in_t() { + return {m_path.c_str(), m_nlink, m_mode, m_uid, + m_gid, m_size, m_blocks, m_atime, + m_mtime, m_ctime, m_nlink_flag, m_mode_flag, + m_size_flag, m_block_flag, m_atime_flag, m_mtime_flag, m_ctime_flag}; } @@ -942,26 +878,26 @@ struct update_metadentry { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err() {} + output() : m_err() {} - output(int32_t err) : - m_err(err) {} + output(int32_t err) : m_err(err) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_err_out_t& out) { + explicit output(const rpc_err_out_t& out) { m_err = out.err; } @@ -1016,32 +952,31 @@ struct get_metadentry_size { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path) : - m_path(path) {} + input(const std::string& path) : m_path(path) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { return m_path; } - explicit - input(const rpc_path_only_in_t& other) : - m_path(other.path) {} + explicit input(const rpc_path_only_in_t& other) : m_path(other.path) {} - explicit - operator rpc_path_only_in_t() { + explicit operator rpc_path_only_in_t() { return {m_path.c_str()}; } @@ -1051,28 +986,27 @@ struct get_metadentry_size { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_ret_size() {} + output() : m_err(), m_ret_size() {} - output(int32_t err, int64_t ret_size) : - m_err(err), - m_ret_size(ret_size) {} + output(int32_t err, int64_t ret_size) + : m_err(err), m_ret_size(ret_size) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_get_metadentry_size_out_t& out) { + explicit output(const rpc_get_metadentry_size_out_t& out) { m_err = out.err; m_ret_size = out.ret_size; } @@ -1134,26 +1068,24 @@ struct update_metadentry_size { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - uint64_t size, - int64_t offset, - bool append) : - m_path(path), - m_size(size), - m_offset(offset), - m_append(append) {} + input(const std::string& path, uint64_t size, int64_t offset, + bool append) + : m_path(path), m_size(size), m_offset(offset), m_append(append) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -1175,15 +1107,11 @@ struct update_metadentry_size { return m_append; } - explicit - input(const rpc_update_metadentry_size_in_t& other) : - m_path(other.path), - m_size(other.size), - m_offset(other.offset), - m_append(other.append) {} + explicit input(const rpc_update_metadentry_size_in_t& other) + : m_path(other.path), m_size(other.size), m_offset(other.offset), + m_append(other.append) {} - explicit - operator rpc_update_metadentry_size_in_t() { + explicit operator rpc_update_metadentry_size_in_t() { return {m_path.c_str(), m_size, m_offset, m_append}; } @@ -1196,28 +1124,27 @@ struct update_metadentry_size { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_ret_size() {} + output() : m_err(), m_ret_size() {} - output(int32_t err, int64_t ret_size) : - m_err(err), - m_ret_size(ret_size) {} + output(int32_t err, int64_t ret_size) + : m_err(err), m_ret_size(ret_size) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_update_metadentry_size_out_t& out) { + explicit output(const rpc_update_metadentry_size_out_t& out) { m_err = out.err; m_ret_size = out.ret_size; } @@ -1281,22 +1208,23 @@ struct mk_symlink { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - const std::string& target_path) : - m_path(path), - m_target_path(target_path) {} + input(const std::string& path, const std::string& target_path) + : m_path(path), m_target_path(target_path) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -1308,13 +1236,10 @@ struct mk_symlink { return m_target_path; } - explicit - input(const rpc_mk_symlink_in_t& other) : - m_path(other.path), - m_target_path(other.target_path) {} + explicit input(const rpc_mk_symlink_in_t& other) + : m_path(other.path), m_target_path(other.target_path) {} - explicit - operator rpc_mk_symlink_in_t() { + explicit operator rpc_mk_symlink_in_t() { return {m_path.c_str(), m_target_path.c_str()}; } @@ -1325,26 +1250,26 @@ struct mk_symlink { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err() {} + output() : m_err() {} - output(int32_t err) : - m_err(err) {} + output(int32_t err) : m_err(err) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_err_out_t& out) { + explicit output(const rpc_err_out_t& out) { m_err = out.err; } @@ -1401,36 +1326,29 @@ struct write_data { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - int64_t offset, - uint64_t host_id, - uint64_t host_size, - uint64_t chunk_n, - uint64_t chunk_start, - uint64_t chunk_end, - uint64_t total_chunk_size, - const hermes::exposed_memory& buffers) : - m_path(path), - m_offset(offset), - m_host_id(host_id), - m_host_size(host_size), - m_chunk_n(chunk_n), - m_chunk_start(chunk_start), - m_chunk_end(chunk_end), - m_total_chunk_size(total_chunk_size), - m_buffers(buffers) {} + input(const std::string& path, int64_t offset, uint64_t host_id, + uint64_t host_size, uint64_t chunk_n, uint64_t chunk_start, + uint64_t chunk_end, uint64_t total_chunk_size, + const hermes::exposed_memory& buffers) + : m_path(path), m_offset(offset), m_host_id(host_id), + m_host_size(host_size), m_chunk_n(chunk_n), + m_chunk_start(chunk_start), m_chunk_end(chunk_end), + m_total_chunk_size(total_chunk_size), m_buffers(buffers) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -1477,31 +1395,18 @@ struct write_data { return m_buffers; } - explicit - input(const rpc_write_data_in_t& other) : - m_path(other.path), - m_offset(other.offset), - m_host_id(other.host_id), - m_host_size(other.host_size), - m_chunk_n(other.chunk_n), - m_chunk_start(other.chunk_start), - m_chunk_end(other.chunk_end), - m_total_chunk_size(other.total_chunk_size), - m_buffers(other.bulk_handle) {} - - explicit - operator rpc_write_data_in_t() { - return { - m_path.c_str(), - m_offset, - m_host_id, - m_host_size, - m_chunk_n, - m_chunk_start, - m_chunk_end, - m_total_chunk_size, - hg_bulk_t(m_buffers) - }; + explicit input(const rpc_write_data_in_t& other) + : m_path(other.path), m_offset(other.offset), + m_host_id(other.host_id), m_host_size(other.host_size), + m_chunk_n(other.chunk_n), m_chunk_start(other.chunk_start), + m_chunk_end(other.chunk_end), + m_total_chunk_size(other.total_chunk_size), + m_buffers(other.bulk_handle) {} + + explicit operator rpc_write_data_in_t() { + return {m_path.c_str(), m_offset, m_host_id, + m_host_size, m_chunk_n, m_chunk_start, + m_chunk_end, m_total_chunk_size, hg_bulk_t(m_buffers)}; } private: @@ -1518,28 +1423,26 @@ struct write_data { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_io_size() {} + output() : m_err(), m_io_size() {} - output(int32_t err, size_t io_size) : - m_err(err), - m_io_size(io_size) {} + output(int32_t err, size_t io_size) : m_err(err), m_io_size(io_size) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_data_out_t& out) { + explicit output(const rpc_data_out_t& out) { m_err = out.err; m_io_size = out.io_size; } @@ -1601,36 +1504,29 @@ struct read_data { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - int64_t offset, - uint64_t host_id, - uint64_t host_size, - uint64_t chunk_n, - uint64_t chunk_start, - uint64_t chunk_end, - uint64_t total_chunk_size, - const hermes::exposed_memory& buffers) : - m_path(path), - m_offset(offset), - m_host_id(host_id), - m_host_size(host_size), - m_chunk_n(chunk_n), - m_chunk_start(chunk_start), - m_chunk_end(chunk_end), - m_total_chunk_size(total_chunk_size), - m_buffers(buffers) {} + input(const std::string& path, int64_t offset, uint64_t host_id, + uint64_t host_size, uint64_t chunk_n, uint64_t chunk_start, + uint64_t chunk_end, uint64_t total_chunk_size, + const hermes::exposed_memory& buffers) + : m_path(path), m_offset(offset), m_host_id(host_id), + m_host_size(host_size), m_chunk_n(chunk_n), + m_chunk_start(chunk_start), m_chunk_end(chunk_end), + m_total_chunk_size(total_chunk_size), m_buffers(buffers) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -1677,31 +1573,18 @@ struct read_data { return m_buffers; } - explicit - input(const rpc_read_data_in_t& other) : - m_path(other.path), - m_offset(other.offset), - m_host_id(other.host_id), - m_host_size(other.host_size), - m_chunk_n(other.chunk_n), - m_chunk_start(other.chunk_start), - m_chunk_end(other.chunk_end), - m_total_chunk_size(other.total_chunk_size), - m_buffers(other.bulk_handle) {} - - explicit - operator rpc_read_data_in_t() { - return { - m_path.c_str(), - m_offset, - m_host_id, - m_host_size, - m_chunk_n, - m_chunk_start, - m_chunk_end, - m_total_chunk_size, - hg_bulk_t(m_buffers) - }; + explicit input(const rpc_read_data_in_t& other) + : m_path(other.path), m_offset(other.offset), + m_host_id(other.host_id), m_host_size(other.host_size), + m_chunk_n(other.chunk_n), m_chunk_start(other.chunk_start), + m_chunk_end(other.chunk_end), + m_total_chunk_size(other.total_chunk_size), + m_buffers(other.bulk_handle) {} + + explicit operator rpc_read_data_in_t() { + return {m_path.c_str(), m_offset, m_host_id, + m_host_size, m_chunk_n, m_chunk_start, + m_chunk_end, m_total_chunk_size, hg_bulk_t(m_buffers)}; } private: @@ -1718,28 +1601,26 @@ struct read_data { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_io_size() {} + output() : m_err(), m_io_size() {} - output(int32_t err, size_t io_size) : - m_err(err), - m_io_size(io_size) {} + output(int32_t err, size_t io_size) : m_err(err), m_io_size(io_size) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_data_out_t& out) { + explicit output(const rpc_data_out_t& out) { m_err = out.err; m_io_size = out.io_size; } @@ -1801,22 +1682,23 @@ struct trunc_data { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - uint64_t length) : - m_path(path), - m_length(length) {} + input(const std::string& path, uint64_t length) + : m_path(path), m_length(length) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -1828,13 +1710,10 @@ struct trunc_data { return m_length; } - explicit - input(const rpc_trunc_in_t& other) : - m_path(other.path), - m_length(other.length) {} + explicit input(const rpc_trunc_in_t& other) + : m_path(other.path), m_length(other.length) {} - explicit - operator rpc_trunc_in_t() { + explicit operator rpc_trunc_in_t() { return { m_path.c_str(), m_length, @@ -1848,26 +1727,26 @@ struct trunc_data { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err() {} + output() : m_err() {} - output(int32_t err) : - m_err(err) {} + output(int32_t err) : m_err(err) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_err_out_t& out) { + explicit output(const rpc_err_out_t& out) { m_err = out.err; } @@ -1922,22 +1801,23 @@ struct get_dirents { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(const std::string& path, - const hermes::exposed_memory& buffers) : - m_path(path), - m_buffers(buffers) {} + input(const std::string& path, const hermes::exposed_memory& buffers) + : m_path(path), m_buffers(buffers) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; std::string path() const { @@ -1949,17 +1829,11 @@ struct get_dirents { return m_buffers; } - explicit - input(const rpc_get_dirents_in_t& other) : - m_path(other.path), - m_buffers(other.bulk_handle) {} + explicit input(const rpc_get_dirents_in_t& other) + : m_path(other.path), m_buffers(other.bulk_handle) {} - explicit - operator rpc_get_dirents_in_t() { - return { - m_path.c_str(), - hg_bulk_t(m_buffers) - }; + explicit operator rpc_get_dirents_in_t() { + return {m_path.c_str(), hg_bulk_t(m_buffers)}; } private: @@ -1969,28 +1843,27 @@ struct get_dirents { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_dirents_size() {} + output() : m_err(), m_dirents_size() {} - output(int32_t err, size_t dirents_size) : - m_err(err), - m_dirents_size(dirents_size) {} + output(int32_t err, size_t dirents_size) + : m_err(err), m_dirents_size(dirents_size) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_get_dirents_out_t& out) { + explicit output(const rpc_get_dirents_out_t& out) { m_err = out.err; m_dirents_size = out.dirents_size; } @@ -2052,32 +1925,32 @@ struct chunk_stat { class input { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - input(int32_t dummy) : - m_dummy(dummy) {} + input(int32_t dummy) : m_dummy(dummy) {} input(input&& rhs) = default; input(const input& other) = default; - input& operator=(input&& rhs) = default; + input& + operator=(input&& rhs) = default; - input& operator=(const input& other) = default; + input& + operator=(const input& other) = default; int32_t dummy() const { return m_dummy; } - explicit - input(const rpc_chunk_stat_in_t& other) : - m_dummy(other.dummy) {} + explicit input(const rpc_chunk_stat_in_t& other) + : m_dummy(other.dummy) {} - explicit - operator rpc_chunk_stat_in_t() { + explicit operator rpc_chunk_stat_in_t() { return {m_dummy}; } @@ -2087,32 +1960,29 @@ struct chunk_stat { class output { - template - friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*); + template + friend hg_return_t + hermes::detail::post_to_mercury(ExecutionContext*); public: - output() : - m_err(), - m_chunk_size(), - m_chunk_total(), - m_chunk_free() {} - - output(int32_t err, uint64_t chunk_size, uint64_t chunk_total, uint64_t chunk_free) : - m_err(err), - m_chunk_size(chunk_size), - m_chunk_total(chunk_total), - m_chunk_free(chunk_free) {} + output() : m_err(), m_chunk_size(), m_chunk_total(), m_chunk_free() {} + + output(int32_t err, uint64_t chunk_size, uint64_t chunk_total, + uint64_t chunk_free) + : m_err(err), m_chunk_size(chunk_size), m_chunk_total(chunk_total), + m_chunk_free(chunk_free) {} output(output&& rhs) = default; output(const output& other) = default; - output& operator=(output&& rhs) = default; + output& + operator=(output&& rhs) = default; - output& operator=(const output& other) = default; + output& + operator=(const output& other) = default; - explicit - output(const rpc_chunk_stat_out_t& out) { + explicit output(const rpc_chunk_stat_out_t& out) { m_err = out.err; m_chunk_size = out.chunk_size; m_chunk_total = out.chunk_total; diff --git a/include/config.hpp b/include/config.hpp index 83b5f4bc2..98928b75d 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -39,8 +39,8 @@ constexpr auto client_log_path = "/tmp/gkfs_client.log"; constexpr auto daemon_log_path = "/tmp/gkfs_daemon.log"; constexpr auto client_log_level = "info,errors,critical,hermes"; -constexpr auto daemon_log_level = 4; //info -} // namespace logging +constexpr auto daemon_log_level = 4; // info +} // namespace log namespace metadata { // which metadata should be considered apart from size and mode @@ -53,11 +53,12 @@ constexpr auto use_blocks = false; namespace rpc { constexpr auto chunksize = 524288; // in bytes (e.g., 524288 == 512KB) -//size of preallocated buffer to hold directory entries in rpc call +// size of preallocated buffer to hold directory entries in rpc call constexpr auto dirents_buff_size = (8 * 1024 * 1024); // 8 mega /* - * Indicates the number of concurrent progress to drive I/O operations of chunk files to and from local file systems - * The value is directly mapped to created Argobots xstreams, controlled in a single pool with ABT_snoozer scheduler + * Indicates the number of concurrent progress to drive I/O operations of chunk + * files to and from local file systems The value is directly mapped to created + * Argobots xstreams, controlled in a single pool with ABT_snoozer scheduler */ constexpr auto daemon_io_xstreams = 8; // Number of threads used for RPC handlers at the daemon @@ -69,7 +70,7 @@ namespace rocksdb { constexpr auto use_write_ahead_log = false; } // namespace rocksdb -} // namespace gkfs } // namespace config +} // namespace gkfs -#endif //GEKKOFS_CONFIG_HPP +#endif // GEKKOFS_CONFIG_HPP diff --git a/include/daemon/backend/data/chunk_storage.hpp b/include/daemon/backend/data/chunk_storage.hpp index 934cfe513..6a8f2c433 100644 --- a/include/daemon/backend/data/chunk_storage.hpp +++ b/include/daemon/backend/data/chunk_storage.hpp @@ -37,46 +37,56 @@ struct ChunkStat { class ChunkStorageException : public std::system_error { public: - ChunkStorageException(const int err_code, const std::string& s) : std::system_error(err_code, - std::generic_category(), s) {}; + ChunkStorageException(const int err_code, const std::string& s) + : std::system_error(err_code, std::generic_category(), s){}; }; class ChunkStorage { private: - std::shared_ptr log_; std::string root_path_; size_t chunksize_; - inline std::string absolute(const std::string& internal_path) const; + inline std::string + absolute(const std::string& internal_path) const; - static inline std::string get_chunks_dir(const std::string& file_path); + static inline std::string + get_chunks_dir(const std::string& file_path); - static inline std::string get_chunk_path(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id); + static inline std::string + get_chunk_path(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id); - void init_chunk_space(const std::string& file_path) const; + void + init_chunk_space(const std::string& file_path) const; public: ChunkStorage(std::string& path, size_t chunksize); - void destroy_chunk_space(const std::string& file_path) const; + void + destroy_chunk_space(const std::string& file_path) const; ssize_t - write_chunk(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id, const char* buf, size_t size, - off64_t offset) const; + write_chunk(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id, + const char* buf, size_t size, off64_t offset) const; - ssize_t read_chunk(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id, char* buf, size_t size, - off64_t offset) const; + ssize_t + read_chunk(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id, + char* buf, size_t size, off64_t offset) const; - void trim_chunk_space(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_start); + void + trim_chunk_space(const std::string& file_path, + gkfs::rpc::chnk_id_t chunk_start); - void truncate_chunk_file(const std::string& file_path, gkfs::rpc::chnk_id_t chunk_id, off_t length); + void + truncate_chunk_file(const std::string& file_path, + gkfs::rpc::chnk_id_t chunk_id, off_t length); - ChunkStat chunk_stat() const; + ChunkStat + chunk_stat() const; }; } // namespace data } // namespace gkfs -#endif //GEKKOFS_CHUNK_STORAGE_HPP +#endif // GEKKOFS_CHUNK_STORAGE_HPP diff --git a/include/daemon/backend/data/data_module.hpp b/include/daemon/backend/data/data_module.hpp index 63c2fc4da..e6a14b686 100644 --- a/include/daemon/backend/data/data_module.hpp +++ b/include/daemon/backend/data/data_module.hpp @@ -27,27 +27,31 @@ private: std::shared_ptr log_; public: - static constexpr const char* LOGGER_NAME = "DataModule"; - static DataModule* getInstance() { + static DataModule* + getInstance() { static DataModule instance; return &instance; } DataModule(DataModule const&) = delete; - void operator=(DataModule const&) = delete; - - const std::shared_ptr& log() const; + void + operator=(DataModule const&) = delete; - void log(const std::shared_ptr& log); + const std::shared_ptr& + log() const; + void + log(const std::shared_ptr& log); }; -#define GKFS_DATA_MOD (static_cast(gkfs::data::DataModule::getInstance())) +#define GKFS_DATA_MOD \ + (static_cast( \ + gkfs::data::DataModule::getInstance())) } // namespace data } // namespace gkfs -#endif //GEKKOFS_DAEMON_DATA_LOGGING_HPP +#endif // GEKKOFS_DAEMON_DATA_LOGGING_HPP diff --git a/include/daemon/backend/data/file_handle.hpp b/include/daemon/backend/data/file_handle.hpp index 19e26b2b8..93b53c398 100644 --- a/include/daemon/backend/data/file_handle.hpp +++ b/include/daemon/backend/data/file_handle.hpp @@ -24,37 +24,38 @@ namespace gkfs { namespace data { /** - * File handle to encapsulate a file descriptor, allowing RAII closing of the file descriptor + * File handle to encapsulate a file descriptor, allowing RAII closing of the + * file descriptor */ class FileHandle { private: - constexpr static const int init_value{-1}; int fd_{init_value}; std::string path_{}; public: - FileHandle() = default; - explicit FileHandle(int fd, std::string path) noexcept : - fd_(fd) {} + explicit FileHandle(int fd, std::string path) noexcept : fd_(fd) {} FileHandle(FileHandle&& rhs) = default; FileHandle(const FileHandle& other) = delete; - FileHandle& operator=(FileHandle&& rhs) = default; + FileHandle& + operator=(FileHandle&& rhs) = default; - FileHandle& operator=(const FileHandle& other) = delete; + FileHandle& + operator=(const FileHandle& other) = delete; explicit operator bool() const noexcept { return valid(); } - bool operator!() const noexcept { + bool + operator!() const noexcept { return !valid(); } @@ -72,11 +73,13 @@ public: * Closes file descriptor and resets it to initial value * @return */ - bool close() noexcept { - if (fd_ != init_value) { - if (::close(fd_) < 0) { - GKFS_DATA_MOD->log()->warn("{}() Failed to close file descriptor '{}' path '{}' errno '{}'", __func__, - fd_, path_, ::strerror(errno)); + bool + close() noexcept { + if(fd_ != init_value) { + if(::close(fd_) < 0) { + GKFS_DATA_MOD->log()->warn( + "{}() Failed to close file descriptor '{}' path '{}' errno '{}'", + __func__, fd_, path_, ::strerror(errno)); return false; } } @@ -85,15 +88,13 @@ public: } ~FileHandle() { - if (fd_ != init_value) + if(fd_ != init_value) close(); } - - }; } // namespace data } // namespace gkfs -#endif //GEKKOFS_DAEMON_FILE_HANDLE_HPP +#endif // GEKKOFS_DAEMON_FILE_HANDLE_HPP diff --git a/include/daemon/backend/exceptions.hpp b/include/daemon/backend/exceptions.hpp index b5cc11d53..bcf1f0c9b 100644 --- a/include/daemon/backend/exceptions.hpp +++ b/include/daemon/backend/exceptions.hpp @@ -22,15 +22,15 @@ namespace metadata { class DBException : public std::runtime_error { public: - explicit DBException(const std::string& s) : std::runtime_error(s) {}; + explicit DBException(const std::string& s) : std::runtime_error(s){}; }; class NotFoundException : public DBException { public: - explicit NotFoundException(const std::string& s) : DBException(s) {}; + explicit NotFoundException(const std::string& s) : DBException(s){}; }; } // namespace metadata } // namespace gkfs -#endif //GEKKOFS_DB_EXCEPTIONS_HPP +#endif // GEKKOFS_DB_EXCEPTIONS_HPP diff --git a/include/daemon/backend/metadata/db.hpp b/include/daemon/backend/metadata/db.hpp index 4b2e927c3..e899068d9 100644 --- a/include/daemon/backend/metadata/db.hpp +++ b/include/daemon/backend/metadata/db.hpp @@ -30,33 +30,45 @@ private: rdb::WriteOptions write_opts; std::string path; - static void optimize_rocksdb_options(rdb::Options& options); + static void + optimize_rocksdb_options(rdb::Options& options); public: - static inline void throw_rdb_status_excpt(const rdb::Status& s); + static inline void + throw_rdb_status_excpt(const rdb::Status& s); MetadataDB(const std::string& path); - std::string get(const std::string& key) const; + std::string + get(const std::string& key) const; - void put(const std::string& key, const std::string& val); + void + put(const std::string& key, const std::string& val); - void remove(const std::string& key); + void + remove(const std::string& key); - bool exists(const std::string& key); + bool + exists(const std::string& key); - void update(const std::string& old_key, const std::string& new_key, const std::string& val); + void + update(const std::string& old_key, const std::string& new_key, + const std::string& val); - void increase_size(const std::string& key, size_t size, bool append); + void + increase_size(const std::string& key, size_t size, bool append); - void decrease_size(const std::string& key, size_t size); + void + decrease_size(const std::string& key, size_t size); - std::vector> get_dirents(const std::string& dir) const; + std::vector> + get_dirents(const std::string& dir) const; - void iterate_all(); + void + iterate_all(); }; } // namespace metadata } // namespace gkfs -#endif //GEKKOFS_METADATA_DB_HPP +#endif // GEKKOFS_METADATA_DB_HPP diff --git a/include/daemon/backend/metadata/merge.hpp b/include/daemon/backend/metadata/merge.hpp index acba86a4f..17f28558b 100644 --- a/include/daemon/backend/metadata/merge.hpp +++ b/include/daemon/backend/metadata/merge.hpp @@ -33,18 +33,24 @@ class MergeOperand { public: constexpr static char operand_id_suffix = ':'; - std::string serialize() const; + std::string + serialize() const; - static OperandID get_id(const rdb::Slice& serialized_op); + static OperandID + get_id(const rdb::Slice& serialized_op); - static rdb::Slice get_params(const rdb::Slice& serialized_op); + static rdb::Slice + get_params(const rdb::Slice& serialized_op); protected: - std::string serialize_id() const; + std::string + serialize_id() const; - virtual std::string serialize_params() const = 0; + virtual std::string + serialize_params() const = 0; - virtual OperandID id() const = 0; + virtual OperandID + id() const = 0; }; class IncreaseSizeOperand : public MergeOperand { @@ -60,9 +66,11 @@ public: explicit IncreaseSizeOperand(const rdb::Slice& serialized_op); - OperandID id() const override; + OperandID + id() const override; - std::string serialize_params() const override; + std::string + serialize_params() const override; }; class DecreaseSizeOperand : public MergeOperand { @@ -73,9 +81,11 @@ public: explicit DecreaseSizeOperand(const rdb::Slice& serialized_op); - OperandID id() const override; + OperandID + id() const override; - std::string serialize_params() const override; + std::string + serialize_params() const override; }; class CreateOperand : public MergeOperand { @@ -84,25 +94,32 @@ public: explicit CreateOperand(const std::string& metadata); - OperandID id() const override; + OperandID + id() const override; - std::string serialize_params() const override; + std::string + serialize_params() const override; }; class MetadataMergeOperator : public rocksdb::MergeOperator { public: ~MetadataMergeOperator() override = default; - bool FullMergeV2(const MergeOperationInput& merge_in, - MergeOperationOutput* merge_out) const override; + bool + FullMergeV2(const MergeOperationInput& merge_in, + MergeOperationOutput* merge_out) const override; - bool PartialMergeMulti(const rdb::Slice& key, - const std::deque& operand_list, - std::string* new_value, rdb::Logger* logger) const override; + bool + PartialMergeMulti(const rdb::Slice& key, + const std::deque& operand_list, + std::string* new_value, + rdb::Logger* logger) const override; - const char* Name() const override; + const char* + Name() const override; - bool AllowSingleOperand() const override; + bool + AllowSingleOperand() const override; }; } // namespace metadata diff --git a/include/daemon/classes/fs_data.hpp b/include/daemon/classes/fs_data.hpp index 074a70b5d..ed582caa0 100644 --- a/include/daemon/classes/fs_data.hpp +++ b/include/daemon/classes/fs_data.hpp @@ -65,82 +65,114 @@ private: bool blocks_state_; public: - static FsData* getInstance() { + static FsData* + getInstance() { static FsData instance; return &instance; } FsData(FsData const&) = delete; - void operator=(FsData const&) = delete; + void + operator=(FsData const&) = delete; // getter/setter - const std::shared_ptr& spdlogger() const; + const std::shared_ptr& + spdlogger() const; - void spdlogger(const std::shared_ptr& spdlogger_); + void + spdlogger(const std::shared_ptr& spdlogger_); - const std::string& rootdir() const; + const std::string& + rootdir() const; - void rootdir(const std::string& rootdir_); + void + rootdir(const std::string& rootdir_); - const std::string& mountdir() const; + const std::string& + mountdir() const; - void mountdir(const std::string& mountdir_); + void + mountdir(const std::string& mountdir_); - const std::string& metadir() const; + const std::string& + metadir() const; - void metadir(const std::string& metadir_); + void + metadir(const std::string& metadir_); - const std::shared_ptr& mdb() const; + const std::shared_ptr& + mdb() const; - void mdb(const std::shared_ptr& mdb); + void + mdb(const std::shared_ptr& mdb); - void close_mdb(); + void + close_mdb(); - const std::shared_ptr& storage() const; + const std::shared_ptr& + storage() const; - void storage(const std::shared_ptr& storage); + void + storage(const std::shared_ptr& storage); - const std::string& rpc_protocol() const; + const std::string& + rpc_protocol() const; - void rpc_protocol(const std::string& rpc_protocol); + void + rpc_protocol(const std::string& rpc_protocol); - const std::string& bind_addr() const; + const std::string& + bind_addr() const; - void bind_addr(const std::string& addr); + void + bind_addr(const std::string& addr); - const std::string& hosts_file() const; + const std::string& + hosts_file() const; - bool use_auto_sm() const; + bool + use_auto_sm() const; - void use_auto_sm(bool use_auto_sm); + void + use_auto_sm(bool use_auto_sm); - void hosts_file(const std::string& lookup_file); + void + hosts_file(const std::string& lookup_file); - bool atime_state() const; + bool + atime_state() const; - void atime_state(bool atime_state); + void + atime_state(bool atime_state); - bool mtime_state() const; + bool + mtime_state() const; - void mtime_state(bool mtime_state); + void + mtime_state(bool mtime_state); - bool ctime_state() const; + bool + ctime_state() const; - void ctime_state(bool ctime_state); + void + ctime_state(bool ctime_state); - bool link_cnt_state() const; + bool + link_cnt_state() const; - void link_cnt_state(bool link_cnt_state); + void + link_cnt_state(bool link_cnt_state); - bool blocks_state() const; - - void blocks_state(bool blocks_state); + bool + blocks_state() const; + void + blocks_state(bool blocks_state); }; } // namespace daemon } // namespace gkfs -#endif //LFS_FS_DATA_H +#endif // LFS_FS_DATA_H diff --git a/include/daemon/classes/rpc_data.hpp b/include/daemon/classes/rpc_data.hpp index 203330e51..b8df6c71e 100644 --- a/include/daemon/classes/rpc_data.hpp +++ b/include/daemon/classes/rpc_data.hpp @@ -25,7 +25,8 @@ class RPCData { private: RPCData() {} - // Margo IDs. They can also be used to retrieve the Mercury classes and contexts that were created at init time + // Margo IDs. They can also be used to retrieve the Mercury classes and + // contexts that were created at init time margo_instance_id server_rpc_mid_; // Argobots I/O pools and execution streams @@ -34,37 +35,45 @@ private: std::string self_addr_str_; public: - - static RPCData* getInstance() { + static RPCData* + getInstance() { static RPCData instance; return &instance; } RPCData(RPCData const&) = delete; - void operator=(RPCData const&) = delete; + void + operator=(RPCData const&) = delete; // Getter/Setter - margo_instance* server_rpc_mid(); - - void server_rpc_mid(margo_instance* server_rpc_mid); + margo_instance* + server_rpc_mid(); - ABT_pool io_pool() const; + void + server_rpc_mid(margo_instance* server_rpc_mid); - void io_pool(ABT_pool io_pool); + ABT_pool + io_pool() const; - std::vector& io_streams(); + void + io_pool(ABT_pool io_pool); - void io_streams(const std::vector& io_streams); + std::vector& + io_streams(); - const std::string& self_addr_str() const; + void + io_streams(const std::vector& io_streams); - void self_addr_str(const std::string& addr_str); + const std::string& + self_addr_str() const; + void + self_addr_str(const std::string& addr_str); }; } // namespace daemon } // namespace gkfs -#endif //LFS_RPC_DATA_HPP +#endif // LFS_RPC_DATA_HPP diff --git a/include/daemon/daemon.hpp b/include/daemon/daemon.hpp index 16cf7f7bf..934f12a75 100644 --- a/include/daemon/daemon.hpp +++ b/include/daemon/daemon.hpp @@ -30,7 +30,9 @@ extern "C" { #include #include -#define GKFS_DATA (static_cast(gkfs::daemon::FsData::getInstance())) -#define RPC_DATA (static_cast(gkfs::daemon::RPCData::getInstance())) +#define GKFS_DATA \ + (static_cast(gkfs::daemon::FsData::getInstance())) +#define RPC_DATA \ + (static_cast(gkfs::daemon::RPCData::getInstance())) #endif // GKFS_DAEMON_DAEMON_HPP diff --git a/include/daemon/env.hpp b/include/daemon/env.hpp index 156184507..4c55d370e 100644 --- a/include/daemon/env.hpp +++ b/include/daemon/env.hpp @@ -30,5 +30,3 @@ static constexpr auto HOSTS_FILE = ADD_PREFIX("HOSTS_FILE"); #undef ADD_PREFIX #endif // GKFS_DAEMON_ENV - - diff --git a/include/daemon/handler/rpc_defs.hpp b/include/daemon/handler/rpc_defs.hpp index e230969eb..72cbcde42 100644 --- a/include/daemon/handler/rpc_defs.hpp +++ b/include/daemon/handler/rpc_defs.hpp @@ -55,4 +55,4 @@ DECLARE_MARGO_RPC_HANDLER(rpc_srv_truncate) DECLARE_MARGO_RPC_HANDLER(rpc_srv_get_chunk_stat) -#endif //GKFS_DAEMON_RPC_DEFS_HPP +#endif // GKFS_DAEMON_RPC_DEFS_HPP diff --git a/include/daemon/handler/rpc_util.hpp b/include/daemon/handler/rpc_util.hpp index dd29b4d87..52fb1b60c 100644 --- a/include/daemon/handler/rpc_util.hpp +++ b/include/daemon/handler/rpc_util.hpp @@ -25,64 +25,72 @@ extern "C" { namespace gkfs { namespace rpc { -template -inline hg_return_t cleanup(hg_handle_t* handle, InputType* input, OutputType* output, hg_bulk_t* bulk_handle) { +template +inline hg_return_t +cleanup(hg_handle_t* handle, InputType* input, OutputType* output, + hg_bulk_t* bulk_handle) { auto ret = HG_SUCCESS; - if (bulk_handle) { + if(bulk_handle) { ret = margo_bulk_free(*bulk_handle); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; } - if (input && handle) { + if(input && handle) { ret = margo_free_input(*handle, input); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; } - if (output && handle) { + if(output && handle) { ret = margo_free_output(*handle, output); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; } - if (handle) { + if(handle) { ret = margo_destroy(*handle); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; } return ret; } -template -inline hg_return_t respond(hg_handle_t* handle, OutputType* output) { +template +inline hg_return_t +respond(hg_handle_t* handle, OutputType* output) { auto ret = HG_SUCCESS; - if (output && handle) { + if(output && handle) { ret = margo_respond(*handle, output); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; } return ret; } -template -inline hg_return_t cleanup_respond(hg_handle_t* handle, InputType* input, OutputType* output, hg_bulk_t* bulk_handle) { +template +inline hg_return_t +cleanup_respond(hg_handle_t* handle, InputType* input, OutputType* output, + hg_bulk_t* bulk_handle) { auto ret = respond(handle, output); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; - return cleanup(handle, input, static_cast(nullptr), bulk_handle); + return cleanup(handle, input, static_cast(nullptr), + bulk_handle); } -template -inline hg_return_t cleanup_respond(hg_handle_t* handle, InputType* input, OutputType* output) { +template +inline hg_return_t +cleanup_respond(hg_handle_t* handle, InputType* input, OutputType* output) { return cleanup_respond(handle, input, output, nullptr); } -template -inline hg_return_t cleanup_respond(hg_handle_t* handle, OutputType* output) { +template +inline hg_return_t +cleanup_respond(hg_handle_t* handle, OutputType* output) { auto ret = respond(handle, output); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; - if (handle) { + if(handle) { ret = margo_destroy(*handle); - if (ret != HG_SUCCESS) + if(ret != HG_SUCCESS) return ret; } return ret; @@ -92,4 +100,4 @@ inline hg_return_t cleanup_respond(hg_handle_t* handle, OutputType* output) { } // namespace gkfs -#endif //GEKKOFS_DAEMON_RPC_UTIL_HPP +#endif // GEKKOFS_DAEMON_RPC_UTIL_HPP diff --git a/include/daemon/ops/data.hpp b/include/daemon/ops/data.hpp index f11bb154b..86831ea16 100644 --- a/include/daemon/ops/data.hpp +++ b/include/daemon/ops/data.hpp @@ -30,52 +30,55 @@ namespace data { class ChunkOpException : public std::runtime_error { public: - explicit ChunkOpException(const std::string& s) : std::runtime_error(s) {}; + explicit ChunkOpException(const std::string& s) : std::runtime_error(s){}; }; class ChunkWriteOpException : public ChunkOpException { public: - explicit ChunkWriteOpException(const std::string& s) : ChunkOpException(s) {}; + explicit ChunkWriteOpException(const std::string& s) + : ChunkOpException(s){}; }; class ChunkReadOpException : public ChunkOpException { public: - explicit ChunkReadOpException(const std::string& s) : ChunkOpException(s) {}; + explicit ChunkReadOpException(const std::string& s) : ChunkOpException(s){}; }; class ChunkMetaOpException : public ChunkOpException { public: - explicit ChunkMetaOpException(const std::string& s) : ChunkOpException(s) {}; + explicit ChunkMetaOpException(const std::string& s) : ChunkOpException(s){}; }; /** * Classes to encapsulate asynchronous chunk operations. * All operations on chunk files must go through the Argobots' task queues. * Otherwise operations may overtake operations in the queues. - * This applies to write, read, and truncate which may modify the middle of a chunk, essentially a write operation. + * This applies to write, read, and truncate which may modify the middle of a + * chunk, essentially a write operation. * * Note: This class is not thread-safe. * - * In the future, this class may be used to provide failure tolerance for IO tasks + * In the future, this class may be used to provide failure tolerance for IO + * tasks * * Base class using the CRTP idiom */ -template +template class ChunkOperation { protected: - const std::string path_; std::vector abt_tasks_; std::vector task_eventuals_; public: - - explicit ChunkOperation(const std::string& path) : ChunkOperation(path, 1) {}; + explicit ChunkOperation(const std::string& path) + : ChunkOperation(path, 1){}; ChunkOperation(std::string path, size_t n) : path_(std::move(path)) { - // Knowing n beforehand is important and cannot be dynamic. Otherwise eventuals cause seg faults + // Knowing n beforehand is important and cannot be dynamic. Otherwise + // eventuals cause seg faults abt_tasks_.resize(n); task_eventuals_.resize(n); }; @@ -87,16 +90,17 @@ public: /** * Cleans up and cancels all tasks in flight */ - void cancel_all_tasks() { + void + cancel_all_tasks() { GKFS_DATA->spdlogger()->trace("{}() enter", __func__); - for (auto& task : abt_tasks_) { - if (task) { + for(auto& task : abt_tasks_) { + if(task) { ABT_task_cancel(task); ABT_task_free(&task); } } - for (auto& eventual : task_eventuals_) { - if (eventual) { + for(auto& eventual : task_eventuals_) { + if(eventual) { ABT_eventual_reset(eventual); ABT_eventual_free(&eventual); } @@ -118,28 +122,30 @@ private: ABT_eventual eventual; }; - struct chunk_truncate_args task_arg_{}; + struct chunk_truncate_args task_arg_ {}; - static void truncate_abt(void* _arg); + static void + truncate_abt(void* _arg); - void clear_task_args(); + void + clear_task_args(); public: - explicit ChunkTruncateOperation(const std::string& path); ~ChunkTruncateOperation() = default; - void truncate(size_t size); + void + truncate(size_t size); - int wait_for_task(); + int + wait_for_task(); }; class ChunkWriteOperation : public ChunkOperation { friend class ChunkOperation; private: - struct chunk_write_args { const std::string* path; const char* buf; @@ -151,20 +157,23 @@ private: std::vector task_args_; - static void write_file_abt(void* _arg); + static void + write_file_abt(void* _arg); - void clear_task_args(); + void + clear_task_args(); public: - ChunkWriteOperation(const std::string& path, size_t n); ~ChunkWriteOperation() = default; - void write_nonblock(size_t idx, uint64_t chunk_id, const char* bulk_buf_ptr, size_t size, off64_t offset); - - std::pair wait_for_tasks(); + void + write_nonblock(size_t idx, uint64_t chunk_id, const char* bulk_buf_ptr, + size_t size, off64_t offset); + std::pair + wait_for_tasks(); }; @@ -172,7 +181,6 @@ class ChunkReadOperation : public ChunkOperation { friend class ChunkOperation; private: - struct chunk_read_args { const std::string* path; char* buf; @@ -184,12 +192,13 @@ private: std::vector task_args_; - static void read_file_abt(void* _arg); + static void + read_file_abt(void* _arg); - void clear_task_args(); + void + clear_task_args(); public: - struct bulk_args { margo_instance_id mid; hg_addr_t origin_addr; @@ -204,14 +213,15 @@ public: ~ChunkReadOperation() = default; - void read_nonblock(size_t idx, uint64_t chunk_id, char* bulk_buf_ptr, size_t size, off64_t offset); + void + read_nonblock(size_t idx, uint64_t chunk_id, char* bulk_buf_ptr, + size_t size, off64_t offset); std::pair wait_for_tasks_and_push_back(const bulk_args& args); - }; } // namespace data } // namespace gkfs -#endif //GEKKOFS_DAEMON_DATA_HPP +#endif // GEKKOFS_DAEMON_DATA_HPP diff --git a/include/daemon/ops/metadentry.hpp b/include/daemon/ops/metadentry.hpp index fd41aa712..99b2f39b5 100644 --- a/include/daemon/ops/metadentry.hpp +++ b/include/daemon/ops/metadentry.hpp @@ -21,23 +21,31 @@ namespace gkfs { namespace metadata { -Metadata get(const std::string& path); +Metadata +get(const std::string& path); -std::string get_str(const std::string& path); +std::string +get_str(const std::string& path); -size_t get_size(const std::string& path); +size_t +get_size(const std::string& path); -std::vector> get_dirents(const std::string& dir); +std::vector> +get_dirents(const std::string& dir); -void create(const std::string& path, Metadata& md); +void +create(const std::string& path, Metadata& md); -void update(const std::string& path, Metadata& md); +void +update(const std::string& path, Metadata& md); -void update_size(const std::string& path, size_t io_size, off_t offset, bool append); +void +update_size(const std::string& path, size_t io_size, off_t offset, bool append); -void remove(const std::string& path); +void +remove(const std::string& path); } // namespace metadata } // namespace gkfs -#endif //GEKKOFS_METADENTRY_HPP +#endif // GEKKOFS_METADENTRY_HPP diff --git a/include/daemon/scheduler/agios.hpp b/include/daemon/scheduler/agios.hpp index 457538f75..8263def3f 100644 --- a/include/daemon/scheduler/agios.hpp +++ b/include/daemon/scheduler/agios.hpp @@ -3,16 +3,22 @@ #include -void agios_initialize(); +void +agios_initialize(); -void agios_shutdown(); +void +agios_shutdown(); -void* agios_callback(int64_t request_id); +void* +agios_callback(int64_t request_id); -void* agios_callback_aggregated(int64_t* requests, int32_t total); +void* +agios_callback_aggregated(int64_t* requests, int32_t total); -void* agios_eventual_callback(int64_t request_id, void* info); +void* +agios_eventual_callback(int64_t request_id, void* info); -unsigned long long int generate_unique_id(); +unsigned long long int +generate_unique_id(); #endif \ No newline at end of file diff --git a/include/daemon/util.hpp b/include/daemon/util.hpp index ceb5f70d5..c8845847a 100644 --- a/include/daemon/util.hpp +++ b/include/daemon/util.hpp @@ -16,10 +16,12 @@ namespace gkfs { namespace util { -void populate_hosts_file(); +void +populate_hosts_file(); -void destroy_hosts_file(); -} -} +void +destroy_hosts_file(); +} // namespace util +} // namespace gkfs -#endif //GEKKOFS_DAEMON_UTIL_HPP +#endif // GEKKOFS_DAEMON_UTIL_HPP diff --git a/include/global/chunk_calc_util.hpp b/include/global/chunk_calc_util.hpp index 20696fb81..4e0ccb8db 100644 --- a/include/global/chunk_calc_util.hpp +++ b/include/global/chunk_calc_util.hpp @@ -22,14 +22,17 @@ namespace util { /** * Compute the base2 logarithm for 64 bit integers */ -inline int log2(uint64_t n) { +inline int +log2(uint64_t n) { - /* see http://stackoverflow.com/questions/11376288/fast-computing-of-log2-for-64-bit-integers */ + /* see + * http://stackoverflow.com/questions/11376288/fast-computing-of-log2-for-64-bit-integers + */ static const int table[64] = { - 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3, 61, - 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4, 62, + 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3, 61, + 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4, 62, 57, 46, 52, 38, 26, 32, 41, 50, 36, 17, 19, 29, 10, 13, 21, 56, - 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5, 63}; + 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5, 63}; n |= n >> 1; n |= n >> 2; @@ -45,7 +48,8 @@ inline int log2(uint64_t n) { /** * Align an @offset to the closest left side chunk boundary */ -inline off64_t chnk_lalign(const off64_t offset, const size_t chnk_size) { +inline off64_t +chnk_lalign(const off64_t offset, const size_t chnk_size) { return offset & ~(chnk_size - 1); } @@ -53,7 +57,8 @@ inline off64_t chnk_lalign(const off64_t offset, const size_t chnk_size) { /** * Align an @offset to the closest right side chunk boundary */ -inline off64_t chnk_ralign(const off64_t offset, const size_t chnk_size) { +inline off64_t +chnk_ralign(const off64_t offset, const size_t chnk_size) { return chnk_lalign(offset + chnk_size, chnk_size); } @@ -64,7 +69,8 @@ inline off64_t chnk_ralign(const off64_t offset, const size_t chnk_size) { * * If @offset is a boundary the resulting padding will be 0 */ -inline size_t chnk_lpad(const off64_t offset, const size_t chnk_size) { +inline size_t +chnk_lpad(const off64_t offset, const size_t chnk_size) { return offset % chnk_size; } @@ -75,7 +81,8 @@ inline size_t chnk_lpad(const off64_t offset, const size_t chnk_size) { * * If @offset is a boundary the resulting padding will be 0 */ -inline size_t chnk_rpad(const off64_t offset, const size_t chnk_size) { +inline size_t +chnk_rpad(const off64_t offset, const size_t chnk_size) { return (-offset) % chnk_size; } @@ -88,13 +95,16 @@ inline size_t chnk_rpad(const off64_t offset, const size_t chnk_size) { * chunk_id(2,4) = 0; * chunk_id(0,4) = 0; */ -inline uint64_t chnk_id_for_offset(const off64_t offset, const size_t chnk_size) { +inline uint64_t +chnk_id_for_offset(const off64_t offset, const size_t chnk_size) { /* - * This does not work for offsets that use the 64th bit, i.e., 9223372036854775808. - * 9223372036854775808 - 1 uses 63 bits and still works. `offset / chnk_size` works with the 64th bit. - * With this number we can address more than 19,300,000 exabytes of data though. Hi future me? + * This does not work for offsets that use the 64th bit, i.e., + * 9223372036854775808. 9223372036854775808 - 1 uses 63 bits and still + * works. `offset / chnk_size` works with the 64th bit. With this number we + * can address more than 19,300,000 exabytes of data though. Hi future me? */ - return static_cast(chnk_lalign(offset, chnk_size) >> log2(chnk_size)); + return static_cast(chnk_lalign(offset, chnk_size) >> + log2(chnk_size)); } @@ -102,7 +112,9 @@ inline uint64_t chnk_id_for_offset(const off64_t offset, const size_t chnk_size) * Return the number of chunks involved in an operation that operates * from @offset for a certain amount of bytes (@count). */ -inline uint64_t chnk_count_for_offset(const off64_t offset, const size_t count, const size_t chnk_size) { +inline uint64_t +chnk_count_for_offset(const off64_t offset, const size_t count, + const size_t chnk_size) { off64_t chnk_start = chnk_lalign(offset, chnk_size); off64_t chnk_end = chnk_lalign(offset + count - 1, chnk_size); diff --git a/include/global/env_util.hpp b/include/global/env_util.hpp index 098d8a427..996a1bfcb 100644 --- a/include/global/env_util.hpp +++ b/include/global/env_util.hpp @@ -19,7 +19,8 @@ namespace gkfs { namespace env { -std::string get_var(const std::string& name, const std::string& default_value = ""); +std::string +get_var(const std::string& name, const std::string& default_value = ""); } // namespace env } // namespace gkfs diff --git a/include/global/global_defs.hpp b/include/global/global_defs.hpp index c2dcf5442..9635120c1 100644 --- a/include/global/global_defs.hpp +++ b/include/global/global_defs.hpp @@ -16,7 +16,8 @@ namespace gkfs { -// These constexpr set the RPC's identity and which handler the receiver end should use +// These constexpr set the RPC's identity and which handler the receiver end +// should use namespace rpc { using chnk_id_t = unsigned long; @@ -52,4 +53,4 @@ constexpr auto na_sm = "na+sm"; } // namespace gkfs -#endif //GEKKOFS_GLOBAL_DEFS_HPP +#endif // GEKKOFS_GLOBAL_DEFS_HPP diff --git a/include/global/log_util.hpp b/include/global/log_util.hpp index ea70b34ca..bf6bd727d 100644 --- a/include/global/log_util.hpp +++ b/include/global/log_util.hpp @@ -19,12 +19,16 @@ namespace gkfs { namespace log { -spdlog::level::level_enum get_level(std::string level_str); +spdlog::level::level_enum +get_level(std::string level_str); -spdlog::level::level_enum get_level(unsigned long level); +spdlog::level::level_enum +get_level(unsigned long level); -void setup(const std::vector& loggers, spdlog::level::level_enum level, const std::string& path); -} -} +void +setup(const std::vector& loggers, spdlog::level::level_enum level, + const std::string& path); +} // namespace log +} // namespace gkfs #endif diff --git a/include/global/metadata.hpp b/include/global/metadata.hpp index 71901438b..5a6b3d328 100644 --- a/include/global/metadata.hpp +++ b/include/global/metadata.hpp @@ -28,15 +28,17 @@ constexpr mode_t LINK_MODE = ((S_IRWXU | S_IRWXG | S_IRWXO) | S_IFLNK); class Metadata { private: - time_t atime_; // access time. gets updated on file access unless mounted with noatime - time_t mtime_; // modify time. gets updated when file content is modified. - time_t ctime_; // change time. gets updated when the file attributes are changed AND when file content is modified. + time_t atime_; // access time. gets updated on file access unless mounted + // with noatime + time_t mtime_; // modify time. gets updated when file content is modified. + time_t ctime_; // change time. gets updated when the file attributes are + // changed AND when file content is modified. mode_t mode_; - nlink_t link_count_; // number of names for this inode (hardlinks) - size_t size_; // size_ in bytes, might be computed instead of stored - blkcnt_t blocks_; // allocated file system blocks_ + nlink_t link_count_; // number of names for this inode (hardlinks) + size_t size_; // size_ in bytes, might be computed instead of stored + blkcnt_t blocks_; // allocated file system blocks_ #ifdef HAS_SYMLINKS - std::string target_path_; // For links this is the path of the target file + std::string target_path_; // For links this is the path of the target file #endif @@ -54,48 +56,68 @@ public: // Construct from a binary representation of the object explicit Metadata(const std::string& binary_str); - std::string serialize() const; + std::string + serialize() const; - void init_ACM_time(); + void + init_ACM_time(); - void update_ACM_time(bool a, bool c, bool m); + void + update_ACM_time(bool a, bool c, bool m); - //Getter and Setter - time_t atime() const; + // Getter and Setter + time_t + atime() const; - void atime(time_t atime_); + void + atime(time_t atime_); - time_t mtime() const; + time_t + mtime() const; - void mtime(time_t mtime_); + void + mtime(time_t mtime_); - time_t ctime() const; + time_t + ctime() const; - void ctime(time_t ctime_); + void + ctime(time_t ctime_); - mode_t mode() const; + mode_t + mode() const; - void mode(mode_t mode_); + void + mode(mode_t mode_); - nlink_t link_count() const; + nlink_t + link_count() const; - void link_count(nlink_t link_count_); + void + link_count(nlink_t link_count_); - size_t size() const; + size_t + size() const; - void size(size_t size_); + void + size(size_t size_); - blkcnt_t blocks() const; + blkcnt_t + blocks() const; - void blocks(blkcnt_t blocks_); + void + blocks(blkcnt_t blocks_); #ifdef HAS_SYMLINKS - std::string target_path() const; + std::string + target_path() const; - void target_path(const std::string& target_path); + void + target_path(const std::string& target_path); - bool is_link() const; + bool + is_link() const; #endif }; @@ -104,4 +126,4 @@ public: } // namespace gkfs -#endif //FS_METADATA_H +#endif // FS_METADATA_H diff --git a/include/global/path_util.hpp b/include/global/path_util.hpp index 61a4387c7..02e9fe29c 100644 --- a/include/global/path_util.hpp +++ b/include/global/path_util.hpp @@ -24,21 +24,29 @@ constexpr unsigned int max_length = 4096; // 4k chars constexpr char separator = '/'; // PATH SEPARATOR -bool is_relative(const std::string& path); +bool +is_relative(const std::string& path); -bool is_absolute(const std::string& path); +bool +is_absolute(const std::string& path); -bool has_trailing_slash(const std::string& path); +bool +has_trailing_slash(const std::string& path); -std::string prepend_path(const std::string& path, const char* raw_path); +std::string +prepend_path(const std::string& path, const char* raw_path); -std::string absolute_to_relative(const std::string& root_path, const std::string& absolute_path); // unused ATM +std::string +absolute_to_relative(const std::string& root_path, + const std::string& absolute_path); // unused ATM -std::string dirname(const std::string& path); +std::string +dirname(const std::string& path); -std::vector split_path(const std::string& path); +std::vector +split_path(const std::string& path); -} // namespace gkfs } // namespace path +} // namespace gkfs -#endif //GEKKOFS_PATH_UTIL_HPP +#endif // GEKKOFS_PATH_UTIL_HPP diff --git a/include/global/rpc/distributor.hpp b/include/global/rpc/distributor.hpp index d01a79412..8f8d91593 100644 --- a/include/global/rpc/distributor.hpp +++ b/include/global/rpc/distributor.hpp @@ -26,13 +26,17 @@ using host_t = unsigned int; class Distributor { public: - virtual host_t localhost() const = 0; + virtual host_t + localhost() const = 0; - virtual host_t locate_data(const std::string& path, const chunkid_t& chnk_id) const = 0; + virtual host_t + locate_data(const std::string& path, const chunkid_t& chnk_id) const = 0; - virtual host_t locate_file_metadata(const std::string& path) const = 0; + virtual host_t + locate_file_metadata(const std::string& path) const = 0; - virtual std::vector locate_directory_metadata(const std::string& path) const = 0; + virtual std::vector + locate_directory_metadata(const std::string& path) const = 0; }; @@ -42,31 +46,43 @@ private: unsigned int hosts_size_; std::vector all_hosts_; std::hash str_hash; + public: SimpleHashDistributor(host_t localhost, unsigned int hosts_size); - host_t localhost() const override; + host_t + localhost() const override; - host_t locate_data(const std::string& path, const chunkid_t& chnk_id) const override; + host_t + locate_data(const std::string& path, + const chunkid_t& chnk_id) const override; - host_t locate_file_metadata(const std::string& path) const override; + host_t + locate_file_metadata(const std::string& path) const override; - std::vector locate_directory_metadata(const std::string& path) const override; + std::vector + locate_directory_metadata(const std::string& path) const override; }; class LocalOnlyDistributor : public Distributor { private: host_t localhost_; + public: explicit LocalOnlyDistributor(host_t localhost); - host_t localhost() const override; + host_t + localhost() const override; - host_t locate_data(const std::string& path, const chunkid_t& chnk_id) const override; + host_t + locate_data(const std::string& path, + const chunkid_t& chnk_id) const override; - host_t locate_file_metadata(const std::string& path) const override; + host_t + locate_file_metadata(const std::string& path) const override; - std::vector locate_directory_metadata(const std::string& path) const override; + std::vector + locate_directory_metadata(const std::string& path) const override; }; class ForwarderDistributor : public Distributor { @@ -75,19 +91,25 @@ private: unsigned int hosts_size_; std::vector all_hosts_; std::hash str_hash; + public: ForwarderDistributor(host_t fwhost, unsigned int hosts_size); - host_t localhost() const override final; + host_t + localhost() const override final; - host_t locate_data(const std::string& path, const chunkid_t& chnk_id) const override final; + host_t + locate_data(const std::string& path, + const chunkid_t& chnk_id) const override final; - host_t locate_file_metadata(const std::string& path) const override; + host_t + locate_file_metadata(const std::string& path) const override; - std::vector locate_directory_metadata(const std::string& path) const override; + std::vector + locate_directory_metadata(const std::string& path) const override; }; } // namespace rpc } // namespace gkfs -#endif //GEKKOFS_RPC_LOCATOR_HPP +#endif // GEKKOFS_RPC_LOCATOR_HPP diff --git a/include/global/rpc/rpc_types.hpp b/include/global/rpc/rpc_types.hpp index 65b086ad2..3cdc72bde 100644 --- a/include/global/rpc/rpc_types.hpp +++ b/include/global/rpc/rpc_types.hpp @@ -23,129 +23,84 @@ extern "C" { /* visible API for RPC data types used in RPCS */ // misc generic rpc types -MERCURY_GEN_PROC(rpc_err_out_t, - ((hg_int32_t) (err))) +MERCURY_GEN_PROC(rpc_err_out_t, ((hg_int32_t)(err))) // Metadentry MERCURY_GEN_PROC(rpc_mk_node_in_t, - ((hg_const_string_t) (path)) - ((uint32_t) (mode))) + ((hg_const_string_t)(path))((uint32_t)(mode))) -MERCURY_GEN_PROC(rpc_path_only_in_t, - ((hg_const_string_t) (path))) +MERCURY_GEN_PROC(rpc_path_only_in_t, ((hg_const_string_t)(path))) MERCURY_GEN_PROC(rpc_stat_out_t, - ((hg_int32_t) (err)) - ((hg_const_string_t) (db_val))) + ((hg_int32_t)(err))((hg_const_string_t)(db_val))) -MERCURY_GEN_PROC(rpc_rm_node_in_t, - ((hg_const_string_t) (path))) +MERCURY_GEN_PROC(rpc_rm_node_in_t, ((hg_const_string_t)(path))) MERCURY_GEN_PROC(rpc_trunc_in_t, - ((hg_const_string_t) (path)) - ((hg_uint64_t) (length))) - -MERCURY_GEN_PROC(rpc_update_metadentry_in_t, - ((hg_const_string_t) (path)) - ((uint64_t) (nlink)) - ((hg_uint32_t) (mode)) - ((hg_uint32_t) (uid)) - ((hg_uint32_t) (gid)) - ((hg_int64_t) (size)) - ((hg_int64_t) (blocks)) - ((hg_int64_t) (atime)) - ((hg_int64_t) (mtime)) - ((hg_int64_t) (ctime)) - ((hg_bool_t) (nlink_flag)) - ((hg_bool_t) (mode_flag)) - ((hg_bool_t) (size_flag)) - ((hg_bool_t) (block_flag)) - ((hg_bool_t) (atime_flag)) - ((hg_bool_t) (mtime_flag)) - ((hg_bool_t) (ctime_flag))) + ((hg_const_string_t)(path))((hg_uint64_t)(length))) + +MERCURY_GEN_PROC( + rpc_update_metadentry_in_t, + ((hg_const_string_t)(path))((uint64_t)(nlink))((hg_uint32_t)(mode))( + (hg_uint32_t)(uid))((hg_uint32_t)(gid))((hg_int64_t)(size))( + (hg_int64_t)(blocks))((hg_int64_t)(atime))((hg_int64_t)(mtime))( + (hg_int64_t)(ctime))((hg_bool_t)(nlink_flag))( + (hg_bool_t)(mode_flag))((hg_bool_t)(size_flag))( + (hg_bool_t)(block_flag))((hg_bool_t)(atime_flag))( + (hg_bool_t)(mtime_flag))((hg_bool_t)(ctime_flag))) MERCURY_GEN_PROC(rpc_update_metadentry_size_in_t, - ((hg_const_string_t) (path)) - ((hg_uint64_t) (size)) - ((hg_int64_t) (offset)) - ((hg_bool_t) (append))) + ((hg_const_string_t)(path))((hg_uint64_t)(size))( + (hg_int64_t)(offset))((hg_bool_t)(append))) MERCURY_GEN_PROC(rpc_update_metadentry_size_out_t, - ((hg_int32_t) (err)) - ((hg_int64_t) (ret_size))) + ((hg_int32_t)(err))((hg_int64_t)(ret_size))) MERCURY_GEN_PROC(rpc_get_metadentry_size_out_t, - ((hg_int32_t) (err)) - ((hg_int64_t) (ret_size))) + ((hg_int32_t)(err))((hg_int64_t)(ret_size))) #ifdef HAS_SYMLINKS MERCURY_GEN_PROC(rpc_mk_symlink_in_t, - ((hg_const_string_t) (path)) - ((hg_const_string_t) (target_path)) -) + ((hg_const_string_t)(path))((hg_const_string_t)(target_path))) #endif // data -MERCURY_GEN_PROC(rpc_read_data_in_t, - ((hg_const_string_t) (path)) - ((int64_t) (offset)) - ((hg_uint64_t) (host_id)) - ((hg_uint64_t) (host_size)) - ((hg_uint64_t) (chunk_n)) - ((hg_uint64_t) (chunk_start)) - ((hg_uint64_t) (chunk_end)) - ((hg_uint64_t) (total_chunk_size)) - ((hg_bulk_t) (bulk_handle))) - -MERCURY_GEN_PROC(rpc_data_out_t, - ((int32_t) (err)) - ((hg_size_t) (io_size))) - -MERCURY_GEN_PROC(rpc_write_data_in_t, - ((hg_const_string_t) (path)) - ((int64_t) (offset)) - ((hg_uint64_t) (host_id)) - ((hg_uint64_t) (host_size)) - ((hg_uint64_t) (chunk_n)) - ((hg_uint64_t) (chunk_start)) - ((hg_uint64_t) (chunk_end)) - ((hg_uint64_t) (total_chunk_size)) - ((hg_bulk_t) (bulk_handle))) +MERCURY_GEN_PROC( + rpc_read_data_in_t, + ((hg_const_string_t)(path))((int64_t)(offset))((hg_uint64_t)(host_id))( + (hg_uint64_t)(host_size))((hg_uint64_t)(chunk_n))( + (hg_uint64_t)(chunk_start))((hg_uint64_t)(chunk_end))( + (hg_uint64_t)(total_chunk_size))((hg_bulk_t)(bulk_handle))) + +MERCURY_GEN_PROC(rpc_data_out_t, ((int32_t)(err))((hg_size_t)(io_size))) + +MERCURY_GEN_PROC( + rpc_write_data_in_t, + ((hg_const_string_t)(path))((int64_t)(offset))((hg_uint64_t)(host_id))( + (hg_uint64_t)(host_size))((hg_uint64_t)(chunk_n))( + (hg_uint64_t)(chunk_start))((hg_uint64_t)(chunk_end))( + (hg_uint64_t)(total_chunk_size))((hg_bulk_t)(bulk_handle))) MERCURY_GEN_PROC(rpc_get_dirents_in_t, - ((hg_const_string_t) (path)) - ((hg_bulk_t) (bulk_handle)) -) + ((hg_const_string_t)(path))((hg_bulk_t)(bulk_handle))) MERCURY_GEN_PROC(rpc_get_dirents_out_t, - ((hg_int32_t) (err)) - ((hg_size_t) (dirents_size)) -) + ((hg_int32_t)(err))((hg_size_t)(dirents_size))) MERCURY_GEN_PROC(rpc_config_out_t, - ((hg_const_string_t) (mountdir)) - ((hg_const_string_t) (rootdir)) - ((hg_bool_t) (atime_state)) - ((hg_bool_t) (mtime_state)) - ((hg_bool_t) (ctime_state)) - ((hg_bool_t) (link_cnt_state)) - ((hg_bool_t) (blocks_state)) - ((hg_uint32_t) (uid)) - ((hg_uint32_t) (gid)) -) - - -MERCURY_GEN_PROC(rpc_chunk_stat_in_t, - ((hg_int32_t) (dummy)) -) + ((hg_const_string_t)(mountdir))((hg_const_string_t)(rootdir))( + (hg_bool_t)(atime_state))((hg_bool_t)(mtime_state))( + (hg_bool_t)(ctime_state))((hg_bool_t)(link_cnt_state))( + (hg_bool_t)(blocks_state))((hg_uint32_t)(uid))( + (hg_uint32_t)(gid))) + + +MERCURY_GEN_PROC(rpc_chunk_stat_in_t, ((hg_int32_t)(dummy))) MERCURY_GEN_PROC(rpc_chunk_stat_out_t, - ((hg_int32_t) (err)) - ((hg_uint64_t) (chunk_size)) - ((hg_uint64_t) (chunk_total)) - ((hg_uint64_t) (chunk_free)) -) + ((hg_int32_t)(err))((hg_uint64_t)(chunk_size))( + (hg_uint64_t)(chunk_total))((hg_uint64_t)(chunk_free))) -#endif //LFS_RPC_TYPES_HPP +#endif // LFS_RPC_TYPES_HPP diff --git a/include/global/rpc/rpc_util.hpp b/include/global/rpc/rpc_util.hpp index cdac93a2b..139a1418f 100644 --- a/include/global/rpc/rpc_util.hpp +++ b/include/global/rpc/rpc_util.hpp @@ -25,13 +25,16 @@ extern "C" { namespace gkfs { namespace rpc { -hg_bool_t bool_to_merc_bool(bool state); +hg_bool_t +bool_to_merc_bool(bool state); -std::string get_my_hostname(bool short_hostname = false); +std::string +get_my_hostname(bool short_hostname = false); -std::string get_host_by_name(const std::string& hostname); +std::string +get_host_by_name(const std::string& hostname); } // namespace rpc } // namespace gkfs -#endif //GEKKOFS_GLOBAL_RPC_UTILS_HPP +#endif // GEKKOFS_GLOBAL_RPC_UTILS_HPP diff --git a/src/client/gkfs_functions.cpp b/src/client/gkfs_functions.cpp index bcda83769..2684df4b7 100644 --- a/src/client/gkfs_functions.cpp +++ b/src/client/gkfs_functions.cpp @@ -36,10 +36,11 @@ using namespace std; * Macro used within getdents{,64} functions. * __ALIGN_KERNEL defined in linux/kernel.h */ -#define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) +#define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) /* - * linux_dirent is used in getdents() but is privately defined in the linux kernel: fs/readdir.c. + * linux_dirent is used in getdents() but is privately defined in the linux + * kernel: fs/readdir.c. */ struct linux_dirent { unsigned long d_ino; @@ -48,38 +49,42 @@ struct linux_dirent { char d_name[1]; }; /* - * linux_dirent64 is used in getdents64() and defined in the linux kernel: include/linux/dirent.h. - * However, it is not part of the kernel-headers and cannot be imported. + * linux_dirent64 is used in getdents64() and defined in the linux kernel: + * include/linux/dirent.h. However, it is not part of the kernel-headers and + * cannot be imported. */ struct linux_dirent64 { uint64_t d_ino; int64_t d_off; unsigned short d_reclen; unsigned char d_type; - char d_name[1]; // originally `char d_name[0]` in kernel, but ISO C++ forbids zero-size array 'd_name' + char d_name[1]; // originally `char d_name[0]` in kernel, but ISO C++ + // forbids zero-size array 'd_name' }; namespace { /** - * Checks if metadata for parent directory exists (can be disabled with CREATE_CHECK_PARENTS). - * errno may be set + * Checks if metadata for parent directory exists (can be disabled with + * CREATE_CHECK_PARENTS). errno may be set * @param path * @return 0 on success, -1 on failure */ -int check_parent_dir(const std::string& path) { +int +check_parent_dir(const std::string& path) { #if CREATE_CHECK_PARENTS auto p_comp = gkfs::path::dirname(path); auto md = gkfs::util::get_metadata(p_comp); - if (!md) { - if (errno == ENOENT) { + if(!md) { + if(errno == ENOENT) { LOG(DEBUG, "Parent component does not exist: '{}'", p_comp); } else { - LOG(ERROR, "Failed to get metadata for parent component '{}': {}", path, strerror(errno)); + LOG(ERROR, "Failed to get metadata for parent component '{}': {}", + path, strerror(errno)); } return -1; } - if (!S_ISDIR(md->mode())) { + if(!S_ISDIR(md->mode())) { LOG(DEBUG, "Parent component is not a directory: '{}'", p_comp); errno = ENOTDIR; return -1; @@ -100,15 +105,16 @@ namespace syscall { * @param flags * @return 0 on success, -1 on failure */ -int gkfs_open(const std::string& path, mode_t mode, int flags) { +int +gkfs_open(const std::string& path, mode_t mode, int flags) { - if (flags & O_PATH) { + if(flags & O_PATH) { LOG(ERROR, "`O_PATH` flag is not supported"); errno = ENOTSUP; return -1; } - if (flags & O_APPEND) { + if(flags & O_APPEND) { LOG(ERROR, "`O_APPEND` flag is not supported"); errno = ENOTSUP; return -1; @@ -116,8 +122,8 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { bool exists = true; auto md = gkfs::util::get_metadata(path); - if (!md) { - if (errno == ENOENT) { + if(!md) { + if(errno == ENOENT) { exists = false; } else { LOG(ERROR, "Error while retriving stat to file"); @@ -125,8 +131,8 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { } } - if (!exists) { - if (!(flags & O_CREAT)) { + if(!exists) { + if(!(flags & O_CREAT)) { // file doesn't exists and O_CREAT was not set errno = ENOENT; return -1; @@ -135,29 +141,31 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { /*** CREATION ***/ assert(flags & O_CREAT); - if (flags & O_DIRECTORY) { + if(flags & O_DIRECTORY) { LOG(ERROR, "O_DIRECTORY use with O_CREAT. NOT SUPPORTED"); errno = ENOTSUP; return -1; } - // no access check required here. If one is using our FS they have the permissions. - if (gkfs_create(path, mode | S_IFREG)) { - LOG(ERROR, "Error creating non-existent file: '{}'", strerror(errno)); + // no access check required here. If one is using our FS they have the + // permissions. + if(gkfs_create(path, mode | S_IFREG)) { + LOG(ERROR, "Error creating non-existent file: '{}'", + strerror(errno)); return -1; } } else { /* File already exists */ - if (flags & O_EXCL) { + if(flags & O_EXCL) { // File exists and O_EXCL was set errno = EEXIST; return -1; } #ifdef HAS_SYMLINKS - if (md->is_link()) { - if (flags & O_NOFOLLOW) { + if(md->is_link()) { + if(flags & O_NOFOLLOW) { LOG(WARNING, "Symlink found and O_NOFOLLOW flag was specified"); errno = ELOOP; return -1; @@ -166,7 +174,7 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { } #endif - if (S_ISDIR(md->mode())) { + if(S_ISDIR(md->mode())) { return gkfs_opendir(path); } @@ -174,15 +182,16 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { /*** Regular file exists ***/ assert(S_ISREG(md->mode())); - if ((flags & O_TRUNC) && ((flags & O_RDWR) || (flags & O_WRONLY))) { - if (gkfs_truncate(path, md->size(), 0)) { + if((flags & O_TRUNC) && ((flags & O_RDWR) || (flags & O_WRONLY))) { + if(gkfs_truncate(path, md->size(), 0)) { LOG(ERROR, "Error truncating file"); return -1; } } } - return CTX->file_map()->add(std::make_shared(path, flags)); + return CTX->file_map()->add( + std::make_shared(path, flags)); } /** @@ -192,10 +201,11 @@ int gkfs_open(const std::string& path, mode_t mode, int flags) { * @param mode * @return 0 on success, -1 on failure */ -int gkfs_create(const std::string& path, mode_t mode) { +int +gkfs_create(const std::string& path, mode_t mode) { - //file type must be set - switch (mode & S_IFMT) { + // file type must be set + switch(mode & S_IFMT) { case 0: mode |= S_IFREG; break; @@ -215,11 +225,11 @@ int gkfs_create(const std::string& path, mode_t mode) { return -1; } - if (check_parent_dir(path)) { + if(check_parent_dir(path)) { return -1; } auto err = gkfs::rpc::forward_create(path, mode); - if (err) { + if(err) { errno = err; return -1; } @@ -232,14 +242,15 @@ int gkfs_create(const std::string& path, mode_t mode) { * @param path * @return 0 on success, -1 on failure */ -int gkfs_remove(const std::string& path) { +int +gkfs_remove(const std::string& path) { auto md = gkfs::util::get_metadata(path); - if (!md) { + if(!md) { return -1; } bool has_data = S_ISREG(md->mode()) && (md->size() != 0); auto err = gkfs::rpc::forward_remove(path, !has_data, md->size()); - if (err) { + if(err) { errno = err; return -1; } @@ -254,9 +265,10 @@ int gkfs_remove(const std::string& path) { * @param follow_links * @return 0 on success, -1 on failure */ -int gkfs_access(const std::string& path, const int mask, bool follow_links) { +int +gkfs_access(const std::string& path, const int mask, bool follow_links) { auto md = gkfs::util::get_metadata(path, follow_links); - if (!md) { + if(!md) { errno = ENOENT; return -1; } @@ -271,9 +283,10 @@ int gkfs_access(const std::string& path, const int mask, bool follow_links) { * @param follow_links * @return 0 on success, -1 on failure */ -int gkfs_stat(const string& path, struct stat* buf, bool follow_links) { +int +gkfs_stat(const string& path, struct stat* buf, bool follow_links) { auto md = gkfs::util::get_metadata(path, follow_links); - if (!md) { + if(!md) { return -1; } gkfs::util::metadata_to_stat(path, *md, *buf); @@ -293,13 +306,15 @@ int gkfs_stat(const string& path, struct stat* buf, bool follow_links) { * @param follow_links * @return 0 on success, -1 on failure */ -int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, struct statx* buf, bool follow_links) { +int +gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, + struct statx* buf, bool follow_links) { auto md = gkfs::util::get_metadata(path, follow_links); - if (!md) { + if(!md) { return -1; } - struct stat tmp{}; + struct stat tmp {}; gkfs::util::metadata_to_stat(path, *md, tmp); @@ -337,11 +352,12 @@ int gkfs_statx(int dirfs, const std::string& path, int flags, unsigned int mask, * @param buf * @return 0 on success, -1 on failure */ -int gkfs_statfs(struct statfs* buf) { +int +gkfs_statfs(struct statfs* buf) { auto ret = gkfs::rpc::forward_get_chunk_stat(); auto err = ret.first; - if (err) { + if(err) { LOG(ERROR, "{}() Failure with error: '{}'", err); errno = err; return -1; @@ -371,10 +387,11 @@ int gkfs_statfs(struct statfs* buf) { * @param buf * @return 0 on success, -1 on failure */ -int gkfs_statvfs(struct statvfs* buf) { +int +gkfs_statvfs(struct statvfs* buf) { auto ret = gkfs::rpc::forward_get_chunk_stat(); auto err = ret.first; - if (err) { + if(err) { LOG(ERROR, "{}() Failure with error: '{}'", err); errno = err; return -1; @@ -403,22 +420,25 @@ int gkfs_statvfs(struct statvfs* buf) { * @param whence * @return 0 on success, -1 on failure */ -off_t gkfs_lseek(unsigned int fd, off_t offset, unsigned int whence) { +off_t +gkfs_lseek(unsigned int fd, off_t offset, unsigned int whence) { return gkfs_lseek(CTX->file_map()->get(fd), offset, whence); } /** - * gkfs wrapper for lseek() system calls with available shared ptr to gkfs FileMap - * errno may be set + * gkfs wrapper for lseek() system calls with available shared ptr to gkfs + * FileMap errno may be set * @param gkfs_fd * @param offset * @param whence * @return 0 on success, -1 on failure */ -off_t gkfs_lseek(shared_ptr gkfs_fd, off_t offset, unsigned int whence) { - switch (whence) { +off_t +gkfs_lseek(shared_ptr gkfs_fd, off_t offset, + unsigned int whence) { + switch(whence) { case SEEK_SET: - if (offset < 0) { + if(offset < 0) { errno = EINVAL; return -1; } @@ -430,13 +450,13 @@ off_t gkfs_lseek(shared_ptr gkfs_fd, off_t offset, unsi case SEEK_END: { auto ret = gkfs::rpc::forward_get_metadentry_size(gkfs_fd->path()); auto err = ret.first; - if (err) { + if(err) { errno = err; return -1; } auto file_size = ret.second; - if (offset < 0 && file_size < -offset) { + if(offset < 0 && file_size < -offset) { errno = EINVAL; return -1; } @@ -469,22 +489,23 @@ off_t gkfs_lseek(shared_ptr gkfs_fd, off_t offset, unsi * @param new_size * @return 0 on success, -1 on failure */ -int gkfs_truncate(const std::string& path, off_t old_size, off_t new_size) { +int +gkfs_truncate(const std::string& path, off_t old_size, off_t new_size) { assert(new_size >= 0); assert(new_size <= old_size); - if (new_size == old_size) { + if(new_size == old_size) { return 0; } auto err = gkfs::rpc::forward_decr_size(path, new_size); - if (err) { + if(err) { LOG(DEBUG, "Failed to decrease size"); errno = err; return -1; } err = gkfs::rpc::forward_truncate(path, old_size, new_size); - if (err) { + if(err) { LOG(DEBUG, "Failed to truncate data"); errno = err; return -1; @@ -499,7 +520,8 @@ int gkfs_truncate(const std::string& path, off_t old_size, off_t new_size) { * @param length * @return 0 on success, -1 on failure */ -int gkfs_truncate(const std::string& path, off_t length) { +int +gkfs_truncate(const std::string& path, off_t length) { /* TODO CONCURRENCY: * At the moment we first ask the length to the metadata-server in order to * know which data-server have data to be deleted. @@ -508,18 +530,18 @@ int gkfs_truncate(const std::string& path, off_t length) { * gkfs_trunc_data, some more data could have been added to the file and the * length increased. */ - if (length < 0) { + if(length < 0) { LOG(DEBUG, "Length is negative: {}", length); errno = EINVAL; return -1; } auto md = gkfs::util::get_metadata(path, true); - if (!md) { + if(!md) { return -1; } auto size = md->size(); - if (static_cast(length) > size) { + if(static_cast(length) > size) { LOG(DEBUG, "Length is greater then file size: {} > {}", length, size); errno = EINVAL; return -1; @@ -533,7 +555,8 @@ int gkfs_truncate(const std::string& path, off_t length) { * @param oldfd * @return file descriptor int or -1 on error */ -int gkfs_dup(const int oldfd) { +int +gkfs_dup(const int oldfd) { return CTX->file_map()->dup(oldfd); } @@ -544,7 +567,8 @@ int gkfs_dup(const int oldfd) { * @param newfd * @return file descriptor int or -1 on error */ -int gkfs_dup2(const int oldfd, const int newfd) { +int +gkfs_dup2(const int oldfd, const int newfd) { return CTX->file_map()->dup2(oldfd, newfd); } @@ -557,8 +581,10 @@ int gkfs_dup2(const int oldfd, const int newfd) { * @param offset * @return written size or -1 on error */ -ssize_t gkfs_pwrite(std::shared_ptr file, const char* buf, size_t count, off64_t offset) { - if (file->type() != gkfs::filemap::FileType::regular) { +ssize_t +gkfs_pwrite(std::shared_ptr file, const char* buf, + size_t count, off64_t offset) { + if(file->type() != gkfs::filemap::FileType::regular) { assert(file->type() == gkfs::filemap::FileType::directory); LOG(WARNING, "Cannot read from directory"); errno = EISDIR; @@ -567,18 +593,20 @@ ssize_t gkfs_pwrite(std::shared_ptr file, const char* b auto path = make_shared(file->path()); auto append_flag = file->get_flag(gkfs::filemap::OpenFile_flags::append); - auto ret_update_size = gkfs::rpc::forward_update_metadentry_size(*path, count, offset, append_flag); + auto ret_update_size = gkfs::rpc::forward_update_metadentry_size( + *path, count, offset, append_flag); auto err = ret_update_size.first; - if (err) { + if(err) { LOG(ERROR, "update_metadentry_size() failed with err '{}'", err); errno = err; return -1; } auto updated_size = ret_update_size.second; - auto ret_write = gkfs::rpc::forward_write(*path, buf, append_flag, offset, count, updated_size); + auto ret_write = gkfs::rpc::forward_write(*path, buf, append_flag, offset, + count, updated_size); err = ret_write.first; - if (err) { + if(err) { LOG(WARNING, "gkfs::rpc::forward_write() failed with err '{}'", err); errno = err; return -1; @@ -595,7 +623,8 @@ ssize_t gkfs_pwrite(std::shared_ptr file, const char* b * @param offset * @return written size or -1 on error */ -ssize_t gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) { +ssize_t +gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) { auto file = CTX->file_map()->get(fd); return gkfs_pwrite(file, reinterpret_cast(buf), count, offset); } @@ -608,14 +637,16 @@ ssize_t gkfs_pwrite_ws(int fd, const void* buf, size_t count, off64_t offset) { * @param count * @return written size or -1 on error */ -ssize_t gkfs_write(int fd, const void* buf, size_t count) { +ssize_t +gkfs_write(int fd, const void* buf, size_t count) { auto gkfs_fd = CTX->file_map()->get(fd); - auto pos = gkfs_fd->pos(); //retrieve the current offset - if (gkfs_fd->get_flag(gkfs::filemap::OpenFile_flags::append)) + auto pos = gkfs_fd->pos(); // retrieve the current offset + if(gkfs_fd->get_flag(gkfs::filemap::OpenFile_flags::append)) gkfs_lseek(gkfs_fd, 0, SEEK_END); - auto ret = gkfs_pwrite(gkfs_fd, reinterpret_cast(buf), count, pos); + auto ret = gkfs_pwrite(gkfs_fd, reinterpret_cast(buf), count, + pos); // Update offset in file descriptor in the file map - if (ret > 0) { + if(ret > 0) { gkfs_fd->pos(pos + count); } return ret; @@ -630,31 +661,32 @@ ssize_t gkfs_write(int fd, const void* buf, size_t count) { * @param offset * @return written size or -1 on error */ -ssize_t gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset) { +ssize_t +gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset) { auto file = CTX->file_map()->get(fd); auto pos = offset; // keep track of current position ssize_t written = 0; ssize_t ret; - for (int i = 0; i < iovcnt; ++i) { + for(int i = 0; i < iovcnt; ++i) { auto count = (iov + i)->iov_len; - if (count == 0) { + if(count == 0) { continue; } auto buf = (iov + i)->iov_base; ret = gkfs_pwrite(file, reinterpret_cast(buf), count, pos); - if (ret == -1) { + if(ret == -1) { break; } written += ret; pos += ret; - if (static_cast(ret) < count) { + if(static_cast(ret) < count) { break; } } - if (written == 0) { + if(written == 0) { return -1; } return written; @@ -668,13 +700,14 @@ ssize_t gkfs_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset) * @param iovcnt * @return written size or -1 on error */ -ssize_t gkfs_writev(int fd, const struct iovec* iov, int iovcnt) { +ssize_t +gkfs_writev(int fd, const struct iovec* iov, int iovcnt) { auto gkfs_fd = CTX->file_map()->get(fd); auto pos = gkfs_fd->pos(); // retrieve the current offset auto ret = gkfs_pwritev(fd, iov, iovcnt, pos); assert(ret != 0); - if (ret < 0) { + if(ret < 0) { return -1; } gkfs_fd->pos(pos + ret); @@ -689,21 +722,24 @@ ssize_t gkfs_writev(int fd, const struct iovec* iov, int iovcnt) { * @param offset * @return read size or -1 on error */ -ssize_t gkfs_pread(std::shared_ptr file, char* buf, size_t count, off64_t offset) { - if (file->type() != gkfs::filemap::FileType::regular) { +ssize_t +gkfs_pread(std::shared_ptr file, char* buf, + size_t count, off64_t offset) { + if(file->type() != gkfs::filemap::FileType::regular) { assert(file->type() == gkfs::filemap::FileType::directory); LOG(WARNING, "Cannot read from directory"); errno = EISDIR; return -1; } - // Zeroing buffer before read is only relevant for sparse files. Otherwise sparse regions contain invalid data. - if (gkfs::config::io::zero_buffer_before_read) { + // Zeroing buffer before read is only relevant for sparse files. Otherwise + // sparse regions contain invalid data. + if(gkfs::config::io::zero_buffer_before_read) { memset(buf, 0, sizeof(char) * count); } auto ret = gkfs::rpc::forward_read(file->path(), buf, offset, count); auto err = ret.first; - if (err) { + if(err) { LOG(WARNING, "gkfs::rpc::forward_read() failed with ret '{}'", err); errno = err; return -1; @@ -720,12 +756,13 @@ ssize_t gkfs_pread(std::shared_ptr file, char* buf, siz * @param count * @return read size or -1 on error */ -ssize_t gkfs_read(int fd, void* buf, size_t count) { +ssize_t +gkfs_read(int fd, void* buf, size_t count) { auto gkfs_fd = CTX->file_map()->get(fd); - auto pos = gkfs_fd->pos(); //retrieve the current offset + auto pos = gkfs_fd->pos(); // retrieve the current offset auto ret = gkfs_pread(gkfs_fd, reinterpret_cast(buf), count, pos); // Update offset in file descriptor in the file map - if (ret > 0) { + if(ret > 0) { gkfs_fd->pos(pos + ret); } return ret; @@ -740,31 +777,32 @@ ssize_t gkfs_read(int fd, void* buf, size_t count) { * @param offset * @return read size or -1 on error */ -ssize_t gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset) { +ssize_t +gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset) { auto file = CTX->file_map()->get(fd); auto pos = offset; // keep track of current position ssize_t read = 0; ssize_t ret; - for (int i = 0; i < iovcnt; ++i) { + for(int i = 0; i < iovcnt; ++i) { auto count = (iov + i)->iov_len; - if (count == 0) { + if(count == 0) { continue; } auto buf = (iov + i)->iov_base; ret = gkfs_pread(file, reinterpret_cast(buf), count, pos); - if (ret == -1) { + if(ret == -1) { break; } read += ret; pos += ret; - if (static_cast(ret) < count) { + if(static_cast(ret) < count) { break; } } - if (read == 0) { + if(read == 0) { return -1; } return read; @@ -778,13 +816,14 @@ ssize_t gkfs_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset) { * @param iovcnt * @return read size or -1 on error */ -ssize_t gkfs_readv(int fd, const struct iovec* iov, int iovcnt) { +ssize_t +gkfs_readv(int fd, const struct iovec* iov, int iovcnt) { auto gkfs_fd = CTX->file_map()->get(fd); auto pos = gkfs_fd->pos(); // retrieve the current offset auto ret = gkfs_preadv(fd, iov, iovcnt, pos); assert(ret != 0); - if (ret < 0) { + if(ret < 0) { return -1; } gkfs_fd->pos(pos + ret); @@ -800,7 +839,8 @@ ssize_t gkfs_readv(int fd, const struct iovec* iov, int iovcnt) { * @param offset * @return read size or -1 on error */ -ssize_t gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset) { +ssize_t +gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset) { auto gkfs_fd = CTX->file_map()->get(fd); return gkfs_pread(gkfs_fd, reinterpret_cast(buf), count, offset); } @@ -811,13 +851,14 @@ ssize_t gkfs_pread_ws(int fd, void* buf, size_t count, off64_t offset) { * @param path * @return 0 on success or -1 on error */ -int gkfs_opendir(const std::string& path) { +int +gkfs_opendir(const std::string& path) { auto md = gkfs::util::get_metadata(path); - if (!md) { + if(!md) { return -1; } - if (!S_ISDIR(md->mode())) { + if(!S_ISDIR(md->mode())) { LOG(DEBUG, "Path is not a directory"); errno = ENOTDIR; return -1; @@ -825,7 +866,7 @@ int gkfs_opendir(const std::string& path) { auto ret = gkfs::rpc::forward_get_dirents(path); auto err = ret.first; - if (err) { + if(err) { errno = err; return -1; } @@ -839,14 +880,15 @@ int gkfs_opendir(const std::string& path) { * @param path * @return 0 on success or -1 on error */ -int gkfs_rmdir(const std::string& path) { +int +gkfs_rmdir(const std::string& path) { auto md = gkfs::util::get_metadata(path); - if (!md) { + if(!md) { LOG(DEBUG, "Path '{}' does not exist: ", path); errno = ENOENT; return -1; } - if (!S_ISDIR(md->mode())) { + if(!S_ISDIR(md->mode())) { LOG(DEBUG, "Path '{}' is not a directory", path); errno = ENOTDIR; return -1; @@ -854,18 +896,18 @@ int gkfs_rmdir(const std::string& path) { auto ret = gkfs::rpc::forward_get_dirents(path); auto err = ret.first; - if (err) { + if(err) { errno = err; return -1; } assert(ret.second); auto open_dir = ret.second; - if (open_dir->size() != 0) { + if(open_dir->size() != 0) { errno = ENOTEMPTY; return -1; } err = gkfs::rpc::forward_remove(path, true, 0); - if (err) { + if(err) { errno = err; return -1; } @@ -880,51 +922,55 @@ int gkfs_rmdir(const std::string& path) { * @param count * @return 0 on success or -1 on error */ -int gkfs_getdents(unsigned int fd, - struct linux_dirent* dirp, - unsigned int count) { +int +gkfs_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { // Get opendir object (content was downloaded with opendir() call) auto open_dir = CTX->file_map()->get_dir(fd); - if (open_dir == nullptr) { - //Cast did not succeeded: open_file is a regular file + if(open_dir == nullptr) { + // Cast did not succeeded: open_file is a regular file errno = EBADF; return -1; } // get directory position of which entries to return auto pos = open_dir->pos(); - if (pos >= open_dir->size()) { + if(pos >= open_dir->size()) { return 0; } unsigned int written = 0; struct linux_dirent* current_dirp = nullptr; - while (pos < open_dir->size()) { + while(pos < open_dir->size()) { // get dentry fir current position auto de = open_dir->getdent(pos); /* - * Calculate the total dentry size within the kernel struct `linux_dirent` depending on the file name size. - * The size is then aligned to the size of `long` boundary. - * This line was originally defined in the linux kernel: fs/readdir.c in function filldir(): - * int reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2, sizeof(long)); - * However, since d_name is null-terminated and de.name().size() does not include space - * for the null-terminator, we add 1. Thus, + 3 in total. + * Calculate the total dentry size within the kernel struct + * `linux_dirent` depending on the file name size. The size is then + * aligned to the size of `long` boundary. This line was originally + * defined in the linux kernel: fs/readdir.c in function filldir(): int + * reclen = ALIGN(offsetof(struct linux_dirent, d_name) + namlen + 2, + * sizeof(long)); However, since d_name is null-terminated and + * de.name().size() does not include space for the null-terminator, we + * add 1. Thus, + 3 in total. */ - auto total_size = ALIGN(offsetof( - struct linux_dirent, d_name) + de.name().size() + 3, sizeof(long)); - if (total_size > (count - written)) { - //no enough space left on user buffer to insert next dirent + auto total_size = ALIGN(offsetof(struct linux_dirent, d_name) + + de.name().size() + 3, + sizeof(long)); + if(total_size > (count - written)) { + // no enough space left on user buffer to insert next dirent break; } - current_dirp = reinterpret_cast(reinterpret_cast(dirp) + written); - current_dirp->d_ino = std::hash()( - open_dir->path() + "/" + de.name()); + current_dirp = reinterpret_cast( + reinterpret_cast(dirp) + written); + current_dirp->d_ino = + std::hash()(open_dir->path() + "/" + de.name()); current_dirp->d_reclen = total_size; *(reinterpret_cast(current_dirp) + total_size - 1) = - ((de.type() == gkfs::filemap::FileType::regular) ? DT_REG : DT_DIR); + ((de.type() == gkfs::filemap::FileType::regular) ? DT_REG + : DT_DIR); LOG(DEBUG, "name {}: {}", pos, de.name()); std::strcpy(&(current_dirp->d_name[0]), de.name().c_str()); @@ -933,7 +979,7 @@ int gkfs_getdents(unsigned int fd, written += total_size; } - if (written == 0) { + if(written == 0) { errno = EINVAL; return -1; } @@ -950,47 +996,53 @@ int gkfs_getdents(unsigned int fd, * @param count * @return 0 on success or -1 on error */ -int gkfs_getdents64(unsigned int fd, - struct linux_dirent64* dirp, - unsigned int count) { +int +gkfs_getdents64(unsigned int fd, struct linux_dirent64* dirp, + unsigned int count) { auto open_dir = CTX->file_map()->get_dir(fd); - if (open_dir == nullptr) { - //Cast did not succeeded: open_file is a regular file + if(open_dir == nullptr) { + // Cast did not succeeded: open_file is a regular file errno = EBADF; return -1; } auto pos = open_dir->pos(); - if (pos >= open_dir->size()) { + if(pos >= open_dir->size()) { return 0; } unsigned int written = 0; struct linux_dirent64* current_dirp = nullptr; - while (pos < open_dir->size()) { + while(pos < open_dir->size()) { auto de = open_dir->getdent(pos); /* - * Calculate the total dentry size within the kernel struct `linux_dirent` depending on the file name size. - * The size is then aligned to the size of `long` boundary. + * Calculate the total dentry size within the kernel struct + * `linux_dirent` depending on the file name size. The size is then + * aligned to the size of `long` boundary. * - * This line was originally defined in the linux kernel: fs/readdir.c in function filldir64(): - * int reclen = ALIGN(offsetof(struct linux_dirent64, d_name) + namlen + 1, sizeof(u64)); - * We keep + 1 because: - * Since d_name is null-terminated and de.name().size() does not include space - * for the null-terminator, we add 1. Since d_name in our `struct linux_dirent64` definition - * is not a zero-size array (as opposed to the kernel version), we subtract 1. Thus, it stays + 1. + * This line was originally defined in the linux kernel: fs/readdir.c in + * function filldir64(): int reclen = ALIGN(offsetof(struct + * linux_dirent64, d_name) + namlen + 1, sizeof(u64)); We keep + 1 + * because: Since d_name is null-terminated and de.name().size() does + * not include space for the null-terminator, we add 1. Since d_name in + * our `struct linux_dirent64` definition is not a zero-size array (as + * opposed to the kernel version), we subtract 1. Thus, it stays + 1. */ - auto total_size = ALIGN(offsetof( - struct linux_dirent64, d_name) + de.name().size() + 1, sizeof(uint64_t)); - if (total_size > (count - written)) { - //no enough space left on user buffer to insert next dirent + auto total_size = ALIGN(offsetof(struct linux_dirent64, d_name) + + de.name().size() + 1, + sizeof(uint64_t)); + if(total_size > (count - written)) { + // no enough space left on user buffer to insert next dirent break; } - current_dirp = reinterpret_cast(reinterpret_cast(dirp) + written); - current_dirp->d_ino = std::hash()( - open_dir->path() + "/" + de.name()); + current_dirp = reinterpret_cast( + reinterpret_cast(dirp) + written); + current_dirp->d_ino = + std::hash()(open_dir->path() + "/" + de.name()); current_dirp->d_reclen = total_size; - current_dirp->d_type = ((de.type() == gkfs::filemap::FileType::regular) ? DT_REG : DT_DIR); + current_dirp->d_type = + ((de.type() == gkfs::filemap::FileType::regular) ? DT_REG + : DT_DIR); LOG(DEBUG, "name {}: {}", pos, de.name()); std::strcpy(&(current_dirp->d_name[0]), de.name().c_str()); @@ -999,7 +1051,7 @@ int gkfs_getdents64(unsigned int fd, written += total_size; } - if (written == 0) { + if(written == 0) { errno = EINVAL; return -1; } @@ -1020,16 +1072,17 @@ int gkfs_getdents64(unsigned int fd, * @param target_path * @return 0 on success or -1 on error */ -int gkfs_mk_symlink(const std::string& path, const std::string& target_path) { +int +gkfs_mk_symlink(const std::string& path, const std::string& target_path) { /* The following check is not POSIX compliant. * In POSIX the target is not checked at all. - * Here if the target is a directory we raise a NOTSUP error. - * So that application know we don't support link to directory. - */ + * Here if the target is a directory we raise a NOTSUP error. + * So that application know we don't support link to directory. + */ auto target_md = gkfs::util::get_metadata(target_path, false); - if (target_md != nullptr) { + if(target_md != nullptr) { auto trg_mode = target_md->mode(); - if (!(S_ISREG(trg_mode) || S_ISLNK(trg_mode))) { + if(!(S_ISREG(trg_mode) || S_ISLNK(trg_mode))) { assert(S_ISDIR(trg_mode)); LOG(DEBUG, "Target path is a directory. Not supported"); errno = ENOTSUP; @@ -1037,18 +1090,18 @@ int gkfs_mk_symlink(const std::string& path, const std::string& target_path) { } } - if (check_parent_dir(path)) { + if(check_parent_dir(path)) { return -1; } auto link_md = gkfs::util::get_metadata(path, false); - if (link_md != nullptr) { + if(link_md != nullptr) { LOG(DEBUG, "Link exists: '{}'", path); errno = EEXIST; return -1; } auto err = gkfs::rpc::forward_mk_symlink(path, target_path); - if (err) { + if(err) { errno = err; return -1; } @@ -1066,20 +1119,22 @@ int gkfs_mk_symlink(const std::string& path, const std::string& target_path) { * @param bufsize * @return 0 on success or -1 on error */ -int gkfs_readlink(const std::string& path, char* buf, int bufsize) { +int +gkfs_readlink(const std::string& path, char* buf, int bufsize) { auto md = gkfs::util::get_metadata(path, false); - if (md == nullptr) { + if(md == nullptr) { LOG(DEBUG, "Named link doesn't exist"); return -1; } - if (!(md->is_link())) { + if(!(md->is_link())) { LOG(DEBUG, "The named file is not a symbolic link"); errno = EINVAL; return -1; } int path_size = md->target_path().size() + CTX->mountdir().size(); - if (path_size >= bufsize) { - LOG(WARNING, "Destination buffer size is too short: {} < {}, {} ", bufsize, path_size, md->target_path()); + if(path_size >= bufsize) { + LOG(WARNING, "Destination buffer size is too short: {} < {}, {} ", + bufsize, path_size, md->target_path()); errno = ENAMETOOLONG; return -1; } diff --git a/src/client/hooks.cpp b/src/client/hooks.cpp index a4571035f..1e845cd44 100644 --- a/src/client/hooks.cpp +++ b/src/client/hooks.cpp @@ -33,7 +33,8 @@ extern "C" { namespace { // TODO replace all internal gkfs errno variable usage with LEAF -inline int with_errno(int ret) { +inline int +with_errno(int ret) { return (ret < 0) ? -errno : ret; } @@ -42,19 +43,21 @@ inline int with_errno(int ret) { namespace gkfs { namespace hook { -int hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { +int +hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { LOG(DEBUG, "{}() called with fd: {}, path: \"{}\", flags: {}, mode: {}", __func__, dirfd, cpath, flags, mode); std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: return syscall_no_intercept(SYS_openat, dirfd, cpath, flags, mode); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_openat, dirfd, resolved.c_str(), flags, mode); + return syscall_no_intercept(SYS_openat, dirfd, resolved.c_str(), + flags, mode); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; @@ -68,18 +71,19 @@ int hook_openat(int dirfd, const char* cpath, int flags, mode_t mode) { } } -int hook_close(int fd) { +int +hook_close(int fd) { LOG(DEBUG, "{}() called with fd: {}", __func__, fd); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { // No call to the daemon is required CTX->file_map()->remove(fd); return 0; } - if (CTX->is_internal_fd(fd)) { - // the client application (for some reason) is trying to close an + if(CTX->is_internal_fd(fd)) { + // the client application (for some reason) is trying to close an // internal fd: ignore it return 0; } @@ -87,13 +91,14 @@ int hook_close(int fd) { return syscall_no_intercept(SYS_close, fd); } -int hook_stat(const char* path, struct stat* buf) { +int +hook_stat(const char* path, struct stat* buf) { - LOG(DEBUG, "{}() called with path: \"{}\", buf: {}", - __func__, path, fmt::ptr(buf)); + LOG(DEBUG, "{}() called with path: \"{}\", buf: {}", __func__, path, + fmt::ptr(buf)); std::string rel_path; - if (CTX->relativize_path(path, rel_path, false)) { + if(CTX->relativize_path(path, rel_path, false)) { return with_errno(gkfs::syscall::gkfs_stat(rel_path, buf)); } return syscall_no_intercept(SYS_stat, rel_path.c_str(), buf); @@ -101,30 +106,35 @@ int hook_stat(const char* path, struct stat* buf) { #ifdef STATX_TYPE -int hook_statx(int dirfd, const char* path, int flags, unsigned int mask, struct ::statx* buf) { +int +hook_statx(int dirfd, const char* path, int flags, unsigned int mask, + struct ::statx* buf) { - LOG(DEBUG, "{}() called with dirfd: '{}', path: \"{}\", flags: '{}', mask: '{}', buf: '{}'", + LOG(DEBUG, + "{}() called with dirfd: '{}', path: \"{}\", flags: '{}', mask: '{}', buf: '{}'", __func__, dirfd, path, flags, mask, fmt::ptr(buf)); std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, path, resolved); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: - return syscall_no_intercept(SYS_statx, dirfd, path, flags, mask, buf); + return syscall_no_intercept(SYS_statx, dirfd, path, flags, mask, + buf); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_statx, dirfd, resolved.c_str(), flags, mask, buf); + return syscall_no_intercept(SYS_statx, dirfd, resolved.c_str(), + flags, mask, buf); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; case gkfs::preload::RelativizeStatus::internal: - return with_errno(gkfs::syscall::gkfs_statx(dirfd, resolved.c_str(), flags, mask, buf)); + return with_errno(gkfs::syscall::gkfs_statx(dirfd, resolved.c_str(), + flags, mask, buf)); default: LOG(ERROR, "{}() relativize status unknown: {}", __func__); return -EINVAL; - } return syscall_no_intercept(SYS_statx, dirfd, path, flags, mask, buf); @@ -132,48 +142,52 @@ int hook_statx(int dirfd, const char* path, int flags, unsigned int mask, struct #endif -int hook_lstat(const char* path, struct stat* buf) { +int +hook_lstat(const char* path, struct stat* buf) { - LOG(DEBUG, "{}() called with path: \"{}\", buf: {}", - __func__, path, fmt::ptr(buf)); + LOG(DEBUG, "{}() called with path: \"{}\", buf: {}", __func__, path, + fmt::ptr(buf)); std::string rel_path; - if (CTX->relativize_path(path, rel_path)) { + if(CTX->relativize_path(path, rel_path)) { return with_errno(gkfs::syscall::gkfs_stat(rel_path, buf)); } return syscall_no_intercept(SYS_lstat, rel_path.c_str(), buf); } -int hook_fstat(unsigned int fd, struct stat* buf) { +int +hook_fstat(unsigned int fd, struct stat* buf) { - LOG(DEBUG, "{}() called with fd: {}, buf: {}", - __func__, fd, fmt::ptr(buf)); + LOG(DEBUG, "{}() called with fd: {}, buf: {}", __func__, fd, fmt::ptr(buf)); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { auto path = CTX->file_map()->get(fd)->path(); return with_errno(gkfs::syscall::gkfs_stat(path, buf)); } return syscall_no_intercept(SYS_fstat, fd, buf); } -int hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) { +int +hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) { LOG(DEBUG, "{}() called with path: \"{}\", fd: {}, buf: {}, flags: {}", __func__, cpath, dirfd, fmt::ptr(buf), flags); - if (flags & AT_EMPTY_PATH) { + if(flags & AT_EMPTY_PATH) { LOG(ERROR, "{}() AT_EMPTY_PATH flag not supported", __func__); return -ENOTSUP; } std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: - return syscall_no_intercept(SYS_newfstatat, dirfd, cpath, buf, flags); + return syscall_no_intercept(SYS_newfstatat, dirfd, cpath, buf, + flags); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_newfstatat, dirfd, resolved.c_str(), buf, flags); + return syscall_no_intercept(SYS_newfstatat, dirfd, resolved.c_str(), + buf, flags); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; @@ -187,124 +201,140 @@ int hook_fstatat(int dirfd, const char* cpath, struct stat* buf, int flags) { } } -int hook_read(unsigned int fd, void* buf, size_t count) { +int +hook_read(unsigned int fd, void* buf, size_t count) { - LOG(DEBUG, "{}() called with fd: {}, buf: {} count: {}", - __func__, fd, fmt::ptr(buf), count); + LOG(DEBUG, "{}() called with fd: {}, buf: {} count: {}", __func__, fd, + fmt::ptr(buf), count); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_read(fd, buf, count)); } return syscall_no_intercept(SYS_read, fd, buf, count); } -int hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos) { +int +hook_pread(unsigned int fd, char* buf, size_t count, loff_t pos) { - LOG(DEBUG, "{}() called with fd: {}, buf: {}, count: {}, pos: {}", - __func__, fd, fmt::ptr(buf), count, pos); + LOG(DEBUG, "{}() called with fd: {}, buf: {}, count: {}, pos: {}", __func__, + fd, fmt::ptr(buf), count, pos); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_pread_ws(fd, buf, count, pos)); } - /* Since kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). */ + /* Since kernel 2.6: pread() became pread64(), and pwrite() became + * pwrite64(). */ return syscall_no_intercept(SYS_pread64, fd, buf, count, pos); } -int hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) { +int +hook_readv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) { - LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}", - __func__, fd, fmt::ptr(iov), iovcnt); + LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}", __func__, fd, + fmt::ptr(iov), iovcnt); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_readv(fd, iov, iovcnt)); } return syscall_no_intercept(SYS_readv, fd, iov, iovcnt); } -int hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, - unsigned long pos_l, unsigned long pos_h) { +int +hook_preadv(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, + unsigned long pos_l, unsigned long pos_h) { - LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}, " - "pos_l: {}," "pos_h: {}", + LOG(DEBUG, + "{}() called with fd: {}, iov: {}, iovcnt: {}, " + "pos_l: {}," + "pos_h: {}", __func__, fd, fmt::ptr(iov), iovcnt, pos_l, pos_h); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_preadv(fd, iov, iovcnt, pos_l)); } return syscall_no_intercept(SYS_preadv, fd, iov, iovcnt, pos_l); } -int hook_write(unsigned int fd, const char* buf, size_t count) { +int +hook_write(unsigned int fd, const char* buf, size_t count) { - LOG(DEBUG, "{}() called with fd: {}, buf: {}, count {}", - __func__, fd, fmt::ptr(buf), count); + LOG(DEBUG, "{}() called with fd: {}, buf: {}, count {}", __func__, fd, + fmt::ptr(buf), count); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_write(fd, buf, count)); } return syscall_no_intercept(SYS_write, fd, buf, count); } -int hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos) { +int +hook_pwrite(unsigned int fd, const char* buf, size_t count, loff_t pos) { - LOG(DEBUG, "{}() called with fd: {}, buf: {}, count: {}, pos: {}", - __func__, fd, fmt::ptr(buf), count, pos); + LOG(DEBUG, "{}() called with fd: {}, buf: {}, count: {}, pos: {}", __func__, + fd, fmt::ptr(buf), count, pos); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_pwrite_ws(fd, buf, count, pos)); } - /* Since kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). */ + /* Since kernel 2.6: pread() became pread64(), and pwrite() became + * pwrite64(). */ return syscall_no_intercept(SYS_pwrite64, fd, buf, count, pos); } -int hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) { +int +hook_writev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt) { - LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}", - __func__, fd, fmt::ptr(iov), iovcnt); + LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}", __func__, fd, + fmt::ptr(iov), iovcnt); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_writev(fd, iov, iovcnt)); } return syscall_no_intercept(SYS_writev, fd, iov, iovcnt); } -int hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, - unsigned long pos_l, unsigned long pos_h) { +int +hook_pwritev(unsigned long fd, const struct iovec* iov, unsigned long iovcnt, + unsigned long pos_l, unsigned long pos_h) { - LOG(DEBUG, "{}() called with fd: {}, iov: {}, iovcnt: {}, " - "pos_l: {}," "pos_h: {}", + LOG(DEBUG, + "{}() called with fd: {}, iov: {}, iovcnt: {}, " + "pos_l: {}," + "pos_h: {}", __func__, fd, fmt::ptr(iov), iovcnt, pos_l, pos_h); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_pwritev(fd, iov, iovcnt, pos_l)); } return syscall_no_intercept(SYS_pwritev, fd, iov, iovcnt, pos_l); } -int hook_unlinkat(int dirfd, const char* cpath, int flags) { +int +hook_unlinkat(int dirfd, const char* cpath, int flags) { - LOG(DEBUG, "{}() called with dirfd: {}, path: \"{}\", flags: {}", - __func__, dirfd, cpath, flags); + LOG(DEBUG, "{}() called with dirfd: {}, path: \"{}\", flags: {}", __func__, + dirfd, cpath, flags); - if ((flags & ~AT_REMOVEDIR) != 0) { + if((flags & ~AT_REMOVEDIR) != 0) { LOG(ERROR, "{}() Flags unknown: {}", __func__, flags); return -EINVAL; } std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved, false); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: return syscall_no_intercept(SYS_unlinkat, dirfd, cpath, flags); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_unlinkat, dirfd, resolved.c_str(), flags); + return syscall_no_intercept(SYS_unlinkat, dirfd, resolved.c_str(), + flags); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; case gkfs::preload::RelativizeStatus::internal: - if (flags & AT_REMOVEDIR) { + if(flags & AT_REMOVEDIR) { return with_errno(gkfs::syscall::gkfs_rmdir(resolved)); } else { return with_errno(gkfs::syscall::gkfs_remove(resolved)); @@ -316,25 +346,29 @@ int hook_unlinkat(int dirfd, const char* cpath, int flags) { } } -int hook_symlinkat(const char* oldname, int newdfd, const char* newname) { +int +hook_symlinkat(const char* oldname, int newdfd, const char* newname) { LOG(DEBUG, "{}() called with oldname: \"{}\", newfd: {}, newname: \"{}\"", __func__, oldname, newdfd, newname); std::string oldname_resolved; - if (CTX->relativize_path(oldname, oldname_resolved)) { + if(CTX->relativize_path(oldname, oldname_resolved)) { LOG(WARNING, "{}() operation not supported", __func__); return -ENOTSUP; } std::string newname_resolved; - auto rstatus = CTX->relativize_fd_path(newdfd, newname, newname_resolved, false); - switch (rstatus) { + auto rstatus = + CTX->relativize_fd_path(newdfd, newname, newname_resolved, false); + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: - return syscall_no_intercept(SYS_symlinkat, oldname, newdfd, newname); + return syscall_no_intercept(SYS_symlinkat, oldname, newdfd, + newname); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_symlinkat, oldname, newdfd, newname_resolved.c_str()); + return syscall_no_intercept(SYS_symlinkat, oldname, newdfd, + newname_resolved.c_str()); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; @@ -350,15 +384,15 @@ int hook_symlinkat(const char* oldname, int newdfd, const char* newname) { } -int hook_access(const char* path, int mask) { +int +hook_access(const char* path, int mask) { - LOG(DEBUG, "{}() called path: \"{}\", mask: {}", - __func__, path, mask); + LOG(DEBUG, "{}() called path: \"{}\", mask: {}", __func__, path, mask); std::string rel_path; - if (CTX->relativize_path(path, rel_path)) { + if(CTX->relativize_path(path, rel_path)) { auto ret = gkfs::syscall::gkfs_access(rel_path, mask); - if (ret < 0) { + if(ret < 0) { return -errno; } return ret; @@ -366,19 +400,21 @@ int hook_access(const char* path, int mask) { return syscall_no_intercept(SYS_access, rel_path.c_str(), mask); } -int hook_faccessat(int dirfd, const char* cpath, int mode) { +int +hook_faccessat(int dirfd, const char* cpath, int mode) { - LOG(DEBUG, "{}() called with dirfd: {}, path: \"{}\", mode: {}", - __func__, dirfd, cpath, mode); + LOG(DEBUG, "{}() called with dirfd: {}, path: \"{}\", mode: {}", __func__, + dirfd, cpath, mode); std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: return syscall_no_intercept(SYS_faccessat, dirfd, cpath, mode); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_faccessat, dirfd, resolved.c_str(), mode); + return syscall_no_intercept(SYS_faccessat, dirfd, resolved.c_str(), + mode); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; @@ -392,16 +428,18 @@ int hook_faccessat(int dirfd, const char* cpath, int mode) { } } -off_t hook_lseek(unsigned int fd, off_t offset, unsigned int whence) { +off_t +hook_lseek(unsigned int fd, off_t offset, unsigned int whence) { - LOG(DEBUG, "{}() called with fd: {}, offset: {}, whence: {}", - __func__, fd, offset, whence); + LOG(DEBUG, "{}() called with fd: {}, offset: {}, whence: {}", __func__, fd, + offset, whence); - if (CTX->file_map()->exist(fd)) { - auto off_ret = gkfs::syscall::gkfs_lseek(fd, static_cast(offset), whence); - if (off_ret > std::numeric_limits::max()) { + if(CTX->file_map()->exist(fd)) { + auto off_ret = gkfs::syscall::gkfs_lseek( + fd, static_cast(offset), whence); + if(off_ret > std::numeric_limits::max()) { return -EOVERFLOW; - } else if (off_ret < 0) { + } else if(off_ret < 0) { return -errno; } LOG(DEBUG, "{}() returning {}", __func__, off_ret); @@ -410,58 +448,59 @@ off_t hook_lseek(unsigned int fd, off_t offset, unsigned int whence) { return syscall_no_intercept(SYS_lseek, fd, offset, whence); } -int hook_truncate(const char* path, long length) { +int +hook_truncate(const char* path, long length) { - LOG(DEBUG, "{}() called with path: {}, offset: {}", - __func__, path, length); + LOG(DEBUG, "{}() called with path: {}, offset: {}", __func__, path, length); std::string rel_path; - if (CTX->relativize_path(path, rel_path)) { + if(CTX->relativize_path(path, rel_path)) { return with_errno(gkfs::syscall::gkfs_truncate(rel_path, length)); } return syscall_no_intercept(SYS_truncate, rel_path.c_str(), length); } -int hook_ftruncate(unsigned int fd, unsigned long length) { +int +hook_ftruncate(unsigned int fd, unsigned long length) { - LOG(DEBUG, "{}() called with fd: {}, offset: {}", - __func__, fd, length); + LOG(DEBUG, "{}() called with fd: {}, offset: {}", __func__, fd, length); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { auto path = CTX->file_map()->get(fd)->path(); return with_errno(gkfs::syscall::gkfs_truncate(path, length)); } return syscall_no_intercept(SYS_ftruncate, fd, length); } -int hook_dup(unsigned int fd) { +int +hook_dup(unsigned int fd) { - LOG(DEBUG, "{}() called with oldfd: {}", - __func__, fd); + LOG(DEBUG, "{}() called with oldfd: {}", __func__, fd); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_dup(fd)); } return syscall_no_intercept(SYS_dup, fd); } -int hook_dup2(unsigned int oldfd, unsigned int newfd) { +int +hook_dup2(unsigned int oldfd, unsigned int newfd) { - LOG(DEBUG, "{}() called with oldfd: {}, newfd: {}", - __func__, oldfd, newfd); + LOG(DEBUG, "{}() called with oldfd: {}, newfd: {}", __func__, oldfd, newfd); - if (CTX->file_map()->exist(oldfd)) { + if(CTX->file_map()->exist(oldfd)) { return with_errno(gkfs::syscall::gkfs_dup2(oldfd, newfd)); } return syscall_no_intercept(SYS_dup2, oldfd, newfd); } -int hook_dup3(unsigned int oldfd, unsigned int newfd, int flags) { +int +hook_dup3(unsigned int oldfd, unsigned int newfd, int flags) { - LOG(DEBUG, "{}() called with oldfd: {}, newfd: {}, flags: {}", - __func__, oldfd, newfd, flags); + LOG(DEBUG, "{}() called with oldfd: {}, newfd: {}, flags: {}", __func__, + oldfd, newfd, flags); - if (CTX->file_map()->exist(oldfd)) { + if(CTX->file_map()->exist(oldfd)) { // TODO implement O_CLOEXEC flag first which is used with fcntl(2) // It is in glibc since kernel 2.9. So maybe not that important :) LOG(WARNING, "{}() Not supported", __func__); @@ -470,40 +509,45 @@ int hook_dup3(unsigned int oldfd, unsigned int newfd, int flags) { return syscall_no_intercept(SYS_dup3, oldfd, newfd, flags); } -int hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { +int +hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) { - LOG(DEBUG, "{}() called with fd: {}, dirp: {}, count: {}", - __func__, fd, fmt::ptr(dirp), count); + LOG(DEBUG, "{}() called with fd: {}, dirp: {}, count: {}", __func__, fd, + fmt::ptr(dirp), count); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_getdents(fd, dirp, count)); } return syscall_no_intercept(SYS_getdents, fd, dirp, count); } -int hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, unsigned int count) { +int +hook_getdents64(unsigned int fd, struct linux_dirent64* dirp, + unsigned int count) { - LOG(DEBUG, "{}() called with fd: {}, dirp: {}, count: {}", - __func__, fd, fmt::ptr(dirp), count); + LOG(DEBUG, "{}() called with fd: {}, dirp: {}, count: {}", __func__, fd, + fmt::ptr(dirp), count); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_getdents64(fd, dirp, count)); } return syscall_no_intercept(SYS_getdents64, fd, dirp, count); } -int hook_mkdirat(int dirfd, const char* cpath, mode_t mode) { +int +hook_mkdirat(int dirfd, const char* cpath, mode_t mode) { - LOG(DEBUG, "{}() called with dirfd: {}, path: \"{}\", mode: {}", - __func__, dirfd, cpath, mode); + LOG(DEBUG, "{}() called with dirfd: {}, path: \"{}\", mode: {}", __func__, + dirfd, cpath, mode); std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_mkdirat, dirfd, resolved.c_str(), mode); + return syscall_no_intercept(SYS_mkdirat, dirfd, resolved.c_str(), + mode); case gkfs::preload::RelativizeStatus::fd_unknown: return syscall_no_intercept(SYS_mkdirat, dirfd, cpath, mode); @@ -512,7 +556,8 @@ int hook_mkdirat(int dirfd, const char* cpath, mode_t mode) { return -ENOTDIR; case gkfs::preload::RelativizeStatus::internal: - return with_errno(gkfs::syscall::gkfs_create(resolved, mode | S_IFDIR)); + return with_errno( + gkfs::syscall::gkfs_create(resolved, mode | S_IFDIR)); default: LOG(ERROR, "{}() relativize status unknown: {}", __func__); @@ -520,19 +565,21 @@ int hook_mkdirat(int dirfd, const char* cpath, mode_t mode) { } } -int hook_fchmodat(int dirfd, const char* cpath, mode_t mode) { +int +hook_fchmodat(int dirfd, const char* cpath, mode_t mode) { - LOG(DEBUG, "{}() called dirfd: {}, path: \"{}\", mode: {}", - __func__, dirfd, cpath, mode); + LOG(DEBUG, "{}() called dirfd: {}, path: \"{}\", mode: {}", __func__, dirfd, + cpath, mode); std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: return syscall_no_intercept(SYS_fchmodat, dirfd, cpath, mode); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_fchmodat, dirfd, resolved.c_str(), mode); + return syscall_no_intercept(SYS_fchmodat, dirfd, resolved.c_str(), + mode); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; @@ -547,82 +594,82 @@ int hook_fchmodat(int dirfd, const char* cpath, mode_t mode) { } } -int hook_fchmod(unsigned int fd, mode_t mode) { +int +hook_fchmod(unsigned int fd, mode_t mode) { - LOG(DEBUG, "{}() called with fd: {}, mode: {}", - __func__, fd, mode); + LOG(DEBUG, "{}() called with fd: {}, mode: {}", __func__, fd, mode); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { LOG(WARNING, "{}() operation not supported", __func__); return -ENOTSUP; } return syscall_no_intercept(SYS_fchmod, fd, mode); } -int hook_chdir(const char* path) { +int +hook_chdir(const char* path) { - LOG(DEBUG, "{}() called with path: \"{}\"", - __func__, path); + LOG(DEBUG, "{}() called with path: \"{}\"", __func__, path); std::string rel_path; bool internal = CTX->relativize_path(path, rel_path); - if (internal) { - //path falls in our namespace + if(internal) { + // path falls in our namespace auto md = gkfs::util::get_metadata(rel_path); - if (md == nullptr) { + if(md == nullptr) { LOG(ERROR, "{}() path does not exists", __func__); return -ENOENT; } - if (!S_ISDIR(md->mode())) { + if(!S_ISDIR(md->mode())) { LOG(ERROR, "{}() path is not a directory", __func__); return -ENOTDIR; } - //TODO get complete path from relativize_path instead of + // TODO get complete path from relativize_path instead of // removing mountdir and then adding again here rel_path.insert(0, CTX->mountdir()); - if (gkfs::path::has_trailing_slash(rel_path)) { + if(gkfs::path::has_trailing_slash(rel_path)) { // open_dir is '/' rel_path.pop_back(); } } try { gkfs::path::set_cwd(rel_path, internal); - } catch (const std::system_error& se) { + } catch(const std::system_error& se) { return -(se.code().value()); } return 0; } -int hook_fchdir(unsigned int fd) { +int +hook_fchdir(unsigned int fd) { - LOG(DEBUG, "{}() called with fd: {}", - __func__, fd); + LOG(DEBUG, "{}() called with fd: {}", __func__, fd); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { auto open_dir = CTX->file_map()->get_dir(fd); - if (open_dir == nullptr) { - //Cast did not succeeded: open_file is a regular file + if(open_dir == nullptr) { + // Cast did not succeeded: open_file is a regular file LOG(ERROR, "{}() file descriptor refers to a normal file: '{}'", __func__, open_dir->path()); return -EBADF; } std::string new_path = CTX->mountdir() + open_dir->path(); - if (gkfs::path::has_trailing_slash(new_path)) { + if(gkfs::path::has_trailing_slash(new_path)) { // open_dir is '/' new_path.pop_back(); } try { gkfs::path::set_cwd(new_path, true); - } catch (const std::system_error& se) { + } catch(const std::system_error& se) { return -(se.code().value()); } } else { long ret = syscall_no_intercept(SYS_fchdir, fd); - if (ret < 0) { - throw std::system_error(syscall_error_code(ret), - std::system_category(), - "Failed to change directory (fchdir syscall)"); + if(ret < 0) { + throw std::system_error( + syscall_error_code(ret), std::system_category(), + "Failed to change directory (fchdir syscall)"); } gkfs::path::unset_env_cwd(); CTX->cwd(gkfs::path::get_sys_cwd()); @@ -630,13 +677,15 @@ int hook_fchdir(unsigned int fd) { return 0; } -int hook_getcwd(char* buf, unsigned long size) { +int +hook_getcwd(char* buf, unsigned long size) { - LOG(DEBUG, "{}() called with buf: {}, size: {}", - __func__, fmt::ptr(buf), size); + LOG(DEBUG, "{}() called with buf: {}, size: {}", __func__, fmt::ptr(buf), + size); - if (CTX->cwd().size() + 1 > size) { - LOG(ERROR, "{}() buffer too small to host current working dir", __func__); + if(CTX->cwd().size() + 1 > size) { + LOG(ERROR, "{}() buffer too small to host current working dir", + __func__); return -ERANGE; } @@ -644,19 +693,22 @@ int hook_getcwd(char* buf, unsigned long size) { return (CTX->cwd().size() + 1); } -int hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz) { +int +hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz) { LOG(DEBUG, "{}() called with dirfd: {}, path \"{}\", buf: {}, bufsize: {}", __func__, dirfd, cpath, fmt::ptr(buf), bufsiz); std::string resolved; auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved, false); - switch (rstatus) { + switch(rstatus) { case gkfs::preload::RelativizeStatus::fd_unknown: - return syscall_no_intercept(SYS_readlinkat, dirfd, cpath, buf, bufsiz); + return syscall_no_intercept(SYS_readlinkat, dirfd, cpath, buf, + bufsiz); case gkfs::preload::RelativizeStatus::external: - return syscall_no_intercept(SYS_readlinkat, dirfd, resolved.c_str(), buf, bufsiz); + return syscall_no_intercept(SYS_readlinkat, dirfd, resolved.c_str(), + buf, bufsiz); case gkfs::preload::RelativizeStatus::fd_not_a_dir: return -ENOTDIR; @@ -671,16 +723,17 @@ int hook_readlinkat(int dirfd, const char* cpath, char* buf, int bufsiz) { } } -int hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { +int +hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { - LOG(DEBUG, "{}() called with fd: {}, cmd: {}, arg: {}", - __func__, fd, cmd, arg); + LOG(DEBUG, "{}() called with fd: {}, cmd: {}, arg: {}", __func__, fd, cmd, + arg); - if (!CTX->file_map()->exist(fd)) { + if(!CTX->file_map()->exist(fd)) { return syscall_no_intercept(SYS_fcntl, fd, cmd, arg); } int ret; - switch (cmd) { + switch(cmd) { case F_DUPFD: LOG(DEBUG, "{}() F_DUPFD on fd {}", __func__, fd); @@ -689,16 +742,17 @@ int hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { case F_DUPFD_CLOEXEC: LOG(DEBUG, "{}() F_DUPFD_CLOEXEC on fd {}", __func__, fd); ret = gkfs::syscall::gkfs_dup(fd); - if (ret == -1) { + if(ret == -1) { return -errno; } - CTX->file_map()->get(fd)->set_flag(gkfs::filemap::OpenFile_flags::cloexec, true); + CTX->file_map()->get(fd)->set_flag( + gkfs::filemap::OpenFile_flags::cloexec, true); return ret; case F_GETFD: LOG(DEBUG, "{}() F_GETFD on fd {}", __func__, fd); - if (CTX->file_map()->get(fd) - ->get_flag(gkfs::filemap::OpenFile_flags::cloexec)) { + if(CTX->file_map()->get(fd)->get_flag( + gkfs::filemap::OpenFile_flags::cloexec)) { return FD_CLOEXEC; } return 0; @@ -706,47 +760,49 @@ int hook_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) { case F_GETFL: LOG(DEBUG, "{}() F_GETFL on fd {}", __func__, fd); ret = 0; - if (CTX->file_map()->get(fd) - ->get_flag(gkfs::filemap::OpenFile_flags::rdonly)) { + if(CTX->file_map()->get(fd)->get_flag( + gkfs::filemap::OpenFile_flags::rdonly)) { ret |= O_RDONLY; } - if (CTX->file_map()->get(fd) - ->get_flag(gkfs::filemap::OpenFile_flags::wronly)) { + if(CTX->file_map()->get(fd)->get_flag( + gkfs::filemap::OpenFile_flags::wronly)) { ret |= O_WRONLY; } - if (CTX->file_map()->get(fd) - ->get_flag(gkfs::filemap::OpenFile_flags::rdwr)) { + if(CTX->file_map()->get(fd)->get_flag( + gkfs::filemap::OpenFile_flags::rdwr)) { ret |= O_RDWR; } return ret; case F_SETFD: - LOG(DEBUG, "{}() [fd: {}, cmd: F_SETFD, FD_CLOEXEC: {}]", - __func__, fd, (arg & FD_CLOEXEC)); - CTX->file_map()->get(fd) - ->set_flag(gkfs::filemap::OpenFile_flags::cloexec, (arg & FD_CLOEXEC)); + LOG(DEBUG, "{}() [fd: {}, cmd: F_SETFD, FD_CLOEXEC: {}]", __func__, + fd, (arg & FD_CLOEXEC)); + CTX->file_map()->get(fd)->set_flag( + gkfs::filemap::OpenFile_flags::cloexec, (arg & FD_CLOEXEC)); return 0; default: - LOG(ERROR, "{}() unrecognized command {} on fd {}", - __func__, cmd, fd); + LOG(ERROR, "{}() unrecognized command {} on fd {}", __func__, cmd, + fd); return -ENOTSUP; } } -int hook_renameat(int olddfd, const char* oldname, - int newdfd, const char* newname, - unsigned int flags) { +int +hook_renameat(int olddfd, const char* oldname, int newdfd, const char* newname, + unsigned int flags) { - LOG(DEBUG, "{}() called with olddfd: {}, oldname: \"{}\", newfd: {}, " - "newname \"{}\", flags {}", + LOG(DEBUG, + "{}() called with olddfd: {}, oldname: \"{}\", newfd: {}, " + "newname \"{}\", flags {}", __func__, olddfd, oldname, newdfd, newname, flags); const char* oldpath_pass; std::string oldpath_resolved; - auto oldpath_status = CTX->relativize_fd_path(olddfd, oldname, oldpath_resolved); - switch (oldpath_status) { + auto oldpath_status = + CTX->relativize_fd_path(olddfd, oldname, oldpath_resolved); + switch(oldpath_status) { case gkfs::preload::RelativizeStatus::fd_unknown: oldpath_pass = oldname; break; @@ -769,8 +825,9 @@ int hook_renameat(int olddfd, const char* oldname, const char* newpath_pass; std::string newpath_resolved; - auto newpath_status = CTX->relativize_fd_path(newdfd, newname, newpath_resolved); - switch (newpath_status) { + auto newpath_status = + CTX->relativize_fd_path(newdfd, newname, newpath_resolved); + switch(newpath_status) { case gkfs::preload::RelativizeStatus::fd_unknown: newpath_pass = newname; break; @@ -791,39 +848,42 @@ int hook_renameat(int olddfd, const char* oldname, return -EINVAL; } - return syscall_no_intercept(SYS_renameat2, olddfd, oldpath_pass, newdfd, newpath_pass, flags); + return syscall_no_intercept(SYS_renameat2, olddfd, oldpath_pass, newdfd, + newpath_pass, flags); } -int hook_statfs(const char* path, struct statfs* buf) { +int +hook_statfs(const char* path, struct statfs* buf) { - LOG(DEBUG, "{}() called with path: \"{}\", buf: {}", - __func__, path, fmt::ptr(buf)); + LOG(DEBUG, "{}() called with path: \"{}\", buf: {}", __func__, path, + fmt::ptr(buf)); std::string rel_path; - if (CTX->relativize_path(path, rel_path)) { + if(CTX->relativize_path(path, rel_path)) { return with_errno(gkfs::syscall::gkfs_statfs(buf)); } return syscall_no_intercept(SYS_statfs, rel_path.c_str(), buf); } -int hook_fstatfs(unsigned int fd, struct statfs* buf) { +int +hook_fstatfs(unsigned int fd, struct statfs* buf) { - LOG(DEBUG, "{}() called with fd: {}, buf: {}", - __func__, fd, fmt::ptr(buf)); + LOG(DEBUG, "{}() called with fd: {}, buf: {}", __func__, fd, fmt::ptr(buf)); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { return with_errno(gkfs::syscall::gkfs_statfs(buf)); } return syscall_no_intercept(SYS_fstatfs, fd, buf); } -/* The function should broadcast a flush message (pmem_persist i.e.) if the application needs the capabilities*/ -int hook_fsync(unsigned int fd) { +/* The function should broadcast a flush message (pmem_persist i.e.) if the + * application needs the capabilities*/ +int +hook_fsync(unsigned int fd) { - LOG(DEBUG, "{}() called with fd: {}", - __func__, fd); + LOG(DEBUG, "{}() called with fd: {}", __func__, fd); - if (CTX->file_map()->exist(fd)) { + if(CTX->file_map()->exist(fd)) { errno = 0; return 0; } diff --git a/src/client/intercept.cpp b/src/client/intercept.cpp index 55bf4b5c0..1954350c7 100644 --- a/src/client/intercept.cpp +++ b/src/client/intercept.cpp @@ -34,15 +34,18 @@ namespace { thread_local bool reentrance_guard_flag; thread_local gkfs::syscall::info saved_syscall_info; -constexpr void save_current_syscall_info(gkfs::syscall::info info) { +constexpr void +save_current_syscall_info(gkfs::syscall::info info) { saved_syscall_info = info; } -constexpr void reset_current_syscall_info() { +constexpr void +reset_current_syscall_info() { saved_syscall_info = gkfs::syscall::no_info; } -inline gkfs::syscall::info get_current_syscall_info() { +inline gkfs::syscall::info +get_current_syscall_info() { return saved_syscall_info; } @@ -50,62 +53,58 @@ inline gkfs::syscall::info get_current_syscall_info() { /* * hook_internal -- interception hook for internal syscalls * - * This hook is basically used to keep track of file descriptors created - * internally by the library itself. This is important because some + * This hook is basically used to keep track of file descriptors created + * internally by the library itself. This is important because some * applications (e.g. ssh) may attempt to close all open file descriptors * which would leave the library internals in an inconsistent state. * We forward syscalls to the kernel but we keep track of any syscalls that may * create or destroy a file descriptor so that we can mark them as 'internal'. */ inline int -hook_internal(long syscall_number, - long arg0, long arg1, long arg2, - long arg3, long arg4, long arg5, - long* result) { +hook_internal(long syscall_number, long arg0, long arg1, long arg2, long arg3, + long arg4, long arg5, long* result) { #if defined(GKFS_ENABLE_LOGGING) && defined(GKFS_DEBUG_BUILD) - const long args[gkfs::syscall::MAX_ARGS] = { - arg0, arg1, arg2, arg3, arg4, arg5 - }; + const long args[gkfs::syscall::MAX_ARGS] = {arg0, arg1, arg2, + arg3, arg4, arg5}; #endif - LOG(SYSCALL, gkfs::syscall::from_internal_code | gkfs::syscall::to_hook | - gkfs::syscall::not_executed, syscall_number, args); + LOG(SYSCALL, + gkfs::syscall::from_internal_code | gkfs::syscall::to_hook | + gkfs::syscall::not_executed, + syscall_number, args); - switch (syscall_number) { + switch(syscall_number) { case SYS_open: - *result = syscall_no_intercept(syscall_number, - reinterpret_cast(arg0), - static_cast(arg1), - static_cast(arg2)); + *result = syscall_no_intercept( + syscall_number, reinterpret_cast(arg0), + static_cast(arg1), static_cast(arg2)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_creat: - *result = syscall_no_intercept(syscall_number, - reinterpret_cast(arg0), - O_WRONLY | O_CREAT | O_TRUNC, - static_cast(arg1)); + *result = syscall_no_intercept( + syscall_number, reinterpret_cast(arg0), + O_WRONLY | O_CREAT | O_TRUNC, static_cast(arg1)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_openat: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - static_cast(arg3)); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + reinterpret_cast(arg1), static_cast(arg2), + static_cast(arg3)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } @@ -115,7 +114,7 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, static_cast(arg0)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } @@ -125,7 +124,7 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, static_cast(arg0)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } @@ -135,7 +134,7 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, static_cast(arg0)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } @@ -146,19 +145,18 @@ hook_internal(long syscall_number, static_cast(arg0), static_cast(arg1)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_dup3: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - static_cast(arg1), - static_cast(arg2)); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + static_cast(arg1), static_cast(arg2)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } @@ -167,7 +165,7 @@ hook_internal(long syscall_number, case SYS_inotify_init: *result = syscall_no_intercept(syscall_number); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } @@ -177,81 +175,78 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, static_cast(arg0)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_perf_event_open: - *result = syscall_no_intercept(syscall_number, - reinterpret_cast(arg0), - static_cast(arg1), - static_cast(arg2), - static_cast(arg3), - static_cast(arg4)); + *result = syscall_no_intercept( + syscall_number, + reinterpret_cast(arg0), + static_cast(arg1), static_cast(arg2), + static_cast(arg3), static_cast(arg4)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_signalfd: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - reinterpret_cast(arg1)); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + reinterpret_cast(arg1)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_signalfd4: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_timerfd_create: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - static_cast(arg1)); + *result = + syscall_no_intercept(syscall_number, static_cast(arg0), + static_cast(arg1)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_socket: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - static_cast(arg1), - static_cast(arg2)); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + static_cast(arg1), static_cast(arg2)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_socketpair: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - static_cast(arg1), - static_cast(arg2), - reinterpret_cast(arg3)); - - if (*result >= 0) { - reinterpret_cast(arg3)[0] = - CTX->register_internal_fd(reinterpret_cast(arg3)[0]); - reinterpret_cast(arg3)[1] = - CTX->register_internal_fd(reinterpret_cast(arg3)[1]); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + static_cast(arg1), static_cast(arg2), + reinterpret_cast(arg3)); + + if(*result >= 0) { + reinterpret_cast(arg3)[0] = CTX->register_internal_fd( + reinterpret_cast(arg3)[0]); + reinterpret_cast(arg3)[1] = CTX->register_internal_fd( + reinterpret_cast(arg3)[1]); } break; @@ -260,11 +255,11 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, reinterpret_cast(arg0)); - if (*result >= 0) { - reinterpret_cast(arg0)[0] = - CTX->register_internal_fd(reinterpret_cast(arg0)[0]); - reinterpret_cast(arg0)[1] = - CTX->register_internal_fd(reinterpret_cast(arg0)[1]); + if(*result >= 0) { + reinterpret_cast(arg0)[0] = CTX->register_internal_fd( + reinterpret_cast(arg0)[0]); + reinterpret_cast(arg0)[1] = CTX->register_internal_fd( + reinterpret_cast(arg0)[1]); } break; @@ -274,11 +269,11 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, reinterpret_cast(arg0), static_cast(arg1)); - if (*result >= 0) { - reinterpret_cast(arg0)[0] = - CTX->register_internal_fd(reinterpret_cast(arg0)[0]); - reinterpret_cast(arg0)[1] = - CTX->register_internal_fd(reinterpret_cast(arg0)[1]); + if(*result >= 0) { + reinterpret_cast(arg0)[0] = CTX->register_internal_fd( + reinterpret_cast(arg0)[0]); + reinterpret_cast(arg0)[1] = CTX->register_internal_fd( + reinterpret_cast(arg0)[1]); } break; @@ -288,49 +283,50 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, static_cast(arg0)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_eventfd2: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - static_cast(arg1)); + *result = + syscall_no_intercept(syscall_number, static_cast(arg0), + static_cast(arg1)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_recvmsg: { - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = + syscall_no_intercept(syscall_number, static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); // The recvmsg() syscall can receive file descriptors from another // process that the kernel automatically adds to the client's fds // as if dup2 had been called. Whenever that happens, we need to // make sure that we register these additional fds as internal, or // we could inadvertently overwrite them - if (*result >= 0) { + if(*result >= 0) { auto* hdr = reinterpret_cast(arg1); struct cmsghdr* cmsg = CMSG_FIRSTHDR(hdr); - for (; cmsg != NULL; cmsg = CMSG_NXTHDR(hdr, cmsg)) { - if (cmsg->cmsg_type == SCM_RIGHTS) { + for(; cmsg != NULL; cmsg = CMSG_NXTHDR(hdr, cmsg)) { + if(cmsg->cmsg_type == SCM_RIGHTS) { - size_t nfd = cmsg->cmsg_len > CMSG_LEN(0) ? - (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int) : - 0; + size_t nfd = cmsg->cmsg_len > CMSG_LEN(0) + ? (cmsg->cmsg_len - CMSG_LEN(0)) / + sizeof(int) + : 0; - int* fds = - reinterpret_cast(CMSG_DATA(cmsg)); + int* fds = reinterpret_cast(CMSG_DATA(cmsg)); - for (size_t i = 0; i < nfd; ++i) { - LOG(DEBUG, "recvmsg() provided extra fd {}", fds[i]); + for(size_t i = 0; i < nfd; ++i) { + LOG(DEBUG, "recvmsg() provided extra fd {}", + fds[i]); // ensure we update the fds in cmsg // if they have been relocated @@ -344,25 +340,23 @@ hook_internal(long syscall_number, } case SYS_accept: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - reinterpret_cast(arg1), - reinterpret_cast(arg2)); + *result = syscall_no_intercept( + syscall_number, static_cast(arg0), + reinterpret_cast(arg1), + reinterpret_cast(arg2)); - if (*result >= 0) { + if(*result >= 0) { *result = CTX->register_internal_fd(*result); } break; case SYS_fcntl: - *result = syscall_no_intercept(syscall_number, - static_cast(arg0), - static_cast(arg1), - arg2); + *result = + syscall_no_intercept(syscall_number, static_cast(arg0), + static_cast(arg1), arg2); - if (*result >= 0 && - (static_cast(arg1) == F_DUPFD || - static_cast(arg1) == F_DUPFD_CLOEXEC)) { + if(*result >= 0 && (static_cast(arg1) == F_DUPFD || + static_cast(arg1) == F_DUPFD_CLOEXEC)) { *result = CTX->register_internal_fd(*result); } break; @@ -371,28 +365,27 @@ hook_internal(long syscall_number, *result = syscall_no_intercept(syscall_number, static_cast(arg0)); - if (*result == 0) { + if(*result == 0) { CTX->unregister_internal_fd(arg0); } break; default: // ignore any other syscalls, i.e.: pass them on to the kernel - // (syscalls forwarded to the kernel that return are logged in + // (syscalls forwarded to the kernel that return are logged in // hook_forwarded_syscall()) - ::save_current_syscall_info( - gkfs::syscall::from_internal_code | - gkfs::syscall::to_kernel | - gkfs::syscall::not_executed); + ::save_current_syscall_info(gkfs::syscall::from_internal_code | + gkfs::syscall::to_kernel | + gkfs::syscall::not_executed); return gkfs::syscall::forward_to_kernel; } - LOG(SYSCALL, gkfs::syscall::from_internal_code | - gkfs::syscall::to_hook | gkfs::syscall::executed, + LOG(SYSCALL, + gkfs::syscall::from_internal_code | gkfs::syscall::to_hook | + gkfs::syscall::executed, syscall_number, args, *result); return gkfs::syscall::hooked; - } /* @@ -400,61 +393,54 @@ hook_internal(long syscall_number, * * This hook is used to implement any application filesystem-related syscalls. */ -inline -int hook(long syscall_number, - long arg0, long arg1, long arg2, - long arg3, long arg4, long arg5, - long* result) { +inline int +hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, + long arg5, long* result) { #if defined(GKFS_ENABLE_LOGGING) && defined(GKFS_DEBUG_BUILD) - const long args[gkfs::syscall::MAX_ARGS] = { - arg0, arg1, arg2, arg3, arg4, arg5 - }; + const long args[gkfs::syscall::MAX_ARGS] = {arg0, arg1, arg2, + arg3, arg4, arg5}; #endif - LOG(SYSCALL, gkfs::syscall::from_external_code | - gkfs::syscall::to_hook | gkfs::syscall::not_executed, + LOG(SYSCALL, + gkfs::syscall::from_external_code | gkfs::syscall::to_hook | + gkfs::syscall::not_executed, syscall_number, args); - switch (syscall_number) { + switch(syscall_number) { case SYS_execve: - *result = syscall_no_intercept(syscall_number, - reinterpret_cast(arg0), - reinterpret_cast(arg1), - reinterpret_cast(arg2)); + *result = syscall_no_intercept( + syscall_number, reinterpret_cast(arg0), + reinterpret_cast(arg1), + reinterpret_cast(arg2)); break; #ifdef SYS_execveat case SYS_execveat: - *result = syscall_no_intercept(syscall_number, - arg0, - reinterpret_cast(arg1), - reinterpret_cast(arg2), - reinterpret_cast(arg3), - arg4); + *result = syscall_no_intercept( + syscall_number, arg0, reinterpret_cast(arg1), + reinterpret_cast(arg2), + reinterpret_cast(arg3), arg4); break; #endif case SYS_open: - *result = gkfs::hook::hook_openat(AT_FDCWD, - reinterpret_cast(arg0), - static_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_openat( + AT_FDCWD, reinterpret_cast(arg0), + static_cast(arg1), static_cast(arg2)); break; case SYS_creat: - *result = gkfs::hook::hook_openat(AT_FDCWD, - reinterpret_cast(arg0), - O_WRONLY | O_CREAT | O_TRUNC, - static_cast(arg1)); + *result = gkfs::hook::hook_openat( + AT_FDCWD, reinterpret_cast(arg0), + O_WRONLY | O_CREAT | O_TRUNC, static_cast(arg1)); break; case SYS_openat: - *result = gkfs::hook::hook_openat(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - static_cast(arg3)); + *result = gkfs::hook::hook_openat( + static_cast(arg0), reinterpret_cast(arg1), + static_cast(arg2), static_cast(arg3)); break; case SYS_close: @@ -462,35 +448,37 @@ int hook(long syscall_number, break; case SYS_stat: - *result = gkfs::hook::hook_stat(reinterpret_cast(arg0), - reinterpret_cast(arg1)); + *result = + gkfs::hook::hook_stat(reinterpret_cast(arg0), + reinterpret_cast(arg1)); break; #ifdef STATX_TYPE case SYS_statx: - *result = gkfs::hook::hook_statx(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - static_cast(arg3), - reinterpret_cast(arg4)); + *result = gkfs::hook::hook_statx( + static_cast(arg0), reinterpret_cast(arg1), + static_cast(arg2), static_cast(arg3), + reinterpret_cast(arg4)); break; #endif case SYS_lstat: - *result = gkfs::hook::hook_lstat(reinterpret_cast(arg0), - reinterpret_cast(arg1)); + *result = gkfs::hook::hook_lstat( + reinterpret_cast(arg0), + reinterpret_cast(arg1)); break; case SYS_fstat: - *result = gkfs::hook::hook_fstat(static_cast(arg0), - reinterpret_cast(arg1)); + *result = gkfs::hook::hook_fstat( + static_cast(arg0), + reinterpret_cast(arg1)); break; case SYS_newfstatat: - *result = gkfs::hook::hook_fstatat(static_cast(arg0), - reinterpret_cast(arg1), - reinterpret_cast(arg2), - static_cast(arg3)); + *result = gkfs::hook::hook_fstatat( + static_cast(arg0), reinterpret_cast(arg1), + reinterpret_cast(arg2), + static_cast(arg3)); break; case SYS_read: @@ -507,84 +495,89 @@ int hook(long syscall_number, break; case SYS_readv: - *result = gkfs::hook::hook_readv(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_readv( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_preadv: - *result = gkfs::hook::hook_preadv(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - static_cast(arg3), - static_cast(arg4)); + *result = gkfs::hook::hook_preadv( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2), + static_cast(arg3), + static_cast(arg4)); break; case SYS_pwrite64: - *result = gkfs::hook::hook_pwrite(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - static_cast(arg3)); + *result = gkfs::hook::hook_pwrite( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2), static_cast(arg3)); break; case SYS_write: - *result = gkfs::hook::hook_write(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = + gkfs::hook::hook_write(static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_writev: - *result = gkfs::hook::hook_writev(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_writev( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_pwritev: - *result = gkfs::hook::hook_pwritev(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - static_cast(arg3), - static_cast(arg4)); + *result = gkfs::hook::hook_pwritev( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2), + static_cast(arg3), + static_cast(arg4)); break; case SYS_unlink: - *result = gkfs::hook::hook_unlinkat(AT_FDCWD, - reinterpret_cast(arg0), - 0); + *result = gkfs::hook::hook_unlinkat( + AT_FDCWD, reinterpret_cast(arg0), 0); break; case SYS_unlinkat: - *result = gkfs::hook::hook_unlinkat(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_unlinkat( + static_cast(arg0), reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_rmdir: - *result = gkfs::hook::hook_unlinkat(AT_FDCWD, - reinterpret_cast(arg0), - AT_REMOVEDIR); + *result = gkfs::hook::hook_unlinkat( + AT_FDCWD, reinterpret_cast(arg0), + AT_REMOVEDIR); break; case SYS_symlink: - *result = gkfs::hook::hook_symlinkat(reinterpret_cast(arg0), - AT_FDCWD, - reinterpret_cast(arg1)); + *result = gkfs::hook::hook_symlinkat( + reinterpret_cast(arg0), AT_FDCWD, + reinterpret_cast(arg1)); break; case SYS_symlinkat: - *result = gkfs::hook::hook_symlinkat(reinterpret_cast(arg0), - static_cast(arg1), - reinterpret_cast(arg2)); + *result = gkfs::hook::hook_symlinkat( + reinterpret_cast(arg0), static_cast(arg1), + reinterpret_cast(arg2)); break; case SYS_access: - *result = gkfs::hook::hook_access(reinterpret_cast(arg0), - static_cast(arg1)); + *result = + gkfs::hook::hook_access(reinterpret_cast(arg0), + static_cast(arg1)); break; case SYS_faccessat: - *result = gkfs::hook::hook_faccessat(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_faccessat( + static_cast(arg0), reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_lseek: @@ -594,13 +587,15 @@ int hook(long syscall_number, break; case SYS_truncate: - *result = gkfs::hook::hook_truncate(reinterpret_cast(arg0), - static_cast(arg1)); + *result = gkfs::hook::hook_truncate( + reinterpret_cast(arg0), + static_cast(arg1)); break; case SYS_ftruncate: - *result = gkfs::hook::hook_ftruncate(static_cast(arg0), - static_cast(arg1)); + *result = gkfs::hook::hook_ftruncate( + static_cast(arg0), + static_cast(arg1)); break; case SYS_dup: @@ -619,27 +614,30 @@ int hook(long syscall_number, break; case SYS_getdents: - *result = gkfs::hook::hook_getdents(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_getdents( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_getdents64: - *result = gkfs::hook::hook_getdents64(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_getdents64( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_mkdirat: - *result = gkfs::hook::hook_mkdirat(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_mkdirat( + static_cast(arg0), + reinterpret_cast(arg1), + static_cast(arg2)); break; case SYS_mkdir: - *result = gkfs::hook::hook_mkdirat(AT_FDCWD, - reinterpret_cast(arg0), - static_cast(arg1)); + *result = gkfs::hook::hook_mkdirat( + AT_FDCWD, reinterpret_cast(arg0), + static_cast(arg1)); break; case SYS_chmod: @@ -660,7 +658,8 @@ int hook(long syscall_number, break; case SYS_chdir: - *result = gkfs::hook::hook_chdir(reinterpret_cast(arg0)); + *result = + gkfs::hook::hook_chdir(reinterpret_cast(arg0)); break; case SYS_fchdir: @@ -673,17 +672,15 @@ int hook(long syscall_number, break; case SYS_readlink: - *result = gkfs::hook::hook_readlinkat(AT_FDCWD, - reinterpret_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2)); + *result = gkfs::hook::hook_readlinkat( + AT_FDCWD, reinterpret_cast(arg0), + reinterpret_cast(arg1), static_cast(arg2)); break; case SYS_readlinkat: - *result = gkfs::hook::hook_readlinkat(static_cast(arg0), - reinterpret_cast(arg1), - reinterpret_cast(arg2), - static_cast(arg3)); + *result = gkfs::hook::hook_readlinkat( + static_cast(arg0), reinterpret_cast(arg1), + reinterpret_cast(arg2), static_cast(arg3)); break; case SYS_fcntl: @@ -693,37 +690,35 @@ int hook(long syscall_number, break; case SYS_rename: - *result = gkfs::hook::hook_renameat(AT_FDCWD, - reinterpret_cast(arg0), - AT_FDCWD, - reinterpret_cast(arg1), - 0); + *result = gkfs::hook::hook_renameat( + AT_FDCWD, reinterpret_cast(arg0), AT_FDCWD, + reinterpret_cast(arg1), 0); break; case SYS_renameat: - *result = gkfs::hook::hook_renameat(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - reinterpret_cast(arg3), - 0); + *result = gkfs::hook::hook_renameat( + static_cast(arg0), reinterpret_cast(arg1), + static_cast(arg2), reinterpret_cast(arg3), + 0); break; case SYS_renameat2: - *result = gkfs::hook::hook_renameat(static_cast(arg0), - reinterpret_cast(arg1), - static_cast(arg2), - reinterpret_cast(arg3), - static_cast(arg4)); + *result = gkfs::hook::hook_renameat( + static_cast(arg0), reinterpret_cast(arg1), + static_cast(arg2), reinterpret_cast(arg3), + static_cast(arg4)); break; case SYS_fstatfs: - *result = gkfs::hook::hook_fstatfs(static_cast(arg0), - reinterpret_cast(arg1)); + *result = gkfs::hook::hook_fstatfs( + static_cast(arg0), + reinterpret_cast(arg1)); break; case SYS_statfs: - *result = gkfs::hook::hook_statfs(reinterpret_cast(arg0), - reinterpret_cast(arg1)); + *result = gkfs::hook::hook_statfs( + reinterpret_cast(arg0), + reinterpret_cast(arg1)); break; case SYS_fsync: @@ -732,96 +727,74 @@ int hook(long syscall_number, default: // ignore any other syscalls, i.e.: pass them on to the kernel - // (syscalls forwarded to the kernel that return are logged in + // (syscalls forwarded to the kernel that return are logged in // hook_forwarded_syscall()) - ::save_current_syscall_info( - gkfs::syscall::from_external_code | - gkfs::syscall::to_kernel | - gkfs::syscall::not_executed); + ::save_current_syscall_info(gkfs::syscall::from_external_code | + gkfs::syscall::to_kernel | + gkfs::syscall::not_executed); return gkfs::syscall::forward_to_kernel; } - LOG(SYSCALL, gkfs::syscall::from_external_code | - gkfs::syscall::to_hook | gkfs::syscall::executed, + LOG(SYSCALL, + gkfs::syscall::from_external_code | gkfs::syscall::to_hook | + gkfs::syscall::executed, syscall_number, args, *result); return gkfs::syscall::hooked; } void -hook_forwarded_syscall(long syscall_number, - long arg0, long arg1, long arg2, - long arg3, long arg4, long arg5, - long result) { +hook_forwarded_syscall(long syscall_number, long arg0, long arg1, long arg2, + long arg3, long arg4, long arg5, long result) { - if (::get_current_syscall_info() == gkfs::syscall::no_info) { + if(::get_current_syscall_info() == gkfs::syscall::no_info) { return; } #if defined(GKFS_ENABLE_LOGGING) && defined(GKFS_DEBUG_BUILD) - const long args[gkfs::syscall::MAX_ARGS] = { - arg0, arg1, arg2, arg3, arg4, arg5 - }; + const long args[gkfs::syscall::MAX_ARGS] = {arg0, arg1, arg2, + arg3, arg4, arg5}; #endif - LOG(SYSCALL, - ::get_current_syscall_info() | - gkfs::syscall::executed, + LOG(SYSCALL, ::get_current_syscall_info() | gkfs::syscall::executed, syscall_number, args, result); ::reset_current_syscall_info(); } void -hook_clone_at_child(unsigned long flags, - void* child_stack, - int* ptid, - int* ctid, - long newtls) { +hook_clone_at_child(unsigned long flags, void* child_stack, int* ptid, + int* ctid, long newtls) { #if defined(GKFS_ENABLE_LOGGING) && defined(GKFS_DEBUG_BUILD) const long args[gkfs::syscall::MAX_ARGS] = { - static_cast(flags), - reinterpret_cast(child_stack), - reinterpret_cast(ptid), - reinterpret_cast(ctid), - static_cast(newtls), - 0}; + static_cast(flags), reinterpret_cast(child_stack), + reinterpret_cast(ptid), reinterpret_cast(ctid), + static_cast(newtls), 0}; #endif reentrance_guard_flag = true; - LOG(SYSCALL, - ::get_current_syscall_info() | - gkfs::syscall::executed, + LOG(SYSCALL, ::get_current_syscall_info() | gkfs::syscall::executed, SYS_clone, args, 0); reentrance_guard_flag = false; } void -hook_clone_at_parent(unsigned long flags, - void* child_stack, - int* ptid, - int* ctid, - long newtls, - long returned_pid) { +hook_clone_at_parent(unsigned long flags, void* child_stack, int* ptid, + int* ctid, long newtls, long returned_pid) { #if defined(GKFS_ENABLE_LOGGING) && defined(GKFS_DEBUG_BUILD) const long args[gkfs::syscall::MAX_ARGS] = { - static_cast(flags), - reinterpret_cast(child_stack), - reinterpret_cast(ptid), - reinterpret_cast(ctid), - static_cast(newtls), - 0}; + static_cast(flags), reinterpret_cast(child_stack), + reinterpret_cast(ptid), reinterpret_cast(ctid), + static_cast(newtls), 0}; #endif reentrance_guard_flag = true; - LOG(SYSCALL, - ::get_current_syscall_info() | - gkfs::syscall::executed, + LOG(SYSCALL, ::get_current_syscall_info() | gkfs::syscall::executed, SYS_clone, args, returned_pid); reentrance_guard_flag = false; @@ -833,18 +806,16 @@ namespace gkfs { namespace preload { int -internal_hook_guard_wrapper(long syscall_number, - long arg0, long arg1, long arg2, - long arg3, long arg4, long arg5, +internal_hook_guard_wrapper(long syscall_number, long arg0, long arg1, + long arg2, long arg3, long arg4, long arg5, long* syscall_return_value) { assert(CTX->interception_enabled()); - if (reentrance_guard_flag) { - ::save_current_syscall_info( - gkfs::syscall::from_internal_code | - gkfs::syscall::to_kernel | - gkfs::syscall::not_executed); + if(reentrance_guard_flag) { + ::save_current_syscall_info(gkfs::syscall::from_internal_code | + gkfs::syscall::to_kernel | + gkfs::syscall::not_executed); return gkfs::syscall::forward_to_kernel; } @@ -852,9 +823,8 @@ internal_hook_guard_wrapper(long syscall_number, reentrance_guard_flag = true; int oerrno = errno; - was_hooked = hook_internal(syscall_number, - arg0, arg1, arg2, arg3, arg4, arg5, - syscall_return_value); + was_hooked = hook_internal(syscall_number, arg0, arg1, arg2, arg3, arg4, + arg5, syscall_return_value); errno = oerrno; reentrance_guard_flag = false; @@ -877,8 +847,7 @@ internal_hook_guard_wrapper(long syscall_number, * kernel. */ int -hook_guard_wrapper(long syscall_number, - long arg0, long arg1, long arg2, +hook_guard_wrapper(long syscall_number, long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long* syscall_return_value) { @@ -886,19 +855,17 @@ hook_guard_wrapper(long syscall_number, int was_hooked = 0; - if (reentrance_guard_flag) { + if(reentrance_guard_flag) { int oerrno = errno; - was_hooked = hook_internal(syscall_number, - arg0, arg1, arg2, arg3, arg4, arg5, - syscall_return_value); + was_hooked = hook_internal(syscall_number, arg0, arg1, arg2, arg3, arg4, + arg5, syscall_return_value); errno = oerrno; return was_hooked; } reentrance_guard_flag = true; int oerrno = errno; - was_hooked = ::hook(syscall_number, - arg0, arg1, arg2, arg3, arg4, arg5, + was_hooked = ::hook(syscall_number, arg0, arg1, arg2, arg3, arg4, arg5, syscall_return_value); errno = oerrno; reentrance_guard_flag = false; @@ -906,7 +873,8 @@ hook_guard_wrapper(long syscall_number, return was_hooked; } -void start_self_interception() { +void +start_self_interception() { LOG(DEBUG, "Enabling syscall interception for self"); @@ -916,7 +884,8 @@ void start_self_interception() { intercept_hook_point_clone_parent = hook_clone_at_parent; } -void start_interception() { +void +start_interception() { assert(CTX->interception_enabled()); @@ -929,7 +898,8 @@ void start_interception() { intercept_hook_point_clone_parent = hook_clone_at_parent; } -void stop_interception() { +void +stop_interception() { assert(CTX->interception_enabled()); LOG(DEBUG, "Disabling syscall interception for client process"); diff --git a/src/client/logging.cpp b/src/client/logging.cpp index 207ab935e..9f1e099aa 100644 --- a/src/client/logging.cpp +++ b/src/client/logging.cpp @@ -38,14 +38,11 @@ struct opt_info { const log_level mask_; }; -#define STR_AND_LEN(strbuf) \ - strbuf, sizeof(strbuf) - 1 +#define STR_AND_LEN(strbuf) strbuf, sizeof(strbuf) - 1 static const auto constexpr debug_opts = util::make_array( - opt_info{STR_AND_LEN("none"), - {"don't print any messages"}, - log::none}, + opt_info{STR_AND_LEN("none"), {"don't print any messages"}, log::none}, #ifdef GKFS_DEBUG_BUILD @@ -61,30 +58,25 @@ static const auto constexpr debug_opts = util::make_array( {"Trace system calls: print the name of each system call", "and its arguments. All system calls are printed before ", "being executed and therefore their return values are not", - "available in the log", - "[ default: off ]"}, + "available in the log", "[ default: off ]"}, log::syscall_at_entry}, #endif // !GKFS_DEBUG_BUILD opt_info{STR_AND_LEN("info"), - {"Print information messages", - "[ default: on ]"}, + {"Print information messages", "[ default: on ]"}, log::info}, opt_info{STR_AND_LEN("critical"), - {"Print critical errors", - "[ default: on ]"}, + {"Print critical errors", "[ default: on ]"}, log::critical}, opt_info{STR_AND_LEN("errors"), - {"Print errors", - "[ default: on ]"}, + {"Print errors", "[ default: on ]"}, log::error}, opt_info{STR_AND_LEN("warnings"), - {"Print warnings", - "[ default: on ]"}, + {"Print warnings", "[ default: on ]"}, log::warning}, opt_info{STR_AND_LEN("hermes"), @@ -100,8 +92,7 @@ static const auto constexpr debug_opts = util::make_array( #ifdef GKFS_DEBUG_BUILD opt_info{STR_AND_LEN("debug"), - {"Print debug messages", - "[ default: off ]"}, + {"Print debug messages", "[ default: off ]"}, log::debug}, opt_info{STR_AND_LEN("most"), @@ -116,8 +107,7 @@ static const auto constexpr debug_opts = util::make_array( opt_info{STR_AND_LEN("help"), {"Print this help message and exit."}, - log::help} -); + log::help}); static const auto constexpr max_debug_opt_length = sizeof("syscalls_at_entry") - 1; @@ -127,7 +117,7 @@ static const auto constexpr max_help_text_rows = /** * process_log_options -- process the string given as parameter to determine - * which debugging options are enabled and return a + * which debugging options are enabled and return a * log_level describing them */ log_level @@ -137,7 +127,7 @@ process_log_options(const std::string gkfs_debug) { (void) gkfs_debug; logger::log_message(stdout, "warning: logging options ignored: " - "logging support was disabled in this build"); + "logging support was disabled in this build"); return log::none; #endif // ! GKFS_ENABLE_LOGGING @@ -149,43 +139,47 @@ process_log_options(const std::string gkfs_debug) { // skip separating white spaces and commas boost::split(tokens, gkfs_debug, boost::is_any_of(" ,")); - for (const auto& t : tokens) { + for(const auto& t : tokens) { bool is_known = false; - for (const auto& opt : debug_opts) { + for(const auto& opt : debug_opts) { // none disables any future and previous flags observed - if (t == "none") { + if(t == "none") { return log::none; } - if (t == opt.name_) { + if(t == opt.name_) { dm |= opt.mask_; is_known = true; break; } } - if (!is_known) { - logger::log_message(stdout, "warning: logging option '{}' unknown; " - "try {}=help", t, gkfs::env::LOG); + if(!is_known) { + logger::log_message(stdout, + "warning: logging option '{}' unknown; " + "try {}=help", + t, gkfs::env::LOG); } } - if (!!(dm & log::help)) { - logger::log_message(stdout, "Valid options for the {} " - "environment variable are:\n", gkfs::env::LOG); + if(!!(dm & log::help)) { + logger::log_message(stdout, + "Valid options for the {} " + "environment variable are:\n", + gkfs::env::LOG); - for (const auto& opt : debug_opts) { + for(const auto& opt : debug_opts) { const auto padding = max_debug_opt_length - opt.length_ + 2; - logger::log_message(stdout, " {}{:>{}}{}", opt.name_, "", - padding, opt.help_text_[0]); + logger::log_message(stdout, " {}{:>{}}{}", opt.name_, "", padding, + opt.help_text_[0]); - for (auto i = 1lu; i < max_help_text_rows; ++i) { - if (opt.help_text_[i][0] != 0) { + for(auto i = 1lu; i < max_help_text_rows; ++i) { + if(opt.help_text_[i][0] != 0) { logger::log_message(stdout, " {:>{}}{}", "", max_debug_opt_length + 2, opt.help_text_[i]); @@ -195,11 +189,13 @@ process_log_options(const std::string gkfs_debug) { logger::log_message(stdout, ""); } - logger::log_message(stdout, "\n" - "To direct the logging output into a file " - "instead of standard output\n" - "a filename can be specified using the " - "{} environment variable.", gkfs::env::LOG_OUTPUT); + logger::log_message(stdout, + "\n" + "To direct the logging output into a file " + "instead of standard output\n" + "a filename can be specified using the " + "{} environment variable.", + gkfs::env::LOG_OUTPUT); ::_exit(0); } @@ -214,7 +210,7 @@ process_log_filter(const std::string& log_filter) { std::bitset<512> filtered_syscalls; std::vector tokens; - if (log_filter.empty()) { + if(log_filter.empty()) { return filtered_syscalls; } @@ -222,12 +218,14 @@ process_log_filter(const std::string& log_filter) { boost::split(tokens, log_filter, [](char c) { return c == ' ' || c == ','; }); - for (const auto& t : tokens) { + for(const auto& t : tokens) { const auto sc = syscall::lookup_by_name(t); - if (std::strcmp(sc.name(), "unknown_syscall") == 0) { - logger::log_message(stdout, "warning: system call '{}' unknown; " - "will not filter", t); + if(std::strcmp(sc.name(), "unknown_syscall") == 0) { + logger::log_message(stdout, + "warning: system call '{}' unknown; " + "will not filter", + t); continue; } @@ -239,16 +237,13 @@ process_log_filter(const std::string& log_filter) { #endif // GKFS_DEBUG_BUILD -logger::logger(const std::string& opts, - const std::string& path, - bool trunc +logger::logger(const std::string& opts, const std::string& path, bool trunc #ifdef GKFS_DEBUG_BUILD - , - const std::string& filter, - int verbosity + , + const std::string& filter, int verbosity #endif -) : - timezone_(nullptr) { + ) + : timezone_(nullptr) { /* use stderr by default */ log_fd_ = 2; @@ -259,22 +254,24 @@ logger::logger(const std::string& opts, debug_verbosity_ = verbosity; #endif - if (!path.empty()) { + if(!path.empty()) { int flags = O_CREAT | O_RDWR | O_APPEND | O_TRUNC; - if (!trunc) { + if(!trunc) { flags &= ~O_TRUNC; } // we use ::open() here rather than ::syscall_no_intercept(SYS_open) - // because we want the call to be intercepted by our hooks, which + // because we want the call to be intercepted by our hooks, which // allows us to categorize the resulting fd as 'internal' and // relocate it to our private range int fd = ::open(path.c_str(), flags, 0600); - if (fd == -1) { - log(gkfs::log::error, __func__, __LINE__, "Failed to open log " - "file '{}'. Logging will fall back to stderr", path); + if(fd == -1) { + log(gkfs::log::error, __func__, __LINE__, + "Failed to open log " + "file '{}'. Logging will fall back to stderr", + path); return; } @@ -303,8 +300,7 @@ logger::logger(const std::string& opts, using namespace date; timezone_->get_info(date::sys_days{January / 1 / 1970}); #endif // GKFS_DEBUG_BUILD - } - catch (const std::exception& ex) { + } catch(const std::exception& ex) { // if timezone initialization fails, setting timezone_ to nullptr // makes format_timestamp_to() default to producing epoch timestamps timezone_ = nullptr; @@ -314,11 +310,10 @@ logger::logger(const std::string& opts, const auto log_hermes_message = [](const std::string& msg, hermes::log::level l, int severity, const std::string& file, const std::string& func, int lineno) { - const auto name = [](hermes::log::level l, int severity) { using namespace std::string_literals; - switch (l) { + switch(l) { case hermes::log::info: return "info"s; case hermes::log::warning: @@ -339,54 +334,53 @@ logger::logger(const std::string& opts, #ifdef GKFS_DEBUG_BUILD const auto log_hermes_debug_message = - [this](const std::string& msg, hermes::log::level l, - int severity, const std::string& file, - const std::string& func, int lineno) { - - if (severity > debug_verbosity_) { + [this](const std::string& msg, hermes::log::level l, int severity, + const std::string& file, const std::string& func, + int lineno) { + if(severity > debug_verbosity_) { return; } LOG(HERMES, "[debug{}] <{}():{}> {}", - (severity == 0 ? "" : std::to_string(severity + 1)), - func, lineno, msg); + (severity == 0 ? "" : std::to_string(severity + 1)), func, + lineno, msg); }; #endif // GKFS_DEBUG_BUILD - const auto log_hg_message = - [](const std::string& msg, hermes::log::level l, int severity, - const std::string& file, const std::string& func, int lineno) { - - (void) l; + const auto log_hg_message = [](const std::string& msg, hermes::log::level l, + int severity, const std::string& file, + const std::string& func, int lineno) { + (void) l; - // mercury message might contain one or more sub-messages - // separated by '\n' - std::vector sub_msgs; - boost::split(sub_msgs, msg, boost::is_any_of("\n"), boost::token_compress_on); + // mercury message might contain one or more sub-messages + // separated by '\n' + std::vector sub_msgs; + boost::split(sub_msgs, msg, boost::is_any_of("\n"), + boost::token_compress_on); - for (const auto& m : sub_msgs) { - if (!m.empty()) { - LOG(MERCURY, "{}", m); - } - } - }; - - // register log callbacks into hermes so that we can manage - // both its and mercury's log messages - hermes::log::logger::register_callback( - hermes::log::info, log_hermes_message); - hermes::log::logger::register_callback( - hermes::log::warning, log_hermes_message); - hermes::log::logger::register_callback( - hermes::log::error, log_hermes_message); - hermes::log::logger::register_callback( - hermes::log::fatal, log_hermes_message); + for(const auto& m : sub_msgs) { + if(!m.empty()) { + LOG(MERCURY, "{}", m); + } + } + }; + + // register log callbacks into hermes so that we can manage + // both its and mercury's log messages + hermes::log::logger::register_callback(hermes::log::info, + log_hermes_message); + hermes::log::logger::register_callback(hermes::log::warning, + log_hermes_message); + hermes::log::logger::register_callback(hermes::log::error, + log_hermes_message); + hermes::log::logger::register_callback(hermes::log::fatal, + log_hermes_message); #ifdef GKFS_DEBUG_BUILD - hermes::log::logger::register_callback( - hermes::log::debug, log_hermes_debug_message); + hermes::log::logger::register_callback(hermes::log::debug, + log_hermes_debug_message); #endif - hermes::log::logger::register_callback( - hermes::log::mercury, log_hg_message); + hermes::log::logger::register_callback(hermes::log::mercury, + log_hg_message); #endif // GKFS_ENABLE_LOGGING } @@ -396,59 +390,57 @@ logger::~logger() { } void -logger::log_syscall(syscall::info info, - const long syscall_number, - const long args[6], - boost::optional result) { +logger::log_syscall(syscall::info info, const long syscall_number, + const long args[6], boost::optional result) { const bool log_syscall_entry = !!(log::syscall_at_entry & log_mask_); const bool log_syscall_result = !!(log::syscall & log_mask_); // log the syscall if and only if logging for syscalls is enabled - if (!log_syscall_entry && !log_syscall_result) { + if(!log_syscall_entry && !log_syscall_result) { return; } #ifdef GKFS_DEBUG_BUILD - if (filtered_syscalls_[syscall_number]) { + if(filtered_syscalls_[syscall_number]) { return; } #endif // log the syscall even if we don't have information on it, since it may - // be important to the user (we assume that the syscall has completed + // be important to the user (we assume that the syscall has completed // though) - if (info == syscall::no_info) { + if(info == syscall::no_info) { goto print_syscall; } // log the syscall entry if the syscall may not return (e.g. execve) or - // if we are sure that it won't ever return (e.g. exit), even if + // if we are sure that it won't ever return (e.g. exit), even if // log::syscall_at_entry is disabled - if (syscall::may_not_return(syscall_number) || - syscall::never_returns(syscall_number)) { + if(syscall::may_not_return(syscall_number) || + syscall::never_returns(syscall_number)) { goto print_syscall; } - if (log_syscall_entry && syscall::execution_is_pending(info)) { + if(log_syscall_entry && syscall::execution_is_pending(info)) { goto print_syscall; } - if (log_syscall_result && !syscall::execution_is_pending(info)) { + if(log_syscall_result && !syscall::execution_is_pending(info)) { goto print_syscall; } return; - print_syscall: +print_syscall: static_buffer buffer; detail::format_timestamp_to(buffer, timezone_); detail::format_syscall_info_to(buffer, info); - if (result) { + if(result) { syscall::decode(buffer, syscall_number, args, *result); } else { syscall::decode(buffer, syscall_number, args); @@ -461,4 +453,3 @@ logger::log_syscall(syscall::info info, } // namespace log } // namespace gkfs - diff --git a/src/client/open_dir.cpp b/src/client/open_dir.cpp index 9deabe86f..f79316dc2 100644 --- a/src/client/open_dir.cpp +++ b/src/client/open_dir.cpp @@ -18,33 +18,36 @@ namespace gkfs { namespace filemap { -DirEntry::DirEntry(const std::string& name, const FileType type) : - name_(name), type_(type) { -} +DirEntry::DirEntry(const std::string& name, const FileType type) + : name_(name), type_(type) {} -const std::string& DirEntry::name() { +const std::string& +DirEntry::name() { return name_; } -FileType DirEntry::type() { +FileType +DirEntry::type() { return type_; } -OpenDir::OpenDir(const std::string& path) : - OpenFile(path, 0, FileType::directory) { -} +OpenDir::OpenDir(const std::string& path) + : OpenFile(path, 0, FileType::directory) {} -void OpenDir::add(const std::string& name, const FileType& type) { +void +OpenDir::add(const std::string& name, const FileType& type) { entries.push_back(DirEntry(name, type)); } -const DirEntry& OpenDir::getdent(unsigned int pos) { +const DirEntry& +OpenDir::getdent(unsigned int pos) { return entries.at(pos); } -size_t OpenDir::size() { +size_t +OpenDir::size() { return entries.size(); } diff --git a/src/client/open_file_map.cpp b/src/client/open_file_map.cpp index d06a2e3d2..f88b3eccb 100644 --- a/src/client/open_file_map.cpp +++ b/src/client/open_file_map.cpp @@ -27,132 +27,145 @@ using namespace std; namespace gkfs { namespace filemap { -OpenFile::OpenFile(const string& path, const int flags, FileType type) : - type_(type), - path_(path) { +OpenFile::OpenFile(const string& path, const int flags, FileType type) + : type_(type), path_(path) { // set flags to OpenFile - if (flags & O_CREAT) + if(flags & O_CREAT) flags_[gkfs::util::to_underlying(OpenFile_flags::creat)] = true; - if (flags & O_APPEND) + if(flags & O_APPEND) flags_[gkfs::util::to_underlying(OpenFile_flags::append)] = true; - if (flags & O_TRUNC) + if(flags & O_TRUNC) flags_[gkfs::util::to_underlying(OpenFile_flags::trunc)] = true; - if (flags & O_RDONLY) + if(flags & O_RDONLY) flags_[gkfs::util::to_underlying(OpenFile_flags::rdonly)] = true; - if (flags & O_WRONLY) + if(flags & O_WRONLY) flags_[gkfs::util::to_underlying(OpenFile_flags::wronly)] = true; - if (flags & O_RDWR) + if(flags & O_RDWR) flags_[gkfs::util::to_underlying(OpenFile_flags::rdwr)] = true; pos_ = 0; // If O_APPEND flag is used, it will be used before each write. } -OpenFileMap::OpenFileMap() : - fd_idx(10000), - fd_validation_needed(false) {} +OpenFileMap::OpenFileMap() : fd_idx(10000), fd_validation_needed(false) {} -string OpenFile::path() const { +string +OpenFile::path() const { return path_; } -void OpenFile::path(const string& path) { +void +OpenFile::path(const string& path) { OpenFile::path_ = path; } -unsigned long OpenFile::pos() { +unsigned long +OpenFile::pos() { lock_guard lock(pos_mutex_); return pos_; } -void OpenFile::pos(unsigned long pos) { +void +OpenFile::pos(unsigned long pos) { lock_guard lock(pos_mutex_); OpenFile::pos_ = pos; } -bool OpenFile::get_flag(OpenFile_flags flag) { +bool +OpenFile::get_flag(OpenFile_flags flag) { lock_guard lock(pos_mutex_); return flags_[gkfs::util::to_underlying(flag)]; } -void OpenFile::set_flag(OpenFile_flags flag, bool value) { +void +OpenFile::set_flag(OpenFile_flags flag, bool value) { lock_guard lock(flag_mutex_); flags_[gkfs::util::to_underlying(flag)] = value; } -FileType OpenFile::type() const { +FileType +OpenFile::type() const { return type_; } // OpenFileMap starts here -shared_ptr OpenFileMap::get(int fd) { +shared_ptr +OpenFileMap::get(int fd) { lock_guard lock(files_mutex_); auto f = files_.find(fd); - if (f == files_.end()) { + if(f == files_.end()) { return nullptr; } else { return f->second; } } -shared_ptr OpenFileMap::get_dir(int dirfd) { +shared_ptr +OpenFileMap::get_dir(int dirfd) { auto f = get(dirfd); - if (f == nullptr || f->type() != FileType::directory) { + if(f == nullptr || f->type() != FileType::directory) { return nullptr; } return static_pointer_cast(f); } -bool OpenFileMap::exist(const int fd) { +bool +OpenFileMap::exist(const int fd) { lock_guard lock(files_mutex_); auto f = files_.find(fd); return !(f == files_.end()); } -int OpenFileMap::safe_generate_fd_idx_() { +int +OpenFileMap::safe_generate_fd_idx_() { auto fd = generate_fd_idx(); /* * Check if fd is still in use and generate another if yes - * Note that this can only happen once the all fd indices within the int has been used to the int::max - * Once this limit is exceeded, we set fd_idx back to 3 and begin anew. Only then, if a file was open for - * a long time will we have to generate another index. + * Note that this can only happen once the all fd indices within the int has + * been used to the int::max Once this limit is exceeded, we set fd_idx back + * to 3 and begin anew. Only then, if a file was open for a long time will + * we have to generate another index. * - * This situation can only occur when all fd indices have been given away once and we start again, - * in which case the fd_validation_needed flag is set. fd_validation is set to false, if + * This situation can only occur when all fd indices have been given away + * once and we start again, in which case the fd_validation_needed flag is + * set. fd_validation is set to false, if */ - if (fd_validation_needed) { - while (exist(fd)) { + if(fd_validation_needed) { + while(exist(fd)) { fd = generate_fd_idx(); } } return fd; } -int OpenFileMap::add(std::shared_ptr open_file) { +int +OpenFileMap::add(std::shared_ptr open_file) { auto fd = safe_generate_fd_idx_(); lock_guard lock(files_mutex_); files_.insert(make_pair(fd, open_file)); return fd; } -bool OpenFileMap::remove(const int fd) { +bool +OpenFileMap::remove(const int fd) { lock_guard lock(files_mutex_); auto f = files_.find(fd); - if (f == files_.end()) { + if(f == files_.end()) { return false; } files_.erase(fd); - if (fd_validation_needed && files_.empty()) { + if(fd_validation_needed && files_.empty()) { fd_validation_needed = false; LOG(DEBUG, "fd_validation flag reset"); } return true; } -int OpenFileMap::dup(const int oldfd) { +int +OpenFileMap::dup(const int oldfd) { lock_guard lock(files_mutex_); auto open_file = get(oldfd); - if (open_file == nullptr) { + if(open_file == nullptr) { errno = EBADF; return -1; } @@ -161,21 +174,23 @@ int OpenFileMap::dup(const int oldfd) { return newfd; } -int OpenFileMap::dup2(const int oldfd, const int newfd) { +int +OpenFileMap::dup2(const int oldfd, const int newfd) { lock_guard lock(files_mutex_); auto open_file = get(oldfd); - if (open_file == nullptr) { + if(open_file == nullptr) { errno = EBADF; return -1; } - if (oldfd == newfd) + if(oldfd == newfd) return newfd; // remove newfd if exists in filemap silently - if (exist(newfd)) { + if(exist(newfd)) { remove(newfd); } - // to prevent duplicate fd idx in the future. First three fd are reservered by os streams that we do not overwrite - if (get_fd_idx() < newfd && newfd != 0 && newfd != 1 && newfd != 2) + // to prevent duplicate fd idx in the future. First three fd are reservered + // by os streams that we do not overwrite + if(get_fd_idx() < newfd && newfd != 0 && newfd != 1 && newfd != 2) fd_validation_needed = true; files_.insert(make_pair(newfd, open_file)); return newfd; @@ -185,15 +200,18 @@ int OpenFileMap::dup2(const int oldfd, const int newfd) { * Generate new file descriptor index to be used as an fd within one process * @return fd_idx */ -int OpenFileMap::generate_fd_idx() { +int +OpenFileMap::generate_fd_idx() { // We need a mutex here for thread safety std::lock_guard inode_lock(fd_idx_mutex); - if (fd_idx == std::numeric_limits::max()) { - LOG(WARNING, "File descriptor index exceeded ints max value. Setting it back to 100000"); + if(fd_idx == std::numeric_limits::max()) { + LOG(WARNING, + "File descriptor index exceeded ints max value. Setting it back to 100000"); /* - * Setting fd_idx back to 3 could have the effect that fd are given twice for different path. - * This must not happen. Instead a flag is set which tells can tell the OpenFileMap that it should check - * if this fd is really safe to use. + * Setting fd_idx back to 3 could have the effect that fd are given + * twice for different path. This must not happen. Instead a flag is set + * which tells can tell the OpenFileMap that it should check if this fd + * is really safe to use. */ fd_idx = 100000; fd_validation_needed = true; @@ -201,7 +219,8 @@ int OpenFileMap::generate_fd_idx() { return fd_idx++; } -int OpenFileMap::get_fd_idx() { +int +OpenFileMap::get_fd_idx() { std::lock_guard inode_lock(fd_idx_mutex); return fd_idx; } diff --git a/src/client/path.cpp b/src/client/path.cpp index c1aeffe3d..b3004fa0c 100644 --- a/src/client/path.cpp +++ b/src/client/path.cpp @@ -40,35 +40,38 @@ static const string excluded_paths[2] = {"sys/", "proc/"}; * Returns the number of consecutive components at start of `path` * that match the ones in `components` vector. * - * `path_components` will be set to the total number of components found in `path` + * `path_components` will be set to the total number of components found in + * `path` * * Example: * ```ÏÏ * unsigned int tot_comp; - * path_match_components("/matched/head/with/tail", &tot_comp, ["matched", "head", "no"]) == 2; - * tot_comp == 4; + * path_match_components("/matched/head/with/tail", &tot_comp, ["matched", + * "head", "no"]) == 2; tot_comp == 4; * ``` */ -unsigned int match_components(const string& path, unsigned int& path_components, - const ::vector& components) { +unsigned int +match_components(const string& path, unsigned int& path_components, + const ::vector& components) { unsigned int matched = 0; unsigned int processed_components = 0; string::size_type comp_size = 0; // size of current component - string::size_type start = 0; // start index of curr component - string::size_type end = 0; // end index of curr component (last processed Path Separator "separator") + string::size_type start = 0; // start index of curr component + string::size_type end = 0; // end index of curr component (last processed + // Path Separator "separator") - while (++end < path.size()) { + while(++end < path.size()) { start = end; // Find next component end = path.find(path::separator, start); - if (end == string::npos) { + if(end == string::npos) { end = path.size(); } comp_size = end - start; - if (matched == processed_components && - path.compare(start, comp_size, components.at(matched)) == 0) { + if(matched == processed_components && + path.compare(start, comp_size, components.at(matched)) == 0) { ++matched; } ++processed_components; @@ -89,58 +92,63 @@ unsigned int match_components(const string& path, unsigned int& path_components, * returns true if the resolved path fall inside GekkoFS namespace, * and false otherwise. */ -bool resolve(const string& path, string& resolved, bool resolve_last_link) { +bool +resolve(const string& path, string& resolved, bool resolve_last_link) { - LOG(DEBUG, "path: \"{}\", resolved: \"{}\", resolve_last_link: {}", - path, resolved, resolve_last_link); + LOG(DEBUG, "path: \"{}\", resolved: \"{}\", resolve_last_link: {}", path, + resolved, resolve_last_link); assert(path::is_absolute(path)); - for (auto& excl_path: excluded_paths) { - if (path.compare(1, excl_path.length(), excl_path) == 0) { + for(auto& excl_path : excluded_paths) { + if(path.compare(1, excl_path.length(), excl_path) == 0) { LOG(DEBUG, "Skipping: '{}'", path); resolved = path; return false; } } - struct stat st{}; + struct stat st {}; const ::vector& mnt_components = CTX->mountdir_components(); - unsigned int matched_components = 0; // matched number of component in mountdir + unsigned int matched_components = + 0; // matched number of component in mountdir unsigned int resolved_components = 0; string::size_type comp_size = 0; // size of current component - string::size_type start = 0; // start index of curr component - string::size_type end = 0; // end index of curr component (last processed Path Separator "separator") - string::size_type last_slash_pos = 0; // index of last slash in resolved path + string::size_type start = 0; // start index of curr component + string::size_type end = 0; // end index of curr component (last processed + // Path Separator "separator") + string::size_type last_slash_pos = + 0; // index of last slash in resolved path resolved.clear(); resolved.reserve(path.size()); - while (++end < path.size()) { + while(++end < path.size()) { start = end; /* Skip sequence of multiple path-separators. */ - while (start < path.size() && path[start] == path::separator) { + while(start < path.size() && path[start] == path::separator) { ++start; } // Find next component end = path.find(path::separator, start); - if (end == string::npos) { + if(end == string::npos) { end = path.size(); } comp_size = end - start; - if (comp_size == 0) { + if(comp_size == 0) { // component is empty (this must be the last component) break; } - if (comp_size == 1 && path.at(start) == '.') { + if(comp_size == 1 && path.at(start) == '.') { // component is '.', we skip it continue; } - if (comp_size == 2 && path.at(start) == '.' && path.at(start + 1) == '.') { + if(comp_size == 2 && path.at(start) == '.' && + path.at(start + 1) == '.') { // component is '..' we need to rollback resolved path - if (!resolved.empty()) { + if(!resolved.empty()) { resolved.erase(last_slash_pos); /* TODO Optimization * the previous slash position should be stored. @@ -148,8 +156,8 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { */ last_slash_pos = resolved.find_last_of(path::separator); } - if (resolved_components > 0) { - if (matched_components == resolved_components) { + if(resolved_components > 0) { + if(matched_components == resolved_components) { --matched_components; } --resolved_components; @@ -162,39 +170,43 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { last_slash_pos = resolved.size() - 1; resolved.append(path, start, comp_size); - if (matched_components < mnt_components.size()) { + if(matched_components < mnt_components.size()) { // Outside GekkoFS - if (matched_components == resolved_components && - path.compare(start, comp_size, mnt_components.at(matched_components)) == 0) { + if(matched_components == resolved_components && + path.compare(start, comp_size, + mnt_components.at(matched_components)) == 0) { ++matched_components; } - if (lstat(resolved.c_str(), &st) < 0) { + if(lstat(resolved.c_str(), &st) < 0) { LOG(DEBUG, "path \"{}\" does not exist", resolved); resolved.append(path, end, string::npos); return false; } - if (S_ISLNK(st.st_mode)) { - if (!resolve_last_link && end == path.size()) { + if(S_ISLNK(st.st_mode)) { + if(!resolve_last_link && end == path.size()) { continue; } auto link_resolved = ::unique_ptr(new char[PATH_MAX]); - if (realpath(resolved.c_str(), link_resolved.get()) == nullptr) { + if(realpath(resolved.c_str(), link_resolved.get()) == nullptr) { - LOG(ERROR, "Failed to get realpath for link \"{}\". " - "Error: {}", resolved, ::strerror(errno)); + LOG(ERROR, + "Failed to get realpath for link \"{}\". " + "Error: {}", + resolved, ::strerror(errno)); resolved.append(path, end, string::npos); return false; } // substituute resolved with new link path resolved = link_resolved.get(); - matched_components = match_components(resolved, resolved_components, mnt_components); + matched_components = match_components( + resolved, resolved_components, mnt_components); // set matched counter to value coherent with the new path last_slash_pos = resolved.find_last_of(path::separator); continue; - } else if ((!S_ISDIR(st.st_mode)) && (end != path.size())) { + } else if((!S_ISDIR(st.st_mode)) && (end != path.size())) { resolved.append(path, end, string::npos); return false; } @@ -205,86 +217,89 @@ bool resolve(const string& path, string& resolved, bool resolve_last_link) { ++resolved_components; } - if (matched_components >= mnt_components.size()) { + if(matched_components >= mnt_components.size()) { resolved.erase(1, CTX->mountdir().size()); LOG(DEBUG, "internal: \"{}\"", resolved); return true; } - if (resolved.empty()) { + if(resolved.empty()) { resolved.push_back(path::separator); } LOG(DEBUG, "external: \"{}\"", resolved); return false; } -string get_sys_cwd() { +string +get_sys_cwd() { char temp[path::max_length]; - if (long ret = syscall_no_intercept(SYS_getcwd, temp, path::max_length) < 0) { - throw ::system_error(syscall_error_code(ret), - ::system_category(), + if(long ret = + syscall_no_intercept(SYS_getcwd, temp, path::max_length) < 0) { + throw ::system_error(syscall_error_code(ret), ::system_category(), "Failed to retrieve current working directory"); } // getcwd could return "(unreachable)" in some cases - if (temp[0] != path::separator) { - throw ::runtime_error( - "Current working directory is unreachable"); + if(temp[0] != path::separator) { + throw ::runtime_error("Current working directory is unreachable"); } return {temp}; } -void set_sys_cwd(const string& path) { +void +set_sys_cwd(const string& path) { LOG(DEBUG, "Changing working directory to \"{}\"", path); - if (long ret = syscall_no_intercept(SYS_chdir, path.c_str())) { + if(long ret = syscall_no_intercept(SYS_chdir, path.c_str())) { LOG(ERROR, "Failed to change working directory: {}", ::strerror(syscall_error_code(ret))); - throw ::system_error(syscall_error_code(ret), - ::system_category(), + throw ::system_error(syscall_error_code(ret), ::system_category(), "Failed to set system current working directory"); } } -void set_env_cwd(const string& path) { +void +set_env_cwd(const string& path) { LOG(DEBUG, "Setting {} to \"{}\"", gkfs::env::CWD, path); - if (setenv(gkfs::env::CWD, path.c_str(), 1)) { - LOG(ERROR, "Failed while setting {}: {}", - gkfs::env::CWD, ::strerror(errno)); - throw ::system_error(errno, - ::system_category(), - "Failed to set environment current working directory"); + if(setenv(gkfs::env::CWD, path.c_str(), 1)) { + LOG(ERROR, "Failed while setting {}: {}", gkfs::env::CWD, + ::strerror(errno)); + throw ::system_error( + errno, ::system_category(), + "Failed to set environment current working directory"); } } -void unset_env_cwd() { +void +unset_env_cwd() { LOG(DEBUG, "Clearing {}()", gkfs::env::CWD); - if (unsetenv(gkfs::env::CWD)) { + if(unsetenv(gkfs::env::CWD)) { - LOG(ERROR, "Failed to clear {}: {}", - gkfs::env::CWD, ::strerror(errno)); + LOG(ERROR, "Failed to clear {}: {}", gkfs::env::CWD, ::strerror(errno)); - throw ::system_error(errno, - ::system_category(), - "Failed to unset environment current working directory"); + throw ::system_error( + errno, ::system_category(), + "Failed to unset environment current working directory"); } } -void init_cwd() { +void +init_cwd() { const char* env_cwd = ::getenv(gkfs::env::CWD); - if (env_cwd != nullptr) { + if(env_cwd != nullptr) { CTX->cwd(env_cwd); } else { CTX->cwd(get_sys_cwd()); } } -void set_cwd(const string& path, bool internal) { - if (internal) { +void +set_cwd(const string& path, bool internal) { + if(internal) { set_sys_cwd(CTX->mountdir()); set_env_cwd(path); } else { diff --git a/src/client/preload.cpp b/src/client/preload.cpp index 33043ce78..b0985d9ba 100644 --- a/src/client/preload.cpp +++ b/src/client/preload.cpp @@ -45,7 +45,8 @@ pthread_mutex_t remap_mutex; pthread_cond_t remap_signal; #endif -inline void exit_error_msg(int errcode, const string& msg) { +inline void +exit_error_msg(int errcode, const string& msg) { LOG_ERROR("{}", msg); gkfs::log::logger::log_message(stderr, "{}\n", msg); @@ -62,23 +63,23 @@ inline void exit_error_msg(int errcode, const string& msg) { * Initializes the Hermes client for a given transport prefix * @return true if successfully initialized; false otherwise */ -bool init_hermes_client() { +bool +init_hermes_client() { try { hermes::engine_options opts{}; - if (CTX->auto_sm()) + if(CTX->auto_sm()) opts |= hermes::use_auto_sm; - if (gkfs::rpc::protocol::ofi_psm2 == CTX->rpc_protocol()) { + if(gkfs::rpc::protocol::ofi_psm2 == CTX->rpc_protocol()) { opts |= hermes::force_no_block_progress; } - ld_network_service = - std::make_unique( - hermes::get_transport_type(CTX->rpc_protocol()), opts); + ld_network_service = std::make_unique( + hermes::get_transport_type(CTX->rpc_protocol()), opts); ld_network_service->run(); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { fmt::print(stderr, "Failed to initialize Hermes RPC client {}\n", ex.what()); return false; @@ -87,30 +88,33 @@ bool init_hermes_client() { } /** - * This function is only called in the preload constructor and initializes + * This function is only called in the preload constructor and initializes * the file system client */ -void init_ld_environment_() { +void +init_ld_environment_() { vector> hosts{}; try { LOG(INFO, "Loading peer addresses..."); hosts = gkfs::util::read_hosts_file(); - } catch (const std::exception& e) { - exit_error_msg(EXIT_FAILURE, "Failed to load hosts addresses: "s + e.what()); + } catch(const std::exception& e) { + exit_error_msg(EXIT_FAILURE, + "Failed to load hosts addresses: "s + e.what()); } // initialize Hermes interface to Mercury LOG(INFO, "Initializing RPC subsystem..."); - if (!init_hermes_client()) { + if(!init_hermes_client()) { exit_error_msg(EXIT_FAILURE, "Unable to initialize RPC subsystem"); } try { gkfs::util::connect_to_hosts(hosts); - } catch (const std::exception& e) { - exit_error_msg(EXIT_FAILURE, "Failed to connect to hosts: "s + e.what()); + } catch(const std::exception& e) { + exit_error_msg(EXIT_FAILURE, + "Failed to connect to hosts: "s + e.what()); } /* Setup distributor */ @@ -119,46 +123,54 @@ void init_ld_environment_() { gkfs::util::load_forwarding_map(); LOG(INFO, "{}() Forward to {}", __func__, CTX->fwd_host_id()); - } catch (std::exception& e){ - exit_error_msg(EXIT_FAILURE, fmt::format("Unable set the forwarding host '{}'", e.what())); + } catch(std::exception& e) { + exit_error_msg( + EXIT_FAILURE, + fmt::format("Unable set the forwarding host '{}'", e.what())); } - - auto forwarder_dist = std::make_shared(CTX->fwd_host_id(), CTX->hosts().size()); + + auto forwarder_dist = std::make_shared( + CTX->fwd_host_id(), CTX->hosts().size()); CTX->distributor(forwarder_dist); #else - auto simple_hash_dist = std::make_shared(CTX->local_host_id(), - CTX->hosts().size()); + auto simple_hash_dist = std::make_shared( + CTX->local_host_id(), CTX->hosts().size()); CTX->distributor(simple_hash_dist); #endif LOG(INFO, "Retrieving file system configuration..."); - if (!gkfs::rpc::forward_get_fs_config()) { - exit_error_msg(EXIT_FAILURE, "Unable to fetch file system configurations from daemon process through RPC."); + if(!gkfs::rpc::forward_get_fs_config()) { + exit_error_msg( + EXIT_FAILURE, + "Unable to fetch file system configurations from daemon process through RPC."); } LOG(INFO, "Environment initialization successful."); } #ifdef GKFS_ENABLE_FORWARDING -void *forwarding_mapper(void* p) { +void* +forwarding_mapper(void* p) { struct timespec timeout; clock_gettime(CLOCK_REALTIME, &timeout); timeout.tv_sec += 10; // 10 seconds int previous = -1; - while (forwarding_running) { + while(forwarding_running) { try { gkfs::util::load_forwarding_map(); - if (previous != CTX->fwd_host_id()) { + if(previous != CTX->fwd_host_id()) { LOG(INFO, "{}() Forward to {}", __func__, CTX->fwd_host_id()); previous = CTX->fwd_host_id(); } - } catch (std::exception& e) { - exit_error_msg(EXIT_FAILURE, fmt::format("Unable set the forwarding host '{}'", e.what())); + } catch(std::exception& e) { + exit_error_msg(EXIT_FAILURE, + fmt::format("Unable set the forwarding host '{}'", + e.what())); } pthread_mutex_lock(&remap_mutex); @@ -171,7 +183,8 @@ void *forwarding_mapper(void* p) { #endif #ifdef GKFS_ENABLE_FORWARDING -void init_forwarding_mapper() { +void +init_forwarding_mapper() { forwarding_running = true; pthread_create(&mapper, NULL, forwarding_mapper, NULL); @@ -179,7 +192,8 @@ void init_forwarding_mapper() { #endif #ifdef GKFS_ENABLE_FORWARDING -void destroy_forwarding_mapper() { +void +destroy_forwarding_mapper() { forwarding_running = false; pthread_cond_signal(&remap_signal); @@ -188,14 +202,15 @@ void destroy_forwarding_mapper() { } #endif -void log_prog_name() { +void +log_prog_name() { std::string line; std::ifstream cmdline("/proc/self/cmdline"); - if (!cmdline.is_open()) { + if(!cmdline.is_open()) { LOG(ERROR, "Unable to open cmdline file"); throw std::runtime_error("Unable to open cmdline file"); } - if (!getline(cmdline, line)) { + if(!getline(cmdline, line)) { throw std::runtime_error("Unable to read cmdline file"); } std::replace(line.begin(), line.end(), '\0', ' '); @@ -209,7 +224,8 @@ void log_prog_name() { namespace gkfs { namespace preload { -void init_ld_env_if_needed() { +void +init_ld_env_if_needed() { pthread_once(&init_env_thread, init_ld_environment_); } @@ -217,10 +233,13 @@ void init_ld_env_if_needed() { } // namespace gkfs /** - * Called initially ONCE when preload library is used with the LD_PRELOAD environment variable + * Called initially ONCE when preload library is used with the LD_PRELOAD + * environment variable */ -void init_preload() { - // The original errno value will be restored after initialization to not leak internal error codes +void +init_preload() { + // The original errno value will be restored after initialization to not + // leak internal error codes auto oerrno = errno; CTX->enable_interception(); @@ -231,12 +250,12 @@ void init_preload() { LOG(DEBUG, "Logging subsystem initialized"); // Kernel modules such as ib_uverbs may create fds in kernel space and pass - // them to user-space processes using ioctl()-like interfaces. if this - // happens during our internal initialization, there's no way for us to - // control this creation and the fd will be created in the - // [0, MAX_USER_FDS) range rather than in our private - // [MAX_USER_FDS, MAX_OPEN_FDS) range. To prevent this for our internal - // initialization code, we forcefully occupy the user fd range to force + // them to user-space processes using ioctl()-like interfaces. if this + // happens during our internal initialization, there's no way for us to + // control this creation and the fd will be created in the + // [0, MAX_USER_FDS) range rather than in our private + // [MAX_USER_FDS, MAX_OPEN_FDS) range. To prevent this for our internal + // initialization code, we forcefully occupy the user fd range to force // such modules to create fds in our private range. CTX->protect_user_fds(); @@ -258,9 +277,11 @@ void init_preload() { } /** - * Called last when preload library is used with the LD_PRELOAD environment variable + * Called last when preload library is used with the LD_PRELOAD environment + * variable */ -void destroy_preload() { +void +destroy_preload() { #ifdef GKFS_ENABLE_FORWARDING destroy_forwarding_mapper(); #endif diff --git a/src/client/preload_context.cpp b/src/client/preload_context.cpp index 59a2b1f1a..29094beaa 100644 --- a/src/client/preload_context.cpp +++ b/src/client/preload_context.cpp @@ -33,14 +33,13 @@ extern "C" { namespace gkfs { namespace preload { -decltype(PreloadContext::MIN_INTERNAL_FD) constexpr - PreloadContext::MIN_INTERNAL_FD; -decltype(PreloadContext::MAX_USER_FDS) constexpr - PreloadContext::MAX_USER_FDS; +decltype(PreloadContext::MIN_INTERNAL_FD) constexpr PreloadContext:: + MIN_INTERNAL_FD; +decltype(PreloadContext::MAX_USER_FDS) constexpr PreloadContext::MAX_USER_FDS; -PreloadContext::PreloadContext() : - ofm_(std::make_shared()), - fs_conf_(std::make_shared()) { +PreloadContext::PreloadContext() + : ofm_(std::make_shared()), + fs_conf_(std::make_shared()) { internal_fds_.set(); internal_fds_must_relocate_ = true; @@ -49,11 +48,11 @@ PreloadContext::PreloadContext() : void PreloadContext::init_logging() { - const std::string log_opts = - gkfs::env::get_var(gkfs::env::LOG, gkfs::config::log::client_log_level); + const std::string log_opts = gkfs::env::get_var( + gkfs::env::LOG, gkfs::config::log::client_log_level); - const std::string log_output = - gkfs::env::get_var(gkfs::env::LOG_OUTPUT, gkfs::config::log::client_log_path); + const std::string log_output = gkfs::env::get_var( + gkfs::env::LOG_OUTPUT, gkfs::config::log::client_log_path); #ifdef GKFS_DEBUG_BUILD // atoi returns 0 if no int conversion can be performed, which works @@ -73,84 +72,102 @@ PreloadContext::init_logging() { gkfs::log::create_global_logger(log_opts, log_output, log_trunc #ifdef GKFS_DEBUG_BUILD - , log_filter, log_verbosity + , + log_filter, log_verbosity #endif ); } -void PreloadContext::mountdir(const std::string& path) { +void +PreloadContext::mountdir(const std::string& path) { assert(gkfs::path::is_absolute(path)); assert(!gkfs::path::has_trailing_slash(path)); mountdir_components_ = gkfs::path::split_path(path); mountdir_ = path; } -const std::string& PreloadContext::mountdir() const { +const std::string& +PreloadContext::mountdir() const { return mountdir_; } -const std::vector& PreloadContext::mountdir_components() const { +const std::vector& +PreloadContext::mountdir_components() const { return mountdir_components_; } -void PreloadContext::cwd(const std::string& path) { +void +PreloadContext::cwd(const std::string& path) { cwd_ = path; } -const std::string& PreloadContext::cwd() const { +const std::string& +PreloadContext::cwd() const { return cwd_; } -const std::vector& PreloadContext::hosts() const { +const std::vector& +PreloadContext::hosts() const { return hosts_; } -void PreloadContext::hosts(const std::vector& endpoints) { +void +PreloadContext::hosts(const std::vector& endpoints) { hosts_ = endpoints; } -void PreloadContext::clear_hosts() { +void +PreloadContext::clear_hosts() { hosts_.clear(); } -uint64_t PreloadContext::local_host_id() const { +uint64_t +PreloadContext::local_host_id() const { return local_host_id_; } -void PreloadContext::local_host_id(uint64_t id) { +void +PreloadContext::local_host_id(uint64_t id) { local_host_id_ = id; } -uint64_t PreloadContext::fwd_host_id() const { +uint64_t +PreloadContext::fwd_host_id() const { return fwd_host_id_; } -void PreloadContext::fwd_host_id(uint64_t id) { +void +PreloadContext::fwd_host_id(uint64_t id) { fwd_host_id_ = id; } -const std::string& PreloadContext::rpc_protocol() const { +const std::string& +PreloadContext::rpc_protocol() const { return rpc_protocol_; } -void PreloadContext::rpc_protocol(const std::string& rpc_protocol) { +void +PreloadContext::rpc_protocol(const std::string& rpc_protocol) { rpc_protocol_ = rpc_protocol; } -bool PreloadContext::auto_sm() const { +bool +PreloadContext::auto_sm() const { return auto_sm_; } -void PreloadContext::auto_sm(bool auto_sm) { +void +PreloadContext::auto_sm(bool auto_sm) { PreloadContext::auto_sm_ = auto_sm; } -RelativizeStatus PreloadContext::relativize_fd_path(int dirfd, - const char* raw_path, - std::string& relative_path, - bool resolve_last_link) const { +RelativizeStatus +PreloadContext::relativize_fd_path(int dirfd, const char* raw_path, + std::string& relative_path, + bool resolve_last_link) const { - // Relativize path should be called only after the library constructor has been executed + // Relativize path should be called only after the library constructor has + // been executed assert(interception_enabled_); // If we run the constructor we also already setup the mountdir assert(!mountdir_.empty()); @@ -160,18 +177,18 @@ RelativizeStatus PreloadContext::relativize_fd_path(int dirfd, std::string path; - if (raw_path[0] != gkfs::path::separator) { + if(raw_path[0] != gkfs::path::separator) { // path is relative - if (dirfd == AT_FDCWD) { + if(dirfd == AT_FDCWD) { // path is relative to cwd path = gkfs::path::prepend_path(cwd_, raw_path); } else { - if (!ofm_->exist(dirfd)) { + if(!ofm_->exist(dirfd)) { return RelativizeStatus::fd_unknown; } // path is relative to fd auto dir = ofm_->get_dir(dirfd); - if (dir == nullptr) { + if(dir == nullptr) { return RelativizeStatus::fd_not_a_dir; } path = mountdir_; @@ -183,14 +200,18 @@ RelativizeStatus PreloadContext::relativize_fd_path(int dirfd, path = raw_path; } - if (gkfs::path::resolve(path, relative_path, resolve_last_link)) { + if(gkfs::path::resolve(path, relative_path, resolve_last_link)) { return RelativizeStatus::internal; } return RelativizeStatus::external; } -bool PreloadContext::relativize_path(const char* raw_path, std::string& relative_path, bool resolve_last_link) const { - // Relativize path should be called only after the library constructor has been executed +bool +PreloadContext::relativize_path(const char* raw_path, + std::string& relative_path, + bool resolve_last_link) const { + // Relativize path should be called only after the library constructor has + // been executed assert(interception_enabled_); // If we run the constructor we also already setup the mountdir assert(!mountdir_.empty()); @@ -200,7 +221,7 @@ bool PreloadContext::relativize_path(const char* raw_path, std::string& relative std::string path; - if (raw_path[0] != gkfs::path::separator) { + if(raw_path[0] != gkfs::path::separator) { /* Path is not absolute, we need to prepend CWD; * First reserve enough space to minimize memory copy */ @@ -211,39 +232,47 @@ bool PreloadContext::relativize_path(const char* raw_path, std::string& relative return gkfs::path::resolve(path, relative_path, resolve_last_link); } -const std::shared_ptr& PreloadContext::file_map() const { +const std::shared_ptr& +PreloadContext::file_map() const { return ofm_; } -void PreloadContext::distributor(std::shared_ptr d) { +void +PreloadContext::distributor(std::shared_ptr d) { distributor_ = d; } -std::shared_ptr PreloadContext::distributor() const { +std::shared_ptr +PreloadContext::distributor() const { return distributor_; } -const std::shared_ptr& PreloadContext::fs_conf() const { +const std::shared_ptr& +PreloadContext::fs_conf() const { return fs_conf_; } -void PreloadContext::enable_interception() { +void +PreloadContext::enable_interception() { interception_enabled_ = true; } -void PreloadContext::disable_interception() { +void +PreloadContext::disable_interception() { interception_enabled_ = false; } -bool PreloadContext::interception_enabled() const { +bool +PreloadContext::interception_enabled() const { return interception_enabled_; } -int PreloadContext::register_internal_fd(int fd) { +int +PreloadContext::register_internal_fd(int fd) { assert(fd >= 0); - if (!internal_fds_must_relocate_) { + if(!internal_fds_must_relocate_) { LOG(DEBUG, "registering fd {} as internal (no relocation needed)", fd); assert(fd >= MIN_INTERNAL_FD); internal_fds_.reset(fd - MIN_INTERNAL_FD); @@ -255,7 +284,7 @@ int PreloadContext::register_internal_fd(int fd) { std::lock_guard lock(internal_fds_mutex_); const int pos = internal_fds_._Find_first(); - if (static_cast(pos) == internal_fds_.size()) { + if(static_cast(pos) == internal_fds_.size()) { throw std::runtime_error( "Internal GekkoFS file descriptors exhausted, increase MAX_INTERNAL_FDS in " "CMake, rebuild GekkoFS and try again."); @@ -268,18 +297,16 @@ int PreloadContext::register_internal_fd(int fd) { #endif LOG(SYSCALL, - gkfs::syscall::from_internal_code | - gkfs::syscall::to_kernel | - gkfs::syscall::not_executed, + gkfs::syscall::from_internal_code | gkfs::syscall::to_kernel | + gkfs::syscall::not_executed, SYS_dup3, args); - const int ifd = - ::syscall_no_intercept(SYS_dup3, fd, pos + MIN_INTERNAL_FD, O_CLOEXEC); + const int ifd = ::syscall_no_intercept(SYS_dup3, fd, pos + MIN_INTERNAL_FD, + O_CLOEXEC); LOG(SYSCALL, - gkfs::syscall::from_internal_code | - gkfs::syscall::to_kernel | - gkfs::syscall::executed, + gkfs::syscall::from_internal_code | gkfs::syscall::to_kernel | + gkfs::syscall::executed, SYS_dup3, args, ifd); assert(::syscall_error_code(ifd) == 0); @@ -289,9 +316,8 @@ int PreloadContext::register_internal_fd(int fd) { #endif LOG(SYSCALL, - gkfs::syscall::from_internal_code | - gkfs::syscall::to_kernel | - gkfs::syscall::not_executed, + gkfs::syscall::from_internal_code | gkfs::syscall::to_kernel | + gkfs::syscall::not_executed, SYS_close, args2); #if defined(GKFS_ENABLE_LOGGING) && defined(GKFS_DEBUG_BUILD) @@ -301,9 +327,8 @@ int PreloadContext::register_internal_fd(int fd) { #endif LOG(SYSCALL, - gkfs::syscall::from_internal_code | - gkfs::syscall::to_kernel | - gkfs::syscall::executed, + gkfs::syscall::from_internal_code | gkfs::syscall::to_kernel | + gkfs::syscall::executed, SYS_close, args2, rv); LOG(DEBUG, " (fd {} relocated to ifd {})", fd, ifd); @@ -311,7 +336,8 @@ int PreloadContext::register_internal_fd(int fd) { return ifd; } -void PreloadContext::unregister_internal_fd(int fd) { +void +PreloadContext::unregister_internal_fd(int fd) { LOG(DEBUG, "unregistering internal fd {}", fd); @@ -323,9 +349,10 @@ void PreloadContext::unregister_internal_fd(int fd) { internal_fds_.set(pos); } -bool PreloadContext::is_internal_fd(int fd) const { +bool +PreloadContext::is_internal_fd(int fd) const { - if (fd < MIN_INTERNAL_FD) { + if(fd < MIN_INTERNAL_FD) { return false; } @@ -350,8 +377,8 @@ PreloadContext::protect_user_fds() { ::syscall_error_code(ret) != EBADF; }; - for (int fd = 0; fd < MAX_USER_FDS; ++fd) { - if (fd_is_open(fd)) { + for(int fd = 0; fd < MAX_USER_FDS; ++fd) { + if(fd_is_open(fd)) { LOG(DEBUG, " fd {} was already in use, skipping", fd); continue; } @@ -367,15 +394,15 @@ PreloadContext::protect_user_fds() { void PreloadContext::unprotect_user_fds() { - for (std::size_t fd = 0; fd < protected_fds_.size(); ++fd) { - if (!protected_fds_[fd]) { + for(std::size_t fd = 0; fd < protected_fds_.size(); ++fd) { + if(!protected_fds_[fd]) { continue; } const int ret = ::syscall_error_code(::syscall_no_intercept(SYS_close, fd)); - if (ret != 0) { + if(ret != 0) { LOG(ERROR, "Failed to unprotect fd") } } diff --git a/src/client/preload_util.cpp b/src/client/preload_util.cpp index cf19a030a..f827a7780 100644 --- a/src/client/preload_util.cpp +++ b/src/client/preload_util.cpp @@ -44,8 +44,8 @@ namespace { * @return hermes endpoint, if successful * @throws std::runtime_error */ -hermes::endpoint lookup_endpoint(const std::string& uri, - std::size_t max_retries = 3) { +hermes::endpoint +lookup_endpoint(const std::string& uri, std::size_t max_retries = 3) { LOG(DEBUG, "Looking up address \"{}\"", uri); @@ -56,19 +56,20 @@ hermes::endpoint lookup_endpoint(const std::string& uri, do { try { return ld_network_service->lookup(uri); - } catch (const exception& ex) { + } catch(const exception& ex) { error_msg = ex.what(); - LOG(WARNING, "Failed to lookup address '{}'. Attempts [{}/{}]", - uri, attempts + 1, max_retries); + LOG(WARNING, "Failed to lookup address '{}'. Attempts [{}/{}]", uri, + attempts + 1, max_retries); // Wait a random amount of time and try again std::mt19937 g(rd()); // seed the random generator - std::uniform_int_distribution<> distr(50, 50 * (attempts + 2)); // define the range + std::uniform_int_distribution<> distr( + 50, 50 * (attempts + 2)); // define the range std::this_thread::sleep_for(std::chrono::milliseconds(distr(g))); continue; } - } while (++attempts < max_retries); + } while(++attempts < max_retries); throw std::runtime_error( fmt::format("Endpoint for address '{}' could not be found ({})", @@ -80,47 +81,55 @@ hermes::endpoint lookup_endpoint(const std::string& uri, * @param uri * @throws std::runtime_error */ -void extract_protocol(const string& uri) { - if (uri.rfind("://") == string::npos) { +void +extract_protocol(const string& uri) { + if(uri.rfind("://") == string::npos) { // invalid format. kill client throw runtime_error(fmt::format("Invalid format for URI: '{}'", uri)); } string protocol{}; - if (uri.find(gkfs::rpc::protocol::ofi_sockets) != string::npos) { + if(uri.find(gkfs::rpc::protocol::ofi_sockets) != string::npos) { protocol = gkfs::rpc::protocol::ofi_sockets; - } else if (uri.find(gkfs::rpc::protocol::ofi_psm2) != string::npos) { + } else if(uri.find(gkfs::rpc::protocol::ofi_psm2) != string::npos) { protocol = gkfs::rpc::protocol::ofi_psm2; - } else if (uri.find(gkfs::rpc::protocol::ofi_verbs) != string::npos) { + } else if(uri.find(gkfs::rpc::protocol::ofi_verbs) != string::npos) { protocol = gkfs::rpc::protocol::ofi_verbs; } - // check for shared memory protocol. Can be plain shared memory or real ofi protocol + auto_sm - if (uri.find(gkfs::rpc::protocol::na_sm) != string::npos) { - if (protocol.empty()) + // check for shared memory protocol. Can be plain shared memory or real ofi + // protocol + auto_sm + if(uri.find(gkfs::rpc::protocol::na_sm) != string::npos) { + if(protocol.empty()) protocol = gkfs::rpc::protocol::na_sm; else CTX->auto_sm(true); } - if (protocol.empty()) { + if(protocol.empty()) { // unsupported protocol. kill client - throw runtime_error(fmt::format("Unsupported RPC protocol found in hosts file with URI: '{}'", uri)); + throw runtime_error(fmt::format( + "Unsupported RPC protocol found in hosts file with URI: '{}'", + uri)); } - LOG(INFO, "RPC protocol '{}' extracted from hosts file. Using auto_sm is '{}'", protocol, CTX->auto_sm()); + LOG(INFO, + "RPC protocol '{}' extracted from hosts file. Using auto_sm is '{}'", + protocol, CTX->auto_sm()); CTX->rpc_protocol(protocol); } /** - * Reads the daemon generator hosts file by a given path, returning hosts and URI addresses + * Reads the daemon generator hosts file by a given path, returning hosts and + * URI addresses * @param path to hosts file * @return vector> * @throws std::runtime_error */ -vector> load_hostfile(const std::string& path) { +vector> +load_hostfile(const std::string& path) { LOG(DEBUG, "Loading hosts file: \"{}\"", path); ifstream lf(path); - if (!lf) { + if(!lf) { throw runtime_error(fmt::format("Failed to open hosts file '{}': {}", path, strerror(errno))); } @@ -131,8 +140,8 @@ vector> load_hostfile(const std::string& path) { string host; string uri; std::smatch match; - while (getline(lf, line)) { - if (!regex_match(line, match, line_re)) { + while(getline(lf, line)) { + if(!regex_match(line, match, line_re)) { LOG(ERROR, "Unrecognized line format: [path: '{}', line: '{}']", path, line); @@ -144,8 +153,9 @@ vector> load_hostfile(const std::string& path) { uri = match[2]; hosts.emplace_back(host, uri); } - if (hosts.empty()) { - throw runtime_error("Hosts file found but no suitable addresses could be extracted"); + if(hosts.empty()) { + throw runtime_error( + "Hosts file found but no suitable addresses could be extracted"); } extract_protocol(hosts[0].second); return hosts; @@ -163,19 +173,20 @@ namespace util { * @param follow_links * @return shared_ptr for metadata, nullptr else */ -std::shared_ptr get_metadata(const string& path, bool follow_links) { +std::shared_ptr +get_metadata(const string& path, bool follow_links) { std::string attr; auto err = gkfs::rpc::forward_stat(path, attr); - if (err) { + if(err) { errno = err; return nullptr; } #ifdef HAS_SYMLINKS - if (follow_links) { + if(follow_links) { gkfs::metadata::Metadata md{attr}; - while (md.is_link()) { + while(md.is_link()) { err = gkfs::rpc::forward_stat(md.target_path(), attr); - if (err) { + if(err) { errno = err; return nullptr; } @@ -193,7 +204,9 @@ std::shared_ptr get_metadata(const string& path, bool * @param attr * @return */ -int metadata_to_stat(const std::string& path, const gkfs::metadata::Metadata& md, struct stat& attr) { +int +metadata_to_stat(const std::string& path, const gkfs::metadata::Metadata& md, + struct stat& attr) { /* Populate default values */ attr.st_dev = makedev(0, 0); @@ -212,38 +225,41 @@ int metadata_to_stat(const std::string& path, const gkfs::metadata::Metadata& md attr.st_mode = md.mode(); #ifdef HAS_SYMLINKS - if (md.is_link()) + if(md.is_link()) attr.st_size = md.target_path().size() + CTX->mountdir().size(); else #endif attr.st_size = md.size(); - if (CTX->fs_conf()->atime_state) { + if(CTX->fs_conf()->atime_state) { attr.st_atim.tv_sec = md.atime(); } - if (CTX->fs_conf()->mtime_state) { + if(CTX->fs_conf()->mtime_state) { attr.st_mtim.tv_sec = md.mtime(); } - if (CTX->fs_conf()->ctime_state) { + if(CTX->fs_conf()->ctime_state) { attr.st_ctim.tv_sec = md.ctime(); } - if (CTX->fs_conf()->link_cnt_state) { + if(CTX->fs_conf()->link_cnt_state) { attr.st_nlink = md.link_count(); } - if (CTX->fs_conf()->blocks_state) { // last one will not encounter a delimiter anymore + if(CTX->fs_conf()->blocks_state) { // last one will not encounter a + // delimiter anymore attr.st_blocks = md.blocks(); } return 0; } #ifdef GKFS_ENABLE_FORWARDING -map load_forwarding_map_file(const std::string& lfpath) { +map +load_forwarding_map_file(const std::string& lfpath) { LOG(DEBUG, "Loading forwarding map file file: \"{}\"", lfpath); ifstream lf(lfpath); - if (!lf) { - throw runtime_error(fmt::format("Failed to open forwarding map file '{}': {}", + if(!lf) { + throw runtime_error( + fmt::format("Failed to open forwarding map file '{}': {}", lfpath, strerror(errno))); } map forwarding_map; @@ -253,8 +269,8 @@ map load_forwarding_map_file(const std::string& lfpath) { string host; uint64_t forwarder; std::smatch match; - while (getline(lf, line)) { - if (!regex_match(line, match, line_re)) { + while(getline(lf, line)) { + if(!regex_match(line, match, line_re)) { LOG(ERROR, "Unrecognized line format: [path: '{}', line: '{}']", lfpath, line); @@ -271,51 +287,60 @@ map load_forwarding_map_file(const std::string& lfpath) { #endif #ifdef GKFS_ENABLE_FORWARDING -void load_forwarding_map() { +void +load_forwarding_map() { string forwarding_map_file; - forwarding_map_file = gkfs::env::get_var(gkfs::env::FORWARDING_MAP_FILE, gkfs::config::forwarding_file_path); + forwarding_map_file = gkfs::env::get_var( + gkfs::env::FORWARDING_MAP_FILE, gkfs::config::forwarding_file_path); map forwarding_map; - while (forwarding_map.size() == 0) { + while(forwarding_map.size() == 0) { try { forwarding_map = load_forwarding_map_file(forwarding_map_file); - } catch (const exception& e) { - auto emsg = fmt::format("Failed to load forwarding map file: {}", e.what()); + } catch(const exception& e) { + auto emsg = fmt::format("Failed to load forwarding map file: {}", + e.what()); throw runtime_error(emsg); } } - //if (forwarding_map.size() == 0) { - // throw runtime_error(fmt::format("Forwarding map file is empty: '{}'", forwarding_map_file)); + // if (forwarding_map.size() == 0) { + // throw runtime_error(fmt::format("Forwarding map file is empty: '{}'", + // forwarding_map_file)); //} auto local_hostname = get_my_hostname(true); - if (forwarding_map.find(local_hostname) == forwarding_map.end()) { - throw runtime_error(fmt::format("Unable to determine the forwarder for host: '{}'", local_hostname)); + if(forwarding_map.find(local_hostname) == forwarding_map.end()) { + throw runtime_error( + fmt::format("Unable to determine the forwarder for host: '{}'", + local_hostname)); } - LOG(INFO, "Forwarding map loaded for '{}' as '{}'", local_hostname, forwarding_map[local_hostname]); + LOG(INFO, "Forwarding map loaded for '{}' as '{}'", local_hostname, + forwarding_map[local_hostname]); CTX->fwd_host_id(forwarding_map[local_hostname]); } #endif -vector> read_hosts_file() { +vector> +read_hosts_file() { string hostfile; - hostfile = gkfs::env::get_var(gkfs::env::HOSTS_FILE, gkfs::config::hostfile_path); + hostfile = gkfs::env::get_var(gkfs::env::HOSTS_FILE, + gkfs::config::hostfile_path); vector> hosts; try { hosts = load_hostfile(hostfile); - } catch (const exception& e) { + } catch(const exception& e) { auto emsg = fmt::format("Failed to load hosts file: {}", e.what()); throw runtime_error(emsg); } - if (hosts.empty()) { + if(hosts.empty()) { throw runtime_error(fmt::format("Hostfile empty: '{}'", hostfile)); } @@ -329,7 +354,8 @@ vector> read_hosts_file() { * @param hosts vector> * @throws std::runtime_error through lookup_endpoint() */ -void connect_to_hosts(const vector>& hosts) { +void +connect_to_hosts(const vector>& hosts) { auto local_hostname = gkfs::rpc::get_my_hostname(true); bool local_host_found = false; @@ -346,17 +372,17 @@ void connect_to_hosts(const vector>& hosts) { * returning error when addr lookup */ ::random_device rd; // obtain a random number from hardware - ::mt19937 g(rd()); // seed the random generator + ::mt19937 g(rd()); // seed the random generator ::shuffle(host_ids.begin(), host_ids.end(), g); // Shuffle hosts vector // lookup addresses and put abstract server addresses into rpc_addresses - for (const auto& id: host_ids) { + for(const auto& id : host_ids) { const auto& hostname = hosts.at(id).first; const auto& uri = hosts.at(id).second; addrs[id] = lookup_endpoint(uri); - if (!local_host_found && hostname == local_hostname) { + if(!local_host_found && hostname == local_hostname) { LOG(DEBUG, "Found local host: {}", hostname); CTX->local_host_id(id); local_host_found = true; @@ -365,7 +391,7 @@ void connect_to_hosts(const vector>& hosts) { LOG(DEBUG, "Found peer: {}", addrs[id].to_string()); } - if (!local_host_found) { + if(!local_host_found) { LOG(WARNING, "Failed to find local host. Using host '0' as local host"); CTX->local_host_id(0); } diff --git a/src/client/rpc/forward_data.cpp b/src/client/rpc/forward_data.cpp index 0c2c775cc..6d87b31db 100644 --- a/src/client/rpc/forward_data.cpp +++ b/src/client/rpc/forward_data.cpp @@ -31,8 +31,8 @@ namespace rpc { * NOTE: No errno is defined here! */ -// TODO If we decide to keep this functionality with one segment, the function can be merged mostly. -// Code is mostly redundant +// TODO If we decide to keep this functionality with one segment, the function +// can be merged mostly. Code is mostly redundant /** * Send an RPC request to write from a buffer. @@ -44,18 +44,22 @@ namespace rpc { * @param updated_metadentry_size * @return pair */ -pair forward_write(const string& path, const void* buf, const bool append_flag, - const off64_t in_offset, const size_t write_size, - const int64_t updated_metadentry_size) { +pair +forward_write(const string& path, const void* buf, const bool append_flag, + const off64_t in_offset, const size_t write_size, + const int64_t updated_metadentry_size) { assert(write_size > 0); // Calculate chunkid boundaries and numbers so that daemons know in // which interval to look for chunks - off64_t offset = append_flag ? in_offset : (updated_metadentry_size - write_size); + off64_t offset = + append_flag ? in_offset : (updated_metadentry_size - write_size); - auto chnk_start = gkfs::util::chnk_id_for_offset(offset, gkfs::config::rpc::chunksize); - auto chnk_end = gkfs::util::chnk_id_for_offset((offset + write_size) - 1, gkfs::config::rpc::chunksize); + auto chnk_start = gkfs::util::chnk_id_for_offset( + offset, gkfs::config::rpc::chunksize); + auto chnk_end = gkfs::util::chnk_id_for_offset( + (offset + write_size) - 1, gkfs::config::rpc::chunksize); // Collect all chunk ids within count that have the same destination so // that those are send in one rpc bulk transfer @@ -68,22 +72,23 @@ pair forward_write(const string& path, const void* buf, const bool uint64_t chnk_start_target = 0; uint64_t chnk_end_target = 0; - for (uint64_t chnk_id = chnk_start; chnk_id <= chnk_end; chnk_id++) { + for(uint64_t chnk_id = chnk_start; chnk_id <= chnk_end; chnk_id++) { auto target = CTX->distributor()->locate_data(path, chnk_id); - if (target_chnks.count(target) == 0) { - target_chnks.insert(std::make_pair(target, std::vector{chnk_id})); + if(target_chnks.count(target) == 0) { + target_chnks.insert( + std::make_pair(target, std::vector{chnk_id})); targets.push_back(target); } else { target_chnks[target].push_back(chnk_id); } // set first and last chnk targets - if (chnk_id == chnk_start) { + if(chnk_id == chnk_start) { chnk_start_target = target; } - if (chnk_id == chnk_end) { + if(chnk_id == chnk_end) { chnk_end_target = target; } } @@ -98,9 +103,10 @@ pair forward_write(const string& path, const void* buf, const bool hermes::exposed_memory local_buffers; try { - local_buffers = ld_network_service->expose(bufseq, hermes::access_mode::read_only); + local_buffers = ld_network_service->expose( + bufseq, hermes::access_mode::read_only); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "Failed to expose buffers for RMA"); return make_pair(EBUSY, 0); } @@ -112,19 +118,22 @@ pair forward_write(const string& path, const void* buf, const bool // TODO(amiranda): This could be simplified by adding a vector of inputs // to async_engine::broadcast(). This would allow us to avoid manually // looping over handles as we do below - for (const auto& target : targets) { + for(const auto& target : targets) { // total chunk_size for target - auto total_chunk_size = target_chnks[target].size() * gkfs::config::rpc::chunksize; + auto total_chunk_size = + target_chnks[target].size() * gkfs::config::rpc::chunksize; // receiver of first chunk must subtract the offset from first chunk - if (target == chnk_start_target) { - total_chunk_size -= gkfs::util::chnk_lpad(offset, gkfs::config::rpc::chunksize); + if(target == chnk_start_target) { + total_chunk_size -= + gkfs::util::chnk_lpad(offset, gkfs::config::rpc::chunksize); } // receiver of last chunk must subtract - if (target == chnk_end_target) { - total_chunk_size -= gkfs::util::chnk_rpad(offset + write_size, gkfs::config::rpc::chunksize); + if(target == chnk_end_target) { + total_chunk_size -= gkfs::util::chnk_rpad( + offset + write_size, gkfs::config::rpc::chunksize); } auto endp = CTX->hosts().at(target); @@ -138,8 +147,7 @@ pair forward_write(const string& path, const void* buf, const bool // first offset in targets is the chunk with // a potential offset gkfs::util::chnk_lpad(offset, gkfs::config::rpc::chunksize), - target, - CTX->hosts().size(), + target, CTX->hosts().size(), // number of chunks handled by that destination target_chnks[target].size(), // chunk start id of this write @@ -147,22 +155,25 @@ pair forward_write(const string& path, const void* buf, const bool // chunk end id of this write chnk_end, // total size to write - total_chunk_size, - local_buffers); + total_chunk_size, local_buffers); // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that // we can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - handles.emplace_back(ld_network_service->post(endp, in)); + handles.emplace_back( + ld_network_service->post(endp, in)); - LOG(DEBUG, "host: {}, path: \"{}\", chunks: {}, size: {}, offset: {}", + LOG(DEBUG, + "host: {}, path: \"{}\", chunks: {}, size: {}, offset: {}", target, path, in.chunk_n(), total_chunk_size, in.offset()); - } catch (const std::exception& ex) { - LOG(ERROR, "Unable to send non-blocking rpc for " - "path \"{}\" [peer: {}]", path, target); + } catch(const std::exception& ex) { + LOG(ERROR, + "Unable to send non-blocking rpc for " + "path \"{}\" [peer: {}]", + path, target); return make_pair(EBUSY, 0); } } @@ -174,20 +185,20 @@ pair forward_write(const string& path, const void* buf, const bool ssize_t out_size = 0; std::size_t idx = 0; - for (const auto& h : handles) { + for(const auto& h : handles) { try { // XXX We might need a timeout here to not wait forever for an // output that never comes? auto out = h.get().at(0); - if (out.err() != 0) { + if(out.err() != 0) { LOG(ERROR, "Daemon reported error: {}", out.err()); err = out.err(); } out_size += static_cast(out.io_size()); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "Failed to get rpc output for path \"{}\" [peer: {}]", path, targets[idx]); err = EIO; @@ -196,10 +207,11 @@ pair forward_write(const string& path, const void* buf, const bool idx++; } /* - * Typically file systems return the size even if only a part of it was written. - * In our case, we do not keep track which daemon fully wrote its workload. Thus, we always return size 0 on error. + * Typically file systems return the size even if only a part of it was + * written. In our case, we do not keep track which daemon fully wrote its + * workload. Thus, we always return size 0 on error. */ - if (err) + if(err) return make_pair(err, 0); else return make_pair(0, out_size); @@ -213,12 +225,16 @@ pair forward_write(const string& path, const void* buf, const bool * @param read_size * @return pair */ -pair forward_read(const string& path, void* buf, const off64_t offset, const size_t read_size) { +pair +forward_read(const string& path, void* buf, const off64_t offset, + const size_t read_size) { // Calculate chunkid boundaries and numbers so that daemons know in which // interval to look for chunks - auto chnk_start = gkfs::util::chnk_id_for_offset(offset, gkfs::config::rpc::chunksize); - auto chnk_end = gkfs::util::chnk_id_for_offset((offset + read_size - 1), gkfs::config::rpc::chunksize); + auto chnk_start = gkfs::util::chnk_id_for_offset( + offset, gkfs::config::rpc::chunksize); + auto chnk_end = gkfs::util::chnk_id_for_offset( + (offset + read_size - 1), gkfs::config::rpc::chunksize); // Collect all chunk ids within count that have the same destination so // that those are send in one rpc bulk transfer @@ -231,22 +247,23 @@ pair forward_read(const string& path, void* buf, const off64_t off uint64_t chnk_start_target = 0; uint64_t chnk_end_target = 0; - for (uint64_t chnk_id = chnk_start; chnk_id <= chnk_end; chnk_id++) { + for(uint64_t chnk_id = chnk_start; chnk_id <= chnk_end; chnk_id++) { auto target = CTX->distributor()->locate_data(path, chnk_id); - if (target_chnks.count(target) == 0) { - target_chnks.insert(std::make_pair(target, std::vector{chnk_id})); + if(target_chnks.count(target) == 0) { + target_chnks.insert( + std::make_pair(target, std::vector{chnk_id})); targets.push_back(target); } else { target_chnks[target].push_back(chnk_id); } // set first and last chnk targets - if (chnk_id == chnk_start) { + if(chnk_id == chnk_start) { chnk_start_target = target; } - if (chnk_id == chnk_end) { + if(chnk_id == chnk_end) { chnk_end_target = target; } } @@ -261,9 +278,10 @@ pair forward_read(const string& path, void* buf, const off64_t off hermes::exposed_memory local_buffers; try { - local_buffers = ld_network_service->expose(bufseq, hermes::access_mode::write_only); + local_buffers = ld_network_service->expose( + bufseq, hermes::access_mode::write_only); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "Failed to expose buffers for RMA"); return make_pair(EBUSY, 0); } @@ -275,19 +293,22 @@ pair forward_read(const string& path, void* buf, const off64_t off // TODO(amiranda): This could be simplified by adding a vector of inputs // to async_engine::broadcast(). This would allow us to avoid manually // looping over handles as we do below - for (const auto& target : targets) { + for(const auto& target : targets) { // total chunk_size for target - auto total_chunk_size = target_chnks[target].size() * gkfs::config::rpc::chunksize; + auto total_chunk_size = + target_chnks[target].size() * gkfs::config::rpc::chunksize; // receiver of first chunk must subtract the offset from first chunk - if (target == chnk_start_target) { - total_chunk_size -= gkfs::util::chnk_lpad(offset, gkfs::config::rpc::chunksize); + if(target == chnk_start_target) { + total_chunk_size -= + gkfs::util::chnk_lpad(offset, gkfs::config::rpc::chunksize); } // receiver of last chunk must subtract - if (target == chnk_end_target) { - total_chunk_size -= gkfs::util::chnk_rpad(offset + read_size, gkfs::config::rpc::chunksize); + if(target == chnk_end_target) { + total_chunk_size -= gkfs::util::chnk_rpad( + offset + read_size, gkfs::config::rpc::chunksize); } auto endp = CTX->hosts().at(target); @@ -301,8 +322,7 @@ pair forward_read(const string& path, void* buf, const off64_t off // first offset in targets is the chunk with // a potential offset gkfs::util::chnk_lpad(offset, gkfs::config::rpc::chunksize), - target, - CTX->hosts().size(), + target, CTX->hosts().size(), // number of chunks handled by that destination target_chnks[target].size(), // chunk start id of this write @@ -310,8 +330,7 @@ pair forward_read(const string& path, void* buf, const off64_t off // chunk end id of this write chnk_end, // total size to write - total_chunk_size, - local_buffers); + total_chunk_size, local_buffers); // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that // we can retry for RPC_TRIES (see old commits with margo) @@ -324,9 +343,11 @@ pair forward_read(const string& path, void* buf, const off64_t off LOG(DEBUG, "host: {}, path: {}, chunks: {}, size: {}, offset: {}", target, path, in.chunk_n(), total_chunk_size, in.offset()); - } catch (const std::exception& ex) { - LOG(ERROR, "Unable to send non-blocking rpc for path \"{}\" " - "[peer: {}]", path, target); + } catch(const std::exception& ex) { + LOG(ERROR, + "Unable to send non-blocking rpc for path \"{}\" " + "[peer: {}]", + path, target); return make_pair(EBUSY, 0); } } @@ -338,20 +359,20 @@ pair forward_read(const string& path, void* buf, const off64_t off ssize_t out_size = 0; std::size_t idx = 0; - for (const auto& h : handles) { + for(const auto& h : handles) { try { // XXX We might need a timeout here to not wait forever for an // output that never comes? auto out = h.get().at(0); - if (out.err() != 0) { + if(out.err() != 0) { LOG(ERROR, "Daemon reported error: {}", out.err()); err = out.err(); } out_size += static_cast(out.io_size()); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "Failed to get rpc output for path \"{}\" [peer: {}]", path, targets[idx]); err = EIO; @@ -359,10 +380,11 @@ pair forward_read(const string& path, void* buf, const off64_t off idx++; } /* - * Typically file systems return the size even if only a part of it was read. - * In our case, we do not keep track which daemon fully read its workload. Thus, we always return size 0 on error. + * Typically file systems return the size even if only a part of it was + * read. In our case, we do not keep track which daemon fully read its + * workload. Thus, we always return size 0 on error. */ - if (err) + if(err) return make_pair(err, 0); else return make_pair(0, out_size); @@ -375,18 +397,22 @@ pair forward_read(const string& path, void* buf, const off64_t off * @param new_size * @return error code */ -int forward_truncate(const std::string& path, size_t current_size, size_t new_size) { +int +forward_truncate(const std::string& path, size_t current_size, + size_t new_size) { assert(current_size > new_size); // Find out which data servers need to delete data chunks in order to // contact only them - const unsigned int chunk_start = gkfs::util::chnk_id_for_offset(new_size, gkfs::config::rpc::chunksize); - const unsigned int chunk_end = gkfs::util::chnk_id_for_offset(current_size - new_size - 1, - gkfs::config::rpc::chunksize); + const unsigned int chunk_start = gkfs::util::chnk_id_for_offset( + new_size, gkfs::config::rpc::chunksize); + const unsigned int chunk_end = gkfs::util::chnk_id_for_offset( + current_size - new_size - 1, gkfs::config::rpc::chunksize); std::unordered_set hosts; - for (unsigned int chunk_id = chunk_start; chunk_id <= chunk_end; ++chunk_id) { + for(unsigned int chunk_id = chunk_start; chunk_id <= chunk_end; + ++chunk_id) { hosts.insert(CTX->distributor()->locate_data(path, chunk_id)); } @@ -394,7 +420,7 @@ int forward_truncate(const std::string& path, size_t current_size, size_t new_si auto err = 0; - for (const auto& host: hosts) { + for(const auto& host : hosts) { auto endp = CTX->hosts().at(host); @@ -408,30 +434,30 @@ int forward_truncate(const std::string& path, size_t current_size, size_t new_si // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - handles.emplace_back(ld_network_service->post(endp, in)); + handles.emplace_back( + ld_network_service->post(endp, in)); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { // TODO(amiranda): we should cancel all previously posted requests // here, unfortunately, Hermes does not support it yet :/ LOG(ERROR, "Failed to send request to host: {}", host); err = EIO; break; // We need to gather all responses so we can't return here } - } // Wait for RPC responses and then get response - for (const auto& h : handles) { + for(const auto& h : handles) { try { // XXX We might need a timeout here to not wait forever for an // output that never comes? auto out = h.get().at(0); - if (out.err()) { + if(out.err()) { LOG(ERROR, "received error response: {}", out.err()); err = EIO; } - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); err = EIO; } @@ -443,13 +469,14 @@ int forward_truncate(const std::string& path, size_t current_size, size_t new_si * Send an RPC request to chunk stat all hosts * @return pair */ -pair forward_get_chunk_stat() { +pair +forward_get_chunk_stat() { std::vector> handles; auto err = 0; - for (const auto& endp : CTX->hosts()) { + for(const auto& endp : CTX->hosts()) { try { LOG(DEBUG, "Sending RPC to host: {}", endp.to_string()); @@ -460,9 +487,10 @@ pair forward_get_chunk_stat() { // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - handles.emplace_back(ld_network_service->post(endp, in)); + handles.emplace_back( + ld_network_service->post(endp, in)); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { // TODO(amiranda): we should cancel all previously posted requests // here, unfortunately, Hermes does not support it yet :/ LOG(ERROR, "Failed to send request to host: {}", endp.to_string()); @@ -476,7 +504,7 @@ pair forward_get_chunk_stat() { unsigned long chunk_free = 0; // wait for RPC responses - for (std::size_t i = 0; i < handles.size(); ++i) { + for(std::size_t i = 0; i < handles.size(); ++i) { gkfs::rpc::chunk_stat::output out{}; @@ -485,22 +513,23 @@ pair forward_get_chunk_stat() { // output that never comes? out = handles[i].get().at(0); - if (out.err()) { + if(out.err()) { err = out.err(); - LOG(ERROR, "Host '{}' reported err code '{}' during stat chunk.", CTX->hosts().at(i).to_string(), - err); + LOG(ERROR, + "Host '{}' reported err code '{}' during stat chunk.", + CTX->hosts().at(i).to_string(), err); // we don't break here to ensure all responses are processed continue; } assert(out.chunk_size() == chunk_size); chunk_total += out.chunk_total(); chunk_free += out.chunk_free(); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "Failed to get RPC output from host: {}", i); err = EBUSY; } } - if (err) + if(err) return make_pair(err, ChunkStat{}); else return make_pair(0, ChunkStat{chunk_size, chunk_total, chunk_free}); diff --git a/src/client/rpc/forward_management.cpp b/src/client/rpc/forward_management.cpp index 1f19fb449..843999526 100644 --- a/src/client/rpc/forward_management.cpp +++ b/src/client/rpc/forward_management.cpp @@ -22,23 +22,25 @@ namespace gkfs { namespace rpc { /** -* Gets fs configuration information from the running daemon and transfers it to the memory of the library -* @return -*/ -bool forward_get_fs_config() { + * Gets fs configuration information from the running daemon and transfers it to + * the memory of the library + * @return + */ +bool +forward_get_fs_config() { auto endp = CTX->hosts().at(CTX->local_host_id()); gkfs::rpc::fs_config::output out; try { LOG(DEBUG, "Retrieving file system configurations from daemon"); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can retry - // for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ out = ld_network_service->post(endp).get().at(0); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "Retrieving fs configurations from daemon"); return false; } diff --git a/src/client/rpc/forward_metadata.cpp b/src/client/rpc/forward_metadata.cpp index 664e8a15f..2dc4c2ff5 100644 --- a/src/client/rpc/forward_metadata.cpp +++ b/src/client/rpc/forward_metadata.cpp @@ -38,22 +38,25 @@ namespace rpc { * @param mode * @return error code */ -int forward_create(const std::string& path, const mode_t mode) { +int +forward_create(const std::string& path, const mode_t mode) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post(endp, path, mode).get().at(0); + auto out = ld_network_service->post(endp, path, mode) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); return out.err() ? out.err() : 0; - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return EBUSY; } @@ -65,25 +68,28 @@ int forward_create(const std::string& path, const mode_t mode) { * @param attr * @return error code */ -int forward_stat(const std::string& path, string& attr) { +int +forward_stat(const std::string& path, string& attr) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post(endp, path).get().at(0); + auto out = ld_network_service->post(endp, path) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); - if (out.err()) + if(out.err()) return out.err(); attr = out.db_val(); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return EBUSY; } @@ -91,36 +97,43 @@ int forward_stat(const std::string& path, string& attr) { } /** - * Send an RPC for a remove request. This removes metadata and all data chunks possible distributed across many daemons. - * Optimizations are in place for small files (file_size / chunk_size) < number_of_daemons where no broadcast to all - * daemons is used to remove all chunks. Otherwise, a broadcast to all daemons is used. + * Send an RPC for a remove request. This removes metadata and all data chunks + * possible distributed across many daemons. Optimizations are in place for + * small files (file_size / chunk_size) < number_of_daemons where no broadcast + * to all daemons is used to remove all chunks. Otherwise, a broadcast to all + * daemons is used. * @param path * @param remove_metadentry_only * @param size * @return error code */ -int forward_remove(const std::string& path, const bool remove_metadentry_only, const ssize_t size) { +int +forward_remove(const std::string& path, const bool remove_metadentry_only, + const ssize_t size) { // if only the metadentry should be removed, send one rpc to the // metadentry's responsible node to remove the metadata // else, send an rpc to all hosts and thus broadcast chunk_removal. - if (remove_metadentry_only) { - auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); + if(remove_metadentry_only) { + auto endp = + CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that + // we can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post(endp, path).get().at(0); + auto out = ld_network_service->post(endp, path) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); return out.err() ? out.err() : 0; - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return EBUSY; } @@ -129,55 +142,66 @@ int forward_remove(const std::string& path, const bool remove_metadentry_only, c std::vector> handles; // Small files - if (static_cast(size / gkfs::config::rpc::chunksize) < CTX->hosts().size()) { - const auto metadata_host_id = CTX->distributor()->locate_file_metadata(path); + if(static_cast(size / gkfs::config::rpc::chunksize) < + CTX->hosts().size()) { + const auto metadata_host_id = + CTX->distributor()->locate_file_metadata(path); const auto endp_metadata = CTX->hosts().at(metadata_host_id); try { LOG(DEBUG, "Sending RPC to host: {}", endp_metadata.to_string()); gkfs::rpc::remove::input in(path); - handles.emplace_back(ld_network_service->post(endp_metadata, in)); + handles.emplace_back(ld_network_service->post( + endp_metadata, in)); uint64_t chnk_start = 0; uint64_t chnk_end = size / gkfs::config::rpc::chunksize; - for (uint64_t chnk_id = chnk_start; chnk_id <= chnk_end; chnk_id++) { - const auto chnk_host_id = CTX->distributor()->locate_data(path, chnk_id); + for(uint64_t chnk_id = chnk_start; chnk_id <= chnk_end; chnk_id++) { + const auto chnk_host_id = + CTX->distributor()->locate_data(path, chnk_id); /* - * If the chnk host matches the metadata host the remove request as already been sent - * as part of the metadata remove request. + * If the chnk host matches the metadata host the remove request + * as already been sent as part of the metadata remove request. */ - if (chnk_host_id == metadata_host_id) + if(chnk_host_id == metadata_host_id) continue; const auto endp_chnk = CTX->hosts().at(chnk_host_id); LOG(DEBUG, "Sending RPC to host: {}", endp_chnk.to_string()); - handles.emplace_back(ld_network_service->post(endp_chnk, in)); + handles.emplace_back( + ld_network_service->post(endp_chnk, + in)); } - } catch (const std::exception& ex) { - LOG(ERROR, "Failed to forward non-blocking rpc request reduced remove requests"); + } catch(const std::exception& ex) { + LOG(ERROR, + "Failed to forward non-blocking rpc request reduced remove requests"); return EBUSY; } - } else { // "Big" files - for (const auto& endp : CTX->hosts()) { + } else { // "Big" files + for(const auto& endp : CTX->hosts()) { try { LOG(DEBUG, "Sending RPC to host: {}", endp.to_string()); gkfs::rpc::remove::input in(path); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that - // we can retry for RPC_TRIES (see old commits with margo) - // TODO(amiranda): hermes will eventually provide a post(endpoint) - // returning one result and a broadcast(endpoint_set) returning a - // result_set. When that happens we can remove the .at(0) :/ - - handles.emplace_back(ld_network_service->post(endp, in)); - - } catch (const std::exception& ex) { - // TODO(amiranda): we should cancel all previously posted requests - // here, unfortunately, Hermes does not support it yet :/ - LOG(ERROR, "Failed to forward non-blocking rpc request to host: {}", + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so + // that we can retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): hermes will eventually provide a + // post(endpoint) returning one result and a + // broadcast(endpoint_set) returning a result_set. When that + // happens we can remove the .at(0) :/ + + handles.emplace_back( + ld_network_service->post(endp, in)); + + } catch(const std::exception& ex) { + // TODO(amiranda): we should cancel all previously posted + // requests here, unfortunately, Hermes does not support it yet + // :/ + LOG(ERROR, + "Failed to forward non-blocking rpc request to host: {}", endp.to_string()); return EBUSY; } @@ -185,17 +209,17 @@ int forward_remove(const std::string& path, const bool remove_metadentry_only, c } // wait for RPC responses auto err = 0; - for (const auto& h : handles) { + for(const auto& h : handles) { try { // XXX We might need a timeout here to not wait forever for an // output that never comes? auto out = h.get().at(0); - if (out.err() != 0) { + if(out.err() != 0) { LOG(ERROR, "received error response: {}", out.err()); err = out.err(); } - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); err = EBUSY; } @@ -204,28 +228,33 @@ int forward_remove(const std::string& path, const bool remove_metadentry_only, c } /** - * Send an RPC for a decrement file size request. This is for example used during a truncate() call. + * Send an RPC for a decrement file size request. This is for example used + * during a truncate() call. * @param path * @param length * @return error code */ -int forward_decr_size(const std::string& path, size_t length) { +int +forward_decr_size(const std::string& path, size_t length) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post(endp, path, length).get().at(0); + auto out = ld_network_service + ->post(endp, path, length) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); return out.err() ? out.err() : 0; - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return EBUSY; } @@ -240,42 +269,45 @@ int forward_decr_size(const std::string& path, size_t length) { * @param md_flags * @return error code */ -int forward_update_metadentry(const string& path, const gkfs::metadata::Metadata& md, - const gkfs::metadata::MetadentryUpdateFlags& md_flags) { +int +forward_update_metadentry( + const string& path, const gkfs::metadata::Metadata& md, + const gkfs::metadata::MetadentryUpdateFlags& md_flags) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post( - endp, - path, - (md_flags.link_count ? md.link_count() : 0), - /* mode */ 0, - /* uid */ 0, - /* gid */ 0, - (md_flags.size ? md.size() : 0), - (md_flags.blocks ? md.blocks() : 0), - (md_flags.atime ? md.atime() : 0), - (md_flags.mtime ? md.mtime() : 0), - (md_flags.ctime ? md.ctime() : 0), - bool_to_merc_bool(md_flags.link_count), - /* mode_flag */ false, - bool_to_merc_bool(md_flags.size), - bool_to_merc_bool(md_flags.blocks), - bool_to_merc_bool(md_flags.atime), - bool_to_merc_bool(md_flags.mtime), - bool_to_merc_bool(md_flags.ctime)).get().at(0); + auto out = ld_network_service + ->post( + endp, path, + (md_flags.link_count ? md.link_count() : 0), + /* mode */ 0, + /* uid */ 0, + /* gid */ 0, (md_flags.size ? md.size() : 0), + (md_flags.blocks ? md.blocks() : 0), + (md_flags.atime ? md.atime() : 0), + (md_flags.mtime ? md.mtime() : 0), + (md_flags.ctime ? md.ctime() : 0), + bool_to_merc_bool(md_flags.link_count), + /* mode_flag */ false, + bool_to_merc_bool(md_flags.size), + bool_to_merc_bool(md_flags.blocks), + bool_to_merc_bool(md_flags.atime), + bool_to_merc_bool(md_flags.mtime), + bool_to_merc_bool(md_flags.ctime)) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); return out.err() ? out.err() : 0; - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return EBUSY; } @@ -291,27 +323,31 @@ int forward_update_metadentry(const string& path, const gkfs::metadata::Metadata * @return pair */ pair -forward_update_metadentry_size(const string& path, const size_t size, const off64_t offset, const bool append_flag) { +forward_update_metadentry_size(const string& path, const size_t size, + const off64_t offset, const bool append_flag) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post( - endp, path, size, offset, - bool_to_merc_bool(append_flag)).get().at(0); + auto out = ld_network_service + ->post( + endp, path, size, offset, + bool_to_merc_bool(append_flag)) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); - if (out.err()) + if(out.err()) return make_pair(out.err(), 0); else return make_pair(0, out.ret_size()); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return make_pair(EBUSY, 0); } @@ -323,26 +359,30 @@ forward_update_metadentry_size(const string& path, const size_t size, const off6 * @param path * @return pair */ -pair forward_get_metadentry_size(const std::string& path) { +pair +forward_get_metadentry_size(const std::string& path) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post(endp, path).get().at(0); + auto out = ld_network_service + ->post(endp, path) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); - if (out.err()) + if(out.err()) return make_pair(out.err(), 0); else return make_pair(0, out.ret_size()); - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return make_pair(EBUSY, 0); } @@ -353,7 +393,8 @@ pair forward_get_metadentry_size(const std::string& path) { * @param open_dir * @return error code */ -pair> forward_get_dirents(const string& path) { +pair> +forward_get_dirents(const string& path) { LOG(DEBUG, "{}() enter for path '{}'", __func__, path) @@ -365,27 +406,27 @@ pair> forward_get_dirents(const string& * It turns out that this operation is increadibly slow for such a big * buffer. Moreover we don't need a zeroed buffer here. */ - auto large_buffer = std::unique_ptr(new char[gkfs::config::rpc::dirents_buff_size]); + auto large_buffer = std::unique_ptr( + new char[gkfs::config::rpc::dirents_buff_size]); - //XXX there is a rounding error here depending on the number of targets... - const std::size_t per_host_buff_size = gkfs::config::rpc::dirents_buff_size / targets.size(); + // XXX there is a rounding error here depending on the number of targets... + const std::size_t per_host_buff_size = + gkfs::config::rpc::dirents_buff_size / targets.size(); // expose local buffers for RMA from servers std::vector exposed_buffers; exposed_buffers.reserve(targets.size()); - for (std::size_t i = 0; i < targets.size(); ++i) { + for(std::size_t i = 0; i < targets.size(); ++i) { try { exposed_buffers.emplace_back(ld_network_service->expose( - std::vector{ - hermes::mutable_buffer{ - large_buffer.get() + (i * per_host_buff_size), - per_host_buff_size - } - }, + std::vector{hermes::mutable_buffer{ + large_buffer.get() + (i * per_host_buff_size), + per_host_buff_size}}, hermes::access_mode::write_only)); - } catch (const std::exception& ex) { - LOG(ERROR, "{}() Failed to expose buffers for RMA. err '{}'", __func__, ex.what()); + } catch(const std::exception& ex) { + LOG(ERROR, "{}() Failed to expose buffers for RMA. err '{}'", + __func__, ex.what()); return make_pair(EBUSY, nullptr); } } @@ -394,7 +435,7 @@ pair> forward_get_dirents(const string& // send RPCs std::vector> handles; - for (std::size_t i = 0; i < targets.size(); ++i) { + for(std::size_t i = 0; i < targets.size(); ++i) { // Setup rpc input parameters for each host auto endp = CTX->hosts().at(targets[i]); @@ -403,10 +444,12 @@ pair> forward_get_dirents(const string& try { LOG(DEBUG, "{}() Sending RPC to host: '{}'", __func__, targets[i]); - handles.emplace_back(ld_network_service->post(endp, in)); - } catch (const std::exception& ex) { - LOG(ERROR, "{}() Unable to send non-blocking get_dirents() on {} [peer: {}] err '{}'", __func__, path, - targets[i], ex.what()); + handles.emplace_back( + ld_network_service->post(endp, in)); + } catch(const std::exception& ex) { + LOG(ERROR, + "{}() Unable to send non-blocking get_dirents() on {} [peer: {}] err '{}'", + __func__, path, targets[i], ex.what()); err = EBUSY; break; // we need to gather responses from already sent RPCS } @@ -419,7 +462,7 @@ pair> forward_get_dirents(const string& auto send_error = err != 0; auto open_dir = make_shared(path); // wait for RPC responses - for (std::size_t i = 0; i < handles.size(); ++i) { + for(std::size_t i = 0; i < handles.size(); ++i) { gkfs::rpc::get_dirents::output out; @@ -428,21 +471,23 @@ pair> forward_get_dirents(const string& // output that never comes? out = handles[i].get().at(0); // skip processing dirent data if there was an error during send - // In this case all responses are gathered but their contents skipped - if (send_error) + // In this case all responses are gathered but their contents + // skipped + if(send_error) continue; - if (out.err() != 0) { - LOG(ERROR, "{}() Failed to retrieve dir entries from host '{}'. Error '{}', path '{}'", __func__, - targets[i], - strerror(out.err()), path); + if(out.err() != 0) { + LOG(ERROR, + "{}() Failed to retrieve dir entries from host '{}'. Error '{}', path '{}'", + __func__, targets[i], strerror(out.err()), path); err = out.err(); // We need to gather all responses before exiting continue; } - } catch (const std::exception& ex) { - LOG(ERROR, "{}() Failed to get rpc output.. [path: {}, target host: {}] err '{}'", __func__, path, - targets[i], ex.what()); + } catch(const std::exception& ex) { + LOG(ERROR, + "{}() Failed to get rpc output.. [path: {}, target host: {}] err '{}'", + __func__, path, targets[i], ex.what()); err = EBUSY; // We need to gather all responses before exiting continue; @@ -455,17 +500,22 @@ pair> forward_get_dirents(const string& void* base_ptr = exposed_buffers[i].begin()->data(); bool* bool_ptr = reinterpret_cast(base_ptr); - char* names_ptr = reinterpret_cast(base_ptr) + (out.dirents_size() * sizeof(bool)); + char* names_ptr = reinterpret_cast(base_ptr) + + (out.dirents_size() * sizeof(bool)); - for (std::size_t j = 0; j < out.dirents_size(); j++) { + for(std::size_t j = 0; j < out.dirents_size(); j++) { - gkfs::filemap::FileType ftype = (*bool_ptr) ? gkfs::filemap::FileType::directory - : gkfs::filemap::FileType::regular; + gkfs::filemap::FileType ftype = + (*bool_ptr) ? gkfs::filemap::FileType::directory + : gkfs::filemap::FileType::regular; bool_ptr++; - // Check that we are not outside the recv_buff for this specific host + // Check that we are not outside the recv_buff for this specific + // host assert((names_ptr - reinterpret_cast(base_ptr)) > 0); - assert(static_cast(names_ptr - reinterpret_cast(base_ptr)) < per_host_buff_size); + assert(static_cast( + names_ptr - reinterpret_cast(base_ptr)) < + per_host_buff_size); auto name = std::string(names_ptr); // number of characters in entry + \0 terminator @@ -485,23 +535,28 @@ pair> forward_get_dirents(const string& * @param target_path * @return error code */ -int forward_mk_symlink(const std::string& path, const std::string& target_path) { +int +forward_mk_symlink(const std::string& path, const std::string& target_path) { auto endp = CTX->hosts().at(CTX->distributor()->locate_file_metadata(path)); try { LOG(DEBUG, "Sending RPC ..."); - // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can - // retry for RPC_TRIES (see old commits with margo) + // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we + // can retry for RPC_TRIES (see old commits with margo) // TODO(amiranda): hermes will eventually provide a post(endpoint) // returning one result and a broadcast(endpoint_set) returning a // result_set. When that happens we can remove the .at(0) :/ - auto out = ld_network_service->post(endp, path, target_path).get().at(0); + auto out = + ld_network_service + ->post(endp, path, target_path) + .get() + .at(0); LOG(DEBUG, "Got response success: {}", out.err()); return out.err() ? out.err() : 0; - } catch (const std::exception& ex) { + } catch(const std::exception& ex) { LOG(ERROR, "while getting rpc output"); return EBUSY; } diff --git a/src/client/rpc/rpc_types.cpp b/src/client/rpc/rpc_types.cpp index 7aaffaae1..61b920e02 100644 --- a/src/client/rpc/rpc_types.cpp +++ b/src/client/rpc/rpc_types.cpp @@ -17,7 +17,8 @@ //============================================================================== // register request types so that they can be used by users and the engine // -void hermes::detail::register_user_request_types() { +void +hermes::detail::register_user_request_types() { (void) registered_requests().add(); (void) registered_requests().add(); (void) registered_requests().add(); @@ -36,5 +37,4 @@ void hermes::detail::register_user_request_types() { (void) registered_requests().add(); (void) registered_requests().add(); (void) registered_requests().add(); - } \ No newline at end of file diff --git a/src/daemon/backend/data/chunk_storage.cpp b/src/daemon/backend/data/chunk_storage.cpp index b4c4e116b..b6b6aa190 100644 --- a/src/daemon/backend/data/chunk_storage.cpp +++ b/src/daemon/backend/data/chunk_storage.cpp @@ -33,19 +33,23 @@ namespace data { // private functions -string ChunkStorage::absolute(const string& internal_path) const { +string +ChunkStorage::absolute(const string& internal_path) const { assert(gkfs::path::is_relative(internal_path)); return fmt::format("{}/{}", root_path_, internal_path); } -string ChunkStorage::get_chunks_dir(const string& file_path) { +string +ChunkStorage::get_chunks_dir(const string& file_path) { assert(gkfs::path::is_absolute(file_path)); string chunk_dir = file_path.substr(1); ::replace(chunk_dir.begin(), chunk_dir.end(), '/', ':'); return chunk_dir; } -string ChunkStorage::get_chunk_path(const string& file_path, gkfs::rpc::chnk_id_t chunk_id) { +string +ChunkStorage::get_chunk_path(const string& file_path, + gkfs::rpc::chnk_id_t chunk_id) { return fmt::format("{}/{}", get_chunks_dir(file_path), chunk_id); } @@ -55,12 +59,14 @@ string ChunkStorage::get_chunk_path(const string& file_path, gkfs::rpc::chnk_id_ * @param file_path * @throws ChunkStorageException on error */ -void ChunkStorage::init_chunk_space(const string& file_path) const { +void +ChunkStorage::init_chunk_space(const string& file_path) const { auto chunk_dir = absolute(get_chunks_dir(file_path)); auto err = mkdir(chunk_dir.c_str(), 0750); - if (err == -1 && errno != EEXIST) { - auto err_str = fmt::format("{}() Failed to create chunk directory. File: '{}', Error: '{}'", __func__, - file_path, errno); + if(err == -1 && errno != EEXIST) { + auto err_str = fmt::format( + "{}() Failed to create chunk directory. File: '{}', Error: '{}'", + __func__, file_path, errno); throw ChunkStorageException(errno, err_str); } } @@ -73,9 +79,8 @@ void ChunkStorage::init_chunk_space(const string& file_path) const { * @param chunksize * @throws ChunkStorageException */ -ChunkStorage::ChunkStorage(string& path, const size_t chunksize) : - root_path_(path), - chunksize_(chunksize) { +ChunkStorage::ChunkStorage(string& path, const size_t chunksize) + : root_path_(path), chunksize_(chunksize) { /* Get logger instance and set it for data module and chunk storage */ GKFS_DATA_MOD->log(spdlog::get(GKFS_DATA_MOD->LOGGER_NAME)); assert(GKFS_DATA_MOD->log()); @@ -83,12 +88,14 @@ ChunkStorage::ChunkStorage(string& path, const size_t chunksize) : assert(log_); assert(gkfs::path::is_absolute(root_path_)); // Verify that we have sufficient access for chunk directories - if (access(root_path_.c_str(), W_OK | R_OK) != 0) { - auto err_str = fmt::format("{}() Insufficient permissions to create chunk directories in path '{}'", __func__, - root_path_); + if(access(root_path_.c_str(), W_OK | R_OK) != 0) { + auto err_str = fmt::format( + "{}() Insufficient permissions to create chunk directories in path '{}'", + __func__, root_path_); throw ChunkStorageException(EPERM, err_str); } - log_->debug("{}() Chunk storage initialized with path: '{}'", __func__, root_path_); + log_->debug("{}() Chunk storage initialized with path: '{}'", __func__, + root_path_); } /** @@ -96,15 +103,18 @@ ChunkStorage::ChunkStorage(string& path, const size_t chunksize) : * @param file_path * @throws ChunkStorageException */ -void ChunkStorage::destroy_chunk_space(const string& file_path) const { +void +ChunkStorage::destroy_chunk_space(const string& file_path) const { auto chunk_dir = absolute(get_chunks_dir(file_path)); try { // Note: remove_all does not throw an error when path doesn't exist. auto n = bfs::remove_all(chunk_dir); - log_->debug("{}() Removed '{}' files from '{}'", __func__, n, chunk_dir); - } catch (const bfs::filesystem_error& e) { - auto err_str = fmt::format("{}() Failed to remove chunk directory. Path: '{}', Error: '{}'", __func__, - chunk_dir, e.what()); + log_->debug("{}() Removed '{}' files from '{}'", __func__, n, + chunk_dir); + } catch(const bfs::filesystem_error& e) { + auto err_str = fmt::format( + "{}() Failed to remove chunk directory. Path: '{}', Error: '{}'", + __func__, chunk_dir, e.what()); throw ChunkStorageException(e.code().value(), err_str); } } @@ -113,7 +123,9 @@ void ChunkStorage::destroy_chunk_space(const string& file_path) const { * Writes a chunk file. * On failure throws ChunkStorageException with encapsulated error code * - * Refer to https://www.gnu.org/software/libc/manual/html_node/I_002fO-Primitives.html for pwrite behavior + * Refer to + * https://www.gnu.org/software/libc/manual/html_node/I_002fO-Primitives.html + * for pwrite behavior * * @param file_path * @param chunk_id @@ -124,8 +136,9 @@ void ChunkStorage::destroy_chunk_space(const string& file_path) const { * @throws ChunkStorageException (caller will handle eventual signalling) */ ssize_t -ChunkStorage::write_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id, const char* buf, size_t size, - off64_t offset) const { +ChunkStorage::write_chunk(const string& file_path, + gkfs::rpc::chnk_id_t chunk_id, const char* buf, + size_t size, off64_t offset) const { assert((offset + size) <= chunksize_); // may throw ChunkStorageException on failure @@ -133,10 +146,12 @@ ChunkStorage::write_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id auto chunk_path = absolute(get_chunk_path(file_path, chunk_id)); - FileHandle fh(open(chunk_path.c_str(), O_WRONLY | O_CREAT, 0640), chunk_path); - if (!fh.valid()) { - auto err_str = fmt::format("{}() Failed to open chunk file for write. File: '{}', Error: '{}'", __func__, - chunk_path, ::strerror(errno)); + FileHandle fh(open(chunk_path.c_str(), O_WRONLY | O_CREAT, 0640), + chunk_path); + if(!fh.valid()) { + auto err_str = fmt::format( + "{}() Failed to open chunk file for write. File: '{}', Error: '{}'", + __func__, chunk_path, ::strerror(errno)); throw ChunkStorageException(errno, err_str); } @@ -144,14 +159,13 @@ ChunkStorage::write_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id ssize_t wrote{}; do { - wrote = pwrite(fh.native(), - buf + wrote_total, - size - wrote_total, + wrote = pwrite(fh.native(), buf + wrote_total, size - wrote_total, offset + wrote_total); - if (wrote < 0) { - // retry if a signal or anything else has interrupted the read system call - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + if(wrote < 0) { + // retry if a signal or anything else has interrupted the read + // system call + if(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue; auto err_str = fmt::format( "{}() Failed to write chunk file. File: '{}', size: '{}', offset: '{}', Error: '{}'", @@ -159,7 +173,7 @@ ChunkStorage::write_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id throw ChunkStorageException(errno, err_str); } wrote_total += wrote; - } while (wrote_total != size); + } while(wrote_total != size); // file is closed via the file handle's destructor. return wrote_total; @@ -169,7 +183,9 @@ ChunkStorage::write_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id * Read from a chunk file. * On failure throws ChunkStorageException with encapsulated error code * - * Refer to https://www.gnu.org/software/libc/manual/html_node/I_002fO-Primitives.html for pread behavior + * Refer to + * https://www.gnu.org/software/libc/manual/html_node/I_002fO-Primitives.html + * for pread behavior * @param file_path * @param chunk_id * @param buf @@ -179,90 +195,101 @@ ChunkStorage::write_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id * @throws ChunkStorageException (caller will handle eventual signalling) */ ssize_t -ChunkStorage::read_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id, char* buf, size_t size, - off64_t offset) const { +ChunkStorage::read_chunk(const string& file_path, gkfs::rpc::chnk_id_t chunk_id, + char* buf, size_t size, off64_t offset) const { assert((offset + size) <= chunksize_); auto chunk_path = absolute(get_chunk_path(file_path, chunk_id)); FileHandle fh(open(chunk_path.c_str(), O_RDONLY), chunk_path); - if (!fh.valid()) { - auto err_str = fmt::format("{}() Failed to open chunk file for read. File: '{}', Error: '{}'", __func__, - chunk_path, ::strerror(errno)); + if(!fh.valid()) { + auto err_str = fmt::format( + "{}() Failed to open chunk file for read. File: '{}', Error: '{}'", + __func__, chunk_path, ::strerror(errno)); throw ChunkStorageException(errno, err_str); } size_t read_total = 0; ssize_t read = 0; do { - read = pread64(fh.native(), - buf + read_total, - size - read_total, + read = pread64(fh.native(), buf + read_total, size - read_total, offset + read_total); - if (read == 0) { + if(read == 0) { /* - * A value of zero indicates end-of-file (except if the value of the size argument is also zero). - * This is not considered an error. If you keep calling read while at end-of-file, - * it will keep returning zero and doing nothing else. - * Hence, we break here. + * A value of zero indicates end-of-file (except if the value of the + * size argument is also zero). This is not considered an error. If + * you keep calling read while at end-of-file, it will keep + * returning zero and doing nothing else. Hence, we break here. */ break; } - if (read < 0) { - // retry if a signal or anything else has interrupted the read system call - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + if(read < 0) { + // retry if a signal or anything else has interrupted the read + // system call + if(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) continue; - auto err_str = fmt::format("Failed to read chunk file. File: '{}', size: '{}', offset: '{}', Error: '{}'", - chunk_path, size, offset, ::strerror(errno)); + auto err_str = fmt::format( + "Failed to read chunk file. File: '{}', size: '{}', offset: '{}', Error: '{}'", + chunk_path, size, offset, ::strerror(errno)); throw ChunkStorageException(errno, err_str); } #ifndef NDEBUG - if (read_total + read < size) { - log_->debug("Read less bytes than requested: '{}'/{}. Total read was '{}'. This is not an error!", read, - size - read_total, size); + if(read_total + read < size) { + log_->debug( + "Read less bytes than requested: '{}'/{}. Total read was '{}'. This is not an error!", + read, size - read_total, size); } #endif assert(read > 0); read_total += read; - } while (read_total != size); + } while(read_total != size); // file is closed via the file handle's destructor. return read_total; } /** -* Delete all chunks starting with chunk a chunk id. -* Note eventual consistency here: While chunks are removed, there is no lock that prevents -* other processes from modifying anything in that directory. -* It is the application's responsibility to stop modifying the file while truncate is executed -* -* If an error is encountered when removing a chunk file, the function will still remove all files and -* report the error afterwards with ChunkStorageException. + * Delete all chunks starting with chunk a chunk id. + * Note eventual consistency here: While chunks are removed, there is no lock + * that prevents other processes from modifying anything in that directory. It + * is the application's responsibility to stop modifying the file while truncate + * is executed + * + * If an error is encountered when removing a chunk file, the function will + * still remove all files and report the error afterwards with + * ChunkStorageException. * @param file_path * @param chunk_start * @throws ChunkStorageException */ -void ChunkStorage::trim_chunk_space(const string& file_path, gkfs::rpc::chnk_id_t chunk_start) { +void +ChunkStorage::trim_chunk_space(const string& file_path, + gkfs::rpc::chnk_id_t chunk_start) { auto chunk_dir = absolute(get_chunks_dir(file_path)); const bfs::directory_iterator end; auto err_flag = false; - for (bfs::directory_iterator chunk_file(chunk_dir); chunk_file != end; ++chunk_file) { + for(bfs::directory_iterator chunk_file(chunk_dir); chunk_file != end; + ++chunk_file) { auto chunk_path = chunk_file->path(); auto chunk_id = std::stoul(chunk_path.filename().c_str()); - if (chunk_id >= chunk_start) { + if(chunk_id >= chunk_start) { auto err = unlink(chunk_path.c_str()); - if (err == -1 && errno != ENOENT) { + if(err == -1 && errno != ENOENT) { err_flag = true; - log_->warn("{}() Failed to remove chunk file. File: '{}', Error: '{}'", __func__, chunk_path.native(), - ::strerror(errno)); + log_->warn( + "{}() Failed to remove chunk file. File: '{}', Error: '{}'", + __func__, chunk_path.native(), ::strerror(errno)); } } } - if (err_flag) - throw ChunkStorageException(EIO, fmt::format("{}() One or more errors occurred when truncating '{}'", __func__, - file_path)); + if(err_flag) + throw ChunkStorageException( + EIO, + fmt::format( + "{}() One or more errors occurred when truncating '{}'", + __func__, file_path)); } /** @@ -272,41 +299,45 @@ void ChunkStorage::trim_chunk_space(const string& file_path, gkfs::rpc::chnk_id_ * @param length * @throws ChunkStorageException */ -void ChunkStorage::truncate_chunk_file(const string& file_path, gkfs::rpc::chnk_id_t chunk_id, off_t length) { +void +ChunkStorage::truncate_chunk_file(const string& file_path, + gkfs::rpc::chnk_id_t chunk_id, off_t length) { auto chunk_path = absolute(get_chunk_path(file_path, chunk_id)); - assert(length > 0 && static_cast(length) <= chunksize_); + assert(length > 0 && + static_cast(length) <= chunksize_); auto ret = truncate(chunk_path.c_str(), length); - if (ret == -1) { - auto err_str = fmt::format("Failed to truncate chunk file. File: '{}', Error: '{}'", chunk_path, - ::strerror(errno)); + if(ret == -1) { + auto err_str = fmt::format( + "Failed to truncate chunk file. File: '{}', Error: '{}'", + chunk_path, ::strerror(errno)); throw ChunkStorageException(errno, err_str); } } /** - * Calls statfs on the chunk directory to get statistic on its used and free size left + * Calls statfs on the chunk directory to get statistic on its used and free + * size left * @return ChunkStat * @throws ChunkStorageException */ -ChunkStat ChunkStorage::chunk_stat() const { - struct statfs sfs{}; - - if (statfs(root_path_.c_str(), &sfs) != 0) { - auto err_str = fmt::format("Failed to get filesystem statistic for chunk directory. Error: '{}'", - ::strerror(errno)); +ChunkStat +ChunkStorage::chunk_stat() const { + struct statfs sfs {}; + + if(statfs(root_path_.c_str(), &sfs) != 0) { + auto err_str = fmt::format( + "Failed to get filesystem statistic for chunk directory. Error: '{}'", + ::strerror(errno)); throw ChunkStorageException(errno, err_str); } - log_->debug("Chunksize '{}', total '{}', free '{}'", sfs.f_bsize, sfs.f_blocks, sfs.f_bavail); - auto bytes_total = - static_cast(sfs.f_bsize) * - static_cast(sfs.f_blocks); - auto bytes_free = - static_cast(sfs.f_bsize) * - static_cast(sfs.f_bavail); - return {chunksize_, - bytes_total / chunksize_, - bytes_free / chunksize_}; + log_->debug("Chunksize '{}', total '{}', free '{}'", sfs.f_bsize, + sfs.f_blocks, sfs.f_bavail); + auto bytes_total = static_cast(sfs.f_bsize) * + static_cast(sfs.f_blocks); + auto bytes_free = static_cast(sfs.f_bsize) * + static_cast(sfs.f_bavail); + return {chunksize_, bytes_total / chunksize_, bytes_free / chunksize_}; } } // namespace data diff --git a/src/daemon/backend/data/data_module.cpp b/src/daemon/backend/data/data_module.cpp index 42391cc0f..781af08f5 100644 --- a/src/daemon/backend/data/data_module.cpp +++ b/src/daemon/backend/data/data_module.cpp @@ -16,11 +16,13 @@ namespace gkfs { namespace data { -const std::shared_ptr& DataModule::log() const { +const std::shared_ptr& +DataModule::log() const { return log_; } -void DataModule::log(const std::shared_ptr& log) { +void +DataModule::log(const std::shared_ptr& log) { DataModule::log_ = log; } diff --git a/src/daemon/backend/metadata/db.cpp b/src/daemon/backend/metadata/db.cpp index f0226ce22..f9f61d0d8 100644 --- a/src/daemon/backend/metadata/db.cpp +++ b/src/daemon/backend/metadata/db.cpp @@ -37,54 +37,59 @@ MetadataDB::MetadataDB(const std::string& path) : path(path) { write_opts.disableWAL = !(gkfs::config::rocksdb::use_write_ahead_log); rdb::DB* rdb_ptr; auto s = rocksdb::DB::Open(options, path, &rdb_ptr); - if (!s.ok()) { + if(!s.ok()) { throw std::runtime_error("Failed to open RocksDB: " + s.ToString()); } this->db.reset(rdb_ptr); } -void MetadataDB::throw_rdb_status_excpt(const rdb::Status& s) { +void +MetadataDB::throw_rdb_status_excpt(const rdb::Status& s) { assert(!s.ok()); - if (s.IsNotFound()) { + if(s.IsNotFound()) { throw NotFoundException(s.ToString()); } else { throw DBException(s.ToString()); } } -std::string MetadataDB::get(const std::string& key) const { +std::string +MetadataDB::get(const std::string& key) const { std::string val; auto s = db->Get(rdb::ReadOptions(), key, &val); - if (!s.ok()) { + if(!s.ok()) { MetadataDB::throw_rdb_status_excpt(s); } return val; } -void MetadataDB::put(const std::string& key, const std::string& val) { +void +MetadataDB::put(const std::string& key, const std::string& val) { assert(gkfs::path::is_absolute(key)); assert(key == "/" || !gkfs::path::has_trailing_slash(key)); auto cop = CreateOperand(val); auto s = db->Merge(write_opts, key, cop.serialize()); - if (!s.ok()) { + if(!s.ok()) { MetadataDB::throw_rdb_status_excpt(s); } } -void MetadataDB::remove(const std::string& key) { +void +MetadataDB::remove(const std::string& key) { auto s = db->Delete(write_opts, key); - if (!s.ok()) { + if(!s.ok()) { MetadataDB::throw_rdb_status_excpt(s); } } -bool MetadataDB::exists(const std::string& key) { +bool +MetadataDB::exists(const std::string& key) { std::string val; auto s = db->Get(rdb::ReadOptions(), key, &val); - if (!s.ok()) { - if (s.IsNotFound()) { + if(!s.ok()) { + if(s.IsNotFound()) { return false; } else { MetadataDB::throw_rdb_status_excpt(s); @@ -100,29 +105,33 @@ bool MetadataDB::exists(const std::string& key) { * @param val * @return */ -void MetadataDB::update(const std::string& old_key, const std::string& new_key, const std::string& val) { - //TODO use rdb::Put() method +void +MetadataDB::update(const std::string& old_key, const std::string& new_key, + const std::string& val) { + // TODO use rdb::Put() method rdb::WriteBatch batch; batch.Delete(old_key); batch.Put(new_key, val); auto s = db->Write(write_opts, &batch); - if (!s.ok()) { + if(!s.ok()) { MetadataDB::throw_rdb_status_excpt(s); } } -void MetadataDB::increase_size(const std::string& key, size_t size, bool append) { +void +MetadataDB::increase_size(const std::string& key, size_t size, bool append) { auto uop = IncreaseSizeOperand(size, append); auto s = db->Merge(write_opts, key, uop.serialize()); - if (!s.ok()) { + if(!s.ok()) { MetadataDB::throw_rdb_status_excpt(s); } } -void MetadataDB::decrease_size(const std::string& key, size_t size) { +void +MetadataDB::decrease_size(const std::string& key, size_t size) { auto uop = DecreaseSizeOperand(size); auto s = db->Merge(write_opts, key, uop.serialize()); - if (!s.ok()) { + if(!s.ok()) { MetadataDB::throw_rdb_status_excpt(s); } } @@ -134,12 +143,13 @@ void MetadataDB::decrease_size(const std::string& key, size_t size) { * where name is the name of the entries and is_dir * is true in the case the entry is a directory. */ -std::vector> MetadataDB::get_dirents(const std::string& dir) const { +std::vector> +MetadataDB::get_dirents(const std::string& dir) const { auto root_path = dir; assert(gkfs::path::is_absolute(root_path)); - //add trailing slash if missing - if (!gkfs::path::has_trailing_slash(root_path) && root_path.size() != 1) { - //add trailing slash only if missing and is not the root_folder "/" + // add trailing slash if missing + if(!gkfs::path::has_trailing_slash(root_path) && root_path.size() != 1) { + // add trailing slash only if missing and is not the root_folder "/" root_path.push_back('/'); } @@ -148,26 +158,24 @@ std::vector> MetadataDB::get_dirents(const std::str std::vector> entries; - for (it->Seek(root_path); - it->Valid() && - it->key().starts_with(root_path); - it->Next()) { + for(it->Seek(root_path); it->Valid() && it->key().starts_with(root_path); + it->Next()) { - if (it->key().size() == root_path.size()) { - //we skip this path cause it is exactly the root_path + if(it->key().size() == root_path.size()) { + // we skip this path cause it is exactly the root_path continue; } /***** Get File name *****/ auto name = it->key().ToString(); - if (name.find_first_of('/', root_path.size()) != std::string::npos) { - //skip stuff deeper then one level depth + if(name.find_first_of('/', root_path.size()) != std::string::npos) { + // skip stuff deeper then one level depth continue; } // remove prefix name = name.substr(root_path.size()); - //relative path of directory entries must not be empty + // relative path of directory entries must not be empty assert(!name.empty()); Metadata md(it->value().ToString()); @@ -179,18 +187,20 @@ std::vector> MetadataDB::get_dirents(const std::str return entries; } -void MetadataDB::iterate_all() { +void +MetadataDB::iterate_all() { std::string key; std::string val; // Do RangeScan on parent inode auto iter = db->NewIterator(rdb::ReadOptions()); - for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { + for(iter->SeekToFirst(); iter->Valid(); iter->Next()) { key = iter->key().ToString(); val = iter->value().ToString(); } } -void MetadataDB::optimize_rocksdb_options(rdb::Options& options) { +void +MetadataDB::optimize_rocksdb_options(rdb::Options& options) { options.max_successive_merges = 128; } diff --git a/src/daemon/backend/metadata/merge.cpp b/src/daemon/backend/metadata/merge.cpp index be101f780..30591d9bd 100644 --- a/src/daemon/backend/metadata/merge.cpp +++ b/src/daemon/backend/metadata/merge.cpp @@ -19,7 +19,8 @@ using namespace std; namespace gkfs { namespace metadata { -string MergeOperand::serialize_id() const { +string +MergeOperand::serialize_id() const { string s; s.reserve(2); s += (char) id(); // TODO check if static_cast can be used @@ -27,46 +28,51 @@ string MergeOperand::serialize_id() const { return s; } -string MergeOperand::serialize() const { +string +MergeOperand::serialize() const { string s = serialize_id(); s += serialize_params(); return s; } -OperandID MergeOperand::get_id(const rdb::Slice& serialized_op) { +OperandID +MergeOperand::get_id(const rdb::Slice& serialized_op) { return static_cast(serialized_op[0]); } -rdb::Slice MergeOperand::get_params(const rdb::Slice& serialized_op) { +rdb::Slice +MergeOperand::get_params(const rdb::Slice& serialized_op) { assert(serialized_op[1] == operand_id_suffix); return {serialized_op.data() + 2, serialized_op.size() - 2}; } -IncreaseSizeOperand::IncreaseSizeOperand(const size_t size, const bool append) : - size(size), append(append) {} +IncreaseSizeOperand::IncreaseSizeOperand(const size_t size, const bool append) + : size(size), append(append) {} IncreaseSizeOperand::IncreaseSizeOperand(const rdb::Slice& serialized_op) { size_t chrs_parsed = 0; size_t read = 0; - //Parse size + // Parse size size = ::stoul(serialized_op.data() + chrs_parsed, &read); chrs_parsed += read + 1; assert(serialized_op[chrs_parsed - 1] == separator); - //Parse append flag + // Parse append flag assert(serialized_op[chrs_parsed] == false_char || serialized_op[chrs_parsed] == true_char); append = serialized_op[chrs_parsed] != false_char; - //check that we consumed all the input string + // check that we consumed all the input string assert(chrs_parsed + 1 == serialized_op.size()); } -OperandID IncreaseSizeOperand::id() const { +OperandID +IncreaseSizeOperand::id() const { return OperandID::increase_size; } -string IncreaseSizeOperand::serialize_params() const { +string +IncreaseSizeOperand::serialize_params() const { string s; s.reserve(3); s += ::to_string(size); @@ -76,53 +82,57 @@ string IncreaseSizeOperand::serialize_params() const { } -DecreaseSizeOperand::DecreaseSizeOperand(const size_t size) : - size(size) {} +DecreaseSizeOperand::DecreaseSizeOperand(const size_t size) : size(size) {} DecreaseSizeOperand::DecreaseSizeOperand(const rdb::Slice& serialized_op) { - //Parse size + // Parse size size_t read = 0; - //we need to convert serialized_op to a string because it doesn't contain the - //leading slash needed by stoul + // we need to convert serialized_op to a string because it doesn't contain + // the leading slash needed by stoul size = ::stoul(serialized_op.ToString(), &read); - //check that we consumed all the input string + // check that we consumed all the input string assert(read == serialized_op.size()); } -OperandID DecreaseSizeOperand::id() const { +OperandID +DecreaseSizeOperand::id() const { return OperandID::decrease_size; } -string DecreaseSizeOperand::serialize_params() const { +string +DecreaseSizeOperand::serialize_params() const { return ::to_string(size); } CreateOperand::CreateOperand(const string& metadata) : metadata(metadata) {} -OperandID CreateOperand::id() const { +OperandID +CreateOperand::id() const { return OperandID::create; } -string CreateOperand::serialize_params() const { +string +CreateOperand::serialize_params() const { return metadata; } -bool MetadataMergeOperator::FullMergeV2( - const MergeOperationInput& merge_in, - MergeOperationOutput* merge_out) const { +bool +MetadataMergeOperator::FullMergeV2(const MergeOperationInput& merge_in, + MergeOperationOutput* merge_out) const { string prev_md_value; auto ops_it = merge_in.operand_list.cbegin(); - if (merge_in.existing_value == nullptr) { - //The key to operate on doesn't exists in DB - if (MergeOperand::get_id(ops_it[0]) != OperandID::create) { - throw ::runtime_error("Merge operation failed: key do not exists and first operand is not a creation"); + if(merge_in.existing_value == nullptr) { + // The key to operate on doesn't exists in DB + if(MergeOperand::get_id(ops_it[0]) != OperandID::create) { + throw ::runtime_error( + "Merge operation failed: key do not exists and first operand is not a creation"); // TODO use logger to print err info; - //Log(logger, "Key %s do not exists", existing_value->ToString().c_str()); - //return false; + // Log(logger, "Key %s do not exists", + // existing_value->ToString().c_str()); return false; } prev_md_value = MergeOperand::get_params(ops_it[0]).ToString(); ops_it++; @@ -134,28 +144,29 @@ bool MetadataMergeOperator::FullMergeV2( size_t fsize = md.size(); - for (; ops_it != merge_in.operand_list.cend(); ++ops_it) { + for(; ops_it != merge_in.operand_list.cend(); ++ops_it) { const rdb::Slice& serialized_op = *ops_it; assert(serialized_op.size() >= 2); auto operand_id = MergeOperand::get_id(serialized_op); auto parameters = MergeOperand::get_params(serialized_op); - if (operand_id == OperandID::increase_size) { + if(operand_id == OperandID::increase_size) { auto op = IncreaseSizeOperand(parameters); - if (op.append) { - //append mode, just increment file + if(op.append) { + // append mode, just increment file fsize += op.size; } else { fsize = ::max(op.size, fsize); } - } else if (operand_id == OperandID::decrease_size) { + } else if(operand_id == OperandID::decrease_size) { auto op = DecreaseSizeOperand(parameters); assert(op.size < fsize); // we assume no concurrency here fsize = op.size; - } else if (operand_id == OperandID::create) { + } else if(operand_id == OperandID::create) { continue; } else { - throw ::runtime_error("Unrecognized merge operand ID: " + (char) operand_id); + throw ::runtime_error("Unrecognized merge operand ID: " + + (char) operand_id); } } @@ -164,17 +175,20 @@ bool MetadataMergeOperator::FullMergeV2( return true; } -bool MetadataMergeOperator::PartialMergeMulti(const rdb::Slice& key, - const ::deque& operand_list, - string* new_value, rdb::Logger* logger) const { +bool +MetadataMergeOperator::PartialMergeMulti( + const rdb::Slice& key, const ::deque& operand_list, + string* new_value, rdb::Logger* logger) const { return false; } -const char* MetadataMergeOperator::Name() const { +const char* +MetadataMergeOperator::Name() const { return "MetadataMergeOperator"; } -bool MetadataMergeOperator::AllowSingleOperand() const { +bool +MetadataMergeOperator::AllowSingleOperand() const { return true; } diff --git a/src/daemon/classes/fs_data.cpp b/src/daemon/classes/fs_data.cpp index 241172525..cf117f063 100644 --- a/src/daemon/classes/fs_data.cpp +++ b/src/daemon/classes/fs_data.cpp @@ -20,135 +20,160 @@ namespace daemon { // getter/setter -const std::shared_ptr& FsData::spdlogger() const { +const std::shared_ptr& +FsData::spdlogger() const { return spdlogger_; } -void FsData::spdlogger(const std::shared_ptr& spdlogger) { +void +FsData::spdlogger(const std::shared_ptr& spdlogger) { FsData::spdlogger_ = spdlogger; } -const std::shared_ptr& FsData::mdb() const { +const std::shared_ptr& +FsData::mdb() const { return mdb_; } -void FsData::mdb(const std::shared_ptr& mdb) { +void +FsData::mdb(const std::shared_ptr& mdb) { mdb_ = mdb; } -void FsData::close_mdb() { +void +FsData::close_mdb() { mdb_.reset(); } -const std::shared_ptr& FsData::storage() const { +const std::shared_ptr& +FsData::storage() const { return storage_; } -void FsData::storage(const std::shared_ptr& storage) { +void +FsData::storage(const std::shared_ptr& storage) { storage_ = storage; } -const std::string& FsData::rootdir() const { +const std::string& +FsData::rootdir() const { return rootdir_; } -void FsData::rootdir(const std::string& rootdir) { +void +FsData::rootdir(const std::string& rootdir) { FsData::rootdir_ = rootdir; } -const std::string& FsData::mountdir() const { +const std::string& +FsData::mountdir() const { return mountdir_; } -void FsData::mountdir(const std::string& mountdir) { +void +FsData::mountdir(const std::string& mountdir) { FsData::mountdir_ = mountdir; } -const std::string& FsData::metadir() const { +const std::string& +FsData::metadir() const { return metadir_; } -void FsData::metadir(const std::string& metadir) { +void +FsData::metadir(const std::string& metadir) { FsData::metadir_ = metadir; } -const std::string& FsData::rpc_protocol() const { +const std::string& +FsData::rpc_protocol() const { return rpc_protocol_; } -void FsData::rpc_protocol(const std::string& rpc_protocol) { +void +FsData::rpc_protocol(const std::string& rpc_protocol) { rpc_protocol_ = rpc_protocol; } -const std::string& FsData::bind_addr() const { +const std::string& +FsData::bind_addr() const { return bind_addr_; } -void FsData::bind_addr(const std::string& addr) { +void +FsData::bind_addr(const std::string& addr) { bind_addr_ = addr; } -const std::string& FsData::hosts_file() const { +const std::string& +FsData::hosts_file() const { return hosts_file_; } -void FsData::hosts_file(const std::string& lookup_file) { +void +FsData::hosts_file(const std::string& lookup_file) { hosts_file_ = lookup_file; } -bool FsData::use_auto_sm() const { +bool +FsData::use_auto_sm() const { return use_auto_sm_; } -void FsData::use_auto_sm(bool use_auto_sm) { +void +FsData::use_auto_sm(bool use_auto_sm) { use_auto_sm_ = use_auto_sm; } -bool FsData::atime_state() const { +bool +FsData::atime_state() const { return atime_state_; } -void FsData::atime_state(bool atime_state) { +void +FsData::atime_state(bool atime_state) { FsData::atime_state_ = atime_state; } -bool FsData::mtime_state() const { +bool +FsData::mtime_state() const { return mtime_state_; } -void FsData::mtime_state(bool mtime_state) { +void +FsData::mtime_state(bool mtime_state) { FsData::mtime_state_ = mtime_state; } -bool FsData::ctime_state() const { +bool +FsData::ctime_state() const { return ctime_state_; } -void FsData::ctime_state(bool ctime_state) { +void +FsData::ctime_state(bool ctime_state) { FsData::ctime_state_ = ctime_state; } -bool FsData::link_cnt_state() const { +bool +FsData::link_cnt_state() const { return link_cnt_state_; } -void FsData::link_cnt_state(bool link_cnt_state) { +void +FsData::link_cnt_state(bool link_cnt_state) { FsData::link_cnt_state_ = link_cnt_state; } -bool FsData::blocks_state() const { +bool +FsData::blocks_state() const { return blocks_state_; } -void FsData::blocks_state(bool blocks_state) { +void +FsData::blocks_state(bool blocks_state) { FsData::blocks_state_ = blocks_state; } } // namespace daemon } // namespace gkfs - - - - - - diff --git a/src/daemon/classes/rpc_data.cpp b/src/daemon/classes/rpc_data.cpp index 3f8064917..0d0d494f0 100644 --- a/src/daemon/classes/rpc_data.cpp +++ b/src/daemon/classes/rpc_data.cpp @@ -21,35 +21,43 @@ namespace daemon { // Getter/Setter -margo_instance* RPCData::server_rpc_mid() { +margo_instance* +RPCData::server_rpc_mid() { return server_rpc_mid_; } -void RPCData::server_rpc_mid(margo_instance* server_rpc_mid) { +void +RPCData::server_rpc_mid(margo_instance* server_rpc_mid) { RPCData::server_rpc_mid_ = server_rpc_mid; } -ABT_pool RPCData::io_pool() const { +ABT_pool +RPCData::io_pool() const { return io_pool_; } -void RPCData::io_pool(ABT_pool io_pool) { +void +RPCData::io_pool(ABT_pool io_pool) { RPCData::io_pool_ = io_pool; } -vector& RPCData::io_streams() { +vector& +RPCData::io_streams() { return io_streams_; } -void RPCData::io_streams(const vector& io_streams) { +void +RPCData::io_streams(const vector& io_streams) { RPCData::io_streams_ = io_streams; } -const std::string& RPCData::self_addr_str() const { +const std::string& +RPCData::self_addr_str() const { return self_addr_str_; } -void RPCData::self_addr_str(const std::string& addr_str) { +void +RPCData::self_addr_str(const std::string& addr_str) { self_addr_str_ = addr_str; } diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 999a44a41..98f2faf67 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -50,24 +50,29 @@ namespace bfs = boost::filesystem; static condition_variable shutdown_please; static mutex mtx; -void init_io_tasklet_pool() { - static_assert(gkfs::config::rpc::daemon_io_xstreams >= 0, "Daemon IO Execution streams must be higher than 0!"); +void +init_io_tasklet_pool() { + static_assert(gkfs::config::rpc::daemon_io_xstreams >= 0, + "Daemon IO Execution streams must be higher than 0!"); unsigned int xstreams_num = gkfs::config::rpc::daemon_io_xstreams; - //retrieve the pool of the just created scheduler + // retrieve the pool of the just created scheduler ABT_pool pool; - auto ret = ABT_pool_create_basic(ABT_POOL_FIFO_WAIT, ABT_POOL_ACCESS_MPMC, ABT_TRUE, &pool); - if (ret != ABT_SUCCESS) { + auto ret = ABT_pool_create_basic(ABT_POOL_FIFO_WAIT, ABT_POOL_ACCESS_MPMC, + ABT_TRUE, &pool); + if(ret != ABT_SUCCESS) { throw runtime_error("Failed to create I/O tasks pool"); } - //create all subsequent xstream and the associated scheduler, all tapping into the same pool + // create all subsequent xstream and the associated scheduler, all tapping + // into the same pool vector xstreams(xstreams_num); - for (unsigned int i = 0; i < xstreams_num; ++i) { + for(unsigned int i = 0; i < xstreams_num; ++i) { ret = ABT_xstream_create_basic(ABT_SCHED_BASIC_WAIT, 1, &pool, ABT_SCHED_CONFIG_NULL, &xstreams[i]); - if (ret != ABT_SUCCESS) { - throw runtime_error("Failed to create task execution streams for I/O operations"); + if(ret != ABT_SUCCESS) { + throw runtime_error( + "Failed to create task execution streams for I/O operations"); } } @@ -79,31 +84,45 @@ void init_io_tasklet_pool() { * Registers RPC handlers to Margo instance * @param hg_class */ -void register_server_rpcs(margo_instance_id mid) { - MARGO_REGISTER(mid, gkfs::rpc::tag::fs_config, void, rpc_config_out_t, rpc_srv_get_fs_config); - MARGO_REGISTER(mid, gkfs::rpc::tag::create, rpc_mk_node_in_t, rpc_err_out_t, rpc_srv_create); - MARGO_REGISTER(mid, gkfs::rpc::tag::stat, rpc_path_only_in_t, rpc_stat_out_t, rpc_srv_stat); - MARGO_REGISTER(mid, gkfs::rpc::tag::decr_size, rpc_trunc_in_t, rpc_err_out_t, rpc_srv_decr_size); - MARGO_REGISTER(mid, gkfs::rpc::tag::remove, rpc_rm_node_in_t, rpc_err_out_t, rpc_srv_remove); - MARGO_REGISTER(mid, gkfs::rpc::tag::update_metadentry, rpc_update_metadentry_in_t, rpc_err_out_t, +void +register_server_rpcs(margo_instance_id mid) { + MARGO_REGISTER(mid, gkfs::rpc::tag::fs_config, void, rpc_config_out_t, + rpc_srv_get_fs_config); + MARGO_REGISTER(mid, gkfs::rpc::tag::create, rpc_mk_node_in_t, rpc_err_out_t, + rpc_srv_create); + MARGO_REGISTER(mid, gkfs::rpc::tag::stat, rpc_path_only_in_t, + rpc_stat_out_t, rpc_srv_stat); + MARGO_REGISTER(mid, gkfs::rpc::tag::decr_size, rpc_trunc_in_t, + rpc_err_out_t, rpc_srv_decr_size); + MARGO_REGISTER(mid, gkfs::rpc::tag::remove, rpc_rm_node_in_t, rpc_err_out_t, + rpc_srv_remove); + MARGO_REGISTER(mid, gkfs::rpc::tag::update_metadentry, + rpc_update_metadentry_in_t, rpc_err_out_t, rpc_srv_update_metadentry); - MARGO_REGISTER(mid, gkfs::rpc::tag::get_metadentry_size, rpc_path_only_in_t, rpc_get_metadentry_size_out_t, - rpc_srv_get_metadentry_size); - MARGO_REGISTER(mid, gkfs::rpc::tag::update_metadentry_size, rpc_update_metadentry_size_in_t, - rpc_update_metadentry_size_out_t, rpc_srv_update_metadentry_size); - MARGO_REGISTER(mid, gkfs::rpc::tag::get_dirents, rpc_get_dirents_in_t, rpc_get_dirents_out_t, - rpc_srv_get_dirents); + MARGO_REGISTER(mid, gkfs::rpc::tag::get_metadentry_size, rpc_path_only_in_t, + rpc_get_metadentry_size_out_t, rpc_srv_get_metadentry_size); + MARGO_REGISTER(mid, gkfs::rpc::tag::update_metadentry_size, + rpc_update_metadentry_size_in_t, + rpc_update_metadentry_size_out_t, + rpc_srv_update_metadentry_size); + MARGO_REGISTER(mid, gkfs::rpc::tag::get_dirents, rpc_get_dirents_in_t, + rpc_get_dirents_out_t, rpc_srv_get_dirents); #ifdef HAS_SYMLINKS - MARGO_REGISTER(mid, gkfs::rpc::tag::mk_symlink, rpc_mk_symlink_in_t, rpc_err_out_t, rpc_srv_mk_symlink); + MARGO_REGISTER(mid, gkfs::rpc::tag::mk_symlink, rpc_mk_symlink_in_t, + rpc_err_out_t, rpc_srv_mk_symlink); #endif - MARGO_REGISTER(mid, gkfs::rpc::tag::write, rpc_write_data_in_t, rpc_data_out_t, rpc_srv_write); - MARGO_REGISTER(mid, gkfs::rpc::tag::read, rpc_read_data_in_t, rpc_data_out_t, rpc_srv_read); - MARGO_REGISTER(mid, gkfs::rpc::tag::truncate, rpc_trunc_in_t, rpc_err_out_t, rpc_srv_truncate); - MARGO_REGISTER(mid, gkfs::rpc::tag::get_chunk_stat, rpc_chunk_stat_in_t, rpc_chunk_stat_out_t, - rpc_srv_get_chunk_stat); + MARGO_REGISTER(mid, gkfs::rpc::tag::write, rpc_write_data_in_t, + rpc_data_out_t, rpc_srv_write); + MARGO_REGISTER(mid, gkfs::rpc::tag::read, rpc_read_data_in_t, + rpc_data_out_t, rpc_srv_read); + MARGO_REGISTER(mid, gkfs::rpc::tag::truncate, rpc_trunc_in_t, rpc_err_out_t, + rpc_srv_truncate); + MARGO_REGISTER(mid, gkfs::rpc::tag::get_chunk_stat, rpc_chunk_stat_in_t, + rpc_chunk_stat_out_t, rpc_srv_get_chunk_stat); } -void init_rpc_server() { +void +init_rpc_server() { hg_addr_t addr_self; hg_size_t addr_self_cstring_sz = 128; char addr_self_cstring[128]; @@ -111,26 +130,26 @@ void init_rpc_server() { hg_options.auto_sm = GKFS_DATA->use_auto_sm() ? HG_TRUE : HG_FALSE; hg_options.stats = HG_FALSE; hg_options.na_class = nullptr; - if (gkfs::rpc::protocol::ofi_psm2 == GKFS_DATA->rpc_protocol()) + if(gkfs::rpc::protocol::ofi_psm2 == GKFS_DATA->rpc_protocol()) hg_options.na_init_info.progress_mode = NA_NO_BLOCK; // Start Margo (this will also initialize Argobots and Mercury internally) - auto mid = margo_init_opt(GKFS_DATA->bind_addr().c_str(), - MARGO_SERVER_MODE, - &hg_options, - HG_TRUE, + auto mid = margo_init_opt(GKFS_DATA->bind_addr().c_str(), MARGO_SERVER_MODE, + &hg_options, HG_TRUE, gkfs::config::rpc::daemon_handler_xstreams); - if (mid == MARGO_INSTANCE_NULL) { + if(mid == MARGO_INSTANCE_NULL) { throw runtime_error("Failed to initialize the Margo RPC server"); } - // Figure out what address this server is listening on (must be freed when finished) + // Figure out what address this server is listening on (must be freed when + // finished) auto hret = margo_addr_self(mid, &addr_self); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { margo_finalize(mid); throw runtime_error("Failed to retrieve server RPC address"); } // Convert the address to a cstring (with \0 terminator). - hret = margo_addr_to_string(mid, addr_self_cstring, &addr_self_cstring_sz, addr_self); - if (hret != HG_SUCCESS) { + hret = margo_addr_to_string(mid, addr_self_cstring, &addr_self_cstring_sz, + addr_self); + if(hret != HG_SUCCESS) { margo_addr_free(mid, addr_self); margo_finalize(mid); throw runtime_error("Failed to convert server RPC address to string"); @@ -140,7 +159,8 @@ void init_rpc_server() { std::string addr_self_str(addr_self_cstring); RPC_DATA->self_addr_str(addr_self_str); - GKFS_DATA->spdlogger()->info("{}() Accepting RPCs on address {}", __func__, addr_self_cstring); + GKFS_DATA->spdlogger()->info("{}() Accepting RPCs on address {}", __func__, + addr_self_cstring); // Put context and class into RPC_data object RPC_DATA->server_rpc_mid(mid); @@ -149,14 +169,19 @@ void init_rpc_server() { register_server_rpcs(mid); } -void init_environment() { +void +init_environment() { // Initialize metadata db std::string metadata_path = GKFS_DATA->metadir() + "/rocksdb"s; - GKFS_DATA->spdlogger()->debug("{}() Initializing metadata DB: '{}'", __func__, metadata_path); + GKFS_DATA->spdlogger()->debug("{}() Initializing metadata DB: '{}'", + __func__, metadata_path); try { - GKFS_DATA->mdb(std::make_shared(metadata_path)); - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to initialize metadata DB: {}", __func__, e.what()); + GKFS_DATA->mdb( + std::make_shared(metadata_path)); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to initialize metadata DB: {}", __func__, + e.what()); throw; } @@ -166,32 +191,40 @@ void init_environment() { #ifdef GKFS_ENABLE_AGIOS // Initialize AGIOS scheduler - GKFS_DATA->spdlogger()->debug("{}() Initializing AGIOS scheduler: '{}'", __func__, "/tmp/agios.conf"); + GKFS_DATA->spdlogger()->debug("{}() Initializing AGIOS scheduler: '{}'", + __func__, "/tmp/agios.conf"); try { agios_initialize(); - } catch (const std::exception & e) { - GKFS_DATA->spdlogger()->error("{}() Failed to initialize AGIOS scheduler: {}", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to initialize AGIOS scheduler: {}", __func__, + e.what()); throw; } #endif // Initialize data backend std::string chunk_storage_path = GKFS_DATA->rootdir() + "/data/chunks"s; - GKFS_DATA->spdlogger()->debug("{}() Initializing storage backend: '{}'", __func__, chunk_storage_path); + GKFS_DATA->spdlogger()->debug("{}() Initializing storage backend: '{}'", + __func__, chunk_storage_path); bfs::create_directories(chunk_storage_path); try { - GKFS_DATA->storage( - std::make_shared(chunk_storage_path, gkfs::config::rpc::chunksize)); - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to initialize storage backend: {}", __func__, e.what()); + GKFS_DATA->storage(std::make_shared( + chunk_storage_path, gkfs::config::rpc::chunksize)); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to initialize storage backend: {}", __func__, + e.what()); throw; } // Init margo for RPC - GKFS_DATA->spdlogger()->debug("{}() Initializing RPC server: '{}'", __func__, GKFS_DATA->bind_addr()); + GKFS_DATA->spdlogger()->debug("{}() Initializing RPC server: '{}'", + __func__, GKFS_DATA->bind_addr()); try { init_rpc_server(); - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to initialize RPC server: {}", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to initialize RPC server: {}", __func__, e.what()); throw; } @@ -199,12 +232,15 @@ void init_environment() { try { GKFS_DATA->spdlogger()->debug("{}() Initializing I/O pool", __func__); init_io_tasklet_pool(); - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to initialize Argobots pool for I/O: {}", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to initialize Argobots pool for I/O: {}", __func__, + e.what()); throw; } - // TODO set metadata configurations. these have to go into a user configurable file that is parsed here + // TODO set metadata configurations. these have to go into a user + // configurable file that is parsed here GKFS_DATA->atime_state(gkfs::config::metadata::use_atime); GKFS_DATA->mtime_state(gkfs::config::metadata::use_mtime); GKFS_DATA->ctime_state(gkfs::config::metadata::use_ctime); @@ -214,11 +250,12 @@ void init_environment() { gkfs::metadata::Metadata root_md{S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO}; try { gkfs::metadata::create("/", root_md); - } catch (const std::exception& e) { - throw runtime_error("Failed to write root metadentry to KV store: "s + e.what()); + } catch(const std::exception& e) { + throw runtime_error("Failed to write root metadentry to KV store: "s + + e.what()); } // setup hostfile to let clients know that a daemon is running on this host - if (!GKFS_DATA->hosts_file().empty()) { + if(!GKFS_DATA->hosts_file().empty()) { gkfs::util::populate_hosts_file(); } GKFS_DATA->spdlogger()->info("Startup successful. Daemon is ready."); @@ -228,11 +265,14 @@ void init_environment() { /** * Initialize the AGIOS scheduling library */ -void agios_initialize() { +void +agios_initialize() { char configuration[] = "/tmp/agios.conf"; - if (!agios_init(NULL, NULL, configuration, 0)) { - GKFS_DATA->spdlogger()->error("{}() Failed to initialize AGIOS scheduler: '{}'", __func__, configuration); + if(!agios_init(NULL, NULL, configuration, 0)) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to initialize AGIOS scheduler: '{}'", __func__, + configuration); agios_exit(); @@ -244,27 +284,31 @@ void agios_initialize() { /** * Destroys the margo, argobots, and mercury environments */ -void destroy_enviroment() { +void +destroy_enviroment() { GKFS_DATA->spdlogger()->debug("{}() Removing mount directory", __func__); boost::system::error_code ecode; bfs::remove_all(GKFS_DATA->mountdir(), ecode); - GKFS_DATA->spdlogger()->debug("{}() Freeing I/O executions streams", __func__); - for (unsigned int i = 0; i < RPC_DATA->io_streams().size(); i++) { + GKFS_DATA->spdlogger()->debug("{}() Freeing I/O executions streams", + __func__); + for(unsigned int i = 0; i < RPC_DATA->io_streams().size(); i++) { ABT_xstream_join(RPC_DATA->io_streams().at(i)); ABT_xstream_free(&RPC_DATA->io_streams().at(i)); } - if (!GKFS_DATA->hosts_file().empty()) { + if(!GKFS_DATA->hosts_file().empty()) { GKFS_DATA->spdlogger()->debug("{}() Removing hosts file", __func__); try { gkfs::util::destroy_hosts_file(); - } catch (const bfs::filesystem_error& e) { - GKFS_DATA->spdlogger()->debug("{}() hosts file not found", __func__); + } catch(const bfs::filesystem_error& e) { + GKFS_DATA->spdlogger()->debug("{}() hosts file not found", + __func__); } } - if (RPC_DATA->server_rpc_mid() != nullptr) { - GKFS_DATA->spdlogger()->debug("{}() Finalizing margo RPC server", __func__); + if(RPC_DATA->server_rpc_mid() != nullptr) { + GKFS_DATA->spdlogger()->debug("{}() Finalizing margo RPC server", + __func__); margo_finalize(RPC_DATA->server_rpc_mid()); } @@ -272,27 +316,31 @@ void destroy_enviroment() { GKFS_DATA->close_mdb(); } -void shutdown_handler(int dummy) { - GKFS_DATA->spdlogger()->info("{}() Received signal: '{}'", __func__, strsignal(dummy)); +void +shutdown_handler(int dummy) { + GKFS_DATA->spdlogger()->info("{}() Received signal: '{}'", __func__, + strsignal(dummy)); shutdown_please.notify_all(); } -void initialize_loggers() { +void +initialize_loggers() { std::string path = gkfs::config::log::daemon_log_path; // Try to get log path from env variable std::string env_path_key = DAEMON_ENV_PREFIX; env_path_key += "DAEMON_LOG_PATH"; char* env_path = getenv(env_path_key.c_str()); - if (env_path != nullptr) { + if(env_path != nullptr) { path = env_path; } - spdlog::level::level_enum level = gkfs::log::get_level(gkfs::config::log::daemon_log_level); + spdlog::level::level_enum level = + gkfs::log::get_level(gkfs::config::log::daemon_log_level); // Try to get log path from env variable std::string env_level_key = DAEMON_ENV_PREFIX; env_level_key += "LOG_LEVEL"; char* env_level = getenv(env_level_key.c_str()); - if (env_level != nullptr) { + if(env_level != nullptr) { level = gkfs::log::get_level(env_level); } @@ -310,39 +358,42 @@ void initialize_loggers() { * @param vm * @throws runtime_error */ -void parse_input(const po::variables_map& vm) { +void +parse_input(const po::variables_map& vm) { auto rpc_protocol = string(gkfs::rpc::protocol::ofi_sockets); - if (vm.count("rpc-protocol")) { + if(vm.count("rpc-protocol")) { rpc_protocol = vm["rpc-protocol"].as(); - if (rpc_protocol != gkfs::rpc::protocol::ofi_verbs && - rpc_protocol != gkfs::rpc::protocol::ofi_sockets && - rpc_protocol != gkfs::rpc::protocol::ofi_psm2) { - throw runtime_error( - fmt::format("Given RPC protocol '{}' not supported. Check --help for supported protocols.", - rpc_protocol)); + if(rpc_protocol != gkfs::rpc::protocol::ofi_verbs && + rpc_protocol != gkfs::rpc::protocol::ofi_sockets && + rpc_protocol != gkfs::rpc::protocol::ofi_psm2) { + throw runtime_error(fmt::format( + "Given RPC protocol '{}' not supported. Check --help for supported protocols.", + rpc_protocol)); } } auto use_auto_sm = vm.count("auto-sm") != 0; GKFS_DATA->use_auto_sm(use_auto_sm); - GKFS_DATA->spdlogger()->debug("{}() Shared memory (auto_sm) for intra-node communication (IPCs) set to '{}'.", - __func__, use_auto_sm); + GKFS_DATA->spdlogger()->debug( + "{}() Shared memory (auto_sm) for intra-node communication (IPCs) set to '{}'.", + __func__, use_auto_sm); string addr{}; - if (vm.count("listen")) { + if(vm.count("listen")) { addr = vm["listen"].as(); // ofi+verbs requires an empty addr to bind to the ib interface - if (rpc_protocol == gkfs::rpc::protocol::ofi_verbs) { + if(rpc_protocol == gkfs::rpc::protocol::ofi_verbs) { /* - * FI_VERBS_IFACE : The prefix or the full name of the network interface associated with the verbs device (default: ib) - * Mercury does not allow to bind to an address when ofi+verbs is used + * FI_VERBS_IFACE : The prefix or the full name of the network + * interface associated with the verbs device (default: ib) Mercury + * does not allow to bind to an address when ofi+verbs is used */ - if (!secure_getenv("FI_VERBS_IFACE")) + if(!secure_getenv("FI_VERBS_IFACE")) setenv("FI_VERBS_IFACE", addr.c_str(), 1); addr = ""s; } } else { - if (rpc_protocol != gkfs::rpc::protocol::ofi_verbs) + if(rpc_protocol != gkfs::rpc::protocol::ofi_verbs) addr = gkfs::rpc::get_my_hostname(true); } @@ -350,16 +401,18 @@ void parse_input(const po::variables_map& vm) { GKFS_DATA->bind_addr(fmt::format("{}://{}", rpc_protocol, addr)); string hosts_file; - if (vm.count("hosts-file")) { + if(vm.count("hosts-file")) { hosts_file = vm["hosts-file"].as(); } else { - hosts_file = gkfs::env::get_var(gkfs::env::HOSTS_FILE, gkfs::config::hostfile_path); + hosts_file = gkfs::env::get_var(gkfs::env::HOSTS_FILE, + gkfs::config::hostfile_path); } GKFS_DATA->hosts_file(hosts_file); assert(vm.count("mountdir")); auto mountdir = vm["mountdir"].as(); - // Create mountdir. We use this dir to get some information on the underlying fs with statfs in gkfs_statfs + // Create mountdir. We use this dir to get some information on the + // underlying fs with statfs in gkfs_statfs bfs::create_directories(mountdir); GKFS_DATA->mountdir(bfs::canonical(mountdir).native()); @@ -373,16 +426,17 @@ void parse_input(const po::variables_map& vm) { auto rootdir_path = bfs::path(rootdir) / fmt::format_int(getpid()).str(); #endif - GKFS_DATA->spdlogger()->debug("{}() Root directory: '{}'", - __func__, rootdir_path.native()); + GKFS_DATA->spdlogger()->debug("{}() Root directory: '{}'", __func__, + rootdir_path.native()); bfs::create_directories(rootdir_path); GKFS_DATA->rootdir(rootdir_path.native()); - if (vm.count("metadir")) { + if(vm.count("metadir")) { auto metadir = vm["metadir"].as(); #ifdef GKFS_ENABLE_FORWARDING - auto metadir_path = bfs::path(metadir) / fmt::format_int(getpid()).str(); + auto metadir_path = + bfs::path(metadir) / fmt::format_int(getpid()).str(); #else auto metadir_path = bfs::path(metadir); #endif @@ -390,61 +444,67 @@ void parse_input(const po::variables_map& vm) { bfs::create_directories(metadir_path); GKFS_DATA->metadir(bfs::canonical(metadir_path).native()); - GKFS_DATA->spdlogger()->debug("{}() Meta directory: '{}'", - __func__, metadir_path.native()); + GKFS_DATA->spdlogger()->debug("{}() Meta directory: '{}'", __func__, + metadir_path.native()); } else { // use rootdir as metadata dir auto metadir = vm["rootdir"].as(); #ifdef GKFS_ENABLE_FORWARDING - auto metadir_path = bfs::path(metadir) / fmt::format_int(getpid()).str(); + auto metadir_path = + bfs::path(metadir) / fmt::format_int(getpid()).str(); bfs::create_directories(metadir_path); GKFS_DATA->metadir(bfs::canonical(metadir_path).native()); #else GKFS_DATA->metadir(GKFS_DATA->rootdir()); #endif } - - } -int main(int argc, const char* argv[]) { +int +main(int argc, const char* argv[]) { // Define arg parsing po::options_description desc("Allowed options"); desc.add_options()("help,h", "Help message"); - desc.add_options()("mountdir,m", po::value()->required(), - "Virtual mounting directory where GekkoFS is available."); - desc.add_options()("rootdir,r", po::value()->required(), - "Local data directory where GekkoFS data for this daemon is stored."); + desc.add_options()( + "mountdir,m", po::value()->required(), + "Virtual mounting directory where GekkoFS is available."); + desc.add_options()( + "rootdir,r", po::value()->required(), + "Local data directory where GekkoFS data for this daemon is stored."); desc.add_options()( "metadir,i", po::value(), "Metadata directory where GekkoFS' RocksDB data directory is located. If not set, rootdir is used."); - desc.add_options()("listen,l", po::value(), - "Address or interface to bind the daemon to. Default: local hostname.\n" - "When used with ofi+verbs the FI_VERBS_IFACE environment variable is set accordingly " - "which associates the verbs device with the network interface. In case FI_VERBS_IFACE " - "is already defined, the argument is ignored. Default 'ib'."); + desc.add_options()( + "listen,l", po::value(), + "Address or interface to bind the daemon to. Default: local hostname.\n" + "When used with ofi+verbs the FI_VERBS_IFACE environment variable is set accordingly " + "which associates the verbs device with the network interface. In case FI_VERBS_IFACE " + "is already defined, the argument is ignored. Default 'ib'."); desc.add_options()("hosts-file,H", po::value(), "Shared file used by deamons to register their " "endpoints. (default './gkfs_hosts.txt')"); - desc.add_options()("rpc-protocol,P", po::value(), - "Used RPC protocol for inter-node communication.\n" - "Available: {ofi+sockets, ofi+verbs, ofi+psm2} for TCP, Infiniband, " - "and Omni-Path, respectively. (Default ofi+sockets)\n" - "Libfabric must have enabled support verbs or psm2."); - desc.add_options()("auto-sm", "Enables intra-node communication (IPCs) via the `na+sm` (shared memory) protocol, " - "instead of using the RPC protocol. (Default off)"); + desc.add_options()( + "rpc-protocol,P", po::value(), + "Used RPC protocol for inter-node communication.\n" + "Available: {ofi+sockets, ofi+verbs, ofi+psm2} for TCP, Infiniband, " + "and Omni-Path, respectively. (Default ofi+sockets)\n" + "Libfabric must have enabled support verbs or psm2."); + desc.add_options()( + "auto-sm", + "Enables intra-node communication (IPCs) via the `na+sm` (shared memory) protocol, " + "instead of using the RPC protocol. (Default off)"); desc.add_options()("version", "Print version and exit."); po::variables_map vm{}; po::store(po::parse_command_line(argc, argv, desc), vm); - if (vm.count("help")) { + if(vm.count("help")) { cout << desc << "\n"; return 1; } - if (vm.count("version")) { + if(vm.count("version")) { cout << GKFS_VERSION_STRING << endl; #ifndef NDEBUG cout << "Debug: ON" << endl; @@ -456,13 +516,14 @@ int main(int argc, const char* argv[]) { #else cout << "Create check parents: OFF" << endl; #endif - cout << "Chunk size: " << gkfs::config::rpc::chunksize << " bytes" << endl; + cout << "Chunk size: " << gkfs::config::rpc::chunksize << " bytes" + << endl; return 0; } try { po::notify(vm); - } catch (po::required_option& e) { + } catch(po::required_option& e) { std::cerr << "Error: " << e.what() << "\n"; return 1; } @@ -474,19 +535,22 @@ int main(int argc, const char* argv[]) { // parse all input parameters and populate singleton structures try { parse_input(vm); - } catch (const std::exception& e) { - cerr << fmt::format("Parsing arguments failed: '{}'. Exiting.", e.what()); + } catch(const std::exception& e) { + cerr << fmt::format("Parsing arguments failed: '{}'. Exiting.", + e.what()); exit(EXIT_FAILURE); } /* - * Initialize environment and start daemon. Wait until signaled to cancel before shutting down + * Initialize environment and start daemon. Wait until signaled to cancel + * before shutting down */ try { GKFS_DATA->spdlogger()->info("{}() Initializing environment", __func__); init_environment(); - } catch (const std::exception& e) { - auto emsg = fmt::format("Failed to initialize environment: {}", e.what()); + } catch(const std::exception& e) { + auto emsg = + fmt::format("Failed to initialize environment: {}", e.what()); GKFS_DATA->spdlogger()->error(emsg); cerr << emsg << endl; destroy_enviroment(); diff --git a/src/daemon/handler/srv_data.cpp b/src/daemon/handler/srv_data.cpp index 94e355c0a..a66d1748e 100644 --- a/src/daemon/handler/srv_data.cpp +++ b/src/daemon/handler/srv_data.cpp @@ -25,15 +25,16 @@ #ifdef GKFS_ENABLE_AGIOS #include -#define AGIOS_READ 0 -#define AGIOS_WRITE 1 +#define AGIOS_READ 0 +#define AGIOS_WRITE 1 #define AGIOS_SERVER_ID_IGNORE 0 #endif using namespace std; /* - * This file contains all Margo RPC handlers that are concerning management operations + * This file contains all Margo RPC handlers that are concerning management + * operations */ namespace { @@ -43,7 +44,8 @@ namespace { * @param handle * @return */ -hg_return_t rpc_srv_write(hg_handle_t handle) { +hg_return_t +rpc_srv_write(hg_handle_t handle) { /* * 1. Setup */ @@ -55,8 +57,9 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { out.io_size = 0; // Getting some information from margo auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Could not get RPC input data with err {}", __func__, ret); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "{}() Could not get RPC input data with err {}", __func__, ret); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } auto hgi = margo_get_info(handle); @@ -64,55 +67,73 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { auto bulk_size = margo_bulk_get_size(in.bulk_handle); GKFS_DATA->spdlogger()->debug( "{}() path: '{}' chunk_start '{}' chunk_end '{}' chunk_n '{}' total_chunk_size '{}' bulk_size: '{}' offset: '{}'", - __func__, in.path, in.chunk_start, in.chunk_end, in.chunk_n, in.total_chunk_size, bulk_size, in.offset); + __func__, in.path, in.chunk_start, in.chunk_end, in.chunk_n, + in.total_chunk_size, bulk_size, in.offset); #ifdef GKFS_ENABLE_AGIOS - int *data; + int* data; ABT_eventual eventual = ABT_EVENTUAL_NULL; /* creating eventual */ ABT_eventual_create(sizeof(int64_t), &eventual); unsigned long long int request_id = generate_unique_id(); - char *agios_path = (char*) in.path; - - // We should call AGIOS before chunking (as that is an internal way to handle the requests) - if (!agios_add_request(agios_path, AGIOS_WRITE, in.offset, in.total_chunk_size, request_id, AGIOS_SERVER_ID_IGNORE, agios_eventual_callback, eventual)) { - GKFS_DATA->spdlogger()->error("{}() Failed to send request to AGIOS", __func__); + char* agios_path = (char*) in.path; + + // We should call AGIOS before chunking (as that is an internal way to + // handle the requests) + if(!agios_add_request(agios_path, AGIOS_WRITE, in.offset, + in.total_chunk_size, request_id, + AGIOS_SERVER_ID_IGNORE, agios_eventual_callback, + eventual)) { + GKFS_DATA->spdlogger()->error("{}() Failed to send request to AGIOS", + __func__); } else { - GKFS_DATA->spdlogger()->debug("{}() request {} was sent to AGIOS", __func__, request_id); + GKFS_DATA->spdlogger()->debug("{}() request {} was sent to AGIOS", + __func__, request_id); } /* Block until the eventual is signaled */ - ABT_eventual_wait(eventual, (void **)&data); + ABT_eventual_wait(eventual, (void**) &data); unsigned long long int result = *data; - GKFS_DATA->spdlogger()->debug("{}() request {} was unblocked (offset = {})!", __func__, result, in.offset); + GKFS_DATA->spdlogger()->debug( + "{}() request {} was unblocked (offset = {})!", __func__, result, + in.offset); ABT_eventual_free(&eventual); // Let AGIOS knows it can release the request, as it is completed - if (!agios_release_request(agios_path, AGIOS_WRITE, in.total_chunk_size, in.offset)) { - GKFS_DATA->spdlogger()->error("{}() Failed to release request from AGIOS", __func__); + if(!agios_release_request(agios_path, AGIOS_WRITE, in.total_chunk_size, + in.offset)) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to release request from AGIOS", __func__); } #endif /* * 2. Set up buffers for pull bulk transfers */ - void* bulk_buf; // buffer for bulk transfer + void* bulk_buf; // buffer for bulk transfer vector bulk_buf_ptrs(in.chunk_n); // buffer-chunk offsets - // create bulk handle and allocated memory for buffer with buf_sizes information - ret = margo_bulk_create(mid, 1, nullptr, &in.total_chunk_size, HG_BULK_READWRITE, &bulk_handle); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", __func__); - return gkfs::rpc::cleanup_respond(&handle, &in, &out, static_cast(nullptr)); + // create bulk handle and allocated memory for buffer with buf_sizes + // information + ret = margo_bulk_create(mid, 1, nullptr, &in.total_chunk_size, + HG_BULK_READWRITE, &bulk_handle); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", + __func__); + return gkfs::rpc::cleanup_respond(&handle, &in, &out, + static_cast(nullptr)); } // access the internally allocated memory buffer and put it into buf_ptrs uint32_t actual_count; - ret = margo_bulk_access(bulk_handle, 0, in.total_chunk_size, HG_BULK_READWRITE, 1, &bulk_buf, + ret = margo_bulk_access(bulk_handle, 0, in.total_chunk_size, + HG_BULK_READWRITE, 1, &bulk_buf, &in.total_chunk_size, &actual_count); - if (ret != HG_SUCCESS || actual_count != 1) { - GKFS_DATA->spdlogger()->error("{}() Failed to access allocated buffer from bulk handle", __func__); + if(ret != HG_SUCCESS || actual_count != 1) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to access allocated buffer from bulk handle", + __func__); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } auto const host_id = in.host_id; @@ -132,28 +153,36 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { /* * consider the following cases: * 1. Very first chunk has offset or not and is serviced by this node - * 2. If offset, will still be only 1 chunk written (small IO): (offset + bulk_size <= CHUNKSIZE) ? bulk_size - * 3. If no offset, will only be 1 chunk written (small IO): (bulk_size <= CHUNKSIZE) ? bulk_size + * 2. If offset, will still be only 1 chunk written (small IO): (offset + + * bulk_size <= CHUNKSIZE) ? bulk_size + * 3. If no offset, will only be 1 chunk written (small IO): (bulk_size <= + * CHUNKSIZE) ? bulk_size * 4. Chunks between start and end chunk have size of the CHUNKSIZE - * 5. Last chunk (if multiple chunks are written): Don't write CHUNKSIZE but chnk_size_left for this destination - * Last chunk can also happen if only one chunk is written. This is covered by 2 and 3. + * 5. Last chunk (if multiple chunks are written): Don't write CHUNKSIZE but + * chnk_size_left for this destination Last chunk can also happen if only + * one chunk is written. This is covered by 2 and 3. */ // temporary variables - auto transfer_size = (bulk_size <= gkfs::config::rpc::chunksize) ? bulk_size : gkfs::config::rpc::chunksize; + auto transfer_size = (bulk_size <= gkfs::config::rpc::chunksize) + ? bulk_size + : gkfs::config::rpc::chunksize; uint64_t origin_offset; uint64_t local_offset; // object for asynchronous disk IO gkfs::data::ChunkWriteOperation chunk_op{in.path, in.chunk_n}; /* - * 3. Calculate chunk sizes that correspond to this host, transfer data, and start tasks to write to disk + * 3. Calculate chunk sizes that correspond to this host, transfer data, and + * start tasks to write to disk */ - // Start to look for a chunk that hashes to this host with the first chunk in the buffer - for (auto chnk_id_file = in.chunk_start; - chnk_id_file <= in.chunk_end && chnk_id_curr < in.chunk_n; chnk_id_file++) { + // Start to look for a chunk that hashes to this host with the first chunk + // in the buffer + for(auto chnk_id_file = in.chunk_start; + chnk_id_file <= in.chunk_end && chnk_id_curr < in.chunk_n; + chnk_id_file++) { // Continue if chunk does not hash to this host #ifndef GKFS_ENABLE_FORWARDING - if (distributor.locate_data(in.path, chnk_id_file) != host_id) { + if(distributor.locate_data(in.path, chnk_id_file) != host_id) { GKFS_DATA->spdlogger()->trace( "{}() chunkid '{}' ignored as it does not match to this host with id '{}'. chnk_id_curr '{}'", __func__, chnk_id_file, host_id, chnk_id_curr); @@ -161,23 +190,30 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { } #endif - chnk_ids_host[chnk_id_curr] = chnk_id_file; // save this id to host chunk list - // offset case. Only relevant in the first iteration of the loop and if the chunk hashes to this host - if (chnk_id_file == in.chunk_start && in.offset > 0) { - // if only 1 destination and 1 chunk (small write) the transfer_size == bulk_size + chnk_ids_host[chnk_id_curr] = + chnk_id_file; // save this id to host chunk list + // offset case. Only relevant in the first iteration of the loop and if + // the chunk hashes to this host + if(chnk_id_file == in.chunk_start && in.offset > 0) { + // if only 1 destination and 1 chunk (small write) the transfer_size + // == bulk_size size_t offset_transfer_size = 0; - if (in.offset + bulk_size <= gkfs::config::rpc::chunksize) + if(in.offset + bulk_size <= gkfs::config::rpc::chunksize) offset_transfer_size = bulk_size; else - offset_transfer_size = static_cast(gkfs::config::rpc::chunksize - in.offset); - ret = margo_bulk_transfer(mid, HG_BULK_PULL, hgi->addr, in.bulk_handle, 0, - bulk_handle, 0, offset_transfer_size); - if (ret != HG_SUCCESS) { + offset_transfer_size = static_cast( + gkfs::config::rpc::chunksize - in.offset); + ret = margo_bulk_transfer(mid, HG_BULK_PULL, hgi->addr, + in.bulk_handle, 0, bulk_handle, 0, + offset_transfer_size); + if(ret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error( - "{}() Failed to pull data from client for chunk {} (startchunk {}; endchunk {}", __func__, - chnk_id_file, in.chunk_start, in.chunk_end - 1); + "{}() Failed to pull data from client for chunk {} (startchunk {}; endchunk {}", + __func__, chnk_id_file, in.chunk_start, + in.chunk_end - 1); out.err = EBUSY; - return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); + return gkfs::rpc::cleanup_respond(&handle, &in, &out, + &bulk_handle); } bulk_buf_ptrs[chnk_id_curr] = chnk_ptr; chnk_sizes[chnk_id_curr] = offset_transfer_size; @@ -185,28 +221,35 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { chnk_size_left_host -= offset_transfer_size; } else { local_offset = in.total_chunk_size - chnk_size_left_host; - // origin offset of a chunk is dependent on a given offset in a write operation - if (in.offset > 0) + // origin offset of a chunk is dependent on a given offset in a + // write operation + if(in.offset > 0) origin_offset = (gkfs::config::rpc::chunksize - in.offset) + - ((chnk_id_file - in.chunk_start) - 1) * gkfs::config::rpc::chunksize; + ((chnk_id_file - in.chunk_start) - 1) * + gkfs::config::rpc::chunksize; else - origin_offset = (chnk_id_file - in.chunk_start) * gkfs::config::rpc::chunksize; + origin_offset = (chnk_id_file - in.chunk_start) * + gkfs::config::rpc::chunksize; // last chunk might have different transfer_size - if (chnk_id_curr == in.chunk_n - 1) + if(chnk_id_curr == in.chunk_n - 1) transfer_size = chnk_size_left_host; GKFS_DATA->spdlogger()->trace( "{}() BULK_TRANSFER_PULL hostid {} file {} chnkid {} total_Csize {} Csize_left {} origin offset {} local offset {} transfersize {}", - __func__, host_id, in.path, chnk_id_file, in.total_chunk_size, chnk_size_left_host, - origin_offset, local_offset, transfer_size); + __func__, host_id, in.path, chnk_id_file, + in.total_chunk_size, chnk_size_left_host, origin_offset, + local_offset, transfer_size); // RDMA the data to here - ret = margo_bulk_transfer(mid, HG_BULK_PULL, hgi->addr, in.bulk_handle, origin_offset, + ret = margo_bulk_transfer(mid, HG_BULK_PULL, hgi->addr, + in.bulk_handle, origin_offset, bulk_handle, local_offset, transfer_size); - if (ret != HG_SUCCESS) { + if(ret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error( - "{}() Failed to pull data from client. file {} chunk {} (startchunk {}; endchunk {})", __func__, - in.path, chnk_id_file, in.chunk_start, (in.chunk_end - 1)); + "{}() Failed to pull data from client. file {} chunk {} (startchunk {}; endchunk {})", + __func__, in.path, chnk_id_file, in.chunk_start, + (in.chunk_end - 1)); out.err = EBUSY; - return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); + return gkfs::rpc::cleanup_respond(&handle, &in, &out, + &bulk_handle); } bulk_buf_ptrs[chnk_id_curr] = chnk_ptr; chnk_sizes[chnk_id_curr] = transfer_size; @@ -215,22 +258,26 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { } try { // start tasklet for writing chunk - chunk_op.write_nonblock(chnk_id_curr, chnk_ids_host[chnk_id_curr], bulk_buf_ptrs[chnk_id_curr], - chnk_sizes[chnk_id_curr], (chnk_id_file == in.chunk_start) ? in.offset : 0); - } catch (const gkfs::data::ChunkWriteOpException& e) { - // This exception is caused by setup of Argobots variables. If this fails, something is really wrong - GKFS_DATA->spdlogger()->error("{}() while write_nonblock err '{}'", __func__, e.what()); + chunk_op.write_nonblock( + chnk_id_curr, chnk_ids_host[chnk_id_curr], + bulk_buf_ptrs[chnk_id_curr], chnk_sizes[chnk_id_curr], + (chnk_id_file == in.chunk_start) ? in.offset : 0); + } catch(const gkfs::data::ChunkWriteOpException& e) { + // This exception is caused by setup of Argobots variables. If this + // fails, something is really wrong + GKFS_DATA->spdlogger()->error("{}() while write_nonblock err '{}'", + __func__, e.what()); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } // next chunk chnk_id_curr++; - } // Sanity check that all chunks where detected in previous loop // TODO don't proceed if that happens. - if (chnk_size_left_host != 0) - GKFS_DATA->spdlogger()->warn("{}() Not all chunks were detected!!! Size left {}", __func__, - chnk_size_left_host); + if(chnk_size_left_host != 0) + GKFS_DATA->spdlogger()->warn( + "{}() Not all chunks were detected!!! Size left {}", __func__, + chnk_size_left_host); /* * 4. Read task results and accumulate in out.io_size */ @@ -239,15 +286,17 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { out.io_size = write_result.second; // Sanity check to see if all data has been written - if (in.total_chunk_size != out.io_size) { - GKFS_DATA->spdlogger()->warn("{}() total chunk size {} and out.io_size {} mismatch!", __func__, - in.total_chunk_size, out.io_size); + if(in.total_chunk_size != out.io_size) { + GKFS_DATA->spdlogger()->warn( + "{}() total chunk size {} and out.io_size {} mismatch!", + __func__, in.total_chunk_size, out.io_size); } /* * 5. Respond and cleanup */ - GKFS_DATA->spdlogger()->debug("{}() Sending output response {}", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output response {}", __func__, + out.err); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } @@ -256,7 +305,8 @@ hg_return_t rpc_srv_write(hg_handle_t handle) { * @param handle * @return */ -hg_return_t rpc_srv_read(hg_handle_t handle) { +hg_return_t +rpc_srv_read(hg_handle_t handle) { /* * 1. Setup */ @@ -268,8 +318,9 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { out.io_size = 0; // Getting some information from margo auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Could not get RPC input data with err {}", __func__, ret); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "{}() Could not get RPC input data with err {}", __func__, ret); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } auto hgi = margo_get_info(handle); @@ -278,55 +329,73 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { GKFS_DATA->spdlogger()->debug( "{}() path: '{}' chunk_start '{}' chunk_end '{}' chunk_n '{}' total_chunk_size '{}' bulk_size: '{}' offset: '{}'", - __func__, in.path, in.chunk_start, in.chunk_end, in.chunk_n, in.total_chunk_size, bulk_size, in.offset); + __func__, in.path, in.chunk_start, in.chunk_end, in.chunk_n, + in.total_chunk_size, bulk_size, in.offset); #ifdef GKFS_ENABLE_AGIOS - int *data; + int* data; ABT_eventual eventual = ABT_EVENTUAL_NULL; /* creating eventual */ ABT_eventual_create(sizeof(int64_t), &eventual); unsigned long long int request_id = generate_unique_id(); - char *agios_path = (char*) in.path; - - // We should call AGIOS before chunking (as that is an internal way to handle the requests) - if (!agios_add_request(agios_path, AGIOS_READ, in.offset, in.total_chunk_size, request_id, AGIOS_SERVER_ID_IGNORE, agios_eventual_callback, eventual)) { - GKFS_DATA->spdlogger()->error("{}() Failed to send request to AGIOS", __func__); + char* agios_path = (char*) in.path; + + // We should call AGIOS before chunking (as that is an internal way to + // handle the requests) + if(!agios_add_request(agios_path, AGIOS_READ, in.offset, + in.total_chunk_size, request_id, + AGIOS_SERVER_ID_IGNORE, agios_eventual_callback, + eventual)) { + GKFS_DATA->spdlogger()->error("{}() Failed to send request to AGIOS", + __func__); } else { - GKFS_DATA->spdlogger()->debug("{}() request {} was sent to AGIOS", __func__, request_id); + GKFS_DATA->spdlogger()->debug("{}() request {} was sent to AGIOS", + __func__, request_id); } /* block until the eventual is signaled */ - ABT_eventual_wait(eventual, (void **)&data); + ABT_eventual_wait(eventual, (void**) &data); unsigned long long int result = *data; - GKFS_DATA->spdlogger()->debug("{}() request {} was unblocked (offset = {})!", __func__, result, in.offset); + GKFS_DATA->spdlogger()->debug( + "{}() request {} was unblocked (offset = {})!", __func__, result, + in.offset); ABT_eventual_free(&eventual); // let AGIOS knows it can release the request, as it is completed - if (!agios_release_request(agios_path, AGIOS_READ, in.total_chunk_size, in.offset)) { - GKFS_DATA->spdlogger()->error("{}() Failed to release request from AGIOS", __func__); + if(!agios_release_request(agios_path, AGIOS_READ, in.total_chunk_size, + in.offset)) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to release request from AGIOS", __func__); } #endif /* * 2. Set up buffers for pull bulk transfers */ - void* bulk_buf; // buffer for bulk transfer + void* bulk_buf; // buffer for bulk transfer vector bulk_buf_ptrs(in.chunk_n); // buffer-chunk offsets - // create bulk handle and allocated memory for buffer with buf_sizes information - ret = margo_bulk_create(mid, 1, nullptr, &in.total_chunk_size, HG_BULK_READWRITE, &bulk_handle); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", __func__); - return gkfs::rpc::cleanup_respond(&handle, &in, &out, static_cast(nullptr)); + // create bulk handle and allocated memory for buffer with buf_sizes + // information + ret = margo_bulk_create(mid, 1, nullptr, &in.total_chunk_size, + HG_BULK_READWRITE, &bulk_handle); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", + __func__); + return gkfs::rpc::cleanup_respond(&handle, &in, &out, + static_cast(nullptr)); } // access the internally allocated memory buffer and put it into buf_ptrs uint32_t actual_count; - ret = margo_bulk_access(bulk_handle, 0, in.total_chunk_size, HG_BULK_READWRITE, 1, &bulk_buf, + ret = margo_bulk_access(bulk_handle, 0, in.total_chunk_size, + HG_BULK_READWRITE, 1, &bulk_buf, &in.total_chunk_size, &actual_count); - if (ret != HG_SUCCESS || actual_count != 1) { - GKFS_DATA->spdlogger()->error("{}() Failed to access allocated buffer from bulk handle", __func__); + if(ret != HG_SUCCESS || actual_count != 1) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to access allocated buffer from bulk handle", + __func__); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } #ifndef GKFS_ENABLE_FORWARDING @@ -349,18 +418,23 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { // temporary traveling pointer auto chnk_ptr = static_cast(bulk_buf); // temporary variables - auto transfer_size = (bulk_size <= gkfs::config::rpc::chunksize) ? bulk_size : gkfs::config::rpc::chunksize; + auto transfer_size = (bulk_size <= gkfs::config::rpc::chunksize) + ? bulk_size + : gkfs::config::rpc::chunksize; // object for asynchronous disk IO gkfs::data::ChunkReadOperation chunk_read_op{in.path, in.chunk_n}; /* - * 3. Calculate chunk sizes that correspond to this host and start tasks to read from disk + * 3. Calculate chunk sizes that correspond to this host and start tasks to + * read from disk */ - // Start to look for a chunk that hashes to this host with the first chunk in the buffer - for (auto chnk_id_file = in.chunk_start; - chnk_id_file <= in.chunk_end && chnk_id_curr < in.chunk_n; chnk_id_file++) { + // Start to look for a chunk that hashes to this host with the first chunk + // in the buffer + for(auto chnk_id_file = in.chunk_start; + chnk_id_file <= in.chunk_end && chnk_id_curr < in.chunk_n; + chnk_id_file++) { // Continue if chunk does not hash to this host #ifndef GKFS_ENABLE_FORWARDING - if (distributor.locate_data(in.path, chnk_id_file) != host_id) { + if(distributor.locate_data(in.path, chnk_id_file) != host_id) { GKFS_DATA->spdlogger()->trace( "{}() chunkid '{}' ignored as it does not match to this host with id '{}'. chnk_id_curr '{}'", __func__, chnk_id_file, host_id, chnk_id_curr); @@ -368,15 +442,19 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { } #endif - chnk_ids_host[chnk_id_curr] = chnk_id_file; // save this id to host chunk list - // Only relevant in the first iteration of the loop and if the chunk hashes to this host - if (chnk_id_file == in.chunk_start && in.offset > 0) { - // if only 1 destination and 1 chunk (small read) the transfer_size == bulk_size + chnk_ids_host[chnk_id_curr] = + chnk_id_file; // save this id to host chunk list + // Only relevant in the first iteration of the loop and if the chunk + // hashes to this host + if(chnk_id_file == in.chunk_start && in.offset > 0) { + // if only 1 destination and 1 chunk (small read) the transfer_size + // == bulk_size size_t offset_transfer_size = 0; - if (in.offset + bulk_size <= gkfs::config::rpc::chunksize) + if(in.offset + bulk_size <= gkfs::config::rpc::chunksize) offset_transfer_size = bulk_size; else - offset_transfer_size = static_cast(gkfs::config::rpc::chunksize - in.offset); + offset_transfer_size = static_cast( + gkfs::config::rpc::chunksize - in.offset); // Setting later transfer offsets local_offsets[chnk_id_curr] = 0; origin_offsets[chnk_id_curr] = 0; @@ -386,16 +464,20 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { chnk_ptr += offset_transfer_size; chnk_size_left_host -= offset_transfer_size; } else { - local_offsets[chnk_id_curr] = in.total_chunk_size - chnk_size_left_host; - // origin offset of a chunk is dependent on a given offset in a write operation - if (in.offset > 0) + local_offsets[chnk_id_curr] = + in.total_chunk_size - chnk_size_left_host; + // origin offset of a chunk is dependent on a given offset in a + // write operation + if(in.offset > 0) origin_offsets[chnk_id_curr] = (gkfs::config::rpc::chunksize - in.offset) + - ((chnk_id_file - in.chunk_start) - 1) * gkfs::config::rpc::chunksize; + ((chnk_id_file - in.chunk_start) - 1) * + gkfs::config::rpc::chunksize; else - origin_offsets[chnk_id_curr] = (chnk_id_file - in.chunk_start) * gkfs::config::rpc::chunksize; + origin_offsets[chnk_id_curr] = (chnk_id_file - in.chunk_start) * + gkfs::config::rpc::chunksize; // last chunk might have different transfer_size - if (chnk_id_curr == in.chunk_n - 1) + if(chnk_id_curr == in.chunk_n - 1) transfer_size = chnk_size_left_host; bulk_buf_ptrs[chnk_id_curr] = chnk_ptr; chnk_sizes[chnk_id_curr] = transfer_size; @@ -405,20 +487,26 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { } try { // start tasklet for read operation - chunk_read_op.read_nonblock(chnk_id_curr, chnk_ids_host[chnk_id_curr], bulk_buf_ptrs[chnk_id_curr], - chnk_sizes[chnk_id_curr], (chnk_id_file == in.chunk_start) ? in.offset : 0); - } catch (const gkfs::data::ChunkReadOpException& e) { - // This exception is caused by setup of Argobots variables. If this fails, something is really wrong - GKFS_DATA->spdlogger()->error("{}() while read_nonblock err '{}'", __func__, e.what()); + chunk_read_op.read_nonblock( + chnk_id_curr, chnk_ids_host[chnk_id_curr], + bulk_buf_ptrs[chnk_id_curr], chnk_sizes[chnk_id_curr], + (chnk_id_file == in.chunk_start) ? in.offset : 0); + } catch(const gkfs::data::ChunkReadOpException& e) { + // This exception is caused by setup of Argobots variables. If this + // fails, something is really wrong + GKFS_DATA->spdlogger()->error("{}() while read_nonblock err '{}'", + __func__, e.what()); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } chnk_id_curr++; } // Sanity check that all chunks where detected in previous loop - // TODO error out. If we continue this will crash the server when sending results back that don't exist. - if (chnk_size_left_host != 0) - GKFS_DATA->spdlogger()->warn("{}() Not all chunks were detected!!! Size left {}", __func__, - chnk_size_left_host); + // TODO error out. If we continue this will crash the server when sending + // results back that don't exist. + if(chnk_size_left_host != 0) + GKFS_DATA->spdlogger()->warn( + "{}() Not all chunks were detected!!! Size left {}", __func__, + chnk_size_left_host); /* * 4. Read task results and accumulate in out.io_size */ @@ -438,7 +526,8 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { /* * 5. Respond and cleanup */ - GKFS_DATA->spdlogger()->debug("{}() Sending output response, err: {}", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output response, err: {}", + __func__, out.err); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } @@ -448,32 +537,38 @@ hg_return_t rpc_srv_read(hg_handle_t handle) { * @param handle * @return */ -hg_return_t rpc_srv_truncate(hg_handle_t handle) { +hg_return_t +rpc_srv_truncate(hg_handle_t handle) { rpc_trunc_in_t in{}; rpc_err_out_t out{}; out.err = EIO; // Getting some information from margo auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Could not get RPC input data with err {}", __func__, ret); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "{}() Could not get RPC input data with err {}", __func__, ret); return gkfs::rpc::cleanup_respond(&handle, &in, &out); } - GKFS_DATA->spdlogger()->debug("{}() path: '{}', length: '{}'", __func__, in.path, in.length); + GKFS_DATA->spdlogger()->debug("{}() path: '{}', length: '{}'", __func__, + in.path, in.length); gkfs::data::ChunkTruncateOperation chunk_op{in.path}; try { // start tasklet for truncate operation chunk_op.truncate(in.length); - } catch (const gkfs::data::ChunkMetaOpException& e) { - // This exception is caused by setup of Argobots variables. If this fails, something is really wrong - GKFS_DATA->spdlogger()->error("{}() while truncate err '{}'", __func__, e.what()); + } catch(const gkfs::data::ChunkMetaOpException& e) { + // This exception is caused by setup of Argobots variables. If this + // fails, something is really wrong + GKFS_DATA->spdlogger()->error("{}() while truncate err '{}'", __func__, + e.what()); return gkfs::rpc::cleanup_respond(&handle, &in, &out); } // wait and get output out.err = chunk_op.wait_for_task(); - GKFS_DATA->spdlogger()->debug("{}() Sending output response '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output response '{}'", __func__, + out.err); return gkfs::rpc::cleanup_respond(&handle, &in, &out); } @@ -483,7 +578,8 @@ hg_return_t rpc_srv_truncate(hg_handle_t handle) { * @param handle * @return */ -hg_return_t rpc_srv_get_chunk_stat(hg_handle_t handle) { +hg_return_t +rpc_srv_get_chunk_stat(hg_handle_t handle) { GKFS_DATA->spdlogger()->debug("{}() enter", __func__); rpc_chunk_stat_out_t out{}; out.err = EIO; @@ -493,11 +589,13 @@ hg_return_t rpc_srv_get_chunk_stat(hg_handle_t handle) { out.chunk_total = chk_stat.chunk_total; out.chunk_free = chk_stat.chunk_free; out.err = 0; - } catch (const gkfs::data::ChunkStorageException& err) { + } catch(const gkfs::data::ChunkStorageException& err) { GKFS_DATA->spdlogger()->error("{}() {}", __func__, err.what()); out.err = err.code().value(); - } catch (const ::exception& err) { - GKFS_DATA->spdlogger()->error("{}() Unexpected error when chunk stat '{}'", __func__, err.what()); + } catch(const ::exception& err) { + GKFS_DATA->spdlogger()->error( + "{}() Unexpected error when chunk stat '{}'", __func__, + err.what()); out.err = EAGAIN; } @@ -505,7 +603,7 @@ hg_return_t rpc_srv_get_chunk_stat(hg_handle_t handle) { return gkfs::rpc::cleanup_respond(&handle, &out); } -} +} // namespace DEFINE_MARGO_RPC_HANDLER(rpc_srv_write) @@ -516,12 +614,13 @@ DEFINE_MARGO_RPC_HANDLER(rpc_srv_truncate) DEFINE_MARGO_RPC_HANDLER(rpc_srv_get_chunk_stat) #ifdef GKFS_ENABLE_AGIOS -void *agios_eventual_callback(int64_t request_id, void* info) { - GKFS_DATA->spdlogger()->debug("{}() custom callback request {} is ready", __func__, request_id); +void* +agios_eventual_callback(int64_t request_id, void* info) { + GKFS_DATA->spdlogger()->debug("{}() custom callback request {} is ready", + __func__, request_id); ABT_eventual_set((ABT_eventual) info, &request_id, sizeof(int64_t)); return 0; } #endif - diff --git a/src/daemon/handler/srv_management.cpp b/src/daemon/handler/srv_management.cpp index 42752f83d..8156f8316 100644 --- a/src/daemon/handler/srv_management.cpp +++ b/src/daemon/handler/srv_management.cpp @@ -25,7 +25,8 @@ using namespace std; namespace { -hg_return_t rpc_srv_get_fs_config(hg_handle_t handle) { +hg_return_t +rpc_srv_get_fs_config(hg_handle_t handle) { rpc_config_out_t out{}; GKFS_DATA->spdlogger()->debug("{}() Got config RPC", __func__); @@ -40,11 +41,13 @@ hg_return_t rpc_srv_get_fs_config(hg_handle_t handle) { out.blocks_state = static_cast(GKFS_DATA->blocks_state()); out.uid = getuid(); out.gid = getgid(); - GKFS_DATA->spdlogger()->debug("{}() Sending output configs back to library", __func__); + GKFS_DATA->spdlogger()->debug("{}() Sending output configs back to library", + __func__); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Failed to respond to client to serve file system configurations", - __func__); + if(hret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to respond to client to serve file system configurations", + __func__); } // Destroy handle when finished @@ -52,7 +55,6 @@ hg_return_t rpc_srv_get_fs_config(hg_handle_t handle) { return HG_SUCCESS; } -} +} // namespace DEFINE_MARGO_RPC_HANDLER(rpc_srv_get_fs_config) - diff --git a/src/daemon/handler/srv_metadata.cpp b/src/daemon/handler/srv_metadata.cpp index 57ec47f99..99a97dd0c 100644 --- a/src/daemon/handler/srv_metadata.cpp +++ b/src/daemon/handler/srv_metadata.cpp @@ -23,32 +23,38 @@ using namespace std; /* - * This file contains all Margo RPC handlers that are concerning metadata operations + * This file contains all Margo RPC handlers that are concerning metadata + * operations */ namespace { -hg_return_t rpc_srv_create(hg_handle_t handle) { +hg_return_t +rpc_srv_create(hg_handle_t handle) { rpc_mk_node_in_t in; rpc_err_out_t out; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); assert(ret == HG_SUCCESS); - GKFS_DATA->spdlogger()->debug("{}() Got RPC with path '{}'", __func__, in.path); + GKFS_DATA->spdlogger()->debug("{}() Got RPC with path '{}'", __func__, + in.path); gkfs::metadata::Metadata md(in.mode); try { // create metadentry gkfs::metadata::create(in.path, md); out.err = 0; - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to create metadentry: '{}'", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error("{}() Failed to create metadentry: '{}'", + __func__, e.what()); out.err = -1; } - GKFS_DATA->spdlogger()->debug("{}() Sending output err '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output err '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } @@ -59,12 +65,14 @@ hg_return_t rpc_srv_create(hg_handle_t handle) { } -hg_return_t rpc_srv_stat(hg_handle_t handle) { +hg_return_t +rpc_srv_stat(hg_handle_t handle) { rpc_path_only_in_t in{}; rpc_stat_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); assert(ret == HG_SUCCESS); GKFS_DATA->spdlogger()->debug("{}() path: '{}'", __func__, in.path); std::string val; @@ -74,17 +82,21 @@ hg_return_t rpc_srv_stat(hg_handle_t handle) { val = gkfs::metadata::get_str(in.path); out.db_val = val.c_str(); out.err = 0; - GKFS_DATA->spdlogger()->debug("{}() Sending output mode '{}'", __func__, out.db_val); - } catch (const gkfs::metadata::NotFoundException& e) { - GKFS_DATA->spdlogger()->debug("{}() Entry not found: '{}'", __func__, in.path); + GKFS_DATA->spdlogger()->debug("{}() Sending output mode '{}'", __func__, + out.db_val); + } catch(const gkfs::metadata::NotFoundException& e) { + GKFS_DATA->spdlogger()->debug("{}() Entry not found: '{}'", __func__, + in.path); out.err = ENOENT; - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to get metadentry from DB: '{}'", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to get metadentry from DB: '{}'", __func__, + e.what()); out.err = EBUSY; } auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } @@ -95,29 +107,34 @@ hg_return_t rpc_srv_stat(hg_handle_t handle) { } -hg_return_t rpc_srv_decr_size(hg_handle_t handle) { +hg_return_t +rpc_srv_decr_size(hg_handle_t handle) { rpc_trunc_in_t in{}; rpc_err_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); throw runtime_error("Failed to retrieve input from handle"); } - GKFS_DATA->spdlogger()->debug("{}() path: '{}', length: '{}'", __func__, in.path, in.length); + GKFS_DATA->spdlogger()->debug("{}() path: '{}', length: '{}'", __func__, + in.path, in.length); try { GKFS_DATA->mdb()->decrease_size(in.path, in.length); out.err = 0; - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to decrease size: '{}'", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error("{}() Failed to decrease size: '{}'", + __func__, e.what()); out.err = EIO; } - GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); throw runtime_error("Failed to respond"); } @@ -128,35 +145,43 @@ hg_return_t rpc_srv_decr_size(hg_handle_t handle) { } -hg_return_t rpc_srv_remove(hg_handle_t handle) { +hg_return_t +rpc_srv_remove(hg_handle_t handle) { rpc_rm_node_in_t in{}; rpc_err_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); assert(ret == HG_SUCCESS); - GKFS_DATA->spdlogger()->debug("{}() Got remove node RPC with path '{}'", __func__, in.path); + GKFS_DATA->spdlogger()->debug("{}() Got remove node RPC with path '{}'", + __func__, in.path); - // Remove metadentry if exists on the node and remove all chunks for that file + // Remove metadentry if exists on the node and remove all chunks for that + // file try { gkfs::metadata::remove(in.path); out.err = 0; - } catch (const gkfs::metadata::DBException& e) { - GKFS_DATA->spdlogger()->error("{}(): path '{}' message '{}'", __func__, in.path, e.what()); + } catch(const gkfs::metadata::DBException& e) { + GKFS_DATA->spdlogger()->error("{}(): path '{}' message '{}'", __func__, + in.path, e.what()); out.err = EIO; - } catch (const gkfs::data::ChunkStorageException& e) { - GKFS_DATA->spdlogger()->error("{}(): path '{}' errcode '{}' message '{}'", __func__, in.path, e.code().value(), - e.what()); + } catch(const gkfs::data::ChunkStorageException& e) { + GKFS_DATA->spdlogger()->error( + "{}(): path '{}' errcode '{}' message '{}'", __func__, in.path, + e.code().value(), e.what()); out.err = e.code().value(); - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() path '{}' message '{}'", __func__, in.path, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error("{}() path '{}' message '{}'", __func__, + in.path, e.what()); out.err = EBUSY; } - GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } // Destroy handle when finished @@ -166,43 +191,47 @@ hg_return_t rpc_srv_remove(hg_handle_t handle) { } -hg_return_t rpc_srv_update_metadentry(hg_handle_t handle) { +hg_return_t +rpc_srv_update_metadentry(hg_handle_t handle) { rpc_update_metadentry_in_t in{}; rpc_err_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); assert(ret == HG_SUCCESS); - GKFS_DATA->spdlogger()->debug("{}() Got update metadentry RPC with path '{}'", __func__, in.path); + GKFS_DATA->spdlogger()->debug( + "{}() Got update metadentry RPC with path '{}'", __func__, in.path); // do update try { gkfs::metadata::Metadata md = gkfs::metadata::get(in.path); - if (in.block_flag == HG_TRUE) + if(in.block_flag == HG_TRUE) md.blocks(in.blocks); - if (in.nlink_flag == HG_TRUE) + if(in.nlink_flag == HG_TRUE) md.link_count(in.nlink); - if (in.size_flag == HG_TRUE) + if(in.size_flag == HG_TRUE) md.size(in.size); - if (in.atime_flag == HG_TRUE) + if(in.atime_flag == HG_TRUE) md.atime(in.atime); - if (in.mtime_flag == HG_TRUE) + if(in.mtime_flag == HG_TRUE) md.mtime(in.mtime); - if (in.ctime_flag == HG_TRUE) + if(in.ctime_flag == HG_TRUE) md.ctime(in.ctime); gkfs::metadata::update(in.path, md); out.err = 0; - } catch (const std::exception& e) { - //TODO handle NotFoundException + } catch(const std::exception& e) { + // TODO handle NotFoundException GKFS_DATA->spdlogger()->error("{}() Failed to update entry", __func__); out.err = 1; } - GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } @@ -213,35 +242,44 @@ hg_return_t rpc_srv_update_metadentry(hg_handle_t handle) { } -hg_return_t rpc_srv_update_metadentry_size(hg_handle_t handle) { +hg_return_t +rpc_srv_update_metadentry_size(hg_handle_t handle) { rpc_update_metadentry_size_in_t in{}; rpc_update_metadentry_size_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); assert(ret == HG_SUCCESS); - GKFS_DATA->spdlogger()->debug("{}() path: '{}', size: '{}', offset: '{}', append: '{}'", __func__, in.path, in.size, - in.offset, in.append); + GKFS_DATA->spdlogger()->debug( + "{}() path: '{}', size: '{}', offset: '{}', append: '{}'", __func__, + in.path, in.size, in.offset, in.append); try { - gkfs::metadata::update_size(in.path, in.size, in.offset, (in.append == HG_TRUE)); + gkfs::metadata::update_size(in.path, in.size, in.offset, + (in.append == HG_TRUE)); out.err = 0; - //TODO the actual size of the file could be different after the size update + // TODO the actual size of the file could be different after the size + // update // do to concurrency on size out.ret_size = in.size + in.offset; - } catch (const gkfs::metadata::NotFoundException& e) { - GKFS_DATA->spdlogger()->debug("{}() Entry not found: '{}'", __func__, in.path); + } catch(const gkfs::metadata::NotFoundException& e) { + GKFS_DATA->spdlogger()->debug("{}() Entry not found: '{}'", __func__, + in.path); out.err = ENOENT; - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to update metadentry size on DB: '{}'", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to update metadentry size on DB: '{}'", __func__, + e.what()); out.err = EBUSY; } - GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } @@ -252,32 +290,40 @@ hg_return_t rpc_srv_update_metadentry_size(hg_handle_t handle) { } -hg_return_t rpc_srv_get_metadentry_size(hg_handle_t handle) { +hg_return_t +rpc_srv_get_metadentry_size(hg_handle_t handle) { rpc_path_only_in_t in{}; rpc_get_metadentry_size_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); assert(ret == HG_SUCCESS); - GKFS_DATA->spdlogger()->debug("{}() Got update metadentry size RPC with path '{}'", __func__, in.path); + GKFS_DATA->spdlogger()->debug( + "{}() Got update metadentry size RPC with path '{}'", __func__, + in.path); // do update try { out.ret_size = gkfs::metadata::get_size(in.path); out.err = 0; - } catch (const gkfs::metadata::NotFoundException& e) { - GKFS_DATA->spdlogger()->debug("{}() Entry not found: '{}'", __func__, in.path); + } catch(const gkfs::metadata::NotFoundException& e) { + GKFS_DATA->spdlogger()->debug("{}() Entry not found: '{}'", __func__, + in.path); out.err = ENOENT; - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to get metadentry size from DB: '{}'", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to get metadentry size from DB: '{}'", __func__, + e.what()); out.err = EBUSY; } - GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } @@ -288,7 +334,8 @@ hg_return_t rpc_srv_get_metadentry_size(hg_handle_t handle) { } -hg_return_t rpc_srv_get_dirents(hg_handle_t handle) { +hg_return_t +rpc_srv_get_dirents(hg_handle_t handle) { rpc_get_dirents_in_t in{}; rpc_get_dirents_out_t out{}; out.err = EIO; @@ -297,9 +344,10 @@ hg_return_t rpc_srv_get_dirents(hg_handle_t handle) { // Get input parmeters auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) { + if(ret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error( - "{}() Could not get RPC input data with err '{}'", __func__, ret); + "{}() Could not get RPC input data with err '{}'", __func__, + ret); out.err = EBUSY; return gkfs::rpc::cleanup_respond(&handle, &in, &out); } @@ -308,56 +356,67 @@ hg_return_t rpc_srv_get_dirents(hg_handle_t handle) { auto hgi = margo_get_info(handle); auto mid = margo_hg_info_get_instance(hgi); auto bulk_size = margo_bulk_get_size(in.bulk_handle); - GKFS_DATA->spdlogger()->debug("{}() Got RPC: path '{}' bulk_size '{}' ", __func__, in.path, bulk_size); + GKFS_DATA->spdlogger()->debug("{}() Got RPC: path '{}' bulk_size '{}' ", + __func__, in.path, bulk_size); - //Get directory entries from local DB + // Get directory entries from local DB vector> entries{}; try { entries = gkfs::metadata::get_dirents(in.path); - } catch (const ::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Error during get_dirents(): '{}'", __func__, e.what()); + } catch(const ::exception& e) { + GKFS_DATA->spdlogger()->error("{}() Error during get_dirents(): '{}'", + __func__, e.what()); return gkfs::rpc::cleanup_respond(&handle, &in, &out); } - GKFS_DATA->spdlogger()->trace("{}() path '{}' Read database with '{}' entries", __func__, in.path, - entries.size()); + GKFS_DATA->spdlogger()->trace( + "{}() path '{}' Read database with '{}' entries", __func__, in.path, + entries.size()); - if (entries.empty()) { + if(entries.empty()) { out.err = 0; return gkfs::rpc::cleanup_respond(&handle, &in, &out); } - //Calculate total output size - //TODO OPTIMIZATION: this can be calculated inside db_get_dirents + // Calculate total output size + // TODO OPTIMIZATION: this can be calculated inside db_get_dirents size_t tot_names_size = 0; - for (auto const& e: entries) { + for(auto const& e : entries) { tot_names_size += e.first.size(); } - // tot_names_size (# characters in entry) + # entries * (bool size + char size for \0 character) - size_t out_size = tot_names_size + entries.size() * (sizeof(bool) + sizeof(char)); - if (bulk_size < out_size) { - //Source buffer is smaller than total output size + // tot_names_size (# characters in entry) + # entries * (bool size + char + // size for \0 character) + size_t out_size = + tot_names_size + entries.size() * (sizeof(bool) + sizeof(char)); + if(bulk_size < out_size) { + // Source buffer is smaller than total output size GKFS_DATA->spdlogger()->error( - "{}() Entries do not fit source buffer. bulk_size '{}' < out_size '{}' must be satisfied!", __func__, - bulk_size, out_size); + "{}() Entries do not fit source buffer. bulk_size '{}' < out_size '{}' must be satisfied!", + __func__, bulk_size, out_size); out.err = ENOBUFS; return gkfs::rpc::cleanup_respond(&handle, &in, &out); } - void* bulk_buf; //buffer for bulk transfer - // create bulk handle and allocated memory for buffer with out_size information - ret = margo_bulk_create(mid, 1, nullptr, &out_size, HG_BULK_READ_ONLY, &bulk_handle); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", __func__); + void* bulk_buf; // buffer for bulk transfer + // create bulk handle and allocated memory for buffer with out_size + // information + ret = margo_bulk_create(mid, 1, nullptr, &out_size, HG_BULK_READ_ONLY, + &bulk_handle); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error("{}() Failed to create bulk handle", + __func__); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } // access the internally allocated memory buffer and put it into bulk_buf - uint32_t actual_count; // number of segments. we use one here because we push the whole buffer at once - ret = margo_bulk_access(bulk_handle, 0, out_size, HG_BULK_READ_ONLY, 1, &bulk_buf, - &out_size, &actual_count); - if (ret != HG_SUCCESS || actual_count != 1) { - GKFS_DATA->spdlogger()->error("{}() Failed to access allocated buffer from bulk handle", __func__); + uint32_t actual_count; // number of segments. we use one here because we + // push the whole buffer at once + ret = margo_bulk_access(bulk_handle, 0, out_size, HG_BULK_READ_ONLY, 1, + &bulk_buf, &out_size, &actual_count); + if(ret != HG_SUCCESS || actual_count != 1) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to access allocated buffer from bulk handle", + __func__); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } @@ -365,15 +424,16 @@ hg_return_t rpc_srv_get_dirents(hg_handle_t handle) { "{}() path '{}' entries '{}' out_size '{}'. Set up local read only bulk handle and allocated buffer with size '{}'", __func__, in.path, entries.size(), out_size, out_size); - //Serialize output data on local buffer + // Serialize output data on local buffer auto out_buff_ptr = static_cast(bulk_buf); auto bool_ptr = reinterpret_cast(out_buff_ptr); auto names_ptr = out_buff_ptr + entries.size(); - for (auto const& e: entries) { - if (e.first.empty()) { + for(auto const& e : entries) { + if(e.first.empty()) { GKFS_DATA->spdlogger()->warn( - "{}() Entry in readdir() empty. If this shows up, something else is very wrong.", __func__); + "{}() Entry in readdir() empty. If this shows up, something else is very wrong.", + __func__); } *bool_ptr = e.second; bool_ptr++; @@ -385,52 +445,58 @@ hg_return_t rpc_srv_get_dirents(hg_handle_t handle) { } GKFS_DATA->spdlogger()->trace( - "{}() path '{}' entries '{}' out_size '{}'. Copied data to bulk_buffer. NEXT bulk_transfer", __func__, - in.path, entries.size(), out_size); + "{}() path '{}' entries '{}' out_size '{}'. Copied data to bulk_buffer. NEXT bulk_transfer", + __func__, in.path, entries.size(), out_size); - ret = margo_bulk_transfer(mid, HG_BULK_PUSH, hgi->addr, in.bulk_handle, 0, bulk_handle, 0, out_size); - if (ret != HG_SUCCESS) { + ret = margo_bulk_transfer(mid, HG_BULK_PUSH, hgi->addr, in.bulk_handle, 0, + bulk_handle, 0, out_size); + if(ret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error( "{}() Failed to push '{}' dirents on path '{}' to client with bulk size '{}' and out_size '{}'", - __func__, - entries.size(), in.path, bulk_size, out_size); + __func__, entries.size(), in.path, bulk_size, out_size); out.err = EBUSY; return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } out.dirents_size = entries.size(); out.err = 0; - GKFS_DATA->spdlogger()->debug("{}() Sending output response err '{}' dirents_size '{}'. DONE", __func__, - out.err, - out.dirents_size); + GKFS_DATA->spdlogger()->debug( + "{}() Sending output response err '{}' dirents_size '{}'. DONE", + __func__, out.err, out.dirents_size); return gkfs::rpc::cleanup_respond(&handle, &in, &out, &bulk_handle); } #ifdef HAS_SYMLINKS -hg_return_t rpc_srv_mk_symlink(hg_handle_t handle) { +hg_return_t +rpc_srv_mk_symlink(hg_handle_t handle) { rpc_mk_symlink_in_t in{}; rpc_err_out_t out{}; auto ret = margo_get_input(handle, &in); - if (ret != HG_SUCCESS) { - GKFS_DATA->spdlogger()->error("{}() Failed to retrieve input from handle", __func__); + if(ret != HG_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "{}() Failed to retrieve input from handle", __func__); } - GKFS_DATA->spdlogger()->debug("{}() Got RPC with path '{}'", __func__, in.path); + GKFS_DATA->spdlogger()->debug("{}() Got RPC with path '{}'", __func__, + in.path); try { - gkfs::metadata::Metadata md = {gkfs::metadata::LINK_MODE, in.target_path}; + gkfs::metadata::Metadata md = {gkfs::metadata::LINK_MODE, + in.target_path}; // create metadentry gkfs::metadata::create(in.path, md); out.err = 0; - } catch (const std::exception& e) { - GKFS_DATA->spdlogger()->error("{}() Failed to create metadentry: '{}'", __func__, e.what()); + } catch(const std::exception& e) { + GKFS_DATA->spdlogger()->error("{}() Failed to create metadentry: '{}'", + __func__, e.what()); out.err = -1; } - GKFS_DATA->spdlogger()->debug("{}() Sending output err '{}'", __func__, out.err); + GKFS_DATA->spdlogger()->debug("{}() Sending output err '{}'", __func__, + out.err); auto hret = margo_respond(handle, &out); - if (hret != HG_SUCCESS) { + if(hret != HG_SUCCESS) { GKFS_DATA->spdlogger()->error("{}() Failed to respond", __func__); } @@ -442,7 +508,7 @@ hg_return_t rpc_srv_mk_symlink(hg_handle_t handle) { #endif -} +} // namespace DEFINE_MARGO_RPC_HANDLER(rpc_srv_create) diff --git a/src/daemon/ops/data.cpp b/src/daemon/ops/data.cpp index 020918a84..741bd7d09 100644 --- a/src/daemon/ops/data.cpp +++ b/src/daemon/ops/data.cpp @@ -35,10 +35,12 @@ namespace data { * const string* path; size_t size; ABT_eventual* eventual; - * This function is driven by the IO pool. so there is a maximum allowed number of concurrent operations per daemon. + * This function is driven by the IO pool. so there is a maximum allowed number + of concurrent operations per daemon. * @return error is put into eventual to signal that it finished */ -void ChunkTruncateOperation::truncate_abt(void* _arg) { +void +ChunkTruncateOperation::truncate_abt(void* _arg) { assert(_arg); // Unpack args auto* arg = static_cast(_arg); @@ -47,44 +49,54 @@ void ChunkTruncateOperation::truncate_abt(void* _arg) { int err_response = 0; try { // get chunk from where to cut off - auto chunk_id_start = gkfs::util::chnk_id_for_offset(size, gkfs::config::rpc::chunksize); + auto chunk_id_start = gkfs::util::chnk_id_for_offset( + size, gkfs::config::rpc::chunksize); // do not last delete chunk if it is in the middle of a chunk - auto left_pad = gkfs::util::chnk_lpad(size, gkfs::config::rpc::chunksize); - if (left_pad != 0) { - GKFS_DATA->storage()->truncate_chunk_file(path, chunk_id_start, left_pad); + auto left_pad = + gkfs::util::chnk_lpad(size, gkfs::config::rpc::chunksize); + if(left_pad != 0) { + GKFS_DATA->storage()->truncate_chunk_file(path, chunk_id_start, + left_pad); chunk_id_start++; } GKFS_DATA->storage()->trim_chunk_space(path, chunk_id_start); - } catch (const ChunkStorageException& err) { + } catch(const ChunkStorageException& err) { GKFS_DATA->spdlogger()->error("{}() {}", __func__, err.what()); err_response = err.code().value(); - } catch (const ::exception& err) { - GKFS_DATA->spdlogger()->error("{}() Unexpected error truncating file '{}' to length '{}'", __func__, path, - size); + } catch(const ::exception& err) { + GKFS_DATA->spdlogger()->error( + "{}() Unexpected error truncating file '{}' to length '{}'", + __func__, path, size); err_response = EIO; } ABT_eventual_set(arg->eventual, &err_response, sizeof(err_response)); } -void ChunkTruncateOperation::clear_task_args() { +void +ChunkTruncateOperation::clear_task_args() { task_arg_ = {}; } -ChunkTruncateOperation::ChunkTruncateOperation(const string& path) : ChunkOperation{path, 1} {} +ChunkTruncateOperation::ChunkTruncateOperation(const string& path) + : ChunkOperation{path, 1} {} /** - * Starts a tasklet for requested truncate. In essence all chunk files after the given offset is removed - * Only one truncate call is allowed at a time + * Starts a tasklet for requested truncate. In essence all chunk files after the + * given offset is removed Only one truncate call is allowed at a time */ -void ChunkTruncateOperation::truncate(size_t size) { +void +ChunkTruncateOperation::truncate(size_t size) { assert(!task_eventuals_[0]); - GKFS_DATA->spdlogger()->trace("ChunkTruncateOperation::{}() enter: path '{}' size '{}'", __func__, path_, - size); + GKFS_DATA->spdlogger()->trace( + "ChunkTruncateOperation::{}() enter: path '{}' size '{}'", __func__, + path_, size); // sizeof(int) comes from truncate's return type - auto abt_err = ABT_eventual_create(sizeof(int), &task_eventuals_[0]); // truncate file return value - if (abt_err != ABT_SUCCESS) { - auto err_str = fmt::format("ChunkTruncateOperation::{}() Failed to create ABT eventual with abt_err '{}'", - __func__, abt_err); + auto abt_err = ABT_eventual_create( + sizeof(int), &task_eventuals_[0]); // truncate file return value + if(abt_err != ABT_SUCCESS) { + auto err_str = fmt::format( + "ChunkTruncateOperation::{}() Failed to create ABT eventual with abt_err '{}'", + __func__, abt_err); throw ChunkMetaOpException(err_str); } @@ -93,29 +105,34 @@ void ChunkTruncateOperation::truncate(size_t size) { task_arg.size = size; task_arg.eventual = task_eventuals_[0]; - abt_err = ABT_task_create(RPC_DATA->io_pool(), truncate_abt, &task_arg_, &abt_tasks_[0]); - if (abt_err != ABT_SUCCESS) { - auto err_str = fmt::format("ChunkTruncateOperation::{}() Failed to create ABT task with abt_err '{}'", __func__, - abt_err); + abt_err = ABT_task_create(RPC_DATA->io_pool(), truncate_abt, &task_arg_, + &abt_tasks_[0]); + if(abt_err != ABT_SUCCESS) { + auto err_str = fmt::format( + "ChunkTruncateOperation::{}() Failed to create ABT task with abt_err '{}'", + __func__, abt_err); throw ChunkMetaOpException(err_str); } - } -int ChunkTruncateOperation::wait_for_task() { - GKFS_DATA->spdlogger()->trace("ChunkTruncateOperation::{}() enter: path '{}'", __func__, path_); +int +ChunkTruncateOperation::wait_for_task() { + GKFS_DATA->spdlogger()->trace( + "ChunkTruncateOperation::{}() enter: path '{}'", __func__, path_); int trunc_err = 0; int* task_err = nullptr; auto abt_err = ABT_eventual_wait(task_eventuals_[0], (void**) &task_err); - if (abt_err != ABT_SUCCESS) { - GKFS_DATA->spdlogger()->error("ChunkTruncateOperation::{}() Error when waiting on ABT eventual", __func__); + if(abt_err != ABT_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "ChunkTruncateOperation::{}() Error when waiting on ABT eventual", + __func__); ABT_eventual_free(&task_eventuals_[0]); return EIO; } assert(task_err != nullptr); - if (*task_err != 0) { + if(*task_err != 0) { trunc_err = *task_err; } ABT_eventual_free(&task_eventuals_[0]); @@ -134,41 +151,48 @@ int ChunkTruncateOperation::wait_for_task() { size_t size; off64_t off; ABT_eventual* eventual; - * This function is driven by the IO pool. so there is a maximum allowed number of concurrent IO operations per daemon. - * This function is called by tasklets, as this function cannot be allowed to block. + * This function is driven by the IO pool. so there is a maximum allowed number + of concurrent IO operations per daemon. + * This function is called by tasklets, as this function cannot be allowed to + block. * @return written_size is put into eventual to signal that it finished */ -void ChunkWriteOperation::write_file_abt(void* _arg) { +void +ChunkWriteOperation::write_file_abt(void* _arg) { assert(_arg); // Unpack args auto* arg = static_cast(_arg); const string& path = *(arg->path); ssize_t wrote{0}; try { - wrote = GKFS_DATA->storage()->write_chunk(path, arg->chnk_id, arg->buf, arg->size, arg->off); - } catch (const ChunkStorageException& err) { + wrote = GKFS_DATA->storage()->write_chunk(path, arg->chnk_id, arg->buf, + arg->size, arg->off); + } catch(const ChunkStorageException& err) { GKFS_DATA->spdlogger()->error("{}() {}", __func__, err.what()); wrote = -(err.code().value()); - } catch (const ::exception& err) { - GKFS_DATA->spdlogger()->error("{}() Unexpected error writing chunk {} of file {}", __func__, arg->chnk_id, - path); + } catch(const ::exception& err) { + GKFS_DATA->spdlogger()->error( + "{}() Unexpected error writing chunk {} of file {}", __func__, + arg->chnk_id, path); wrote = -EIO; } ABT_eventual_set(arg->eventual, &wrote, sizeof(wrote)); } -void ChunkWriteOperation::clear_task_args() { +void +ChunkWriteOperation::clear_task_args() { task_args_.clear(); } -ChunkWriteOperation::ChunkWriteOperation(const string& path, size_t n) : ChunkOperation{path, n} { +ChunkWriteOperation::ChunkWriteOperation(const string& path, size_t n) + : ChunkOperation{path, n} { task_args_.resize(n); } /** - * Write buffer from a single chunk referenced by its ID. Put task into IO queue. - * On failure the write operations is aborted, throwing an error, and cleaned up. - * The caller may repeat a failed call. + * Write buffer from a single chunk referenced by its ID. Put task into IO + * queue. On failure the write operations is aborted, throwing an error, and + * cleaned up. The caller may repeat a failed call. * @param chunk_id * @param bulk_buf_ptr * @param size @@ -176,17 +200,21 @@ ChunkWriteOperation::ChunkWriteOperation(const string& path, size_t n) : ChunkOp * @throws ChunkWriteOpException */ void -ChunkWriteOperation::write_nonblock(size_t idx, const uint64_t chunk_id, const char* bulk_buf_ptr, - const size_t size, +ChunkWriteOperation::write_nonblock(size_t idx, const uint64_t chunk_id, + const char* bulk_buf_ptr, const size_t size, const off64_t offset) { assert(idx < task_args_.size()); - GKFS_DATA->spdlogger()->trace("ChunkWriteOperation::{}() enter: idx '{}' path '{}' size '{}' offset '{}'", __func__, - idx, path_, size, offset); + GKFS_DATA->spdlogger()->trace( + "ChunkWriteOperation::{}() enter: idx '{}' path '{}' size '{}' offset '{}'", + __func__, idx, path_, size, offset); // sizeof(ssize_t) comes from pwrite's return type - auto abt_err = ABT_eventual_create(sizeof(ssize_t), &task_eventuals_[idx]); // written file return value - if (abt_err != ABT_SUCCESS) { - auto err_str = fmt::format("ChunkWriteOperation::{}() Failed to create ABT eventual with abt_err '{}'", - __func__, abt_err); + auto abt_err = ABT_eventual_create( + sizeof(ssize_t), + &task_eventuals_[idx]); // written file return value + if(abt_err != ABT_SUCCESS) { + auto err_str = fmt::format( + "ChunkWriteOperation::{}() Failed to create ABT eventual with abt_err '{}'", + __func__, abt_err); throw ChunkWriteOpException(err_str); } @@ -198,41 +226,49 @@ ChunkWriteOperation::write_nonblock(size_t idx, const uint64_t chunk_id, const c task_arg.off = offset; task_arg.eventual = task_eventuals_[idx]; - abt_err = ABT_task_create(RPC_DATA->io_pool(), write_file_abt, &task_args_[idx], &abt_tasks_[idx]); - if (abt_err != ABT_SUCCESS) { - auto err_str = fmt::format("ChunkWriteOperation::{}() Failed to create ABT task with abt_err '{}'", __func__, - abt_err); + abt_err = ABT_task_create(RPC_DATA->io_pool(), write_file_abt, + &task_args_[idx], &abt_tasks_[idx]); + if(abt_err != ABT_SUCCESS) { + auto err_str = fmt::format( + "ChunkWriteOperation::{}() Failed to create ABT task with abt_err '{}'", + __func__, abt_err); throw ChunkWriteOpException(err_str); } } /** - * Waits for all Argobots tasklets to finish and report back the write error code and the size written. + * Waits for all Argobots tasklets to finish and report back the write error + * code and the size written. * @return */ -pair ChunkWriteOperation::wait_for_tasks() { - GKFS_DATA->spdlogger()->trace("ChunkWriteOperation::{}() enter: path '{}'", __func__, path_); +pair +ChunkWriteOperation::wait_for_tasks() { + GKFS_DATA->spdlogger()->trace("ChunkWriteOperation::{}() enter: path '{}'", + __func__, path_); size_t total_written = 0; int io_err = 0; /* - * gather all Eventual's information. do not throw here to properly cleanup all eventuals - * On error, cleanup eventuals and set written data to 0 as written data is corrupted + * gather all Eventual's information. do not throw here to properly cleanup + * all eventuals On error, cleanup eventuals and set written data to 0 as + * written data is corrupted */ - for (auto& e : task_eventuals_) { + for(auto& e : task_eventuals_) { ssize_t* task_size = nullptr; auto abt_err = ABT_eventual_wait(e, (void**) &task_size); - if (abt_err != ABT_SUCCESS) { - GKFS_DATA->spdlogger()->error("ChunkWriteOperation::{}() Error when waiting on ABT eventual", __func__); + if(abt_err != ABT_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "ChunkWriteOperation::{}() Error when waiting on ABT eventual", + __func__); io_err = EIO; ABT_eventual_free(&e); continue; } - if (io_err != 0) { + if(io_err != 0) { ABT_eventual_free(&e); continue; } assert(task_size != nullptr); - if (*task_size < 0) { + if(*task_size < 0) { io_err = -(*task_size); } else { total_written += *task_size; @@ -240,7 +276,7 @@ pair ChunkWriteOperation::wait_for_tasks() { ABT_eventual_free(&e); } // in case of error set written size to zero as data would be corrupted - if (io_err != 0) + if(io_err != 0) total_written = 0; return make_pair(io_err, total_written); } @@ -257,35 +293,43 @@ pair ChunkWriteOperation::wait_for_tasks() { size_t size; off64_t off; ABT_eventual* eventual; - * This function is driven by the IO pool. so there is a maximum allowed number of concurrent IO operations per daemon. - * This function is called by tasklets, as this function cannot be allowed to block. + * This function is driven by the IO pool. so there is a maximum allowed number + of concurrent IO operations per daemon. + * This function is called by tasklets, as this function cannot be allowed to + block. * @return read_size is put into eventual to signal that it finished */ -void ChunkReadOperation::read_file_abt(void* _arg) { +void +ChunkReadOperation::read_file_abt(void* _arg) { assert(_arg); - //unpack args + // unpack args auto* arg = static_cast(_arg); const string& path = *(arg->path); ssize_t read = 0; try { - // Under expected circumstances (error or no error) read_chunk will signal the eventual - read = GKFS_DATA->storage()->read_chunk(path, arg->chnk_id, arg->buf, arg->size, arg->off); - } catch (const ChunkStorageException& err) { + // Under expected circumstances (error or no error) read_chunk will + // signal the eventual + read = GKFS_DATA->storage()->read_chunk(path, arg->chnk_id, arg->buf, + arg->size, arg->off); + } catch(const ChunkStorageException& err) { GKFS_DATA->spdlogger()->error("{}() {}", __func__, err.what()); read = -(err.code().value()); - } catch (const ::exception& err) { - GKFS_DATA->spdlogger()->error("{}() Unexpected error reading chunk {} of file {}", __func__, arg->chnk_id, - path); + } catch(const ::exception& err) { + GKFS_DATA->spdlogger()->error( + "{}() Unexpected error reading chunk {} of file {}", __func__, + arg->chnk_id, path); read = -EIO; } ABT_eventual_set(arg->eventual, &read, sizeof(read)); } -void ChunkReadOperation::clear_task_args() { +void +ChunkReadOperation::clear_task_args() { task_args_.clear(); } -ChunkReadOperation::ChunkReadOperation(const string& path, size_t n) : ChunkOperation{path, n} { +ChunkReadOperation::ChunkReadOperation(const string& path, size_t n) + : ChunkOperation{path, n} { task_args_.resize(n); } @@ -299,16 +343,20 @@ ChunkReadOperation::ChunkReadOperation(const string& path, size_t n) : ChunkOper * @param offset */ void -ChunkReadOperation::read_nonblock(size_t idx, const uint64_t chunk_id, char* bulk_buf_ptr, const size_t size, +ChunkReadOperation::read_nonblock(size_t idx, const uint64_t chunk_id, + char* bulk_buf_ptr, const size_t size, const off64_t offset) { assert(idx < task_args_.size()); - GKFS_DATA->spdlogger()->trace("ChunkReadOperation::{}() enter: idx '{}' path '{}' size '{}' offset '{}'", __func__, - idx, path_, size, offset); + GKFS_DATA->spdlogger()->trace( + "ChunkReadOperation::{}() enter: idx '{}' path '{}' size '{}' offset '{}'", + __func__, idx, path_, size, offset); // sizeof(ssize_t) comes from pread's return type - auto abt_err = ABT_eventual_create(sizeof(ssize_t), &task_eventuals_[idx]); // read file return value - if (abt_err != ABT_SUCCESS) { - auto err_str = fmt::format("ChunkReadOperation::{}() Failed to create ABT eventual with abt_err '{}'", - __func__, abt_err); + auto abt_err = ABT_eventual_create( + sizeof(ssize_t), &task_eventuals_[idx]); // read file return value + if(abt_err != ABT_SUCCESS) { + auto err_str = fmt::format( + "ChunkReadOperation::{}() Failed to create ABT eventual with abt_err '{}'", + __func__, abt_err); throw ChunkReadOpException(err_str); } @@ -320,66 +368,77 @@ ChunkReadOperation::read_nonblock(size_t idx, const uint64_t chunk_id, char* bul task_arg.off = offset; task_arg.eventual = task_eventuals_[idx]; - abt_err = ABT_task_create(RPC_DATA->io_pool(), read_file_abt, &task_args_[idx], &abt_tasks_[idx]); - if (abt_err != ABT_SUCCESS) { - auto err_str = fmt::format("ChunkReadOperation::{}() Failed to create ABT task with abt_err '{}'", __func__, - abt_err); + abt_err = ABT_task_create(RPC_DATA->io_pool(), read_file_abt, + &task_args_[idx], &abt_tasks_[idx]); + if(abt_err != ABT_SUCCESS) { + auto err_str = fmt::format( + "ChunkReadOperation::{}() Failed to create ABT task with abt_err '{}'", + __func__, abt_err); throw ChunkReadOpException(err_str); } - } -pair ChunkReadOperation::wait_for_tasks_and_push_back(const bulk_args& args) { - GKFS_DATA->spdlogger()->trace("ChunkReadOperation::{}() enter: path '{}'", __func__, path_); +pair +ChunkReadOperation::wait_for_tasks_and_push_back(const bulk_args& args) { + GKFS_DATA->spdlogger()->trace("ChunkReadOperation::{}() enter: path '{}'", + __func__, path_); assert(args.chunk_ids->size() == task_args_.size()); size_t total_read = 0; int io_err = 0; /* - * gather all Eventual's information. do not throw here to properly cleanup all eventuals - * As soon as an error is encountered, bulk_transfers will no longer be executed as the data would be corrupted - * The loop continues until all eventuals have been cleaned and freed. + * gather all Eventual's information. do not throw here to properly cleanup + * all eventuals As soon as an error is encountered, bulk_transfers will no + * longer be executed as the data would be corrupted The loop continues + * until all eventuals have been cleaned and freed. */ - for (uint64_t idx = 0; idx < task_args_.size(); idx++) { + for(uint64_t idx = 0; idx < task_args_.size(); idx++) { ssize_t* task_size = nullptr; - auto abt_err = ABT_eventual_wait(task_eventuals_[idx], (void**) &task_size); - if (abt_err != ABT_SUCCESS) { - GKFS_DATA->spdlogger()->error("ChunkReadOperation::{}() Error when waiting on ABT eventual", __func__); + auto abt_err = + ABT_eventual_wait(task_eventuals_[idx], (void**) &task_size); + if(abt_err != ABT_SUCCESS) { + GKFS_DATA->spdlogger()->error( + "ChunkReadOperation::{}() Error when waiting on ABT eventual", + __func__); io_err = EIO; ABT_eventual_free(&task_eventuals_[idx]); continue; } // error occured. stop processing but clean up - if (io_err != 0) { + if(io_err != 0) { ABT_eventual_free(&task_eventuals_[idx]); continue; } assert(task_size != nullptr); - if (*task_size < 0) { + if(*task_size < 0) { // sparse regions do not have chunk files and are therefore skipped - if (-(*task_size) == ENOENT) { + if(-(*task_size) == ENOENT) { ABT_eventual_free(&task_eventuals_[idx]); continue; } io_err = -(*task_size); // make error code > 0 - } else if (*task_size == 0) { - // read size of 0 is not an error and can happen because reading the end-of-file + } else if(*task_size == 0) { + // read size of 0 is not an error and can happen because reading the + // end-of-file ABT_eventual_free(&task_eventuals_[idx]); continue; } else { // successful case, push read data back to client GKFS_DATA->spdlogger()->trace( "ChunkReadOperation::{}() BULK_TRANSFER_PUSH file '{}' chnkid '{}' origin offset '{}' local offset '{}' transfersize '{}'", - __func__, path_, args.chunk_ids->at(idx), args.origin_offsets->at(idx), args.local_offsets->at(idx), + __func__, path_, args.chunk_ids->at(idx), + args.origin_offsets->at(idx), args.local_offsets->at(idx), *task_size); assert(task_args_[idx].chnk_id == args.chunk_ids->at(idx)); - auto margo_err = margo_bulk_transfer(args.mid, HG_BULK_PUSH, args.origin_addr, args.origin_bulk_handle, - args.origin_offsets->at(idx), args.local_bulk_handle, - args.local_offsets->at(idx), *task_size); - if (margo_err != HG_SUCCESS) { + auto margo_err = margo_bulk_transfer( + args.mid, HG_BULK_PUSH, args.origin_addr, + args.origin_bulk_handle, args.origin_offsets->at(idx), + args.local_bulk_handle, args.local_offsets->at(idx), + *task_size); + if(margo_err != HG_SUCCESS) { GKFS_DATA->spdlogger()->error( - "ChunkReadOperation::{}() Failed to margo_bulk_transfer with margo err: '{}'", __func__, - margo_err); + "ChunkReadOperation::{}() Failed to margo_bulk_transfer with margo err: '{}'", + __func__, margo_err); io_err = EBUSY; continue; } @@ -388,7 +447,7 @@ pair ChunkReadOperation::wait_for_tasks_and_push_back(const bulk_ar ABT_eventual_free(&task_eventuals_[idx]); } // in case of error set read size to zero as data would be corrupted - if (io_err != 0) + if(io_err != 0) total_read = 0; return make_pair(io_err, total_read); } diff --git a/src/daemon/ops/metadentry.cpp b/src/daemon/ops/metadentry.cpp index d241b03bd..8be7db90d 100644 --- a/src/daemon/ops/metadentry.cpp +++ b/src/daemon/ops/metadentry.cpp @@ -22,12 +22,14 @@ namespace gkfs { namespace metadata { /** - * Returns the metadata of an object at a specific path. The metadata can be of dummy values if configured + * Returns the metadata of an object at a specific path. The metadata can be of + * dummy values if configured * @param path * @param attr * @return */ -Metadata get(const std::string& path) { +Metadata +get(const std::string& path) { return Metadata(get_str(path)); } @@ -36,7 +38,8 @@ Metadata get(const std::string& path) { * @param path * @return */ -std::string get_str(const std::string& path) { +std::string +get_str(const std::string& path) { return GKFS_DATA->mdb()->get(path); } @@ -46,7 +49,8 @@ std::string get_str(const std::string& path) { * @param ret_size (return val) * @return err */ -size_t get_size(const string& path) { +size_t +get_size(const string& path) { return get(path).size(); } @@ -55,7 +59,8 @@ size_t get_size(const string& path) { * @param dir * @return */ -std::vector> get_dirents(const std::string& dir) { +std::vector> +get_dirents(const std::string& dir) { return GKFS_DATA->mdb()->get_dirents(dir); } @@ -64,18 +69,20 @@ std::vector> get_dirents(const std::string& dir) { * @param path * @param mode */ -void create(const std::string& path, Metadata& md) { +void +create(const std::string& path, Metadata& md) { // update metadata object based on what metadata is needed - if (GKFS_DATA->atime_state() || GKFS_DATA->mtime_state() || GKFS_DATA->ctime_state()) { + if(GKFS_DATA->atime_state() || GKFS_DATA->mtime_state() || + GKFS_DATA->ctime_state()) { std::time_t time; std::time(&time); auto time_s = fmt::format_int(time).str(); - if (GKFS_DATA->atime_state()) + if(GKFS_DATA->atime_state()) md.atime(time); - if (GKFS_DATA->mtime_state()) + if(GKFS_DATA->mtime_state()) md.mtime(time); - if (GKFS_DATA->ctime_state()) + if(GKFS_DATA->ctime_state()) md.ctime(time); } GKFS_DATA->mdb()->put(path, md.serialize()); @@ -86,17 +93,20 @@ void create(const std::string& path, Metadata& md) { * @param path * @param md */ -void update(const string& path, Metadata& md) { +void +update(const string& path, Metadata& md) { GKFS_DATA->mdb()->update(path, path, md.serialize()); } /** - * Updates a metadentry's size atomically and returns the corresponding size after update + * Updates a metadentry's size atomically and returns the corresponding size + * after update * @param path * @param io_size * @return the updated size */ -void update_size(const string& path, size_t io_size, off64_t offset, bool append) { +void +update_size(const string& path, size_t io_size, off64_t offset, bool append) { GKFS_DATA->mdb()->increase_size(path, io_size + offset, append); } @@ -106,15 +116,19 @@ void update_size(const string& path, size_t io_size, off64_t offset, bool append * @return * @throws gkfs::metadata::DBException, gkfs::data::ChunkStorageException */ -void remove(const string& path) { +void +remove(const string& path) { /* - * try to remove metadata from kv store but catch NotFoundException which is not an error in this case - * because removes can be broadcast to catch all data chunks but only one node will hold the kv store entry. + * try to remove metadata from kv store but catch NotFoundException which is + * not an error in this case because removes can be broadcast to catch all + * data chunks but only one node will hold the kv store entry. */ try { GKFS_DATA->mdb()->remove(path); // remove metadata from KV store - } catch (const NotFoundException& e) {} - GKFS_DATA->storage()->destroy_chunk_space(path); // destroys all chunks for the path on this node + } catch(const NotFoundException& e) { + } + GKFS_DATA->storage()->destroy_chunk_space( + path); // destroys all chunks for the path on this node } } // namespace metadata diff --git a/src/daemon/scheduler/agios.cpp b/src/daemon/scheduler/agios.cpp index 818a3fd71..037f1fb97 100644 --- a/src/daemon/scheduler/agios.cpp +++ b/src/daemon/scheduler/agios.cpp @@ -1,6 +1,7 @@ #include -unsigned long long int generate_unique_id() { +unsigned long long int +generate_unique_id() { // Calculates the hash of this request timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); diff --git a/src/daemon/util.cpp b/src/daemon/util.cpp index 8202cde1d..2f3edd919 100644 --- a/src/daemon/util.cpp +++ b/src/daemon/util.cpp @@ -23,23 +23,29 @@ using namespace std; namespace gkfs { namespace util { -void populate_hosts_file() { +void +populate_hosts_file() { const auto& hosts_file = GKFS_DATA->hosts_file(); - GKFS_DATA->spdlogger()->debug("{}() Populating hosts file: '{}'", __func__, hosts_file); + GKFS_DATA->spdlogger()->debug("{}() Populating hosts file: '{}'", __func__, + hosts_file); ofstream lfstream(hosts_file, ios::out | ios::app); - if (!lfstream) { - throw runtime_error( - fmt::format("Failed to open hosts file '{}': {}", hosts_file, strerror(errno))); + if(!lfstream) { + throw runtime_error(fmt::format("Failed to open hosts file '{}': {}", + hosts_file, strerror(errno))); } - lfstream << fmt::format("{} {}", gkfs::rpc::get_my_hostname(true), RPC_DATA->self_addr_str()) << std::endl; - if (!lfstream) { + lfstream << fmt::format("{} {}", gkfs::rpc::get_my_hostname(true), + RPC_DATA->self_addr_str()) + << std::endl; + if(!lfstream) { throw runtime_error( - fmt::format("Failed to write on hosts file '{}': {}", hosts_file, strerror(errno))); + fmt::format("Failed to write on hosts file '{}': {}", + hosts_file, strerror(errno))); } lfstream.close(); } -void destroy_hosts_file() { +void +destroy_hosts_file() { std::remove(GKFS_DATA->hosts_file().c_str()); } diff --git a/src/global/env_util.cpp b/src/global/env_util.cpp index 258b7d52e..731afe2af 100644 --- a/src/global/env_util.cpp +++ b/src/global/env_util.cpp @@ -18,7 +18,8 @@ using namespace std; -string gkfs::env::get_var(const string& name, const string& default_value) { +string +gkfs::env::get_var(const string& name, const string& default_value) { const char* const val = ::secure_getenv(name.c_str()); return val != nullptr ? string(val) : default_value; } diff --git a/src/global/log_util.cpp b/src/global/log_util.cpp index 256f2bca2..76dd4564a 100644 --- a/src/global/log_util.cpp +++ b/src/global/log_util.cpp @@ -20,34 +20,39 @@ using namespace std; -spdlog::level::level_enum gkfs::log::get_level(string level_str) { +spdlog::level::level_enum +gkfs::log::get_level(string level_str) { char* parse_end; auto level = strtoul(level_str.c_str(), &parse_end, 10); - if (parse_end != (level_str.c_str() + level_str.size())) { + if(parse_end != (level_str.c_str() + level_str.size())) { // no conversion could be performed. Must be a string then - ::transform(level_str.begin(), level_str.end(), level_str.begin(), ::tolower); - if (level_str == "off"s) + ::transform(level_str.begin(), level_str.end(), level_str.begin(), + ::tolower); + if(level_str == "off"s) return spdlog::level::off; - else if (level_str == "critical"s) + else if(level_str == "critical"s) return spdlog::level::critical; - else if (level_str == "err"s) + else if(level_str == "err"s) return spdlog::level::err; - else if (level_str == "warn"s) + else if(level_str == "warn"s) return spdlog::level::warn; - else if (level_str == "info"s) + else if(level_str == "info"s) return spdlog::level::info; - else if (level_str == "debug"s) + else if(level_str == "debug"s) return spdlog::level::debug; - else if (level_str == "trace"s) + else if(level_str == "trace"s) return spdlog::level::trace; else - throw runtime_error(fmt::format("Error: log level '{}' is invalid. Check help/readme.", level_str)); + throw runtime_error(fmt::format( + "Error: log level '{}' is invalid. Check help/readme.", + level_str)); } else return get_level(level); } -spdlog::level::level_enum gkfs::log::get_level(unsigned long level) { - switch (level) { +spdlog::level::level_enum +gkfs::log::get_level(unsigned long level) { + switch(level) { case 0: return spdlog::level::off; case 1: @@ -65,22 +70,23 @@ spdlog::level::level_enum gkfs::log::get_level(unsigned long level) { } } -void gkfs::log::setup(const vector& loggers_name, - spdlog::level::level_enum level, const string& path) { +void +gkfs::log::setup(const vector& loggers_name, + spdlog::level::level_enum level, const string& path) { /* Create common sink */ auto file_sink = make_shared(path); /* Create and configure loggers */ auto loggers = list>(); - for (const auto& name: loggers_name) { + for(const auto& name : loggers_name) { auto logger = make_shared(name, file_sink); logger->flush_on(spdlog::level::trace); loggers.push_back(logger); } /* register loggers */ - for (const auto& logger: loggers) { + for(const auto& logger : loggers) { spdlog::register_logger(logger); } diff --git a/src/global/metadata.cpp b/src/global/metadata.cpp index a85c1647d..83808eeda 100644 --- a/src/global/metadata.cpp +++ b/src/global/metadata.cpp @@ -29,28 +29,17 @@ namespace metadata { static const char MSP = '|'; // metadata separator -Metadata::Metadata(const mode_t mode) : - atime_(), - mtime_(), - ctime_(), - mode_(mode), - link_count_(0), - size_(0), - blocks_(0) { +Metadata::Metadata(const mode_t mode) + : atime_(), mtime_(), ctime_(), mode_(mode), link_count_(0), size_(0), + blocks_(0) { assert(S_ISDIR(mode_) || S_ISREG(mode_)); } #ifdef HAS_SYMLINKS -Metadata::Metadata(const mode_t mode, const std::string& target_path) : - atime_(), - mtime_(), - ctime_(), - mode_(mode), - link_count_(0), - size_(0), - blocks_(0), - target_path_(target_path) { +Metadata::Metadata(const mode_t mode, const std::string& target_path) + : atime_(), mtime_(), ctime_(), mode_(mode), link_count_(0), size_(0), + blocks_(0), target_path_(target_path) { assert(S_ISLNK(mode_) || S_ISDIR(mode_) || S_ISREG(mode_)); // target_path should be there only if this is a link assert(target_path_.empty() || S_ISLNK(mode_)); @@ -78,31 +67,32 @@ Metadata::Metadata(const std::string& binary_str) { ptr += read; // The order is important. don't change. - if (gkfs::config::metadata::use_atime) { + if(gkfs::config::metadata::use_atime) { assert(*ptr == MSP); atime_ = static_cast(std::stol(++ptr, &read)); assert(read > 0); ptr += read; } - if (gkfs::config::metadata::use_mtime) { + if(gkfs::config::metadata::use_mtime) { assert(*ptr == MSP); mtime_ = static_cast(std::stol(++ptr, &read)); assert(read > 0); ptr += read; } - if (gkfs::config::metadata::use_ctime) { + if(gkfs::config::metadata::use_ctime) { assert(*ptr == MSP); ctime_ = static_cast(std::stol(++ptr, &read)); assert(read > 0); ptr += read; } - if (gkfs::config::metadata::use_link_cnt) { + if(gkfs::config::metadata::use_link_cnt) { assert(*ptr == MSP); link_count_ = static_cast(std::stoul(++ptr, &read)); assert(read > 0); ptr += read; } - if (gkfs::config::metadata::use_blocks) { // last one will not encounter a delimiter anymore + if(gkfs::config::metadata::use_blocks) { // last one will not encounter a + // delimiter anymore assert(*ptr == MSP); blocks_ = static_cast(std::stoul(++ptr, &read)); assert(read > 0); @@ -122,29 +112,30 @@ Metadata::Metadata(const std::string& binary_str) { assert(*ptr == '\0'); } -std::string Metadata::serialize() const { +std::string +Metadata::serialize() const { std::string s; // The order is important. don't change. s += fmt::format_int(mode_).c_str(); // add mandatory mode s += MSP; s += fmt::format_int(size_).c_str(); // add mandatory size - if (gkfs::config::metadata::use_atime) { + if(gkfs::config::metadata::use_atime) { s += MSP; s += fmt::format_int(atime_).c_str(); } - if (gkfs::config::metadata::use_mtime) { + if(gkfs::config::metadata::use_mtime) { s += MSP; s += fmt::format_int(mtime_).c_str(); } - if (gkfs::config::metadata::use_ctime) { + if(gkfs::config::metadata::use_ctime) { s += MSP; s += fmt::format_int(ctime_).c_str(); } - if (gkfs::config::metadata::use_link_cnt) { + if(gkfs::config::metadata::use_link_cnt) { s += MSP; s += fmt::format_int(link_count_).c_str(); } - if (gkfs::config::metadata::use_blocks) { + if(gkfs::config::metadata::use_blocks) { s += MSP; s += fmt::format_int(blocks_).c_str(); } @@ -157,7 +148,8 @@ std::string Metadata::serialize() const { return s; } -void Metadata::init_ACM_time() { +void +Metadata::init_ACM_time() { std::time_t time; std::time(&time); atime_ = time; @@ -165,83 +157,100 @@ void Metadata::init_ACM_time() { ctime_ = time; } -void Metadata::update_ACM_time(bool a, bool c, bool m) { +void +Metadata::update_ACM_time(bool a, bool c, bool m) { std::time_t time; std::time(&time); - if (a) + if(a) atime_ = time; - if (c) + if(c) ctime_ = time; - if (m) + if(m) mtime_ = time; } //-------------------------------------------- GETTER/SETTER -time_t Metadata::atime() const { +time_t +Metadata::atime() const { return atime_; } -void Metadata::atime(time_t atime) { +void +Metadata::atime(time_t atime) { Metadata::atime_ = atime; } -time_t Metadata::mtime() const { +time_t +Metadata::mtime() const { return mtime_; } -void Metadata::mtime(time_t mtime) { +void +Metadata::mtime(time_t mtime) { Metadata::mtime_ = mtime; } -time_t Metadata::ctime() const { +time_t +Metadata::ctime() const { return ctime_; } -void Metadata::ctime(time_t ctime) { +void +Metadata::ctime(time_t ctime) { Metadata::ctime_ = ctime; } -mode_t Metadata::mode() const { +mode_t +Metadata::mode() const { return mode_; } -void Metadata::mode(mode_t mode) { +void +Metadata::mode(mode_t mode) { Metadata::mode_ = mode; } -nlink_t Metadata::link_count() const { +nlink_t +Metadata::link_count() const { return link_count_; } -void Metadata::link_count(nlink_t link_count) { +void +Metadata::link_count(nlink_t link_count) { Metadata::link_count_ = link_count; } -size_t Metadata::size() const { +size_t +Metadata::size() const { return size_; } -void Metadata::size(size_t size) { +void +Metadata::size(size_t size) { Metadata::size_ = size; } -blkcnt_t Metadata::blocks() const { +blkcnt_t +Metadata::blocks() const { return blocks_; } -void Metadata::blocks(blkcnt_t blocks) { +void +Metadata::blocks(blkcnt_t blocks) { Metadata::blocks_ = blocks; } #ifdef HAS_SYMLINKS -std::string Metadata::target_path() const { +std::string +Metadata::target_path() const { assert(!target_path_.empty()); return target_path_; } -void Metadata::target_path(const std::string& target_path) { +void +Metadata::target_path(const std::string& target_path) { // target_path should be there only if this is a link assert(target_path.empty() || S_ISLNK(mode_)); // target_path should be absolute @@ -249,7 +258,8 @@ void Metadata::target_path(const std::string& target_path) { target_path_ = target_path; } -bool Metadata::is_link() const { +bool +Metadata::is_link() const { return S_ISLNK(mode_); } diff --git a/src/global/path_util.cpp b/src/global/path_util.cpp index 671556702..78529363d 100644 --- a/src/global/path_util.cpp +++ b/src/global/path_util.cpp @@ -22,17 +22,18 @@ using namespace std; namespace gkfs { namespace path { -bool is_relative(const string& path) { - return (!path.empty()) && - (path.front() != separator); +bool +is_relative(const string& path) { + return (!path.empty()) && (path.front() != separator); } -bool is_absolute(const string& path) { - return (!path.empty()) && - (path.front() == separator); +bool +is_absolute(const string& path) { + return (!path.empty()) && (path.front() == separator); } -bool has_trailing_slash(const string& path) { +bool +has_trailing_slash(const string& path) { return (!path.empty()) && (path.back() == separator); } @@ -55,7 +56,8 @@ bool has_trailing_slash(const string& path) { * prepend_path("/tmp/prefix", "./my/path") == "/tmp/prefix/./my/path" * ``` */ -string prepend_path(const string& prefix_path, const char* raw_path) { +string +prepend_path(const string& prefix_path, const char* raw_path) { assert(!has_trailing_slash(prefix_path)); ::size_t raw_len = ::strlen(raw_path); string res; @@ -73,15 +75,16 @@ string prepend_path(const string& prefix_path, const char* raw_path) { * Example: * split_path("/first/second/third") == ["first", "second", "third"] */ -::vector split_path(const string& path) { +::vector +split_path(const string& path) { ::vector tokens; size_t start = string::npos; size_t end = (path.front() != separator) ? 0 : 1; - while (end != string::npos && end < path.size()) { + while(end != string::npos && end < path.size()) { start = end; end = path.find(separator, start); tokens.push_back(path.substr(start, end - start)); - if (end != string::npos) { + if(end != string::npos) { ++end; } } @@ -91,37 +94,43 @@ string prepend_path(const string& prefix_path, const char* raw_path) { /** Make an absolute path relative to a root path * - * Convert @absolute_path into a relative one with respect to the given @root_path. - * If @absolute_path do not start at the given @root_path an empty string will be returned. - * NOTE: Trailing slash will be stripped from the new constructed relative path. + * Convert @absolute_path into a relative one with respect to the given + * @root_path. If @absolute_path do not start at the given @root_path an empty + * string will be returned. NOTE: Trailing slash will be stripped from the new + * constructed relative path. */ -string absolute_to_relative(const string& root_path, const string& absolute_path) { +string +absolute_to_relative(const string& root_path, const string& absolute_path) { assert(is_absolute(root_path)); assert(is_absolute(absolute_path)); assert(!has_trailing_slash(root_path)); - auto diff_its = ::mismatch(absolute_path.cbegin(), absolute_path.cend(), root_path.cbegin()); - if (diff_its.second != root_path.cend()) { + auto diff_its = ::mismatch(absolute_path.cbegin(), absolute_path.cend(), + root_path.cbegin()); + if(diff_its.second != root_path.cend()) { // complete path doesn't start with root_path return {}; } - // iterator to the starting char of the relative portion of the @absolute_path + // iterator to the starting char of the relative portion of the + // @absolute_path auto rel_it_begin = diff_its.first; // iterator to the end of the relative portion of the @absolute_path auto rel_it_end = absolute_path.cend(); // relative path start exactly after the root_path prefix - assert((size_t) (rel_it_begin - absolute_path.cbegin()) == root_path.size()); + assert((size_t)(rel_it_begin - absolute_path.cbegin()) == root_path.size()); - if (rel_it_begin == rel_it_end) { - //relative path is empty, @absolute_path was equal to @root_path + if(rel_it_begin == rel_it_end) { + // relative path is empty, @absolute_path was equal to @root_path return {'/'}; } // remove the trailing slash from relative path - if (has_trailing_slash(absolute_path) && - rel_it_begin != rel_it_end - 1) { // the relative path is longer then 1 char ('/') + if(has_trailing_slash(absolute_path) && + rel_it_begin != + rel_it_end - + 1) { // the relative path is longer then 1 char ('/') --rel_it_end; } @@ -130,21 +139,22 @@ string absolute_to_relative(const string& root_path, const string& absolute_path /** * returns the directory name for given path - * @param path - * @return + * @param path + * @return */ -string dirname(const string& path) { +string +dirname(const string& path) { assert(path.size() > 1 || path.front() == separator); assert(path.size() == 1 || !has_trailing_slash(path)); auto parent_path_size = path.find_last_of(separator); assert(parent_path_size != string::npos); - if (parent_path_size == 0) { + if(parent_path_size == 0) { // parent is '/' parent_path_size = 1; } return path.substr(0, parent_path_size); } -} // namespace +} // namespace path } // namespace gkfs \ No newline at end of file diff --git a/src/global/rpc/distributor.cpp b/src/global/rpc/distributor.cpp index e69f1fb71..27772cfc0 100644 --- a/src/global/rpc/distributor.cpp +++ b/src/global/rpc/distributor.cpp @@ -18,81 +18,81 @@ using namespace std; namespace gkfs { namespace rpc { -SimpleHashDistributor:: -SimpleHashDistributor(host_t localhost, unsigned int hosts_size) : - localhost_(localhost), - hosts_size_(hosts_size), - all_hosts_(hosts_size) { +SimpleHashDistributor::SimpleHashDistributor(host_t localhost, + unsigned int hosts_size) + : localhost_(localhost), hosts_size_(hosts_size), all_hosts_(hosts_size) { ::iota(all_hosts_.begin(), all_hosts_.end(), 0); } -host_t SimpleHashDistributor:: -localhost() const { +host_t +SimpleHashDistributor::localhost() const { return localhost_; } -host_t SimpleHashDistributor:: -locate_data(const string& path, const chunkid_t& chnk_id) const { +host_t +SimpleHashDistributor::locate_data(const string& path, + const chunkid_t& chnk_id) const { return str_hash(path + ::to_string(chnk_id)) % hosts_size_; } -host_t SimpleHashDistributor:: -locate_file_metadata(const string& path) const { +host_t +SimpleHashDistributor::locate_file_metadata(const string& path) const { return str_hash(path) % hosts_size_; } -::vector SimpleHashDistributor:: -locate_directory_metadata(const string& path) const { +::vector +SimpleHashDistributor::locate_directory_metadata(const string& path) const { return all_hosts_; } -LocalOnlyDistributor::LocalOnlyDistributor(host_t localhost) : localhost_(localhost) {} +LocalOnlyDistributor::LocalOnlyDistributor(host_t localhost) + : localhost_(localhost) {} -host_t LocalOnlyDistributor:: -localhost() const { +host_t +LocalOnlyDistributor::localhost() const { return localhost_; } -host_t LocalOnlyDistributor:: -locate_data(const string& path, const chunkid_t& chnk_id) const { +host_t +LocalOnlyDistributor::locate_data(const string& path, + const chunkid_t& chnk_id) const { return localhost_; } -host_t LocalOnlyDistributor:: -locate_file_metadata(const string& path) const { +host_t +LocalOnlyDistributor::locate_file_metadata(const string& path) const { return localhost_; } -::vector LocalOnlyDistributor:: -locate_directory_metadata(const string& path) const { +::vector +LocalOnlyDistributor::locate_directory_metadata(const string& path) const { return {localhost_}; } -ForwarderDistributor:: -ForwarderDistributor(host_t fwhost, unsigned int hosts_size) : - fwd_host_(fwhost), - hosts_size_(hosts_size), - all_hosts_(hosts_size) { +ForwarderDistributor::ForwarderDistributor(host_t fwhost, + unsigned int hosts_size) + : fwd_host_(fwhost), hosts_size_(hosts_size), all_hosts_(hosts_size) { ::iota(all_hosts_.begin(), all_hosts_.end(), 0); } -host_t ForwarderDistributor:: -localhost() const { +host_t +ForwarderDistributor::localhost() const { return fwd_host_; } -host_t ForwarderDistributor:: -locate_data(const std::string& path, const chunkid_t& chnk_id) const { +host_t +ForwarderDistributor::locate_data(const std::string& path, + const chunkid_t& chnk_id) const { return fwd_host_; } -host_t ForwarderDistributor:: -locate_file_metadata(const std::string& path) const { +host_t +ForwarderDistributor::locate_file_metadata(const std::string& path) const { return str_hash(path) % hosts_size_; } -std::vector ForwarderDistributor:: -locate_directory_metadata(const std::string& path) const { +std::vector +ForwarderDistributor::locate_directory_metadata(const std::string& path) const { return all_hosts_; } } // namespace rpc diff --git a/src/global/rpc/rpc_util.cpp b/src/global/rpc/rpc_util.cpp index e5607fd33..68353c47d 100644 --- a/src/global/rpc/rpc_util.cpp +++ b/src/global/rpc/rpc_util.cpp @@ -32,8 +32,10 @@ namespace rpc { * @param state * @return */ -hg_bool_t bool_to_merc_bool(const bool state) { - return state ? static_cast(HG_TRUE) : static_cast(HG_FALSE); +hg_bool_t +bool_to_merc_bool(const bool state) { + return state ? static_cast(HG_TRUE) + : static_cast(HG_FALSE); } @@ -41,16 +43,17 @@ hg_bool_t bool_to_merc_bool(const bool state) { * Returns the machine's hostname * @return */ -string get_my_hostname(bool short_hostname) { +string +get_my_hostname(bool short_hostname) { char hostname[1024]; auto ret = gethostname(hostname, 1024); - if (ret == 0) { + if(ret == 0) { string hostname_s(hostname); - if (!short_hostname) + if(!short_hostname) return hostname_s; // get short hostname auto pos = hostname_s.find("."s); - if (pos != string::npos) + if(pos != string::npos) hostname_s = hostname_s.substr(0, pos); return hostname_s; } else @@ -58,7 +61,8 @@ string get_my_hostname(bool short_hostname) { } -string get_host_by_name(const string& hostname) { +string +get_host_by_name(const string& hostname) { int err = 0; struct addrinfo hints; memset(&hints, 0, sizeof(struct addrinfo)); @@ -68,26 +72,18 @@ string get_host_by_name(const string& hostname) { struct addrinfo* addr = nullptr; - err = getaddrinfo( - hostname.c_str(), - nullptr, - &hints, - &addr - ); - if (err) { - throw runtime_error("Error getting address info for '" - + hostname + "': " + gai_strerror(err)); + err = getaddrinfo(hostname.c_str(), nullptr, &hints, &addr); + if(err) { + throw runtime_error("Error getting address info for '" + hostname + + "': " + gai_strerror(err)); } char addr_str[INET6_ADDRSTRLEN]; - err = getnameinfo( - addr->ai_addr, addr->ai_addrlen, - addr_str, INET6_ADDRSTRLEN, - nullptr, 0, - (NI_NUMERICHOST | NI_NOFQDN) - ); - if (err) { + err = getnameinfo(addr->ai_addr, addr->ai_addrlen, addr_str, + INET6_ADDRSTRLEN, nullptr, 0, + (NI_NUMERICHOST | NI_NOFQDN)); + if(err) { throw runtime_error("Error on getnameinfo(): "s + gai_strerror(err)); } freeaddrinfo(addr); -- GitLab