fix directory caching
This commit is contained in:
@ -49,13 +49,13 @@ protected:
|
||||
private:
|
||||
std::unordered_map<remote::file_handle, compat_open_info> compat_lookup_;
|
||||
std::recursive_mutex compat_mutex_;
|
||||
std::unordered_map<std::string, std::vector<void *>> directory_lookup_;
|
||||
std::unordered_map<std::string, std::vector<std::uint64_t>> directory_lookup_;
|
||||
std::recursive_mutex directory_mutex_;
|
||||
std::unordered_map<native_handle, open_info> file_lookup_;
|
||||
mutable std::recursive_mutex file_mutex_;
|
||||
|
||||
protected:
|
||||
void add_directory(const std::string &client_id, void *dir);
|
||||
void add_directory(const std::string &client_id, std::uint64_t handle);
|
||||
|
||||
void close_all(const std::string &client_id);
|
||||
|
||||
@ -71,7 +71,7 @@ protected:
|
||||
open_info &oi) -> bool;
|
||||
|
||||
[[nodiscard]] auto has_open_directory(const std::string &client_id,
|
||||
void *dir) -> bool;
|
||||
std::uint64_t handle) -> bool;
|
||||
|
||||
[[nodiscard]] auto has_compat_open_info(const remote::file_handle &handle,
|
||||
int error_return) -> int;
|
||||
@ -89,7 +89,8 @@ protected:
|
||||
|
||||
void remove_compat_open_info(const remote::file_handle &handle);
|
||||
|
||||
auto remove_directory(const std::string &client_id, void *dir) -> bool;
|
||||
auto remove_directory(const std::string &client_id,
|
||||
std::uint64_t handle) -> bool;
|
||||
|
||||
void remove_open_info(const native_handle &handle);
|
||||
|
||||
|
@ -335,7 +335,7 @@ public:
|
||||
DECODE_OR_RETURN(request, length);
|
||||
|
||||
data_buffer buffer(length);
|
||||
UINT32 bytes_transferred = 0;
|
||||
UINT32 bytes_transferred{0};
|
||||
ret = this->winfsp_read(file_desc, buffer.data(), offset, length,
|
||||
&bytes_transferred);
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
@ -490,7 +490,7 @@ public:
|
||||
|
||||
auto *buffer = request->current_pointer();
|
||||
|
||||
UINT32 bytes_transferred = 0;
|
||||
UINT32 bytes_transferred{0};
|
||||
remote::file_info file_info{};
|
||||
ret = this->winfsp_write(file_desc, buffer, offset, length,
|
||||
write_to_end, constrained_io,
|
||||
@ -506,7 +506,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -521,7 +521,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -536,7 +536,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -551,7 +551,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -569,7 +569,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -601,7 +601,7 @@ public:
|
||||
/*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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -626,7 +626,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -657,7 +657,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -675,7 +675,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -693,7 +693,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -711,7 +711,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -736,7 +736,7 @@ public:
|
||||
/*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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -753,7 +753,7 @@ public:
|
||||
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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -775,7 +775,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -798,7 +798,7 @@ public:
|
||||
/*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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -814,7 +814,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -829,7 +829,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -853,14 +853,14 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
|
||||
remote::file_handle handle = 0;
|
||||
remote::file_handle handle{0};
|
||||
if ((ret = this->fuse_opendir(path.c_str(), handle)) >= 0) {
|
||||
this->add_directory(client_id, reinterpret_cast<void *>(handle));
|
||||
this->add_directory(client_id, handle);
|
||||
response.encode(handle);
|
||||
}
|
||||
return ret;
|
||||
@ -870,7 +870,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -896,7 +896,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -907,8 +907,7 @@ public:
|
||||
remote::file_handle handle;
|
||||
DECODE_OR_RETURN(request, handle);
|
||||
|
||||
if (this->has_open_directory(client_id,
|
||||
reinterpret_cast<void *>(handle))) {
|
||||
if (this->has_open_directory(client_id, handle)) {
|
||||
std::string file_path;
|
||||
ret = this->fuse_readdir(path.c_str(), offset, handle, file_path);
|
||||
if (ret == 0) {
|
||||
@ -925,7 +924,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -940,7 +939,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -949,8 +948,7 @@ public:
|
||||
DECODE_OR_RETURN(request, handle);
|
||||
|
||||
ret = this->fuse_releasedir(path.c_str(), handle);
|
||||
if (this->remove_directory(client_id,
|
||||
reinterpret_cast<void *>(handle))) {
|
||||
if (this->remove_directory(client_id, handle)) {
|
||||
return ret;
|
||||
}
|
||||
return -EBADF;
|
||||
@ -958,7 +956,7 @@ public:
|
||||
/*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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -1071,7 +1069,7 @@ public:
|
||||
/*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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -1100,7 +1098,7 @@ public:
|
||||
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;
|
||||
*request, packet &response) -> packet::error_type { auto ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -1300,8 +1298,7 @@ public:
|
||||
if ((ret = this->json_create_directory_snapshot(path.data(),
|
||||
json_data)) == 0) {
|
||||
this->add_directory(client_id,
|
||||
reinterpret_cast<void *>(
|
||||
json_data["handle"].get<std::uint64_t>()));
|
||||
json_data["handle"].get<std::uint64_t>());
|
||||
response.encode(json_data.dump(0));
|
||||
}
|
||||
return ret;
|
||||
@ -1311,7 +1308,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &response) -> packet::error_type {
|
||||
std::int32_t ret = 0;
|
||||
std::int32_t ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -1323,8 +1320,7 @@ public:
|
||||
DECODE_OR_RETURN(request, page);
|
||||
|
||||
ret = -EBADF;
|
||||
if (this->has_open_directory(client_id,
|
||||
reinterpret_cast<void *>(handle))) {
|
||||
if (this->has_open_directory(client_id, handle)) {
|
||||
json json_data;
|
||||
json_data["directory_list"] = std::vector<json>();
|
||||
json_data["page"] = page;
|
||||
@ -1342,7 +1338,7 @@ public:
|
||||
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
|
||||
const std::string &, packet *request,
|
||||
packet &) -> packet::error_type {
|
||||
auto ret = 0;
|
||||
std::uint32_t ret{0};
|
||||
|
||||
std::string path;
|
||||
DECODE_OR_RETURN(request, path);
|
||||
@ -1351,8 +1347,7 @@ public:
|
||||
DECODE_OR_RETURN(request, handle);
|
||||
|
||||
ret = this->json_release_directory_snapshot(path.data(), handle);
|
||||
if (this->remove_directory(client_id,
|
||||
reinterpret_cast<void *>(handle))) {
|
||||
if (this->remove_directory(client_id, handle)) {
|
||||
return ret;
|
||||
}
|
||||
return -EBADF;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include "comm/packet/packet.hpp"
|
||||
#include "drives/directory_cache.hpp"
|
||||
#include "drives/remote/remote_server_base.hpp"
|
||||
#include "drives/winfsp/i_winfsp_drive.hpp"
|
||||
|
||||
@ -39,9 +40,15 @@ public:
|
||||
: remote_server_base(config, drive,
|
||||
utils::string::to_lower(mount_location)) {}
|
||||
|
||||
private:
|
||||
directory_cache directory_cache_;
|
||||
std::atomic<std::uint64_t> next_handle_{0U};
|
||||
|
||||
private:
|
||||
[[nodiscard]] auto construct_path(std::string path) -> std::string;
|
||||
|
||||
[[nodiscard]] auto get_next_handle() -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto
|
||||
populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info) -> packet::error_type;
|
||||
|
Reference in New Issue
Block a user