Skip to content

Commit

Permalink
branches: add per branch minfreespace w/ original value as default
Browse files Browse the repository at this point in the history
example: /mnt/disk0=RW,1G:/mnt/disk1=RW,2G
  • Loading branch information
trapexit committed Sep 5, 2020
1 parent 98c49b8 commit fc34539
Show file tree
Hide file tree
Showing 68 changed files with 2,902 additions and 710 deletions.
518 changes: 332 additions & 186 deletions src/branch.cpp

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions src/branch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,56 @@

#include "rwlock.hpp"
#include "tofrom_string.hpp"
#include "nonstd/optional.hpp"

#include <string>
#include <vector>

#include <stdint.h>
#include <pthread.h>

class Branch
class Branch : public ToFromString
{
public:
enum Mode
Branch(const uint64_t &default_minfreespace);

public:
int from_string(const std::string &str);
std::string to_string(void) const;

public:
enum class Mode
{
INVALID,
RO,
RW,
NC
};

public:
Mode mode;
std::string path;
uint64_t minfreespace() const;

public:
void set_minfreespace(const uint64_t minfreespace);

public:
bool ro(void) const;
bool nc(void) const;
bool ro_or_nc(void) const;

private:
nonstd::optional<uint64_t> _minfreespace;
const uint64_t *_default_minfreespace;
};

class Branches : public std::vector<Branch>, public ToFromString
typedef std::vector<Branch> BranchVec;

class Branches : public ToFromString
{
public:
Branches();
Branches(const uint64_t &default_minfreespace_);

public:
int from_string(const std::string &str);
Expand All @@ -59,6 +80,8 @@ class Branches : public std::vector<Branch>, public ToFromString

public:
mutable pthread_rwlock_t lock;
BranchVec vec;
const uint64_t &default_minfreespace;
};

class SrcMounts : public ToFromString
Expand Down
2 changes: 1 addition & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Config::Config()

