mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-25 17:36:25 -05:00
checkpoint
This commit is contained in:
parent
d9ab18282f
commit
0bb55624a4
361 changed files with 21008 additions and 1617 deletions
|
|
@ -23,205 +23,17 @@
|
|||
#include "fuse_getattr.hpp"
|
||||
#include "fuse_symlink.hpp"
|
||||
#include "ghc/filesystem.hpp"
|
||||
#include "state.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
#include "fuse.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
namespace gfs = ghc::filesystem;
|
||||
|
||||
namespace error
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
calc(const int rv_,
|
||||
const int prev_,
|
||||
const int cur_)
|
||||
{
|
||||
if(rv_ == -1)
|
||||
{
|
||||
if(prev_ == 0)
|
||||
return 0;
|
||||
return cur_;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace l
|
||||
{
|
||||
static
|
||||
int
|
||||
link_create_path_loop(const StrVec &oldbasepaths_,
|
||||
const string &newbasepath_,
|
||||
const char *oldfusepath_,
|
||||
const char *newfusepath_,
|
||||
const string &newfusedirpath_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
string oldfullpath;
|
||||
string newfullpath;
|
||||
|
||||
error = -1;
|
||||
for(auto &oldbasepath : oldbasepaths_)
|
||||
{
|
||||
oldfullpath = fs::path::make(oldbasepath,oldfusepath_);
|
||||
newfullpath = fs::path::make(oldbasepath,newfusepath_);
|
||||
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
if((rv == -1) && (errno == ENOENT))
|
||||
{
|
||||
rv = fs::clonepath_as_root(newbasepath_,oldbasepath,newfusedirpath_);
|
||||
if(rv == 0)
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
}
|
||||
|
||||
error = error::calc(rv,error,errno);
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link_create_path(const Policy::Search &searchFunc_,
|
||||
const Policy::Action &actionFunc_,
|
||||
const Branches &branches_,
|
||||
const char *oldfusepath_,
|
||||
const char *newfusepath_)
|
||||
{
|
||||
int rv;
|
||||
string newfusedirpath;
|
||||
StrVec oldbasepaths;
|
||||
StrVec newbasepaths;
|
||||
|
||||
rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
newfusedirpath = fs::path::dirname(newfusepath_);
|
||||
|
||||
rv = searchFunc_(branches_,newfusedirpath,&newbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return l::link_create_path_loop(oldbasepaths,newbasepaths[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_)
|
||||
{
|
||||
int rv;
|
||||
string oldfullpath;
|
||||
string newfullpath;
|
||||
|
||||
oldfullpath = fs::path::make(oldbasepath_,oldfusepath_);
|
||||
newfullpath = fs::path::make(oldbasepath_,newfusepath_);
|
||||
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
if((rv == -1) && (errno == ENOENT))
|
||||
errno = EXDEV;
|
||||
if((rv == 0) && (st_->st_ino == 0))
|
||||
rv = fs::lstat(oldfullpath,st_);
|
||||
|
||||
return error::calc(rv,error_,errno);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link_preserve_path_loop(const StrVec &oldbasepaths_,
|
||||
const char *oldfusepath_,
|
||||
const char *newfusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = -1;
|
||||
for(auto &oldbasepath : oldbasepaths_)
|
||||
{
|
||||
error = l::link_preserve_path_core(oldbasepath,
|
||||
oldfusepath_,
|
||||
newfusepath_,
|
||||
st_,
|
||||
error);
|
||||
}
|
||||
|
||||
return -error;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link_preserve_path(const Policy::Action &actionFunc_,
|
||||
const Branches &branches_,
|
||||
const char *oldfusepath_,
|
||||
const char *newfusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
StrVec oldbasepaths;
|
||||
|
||||
rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
return l::link_preserve_path_loop(oldbasepaths,
|
||||
oldfusepath_,
|
||||
newfusepath_,
|
||||
st_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link(Config::Read &cfg_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
if(cfg_->func.create.policy.path_preserving() && !cfg_->ignorepponrename)
|
||||
return l::link_preserve_path(cfg_->func.link.policy,
|
||||
cfg_->branches,
|
||||
oldpath_,
|
||||
newpath_,
|
||||
st_);
|
||||
|
||||
return l::link_create_path(cfg_->func.getattr.policy,
|
||||
cfg_->func.link.policy,
|
||||
cfg_->branches,
|
||||
oldpath_,
|
||||
newpath_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link(Config::Read &cfg_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = l::link(cfg_,oldpath_,newpath_,st_);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
return FUSE::getattr(newpath_,st_,timeouts_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
link_exdev_rel_symlink(const char *oldpath_,
|
||||
|
|
@ -235,9 +47,9 @@ namespace l
|
|||
|
||||
target = target.lexically_relative(linkpath.parent_path());
|
||||
|
||||
rv = FUSE::symlink(target.c_str(),linkpath.c_str());
|
||||
rv = FUSE::SYMLINK::symlink(target.c_str(),linkpath.c_str());
|
||||
if(rv == 0)
|
||||
rv = FUSE::getattr(oldpath_,st_,timeouts_);
|
||||
rv = FUSE::GETATTR::getattr(oldpath_,st_,timeouts_);
|
||||
|
||||
// Disable caching since we created a symlink but should be a regular.
|
||||
timeouts_->attr = 0;
|
||||
|
|
@ -248,26 +60,20 @@ namespace l
|
|||
|
||||
static
|
||||
int
|
||||
link_exdev_abs_base_symlink(const Policy::Search &openPolicy_,
|
||||
const Branches::CPtr &branches_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
link_exdev_abs_base_symlink(const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
StrVec basepaths;
|
||||
std::string target;
|
||||
gfs::path target;
|
||||
|
||||
rv = openPolicy_(branches_,oldpath_,&basepaths);
|
||||
if(rv == -1)
|
||||
return -errno;
|
||||
target = "FIXME";
|
||||
|
||||
target = fs::path::make(basepaths[0],oldpath_);
|
||||
|
||||
rv = FUSE::symlink(target.c_str(),newpath_);
|
||||
rv = FUSE::SYMLINK::symlink(target.c_str(),newpath_);
|
||||
if(rv == 0)
|
||||
rv = FUSE::getattr(oldpath_,st_,timeouts_);
|
||||
rv = FUSE::GETATTR::getattr(oldpath_,st_,timeouts_);
|
||||
|
||||
// Disable caching since we created a symlink but should be a regular.
|
||||
timeouts_->attr = 0;
|
||||
|
|
@ -278,21 +84,20 @@ namespace l
|
|||
|
||||
static
|
||||
int
|
||||
link_exdev_abs_pool_symlink(const std::string &mount_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
link_exdev_abs_pool_symlink(const gfs::path &mount_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
StrVec basepaths;
|
||||
std::string target;
|
||||
gfs::path target;
|
||||
|
||||
target = fs::path::make(mount_,oldpath_);
|
||||
target = mount_ / &oldpath_[1];
|
||||
|
||||
rv = FUSE::symlink(target.c_str(),newpath_);
|
||||
rv = FUSE::SYMLINK::symlink(target.c_str(),newpath_);
|
||||
if(rv == 0)
|
||||
rv = FUSE::getattr(oldpath_,st_,timeouts_);
|
||||
rv = FUSE::GETATTR::getattr(oldpath_,st_,timeouts_);
|
||||
|
||||
// Disable caching since we created a symlink but should be a regular.
|
||||
timeouts_->attr = 0;
|
||||
|
|
@ -303,30 +108,29 @@ namespace l
|
|||
|
||||
static
|
||||
int
|
||||
link_exdev(Config::Read &cfg_,
|
||||
link_exdev(State &s_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
switch(cfg_->link_exdev)
|
||||
switch(s_->link_exdev)
|
||||
{
|
||||
case LinkEXDEV::ENUM::PASSTHROUGH:
|
||||
case LinkEXDEV::INVALID:
|
||||
case LinkEXDEV::PASSTHROUGH:
|
||||
return -EXDEV;
|
||||
case LinkEXDEV::ENUM::REL_SYMLINK:
|
||||
case LinkEXDEV::REL_SYMLINK:
|
||||
return l::link_exdev_rel_symlink(oldpath_,
|
||||
newpath_,
|
||||
st_,
|
||||
timeouts_);
|
||||
case LinkEXDEV::ENUM::ABS_BASE_SYMLINK:
|
||||
return l::link_exdev_abs_base_symlink(cfg_->func.open.policy,
|
||||
cfg_->branches,
|
||||
oldpath_,
|
||||
case LinkEXDEV::ABS_BASE_SYMLINK:
|
||||
return l::link_exdev_abs_base_symlink(oldpath_,
|
||||
newpath_,
|
||||
st_,
|
||||
timeouts_);
|
||||
case LinkEXDEV::ENUM::ABS_POOL_SYMLINK:
|
||||
return l::link_exdev_abs_pool_symlink(cfg_->mount,
|
||||
case LinkEXDEV::ABS_POOL_SYMLINK:
|
||||
return l::link_exdev_abs_pool_symlink(s_->mountpoint,
|
||||
oldpath_,
|
||||
newpath_,
|
||||
st_,
|
||||
|
|
@ -337,7 +141,7 @@ namespace l
|
|||
}
|
||||
}
|
||||
|
||||
namespace FUSE
|
||||
namespace FUSE::LINK
|
||||
{
|
||||
int
|
||||
link(const char *oldpath_,
|
||||
|
|
@ -346,14 +150,14 @@ namespace FUSE
|
|||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
Config::Read cfg;
|
||||
State s;
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const ugid::Set ugid(fc->uid,fc->gid);
|
||||
|
||||
rv = l::link(cfg,oldpath_,newpath_,st_,timeouts_);
|
||||
rv = s->link(oldpath_,newpath_);
|
||||
if(rv == -EXDEV)
|
||||
return l::link_exdev(cfg,oldpath_,newpath_,st_,timeouts_);
|
||||
return l::link_exdev(s,oldpath_,newpath_,st_,timeouts_);
|
||||
|
||||
return rv;
|
||||
return s->getattr(newpath_,st_,timeouts_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue