Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ned14/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2022-05-24 23:32:46 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2022-05-24 23:32:46 +0300
commitbe427f440b7bf13c1735d96c6880086eb61a51eb (patch)
tree9a25f3582cb7cd202975e0c7ce7d5e8d38afafd1
parent613d870764cc19e7005a930d8dac689adcbb940b (diff)
traverse: Fix missing += in last commit which was causing a segfault.
-rw-r--r--include/llfio/revision.hpp6
-rw-r--r--include/llfio/v2.0/detail/impl/traverse.ipp44
2 files changed, 35 insertions, 15 deletions
diff --git a/include/llfio/revision.hpp b/include/llfio/revision.hpp
index b4adfee2..d368598d 100644
--- a/include/llfio/revision.hpp
+++ b/include/llfio/revision.hpp
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
-#define LLFIO_PREVIOUS_COMMIT_REF dc6d416b1e4312ba289425bed2940f8c883b707c
-#define LLFIO_PREVIOUS_COMMIT_DATE "2022-05-16 15:44:29 +00:00"
-#define LLFIO_PREVIOUS_COMMIT_UNIQUE dc6d416b
+#define LLFIO_PREVIOUS_COMMIT_REF 613d870764cc19e7005a930d8dac689adcbb940b
+#define LLFIO_PREVIOUS_COMMIT_DATE "2022-05-24 17:41:32 +00:00"
+#define LLFIO_PREVIOUS_COMMIT_UNIQUE 613d8707
diff --git a/include/llfio/v2.0/detail/impl/traverse.ipp b/include/llfio/v2.0/detail/impl/traverse.ipp
index 67922ed5..3aba2f8e 100644
--- a/include/llfio/v2.0/detail/impl/traverse.ipp
+++ b/include/llfio/v2.0/detail/impl/traverse.ipp
@@ -24,9 +24,11 @@ Distributed under the Boost Software License, Version 1.0.
#include "../../algorithm/traverse.hpp"
+#include <atomic>
#include <condition_variable>
#include <iostream>
#include <list>
+#include <memory>
#include <mutex>
#include <thread>
#include <vector>
@@ -60,27 +62,32 @@ namespace algorithm
}
bool use_slow_path = force_slow_path;
#ifndef _WIN32
- if(!use_slow_path)
+ static const size_t rlimit_maxfd = []() -> size_t
{
struct rlimit r;
if(getrlimit(RLIMIT_NOFILE, &r) >= 0)
{
- if(r.rlim_cur - topdirh->native_handle().fd < 65536)
- {
- use_slow_path = true;
+ return size_t(r.rlim_cur);
+ }
+ return 0;
+ }();
+ if(!use_slow_path)
+ {
+ if(rlimit_maxfd > 0 && rlimit_maxfd - topdirh->native_handle().fd < 65536)
+ {
+ use_slow_path = true;
#ifndef NDEBUG
- std::cerr << "WARNING: llfio::traverse() is using slow path due to " << (r.rlim_cur - topdirh->native_handle().fd)
- << " unused file descriptors remaining! Raise the limit using setrlimit(RLIMIT_NOFILE) if your application is > 1024 fd count safe."
- << std::endl;
+ std::cerr << "WARNING: llfio::traverse() is using slow path due to " << (rlimit_maxfd - topdirh->native_handle().fd)
+ << " unused file descriptors remaining! Raise the limit using setrlimit(RLIMIT_NOFILE) if your application is > 1024 fd count safe."
+ << std::endl;
#endif
- }
}
}
#endif
struct state_t
{
- const size_t max_sso_path_size;
std::mutex lock;
+ size_t max_sso_path_size;
traverse_visitor *visitor{nullptr};
#if 0
struct workitem
@@ -116,7 +123,7 @@ namespace algorithm
size_t bytes = (1 + stem.native_size()) * sizeof(filesystem::path::value_type);
if(!leaf.empty())
{
- bytes = (1 + leaf.native_size()) * sizeof(filesystem::path::value_type);
+ bytes += (1 + leaf.native_size()) * sizeof(filesystem::path::value_type);
}
if(bytes <= sizeof(_sso))
{
@@ -138,6 +145,7 @@ namespace algorithm
});
}
_sso[_sso_length] = 0;
+ assert(_sso_length < LLFIO_ALGORITHM_TRAVERSE_MAX_SSO_PATH_SIZE);
}
else
{
@@ -244,6 +252,7 @@ namespace algorithm
}
state->dirs_processed++;
state->known_dirs_remaining--;
+ const auto max_sso_path_size = state->max_sso_path_size;
g.unlock();
std::shared_ptr<directory_handle> mydirh;
if(mywork.leaf().empty())
@@ -373,7 +382,7 @@ namespace algorithm
}
if(2 == entry_type)
{
- if(maxpathsize <= state->max_sso_path_size)
+ if(maxpathsize <= max_sso_path_size)
{
// Reuse existing base directory handle, but with a longer path fragment
// Note that "slow path" is defined as this branch always being taken
@@ -410,6 +419,17 @@ namespace algorithm
}
size_t dirs_processed = state->dirs_processed, known_dirs_remaining = state->known_dirs_remaining, depth_processed = state->depth_processed,
known_depth_remaining = state->workqueue.size();
+#ifndef _WIN32
+ if(max_sso_path_size < size_t(-1) && rlimit_maxfd > 0 && rlimit_maxfd - mydirh->native_handle().fd < 65536)
+ {
+ state->max_sso_path_size = size_t(-1);
+#ifndef NDEBUG
+ std::cerr << "WARNING: llfio::traverse() is falling back to slow path due to " << (rlimit_maxfd - mydirh->native_handle().fd)
+ << " unused file descriptors remaining! Raise the limit using setrlimit(RLIMIT_NOFILE) if your application is > 1024 fd count safe."
+ << std::endl;
+#endif
+ }
+#endif
g.unlock();
OUTCOME_TRY(state->visitor->stack_updated(data, dirs_processed, known_dirs_remaining, depth_processed, known_depth_remaining));
}
@@ -558,7 +578,7 @@ namespace algorithm
return error_from_exception();
}
}());
- }
+ } // namespace algorithm
} // namespace algorithm
LLFIO_V2_NAMESPACE_END