mirror of https://github.com/trapexit/mergerfs.git
Browse Source
Merge pull request #1123 from trapexit/wait
Merge pull request #1123 from trapexit/wait
Add option to wait for branches to become new mountspull/1125/head
trapexit
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 3034 additions and 106 deletions
-
2LICENSE
-
5README.md
-
11src/branches.cpp
-
3src/branches.hpp
-
3src/config.cpp
-
1src/config.hpp
-
10src/fs_pathvector.hpp
-
112src/fs_wait_for_mount.cpp
-
50src/fs_wait_for_mount.hpp
-
35src/mergerfs.cpp
-
2537src/nonstd/expected.hpp
-
114src/nonstd/optional.hpp
-
96src/syslog.cpp
-
29src/syslog.hpp
@ -0,0 +1,10 @@ |
|||
#pragma once
|
|||
|
|||
#include "ghc/filesystem.hpp"
|
|||
|
|||
#include <vector>
|
|||
|
|||
namespace fs |
|||
{ |
|||
typedef std::vector<ghc::filesystem::path> PathVector; |
|||
} |
@ -0,0 +1,112 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#include "fs_wait_for_mount.hpp"
|
|||
|
|||
#include <thread>
|
|||
|
|||
constexpr std::chrono::milliseconds SLEEP_DURATION = std::chrono::milliseconds(333); |
|||
|
|||
|
|||
bool |
|||
fs::wait_for_mount(const struct stat &src_st_, |
|||
const ghc::filesystem::path &tgtpath_, |
|||
const std::chrono::milliseconds &timeout_) |
|||
{ |
|||
int rv; |
|||
std::chrono::duration<double> time_diff; |
|||
std::chrono::time_point<std::chrono::steady_clock> start_time; |
|||
|
|||
start_time = std::chrono::steady_clock::now(); |
|||
while(true) |
|||
{ |
|||
struct stat tgt_st; |
|||
|
|||
rv = fs::stat(tgtpath_,&tgt_st); |
|||
if(rv == 0) |
|||
{ |
|||
if(tgt_st.st_dev != src_st_.st_dev) |
|||
return true; |
|||
} |
|||
|
|||
time_diff = (std::chrono::steady_clock::now() - start_time); |
|||
if(time_diff > timeout_) |
|||
return false; |
|||
|
|||
std::this_thread::sleep_for(SLEEP_DURATION); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
static |
|||
void |
|||
_wait_for_mount(const struct stat &src_st_, |
|||
const fs::PathVector &tgtpaths_, |
|||
const std::chrono::milliseconds &timeout_, |
|||
fs::PathVector &failed_paths_) |
|||
{ |
|||
bool rv; |
|||
fs::PathVector::const_iterator i; |
|||
std::chrono::milliseconds timeout; |
|||
std::chrono::milliseconds diff; |
|||
std::chrono::time_point<std::chrono::steady_clock> now; |
|||
std::chrono::time_point<std::chrono::steady_clock> start_time; |
|||
|
|||
timeout = timeout_; |
|||
now = start_time = std::chrono::steady_clock::now(); |
|||
for(auto i = tgtpaths_.begin(); i != tgtpaths_.end(); ++i) |
|||
{ |
|||
diff = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time); |
|||
timeout -= diff; |
|||
|
|||
rv = fs::wait_for_mount(src_st_,*i,timeout); |
|||
if(rv == false) |
|||
failed_paths_.push_back(*i); |
|||
|
|||
now = std::chrono::steady_clock::now(); |
|||
} |
|||
} |
|||
|
|||
void |
|||
fs::wait_for_mount(const struct stat &src_st_, |
|||
const fs::PathVector &tgtpaths_, |
|||
const std::chrono::milliseconds &timeout_, |
|||
fs::PathVector &failed_paths_) |
|||
{ |
|||
if(tgtpaths_.empty()) |
|||
return; |
|||
|
|||
_wait_for_mount(src_st_,tgtpaths_,timeout_,failed_paths_); |
|||
} |
|||
|
|||
void |
|||
fs::wait_for_mount(const ghc::filesystem::path &srcpath_, |
|||
const fs::PathVector &tgtpaths_, |
|||
const std::chrono::milliseconds &timeout_, |
|||
fs::PathVector &failed_paths_) |
|||
{ |
|||
int rv; |
|||
struct stat src_st; |
|||
|
|||
rv = fs::stat(srcpath_,&src_st); |
|||
if(rv == -1) |
|||
return; |
|||
|
|||
fs::wait_for_mount(src_st,tgtpaths_,timeout_,failed_paths_); |
|||
} |
@ -0,0 +1,50 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include "ghc/filesystem.hpp"
|
|||
|
|||
#include "fs_pathvector.hpp"
|
|||
#include "fs_stat.hpp"
|
|||
|
|||
#include <chrono>
|
|||
#include <vector>
|
|||
|
|||
|
|||
namespace fs |
|||
{ |
|||
typedef std::vector<ghc::filesystem::path> PathVector; |
|||
|
|||
bool |
|||
wait_for_mount(const struct stat &st, |
|||
const ghc::filesystem::path &tgtpath, |
|||
const std::chrono::milliseconds &timeout); |
|||
|
|||
void |
|||
wait_for_mount(const struct stat &st, |
|||
const fs::PathVector &tgtpaths, |
|||
const std::chrono::milliseconds &timeout, |
|||
fs::PathVector &failed_paths); |
|||
|
|||
void |
|||
wait_for_mount(const ghc::filesystem::path &srcpath, |
|||
const fs::PathVector &tgtpaths, |
|||
const std::chrono::milliseconds &timeout, |
|||
fs::PathVector &failed_paths); |
|||
} |
2537
src/nonstd/expected.hpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,96 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#include <stdarg.h>
|
|||
#include <syslog.h>
|
|||
|
|||
static bool g_SYSLOG_ENABLED = false; |
|||
|
|||
void |
|||
syslog_open() |
|||
{ |
|||
const char *ident = "mergerfs"; |
|||
const int option = (LOG_CONS|LOG_PID); |
|||
const int facility = LOG_USER; |
|||
|
|||
openlog(ident,option,facility); |
|||
g_SYSLOG_ENABLED = true; |
|||
} |
|||
|
|||
void |
|||
syslog_close() |
|||
{ |
|||
closelog(); |
|||
g_SYSLOG_ENABLED = false; |
|||
} |
|||
|
|||
void |
|||
syslog_log(const int priority_, |
|||
const char *format_, |
|||
va_list valist_) |
|||
{ |
|||
if(g_SYSLOG_ENABLED == false) |
|||
return; |
|||
|
|||
vsyslog(priority_,format_,valist_); |
|||
} |
|||
|
|||
void |
|||
syslog_log(const int priority_, |
|||
const char *format_, |
|||
...) |
|||
{ |
|||
va_list valist; |
|||
|
|||
va_start(valist,format_); |
|||
syslog_log(priority_,format_,valist); |
|||
va_end(valist); |
|||
} |
|||
|
|||
void |
|||
syslog_info(const char *format_, |
|||
...) |
|||
{ |
|||
va_list valist; |
|||
|
|||
va_start(valist,format_); |
|||
syslog_log(LOG_INFO,format_,valist); |
|||
va_end(valist); |
|||
} |
|||
|
|||
void |
|||
syslog_warning(const char *format_, |
|||
...) |
|||
{ |
|||
va_list valist; |
|||
|
|||
va_start(valist,format_); |
|||
syslog_log(LOG_WARNING,format_,valist); |
|||
va_end(valist); |
|||
} |
|||
|
|||
void |
|||
syslog_error(const char *format_, |
|||
...) |
|||
{ |
|||
va_list valist; |
|||
|
|||
va_start(valist,format_); |
|||
syslog_log(LOG_ERR,format_,valist); |
|||
va_end(valist); |
|||
} |
@ -0,0 +1,29 @@ |
|||
/*
|
|||
ISC License |
|||
|
|||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link> |
|||
|
|||
Permission to use, copy, modify, and/or distribute this software for any |
|||
purpose with or without fee is hereby granted, provided that the above |
|||
copyright notice and this permission notice appear in all copies. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|||
*/ |
|||
|
|||
#pragma once
|
|||
|
|||
#include <syslog.h>
|
|||
|
|||
|
|||
void syslog_open(); |
|||
void syslog_log(const int priority, const char *format, ...); |
|||
void syslog_info(const char *format, ...); |
|||
void syslog_warning(const char *format, ...); |
|||
void syslog_error(const char *format, ...); |
|||
void syslog_close(); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue