Loading include/client/env.hpp +1 −0 Viewed Changes for include/client/env.hpp: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ static constexpr auto METRICS_PATH = ADD_PREFIX("METRICS_PATH"); static constexpr auto METRICS_IP_PORT = ADD_PREFIX("METRICS_IP_PORT"); #endif static constexpr auto PROTECT_FD = ADD_PREFIX("PROTECT_FD"); static constexpr auto NUM_REPL = ADD_PREFIX("NUM_REPL"); static constexpr auto PROXY_PID_FILE = ADD_PREFIX("PROXY_PID_FILE"); namespace cache { Loading include/client/preload_context.hpp +7 −0 Viewed Changes for include/client/preload_context.hpp: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ private: std::bitset<MAX_USER_FDS> protected_fds_; std::string hostname; int replicas_; bool protect_fds_{false}; std::shared_ptr<gkfs::messagepack::ClientMetrics> write_metrics_; std::shared_ptr<gkfs::messagepack::ClientMetrics> read_metrics_; Loading Loading @@ -314,6 +315,12 @@ public: int get_replicas(); bool protect_fds() const; void protect_fds(bool protect); const std::shared_ptr<gkfs::messagepack::ClientMetrics> write_metrics(); Loading src/client/open_file_map.cpp +20 −9 Viewed Changes for src/client/open_file_map.cpp: 20 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -142,23 +142,30 @@ OpenFileMap::exist(const int fd) { int OpenFileMap::safe_generate_fd_idx_() { auto fd = generate_fd_idx(); int fd = 0; if(CTX->protect_fds()) { 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)) { fd = generate_fd_idx(); } } } else { // Some architectures do not support SYS_open fd = syscall_no_intercept(SYS_openat, AT_FDCWD, "/dev/null", O_RDWR, S_IRUSR | S_IWUSR); } return fd; } Loading @@ -178,6 +185,10 @@ OpenFileMap::remove(const int fd) { return false; } files_.erase(fd); if(!CTX->protect_fds()) { // We close the dev null fd close(fd); } if(fd_validation_needed && files_.empty()) { fd_validation_needed = false; LOG(DEBUG, "fd_validation flag reset"); Loading Loading @@ -237,7 +248,7 @@ OpenFileMap::generate_fd_idx() { * which tells can tell the OpenFileMap that it should check if this fd * is really safe to use. */ fd_idx = 100000; fd_idx = 10000; fd_validation_needed = true; } return fd_idx++; Loading src/client/preload.cpp +15 −3 Viewed Changes for src/client/preload.cpp: 15 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -359,13 +359,14 @@ init_preload() { // The original errno value will be restored after initialization to not // leak internal error codes auto oerrno = errno; CTX->enable_interception(); gkfs::preload::start_self_interception(); if(!init) { init = true; pthread_atfork(&at_fork_syscall, &at_parent_syscall, &at_child_syscall); } CTX->enable_interception(); gkfs::preload::start_self_interception(); CTX->init_logging(); // from here ownwards it is safe to print messages LOG(DEBUG, "Logging subsystem initialized"); Loading @@ -380,7 +381,17 @@ init_preload() { // 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. if(gkfs::env::var_is_set(gkfs::env::PROTECT_FD)) { CTX->protect_fds(true); LOG(INFO, "Protecting user fds"); } else { CTX->protect_fds(false); LOG(INFO, "Not protecting user fds"); } if(CTX->protect_fds()) { CTX->protect_user_fds(); } log_prog_name(); gkfs::path::init_cwd(); Loading @@ -390,6 +401,7 @@ init_preload() { gkfs::preload::init_environment(); CTX->enable_interception(); if(CTX->protect_fds()) CTX->unprotect_user_fds(); auto forwarding_map_file = gkfs::env::get_var( Loading src/client/preload_context.cpp +13 −1 Viewed Changes for src/client/preload_context.cpp: 13 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -487,11 +487,21 @@ PreloadContext::interception_enabled() const { return interception_enabled_; } bool PreloadContext::protect_fds() const { return protect_fds_; } void PreloadContext::protect_fds(bool protect) { protect_fds_ = protect; } int PreloadContext::register_internal_fd(int fd) { assert(fd >= 0); if(!protect_fds()) return fd; if(!internal_fds_must_relocate_) { LOG(DEBUG, "registering fd {} as internal (no relocation needed)", fd); assert(fd >= MIN_INTERNAL_FD); Loading Loading @@ -559,6 +569,8 @@ PreloadContext::register_internal_fd(int fd) { void PreloadContext::unregister_internal_fd(int fd) { if(!protect_fds()) return; LOG(DEBUG, "unregistering internal fd {} >= {} -> {}'", fd, MIN_INTERNAL_FD, fd >= MIN_INTERNAL_FD); Loading Loading
include/client/env.hpp +1 −0 Viewed Changes for include/client/env.hpp: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ static constexpr auto METRICS_PATH = ADD_PREFIX("METRICS_PATH"); static constexpr auto METRICS_IP_PORT = ADD_PREFIX("METRICS_IP_PORT"); #endif static constexpr auto PROTECT_FD = ADD_PREFIX("PROTECT_FD"); static constexpr auto NUM_REPL = ADD_PREFIX("NUM_REPL"); static constexpr auto PROXY_PID_FILE = ADD_PREFIX("PROXY_PID_FILE"); namespace cache { Loading
include/client/preload_context.hpp +7 −0 Viewed Changes for include/client/preload_context.hpp: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -138,6 +138,7 @@ private: std::bitset<MAX_USER_FDS> protected_fds_; std::string hostname; int replicas_; bool protect_fds_{false}; std::shared_ptr<gkfs::messagepack::ClientMetrics> write_metrics_; std::shared_ptr<gkfs::messagepack::ClientMetrics> read_metrics_; Loading Loading @@ -314,6 +315,12 @@ public: int get_replicas(); bool protect_fds() const; void protect_fds(bool protect); const std::shared_ptr<gkfs::messagepack::ClientMetrics> write_metrics(); Loading
src/client/open_file_map.cpp +20 −9 Viewed Changes for src/client/open_file_map.cpp: 20 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -142,23 +142,30 @@ OpenFileMap::exist(const int fd) { int OpenFileMap::safe_generate_fd_idx_() { auto fd = generate_fd_idx(); int fd = 0; if(CTX->protect_fds()) { 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)) { fd = generate_fd_idx(); } } } else { // Some architectures do not support SYS_open fd = syscall_no_intercept(SYS_openat, AT_FDCWD, "/dev/null", O_RDWR, S_IRUSR | S_IWUSR); } return fd; } Loading @@ -178,6 +185,10 @@ OpenFileMap::remove(const int fd) { return false; } files_.erase(fd); if(!CTX->protect_fds()) { // We close the dev null fd close(fd); } if(fd_validation_needed && files_.empty()) { fd_validation_needed = false; LOG(DEBUG, "fd_validation flag reset"); Loading Loading @@ -237,7 +248,7 @@ OpenFileMap::generate_fd_idx() { * which tells can tell the OpenFileMap that it should check if this fd * is really safe to use. */ fd_idx = 100000; fd_idx = 10000; fd_validation_needed = true; } return fd_idx++; Loading
src/client/preload.cpp +15 −3 Viewed Changes for src/client/preload.cpp: 15 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -359,13 +359,14 @@ init_preload() { // The original errno value will be restored after initialization to not // leak internal error codes auto oerrno = errno; CTX->enable_interception(); gkfs::preload::start_self_interception(); if(!init) { init = true; pthread_atfork(&at_fork_syscall, &at_parent_syscall, &at_child_syscall); } CTX->enable_interception(); gkfs::preload::start_self_interception(); CTX->init_logging(); // from here ownwards it is safe to print messages LOG(DEBUG, "Logging subsystem initialized"); Loading @@ -380,7 +381,17 @@ init_preload() { // 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. if(gkfs::env::var_is_set(gkfs::env::PROTECT_FD)) { CTX->protect_fds(true); LOG(INFO, "Protecting user fds"); } else { CTX->protect_fds(false); LOG(INFO, "Not protecting user fds"); } if(CTX->protect_fds()) { CTX->protect_user_fds(); } log_prog_name(); gkfs::path::init_cwd(); Loading @@ -390,6 +401,7 @@ init_preload() { gkfs::preload::init_environment(); CTX->enable_interception(); if(CTX->protect_fds()) CTX->unprotect_user_fds(); auto forwarding_map_file = gkfs::env::get_var( Loading
src/client/preload_context.cpp +13 −1 Viewed Changes for src/client/preload_context.cpp: 13 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -487,11 +487,21 @@ PreloadContext::interception_enabled() const { return interception_enabled_; } bool PreloadContext::protect_fds() const { return protect_fds_; } void PreloadContext::protect_fds(bool protect) { protect_fds_ = protect; } int PreloadContext::register_internal_fd(int fd) { assert(fd >= 0); if(!protect_fds()) return fd; if(!internal_fds_must_relocate_) { LOG(DEBUG, "registering fd {} as internal (no relocation needed)", fd); assert(fd >= MIN_INTERNAL_FD); Loading Loading @@ -559,6 +569,8 @@ PreloadContext::register_internal_fd(int fd) { void PreloadContext::unregister_internal_fd(int fd) { if(!protect_fds()) return; LOG(DEBUG, "unregistering internal fd {} >= {} -> {}'", fd, MIN_INTERNAL_FD, fd >= MIN_INTERNAL_FD); Loading