async_read(true),
auto_cache(false),
branches(),
branches(minfreespace),
cache_attr(1),
cache_entry(1),
cache_files(CacheFiles::ENUM::LIBFUSE),
Expand Down
8 changes: 4 additions & 4 deletions src/from_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ namespace str
{
case 'k':
case 'K':
tmp *= 1024;
tmp *= 1024ULL;
break;

case 'm':
case 'M':
tmp *= (1024 * 1024);
tmp *= (1024ULL * 1024ULL);
break;

case 'g':
case 'G':
tmp *= (1024 * 1024 * 1024);
tmp *= (1024ULL * 1024ULL * 1024ULL);
break;

case 't':
case 'T':
tmp *= (1024ULL * 1024 * 1024 * 1024);
tmp *= (1024ULL * 1024ULL * 1024ULL * 1024ULL);
break;

case '\0':
Expand Down
20 changes: 17 additions & 3 deletions src/fs_findonfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

#include <string>

namespace fs
namespace l
{
static
int
findonfs(const Branches &branches_,
findonfs(const BranchVec &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
Expand All @@ -37,7 +38,6 @@ namespace fs
struct stat st;
std::string fullpath;
const Branch *branch;
const rwlock::ReadGuard guard(&branches_.lock);

rv = fs::fstat(fd_,&st);
if(rv == -1)
Expand Down Expand Up @@ -65,3 +65,17 @@ namespace fs
return (errno=ENOENT,-1);
}
}

namespace fs
{
int
findonfs(const Branches &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
{
rwlock::ReadGuard guard(branches_.lock);

return l::findonfs(branches_.vec,fusepath_,fd_,basepath_);
}
}
9 changes: 3 additions & 6 deletions src/fs_movefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace l
int
movefile(Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreepsace_,
const string &fusepath_,
int *origfd_)
{
Expand All @@ -73,7 +72,7 @@ namespace l
if(rv == -1)
return -1;

rv = createFunc_(branches_,fusepath_,minfreepsace_,&fdout_path);
rv = createFunc_(branches_,fusepath_,&fdout_path);
if(rv == -1)
return -1;

Expand Down Expand Up @@ -135,22 +134,20 @@ namespace fs
int
movefile(const Policy *policy_,
const Branches &basepaths_,
const uint64_t minfreepsace_,
const string &fusepath_,
int *origfd_)
{
return l::movefile(policy_,basepaths_,minfreepsace_,fusepath_,origfd_);
return l::movefile(policy_,basepaths_,fusepath_,origfd_);
}

int
movefile_as_root(const Policy *policy_,
const Branches &basepaths_,
const uint64_t minfreepsace_,
const string &fusepath_,
int *origfd_)
{
const ugid::Set ugid(0,0);

return fs::movefile(policy_,basepaths_,minfreepsace_,fusepath_,origfd_);
return fs::movefile(policy_,basepaths_,fusepath_,origfd_);
}
}
2 changes: 0 additions & 2 deletions src/fs_movefile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ namespace fs
int
movefile(const Policy *policy,
const Branches &branches,
const uint64_t minfreepsace,
const std::string &fusepath,
int *origfd);

int
movefile_as_root(const Policy *policy,
const Branches &branches,
const uint64_t minfreepsace,
const std::string &fusepath,
int *origfd);
}
4 changes: 1 addition & 3 deletions src/fuse_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ namespace l
int
access(Policy::Func::Search searchFunc,
const Branches &branches_,
const uint64_t minfreespace,
const char *fusepath,
const int mask)
{
int rv;
string fullpath;
vector<string> basepaths;

rv = searchFunc(branches_,fusepath,minfreespace,&basepaths);
rv = searchFunc(branches_,fusepath,&basepaths);
if(rv == -1)
return -errno;

Expand All @@ -64,7 +63,6 @@ namespace FUSE

return l::access(config.func.access.policy,
config.branches,
config.minfreespace,
fusepath,
mask);
}
Expand Down
4 changes: 1 addition & 3 deletions src/fuse_chmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ namespace l
int
chmod(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const mode_t mode_)
{
int rv;
vector<string> basepaths;

rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;

Expand All @@ -98,7 +97,6 @@ namespace FUSE

return l::chmod(config.func.chmod.policy,
config.branches,
config.minfreespace,
fusepath_,
mode_);
}
Expand Down
4 changes: 1 addition & 3 deletions src/fuse_chown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ namespace l
int
chown(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const uid_t uid_,
const gid_t gid_)
{
int rv;
vector<string> basepaths;

rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;

Expand All @@ -100,7 +99,6 @@ namespace FUSE

return l::chown(config.func.chown.policy,
config.branches,
config.minfreespace,
fusepath_,
uid_,
gid_);
Expand Down
6 changes: 2 additions & 4 deletions src/fuse_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ namespace l
create(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
Expand All @@ -143,11 +142,11 @@ namespace l

fusedirpath = fs::path::dirname(fusepath_);

rv = searchFunc_(branches_,fusedirpath,minfreespace_,&existingpaths);
rv = searchFunc_(branches_,fusedirpath,&existingpaths);
if(rv == -1)
return -errno;

rv = createFunc_(branches_,fusedirpath,minfreespace_,&createpaths);
rv = createFunc_(branches_,fusedirpath,&createpaths);
if(rv == -1)
return -errno;

Expand Down Expand Up @@ -183,7 +182,6 @@ namespace FUSE
return l::create(config.func.getattr.policy,
config.func.create.policy,
config.branches,
config.minfreespace,
fusepath_,
mode_,
fc->umask,
Expand Down
4 changes: 1 addition & 3 deletions src/fuse_getattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace l
int
getattr(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
struct stat *st_,
const bool symlinkify_,
Expand All @@ -71,7 +70,7 @@ namespace l
string fullpath;
vector<string> basepaths;

rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;

Expand Down Expand Up @@ -108,7 +107,6 @@ namespace FUSE

rv = l::getattr(config.func.getattr.policy,
config.branches,
config.minfreespace,
fusepath_,
st_,
config.symlinkify,
Expand Down
4 changes: 1 addition & 3 deletions src/fuse_getxattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ namespace l
int
getxattr(Policy::Func::Search searchFunc_,
const Branches &branches_,
const size_t minfreespace_,
const char *fusepath_,
const char *attrname_,
char *buf_,
Expand All @@ -175,7 +174,7 @@ namespace l
string fullpath;
vector<string> basepaths;

rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;

Expand Down Expand Up @@ -222,7 +221,6 @@ namespace FUSE

return l::getxattr(config.func.getxattr.policy,
config.branches,
config.minfreespace,
fusepath_,
attrname_,
buf_,
Expand Down

0 comments on commit fc34539

Please sign in to comment.