Browse Source

Rework policies to return branches rather than path strings

pull/1467/head
trapexit 6 days ago
committed by GitHub
parent
commit
86b50d2d4e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      .github/workflows/mkdocs.yml
  2. 28
      src/branch.cpp
  3. 39
      src/branch.hpp
  4. 72
      src/branches.cpp
  5. 38
      src/branches.hpp
  6. 26
      src/config.cpp
  7. 30
      src/fileinfo.hpp
  8. 8
      src/fs_cow.cpp
  9. 16
      src/fs_findonfs.cpp
  10. 8
      src/fs_findonfs.hpp
  11. 35
      src/fs_movefile.cpp
  12. 4
      src/fs_movefile.hpp
  13. 5
      src/fuse_access.cpp
  14. 62
      src/fuse_chmod.cpp
  15. 67
      src/fuse_chown.cpp
  16. 26
      src/fuse_create.cpp
  17. 2
      src/fuse_fgetattr.cpp
  18. 8
      src/fuse_getattr.cpp
  19. 54
      src/fuse_getxattr.cpp
  20. 2
      src/fuse_init.cpp
  21. 32
      src/fuse_ioctl.cpp
  22. 78
      src/fuse_link.cpp
  23. 10
      src/fuse_listxattr.cpp
  24. 54
      src/fuse_mkdir.cpp
  25. 69
      src/fuse_mknod.cpp
  26. 18
      src/fuse_open.cpp
  27. 12
      src/fuse_readdir_cor.cpp
  28. 22
      src/fuse_readdir_cosr.cpp
  29. 6
      src/fuse_readdir_seq.cpp
  30. 13
      src/fuse_readlink.cpp
  31. 52
      src/fuse_removexattr.cpp
  32. 89
      src/fuse_rename.cpp
  33. 16
      src/fuse_rmdir.cpp
  34. 63
      src/fuse_setxattr.cpp
  35. 10
      src/fuse_statfs.cpp
  36. 8
      src/fuse_statx_supported.icpp
  37. 50
      src/fuse_symlink.cpp
  38. 50
      src/fuse_truncate.cpp
  39. 27
      src/fuse_unlink.cpp
  40. 50
      src/fuse_utimens.cpp
  41. 13
      src/int_types.h
  42. 1847
      src/nonstd/optional.hpp
  43. 53
      src/policy.hpp
  44. 28
      src/policy_all.cpp
  45. 12
      src/policy_all.hpp
  46. 6
      src/policy_cache.cpp
  47. 5
      src/policy_cache.hpp
  48. 38
      src/policy_epall.cpp
  49. 12
      src/policy_epall.hpp
  50. 32
      src/policy_epff.cpp
  51. 12
      src/policy_epff.hpp
  52. 60
      src/policy_eplfs.cpp
  53. 12
      src/policy_eplfs.hpp
  54. 56
      src/policy_eplus.cpp
  55. 12
      src/policy_eplus.hpp
  56. 60
      src/policy_epmfs.cpp
  57. 12
      src/policy_epmfs.hpp
  58. 107
      src/policy_eppfrd.cpp
  59. 12
      src/policy_eppfrd.hpp
  60. 18
      src/policy_eprand.cpp
  61. 12
      src/policy_eprand.hpp
  62. 12
      src/policy_erofs.cpp
  63. 12
      src/policy_erofs.hpp
  64. 33
      src/policy_ff.cpp
  65. 13
      src/policy_ff.hpp
  66. 29
      src/policy_lfs.cpp
  67. 12
      src/policy_lfs.hpp
  68. 28
      src/policy_lus.cpp
  69. 12
      src/policy_lus.hpp
  70. 30
      src/policy_mfs.cpp
  71. 12
      src/policy_mfs.hpp
  72. 49
      src/policy_msplfs.cpp
  73. 12
      src/policy_msplfs.hpp
  74. 48
      src/policy_msplus.cpp
  75. 12
      src/policy_msplus.hpp
  76. 49
      src/policy_mspmfs.cpp
  77. 12
      src/policy_mspmfs.hpp
  78. 66
      src/policy_msppfrd.cpp
  79. 12
      src/policy_msppfrd.hpp
  80. 54
      src/policy_newest.cpp
  81. 12
      src/policy_newest.hpp
  82. 58
      src/policy_pfrd.cpp
  83. 12
      src/policy_pfrd.hpp
  84. 18
      src/policy_rand.cpp
  85. 12
      src/policy_rand.hpp
  86. 26
      src/policy_rv.hpp

18
.github/workflows/mkdocs.yml

@ -5,10 +5,10 @@ on:
- master
tags:
- '*'
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
@ -27,12 +27,12 @@ jobs:
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Install dependencies
working-directory: ./mkdocs
working-directory: ./mkdocs
run: |
pip install --no-cache-dir mkdocs mkdocs-material pymdown-extensions mike
- name: Deploy docs
working-directory: ./mkdocs
working-directory: ./mkdocs
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
@ -40,10 +40,10 @@ jobs:
if [ "$REF_TYPE" = "tag" ]; then
mike deploy "$REF_NAME" "latest" --allow-empty --ignore-remote-status --update-aliases
mike set-default "latest"
git checkout gh-pages
git push -f origin gh-pages
#git checkout gh-pages
#git push -f origin gh-pages
elif [ "$REF_TYPE" = "branch" ] && [ "$REF_NAME" = "master" ]; then
mike deploy "master" --ignore-remote-status --allow-empty
git checkout gh-pages
git push -f origin gh-pages
#git checkout gh-pages
#git push -f origin gh-pages
fi

28
src/branch.cpp

@ -21,9 +21,19 @@
#include "errno.hpp"
#include "num.hpp"
Branch::Branch()
{
}
Branch::Branch(const Branch &branch_)
: _minfreespace(branch_._minfreespace),
mode(branch_.mode),
path(branch_.path)
{
}
Branch::Branch(const uint64_t &default_minfreespace_)
: _default_minfreespace(&default_minfreespace_)
Branch::Branch(const u64 &default_minfreespace_)
: _minfreespace(&default_minfreespace_)
{
}
@ -54,27 +64,27 @@ Branch::to_string(void) const
break;
}
if(_minfreespace.has_value())
if(std::holds_alternative<u64>(_minfreespace))
{
rv += ',';
rv += num::humanize(_minfreespace.value());
rv += num::humanize(std::get<u64>(_minfreespace));
}
return rv;
}
void
Branch::set_minfreespace(const uint64_t minfreespace_)
Branch::set_minfreespace(const u64 minfreespace_)
{
_minfreespace = minfreespace_;
}
uint64_t
u64
Branch::minfreespace(void) const
{
if(_minfreespace.has_value())
return _minfreespace.value();
return *_default_minfreespace;
if(std::holds_alternative<const u64*>(_minfreespace))
return *std::get<const u64*>(_minfreespace);
return std::get<u64>(_minfreespace);
}
bool

39
src/branch.hpp

@ -18,31 +18,38 @@
#pragma once
#include "nonstd/optional.hpp"
#include "int_types.h"
#include "strvec.hpp"
#include "tofrom_string.hpp"
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <variant>
class Branch final : public ToFromString
{
public:
typedef std::vector<Branch> Vector;
enum class Mode
{
INVALID,
RO,
RW,
NC
};
public:
Branch(const uint64_t &default_minfreespace_);
std::variant<u64,const u64*> _minfreespace;
Mode mode;
std::string path;
public:
enum class Mode
{
INVALID,
RO,
RW,
NC
};
Branch();
Branch(const Branch&);
Branch(const u64 &default_minfreespace);
public:
bool ro(void) const;
@ -54,14 +61,6 @@ public:
std::string to_string(void) const final;
public:
uint64_t minfreespace() const;
void set_minfreespace(const uint64_t);
public:
Mode mode;
std::string path;
private:
nonstd::optional<uint64_t> _minfreespace;
const uint64_t *_default_minfreespace;
u64 minfreespace() const;
void set_minfreespace(const u64);
};

72
src/branches.cpp

