From ccb0ac1463222ed596939ee9989493e0c55a6677 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Wed, 25 Jun 2014 15:17:26 -0400 Subject: [PATCH] generate the controlfile data on the fly. closes #19 --- src/config.cpp | 12 ++---------- src/config.hpp | 8 +++----- src/fgetattr.cpp | 16 +++++++++++++++- src/getattr.cpp | 20 +++++++++++++++++--- src/mergerfs.cpp | 5 +---- src/option_parser.cpp | 8 +------- src/read.cpp | 2 +- src/read_buf.cpp | 2 +- src/setxattr.cpp | 2 -- src/write.cpp | 2 -- src/write_buf.cpp | 32 ++++++++++++++++---------------- 11 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index a443aca2..37473052 100644 --- a/src/config.cpp +++ b/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) { diff --git a/src/config.hpp b/src/config.hpp index 633575c9..5f44d878 100644 --- a/src/config.hpp +++ b/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); diff --git a/src/fgetattr.cpp b/src/fgetattr.cpp index 7103497e..0f0b77ce 100644 --- a/src/fgetattr.cpp +++ b/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); diff --git a/src/getattr.cpp b/src/getattr.cpp index 8e771cb0..53e8145a 100644 --- a/src/getattr.cpp +++ b/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); } } } diff --git a/src/mergerfs.cpp b/src/mergerfs.cpp index 0d3b0423..1133d89b 100644 --- a/src/mergerfs.cpp +++ b/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; } diff --git a/src/option_parser.cpp b/src/option_parser.cpp index b7be3b22..5be03890 100644 --- a/src/option_parser.cpp +++ b/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(); } } } diff --git a/src/read.cpp b/src/read.cpp index 403c0021..de419e37 100644 --- a/src/read.cpp +++ b/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); diff --git a/src/read_buf.cpp b/src/read_buf.cpp index c349005c..16a456f3 100644 --- a/src/read_buf.cpp +++ b/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); diff --git a/src/setxattr.cpp b/src/setxattr.cpp index 0106b3f9..f071d961 100644 --- a/src/setxattr.cpp +++ b/src/setxattr.cpp @@ -95,8 +95,6 @@ _setxattr_controlfile(config::Config &config, config.policies[*cat] = policy; - config.updateReadStr(); - return 0; #else return -ENOTSUP; diff --git a/src/write.cpp b/src/write.cpp index 110d368f..48e5c4b2 100644 --- a/src/write.cpp +++ b/src/write.cpp @@ -63,8 +63,6 @@ _process_kv(Config &config, config.policies[*cat] = policy; - config.updateReadStr(); - return 0; } diff --git a/src/write_buf.cpp b/src/write_buf.cpp index 19233cd0..c5886360 100644 --- a/src/write_buf.cpp +++ b/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); } }