fix mount state
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
ed59cbb91e
commit
c9904603df
@ -30,16 +30,20 @@ class i_provider;
|
||||
|
||||
class lock_data final {
|
||||
public:
|
||||
explicit lock_data(const provider_type &pt, std::string unique_id /*= ""*/);
|
||||
explicit lock_data(const provider_type &prov, std::string unique_id /*= ""*/);
|
||||
|
||||
lock_data();
|
||||
lock_data(const lock_data &) = delete;
|
||||
lock_data(lock_data &&) = delete;
|
||||
|
||||
auto operator=(const lock_data &) -> lock_data & = delete;
|
||||
auto operator=(lock_data &&) -> lock_data & = delete;
|
||||
|
||||
~lock_data();
|
||||
|
||||
private:
|
||||
const provider_type pt_;
|
||||
const std::string unique_id_;
|
||||
const std::string mutex_id_;
|
||||
provider_type prov_;
|
||||
std::string unique_id_;
|
||||
std::string mutex_id_;
|
||||
int lock_fd_;
|
||||
int lock_status_{EWOULDBLOCK};
|
||||
|
||||
|
@ -36,17 +36,14 @@
|
||||
#include "utils/unix.hpp"
|
||||
|
||||
namespace repertory {
|
||||
lock_data::lock_data(const provider_type &pt, std::string unique_id /*= ""*/)
|
||||
: pt_(pt),
|
||||
lock_data::lock_data(const provider_type &prov, std::string unique_id /*= ""*/)
|
||||
: prov_(prov),
|
||||
unique_id_(std::move(unique_id)),
|
||||
mutex_id_("repertory_" + app_config::get_provider_name(pt) + "_" +
|
||||
mutex_id_("repertory_" + app_config::get_provider_name(prov) + "_" +
|
||||
unique_id_) {
|
||||
lock_fd_ = open(get_lock_file().c_str(), O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);
|
||||
}
|
||||
|
||||
lock_data::lock_data()
|
||||
: pt_(provider_type::sia), unique_id_(""), mutex_id_(""), lock_fd_(-1) {}
|
||||
|
||||
lock_data::~lock_data() { release(); }
|
||||
|
||||
auto lock_data::get_lock_data_file() -> std::string {
|
||||
@ -105,9 +102,6 @@ auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
|
||||
lock_status_ = wait_for_lock(lock_fd_, retry_count);
|
||||
switch (lock_status_) {
|
||||
case 0:
|
||||
if (not set_mount_state(false, "", -1)) {
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
return lock_result::success;
|
||||
case EWOULDBLOCK:
|
||||
return lock_result::locked;
|
||||
@ -140,7 +134,7 @@ auto lock_data::set_mount_state(bool active, const std::string &mount_location,
|
||||
if (handle != -1) {
|
||||
if (wait_for_lock(handle) == 0) {
|
||||
const auto mount_id =
|
||||
app_config::get_provider_display_name(pt_) + unique_id_;
|
||||
app_config::get_provider_display_name(prov_) + unique_id_;
|
||||
json mount_state;
|
||||
if (not utils::file::read_json_file(get_lock_data_file(), mount_state)) {
|
||||
utils::error::raise_error(function_name,
|
||||
|
@ -89,23 +89,9 @@ auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
|
||||
}
|
||||
|
||||
switch (mutex_state_) {
|
||||
case WAIT_OBJECT_0: {
|
||||
case WAIT_OBJECT_0:
|
||||
ret = lock_result::success;
|
||||
auto should_reset = true;
|
||||
json mount_state;
|
||||
if (get_mount_state(pt_, mount_state)) {
|
||||
if (mount_state["Active"].get<bool>() &&
|
||||
mount_state["Location"] == "elevating") {
|
||||
should_reset = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (should_reset) {
|
||||
if (not set_mount_state(false, "", -1)) {
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
ret = lock_result::locked;
|
||||
|
@ -28,13 +28,13 @@
|
||||
#include "providers/provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
#include "utils/com_init_wrapper.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "drives/winfsp/remotewinfsp/remote_client.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/remote_winfsp_drive.hpp"
|
||||
#include "drives/winfsp/winfsp_drive.hpp"
|
||||
#include "utils/com_init_wrapper.hpp"
|
||||
|
||||
using repertory_drive = repertory::winfsp_drive;
|
||||
using remote_client = repertory::remote_winfsp::remote_client;
|
||||
@ -56,6 +56,15 @@ namespace repertory::cli::actions {
|
||||
mount(std::vector<const char *> args, std::string data_directory,
|
||||
int &mount_result, provider_type prov, const std::string &remote_host,
|
||||
std::uint16_t remote_port, const std::string &unique_id) -> exit_code {
|
||||
lock_data global_lock(provider_type::unknown, "global");
|
||||
{
|
||||
auto lock_result = global_lock.grab_lock(100U);
|
||||
if (lock_result != lock_result::success) {
|
||||
std::cerr << "FATAL: Unable to get global lock" << std::endl;
|
||||
return exit_code::lock_failed;
|
||||
}
|
||||
}
|
||||
|
||||
lock_data lock(prov, unique_id);
|
||||
auto lock_result = lock.grab_lock();
|
||||
if (lock_result == lock_result::locked) {
|
||||
@ -97,13 +106,6 @@ mount(std::vector<const char *> args, std::string data_directory,
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
lock_data global_lock(provider_type::unknown, "global");
|
||||
lock_result = global_lock.grab_lock(100U);
|
||||
if (lock_result != lock_result::success) {
|
||||
std::cerr << "FATAL: Unable to get global lock" << std::endl;
|
||||
return exit_code::lock_failed;
|
||||
}
|
||||
|
||||
auto drive_args = utils::cli::parse_drive_options(args, prov, data_directory);
|
||||
app_config config(prov, data_directory);
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
: http_error_codes::internal_error;
|
||||
});
|
||||
|
||||
server->Get("/api/v1/locations", [this](auto && /* req */, auto &&res) {
|
||||
server->Get("/api/v1/locations", [](auto && /* req */, auto &&res) {
|
||||
handle_get_available_locations(res);
|
||||
});
|
||||
|
||||
@ -567,12 +567,12 @@ void handlers::handle_post_mount(const httplib::Request &req,
|
||||
return;
|
||||
}
|
||||
|
||||
config_->set_mount_location(prov, name, location);
|
||||
|
||||
static std::mutex mount_mtx;
|
||||
mutex_lock lock(mount_mtx);
|
||||
|
||||
launch_process(prov, name, {location}, true);
|
||||
config_->set_mount_location(prov, name, location);
|
||||
|
||||
launch_process(prov, name, {"-status"});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user