mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-03-14 09:55:12 +08:00
generate the controlfile data on the fly. closes #19
This commit is contained in:
parent
15a0416eed
commit
ccb0ac1463
@ -39,8 +39,7 @@ namespace mergerfs
|
||||
: action(policies[0]),
|
||||
create(policies[1]),
|
||||
search(policies[2]),
|
||||
controlfile("/.mergerfs"),
|
||||
testmode(false)
|
||||
controlfile("/.mergerfs")
|
||||
{
|
||||
action = &Policy::ff;
|
||||
create = &Policy::epmfs;
|
||||
@ -64,7 +63,7 @@ namespace mergerfs
|
||||
}
|
||||
|
||||
std::string
|
||||
Config::generateReadStr() const
|
||||
Config::controlfiledata() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
@ -75,13 +74,6 @@ namespace mergerfs
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void
|
||||
Config::updateReadStr()
|
||||
{
|
||||
readstr = generateReadStr();
|
||||
controlfilestat.st_size = readstr.size();
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(void)
|
||||
{
|
||||
|
@ -42,8 +42,8 @@ namespace mergerfs
|
||||
public:
|
||||
Config();
|
||||
|
||||
std::string generateReadStr() const;
|
||||
void updateReadStr();
|
||||
public:
|
||||
std::string controlfiledata() const;
|
||||
|
||||
public:
|
||||
std::string destmount;
|
||||
@ -54,11 +54,9 @@ namespace mergerfs
|
||||
const Policy *&create;
|
||||
const Policy *&search;
|
||||
|
||||
public:
|
||||
const std::string controlfile;
|
||||
struct stat controlfilestat;
|
||||
std::string readstr;
|
||||
|
||||
bool testmode;
|
||||
};
|
||||
|
||||
const Config &get(void);
|
||||
|
@ -32,6 +32,18 @@
|
||||
#include "config.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
static
|
||||
int
|
||||
_fgetattr_controlfile(const struct stat &controlfilestat,
|
||||
const std::string cfdata,
|
||||
struct stat &st)
|
||||
{
|
||||
st = controlfilestat;
|
||||
st.st_size = cfdata.size();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_fgetattr(const int fd,
|
||||
@ -57,7 +69,9 @@ namespace mergerfs
|
||||
const FileInfo *fileinfo = (FileInfo*)ffi->fh;
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return (*st = config.controlfilestat,0);
|
||||
return _fgetattr_controlfile(config.controlfilestat,
|
||||
config.controlfiledata(),
|
||||
*st);
|
||||
|
||||
return _fgetattr(fileinfo->fd,
|
||||
*st);
|
||||
|
@ -41,6 +41,18 @@ using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
|
||||
static
|
||||
int
|
||||
_getattr_controlfile(const struct stat &controlfilestat,
|
||||
const std::string cfdata,
|
||||
struct stat &st)
|
||||
{
|
||||
st = controlfilestat;
|
||||
st.st_size = cfdata.size();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_getattr(const fs::SearchFunc searchFunc,
|
||||
@ -66,19 +78,21 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
getattr(const char *fusepath,
|
||||
struct stat *buf)
|
||||
struct stat *st)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return (*buf = config.controlfilestat,0);
|
||||
return _getattr_controlfile(config.controlfilestat,
|
||||
config.controlfiledata(),
|
||||
*st);
|
||||
|
||||
return _getattr(*config.search,
|
||||
config.srcmounts,
|
||||
fusepath,
|
||||
*buf);
|
||||
*st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,10 +157,7 @@ main(int argc,
|
||||
|
||||
mergerfs::options::parse(args,config);
|
||||
|
||||
if(config.testmode == false)
|
||||
rv = mergerfs::main(args,config);
|
||||
else
|
||||
rv = mergerfs::test(args,config);
|
||||
rv = mergerfs::main(args,config);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -83,11 +83,7 @@ process_opt(config::Config &config,
|
||||
break;
|
||||
|
||||
default:
|
||||
case 1:
|
||||
if(argvalue[0] == "test")
|
||||
config.testmode = true;
|
||||
else
|
||||
rv = 1;
|
||||
rv = 1;
|
||||
break;
|
||||
};
|
||||
|
||||
@ -180,8 +176,6 @@ namespace mergerfs
|
||||
::option_processor);
|
||||
|
||||
set_fsname(args,config);
|
||||
|
||||
config.updateReadStr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ namespace mergerfs
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _read_controlfile(config.readstr,
|
||||
return _read_controlfile(config.controlfiledata(),
|
||||
buf,
|
||||
count);
|
||||
|
||||
|
@ -111,7 +111,7 @@ namespace mergerfs
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _read_buf_controlfile(config.readstr,
|
||||
return _read_buf_controlfile(config.controlfiledata(),
|
||||
bufp,
|
||||
size);
|
||||
|
||||
|
@ -95,8 +95,6 @@ _setxattr_controlfile(config::Config &config,
|
||||
|
||||
config.policies[*cat] = policy;
|
||||
|
||||
config.updateReadStr();
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
|
@ -63,8 +63,6 @@ _process_kv(Config &config,
|
||||
|
||||
config.policies[*cat] = policy;
|
||||
|
||||
config.updateReadStr();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -36,18 +36,18 @@ using std::string;
|
||||
static
|
||||
int
|
||||
_write_buf_controlfile(const string controlfile,
|
||||
struct fuse_bufvec *buf,
|
||||
struct fuse_file_info *fi)
|
||||
struct fuse_bufvec &src,
|
||||
struct fuse_file_info &fi)
|
||||
{
|
||||
int rv;
|
||||
size_t size;
|
||||
struct fuse_bufvec dst;
|
||||
|
||||
size = fuse_buf_size(buf);
|
||||
size = fuse_buf_size(&src);
|
||||
dst = FUSE_BUFVEC_INIT(size);
|
||||
dst.buf->mem = malloc(size);
|
||||
|
||||
rv = fuse_buf_copy(&dst,buf,(fuse_buf_copy_flags)0);
|
||||
rv = fuse_buf_copy(&dst,&src,(fuse_buf_copy_flags)0);
|
||||
if(rv < 0)
|
||||
{
|
||||
free(dst.buf->mem);
|
||||
@ -58,7 +58,7 @@ _write_buf_controlfile(const string controlfile,
|
||||
(const char*)dst.buf->mem,
|
||||
size,
|
||||
0,
|
||||
fi);
|
||||
&fi);
|
||||
free(dst.buf->mem);
|
||||
|
||||
return rv;
|
||||
@ -67,19 +67,19 @@ _write_buf_controlfile(const string controlfile,
|
||||
static
|
||||
int
|
||||
_write_buf(const int fd,
|
||||
struct fuse_bufvec *buf,
|
||||
struct fuse_bufvec &src,
|
||||
const off_t offset)
|
||||
{
|
||||
size_t size = fuse_buf_size(buf);
|
||||
struct fuse_bufvec dest = FUSE_BUFVEC_INIT(size);
|
||||
size_t size = fuse_buf_size(&src);
|
||||
struct fuse_bufvec dst = FUSE_BUFVEC_INIT(size);
|
||||
const fuse_buf_copy_flags cpflags =
|
||||
(fuse_buf_copy_flags)(FUSE_BUF_SPLICE_MOVE|FUSE_BUF_SPLICE_NONBLOCK);
|
||||
|
||||
dest.buf->flags = (fuse_buf_flags)(FUSE_BUF_IS_FD|FUSE_BUF_FD_SEEK);
|
||||
dest.buf->fd = fd;
|
||||
dest.buf->pos = offset;
|
||||
dst.buf->flags = (fuse_buf_flags)(FUSE_BUF_IS_FD|FUSE_BUF_FD_SEEK);
|
||||
dst.buf->fd = fd;
|
||||
dst.buf->pos = offset;
|
||||
|
||||
return fuse_buf_copy(&dest,buf,cpflags);
|
||||
return fuse_buf_copy(&dst,&src,cpflags);
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
@ -88,7 +88,7 @@ namespace mergerfs
|
||||
{
|
||||
int
|
||||
write_buf(const char *fusepath,
|
||||
struct fuse_bufvec *buf,
|
||||
struct fuse_bufvec *src,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
@ -96,11 +96,11 @@ namespace mergerfs
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _write_buf_controlfile(config.controlfile,
|
||||
buf,
|
||||
fi);
|
||||
*src,
|
||||
*fi);
|
||||
|
||||
return _write_buf(((FileInfo*)fi->fh)->fd,
|
||||
buf,
|
||||
*src,
|
||||
offset);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user