mirror of https://github.com/trapexit/mergerfs.git
Browse Source
moveonenospc: enhance the feature to allow using a policy
moveonenospc: enhance the feature to allow using a policy
Just like functions you can now set a policy for moveonfreenospc. This allows for more flexibility. For backwards compatibility moveonfreenospc=true is converted to moveonfreenospc=mfs. minfreespace does apply which is slightly different from original behavior.pull/782/head
Antonio SJ Musumeci
4 years ago
23 changed files with 476 additions and 141 deletions
-
4README.md
-
15man/mergerfs.1
-
3src/config.hpp
-
54src/config_moveonenospc.cpp
-
44src/config_moveonenospc.hpp
-
5src/fs.hpp
-
2src/fs_acl.cpp
-
12src/fs_copydata_copy_file_range.cpp
-
18src/fs_copydata_readwrite.cpp
-
37src/fs_file_size.cpp
-
27src/fs_file_size.hpp
-
65src/fs_findonfs.cpp
-
29src/fs_findonfs.hpp
-
41src/fs_has_space.cpp
-
30src/fs_has_space.hpp
-
17src/fs_mktemp.cpp
-
108src/fs_movefile.cpp
-
20src/fs_movefile.hpp
-
8src/fs_path.cpp
-
4src/fs_path.hpp
-
44src/fuse_write.cpp
-
26src/fuse_write_buf.cpp
-
4src/statvfs_util.hpp
@ -0,0 +1,54 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 "ef.hpp"
|
||||
|
#include "from_string.hpp"
|
||||
|
#include "config_moveonenospc.hpp"
|
||||
|
|
||||
|
int |
||||
|
MoveOnENOSPC::from_string(const std::string &s_) |
||||
|
{ |
||||
|
int rv; |
||||
|
std::string s; |
||||
|
const Policy *tmp; |
||||
|
|
||||
|
rv = str::from(s_,&enabled); |
||||
|
if((rv == 0) && (enabled == true)) |
||||
|
s = "mfs"; |
||||
|
ef(rv != 0) |
||||
|
s = s_; |
||||
|
else |
||||
|
return 0; |
||||
|
|
||||
|
tmp = &Policy::find(s); |
||||
|
if(tmp == Policy::invalid) |
||||
|
return -EINVAL; |
||||
|
|
||||
|
policy = tmp; |
||||
|
enabled = true; |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
std::string |
||||
|
MoveOnENOSPC::to_string(void) const |
||||
|
{ |
||||
|
if(enabled) |
||||
|
return policy->to_string(); |
||||
|
return "false"; |
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 "policy.hpp"
|
||||
|
#include "tofrom_string.hpp"
|
||||
|
|
||||
|
#include <string>
|
||||
|
|
||||
|
class MoveOnENOSPC : public ToFromString |
||||
|
{ |
||||
|
public: |
||||
|
MoveOnENOSPC(const bool enabled_) |
||||
|
: enabled(enabled_) |
||||
|
{ |
||||
|
policy = (enabled ? |
||||
|
&Policy::mfs : |
||||
|
&Policy::invalid); |
||||
|
} |
||||
|
|
||||
|
public: |
||||
|
int from_string(const std::string &s); |
||||
|
std::string to_string() const; |
||||
|
|
||||
|
public: |
||||
|
bool enabled; |
||||
|
const Policy *policy; |
||||
|
}; |
@ -0,0 +1,37 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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_base_stat.hpp"
|
||||
|
|
||||
|
#include <stdint.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
int64_t |
||||
|
file_size(const int fd_) |
||||
|
{ |
||||
|
int rv; |
||||
|
struct stat st; |
||||
|
|
||||
|
rv = fs::fstat(fd_,&st); |
||||
|
if(rv == -1) |
||||
|
return -1; |
||||
|
|
||||
|
return st.st_size; |
||||
|
} |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 <stdint.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
int64_t |
||||
|
file_size(const int fd); |
||||
|
} |
@ -0,0 +1,65 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 "branch.hpp"
|
||||
|
#include "fs_base_stat.hpp"
|
||||
|
#include "fs_path.hpp"
|
||||
|
|
||||
|
#include <string>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
int |
||||
|
findonfs(const Branches &branches_, |
||||
|
const std::string &fusepath_, |
||||
|
const int fd_, |
||||
|
std::string *basepath_) |
||||
|
{ |
||||
|
int rv; |
||||
|
dev_t dev; |
||||
|
struct stat st; |
||||
|
std::string fullpath; |
||||
|
const Branch *branch; |
||||
|
const rwlock::ReadGuard guard(&branches_.lock); |
||||
|
|
||||
|
rv = fs::fstat(fd_,&st); |
||||
|
if(rv == -1) |
||||
|
return -1; |
||||
|
|
||||
|
dev = st.st_dev; |
||||
|
for(size_t i = 0, ei = branches_.size(); i != ei; i++) |
||||
|
{ |
||||
|
branch = &branches_[i]; |
||||
|
|
||||
|
fullpath = fs::path::make(branch->path,fusepath_); |
||||
|
|
||||
|
rv = fs::lstat(fullpath,&st); |
||||
|
if(rv == -1) |
||||
|
continue; |
||||
|
|
||||
|
if(st.st_dev != dev) |
||||
|
continue; |
||||
|
|
||||
|
*basepath_ = branch->path; |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
return (errno=ENOENT,-1); |
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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_base_statvfs.hpp"
|
||||
|
#include "statvfs_util.hpp"
|
||||
|
|
||||
|
#include <string>
|
||||
|
|
||||
|
#include <stdint.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
bool |
||||
|
has_space(const std::string &str_, |
||||
|
const int64_t size_) |
||||
|
{ |
||||
|
int rv; |
||||
|
struct statvfs st; |
||||
|
|
||||
|
rv = fs::statvfs(str_,&st); |
||||
|
if(rv == -1) |
||||
|
return false; |
||||
|
|
||||
|
return (StatVFS::spaceavail(st) > size_); |
||||
|
} |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
/*
|
||||
|
ISC License |
||||
|
|
||||
|
Copyright (c) 2020, 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 <string>
|
||||
|
|
||||
|
#include <stdint.h>
|
||||
|
|
||||
|
namespace fs |
||||
|
{ |
||||
|
bool |
||||
|
has_space(const std::string &str, |
||||
|
const int64_t size); |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue