Browse Source

generate the controlfile data on the fly. closes #19

pull/30/head 1.2.2
Antonio SJ Musumeci 11 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. 3
      src/mergerfs.cpp
  6. 6
      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]), : action(policies[0]),
create(policies[1]), create(policies[1]),
search(policies[2]), search(policies[2]),
controlfile("/.mergerfs"),
testmode(false)
controlfile("/.mergerfs")
{ {
action = &Policy::ff; action = &Policy::ff;
create = &Policy::epmfs; create = &Policy::epmfs;
@ -64,7 +63,7 @@ namespace mergerfs
} }
std::string std::string
Config::generateReadStr() const
Config::controlfiledata() const
{ {
std::stringstream ss; std::stringstream ss;
@ -75,13 +74,6 @@ namespace mergerfs
return ss.str(); return ss.str();
} }
void
Config::updateReadStr()
{
readstr = generateReadStr();
controlfilestat.st_size = readstr.size();
}
const Config& const Config&
get(void) get(void)
{ {

8
src/config.hpp

@ -42,8 +42,8 @@ namespace mergerfs
public: public:
Config(); Config();
std::string generateReadStr() const;
void updateReadStr();
public:
std::string controlfiledata() const;
public: public:
std::string destmount; std::string destmount;
@ -54,11 +54,9 @@ namespace mergerfs
const Policy *&create; const Policy *&create;
const Policy *&search; const Policy *&search;
public:
const std::string controlfile; const std::string controlfile;
struct stat controlfilestat; struct stat controlfilestat;
std::string readstr;
bool testmode;
}; };
const Config &get(void); const Config &get(void);

16
src/fgetattr.cpp

@ -32,6 +32,18 @@
#include "config.hpp" #include "config.hpp"
#include "fileinfo.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 static
int int
_fgetattr(const int fd, _fgetattr(const int fd,
@ -57,7 +69,9 @@ namespace mergerfs
const FileInfo *fileinfo = (FileInfo*)ffi->fh; const FileInfo *fileinfo = (FileInfo*)ffi->fh;
if(fusepath == config.controlfile) if(fusepath == config.controlfile)
return (*st = config.controlfilestat,0);
return _fgetattr_controlfile(config.controlfilestat,
config.controlfiledata(),
*st);
return _fgetattr(fileinfo->fd, return _fgetattr(fileinfo->fd,
*st); *st);

20
src/getattr.cpp

@ -41,6 +41,18 @@ using std::string;
using std::vector; using std::vector;
using mergerfs::Policy; 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 static
int int
_getattr(const fs::SearchFunc searchFunc, _getattr(const fs::SearchFunc searchFunc,
@ -66,19 +78,21 @@ namespace mergerfs
{ {
int int
getattr(const char *fusepath, getattr(const char *fusepath,
struct stat *buf)
struct stat *st)
{ {
const struct fuse_context *fc = fuse_get_context(); const struct fuse_context *fc = fuse_get_context();
const config::Config &config = config::get(); const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid); const ugid::SetResetGuard ugid(fc->uid,fc->gid);
if(fusepath == config.controlfile) if(fusepath == config.controlfile)
return (*buf = config.controlfilestat,0);
return _getattr_controlfile(config.controlfilestat,
config.controlfiledata(),
*st);
return _getattr(*config.search, return _getattr(*config.search,
config.srcmounts, config.srcmounts,
fusepath, fusepath,
*buf);
*st);
} }
} }
} }

3
src/mergerfs.cpp

@ -157,10 +157,7 @@ main(int argc,
mergerfs::options::parse(args,config); mergerfs::options::parse(args,config);
if(config.testmode == false)
rv = mergerfs::main(args,config); rv = mergerfs::main(args,config);
else
rv = mergerfs::test(args,config);
return rv; return rv;
} }

6
src/option_parser.cpp

@ -83,10 +83,6 @@ process_opt(config::Config &config,
break; break;
default: default:
case 1:
if(argvalue[0] == "test")
config.testmode = true;
else
rv = 1; rv = 1;
break; break;
}; };
@ -180,8 +176,6 @@ namespace mergerfs
::option_processor); ::option_processor);
set_fsname(args,config); set_fsname(args,config);
config.updateReadStr();
} }
} }
} }

2
src/read.cpp

@ -80,7 +80,7 @@ namespace mergerfs
const config::Config &config = config::get(); const config::Config &config = config::get();
if(fusepath == config.controlfile) if(fusepath == config.controlfile)
return _read_controlfile(config.readstr,
return _read_controlfile(config.controlfiledata(),
buf, buf,
count); count);

2
src/read_buf.cpp

@ -111,7 +111,7 @@ namespace mergerfs
const config::Config &config = config::get(); const config::Config &config = config::get();
if(fusepath == config.controlfile) if(fusepath == config.controlfile)
return _read_buf_controlfile(config.readstr,
return _read_buf_controlfile(config.controlfiledata(),
bufp, bufp,
size); size);

2
src/setxattr.cpp

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

2
src/write.cpp

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

32
src/write_buf.cpp

@ -36,18 +36,18 @@ using std::string;
static static
int int
_write_buf_controlfile(const string controlfile, _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; int rv;
size_t size; size_t size;
struct fuse_bufvec dst; struct fuse_bufvec dst;
size = fuse_buf_size(buf);
size = fuse_buf_size(&src);
dst = FUSE_BUFVEC_INIT(size); dst = FUSE_BUFVEC_INIT(size);
dst.buf->mem = malloc(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) if(rv < 0)
{ {
free(dst.buf->mem); free(dst.buf->mem);
@ -58,7 +58,7 @@ _write_buf_controlfile(const string controlfile,
(const char*)dst.buf->mem, (const char*)dst.buf->mem,
size, size,
0, 0,
fi);
&fi);
free(dst.buf->mem); free(dst.buf->mem);
return rv; return rv;
@ -67,19 +67,19 @@ _write_buf_controlfile(const string controlfile,
static static
int int
_write_buf(const int fd, _write_buf(const int fd,
struct fuse_bufvec *buf,
struct fuse_bufvec &src,
const off_t offset) 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 = const fuse_buf_copy_flags cpflags =
(fuse_buf_copy_flags)(FUSE_BUF_SPLICE_MOVE|FUSE_BUF_SPLICE_NONBLOCK); (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 namespace mergerfs
@ -88,7 +88,7 @@ namespace mergerfs
{ {
int int
write_buf(const char *fusepath, write_buf(const char *fusepath,
struct fuse_bufvec *buf,
struct fuse_bufvec *src,
off_t offset, off_t offset,
struct fuse_file_info *fi) struct fuse_file_info *fi)
{ {
@ -96,11 +96,11 @@ namespace mergerfs
if(fusepath == config.controlfile) if(fusepath == config.controlfile)
return _write_buf_controlfile(config.controlfile, return _write_buf_controlfile(config.controlfile,
buf,
fi);
*src,
*fi);
return _write_buf(((FileInfo*)fi->fh)->fd, return _write_buf(((FileInfo*)fi->fh)->fd,
buf,
*src,
offset); offset);
} }
} }

Loading…
Cancel
Save