Browse Source

generate the controlfile data on the fly. closes #19

pull/30/head 1.2.2
Antonio SJ Musumeci 10 years ago
parent
commit
ccb0ac1463
  1. 12
      src/config.cpp
  2. 8
      src/config.hpp
  3. 16
      src/fgetattr.cpp
  4. 20
      src/getattr.cpp
  5. 5
      src/mergerfs.cpp
  6. 8
      src/option_parser.cpp
  7. 2
      src/read.cpp
  8. 2
      src/read_buf.cpp
  9. 2
      src/setxattr.cpp
  10. 2
      src/write.cpp
  11. 32
      src/write_buf.cpp

12
src/config.cpp

@ -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)
{

8
src/config.hpp

@ -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);

16
src/fgetattr.cpp

@ -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);

20
src/getattr.cpp

@ -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);
}
}
}

5
src/mergerfs.cpp

@ -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;
}

8
src/option_parser.cpp

@ -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();
}
}
}

2
src/read.cpp

@ -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);

2
src/read_buf.cpp

@ -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);

2
src/setxattr.cpp

@ -95,8 +95,6 @@ _setxattr_controlfile(config::Config &config,
config.policies[*cat] = policy;
config.updateReadStr();
return 0;
#else
return -ENOTSUP;

2
src/write.cpp

@ -63,8 +63,6 @@ _process_kv(Config &config,
config.policies[*cat] = policy;
config.updateReadStr();
return 0;
}

32
src/write_buf.cpp

@ -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…
Cancel
Save