From add21a5608425956d2023885cc1809ca20f99363 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 22 Apr 2025 10:31:03 -0500 Subject: [PATCH] refactor --- .../drives/remote/remote_server_base.hpp | 311 +++++++++--------- .../librepertory/include/types/remote.hpp | 5 +- .../drives/fuse/remotefuse/remote_server.cpp | 13 +- .../winfsp/remotewinfsp/remote_server.cpp | 13 +- 4 files changed, 172 insertions(+), 170 deletions(-) diff --git a/repertory/librepertory/include/drives/remote/remote_server_base.hpp b/repertory/librepertory/include/drives/remote/remote_server_base.hpp index 16a2b218..22918309 100644 --- a/repertory/librepertory/include/drives/remote/remote_server_base.hpp +++ b/repertory/librepertory/include/drives/remote/remote_server_base.hpp @@ -39,8 +39,6 @@ #include "utils/base64.hpp" #include "utils/path.hpp" -#define REPERTORY_DIRECTORY_PAGE_SIZE std::size_t(100U) - namespace repertory { template class remote_server_base : public remote_open_file_table, @@ -153,30 +151,6 @@ private: return this->handle_fuse_destroy(); }, }, - /*handlerLookup_.insert({"::fuse_fallocate", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { - auto ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - std::int32_t mode; - DECODE_OR_RETURN(request, mode); - - remote::file_offset offset; - DECODE_OR_RETURN(request, offset); - - remote::file_offset length; - DECODE_OR_RETURN(request, length); - - remote::file_handle handle; - DECODE_OR_RETURN(request, handle); - - return this->fuse_fallocate(path.c_str(), mode, - offset, length, handle); - }});*/ { "::fuse_fgetattr", [this](auto && /* service_flags */, auto && /* client_id */, @@ -217,45 +191,6 @@ private: return this->handle_fuse_getattr(request, response); }, }, - /*handlerLookup_.insert({"::fuse_getxattr", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { auto - ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - std::string name; - DECODE_OR_RETURN(request, name); - - remote::file_size size; - DECODE_OR_RETURN(request, size); - - return this->fuse_getxattr(path.c_str(), - &name[0], nullptr, size); - }}); - handlerLookup_.insert({"::fuse_getxattr_osx", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { auto - ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - std::string name; - DECODE_OR_RETURN(request, name); - - remote::file_size size; - DECODE_OR_RETURN(request, size); - - std::uint32_t position; - DECODE_OR_RETURN(request, position); - - return this->fuse_getxattr_osx(path.c_str(), - &name[0], nullptr, size, position); - }});*/ { "::fuse_getxtimes", [this](auto && /* service_flags */, auto && /* client_id */, @@ -272,21 +207,6 @@ private: return this->handle_fuse_init(); }, }, - /*handlerLookup_.insert({"::remote_fuseListxattr", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { - auto ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - remote::file_size size; - DECODE_OR_RETURN(request, size); - - return this->fuse_listxattr(path.c_str(), - nullptr, size); - }});*/ { "::fuse_mkdir", [this](auto && /* service_flags */, auto && /* client_id */, @@ -343,21 +263,6 @@ private: return this->handle_fuse_releasedir(client_id, request); }, }, - /*handlerLookup_.insert({"::fuse_removexattr", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { - auto ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - std::string name; - DECODE_OR_RETURN(request, name); - - return this->fuse_removexattr(path.c_str(), - &name[0]); - }});*/ { "::fuse_rename", [this](auto && /* service_flags */, auto && /* client_id */, @@ -414,67 +319,6 @@ private: return this->handle_fuse_setvolname(request); }, }, - /*handlerLookup_.insert({"::fuse_setxattr", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { auto - ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - std::string name; - DECODE_OR_RETURN(request, name); - - remote::file_size size; - DECODE_OR_RETURN(request, size); - - if (size > - std::numeric_limits::max()) { return -ERANGE; - } - - data_buffer - value(static_cast(size)); ret = request->Decode(&value[0], - value.size()); if (ret == 0) { std::int32_t flags; - DECODE_OR_RETURN(request, flags); - - ret = this->fuse_setxattr(path.c_str(), - &name[0], &value[0], size, flags); - } - return ret; - }}); - handlerLookup_.insert({"::fuse_setxattr_osx", - [this](std::uint32_t serviceFlags, const - std::string &client_id, std::uint64_t threadId, const std::string - &method, packet *request, packet &response) -> packet::error_type { auto - ret{0}; - - std::string path; - DECODE_OR_RETURN(request, path); - - std::string name; - DECODE_OR_RETURN(request, name); - - remote::file_size size; - DECODE_OR_RETURN(request, size); - - if (size > - std::numeric_limits::max()) { return -ERANGE; - } - - data_buffer - value(static_cast(size)); ret = request->Decode(&value[0], - value.size()); if (ret == 0) { std::int32_t flags; - DECODE_OR_RETURN(request, flags); - - std::uint32_t position; - DECODE_OR_RETURN(request, position); - - ret = this->fuse_setxattr_osx(path.c_str(), - &name[0], &value[0], size, flags, position); - } - return ret; - }});*/ { "::fuse_statfs", [this](auto && /* service_flags */, auto && /* client_id */, @@ -1792,3 +1636,158 @@ protected: } // namespace repertory #endif // REPERTORY_INCLUDE_DRIVES_REMOTE_REMOTE_SERVER_BASE_HPP_ + +/*handlerLookup_.insert({"::fuse_fallocate", + [this](std::uint32_t serviceFlags, const + std::string &client_id, std::uint64_t threadId, const std::string + &method, packet *request, packet &response) -> packet::error_type { + auto ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + std::int32_t mode; + DECODE_OR_RETURN(request, mode); + + remote::file_offset offset; + DECODE_OR_RETURN(request, offset); + + remote::file_offset length; + DECODE_OR_RETURN(request, length); + + remote::file_handle handle; + DECODE_OR_RETURN(request, handle); + + return this->fuse_fallocate(path.c_str(), mode, + offset, length, handle); + }});*/ +/*handlerLookup_.insert({"::fuse_getxattr", + [this](std::uint32_t serviceFlags, const +std::string &client_id, std::uint64_t threadId, const std::string +&method, packet *request, packet &response) -> packet::error_type { auto +ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + std::string name; + DECODE_OR_RETURN(request, name); + + remote::file_size size; + DECODE_OR_RETURN(request, size); + + return this->fuse_getxattr(path.c_str(), +&name[0], nullptr, size); + }}); +handlerLookup_.insert({"::fuse_getxattr_osx", + [this](std::uint32_t serviceFlags, const +std::string &client_id, std::uint64_t threadId, const std::string +&method, packet *request, packet &response) -> packet::error_type { auto +ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + std::string name; + DECODE_OR_RETURN(request, name); + + remote::file_size size; + DECODE_OR_RETURN(request, size); + + std::uint32_t position; + DECODE_OR_RETURN(request, position); + + return this->fuse_getxattr_osx(path.c_str(), +&name[0], nullptr, size, position); + }});*/ +/*handlerLookup_.insert({"::remote_fuseListxattr", + [this](std::uint32_t serviceFlags, const + std::string &client_id, std::uint64_t threadId, const std::string + &method, packet *request, packet &response) -> packet::error_type { + auto ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + remote::file_size size; + DECODE_OR_RETURN(request, size); + + return this->fuse_listxattr(path.c_str(), + nullptr, size); + }});*/ +/*handlerLookup_.insert({"::fuse_removexattr", + [this](std::uint32_t serviceFlags, const + std::string &client_id, std::uint64_t threadId, const std::string + &method, packet *request, packet &response) -> packet::error_type { + auto ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + std::string name; + DECODE_OR_RETURN(request, name); + + return this->fuse_removexattr(path.c_str(), + &name[0]); + }});*/ +/*handlerLookup_.insert({"::fuse_setxattr", + [this](std::uint32_t serviceFlags, const +std::string &client_id, std::uint64_t threadId, const std::string +&method, packet *request, packet &response) -> packet::error_type { auto +ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + std::string name; + DECODE_OR_RETURN(request, name); + + remote::file_size size; + DECODE_OR_RETURN(request, size); + + if (size > +std::numeric_limits::max()) { return -ERANGE; + } + + data_buffer +value(static_cast(size)); ret = request->Decode(&value[0], +value.size()); if (ret == 0) { std::int32_t flags; + DECODE_OR_RETURN(request, flags); + + ret = this->fuse_setxattr(path.c_str(), +&name[0], &value[0], size, flags); + } + return ret; + }}); +handlerLookup_.insert({"::fuse_setxattr_osx", + [this](std::uint32_t serviceFlags, const +std::string &client_id, std::uint64_t threadId, const std::string +&method, packet *request, packet &response) -> packet::error_type { auto +ret{0}; + + std::string path; + DECODE_OR_RETURN(request, path); + + std::string name; + DECODE_OR_RETURN(request, name); + + remote::file_size size; + DECODE_OR_RETURN(request, size); + + if (size > +std::numeric_limits::max()) { return -ERANGE; + } + + data_buffer +value(static_cast(size)); ret = request->Decode(&value[0], +value.size()); if (ret == 0) { std::int32_t flags; + DECODE_OR_RETURN(request, flags); + + std::uint32_t position; + DECODE_OR_RETURN(request, position); + + ret = this->fuse_setxattr_osx(path.c_str(), +&name[0], &value[0], size, flags, position); + } + return ret; + }});*/ diff --git a/repertory/librepertory/include/types/remote.hpp b/repertory/librepertory/include/types/remote.hpp index b5bdc71c..b362d1d1 100644 --- a/repertory/librepertory/include/types/remote.hpp +++ b/repertory/librepertory/include/types/remote.hpp @@ -33,6 +33,7 @@ inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_WINFSP}; inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE}; #endif // defined(_WIN32) +constexpr const auto default_remote_directory_page_size{std::size_t(100U)}; constexpr const auto default_remote_client_pool_size{20U}; constexpr const auto default_remote_max_connections{20U}; constexpr const auto default_remote_receive_timeout_ms{120U * 1000U}; @@ -217,8 +218,8 @@ struct statfs_x final : public statfs { #if !defined(_WIN32) [[nodiscard]] auto create_open_flags(std::uint32_t flags) -> open_flags; -[[nodiscard]] auto -create_os_open_flags(const open_flags &flags) -> std::uint32_t; +[[nodiscard]] auto create_os_open_flags(const open_flags &flags) + -> std::uint32_t; #endif // !defined(_WIN32) } // namespace repertory::remote diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index f1019b04..1a454647 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -1655,7 +1655,7 @@ auto remote_server::json_create_directory_snapshot(const std::string &path, json_data["handle"] = handle; json_data["path"] = path; json_data["page_count"] = utils::divide_with_ceiling( - iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); + iter->get_count(), default_remote_directory_page_size); res = 0; errno = 0; } @@ -1677,17 +1677,18 @@ auto remote_server::json_read_directory_snapshot( if (iter != nullptr) { std::size_t offset{}; json item_json; - while ( - (json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) && - (res = iter->get_json((page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++, - item_json)) == 0) { + while ((json_data["directory_list"].size() < + default_remote_directory_page_size) && + (res = iter->get_json((page * default_remote_directory_page_size) + + offset++, + item_json)) == 0) { json_data["directory_list"].emplace_back(item_json); } json_data["handle"] = handle; json_data["path"] = path; json_data["page"] = page; json_data["page_count"] = utils::divide_with_ceiling( - iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); + iter->get_count(), default_remote_directory_page_size); } auto ret = ((res < 0) ? -errno : 0); diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index 273506ea..e8c4e097 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -855,7 +855,7 @@ auto remote_server::json_create_directory_snapshot(const std::string &path, json_data["path"] = path; json_data["handle"] = handle; json_data["page_count"] = utils::divide_with_ceiling( - iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); + iter->get_count(), default_remote_directory_page_size); res = 0; errno = 0; } @@ -877,17 +877,18 @@ auto remote_server::json_read_directory_snapshot( if (iter != nullptr) { std::size_t offset{}; json item_json; - while ( - (json_data["directory_list"].size() < REPERTORY_DIRECTORY_PAGE_SIZE) && - (res = iter->get_json((page * REPERTORY_DIRECTORY_PAGE_SIZE) + offset++, - item_json)) == 0) { + while ((json_data["directory_list"].size() < + default_remote_directory_page_size) && + (res = iter->get_json((page * default_remote_directory_page_size) + + offset++, + item_json)) == 0) { json_data["directory_list"].emplace_back(item_json); } json_data["handle"] = handle; json_data["path"] = path; json_data["page"] = page; json_data["page_count"] = utils::divide_with_ceiling( - iter->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE); + iter->get_count(), default_remote_directory_page_size); } auto ret = ((res < 0) ? -errno : 0);