@ -23,21 +23,18 @@
#include "fs_glob.hpp"
#include "fs_is_rofs.hpp"
#include "fs_realpathize.hpp"
#include "nonstd/optional.hpp"
#include "int_types.h"
#include "num.hpp"
#include "str.hpp"
#include "syslog.hpp"
#include <string>
#include <optional>
#include <fnmatch.h>
using std::string;
using std::vector;
using nonstd::optional;
Branches::Impl::Impl(const uint64_t &default_minfreespace_)
Branches::Impl::Impl(const u64 &default_minfreespace_)
: _default_minfreespace(default_minfreespace_)
{
}
@ -45,8 +42,9 @@ Branches::Impl::Impl(const uint64_t &default_minfreespace_)
Branches::Impl&
Branches::Impl::operator=(Branches::Impl &rval_)
{
auto this_base = dynamic_cast<Branch::Vector*>(this);
auto rval_base = dynamic_cast<Branch::Vector*>(&rval_);
using type = std::vector<std::shared_ptr<Branch>>;
auto this_base = dynamic_cast<type*>(this);
auto rval_base = dynamic_cast<type*>(&rval_);
*this_base = *rval_base;
@ -56,8 +54,9 @@ Branches::Impl::operator=(Branches::Impl &rval_)
Branches::Impl&
Branches::Impl::operator=(Branches::Impl &&rval_)
{
auto this_base = dynamic_cast<Branch::Vector*>(this);
auto rval_base = dynamic_cast<Branch::Vector*>(&rval_);
using type = std::vector<std::shared_ptr<Branch>>;
auto this_base = dynamic_cast<type*>(this);
auto rval_base = dynamic_cast<type*>(&rval_);
*this_base = std::move(*rval_base);
@ -65,7 +64,7 @@ Branches::Impl::operator=(Branches::Impl &&rval_)
}
const
uint64_t&
u64&
Branches::Impl::minfreespace(void) const
{
return _default_minfreespace;
@ -79,7 +78,7 @@ namespace l
std::string *instr_,
std::string *values_)
{
uint64_t offset;
u64 offset;
offset = s_.find_first_not_of("+<>-=");
if (offset == std::string::npos) {
@ -94,8 +93,8 @@ namespace l
static
int
parse_mode(const string &str_,
Branch::Mode *mode_)
parse_mode(const std::string &str_,
Branch::Mode *mode_)
{
if(str_ == "RW")
*mode_ = Branch::Mode::RW;
@ -111,11 +110,11 @@ namespace l
static
int
parse_minfreespace(const string &str_,
optional<uint64_t> *minfreespace_)
parse_minfreespace(const std::string &str_,
std::optional<u64> *minfreespace_)
{
int rv;
uint64_t uint64;
u64 uint64;
rv = str::from(str_,&uint64);
if(rv < 0)
@ -128,14 +127,14 @@ namespace l
static
int
parse_branch(const string &str_,
string *glob_,
parse_branch(const std::string &str_,
std::string *glob_,
Branch::Mode *mode_,
optional<uint64_t> *minfreespace_)
std::optional<u64> *minfreespace_)
{
int rv;
string options;
vector<string> v;
std::string options;
std::vector<std::string> v;
str::rsplit1(str_,'=',&v);
switch(v.size())
@ -173,21 +172,23 @@ namespace l
static
int
parse(const string &str_,
Branches::Impl *branches_)
parse(const std::string &str_,
Branches::Impl *branches_)
{
int rv;
string glob;
std::string glob;
StrVec paths;
optional<uint64_t> minfreespace;
Branch branch(branches_->minfreespace());
Branch branch;
std::optional<u64> minfreespace;
branch._minfreespace = &branches_->minfreespace();
rv = l::parse_branch(str_,&glob,&branch.mode,&minfreespace);
if(rv < 0)
return rv;
if(minfreespace.has_value())
branch.set_minfreespace(minfreespace.value());
branch._minfreespace = minfreespace.value();
fs::glob(glob,&paths);
if(paths.empty())
@ -197,7 +198,7 @@ namespace l
for(auto &path : paths)
{
branch.path = path;
branches_->push_back(branch);
branches_->emplace_back(branch);
}
return 0;
@ -231,7 +232,7 @@ namespace l
Branches::Impl *branches_)
{
int rv;
vector<string> paths;
std::vector<std::string> paths;
Branches::Impl tmp_branches(branches_->minfreespace());
str::split(str_,':',&paths);
@ -302,10 +303,13 @@ namespace l
for(auto i = branches_->begin(); i != branches_->end();)
{
int match = FNM_NOMATCH;
Branch &branch = *i;
for(auto pi = patterns.cbegin(); pi != patterns.cend() && match != 0; ++pi)
{
match = ::fnmatch(pi->c_str(),i->path.c_str(),0);
match = ::fnmatch(pi->c_str(),
branch.path.c_str(),
0);
}
i = ((match == 0) ? branches_->erase(i) : (i+1));
@ -346,7 +350,7 @@ Branches::Impl::from_string(const std::string &s_)
std::string
Branches::Impl::to_string(void) const
{
string tmp;
std::string tmp;
if(empty())
return tmp;
@ -409,7 +413,7 @@ Branches::from_string(const std::string &str_)
return 0;
}
string
std::string
Branches::to_string(void) const
{
std::lock_guard<std::mutex> lock_guard(_mutex);
@ -452,7 +456,7 @@ std::string
SrcMounts::to_string(void) const
{
std::string rv;
Branches::CPtr branches = _branches;
Branches::Ptr branches = _branches;
if(branches->empty())
return rv;

38
src/branches.hpp

@ -28,43 +28,47 @@
#include <mutex>
#include <string>
#include <vector>
#include <memory>
class Branches final : public ToFromString
{
public:
class Impl final : public ToFromString, public Branch::Vector
class Impl final : public ToFromString,
public std::vector<Branch>
{
private:
const u64 &_default_minfreespace;
public:
typedef std::shared_ptr<Impl> Ptr;
typedef std::shared_ptr<const Impl> CPtr;
using Ptr = std::shared_ptr<Impl>;
public:
Impl(const uint64_t &default_minfreespace_);
Impl(const u64 &default_minfreespace);
public:
int from_string(const std::string &str) final;
std::string to_string(void) const final;
public:
const uint64_t& minfreespace(void) const;
const u64 &minfreespace(void) const;
void to_paths(StrVec &strvec) const;
fs::PathVector to_paths() const;
public:
Impl& operator=(Impl &impl_);
Impl& operator=(Impl &&impl_);
private:
const uint64_t &_default_minfreespace;
};
public:
typedef Branches::Impl::Ptr Ptr;
typedef Branches::Impl::CPtr CPtr;
using Ptr = Branches::Impl::Ptr;
private:
mutable std::mutex _mutex;
Ptr _impl;
public:
Branches(const uint64_t &default_minfreespace_)
Branches(const u64 &default_minfreespace_)
: _impl(std::make_shared<Impl>(default_minfreespace_))
{}
@ -73,21 +77,17 @@ public:
std::string to_string(void) const final;
public:
operator CPtr() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
CPtr operator->() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
operator Ptr() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
Ptr operator->() const { std::lock_guard<std::mutex> lg(_mutex); return _impl; }
public:
void find_and_set_mode_ro();
private:
mutable std::mutex _mutex;
Ptr _impl;
};
class SrcMounts : public ToFromString
{
public:
SrcMounts(Branches &b_);
SrcMounts(Branches &b);
public:
int from_string(const std::string &str) final;

26
src/config.cpp

@ -246,17 +246,11 @@ Config::has_key(const std::string &key_) const
void
Config::keys(std::string &s_) const
{
Str2TFStrMap::const_iterator i;
Str2TFStrMap::const_iterator ei;
s_.reserve(512);
i = _map.begin();
ei = _map.end();
for(; i != ei; ++i)
for(const auto &[key,val] : _map)
{
s_ += i->first;
s_ += key;
s_ += '\0';
}
@ -267,14 +261,11 @@ Config::keys(std::string &s_) const
void
Config::keys_xattr(std::string &s_) const
{
Str2TFStrMap::const_iterator i;
Str2TFStrMap::const_iterator ei;
s_.reserve(1024);
for(i = _map.begin(), ei = _map.end(); i != ei; ++i)
for(const auto &[key,val] : _map)
{
s_ += "user.mergerfs.";
s_ += i->first;
s_ += key;
s_ += '\0';
}
}
@ -396,13 +387,8 @@ std::ostream&
operator<<(std::ostream &os_,
const Config &c_)
{
Str2TFStrMap::const_iterator i;
Str2TFStrMap::const_iterator ei;
for(i = c_._map.begin(), ei = c_._map.end(); i != ei; ++i)
{
os_ << i->first << '=' << i->second->to_string() << std::endl;
}
for(const auto &[key,val] : c_._map)
os_ << key << '=' << val->to_string() << std::endl;
return os_;
}

30
src/fileinfo.hpp

@ -17,29 +17,43 @@
#pragma once
#include "fh.hpp"
#include "branch.hpp"
#include <cstdint>
#include <string>
#include <mutex>
#include "int_types.h"
class FileInfo : public FH
{
public:
FileInfo(const int fd_,
const std::string branchpath_,
const char *fusepath_,
const bool direct_io_)
FileInfo(const int fd_,
const Branch &branch_,
const char *fusepath_,
const bool direct_io_)
: FH(fusepath_),
fd(fd_),
branch(branch_),
direct_io(direct_io_)
{
}
FileInfo(const int fd_,
const Branch *branch_,
const char *fusepath_,
const bool direct_io_)
: FH(fusepath_),
fd(fd_),
branchpath(std::move(branchpath_)),
branch(*branch_),
direct_io(direct_io_)
{
}
public:
int fd;
std::string branchpath;
uint32_t direct_io:1;
Branch branch;
u32 direct_io:1;
std::mutex mutex;
};

8
src/fs_cow.cpp

@ -33,16 +33,14 @@
#include <sys/types.h>
#include <unistd.h>
using std::string;
namespace l
{
static
int
cleanup_on_error(const int src_fd_,
const int dst_fd_ = -1,
const string &dst_fullpath_ = string())
cleanup_on_error(const int src_fd_,
const int dst_fd_ = -1,
const std::string &dst_fullpath_ = {})
{
int error = errno;

16
src/fs_findonfs.cpp

@ -29,10 +29,10 @@ namespace l
{
static
int
findonfs(const Branches::CPtr &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
findonfs(const Branches::Ptr &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
{
int rv;
dev_t dev;
@ -67,10 +67,10 @@ namespace l
namespace fs
{
int
findonfs(const Branches::CPtr &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
findonfs(const Branches::Ptr &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
{
return l::findonfs(branches_,fusepath_,fd_,basepath_);
}

8
src/fs_findonfs.hpp

@ -26,8 +26,8 @@
namespace fs
{
int
findonfs(const Branches::CPtr &branches,
const std::string &fusepath,
const int fd,
std::string *basepath);
findonfs(const Branches::Ptr &branches,
const std::string &fusepath,
const int fd,
std::string *basepath);
}

35
src/fs_movefile.cpp

@ -40,9 +40,6 @@
#include <sys/types.h>
#include <unistd.h>
using std::string;
using std::vector;
static
int
@ -64,8 +61,8 @@ namespace l
static
int
movefile(const Policy::Create &createFunc_,
const Branches::CPtr &branches_,
const string &fusepath_,
const Branches::Ptr &branches_,
const std::string &fusepath_,
int origfd_)
{
int rv;
@ -74,12 +71,12 @@ namespace l
int dstfd_flags;
int origfd_flags;
int64_t srcfd_size;
string fusedir;
string srcfd_branch;
string srcfd_filepath;
string dstfd_filepath;
string dstfd_tmp_filepath;
vector<string> dstfd_branch;
std::string fusedir;
std::string srcfd_branch;
std::string srcfd_filepath;
std::string dstfd_filepath;
std::string dstfd_tmp_filepath;
std::vector<Branch*> dstfd_branch;
srcfd = -1;
dstfd = -1;
@ -88,7 +85,7 @@ namespace l
if(rv == -1)
return -errno;
rv = createFunc_(branches_,fusepath_,&dstfd_branch);
rv = createFunc_(branches_,fusepath_.c_str(),dstfd_branch);
if(rv == -1)
return -errno;
@ -100,12 +97,12 @@ namespace l
if(srcfd_size == -1)
return -errno;
if(fs::has_space(dstfd_branch[0],srcfd_size) == false)
if(fs::has_space(dstfd_branch[0]->path,srcfd_size) == false)
return -ENOSPC;
fusedir = fs::path::dirname(fusepath_);
rv = fs::clonepath(srcfd_branch,dstfd_branch[0],fusedir);
rv = fs::clonepath(srcfd_branch,dstfd_branch[0]->path,fusedir);
if(rv == -1)
return -ENOSPC;
@ -115,7 +112,7 @@ namespace l
if(srcfd == -1)
return -ENOSPC;
dstfd_filepath = dstfd_branch[0];
dstfd_filepath = dstfd_branch[0]->path;
fs::path::append(dstfd_filepath,fusepath_);
std::tie(dstfd,dstfd_tmp_filepath) = fs::mktemp(dstfd_filepath,O_WRONLY);
if(dstfd < 0)
@ -163,8 +160,8 @@ namespace fs
{
int
movefile(const Policy::Create &policy_,
const Branches::CPtr &basepaths_,
const string &fusepath_,
const Branches::Ptr &basepaths_,
const std::string &fusepath_,
int origfd_)
{
return l::movefile(policy_,basepaths_,fusepath_,origfd_);
@ -172,8 +169,8 @@ namespace fs
int
movefile_as_root(const Policy::Create &policy_,
const Branches::CPtr &basepaths_,
const string &fusepath_,
const Branches::Ptr &basepaths_,
const std::string &fusepath_,
int origfd_)
{
const ugid::Set ugid(0,0);

4
src/fs_movefile.hpp

@ -26,13 +26,13 @@ namespace fs
{
int
movefile(const Policy::Create &policy,
const Branches::CPtr &branches,
const Branches::Ptr &branches,
const std::string &fusepath,
int origfd);
int
movefile_as_root(const Policy::Create &policy,
const Branches::CPtr &branches,
const Branches::Ptr &branches,
const std::string &fusepath,
int origfd);
}

5
src/fuse_access.cpp

@ -39,12 +39,13 @@ namespace l
int rv;
string fullpath;
StrVec basepaths;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(branches[0]->path,fusepath_);
rv = fs::eaccess(fullpath,mask_);

62
src/fuse_chmod.cpp

@ -27,39 +27,17 @@
#include <string.h>
using std::string;
namespace l
{
static
int
get_error(const PolicyRV &prv_,
const string &basepath_)
{
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
{
if(prv_.success[i].basepath == basepath_)
return prv_.success[i].rv;
}
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
{
if(prv_.error[i].basepath == basepath_)
return prv_.error[i].rv;
}
return 0;
}
static
void
chmod_loop_core(const string &basepath_,
const char *fusepath_,
const mode_t mode_,
PolicyRV *prv_)
chmod_loop_core(const std::string &basepath_,
const char *fusepath_,
const mode_t mode_,
PolicyRV *prv_)
{
string fullpath;
std::string fullpath;
fullpath = fs::path::make(basepath_,fusepath_);
@ -71,14 +49,14 @@ namespace l
static
void
chmod_loop(const StrVec &basepaths_,
const char *fusepath_,
const mode_t mode_,
PolicyRV *prv_)
chmod_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const mode_t mode_,
PolicyRV *prv_)
{
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
l::chmod_loop_core(basepaths_[i],fusepath_,mode_,prv_);
l::chmod_loop_core(branch->path,fusepath_,mode_,prv_);
}
}
@ -92,24 +70,24 @@ namespace l
{
int rv;
PolicyRV prv;
StrVec basepaths;
std::vector<Branch*> branches;
rv = actionFunc_(branches_,fusepath_,&basepaths);
rv = actionFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
l::chmod_loop(basepaths,fusepath_,mode_,&prv);
if(prv.error.empty())
l::chmod_loop(branches,fusepath_,mode_,&prv);
if(prv.errors.empty())
return 0;
if(prv.success.empty())
return prv.error[0].rv;
if(prv.successes.empty())
return prv.errors[0].rv;
basepaths.clear();
rv = searchFunc_(branches_,fusepath_,&basepaths);
branches.clear();
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::get_error(prv,basepaths[0]);
return prv.get_error(branches[0]->path);
}
}

67
src/fuse_chown.cpp

@ -26,41 +26,18 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
namespace l
{
static
int
get_error(const PolicyRV &prv_,
const string &basepath_)
{
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
{
if(prv_.success[i].basepath == basepath_)
return prv_.success[i].rv;
}
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
{
if(prv_.error[i].basepath == basepath_)
return prv_.error[i].rv;
}
return 0;
}
static
void
chown_loop_core(const string &basepath_,
const char *fusepath_,
const uid_t uid_,
const gid_t gid_,
PolicyRV *prv_)
chown_loop_core(const std::string &basepath_,
const char *fusepath_,
const uid_t uid_,
const gid_t gid_,
PolicyRV *prv_)
{
string fullpath;
std::string fullpath;
fullpath = fs::path::make(basepath_,fusepath_);
@ -72,15 +49,15 @@ namespace l
static
void
chown_loop(const vector<string> &basepaths_,
const char *fusepath_,
const uid_t uid_,
const gid_t gid_,
PolicyRV *prv_)
chown_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const uid_t uid_,
const gid_t gid_,
PolicyRV *prv_)
{
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
l::chown_loop_core(basepaths_[i],fusepath_,uid_,gid_,prv_);
l::chown_loop_core(branch->path,fusepath_,uid_,gid_,prv_);
}
}
@ -95,24 +72,24 @@ namespace l
{
int rv;
PolicyRV prv;
vector<string> basepaths;
std::vector<Branch*> branches;
rv = actionFunc_(branches_,fusepath_,&basepaths);
rv = actionFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
l::chown_loop(basepaths,fusepath_,uid_,gid_,&prv);
if(prv.error.empty())
l::chown_loop(branches,fusepath_,uid_,gid_,&prv);
if(prv.errors.empty())
return 0;
if(prv.success.empty())
return prv.error[0].rv;
if(prv.successes.empty())
return prv.errors[0].rv;
basepaths.clear();
rv = searchFunc_(branches_,fusepath_,&basepaths);
branches.clear();
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::get_error(prv,basepaths[0]);
return prv.get_error(branches[0]->path);
}
}

26
src/fuse_create.cpp

@ -147,23 +147,23 @@ namespace l
static
int
create_core(const std::string &createpath_,
const char *fusepath_,
fuse_file_info_t *ffi_,
const mode_t mode_,
const mode_t umask_)
create_core(const Branch *branch_,
const char *fusepath_,
fuse_file_info_t *ffi_,
const mode_t mode_,
const mode_t umask_)
{
int rv;
FileInfo *fi;
std::string fullpath;
fullpath = fs::path::make(createpath_,fusepath_);
fullpath = fs::path::make(branch_->path,fusepath_);
rv = l::create_core(fullpath,mode_,umask_,ffi_->flags);
if(rv == -1)
return -errno;
fi = new FileInfo(rv,createpath_,fusepath_,ffi_->direct_io);
fi = new FileInfo(rv,branch_,fusepath_,ffi_->direct_io);
ffi_->fh = reinterpret_cast<uint64_t>(fi);
@ -183,20 +183,22 @@ namespace l
int rv;
std::string fullpath;
std::string fusedirpath;
StrVec createpaths;
StrVec existingpaths;
std::vector<Branch*> createpaths;
std::vector<Branch*> existingpaths;
fusedirpath = fs::path::dirname(fusepath_);
rv = searchFunc_(branches_,fusedirpath,&existingpaths);
rv = searchFunc_(branches_,fusedirpath,existingpaths);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,fusedirpath,&createpaths);
rv = createFunc_(branches_,fusedirpath,createpaths);
if(rv == -1)
return -errno;
rv = fs::clonepath_as_root(existingpaths[0],createpaths[0],fusedirpath);
rv = fs::clonepath_as_root(existingpaths[0]->path,
createpaths[0]->path,
fusedirpath);
if(rv == -1)
return -errno;

2
src/fuse_fgetattr.cpp

@ -38,7 +38,7 @@ namespace FUSE
if(rv == -1)
return -errno;
fs::inode::calc(fi->branchpath,
fs::inode::calc(fi->branch.path,
fi->fusepath,
st_);

8
src/fuse_getattr.cpp

@ -105,13 +105,13 @@ namespace l
{
int rv;
string fullpath;
StrVec basepaths;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(branches[0]->path,fusepath_);
switch(followsymlinks_)
{
@ -141,7 +141,7 @@ namespace l
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_))
symlinkify::convert(fullpath,st_);
fs::inode::calc(basepaths[0],fusepath_,st_);
fs::inode::calc(branches[0]->path,fusepath_,st_);
return 0;
}

54
src/fuse_getxattr.cpp

@ -35,8 +35,6 @@
static const char SECURITY_CAPABILITY[] = "security.capability";
using std::string;
namespace l
{
@ -49,10 +47,10 @@ namespace l
static
int
lgetxattr(const string &path_,
const char *attrname_,
void *value_,
const size_t size_)
lgetxattr(const std::string &path_,
const char *attrname_,
void *value_,
const size_t size_)
{
int rv;
@ -70,8 +68,8 @@ namespace l
{
int rv;
size_t len;
string key;
string val;
std::string key;
std::string val;
StrVec attr;
if(!str::startswith(attrname_,"user.mergerfs."))
@ -97,9 +95,9 @@ namespace l
static
int
getxattr_from_string(char *destbuf_,
const size_t destbufsize_,
const string &src_)
getxattr_from_string(char *destbuf_,
const size_t destbufsize_,
const std::string &src_)
{
const size_t srcbufsize = src_.size();
@ -116,12 +114,12 @@ namespace l
static
int
getxattr_user_mergerfs_allpaths(const Branches::CPtr &branches_,
const char *fusepath_,
char *buf_,
const size_t count_)
getxattr_user_mergerfs_allpaths(const Branches::Ptr &branches_,
const char *fusepath_,
char *buf_,
const size_t count_)
{
string concated;
std::string concated;
StrVec paths;
StrVec branches;
@ -136,13 +134,13 @@ namespace l
static
int
getxattr_user_mergerfs(const string &basepath_,
const char *fusepath_,
const string &fullpath_,
const Branches &branches_,
const char *attrname_,
char *buf_,
const size_t count_)
getxattr_user_mergerfs(const std::string &basepath_,
const char *fusepath_,
const std::string &fullpath_,
const Branches &branches_,
const char *attrname_,
char *buf_,
const size_t count_)
{
StrVec attr;
@ -170,17 +168,17 @@ namespace l
const size_t count_)
{
int rv;
string fullpath;
StrVec basepaths;
std::string fullpath;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(branches[0]->path,fusepath_);
if(str::startswith(attrname_,"user.mergerfs."))
return l::getxattr_user_mergerfs(basepaths[0],
return l::getxattr_user_mergerfs(branches[0]->path,
fusepath_,
fullpath,
branches_,

2
src/fuse_init.cpp

@ -157,7 +157,7 @@ namespace l
set_readahead_on_mount_and_branches()
{
Config::Read cfg;
Branches::CPtr branches;
Branches::Ptr branches;
if((uint64_t)cfg->readahead == 0)
return;

32
src/fuse_ioctl.cpp

@ -34,9 +34,6 @@
#include <fcntl.h>
#include <string.h>
using std::string;
using std::vector;
#ifndef _IOC_TYPE
#define _IOC_TYPE(X) (((X) >> 8) & 0xFF)
#endif
@ -146,14 +143,14 @@ namespace l
{
int fd;
int rv;
string fullpath;
StrVec basepaths;
std::string fullpath;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(branches[0]->path,fusepath_);
fd = fs::open(fullpath,O_RDONLY|O_NOATIME|O_NONBLOCK);
if(fd == -1)
@ -210,13 +207,13 @@ namespace l
void *data_)
{
int rv;
StrVec basepaths;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::strcpy(basepaths[0],data_);
return l::strcpy(branches[0]->path,data_);
}
static
@ -246,19 +243,20 @@ namespace l
static
int
file_fullpath(const Policy::Search &searchFunc_,
const Branches &branches_,
const string &fusepath_,
const Branches &ibranches_,
const std::string &fusepath_,
void *data_)
{
int rv;
string fullpath;
StrVec basepaths;
std::string fullpath;
std::vector<Branch*> obranches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(ibranches_,fusepath_,obranches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(obranches[0]->path,fusepath_);
return l::strcpy(fullpath,data_);
}
@ -283,10 +281,10 @@ namespace l
void *data_)
{
Config::Read cfg;
string concated;
std::string concated;
StrVec paths;
StrVec branches;
string &fusepath = reinterpret_cast<FH*>(ffi_->fh)->fusepath;
std::string &fusepath = reinterpret_cast<FH*>(ffi_->fh)->fusepath;
cfg->branches->to_paths(branches);

78
src/fuse_link.cpp

@ -30,8 +30,6 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
namespace error
{
@ -57,27 +55,27 @@ namespace l
{
static
int
link_create_path_loop(const StrVec &oldbasepaths_,
const string &newbasepath_,
const char *oldfusepath_,
const char *newfusepath_,
const string &newfusedirpath_)
link_create_path_loop(const std::vector<Branch*> &oldbranches_,
const Branch *newbranch_,
const char *oldfusepath_,
const char *newfusepath_,
const std::string &newfusedirpath_)
{
int rv;
int error;
string oldfullpath;
string newfullpath;
std::string oldfullpath;
std::string newfullpath;
error = -1;
for(auto &oldbasepath : oldbasepaths_)
for(auto &oldbranch : oldbranches_)
{
oldfullpath = fs::path::make(oldbasepath,oldfusepath_);
newfullpath = fs::path::make(oldbasepath,newfusepath_);
oldfullpath = fs::path::make(oldbranch->path,oldfusepath_);
newfullpath = fs::path::make(oldbranch->path,newfusepath_);
rv = fs::link(oldfullpath,newfullpath);
if((rv == -1) && (errno == ENOENT))
{
rv = fs::clonepath_as_root(newbasepath_,oldbasepath,newfusedirpath_);
rv = fs::clonepath_as_root(newbranch_->path,oldbranch->path,newfusedirpath_);
if(rv == 0)
rv = fs::link(oldfullpath,newfullpath);
}
@ -92,41 +90,41 @@ namespace l
int
link_create_path(const Policy::Search &searchFunc_,
const Policy::Action &actionFunc_,
const Branches &branches_,
const Branches &ibranches_,
const char *oldfusepath_,
const char *newfusepath_)
{
int rv;
string newfusedirpath;
StrVec oldbasepaths;
StrVec newbasepaths;
std::string newfusedirpath;
std::vector<Branch*> oldbranches;
std::vector<Branch*> newbranches;
rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths);
rv = actionFunc_(ibranches_,oldfusepath_,oldbranches);
if(rv == -1)
return -errno;
newfusedirpath = fs::path::dirname(newfusepath_);
rv = searchFunc_(branches_,newfusedirpath,&newbasepaths);
rv = searchFunc_(ibranches_,newfusedirpath,newbranches);
if(rv == -1)
return -errno;
return l::link_create_path_loop(oldbasepaths,newbasepaths[0],
return l::link_create_path_loop(oldbranches,newbranches[0],
oldfusepath_,newfusepath_,
newfusedirpath);
}
static
int
link_preserve_path_core(const string &oldbasepath_,
const char *oldfusepath_,
const char *newfusepath_,
struct stat *st_,
const int error_)
link_preserve_path_core(const std::string &oldbasepath_,
const char *oldfusepath_,
const char *newfusepath_,
struct stat *st_,
const int error_)
{
int rv;
string oldfullpath;
string newfullpath;
std::string oldfullpath;
std::string newfullpath;
oldfullpath = fs::path::make(oldbasepath_,oldfusepath_);
newfullpath = fs::path::make(oldbasepath_,newfusepath_);
@ -142,17 +140,17 @@ namespace l
static
int
link_preserve_path_loop(const StrVec &oldbasepaths_,
const char *oldfusepath_,
const char *newfusepath_,
struct stat *st_)
link_preserve_path_loop(const std::vector<Branch*> &oldbranches_,
const char *oldfusepath_,
const char *newfusepath_,
struct stat *st_)
{
int error;
error = -1;
for(auto &oldbasepath : oldbasepaths_)
for(auto &oldbranch : oldbranches_)
{
error = l::link_preserve_path_core(oldbasepath,
error = l::link_preserve_path_core(oldbranch->path,
oldfusepath_,
newfusepath_,
st_,
@ -171,13 +169,13 @@ namespace l
struct stat *st_)
{
int rv;
StrVec oldbasepaths;
std::vector<Branch*> oldbranches;
rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths);
rv = actionFunc_(branches_,oldfusepath_,oldbranches);
if(rv == -1)
return -errno;
return l::link_preserve_path_loop(oldbasepaths,
return l::link_preserve_path_loop(oldbranches,
oldfusepath_,
newfusepath_,
st_);
@ -248,21 +246,21 @@ namespace l
static
int
link_exdev_abs_base_symlink(const Policy::Search &openPolicy_,
const Branches::CPtr &branches_,
const Branches::Ptr &ibranches_,
const char *oldpath_,
const char *newpath_,
struct stat *st_,
fuse_timeouts_t *timeouts_)
{
int rv;
StrVec basepaths;
std::string target;
std::vector<Branch*> obranches;
rv = openPolicy_(branches_,oldpath_,&basepaths);
rv = openPolicy_(ibranches_,oldpath_,obranches);
if(rv == -1)
return -errno;
target = fs::path::make(basepaths[0],oldpath_);
target = fs::path::make(obranches[0]->path,oldpath_);
rv = FUSE::symlink(target.c_str(),newpath_);
if(rv == 0)

10
src/fuse_listxattr.cpp

@ -56,20 +56,20 @@ namespace l
static
int
listxattr(const Policy::Search &searchFunc_,
const Branches &branches_,
const Branches &ibranches_,
const char *fusepath_,
char *list_,
const size_t size_)
{
int rv;
string fullpath;
StrVec basepaths;
std::string fullpath;
std::vector<Branch*> obranches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(ibranches_,fusepath_,obranches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(obranches[0]->path,fusepath_);
rv = fs::llistxattr(fullpath,list_,size_);

54
src/fuse_mkdir.cpp

@ -27,8 +27,6 @@
#include <string>
using std::string;
namespace error
{
@ -54,9 +52,9 @@ namespace l
{
static
int
mkdir_core(const string &fullpath_,
mode_t mode_,
const mode_t umask_)
mkdir_core(const std::string &fullpath_,
mode_t mode_,
const mode_t umask_)
{
if(!fs::acl::dir_has_defaults(fullpath_))
mode_ &= ~umask_;
@ -66,14 +64,14 @@ namespace l
static
int
mkdir_loop_core(const string &createpath_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
const int error_)
mkdir_loop_core(const std::string &createpath_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
const int error_)
{
int rv;
string fullpath;
std::string fullpath;
fullpath = fs::path::make(createpath_,fusepath_);
@ -84,24 +82,26 @@ namespace l
static
int
mkdir_loop(const string &existingpath_,
const StrVec &createpaths_,
const char *fusepath_,
const string &fusedirpath_,
const mode_t mode_,
const mode_t umask_)
mkdir_loop(const Branch *existingbranch_,
const std::vector<Branch*> &createbranches_,
const char *fusepath_,
const std::string &fusedirpath_,
const mode_t mode_,
const mode_t umask_)
{
int rv;
int error;
error = -1;
for(size_t i = 0, ei = createpaths_.size(); i != ei; i++)
for(auto &createbranch : createbranches_)
{
rv = fs::clonepath_as_root(existingpath_,createpaths_[i],fusedirpath_);
rv = fs::clonepath_as_root(existingbranch_->path,
createbranch->path,
fusedirpath_);
if(rv == -1)
error = error::calc(rv,error,errno);
else
error = l::mkdir_loop_core(createpaths_[i],
error = l::mkdir_loop_core(createbranch->path,
fusepath_,
mode_,
umask_,
@ -121,22 +121,22 @@ namespace l
const mode_t umask_)
{
int rv;
string fusedirpath;
StrVec createpaths;
StrVec existingpaths;
std::string fusedirpath;
std::vector<Branch*> createbranches;
std::vector<Branch*> existingbranches;
fusedirpath = fs::path::dirname(fusepath_);
rv = getattrPolicy_(branches_,fusedirpath.c_str(),&existingpaths);
rv = getattrPolicy_(branches_,fusedirpath,existingbranches);
if(rv == -1)
return -errno;
rv = mkdirPolicy_(branches_,fusedirpath.c_str(),&createpaths);
rv = mkdirPolicy_(branches_,fusedirpath,createbranches);
if(rv == -1)
return -errno;
return l::mkdir_loop(existingpaths[0],
createpaths,
return l::mkdir_loop(existingbranches[0],
createbranches,
fusepath_,
fusedirpath,
mode_,

69
src/fuse_mknod.cpp

@ -27,9 +27,6 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
namespace error
{
@ -56,10 +53,10 @@ namespace l
static
inline
int
mknod_core(const string &fullpath_,
mode_t mode_,
const mode_t umask_,
const dev_t dev_)
mknod_core(const std::string &fullpath_,
mode_t mode_,
const mode_t umask_,
const dev_t dev_)
{
if(!fs::acl::dir_has_defaults(fullpath_))
mode_ &= ~umask_;
@ -69,17 +66,17 @@ namespace l
static
int
mknod_loop_core(const string &createpath_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
const dev_t dev_,
const int error_)
mknod_loop_core(const std::string &createbranch_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
const dev_t dev_,
const int error_)
{
int rv;
string fullpath;
std::string fullpath;
fullpath = fs::path::make(createpath_,fusepath_);
fullpath = fs::path::make(createbranch_,fusepath_);
rv = l::mknod_core(fullpath,mode_,umask_,dev_);
@ -88,25 +85,27 @@ namespace l
static
int
mknod_loop(const string &existingpath_,
const vector<string> &createpaths_,
const char *fusepath_,
const string &fusedirpath_,
const mode_t mode_,
const mode_t umask_,
const dev_t dev_)
mknod_loop(const std::string &existingbranch_,
const std::vector<Branch*> &createbranches_,
const char *fusepath_,
const std::string &fusedirpath_,
const mode_t mode_,
const mode_t umask_,
const dev_t dev_)
{
int rv;
int error;
error = -1;
for(size_t i = 0, ei = createpaths_.size(); i != ei; i++)
for(auto &createbranch : createbranches_)
{
rv = fs::clonepath_as_root(existingpath_,createpaths_[i],fusedirpath_);
rv = fs::clonepath_as_root(existingbranch_,
createbranch->path,
fusedirpath_);
if(rv == -1)
error = error::calc(rv,error,errno);
else
error = l::mknod_loop_core(createpaths_[i],
error = l::mknod_loop_core(createbranch->path,
fusepath_,
mode_,umask_,dev_,error);
}
@ -125,23 +124,27 @@ namespace l
const dev_t dev_)
{
int rv;
string fusedirpath;
vector<string> createpaths;
vector<string> existingpaths;
std::string fusedirpath;
std::vector<Branch*> createbranches;
std::vector<Branch*> existingbranches;
fusedirpath = fs::path::dirname(fusepath_);
rv = searchFunc_(branches_,fusedirpath,&existingpaths);
rv = searchFunc_(branches_,fusedirpath,existingbranches);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,fusedirpath,&createpaths);
rv = createFunc_(branches_,fusedirpath,createbranches);
if(rv == -1)
return -errno;
return l::mknod_loop(existingpaths[0],createpaths,
fusepath_,fusedirpath,
mode_,umask_,dev_);
return l::mknod_loop(existingbranches[0]->path,
createbranches,
fusepath_,
fusedirpath,
mode_,
umask_,
dev_);
}
}

18
src/fuse_open.cpp

@ -190,7 +190,7 @@ namespace l
static
int
open_core(const std::string &basepath_,
open_core(const Branch *branch_,
const char *fusepath_,
fuse_file_info_t *ffi_,
const bool link_cow_,
@ -200,7 +200,7 @@ namespace l
FileInfo *fi;
std::string fullpath;
fullpath = fs::path::make(basepath_,fusepath_);
fullpath = fs::path::make(branch_->path,fusepath_);
if(link_cow_ && fs::cow::is_eligible(fullpath.c_str(),ffi_->flags))
fs::cow::break_link(fullpath.c_str());
@ -211,7 +211,7 @@ namespace l
if(fd == -1)
return -errno;
fi = new FileInfo(fd,basepath_,fusepath_,ffi_->direct_io);
fi = new FileInfo(fd,branch_,fusepath_,ffi_->direct_io);
ffi_->fh = reinterpret_cast<uint64_t>(fi);
@ -221,20 +221,24 @@ namespace l
static
int
open(const Policy::Search &searchFunc_,
const Branches &branches_,
const Branches &ibranches_,
const char *fusepath_,
fuse_file_info_t *ffi_,
const bool link_cow_,
const NFSOpenHack nfsopenhack_)
{
int rv;
StrVec basepaths;
std::vector<Branch*> obranches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(ibranches_,fusepath_,obranches);
if(rv == -1)
return -errno;
return l::open_core(basepaths[0],fusepath_,ffi_,link_cow_,nfsopenhack_);
return l::open_core(obranches[0],
fusepath_,
ffi_,
link_cow_,
nfsopenhack_);
}
}

12
src/fuse_readdir_cor.cpp

@ -141,12 +141,12 @@ namespace l
static
inline
int
concurrent_readdir(ThreadPool &tp_,
const Branches::CPtr &branches_,
const std::string &rel_dirpath_,
fuse_dirents_t *buf_,
const uid_t uid_,
const gid_t gid_)
concurrent_readdir(ThreadPool &tp_,
const Branches::Ptr &branches_,
const std::string &rel_dirpath_,
fuse_dirents_t *buf_,
const uid_t uid_,
const gid_t gid_)
{
HashSet names;
std::mutex mutex;

22
src/fuse_readdir_cosr.cpp

@ -97,11 +97,11 @@ namespace l
static
inline
std::vector<std::future<DirRV>>
opendir(ThreadPool &tp_,
const Branches::CPtr &branches_,
const std::string &rel_dirpath_,
uid_t const uid_,
gid_t const gid_)
opendir(ThreadPool &tp_,
const Branches::Ptr &branches_,
const std::string &rel_dirpath_,
uid_t const uid_,
gid_t const gid_)
{
std::vector<std::future<DirRV>> futures;
@ -187,12 +187,12 @@ namespace l
static
inline
int
readdir(ThreadPool &tp_,
const Branches::CPtr &branches_,
const std::string &rel_dirpath_,
fuse_dirents_t *buf_,
uid_t const uid_,
gid_t const gid_)
readdir(ThreadPool &tp_,
const Branches::Ptr &branches_,
const std::string &rel_dirpath_,
fuse_dirents_t *buf_,
uid_t const uid_,
gid_t const gid_)
{
int rv;
std::vector<std::future<DirRV>> futures;

6
src/fuse_readdir_seq.cpp

@ -83,9 +83,9 @@ namespace l
static
int
readdir(const Branches::CPtr &branches_,
const std::string &rel_dirpath_,
fuse_dirents_t *buf_)
readdir(const Branches::Ptr &branches_,
const std::string &rel_dirpath_,
fuse_dirents_t *buf_)
{
Error error;
HashSet names;

13
src/fuse_readlink.cpp

@ -93,7 +93,7 @@ namespace l
static
int
readlink(const Policy::Search &searchFunc_,
const Branches &branches_,
const Branches &ibranches_,
const char *fusepath_,
char *buf_,
const size_t size_,
@ -102,13 +102,18 @@ namespace l
{
int rv;
StrVec basepaths;
std::vector<Branch*> obranches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(ibranches_,fusepath_,obranches);
if(rv == -1)
return -errno;
return l::readlink_core(basepaths[0],fusepath_,buf_,size_,
symlinkify_,symlinkify_timeout_);
return l::readlink_core(obranches[0]->path,
fusepath_,
buf_,
size_,
symlinkify_,
symlinkify_timeout_);
}
}

52
src/fuse_removexattr.cpp

@ -32,26 +32,6 @@ using std::vector;
namespace l
{
static
int
get_error(const PolicyRV &prv_,
const string &basepath_)
{
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
{
if(prv_.success[i].basepath == basepath_)
return prv_.success[i].rv;
}
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
{
if(prv_.error[i].basepath == basepath_)
return prv_.error[i].rv;
}
return 0;
}
static
void
removexattr_loop_core(const string &basepath_,
@ -71,14 +51,14 @@ namespace l
static
void
removexattr_loop(const vector<string> &basepaths_,
const char *fusepath_,
const char *attrname_,
PolicyRV *prv_)
removexattr_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const char *attrname_,
PolicyRV *prv_)
{
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
l::removexattr_loop_core(basepaths_[i],fusepath_,attrname_,prv_);
l::removexattr_loop_core(branch->path,fusepath_,attrname_,prv_);
}
}
@ -86,30 +66,30 @@ namespace l
int
removexattr(const Policy::Action &actionFunc_,
const Policy::Search &searchFunc_,
const Branches &branches_,
const Branches &ibranches_,
const char *fusepath_,
const char *attrname_)
{
int rv;
PolicyRV prv;
vector<string> basepaths;
std::vector<Branch*> obranches;
rv = actionFunc_(branches_,fusepath_,&basepaths);
rv = actionFunc_(ibranches_,fusepath_,obranches);
if(rv == -1)
return -errno;
l::removexattr_loop(basepaths,fusepath_,attrname_,&prv);
if(prv.error.empty())
l::removexattr_loop(obranches,fusepath_,attrname_,&prv);
if(prv.errors.empty())
return 0;
if(prv.success.empty())
return prv.error[0].rv;
if(prv.successes.empty())
return prv.errors[0].rv;
basepaths.clear();
rv = searchFunc_(branches_,fusepath_,&basepaths);
obranches.clear();
rv = searchFunc_(ibranches_,fusepath_,obranches);
if(rv == -1)
return -errno;
return l::get_error(prv,basepaths[0]);
return prv.get_error(obranches[0]->path);
}
}

89
src/fuse_rename.cpp

@ -35,7 +35,6 @@
#include <iostream>
using std::string;
namespace gfs = ghc::filesystem;
namespace error
@ -62,12 +61,12 @@ namespace l
{
static
bool
contains(const StrVec &haystack_,
const char *needle_)
contains(const std::vector<Branch*> &haystack_,
const char *needle_)
{
for(auto &hay : haystack_)
{
if(hay == needle_)
if(hay->path == needle_)
return true;
}
@ -76,8 +75,8 @@ namespace l
static
bool
contains(const StrVec &haystack_,
const string &needle_)
contains(const std::vector<Branch*> &haystack_,
const std::string &needle_)
{
return l::contains(haystack_,needle_.c_str());
}
@ -90,41 +89,27 @@ namespace l
fs::remove(path);
}
static
void
remove(const Branches::CPtr &branches_,
const std::string &relpath_)
{
std::string fullpath;
for(auto &branch : *branches_)
{
fullpath = fs::path::make(branch.path,relpath_);
fs::remove(fullpath);
}
}
static
int
rename_create_path(const Policy::Search &searchPolicy_,
const Policy::Action &actionPolicy_,
const Branches::CPtr &branches_,
const Branches::Ptr &branches_,
const gfs::path &oldfusepath_,
const gfs::path &newfusepath_)
{
int rv;
int error;
StrVec toremove;
StrVec newbasepath;
StrVec oldbasepaths;
std::vector<Branch*> newbranches;
std::vector<Branch*> oldbranches;
gfs::path oldfullpath;
gfs::path newfullpath;
rv = actionPolicy_(branches_,oldfusepath_,&oldbasepaths);
rv = actionPolicy_(branches_,oldfusepath_,oldbranches);
if(rv == -1)
return -errno;
rv = searchPolicy_(branches_,newfusepath_.parent_path(),&newbasepath);
rv = searchPolicy_(branches_,newfusepath_.parent_path(),newbranches);
if(rv == -1)
return -errno;
@ -134,7 +119,7 @@ namespace l
newfullpath = branch.path;
newfullpath += newfusepath_;
if(!l::contains(oldbasepaths,branch.path))
if(!l::contains(oldbranches,branch.path))
{
toremove.push_back(newfullpath);
continue;
@ -146,7 +131,9 @@ namespace l
rv = fs::rename(oldfullpath,newfullpath);
if(rv == -1)
{
rv = fs::clonepath_as_root(newbasepath[0],branch.path,newfusepath_.parent_path());
rv = fs::clonepath_as_root(newbranches[0]->path,
branch.path,
newfusepath_.parent_path());
if(rv == 0)
rv = fs::rename(oldfullpath,newfullpath);
}
@ -165,18 +152,18 @@ namespace l
static
int
rename_preserve_path(const Policy::Action &actionPolicy_,
const Branches::CPtr &branches_,
const Branches::Ptr &branches_,
const gfs::path &oldfusepath_,
const gfs::path &newfusepath_)
{
int rv;
bool success;
StrVec toremove;
StrVec oldbasepaths;
std::vector<Branch*> oldbranches;
gfs::path oldfullpath;
gfs::path newfullpath;
rv = actionPolicy_(branches_,oldfusepath_,&oldbasepaths);
rv = actionPolicy_(branches_,oldfusepath_,oldbranches);
if(rv == -1)
return -errno;
@ -186,7 +173,7 @@ namespace l
newfullpath = branch.path;
newfullpath += newfusepath_;
if(!l::contains(oldbasepaths,branch.path))
if(!l::contains(oldbranches,branch.path))
{
toremove.push_back(newfullpath);
continue;
@ -216,19 +203,19 @@ namespace l
static
void
rename_exdev_rename_back(const StrVec &basepaths_,
const gfs::path &oldfusepath_)
rename_exdev_rename_back(const std::vector<Branch*> &branches_,
const gfs::path &oldfusepath_)
{
gfs::path oldpath;
gfs::path newpath;
for(auto &basepath : basepaths_)
for(auto &branch : branches_)
{
oldpath = basepath;
oldpath = branch->path;
oldpath /= ".mergerfs_rename_exdev";
oldpath += oldfusepath_;
newpath = basepath;
newpath = branch->path;
newpath += oldfusepath_;
fs::rename(oldpath,newpath);
@ -238,23 +225,23 @@ namespace l
static
int
rename_exdev_rename_target(const Policy::Action &actionPolicy_,
const Branches::CPtr &branches_,
const Branches::Ptr &ibranches_,
const gfs::path &oldfusepath_,
StrVec *basepaths_)
std::vector<Branch*> &obranches_)
{
int rv;
gfs::path clonesrc;
gfs::path clonetgt;
rv = actionPolicy_(branches_,oldfusepath_,basepaths_);
rv = actionPolicy_(ibranches_,oldfusepath_,obranches_);
if(rv == -1)
return -errno;
ugid::SetRootGuard ugidGuard;
for(auto &basepath : *basepaths_)
for(auto &branch : obranches_)
{
clonesrc = basepath;
clonetgt = basepath;
clonesrc = branch->path;
clonetgt = branch->path;
clonetgt /= ".mergerfs_rename_exdev";
rv = fs::clonepath(clonesrc,clonetgt,oldfusepath_.parent_path());
@ -278,7 +265,7 @@ namespace l
return 0;
error:
l::rename_exdev_rename_back(*basepaths_,oldfusepath_);
l::rename_exdev_rename_back(obranches_,oldfusepath_);
return -EXDEV;
}
@ -286,16 +273,16 @@ namespace l
static
int
rename_exdev_rel_symlink(const Policy::Action &actionPolicy_,
const Branches::CPtr &branches_,
const Branches::Ptr &branches_,
const gfs::path &oldfusepath_,
const gfs::path &newfusepath_)
{
int rv;
StrVec basepaths;
gfs::path target;
gfs::path linkpath;
std::vector<Branch*> branches;
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,&basepaths);
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches);
if(rv < 0)
return rv;
@ -306,7 +293,7 @@ namespace l
rv = FUSE::symlink(target.c_str(),linkpath.c_str());
if(rv < 0)
l::rename_exdev_rename_back(basepaths,oldfusepath_);
l::rename_exdev_rename_back(branches,oldfusepath_);
return rv;
}
@ -314,17 +301,17 @@ namespace l
static
int
rename_exdev_abs_symlink(const Policy::Action &actionPolicy_,
const Branches::CPtr &branches_,
const Branches::Ptr &branches_,
const gfs::path &mount_,
const gfs::path &oldfusepath_,
const gfs::path &newfusepath_)
{
int rv;
StrVec basepaths;
gfs::path target;
gfs::path linkpath;
std::vector<Branch*> branches;
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,&basepaths);
rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches);
if(rv < 0)
return rv;
@ -335,7 +322,7 @@ namespace l
rv = FUSE::symlink(target.c_str(),linkpath.c_str());
if(rv < 0)
l::rename_exdev_rename_back(basepaths,oldfusepath_);
l::rename_exdev_rename_back(branches,oldfusepath_);
return rv;
}

16
src/fuse_rmdir.cpp

@ -81,16 +81,16 @@ namespace l
static
int
rmdir_loop(const StrVec &basepaths_,
const char *fusepath_,
const FollowSymlinks followsymlinks_)
rmdir_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const FollowSymlinks followsymlinks_)
{
int error;
error = 0;
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
error = l::rmdir_core(basepaths_[i],fusepath_,followsymlinks_,error);
error = l::rmdir_core(branch->path,fusepath_,followsymlinks_,error);
}
return -error;
@ -104,13 +104,13 @@ namespace l
const char *fusepath_)
{
int rv;
vector<string> basepaths;
std::vector<Branch*> branches;
rv = actionFunc_(branches_,fusepath_,&basepaths);
rv = actionFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::rmdir_loop(basepaths,fusepath_,followsymlinks_);
return l::rmdir_loop(branches,fusepath_,followsymlinks_);
}
}

63
src/fuse_setxattr.cpp

@ -40,26 +40,6 @@ using std::vector;
namespace l
{
static
int
get_error(const PolicyRV &prv_,
const string &basepath_)
{
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
{
if(prv_.success[i].basepath == basepath_)
return prv_.success[i].rv;
}
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
{
if(prv_.error[i].basepath == basepath_)
return prv_.error[i].rv;
}
return 0;
}
static
bool
is_attrname_security_capability(const char *attrname_)
@ -119,19 +99,22 @@ namespace l
static
void
setxattr_loop(const StrVec &basepaths_,
const char *fusepath_,
const char *attrname_,
const char *attrval_,
const size_t attrvalsize_,
const int flags_,
PolicyRV *prv_)
setxattr_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const char *attrname_,
const char *attrval_,
const size_t attrvalsize_,
const int flags_,
PolicyRV *prv_)
{
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
l::setxattr_loop_core(basepaths_[i],fusepath_,
attrname_,attrval_,attrvalsize_,
flags_,prv_);
l::setxattr_loop_core(branch->path,
fusepath_,
attrname_,
attrval_,attrvalsize_,
flags_,
prv_);
}
}
@ -148,24 +131,24 @@ namespace l
{
int rv;
PolicyRV prv;
StrVec basepaths;
std::vector<Branch*> branches;
rv = setxattrPolicy_(branches_,fusepath_,&basepaths);
rv = setxattrPolicy_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
l::setxattr_loop(basepaths,fusepath_,attrname_,attrval_,attrvalsize_,flags_,&prv);
if(prv.error.empty())
l::setxattr_loop(branches,fusepath_,attrname_,attrval_,attrvalsize_,flags_,&prv);
if(prv.errors.empty())
return 0;
if(prv.success.empty())
return prv.error[0].rv;
if(prv.successes.empty())
return prv.errors[0].rv;
basepaths.clear();
rv = getxattrPolicy_(branches_,fusepath_,&basepaths);
branches.clear();
rv = getxattrPolicy_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::get_error(prv,basepaths[0]);
return prv.get_error(branches[0]->path);
}
int

10
src/fuse_statfs.cpp

@ -79,11 +79,11 @@ namespace l
static
int
statfs(const Branches::CPtr &branches_,
const char *fusepath_,
const StatFS mode_,
const StatFSIgnore ignore_,
struct statvfs *fsstat_)
statfs(const Branches::Ptr &branches_,
const char *fusepath_,
const StatFS mode_,
const StatFSIgnore ignore_,
struct statvfs *fsstat_)
{
int rv;
string fullpath;

8
src/fuse_statx_supported.icpp

@ -88,13 +88,13 @@ _statx(const Policy::Search &searchFunc_,
{
int rv;
std::string fullpath;
StrVec basepaths;
std::vector<Branch*> branches;
rv = searchFunc_(branches_,fusepath_,&basepaths);
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
fullpath = fs::path::make(basepaths[0],fusepath_);
fullpath = fs::path::make(branches[0]->path,fusepath_);
switch(followsymlinks_)
{
@ -124,7 +124,7 @@ _statx(const Policy::Search &searchFunc_,
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_))
symlinkify::convert(fullpath,st_);
fs::inode::calc(basepaths[0],fusepath_,st_);
fs::inode::calc(branches[0]->path,fusepath_,st_);
return 0;
}

50
src/fuse_symlink.cpp

@ -58,23 +58,23 @@ namespace l
{
static
int
symlink_loop_core(const string &newbasepath_,
const char *target_,
const char *linkpath_,
struct stat *st_,
const int error_)
symlink_loop_core(const std::string &newbranch_,
const char *target_,
const char *linkpath_,
struct stat *st_,
const int error_)
{
int rv;
string fullnewpath;
fullnewpath = fs::path::make(newbasepath_,linkpath_);
fullnewpath = fs::path::make(newbranch_,linkpath_);
rv = fs::symlink(target_,fullnewpath);
if((rv != -1) && (st_ != NULL) && (st_->st_ino == 0))
{
fs::lstat(fullnewpath,st_);
if(st_->st_ino != 0)
fs::inode::calc(newbasepath_,linkpath_,st_);
fs::inode::calc(newbranch_,linkpath_,st_);
}
return error::calc(rv,error_,errno);
@ -82,24 +82,26 @@ namespace l
static
int
symlink_loop(const string &existingpath_,
const StrVec &newbasepaths_,
const char *target_,
const char *linkpath_,
const string &newdirpath_,
struct stat *st_)
symlink_loop(const std::string &existingbranch_,
const std::vector<Branch*> &newbranches_,
const char *target_,
const char *linkpath_,
const std::string &newdirpath_,
struct stat *st_)
{
int rv;
int error;
error = -1;
for(size_t i = 0, ei = newbasepaths_.size(); i != ei; i++)
for(auto &newbranch :newbranches_)
{
rv = fs::clonepath_as_root(existingpath_,newbasepaths_[i],newdirpath_);
rv = fs::clonepath_as_root(existingbranch_,
newbranch->path,
newdirpath_);
if(rv == -1)
error = error::calc(rv,error,errno);
else
error = l::symlink_loop_core(newbasepaths_[i],
error = l::symlink_loop_core(newbranch->path,
target_,
linkpath_,
st_,
@ -120,21 +122,25 @@ namespace l
{
int rv;
string newdirpath;
StrVec newbasepaths;
StrVec existingpaths;
std::vector<Branch*> newbranches;
std::vector<Branch*> existingbranches;
newdirpath = fs::path::dirname(linkpath_);
rv = searchFunc_(branches_,newdirpath,&existingpaths);
rv = searchFunc_(branches_,newdirpath,existingbranches);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,newdirpath,&newbasepaths);
rv = createFunc_(branches_,newdirpath,newbranches);
if(rv == -1)
return -errno;
return l::symlink_loop(existingpaths[0],newbasepaths,
target_,linkpath_,newdirpath,st_);
return l::symlink_loop(existingbranches[0]->path,
newbranches,
target_,
linkpath_,
newdirpath,
st_);
}
}

50
src/fuse_truncate.cpp

@ -33,26 +33,6 @@ using std::string;
namespace l
{
static
int
get_error(const PolicyRV &prv_,
const string &basepath_)
{
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
{
if(prv_.success[i].basepath == basepath_)
return prv_.success[i].rv;
}
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
{
if(prv_.error[i].basepath == basepath_)
return prv_.error[i].rv;
}
return 0;
}
static
void
truncate_loop_core(const string &basepath_,
@ -72,14 +52,14 @@ namespace l
static
void
truncate_loop(const StrVec &basepaths_,
const char *fusepath_,
const off_t size_,
PolicyRV *prv_)
truncate_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const off_t size_,
PolicyRV *prv_)
{
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
l::truncate_loop_core(basepaths_[i],fusepath_,size_,prv_);
l::truncate_loop_core(branch->path,fusepath_,size_,prv_);
}
}
@ -93,24 +73,24 @@ namespace l
{
int rv;
PolicyRV prv;
StrVec basepaths;
std::vector<Branch*> branches;
rv = actionFunc_(branches_,fusepath_,&basepaths);
rv = actionFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
l::truncate_loop(basepaths,fusepath_,size_,&prv);
if(prv.error.empty())
l::truncate_loop(branches,fusepath_,size_,&prv);
if(prv.errors.empty())
return 0;
if(prv.success.empty())
return prv.error[0].rv;
if(prv.successes.empty())
return prv.errors[0].rv;
basepaths.clear();
rv = searchFunc_(branches_,fusepath_,&basepaths);
branches.clear();
rv = searchFunc_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::get_error(prv,basepaths[0]);
return prv.get_error(branches[0]->path);
}
}

27
src/fuse_unlink.cpp

@ -27,9 +27,6 @@
#include <unistd.h>
using std::string;
using std::vector;
namespace error
{
@ -52,14 +49,14 @@ namespace l
{
static
int
unlink_loop_core(const string &basepath_,
const char *fusepath_,
const int error_)
unlink_loop_core(const std::string &branch_,
const char *fusepath_,
const int error_)
{
int rv;
string fullpath;
std::string fullpath;
fullpath = fs::path::make(basepath_,fusepath_);
fullpath = fs::path::make(branch_,fusepath_);
rv = fs::unlink(fullpath);
@ -68,15 +65,15 @@ namespace l
static
int
unlink_loop(const vector<string> &basepaths_,
const char *fusepath_)
unlink_loop(const std::vector<Branch*> &branches_,
const char *fusepath_)
{
int error;
error = 0;
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
error = l::unlink_loop_core(basepaths_[i],fusepath_,error);
error = l::unlink_loop_core(branch->path,fusepath_,error);
}
return -error;
@ -89,13 +86,13 @@ namespace l
const char *fusepath_)
{
int rv;
vector<string> basepaths;
std::vector<Branch*> branches;
rv = unlinkPolicy_(branches_,fusepath_,&basepaths);
rv = unlinkPolicy_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::unlink_loop(basepaths,fusepath_);
return l::unlink_loop(branches,fusepath_);
}
}

50
src/fuse_utimens.cpp

@ -32,26 +32,6 @@ using std::string;
namespace l
{
static
int
get_error(const PolicyRV &prv_,
const string &basepath_)
{
for(int i = 0, ei = prv_.success.size(); i < ei; i++)
{
if(prv_.success[i].basepath == basepath_)
return prv_.success[i].rv;
}
for(int i = 0, ei = prv_.error.size(); i < ei; i++)
{
if(prv_.error[i].basepath == basepath_)
return prv_.error[i].rv;
}
return 0;
}
static
void
utimens_loop_core(const string &basepath_,
@ -71,14 +51,14 @@ namespace l
static
void
utimens_loop(const StrVec &basepaths_,
const char *fusepath_,
const timespec ts_[2],
PolicyRV *prv_)
utimens_loop(const std::vector<Branch*> &branches_,
const char *fusepath_,
const timespec ts_[2],
PolicyRV *prv_)
{
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
for(auto &branch : branches_)
{
l::utimens_loop_core(basepaths_[i],fusepath_,ts_,prv_);
l::utimens_loop_core(branch->path,fusepath_,ts_,prv_);
}
}
@ -92,24 +72,24 @@ namespace l
{
int rv;
PolicyRV prv;
StrVec basepaths;
std::vector<Branch*> branches;
rv = utimensPolicy_(branches_,fusepath_,&basepaths);
rv = utimensPolicy_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
l::utimens_loop(basepaths,fusepath_,ts_,&prv);
if(prv.error.empty())
l::utimens_loop(branches,fusepath_,ts_,&prv);
if(prv.errors.empty())
return 0;
if(prv.success.empty())
return prv.error[0].rv;
if(prv.successes.empty())
return prv.errors[0].rv;
basepaths.clear();
rv = getattrPolicy_(branches_,fusepath_,&basepaths);
branches.clear();
rv = getattrPolicy_(branches_,fusepath_,branches);
if(rv == -1)
return -errno;
return l::get_error(prv,basepaths[0]);
return prv.get_error(branches[0]->path);
}
}

13
src/int_types.h

@ -0,0 +1,13 @@
#pragma once
#include <stdint.h>
typedef uint64_t u32;
typedef int64_t s32;
typedef uint64_t u64;
typedef int64_t s64;
typedef const uint64_t cu32;
typedef const int64_t cs32;
typedef const uint64_t cu64;
typedef const int64_t cs64;

1847
src/nonstd/optional.hpp
File diff suppressed because it is too large
View File

53
src/policy.hpp

@ -20,6 +20,9 @@
#include "strvec.hpp"
#include <string>
#include <memory>
#include <vector>
namespace Policy
{
@ -33,7 +36,9 @@ namespace Policy
public:
std::string name;
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0;
virtual int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const = 0;
};
class Action
@ -58,19 +63,19 @@ namespace Policy
}
int
operator()(const Branches::CPtr &branches_,
const char *fusepath_,
StrVec *paths_) const
operator()(const Branches::Ptr &branches_,
const char *fusepath_,
std::vector<Branch*> &output_) const
{
return (*impl)(branches_,fusepath_,paths_);
return (*impl)(branches_,fusepath_,output_);
}
int
operator()(const Branches::CPtr &branches_,
operator()(const Branches::Ptr &branches_,
const std::string &fusepath_,
StrVec *paths_) const
std::vector<Branch*> &output_) const
{
return (*impl)(branches_,fusepath_.c_str(),paths_);
return (*impl)(branches_,fusepath_.c_str(),output_);
}
operator bool() const
@ -92,8 +97,10 @@ namespace Policy
public:
std::string name;
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0;
virtual bool path_preserving(void) const = 0;
virtual int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const = 0;
};
class Create
@ -124,19 +131,19 @@ namespace Policy
}
int
operator()(const Branches::CPtr &branches_,
operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &output_) const
{
return (*impl)(branches_,fusepath_,paths_);
return (*impl)(branches_,fusepath_,output_);
}
int
operator()(const Branches::CPtr &branches_,
operator()(const Branches::Ptr &branches_,
const std::string &fusepath_,
StrVec *paths_) const
std::vector<Branch*> &output_) const
{
return (*impl)(branches_,fusepath_.c_str(),paths_);
return (*impl)(branches_,fusepath_.c_str(),output_);
}
operator bool() const
@ -158,7 +165,9 @@ namespace Policy
public:
std::string name;
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0;
virtual int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const = 0;
};
class Search
@ -183,19 +192,19 @@ namespace Policy
}
int
operator()(const Branches::CPtr &branches_,
operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &output_) const
{
return (*impl)(branches_,fusepath_,paths_);
return (*impl)(branches_,fusepath_,output_);
}
int
operator()(const Branches::CPtr &branches_,
operator()(const Branches::Ptr &branches_,
const std::string &fusepath_,
StrVec *paths_) const
std::vector<Branch*> &output_) const
{
return (*impl)(branches_,fusepath_.c_str(),paths_);
return (*impl)(branches_,fusepath_.c_str(),output_);
}
operator bool() const

28
src/policy_all.cpp

@ -31,15 +31,15 @@ namespace all
{
static
int
create(const Branches::CPtr &branches_,
StrVec *paths_)
create(const Branches::Ptr &ibranches_,
std::vector<Branch*> &obranches_)
{
int rv;
int error;
fs::info_t info;
error = ENOENT;
for(auto &branch : *branches_)
for(auto &branch : *ibranches_)
{
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
@ -51,10 +51,10 @@ namespace all
if(info.spaceavail < branch.minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch.path);
obranches_.push_back(&branch);
}
if(paths_->empty())
if(obranches_.empty())
return (errno=error,-1);
return 0;
@ -62,25 +62,25 @@ namespace all
}
int
Policy::All::Action::operator()(const Branches::CPtr &branches_,
Policy::All::Action::operator()(const Branches::Ptr &ibranches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &obranches_) const
{
return Policies::Action::epall(branches_,fusepath_,paths_);
return Policies::Action::epall(ibranches_,fusepath_,obranches_);
}
int
Policy::All::Create::operator()(const Branches::CPtr &branches_,
Policy::All::Create::operator()(const Branches::Ptr &ibranches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &obranches_) const
{
return ::all::create(branches_,paths_);
return ::all::create(ibranches_,obranches_);
}
int
Policy::All::Search::operator()(const Branches::CPtr &branches_,
Policy::All::Search::operator()(const Branches::Ptr &ibranches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &obranches_) const
{
return Policies::Search::epall(branches_,fusepath_,paths_);
return Policies::Search::epall(ibranches_,fusepath_,obranches_);
}

12
src/policy_all.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

6
src/policy_cache.cpp

@ -94,7 +94,7 @@ int
PolicyCache::operator()(const Policy::Search &policy_,
const Branches &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
Value *v;
@ -118,11 +118,11 @@ PolicyCache::operator()(const Policy::Search &policy_,
pthread_mutex_lock(&_lock);
v->time = now;
v->paths = *paths_;
v->paths = paths_;
}
else
{
*paths_ = v->paths;
paths_ = v->paths;
}
pthread_mutex_unlock(&_lock);

5
src/policy_cache.hpp

@ -19,7 +19,6 @@
#pragma once
#include "policy.hpp"
#include "strvec.hpp"
#include <cstdint>
#include <string>
@ -36,7 +35,7 @@ public:
Value();
uint64_t time;
StrVec paths;
std::vector<Branch*> paths;
};
public:
@ -51,7 +50,7 @@ public:
int operator()(const Policy::Search &policy,
const Branches &branches,
const char *fusepath,
StrVec *paths);
std::vector<Branch*> &paths);
public:
uint64_t timeout;

38
src/policy_epall.cpp

@ -33,9 +33,9 @@ namespace epall
{
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
@ -56,10 +56,10 @@ namespace epall
if(info.spaceavail < branch.minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch.path);
paths_.emplace_back(&branch);
}
if(paths_->empty())
if(paths_.empty())
return (errno=error,-1);
return 0;
@ -67,9 +67,9 @@ namespace epall
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
@ -88,10 +88,10 @@ namespace epall
if(readonly)
error_and_continue(error,EROFS);
paths_->push_back(branch.path);
paths_.emplace_back(&branch);
}
if(paths_->empty())
if(paths_.empty())
return (errno=error,-1);
return 0;
@ -99,19 +99,19 @@ namespace epall
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_))
continue;
paths_->push_back(branch.path);
paths_.push_back(&branch);
}
if(paths_->empty())
if(paths_.empty())
return (errno=ENOENT,-1);
return 0;
@ -119,25 +119,25 @@ namespace epall
}
int
Policy::EPAll::Action::operator()(const Branches::CPtr &branches_,
Policy::EPAll::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epall::action(branches_,fusepath_,paths_);
}
int
Policy::EPAll::Create::operator()(const Branches::CPtr &branches_,
Policy::EPAll::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epall::create(branches_,fusepath_,paths_);
}
int
Policy::EPAll::Search::operator()(const Branches::CPtr &branches_,
const char *fusepath_,
StrVec *paths_) const
Policy::EPAll::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
std::vector<Branch*> &paths_) const
{
return ::epall::search(branches_,fusepath_,paths_);
}

12
src/policy_epall.hpp

@ -33,7 +33,9 @@ namespace Policy
}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -45,7 +47,9 @@ namespace Policy
}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -58,7 +62,9 @@ namespace Policy
}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

32
src/policy_epff.cpp

@ -35,9 +35,9 @@ namespace epff
{
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
@ -58,7 +58,7 @@ namespace epff
if(info.spaceavail < branch.minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch.path);
paths_.push_back(&branch);
return 0;
}
@ -68,9 +68,9 @@ namespace epff
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
@ -89,7 +89,7 @@ namespace epff
if(readonly)
error_and_continue(error,EROFS);
paths_->push_back(branch.path);
paths_.push_back(&branch);
return 0;
}
@ -99,16 +99,16 @@ namespace epff
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_))
continue;
paths_->push_back(branch.path);
paths_.push_back(&branch);
return 0;
}
@ -118,25 +118,25 @@ namespace epff
}
int
Policy::EPFF::Action::operator()(const Branches::CPtr &branches_,
const char *fusepath_,
StrVec *paths_) const
Policy::EPFF::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
std::vector<Branch*> &paths_) const
{
return ::epff::action(branches_,fusepath_,paths_);
}
int
Policy::EPFF::Create::operator()(const Branches::CPtr &branches_,
Policy::EPFF::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epff::create(branches_,fusepath_,paths_);
}
int
Policy::EPFF::Search::operator()(const Branches::CPtr &branches_,
Policy::EPFF::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epff::search(branches_,fusepath_,paths_);
}

12
src/policy_epff.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

60
src/policy_eplfs.cpp

@ -35,20 +35,20 @@ namespace eplfs
{
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t eplfs;
Branch *obranch;
fs::info_t info;
const string *basepath;
obranch = nullptr;
error = ENOENT;
eplfs = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
@ -65,33 +65,33 @@ namespace eplfs
continue;
eplfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t eplfs;
Branch *obranch;
fs::info_t info;
const string *basepath;
obranch = nullptr;
error = ENOENT;
eplfs = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro())
error_and_continue(error,EROFS);
@ -106,31 +106,31 @@ namespace eplfs
continue;
eplfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
uint64_t eplfs;
uint64_t spaceavail;
const string *basepath;
Branch *obranch;
obranch = nullptr;
eplfs = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_))
continue;
@ -141,38 +141,38 @@ namespace eplfs
continue;
eplfs = spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=ENOENT,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
}
int
Policy::EPLFS::Action::operator()(const Branches::CPtr &branches_,
Policy::EPLFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eplfs::action(branches_,fusepath_,paths_);
}
int
Policy::EPLFS::Create::operator()(const Branches::CPtr &branches_,
Policy::EPLFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eplfs::create(branches_,fusepath_,paths_);
}
int
Policy::EPLFS::Search::operator()(const Branches::CPtr &branches_,
Policy::EPLFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eplfs::search(branches_,fusepath_,paths_);
}

12
src/policy_eplfs.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

56
src/policy_eplus.cpp

@ -33,19 +33,19 @@ namespace eplus
{
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t eplus;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
eplus = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
@ -63,32 +63,32 @@ namespace eplus
continue;
eplus = info.spaceused;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t eplus;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
eplus = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(auto &branch : *branches_)
{
if(branch.ro())
@ -104,30 +104,30 @@ namespace eplus
continue;
eplus = info.spaceused;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
uint64_t eplus;
uint64_t spaceused;
const string *basepath;
Branch *obranch;
obranch = nullptr;
eplus = 0;
basepath = NULL;
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_))
@ -139,38 +139,38 @@ namespace eplus
continue;
eplus = spaceused;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=ENOENT,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
}
int
Policy::EPLUS::Action::operator()(const Branches::CPtr &branches_,
const char *fusepath_,
StrVec *paths_) const
Policy::EPLUS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
std::vector<Branch*> &paths_) const
{
return ::eplus::action(branches_,fusepath_,paths_);
}
int
Policy::EPLUS::Create::operator()(const Branches::CPtr &branches_,
Policy::EPLUS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eplus::create(branches_,fusepath_,paths_);
}
int
Policy::EPLUS::Search::operator()(const Branches::CPtr &branches_,
Policy::EPLUS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eplus::search(branches_,fusepath_,paths_);
}

12
src/policy_eplus.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

60
src/policy_epmfs.cpp

@ -34,20 +34,20 @@ namespace epmfs
{
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t epmfs;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
epmfs = std::numeric_limits<uint64_t>::min();
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
@ -64,33 +64,33 @@ namespace epmfs
continue;
epmfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t epmfs;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
epmfs = std::numeric_limits<uint64_t>::min();
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro())
error_and_continue(error,EROFS);
@ -105,31 +105,31 @@ namespace epmfs
continue;
epmfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
uint64_t epmfs;
uint64_t spaceavail;
const string *basepath;
Branch *obranch;
obranch = nullptr;
epmfs = 0;
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_))
continue;
@ -140,38 +140,38 @@ namespace epmfs
continue;
epmfs = spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(obranch == nullptr)
return (errno=ENOENT,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
}
int
Policy::EPMFS::Action::operator()(const Branches::CPtr &branches_,
Policy::EPMFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epmfs::action(branches_,fusepath_,paths_);
}
int
Policy::EPMFS::Create::operator()(const Branches::CPtr &branches_,
Policy::EPMFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epmfs::create(branches_,fusepath_,paths_);
}
int
Policy::EPMFS::Search::operator()(const Branches::CPtr &branches_,
Policy::EPMFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::epmfs::search(branches_,fusepath_,paths_);
}

12
src/policy_epmfs.hpp

@ -33,7 +33,9 @@ namespace Policy
}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -45,7 +47,9 @@ namespace Policy
}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -58,7 +62,9 @@ namespace Policy
}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

107
src/policy_eppfrd.cpp

@ -29,29 +29,25 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
struct BranchInfo
{
uint64_t spaceavail;
const string *basepath;
u64 spaceavail;
Branch *branch;
};
typedef vector<BranchInfo> BranchInfoVec;
typedef std::vector<BranchInfo> BranchInfoVec;
namespace eppfrd
{
static
int
get_branchinfo_create(const Branches::CPtr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo_create(const Branches::Ptr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
*sum_ = 0;
@ -72,9 +68,7 @@ namespace eppfrd
*sum_ += info.spaceavail;
bi.spaceavail = info.spaceavail;
bi.basepath = &branch.path;
branchinfo_->push_back(bi);
branchinfo_->push_back({info.spaceavail,&branch});
}
return error;
@ -82,14 +76,13 @@ namespace eppfrd
static
int
get_branchinfo_action(const Branches::CPtr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo_action(const Branches::Ptr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
*sum_ = 0;
@ -108,9 +101,7 @@ namespace eppfrd
*sum_ += info.spaceavail;
bi.spaceavail = info.spaceavail;
bi.basepath = &branch.path;
branchinfo_->push_back(bi);
branchinfo_->push_back({info.spaceavail,&branch});
}
return error;
@ -118,13 +109,12 @@ namespace eppfrd
static
int
get_branchinfo_search(const Branches::CPtr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo_search(const Branches::Ptr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
BranchInfo bi;
uint64_t spaceavail;
*sum_ = 0;
@ -138,17 +128,14 @@ namespace eppfrd
*sum_ += spaceavail;
bi.spaceavail = spaceavail;
bi.basepath = &branch.path;
branchinfo_->push_back(bi);
branchinfo_->push_back({spaceavail,&branch});
}
return ENOENT;
}
static
const
string*
Branch*
get_branch(const BranchInfoVec &branchinfo_,
const uint64_t sum_)
{
@ -167,7 +154,7 @@ namespace eppfrd
if(idx < threshold)
continue;
return branchinfo_[i].basepath;
return branchinfo_[i].branch;
}
return NULL;
@ -175,88 +162,88 @@ namespace eppfrd
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
uint64_t sum;
const string *basepath;
Branch *branch;
BranchInfoVec branchinfo;
error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum);
basepath = eppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum);
branch = eppfrd::get_branch(branchinfo,sum);
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
uint64_t sum;
const string *basepath;
Branch *branch;
BranchInfoVec branchinfo;
error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum);
basepath = eppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum);
branch = eppfrd::get_branch(branchinfo,sum);
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
uint64_t sum;
const string *basepath;
Branch *branch;
BranchInfoVec branchinfo;
error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum);
basepath = eppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum);
branch = eppfrd::get_branch(branchinfo,sum);
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
}
int
Policy::EPPFRD::Action::operator()(const Branches::CPtr &branches_,
Policy::EPPFRD::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eppfrd::action(branches_,fusepath_,paths_);
}
int
Policy::EPPFRD::Create::operator()(const Branches::CPtr &branches_,
Policy::EPPFRD::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eppfrd::create(branches_,fusepath_,paths_);
}
int
Policy::EPPFRD::Search::operator()(const Branches::CPtr &branches_,
Policy::EPPFRD::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::eppfrd::search(branches_,fusepath_,paths_);
}

12
src/policy_eppfrd.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

18
src/policy_eprand.cpp

@ -22,43 +22,43 @@
int
Policy::EPRand::Action::operator()(const Branches::CPtr &branches_,
Policy::EPRand::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
int rv;
rv = Policies::Action::epall(branches_,fusepath_,paths_);
if(rv == 0)
RND::shrink_to_rand_elem(*paths_);
RND::shrink_to_rand_elem(paths_);
return rv;
}
int
Policy::EPRand::Create::operator()(const Branches::CPtr &branches_,
Policy::EPRand::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
int rv;
rv = Policies::Create::epall(branches_,fusepath_,paths_);
if(rv == 0)
RND::shrink_to_rand_elem(*paths_);
RND::shrink_to_rand_elem(paths_);
return rv;
}
int
Policy::EPRand::Search::operator()(const Branches::CPtr &branches_,
Policy::EPRand::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
int rv;
rv = Policies::Search::epall(branches_,fusepath_,paths_);
if(rv == 0)
RND::shrink_to_rand_elem(*paths_);
RND::shrink_to_rand_elem(paths_);
return rv;
}

12
src/policy_eprand.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

12
src/policy_erofs.cpp

@ -24,25 +24,25 @@ using std::string;
int
Policy::ERoFS::Action::operator()(const Branches::CPtr &branches_,
Policy::ERoFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return (errno=EROFS,-1);
}
int
Policy::ERoFS::Create::operator()(const Branches::CPtr &branches_,
Policy::ERoFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return (errno=EROFS,-1);
}
int
Policy::ERoFS::Search::operator()(const Branches::CPtr &branches_,
Policy::ERoFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return (errno=EROFS,-1);
}

12
src/policy_erofs.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving(void) const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

33
src/policy_ff.cpp

@ -25,21 +25,20 @@
#include <string>
using std::string;
namespace ff
{
static
int
create(const Branches::CPtr &branches_,
StrVec *paths_)
create(const Branches::Ptr &ibranches_,
std::vector<Branch*> &obranches_)
{
int rv;
int error;
fs::info_t info;
error = ENOENT;
for(auto &branch : *branches_)
for(auto &branch : *ibranches_)
{
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
@ -51,7 +50,7 @@ namespace ff
if(info.spaceavail < branch.minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch.path);
obranches_.emplace_back(&branch);
return 0;
}
@ -61,25 +60,35 @@ namespace ff
}
int
Policy::FF::Action::operator()(const Branches::CPtr &branches_,
Policy::FF::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::epff(branches_,fusepath_,paths_);
}
int
Policy::FF::Create::operator()(const Branches::CPtr &branches_,
Policy::FF::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::ff::create(branches_,paths_);
}
int
Policy::FF::Search::operator()(const Branches::CPtr &branches_,
Policy::FF::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &output_) const
{
return Policies::Search::epff(branches_,fusepath_,paths_);
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_))
continue;
output_.emplace_back(&branch);
return 0;
}
return (errno=ENOENT,-1);
}

13
src/policy_ff.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,8 +45,11 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
bool path_preserving(void) const final { return false; }
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Search final : public Policy::SearchImpl
@ -55,7 +60,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

29
src/policy_lfs.cpp

@ -27,25 +27,24 @@
#include <limits>
#include <string>
using std::string;
namespace lfs
{
static
int
create(const Branches::CPtr &branches_,
StrVec *paths_)
create(const Branches::Ptr &branches_,
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t lfs;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
lfs = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
@ -60,38 +59,38 @@ namespace lfs
continue;
lfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(!obranch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.push_back(obranch);
return 0;
}
}
int
Policy::LFS::Action::operator()(const Branches::CPtr &branches_,
Policy::LFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::eplfs(branches_,fusepath_,paths_);
}
int
Policy::LFS::Create::operator()(const Branches::CPtr &branches_,
Policy::LFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::lfs::create(branches_,paths_);
}
int
Policy::LFS::Search::operator()(const Branches::CPtr &branches_,
Policy::LFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::eplfs(branches_,fusepath_,paths_);
}

12
src/policy_lfs.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

28
src/policy_lus.cpp

@ -35,18 +35,18 @@ namespace lus
{
static
int
create(const Branches::CPtr &branches_,
StrVec *paths_)
create(const Branches::Ptr &branches_,
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t lus;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
lus = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
@ -61,39 +61,39 @@ namespace lus
if(info.spaceused >= lus)
continue;
lus = info.spaceused;
basepath = &branch.path;
lus = info.spaceused;
obranch = &branch;
}
if(basepath == NULL)
if(!obranch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.push_back(obranch);
return 0;
}
}
int
Policy::LUS::Action::operator()(const Branches::CPtr &branches_,
Policy::LUS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::eplus(branches_,fusepath_,paths_);
}
int
Policy::LUS::Create::operator()(const Branches::CPtr &branches_,
Policy::LUS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::lus::create(branches_,paths_);
}
int
Policy::LUS::Search::operator()(const Branches::CPtr &branches_,
Policy::LUS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::eplus(branches_,fusepath_,paths_);
}

12
src/policy_lus.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

30
src/policy_mfs.cpp

@ -30,19 +30,19 @@ namespace mfs
{
static
int
create(const Branches::CPtr &branches_,
StrVec *paths_)
create(const Branches::Ptr &branches_,
std::vector<Branch*> &paths_)
{
int rv;
int error;
uint64_t mfs;
u64 mfs;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
mfs = 0;
basepath = NULL;
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
error_and_continue(error,EROFS);
@ -57,38 +57,38 @@ namespace mfs
continue;
mfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(!obranch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.push_back(obranch);
return 0;
}
}
int
Policy::MFS::Action::operator()(const Branches::CPtr &branches_,
Policy::MFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::epmfs(branches_,fusepath_,paths_);
}
int
Policy::MFS::Create::operator()(const Branches::CPtr &branches_,
Policy::MFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::mfs::create(branches_,paths_);
}
int
Policy::MFS::Search::operator()(const Branches::CPtr &branches_,
Policy::MFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::epmfs(branches_,fusepath_,paths_);
}

12
src/policy_mfs.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

49
src/policy_msplfs.cpp

@ -28,26 +28,23 @@
#include <limits>
#include <string>
using std::string;
namespace msplfs
{
static
const
string*
create_1(const Branches::CPtr &branches_,
const string &fusepath_,
int *err_)
Branch*
create_1(const Branches::Ptr &branches_,
const std::string &fusepath_,
int *err_)
{
int rv;
uint64_t lfs;
fs::info_t info;
const string *basepath;
Branch *obranch;
basepath = NULL;
obranch = nullptr;
lfs = std::numeric_limits<uint64_t>::max();
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
error_and_continue(*err_,EROFS);
@ -64,63 +61,63 @@ namespace msplfs
continue;
lfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
return basepath;
return obranch;
}
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
string fusepath;
const string *basepath;
Branch *branch;
std::string fusepath;
error = ENOENT;
fusepath = fusepath_;
for(;;)
{
basepath = msplfs::create_1(branches_,fusepath,&error);
if(basepath)
branch = msplfs::create_1(branches_,fusepath,&error);
if(branch)
break;
if(fusepath == "/")
break;
fusepath = fs::path::dirname(fusepath);
}
if(basepath == NULL)
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.push_back(branch);
return 0;
}
}
int
Policy::MSPLFS::Action::operator()(const Branches::CPtr &branches_,
Policy::MSPLFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::eplfs(branches_,fusepath_,paths_);
}
int
Policy::MSPLFS::Create::operator()(const Branches::CPtr &branches_,
Policy::MSPLFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::msplfs::create(branches_,fusepath_,paths_);
}
int
Policy::MSPLFS::Search::operator()(const Branches::CPtr &branches_,
Policy::MSPLFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::eplfs(branches_,fusepath_,paths_);
}

12
src/policy_msplfs.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

48
src/policy_msplus.cpp

@ -27,23 +27,21 @@
#include <limits>
#include <string>
using std::string;
namespace msplus
{
static
const
string*
create_1(const Branches::CPtr &branches_,
const string &fusepath_,
int *err_)
Branch*
create_1(const Branches::Ptr &branches_,
const std::string &fusepath_,
int *err_)
{
int rv;
uint64_t lus;
fs::info_t info;
const string *basepath;
Branch *obranch;
basepath = NULL;
obranch = nullptr;
lus = std::numeric_limits<uint64_t>::max();
for(auto &branch : *branches_)
{
@ -61,64 +59,64 @@ namespace msplus
if(info.spaceused >= lus)
continue;
lus = info.spaceused;;
basepath = &branch.path;
lus = info.spaceused;
obranch = &branch;
}
return basepath;
return obranch;
}
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
string fusepath;
const string *basepath;
Branch *branch;
std::string fusepath;
error = ENOENT;
fusepath = fusepath_;
for(;;)
{
basepath = msplus::create_1(branches_,fusepath,&error);
if(basepath)
branch = msplus::create_1(branches_,fusepath,&error);
if(branch)
break;
if(fusepath == "/")
break;
fusepath = fs::path::dirname(fusepath);
}
if(basepath == NULL)
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
}
int
Policy::MSPLUS::Action::operator()(const Branches::CPtr &branches_,
Policy::MSPLUS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::eplus(branches_,fusepath_,paths_);
}
int
Policy::MSPLUS::Create::operator()(const Branches::CPtr &branches_,
Policy::MSPLUS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::msplus::create(branches_,fusepath_,paths_);
}
int
Policy::MSPLUS::Search::operator()(const Branches::CPtr &branches_,
Policy::MSPLUS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::eplus(branches_,fusepath_,paths_);
}

12
src/policy_msplus.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

49
src/policy_mspmfs.cpp

@ -28,27 +28,22 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
namespace mspmfs
{
static
const
string*
create_1(const Branches::CPtr &branches_,
const string &fusepath_,
int *err_)
Branch*
create_1(const Branches::Ptr &branches_,
const std::string &fusepath_,
int *err_)
{
int rv;
uint64_t mfs;
fs::info_t info;
const string *basepath;
Branch *obranch;
basepath = NULL;
mfs = std::numeric_limits<uint64_t>::min();
for(const auto &branch : *branches_)
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
error_and_continue(*err_,EROFS);
@ -65,63 +60,63 @@ namespace mspmfs
continue;
mfs = info.spaceavail;
basepath = &branch.path;
obranch = &branch;
}
return basepath;
return obranch;
}
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
string fusepath;
const string *basepath;
std::string fusepath;
Branch *branch;
error = ENOENT;
fusepath = fusepath_;
for(;;)
{
basepath = mspmfs::create_1(branches_,fusepath,&error);
if(basepath)
branch = mspmfs::create_1(branches_,fusepath,&error);
if(branch)
break;
if(fusepath == "/")
break;
fusepath = fs::path::dirname(fusepath);
}
if(basepath == NULL)
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
}
int
Policy::MSPMFS::Action::operator()(const Branches::CPtr &branches_,
Policy::MSPMFS::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::epmfs(branches_,fusepath_,paths_);
}
int
Policy::MSPMFS::Create::operator()(const Branches::CPtr &branches_,
Policy::MSPMFS::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::mspmfs::create(branches_,fusepath_,paths_);
}
int
Policy::MSPMFS::Search::operator()(const Branches::CPtr &branches_,
Policy::MSPMFS::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::epmfs(branches_,fusepath_,paths_);
}

12
src/policy_mspmfs.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return true; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

66
src/policy_msppfrd.cpp

@ -30,29 +30,26 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
struct BranchInfo
{
uint64_t spaceavail;
const string *basepath;
u64 spaceavail;
Branch *branch;
};
typedef vector<BranchInfo> BranchInfoVec;
typedef std::vector<BranchInfo> BranchInfoVec;
namespace msppfrd
{
static
int
create_1(const Branches::CPtr &branches_,
const string &fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
create_1(const Branches::Ptr &branches_,
const std::string &fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
*sum_ = 0;
@ -73,9 +70,7 @@ namespace msppfrd
*sum_ += info.spaceavail;
bi.spaceavail = info.spaceavail;
bi.basepath = &branch.path;
branchinfo_->push_back(bi);
branchinfo_->push_back({info.spaceavail,&branch});
}
return error;
@ -83,13 +78,13 @@ namespace msppfrd
static
int
get_branchinfo(const Branches::CPtr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo(const Branches::Ptr &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int error;
string fusepath;
std::string fusepath;
fusepath = fusepath_;
for(;;)
@ -106,8 +101,7 @@ namespace msppfrd
}
static
const
string*
Branch*
get_branch(const BranchInfoVec &branchinfo_,
const uint64_t sum_)
{
@ -115,7 +109,7 @@ namespace msppfrd
uint64_t threshold;
if(sum_ == 0)
return NULL;
return nullptr;
idx = 0;
threshold = RND::rand64(sum_);
@ -126,54 +120,54 @@ namespace msppfrd
if(idx < threshold)
continue;
return branchinfo_[i].basepath;
return branchinfo_[i].branch;
}
return NULL;
return nullptr;
}
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
uint64_t sum;
const string *basepath;
Branch *branch;
BranchInfoVec branchinfo;
error = msppfrd::get_branchinfo(branches_,fusepath_,&branchinfo,&sum);
basepath = msppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
error = msppfrd::get_branchinfo(branches_,fusepath_,&branchinfo,&sum);
branch = msppfrd::get_branch(branchinfo,sum);
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
}
int
Policy::MSPPFRD::Action::operator()(const Branches::CPtr &branches_,
Policy::MSPPFRD::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::eppfrd(branches_,fusepath_,paths_);
}
int
Policy::MSPPFRD::Create::operator()(const Branches::CPtr &branches_,
Policy::MSPPFRD::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::msppfrd::create(branches_,fusepath_,paths_);
}
int
Policy::MSPPFRD::Search::operator()(const Branches::CPtr &branches_,
Policy::MSPPFRD::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::eppfrd(branches_,fusepath_,paths_);
}

12
src/policy_msppfrd.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return true; };
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

54
src/policy_newest.cpp

@ -35,20 +35,20 @@ namespace newest
{
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
time_t newest;
struct stat st;
fs::info_t info;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
newest = std::numeric_limits<time_t>::min();
basepath = NULL;
for(auto &branch : *branches_)
{
if(branch.ro_or_nc())
@ -66,33 +66,33 @@ namespace newest
error_and_continue(error,ENOSPC);
newest = st.st_mtime;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(!obranch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
action(const Branches::CPtr &branches_,
action(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int rv;
int error;
bool readonly;
time_t newest;
struct stat st;
const string *basepath;
Branch *obranch;
obranch = nullptr;
error = ENOENT;
newest = std::numeric_limits<time_t>::min();
basepath = NULL;
for(auto &branch : *branches_)
{
if(branch.ro())
@ -108,29 +108,29 @@ namespace newest
error_and_continue(error,EROFS);
newest = st.st_mtime;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(!obranch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
static
int
search(const Branches::CPtr &branches_,
search(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
time_t newest;
struct stat st;
const string *basepath;
Branch *obranch;
obranch = nullptr;
newest = std::numeric_limits<time_t>::min();
basepath = NULL;
for(auto &branch : *branches_)
{
if(!fs::exists(branch.path,fusepath_,&st))
@ -139,38 +139,38 @@ namespace newest
continue;
newest = st.st_mtime;
basepath = &branch.path;
obranch = &branch;
}
if(basepath == NULL)
if(!obranch)
return (errno=ENOENT,-1);
paths_->push_back(*basepath);
paths_.emplace_back(obranch);
return 0;
}
}
int
Policy::Newest::Action::operator()(const Branches::CPtr &branches_,
Policy::Newest::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::newest::action(branches_,fusepath_,paths_);
}
int
Policy::Newest::Create::operator()(const Branches::CPtr &branches_,
Policy::Newest::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::newest::create(branches_,fusepath_,paths_);
}
int
Policy::Newest::Search::operator()(const Branches::CPtr &branches_,
Policy::Newest::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::newest::search(branches_,fusepath_,paths_);
}

12
src/policy_newest.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

58
src/policy_pfrd.cpp

@ -27,28 +27,25 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
struct BranchInfo
{
uint64_t spaceavail;
const string *basepath;
uint64_t spaceavail;
Branch *branch;
};
typedef vector<BranchInfo> BranchInfoVec;
typedef std::vector<BranchInfo> BranchInfoVec;
namespace pfrd
{
static
int
get_branchinfo(const Branches::CPtr &branches_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo(const Branches::Ptr &branches_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
*sum_ = 0;
@ -67,17 +64,14 @@ namespace pfrd
*sum_ += info.spaceavail;
bi.spaceavail = info.spaceavail;
bi.basepath = &branch.path;
branchinfo_->push_back(bi);
branchinfo_->push_back({info.spaceavail,&branch});
}
return error;
}
static
const
string*
Branch*
get_branch(const BranchInfoVec &branchinfo_,
const uint64_t sum_)
{
@ -85,65 +79,65 @@ namespace pfrd
uint64_t threshold;
if(sum_ == 0)
return NULL;
return nullptr;
idx = 0;
threshold = RND::rand64(sum_);
for(size_t i = 0; i < branchinfo_.size(); i++)
for(auto &bi : branchinfo_)
{
idx += branchinfo_[i].spaceavail;
idx += bi.spaceavail;
if(idx < threshold)
continue;
return branchinfo_[i].basepath;
return bi.branch;
}
return NULL;
return nullptr;
}
static
int
create(const Branches::CPtr &branches_,
create(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_)
std::vector<Branch*> &paths_)
{
int error;
uint64_t sum;
const string *basepath;
Branch *branch;
BranchInfoVec branchinfo;
error = pfrd::get_branchinfo(branches_,&branchinfo,&sum);
basepath = pfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
error = pfrd::get_branchinfo(branches_,&branchinfo,&sum);
branch = pfrd::get_branch(branchinfo,sum);
if(!branch)
return (errno=error,-1);
paths_->push_back(*basepath);
paths_.emplace_back(branch);
return 0;
}
}
int
Policy::PFRD::Action::operator()(const Branches::CPtr &branches_,
Policy::PFRD::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Action::eppfrd(branches_,fusepath_,paths_);
}
int
Policy::PFRD::Create::operator()(const Branches::CPtr &branches_,
Policy::PFRD::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return ::pfrd::create(branches_,fusepath_,paths_);
}
int
Policy::PFRD::Search::operator()(const Branches::CPtr &branches_,
Policy::PFRD::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
return Policies::Search::eppfrd(branches_,fusepath_,paths_);
}

12
src/policy_pfrd.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

18
src/policy_rand.cpp

@ -21,43 +21,43 @@
#include "rnd.hpp"
int
Policy::Rand::Action::operator()(const Branches::CPtr &branches_,
Policy::Rand::Action::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
int rv;
rv = Policies::Action::all(branches_,fusepath_,paths_);
if(rv == 0)
RND::shrink_to_rand_elem(*paths_);
RND::shrink_to_rand_elem(paths_);
return rv;
}
int
Policy::Rand::Create::operator()(const Branches::CPtr &branches_,
Policy::Rand::Create::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
int rv;
rv = Policies::Create::all(branches_,fusepath_,paths_);
if(rv == 0)
RND::shrink_to_rand_elem(*paths_);
RND::shrink_to_rand_elem(paths_);
return rv;
}
int
Policy::Rand::Search::operator()(const Branches::CPtr &branches_,
Policy::Rand::Search::operator()(const Branches::Ptr &branches_,
const char *fusepath_,
StrVec *paths_) const
std::vector<Branch*> &paths_) const
{
int rv;
rv = Policies::Search::all(branches_,fusepath_,paths_);
if(rv == 0)
RND::shrink_to_rand_elem(*paths_);
RND::shrink_to_rand_elem(paths_);
return rv;
}

12
src/policy_rand.hpp

@ -32,7 +32,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
class Create final : public Policy::CreateImpl
@ -43,7 +45,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
bool path_preserving() const final { return false; }
};
@ -55,7 +59,9 @@ namespace Policy
{}
public:
int operator()(const Branches::CPtr&,const char*,StrVec*) const final;
int operator()(const Branches::Ptr&,
const char*,
std::vector<Branch*>&) const final;
};
}
}

26
src/policy_rv.hpp

@ -36,16 +36,34 @@ struct PolicyRV
std::string basepath;
};
std::vector<RV> success;
std::vector<RV> error;
std::vector<RV> successes;
std::vector<RV> errors;
void
insert(const int err_,
const std::string &basepath_)
{
if(err_ == 0)
success.push_back(RV(err_,basepath_));
successes.push_back({err_,basepath_});
else
error.push_back(RV(-err_,basepath_));
errors.push_back({-err_,basepath_});
}
int
get_error(const std::string &basepath_)
{
for(const auto &s : successes)
{
if(s.basepath == basepath_)
return s.rv;
}
for(const auto &e : errors)
{
if(e.basepath == basepath_)
return e.rv;
}
return 0;
}
};
Loading…
Cancel
Save