From 328ed627c54165d75fc382487947ac05d7888027 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 15:12:40 +0000 Subject: Make more testable --- netfs/daemon/Jamfile.jam | 6 ++++++ netfs/daemon/daemon.cpp | 23 ++++++++++++++++------- netfs/daemon/daemon.h | 10 ++++++---- netfs/daemon/daemonService.h | 1 + 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index fd8c463..d42175d 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -50,6 +50,12 @@ lib netfsd : ..//IceBox ..//libxmlpp slicer-xml + : : + . + ../ice//netfsComms + netfsdConfiguration + netfsdConfiguration + ..//IceBox ; diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index d36e63f..6c231f9 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -8,19 +8,28 @@ #include "ioHelpers.h" #include +NetFSDaemon::NetFSDaemon(const Ice::CommunicatorPtr & i) : + ic(i) +{ +} + std::string NetFSDaemon::hostname() { - char buf[128]; - gethostname(buf, sizeof(buf)); - return buf; + auto props = ic->getProperties(); + auto hostNameOverride = props->getProperty("NetFSD.HostNameOverride"); + if (hostNameOverride.empty()) { + char buf[128]; + gethostname(buf, sizeof(buf)); + return buf; + } + return hostNameOverride; } // name = NetFSDaemonAdapter void -NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&) +NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr &, const Ice::StringSeq&) { - this->ic = ic; Ice::PropertiesPtr props = ic->getProperties(); LoadConfiguration(props->getProperty("NetFSD.ConfigPath")); @@ -49,9 +58,9 @@ NetFSDaemon::stop() extern "C" { IceBox::Service * - createNetFSDaemon(Ice::CommunicatorPtr) + createNetFSDaemon(Ice::CommunicatorPtr ic) { - return new NetFSDaemon(); + return new NetFSDaemon(ic); } } diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index 471a296..58d9f2f 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -9,17 +9,19 @@ class NetFSDaemon : public IceBox::Service { public: - virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&); - virtual void stop(); + NetFSDaemon(const Ice::CommunicatorPtr &); + + virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override; + virtual void stop() override; private: void LoadConfiguration(const boost::filesystem::path & path); - Ice::CommunicatorPtr ic; + const Ice::CommunicatorPtr ic; Ice::ObjectAdapterPtr adapter; NetFS::Daemon::RuntimeConfigurationPtr dc; - static std::string hostname(); + std::string hostname(); }; class TempPrivs { diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index 783ad96..ab52eee 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -3,6 +3,7 @@ #include #include +#include class ServiceServer : public NetFS::Service { public: -- cgit v1.2.3 From 741965b51e2b5c36bbf5f5e212f36a60a16aca07 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 15:32:25 +0000 Subject: Centralize slicer lib defs --- netfs/Jamfile.jam | 2 ++ netfs/daemon/Jamfile.jam | 8 +++----- netfs/fuse/Jamfile.jam | 10 ++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index d006225..dd8865e 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -14,6 +14,8 @@ lib IceUtil : : IceUtil ; lib IceBox : : IceBox ; lib pthread : : pthread ; lib fuse : : fuse ; +lib slicer : : : : /usr/include/slicer ; +lib slicer-xml : : : : /usr/include/slicer ; build-project daemon ; build-project fuse ; diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index d42175d..07bdcee 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -1,5 +1,3 @@ -lib slicer : : : : /usr/include/slicer ; -lib slicer-xml : : : : /usr/include/slicer ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -20,14 +18,14 @@ lib netfsdConfiguration : ..//pthread ..//boost_filesystem ..//boost_system - slicer + ..//slicer yes : : . ..//IceUtil ..//Ice ..//boost_system - slicer + ..//slicer ; lib netfsd : @@ -49,7 +47,7 @@ lib netfsd : ..//IceUtil ..//IceBox ..//libxmlpp - slicer-xml + ..//slicer-xml : : . ../ice//netfsComms diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 8223aa7..e7558f6 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,5 +1,3 @@ -lib slicer : : : : /usr/include/slicer ; -lib slicer-xml : : : : /usr/include/slicer ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -19,12 +17,12 @@ obj configuration : ..//Ice ..//IceUtil ..//pthread - slicer + ..//slicer : : ..//IceUtil ..//Ice ..//boost_system - slicer + ..//slicer ; exe netfs : @@ -46,8 +44,8 @@ exe netfs : ..//Ice ..//IceUtil ..//pthread - slicer + ..//slicer ..//libxmlpp - slicer-xml + ..//slicer-xml ; -- cgit v1.2.3 From c28bbc2c15ee0bcba3203c3b5011c3e86213bffd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 16:13:47 +0000 Subject: Refactor to make more testable --- libfusepp/Jamfile.jam | 5 -- libfusepp/fuseAppBase.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++ libfusepp/fuseAppBase.h | 162 +++++++++++++++++++++++++++++++++++ libfusepp/fuseapp.cpp | 214 ---------------------------------------------- libfusepp/fuseapp.h | 162 ----------------------------------- netfs/Jamfile.jam | 1 - netfs/fuse/Jamfile.jam | 22 ++++- netfs/fuse/fuse.cpp | 176 -------------------------------------- netfs/fuse/fuse.h | 115 ------------------------- netfs/fuse/fuseApp.cpp | 170 ++++++++++++++++++++++++++++++++++++ netfs/fuse/fuseApp.h | 115 +++++++++++++++++++++++++ netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/fuse/fuseSystem.cpp | 2 +- netfs/fuse/netfs.cpp | 8 ++ netfs/fuse/pch.hpp | 4 +- 17 files changed, 692 insertions(+), 684 deletions(-) delete mode 100644 libfusepp/Jamfile.jam create mode 100644 libfusepp/fuseAppBase.cpp create mode 100644 libfusepp/fuseAppBase.h delete mode 100644 libfusepp/fuseapp.cpp delete mode 100644 libfusepp/fuseapp.h delete mode 100644 netfs/fuse/fuse.cpp delete mode 100644 netfs/fuse/fuse.h create mode 100644 netfs/fuse/fuseApp.cpp create mode 100644 netfs/fuse/fuseApp.h create mode 100644 netfs/fuse/netfs.cpp diff --git a/libfusepp/Jamfile.jam b/libfusepp/Jamfile.jam deleted file mode 100644 index 1ba4a26..0000000 --- a/libfusepp/Jamfile.jam +++ /dev/null @@ -1,5 +0,0 @@ -project - : usage-requirements - . - ; - diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp new file mode 100644 index 0000000..4d9ca97 --- /dev/null +++ b/libfusepp/fuseAppBase.cpp @@ -0,0 +1,214 @@ +#include "fuseAppBase.h" +#include +#include +#include +#include +#include +#include + +FuseAppBase * FuseAppBase::fuseApp; + +FuseAppBase::FuseAppBase() +{ +} +FuseAppBase::~FuseAppBase() +{ +} +void * FuseAppBase::init(fuse_conn_info*) +{ + return NULL; +} +int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) +{ + return 1; +} +int FuseAppBase::access(const char *, int) +{ + return -ENOSYS; +} +int FuseAppBase::chmod(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::chown(const char *, uid_t, gid_t) +{ + return -ENOSYS; +} +int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flush(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::getattr(const char *, struct stat *) +{ + return -ENOSYS; +} +int FuseAppBase::getxattr(const char *, const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::link(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::listxattr(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::mkdir(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::mknod(const char *, mode_t, dev_t) +{ + return -ENOSYS; +} +int FuseAppBase::open(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::opendir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readlink(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::release(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::releasedir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::removexattr(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rename(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rmdir(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) +{ + return -ENOSYS; +} +int FuseAppBase::statfs(const char *, struct statvfs *) +{ + return -ENOSYS; +} +int FuseAppBase::symlink(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::truncate(const char *, off_t) +{ + return -ENOSYS; +} +int FuseAppBase::unlink(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) +{ + return -ENOSYS; +} +int FuseAppBase::utimens(const char *, const struct timespec[2]) +{ + return -ENOSYS; +} +int FuseAppBase::bmap(const char *, size_t, uint64_t *) +{ + return -ENOSYS; +} +int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) +{ + return -ENOSYS; +} +int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) +{ + return -ENOSYS; +} +int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flock(const char *, struct fuse_file_info *, int) +{ + return -ENOSYS; +} +int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::onError(const std::exception & e) throw() +{ + fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); + return -ENOSYS; +} + +void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) +{ + return fuseApp->init(conn); +} +void FuseAppBase::fuseDestroy(void *) +{ + delete fuseApp; +} + +struct fuse_args +FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) +{ + struct fuse_opt fuse_opts[] = { + { NULL, 0, 0 } + }; + fuseApp = fa; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + if (fuse_opt_parse(&args, fuseApp, fuse_opts, + fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { + exit(1); + } + return args; +} + diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h new file mode 100644 index 0000000..a320d36 --- /dev/null +++ b/libfusepp/fuseAppBase.h @@ -0,0 +1,162 @@ +#ifndef FUSEAPP_H +#define FUSEAPP_H + +#define FUSE_USE_VERSION 26 +#include +#include +#include +#include +#include + +class FuseAppBase { + public: + FuseAppBase(); + virtual ~FuseAppBase() = 0; + virtual void * init (struct fuse_conn_info * info); + virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); + virtual int access(const char *, int); + virtual int chmod(const char *, mode_t); + virtual int chown(const char *, uid_t, gid_t); + virtual int create(const char *, mode_t, struct fuse_file_info *); + virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); + virtual int flush(const char *, struct fuse_file_info *); + virtual int fsync(const char *, int, struct fuse_file_info *); + virtual int fsyncdir(const char *, int, struct fuse_file_info *); + virtual int ftruncate(const char *, off_t, struct fuse_file_info *); + virtual int getattr(const char *, struct stat *); + virtual int getxattr(const char *, const char *, char *, size_t); + virtual int link(const char *, const char *); + virtual int listxattr(const char *, char *, size_t); + virtual int mkdir(const char *, mode_t); + virtual int mknod(const char *, mode_t, dev_t); + virtual int open(const char *, struct fuse_file_info *); + virtual int opendir(const char *, struct fuse_file_info *); + virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); + virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); + virtual int readlink(const char *, char *, size_t); + virtual int release(const char *, struct fuse_file_info *); + virtual int releasedir(const char *, struct fuse_file_info *); + virtual int removexattr(const char *, const char *); + virtual int rename(const char *, const char *); + virtual int rmdir(const char *); + virtual int setxattr(const char *, const char *, const char *, size_t, int); + virtual int statfs(const char *, struct statvfs *); + virtual int symlink(const char *, const char *); + virtual int truncate(const char *, off_t); + virtual int unlink(const char *); + virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); + virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); + virtual int utimens(const char *, const struct timespec tv[2]); + virtual int bmap(const char *, size_t blocksize, uint64_t *idx); + virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); + virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); + virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); + virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); + virtual int flock(const char *, struct fuse_file_info *, int op); + virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); + virtual int onError(const std::exception & err) throw(); + +#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) + template + static int run(int & argc, char** & argv, FuseApp * fa) + { + auto args = runint(argc, argv, fa); + struct fuse_operations operations = { + fuseCall::GetHelper(getattr), + fuseCall::GetHelper(readlink), + NULL, // getdir deprecated + fuseCall::GetHelper(mknod), + fuseCall::GetHelper(mkdir), + fuseCall::GetHelper(unlink), + fuseCall::GetHelper(rmdir), + fuseCall::GetHelper(symlink), + fuseCall::GetHelper(rename), + fuseCall::GetHelper(link), + fuseCall::GetHelper(chmod), + fuseCall::GetHelper(chown), + fuseCall::GetHelper(truncate), + NULL, // utime deprecated + fuseCall::GetHelper(open), + fuseCall::GetHelper(read), + fuseCall::GetHelper(write), + fuseCall::GetHelper(statfs), + fuseCall::GetHelper(flush), + fuseCall::GetHelper(release), + fuseCall::GetHelper(fsync), + fuseCall::GetHelper(setxattr), + fuseCall::GetHelper(getxattr), + fuseCall::GetHelper(listxattr), + fuseCall::GetHelper(removexattr), + fuseCall::GetHelper(opendir), + fuseCall::GetHelper(readdir), + fuseCall::GetHelper(releasedir), + fuseCall::GetHelper(fsyncdir), + fuseInit, + fuseDestroy, + fuseCall::GetHelper(access), + fuseCall::GetHelper(create), + fuseCall::GetHelper(ftruncate), + fuseCall::GetHelper(fgetattr), +#if (FUSE_MINOR_VERSION >= 6) + fuseCall::GetHelper(lock), + fuseCall::GetHelper(utimens), + fuseCall::GetHelper(bmap), +#if (FUSE_MINOR_VERSION >= 8) + 0, // flag_nullpath_ok +#if (FUSE_MINOR_VERSION >= 9) + 0, // flag_nopath + 0, // flag_utime_omit_ok +#endif + 0, // flag_reserved + fuseCall::GetHelper(ioctl), + fuseCall::GetHelper(poll), +#if (FUSE_MINOR_VERSION >= 9) + fuseCall::GetHelper(write_buf), + fuseCall::GetHelper(read_buf), + fuseCall::GetHelper(flock), + fuseCall::GetHelper(fallocate), +#endif +#endif +#endif + }; + return fuse_main(args.argc, args.argv, &operations, fa); + } + private: + static struct fuse_args runint(int &, char ** &, FuseAppBase *); + static void * fuseInit(struct fuse_conn_info *conn); + static void fuseDestroy(void *); + + template + class fuseCall { + public: + typedef int (*WrapperFunc)(Args...); + template + static WrapperFunc getHelper(bool implemented) + { + auto func = &helper; + return implemented ? func : NULL; + } + template + static int helper(Args ... a) + { + try { + return (fuseApp->*f)(a...); + } + catch (const std::exception & ex) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; + } + return helper(a...); + } + catch (...) { + fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); + return -ENOSYS; + } + } + }; + + static FuseAppBase * fuseApp; +}; + +#endif + diff --git a/libfusepp/fuseapp.cpp b/libfusepp/fuseapp.cpp deleted file mode 100644 index 1a6494a..0000000 --- a/libfusepp/fuseapp.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "fuseapp.h" -#include -#include -#include -#include -#include -#include - -FuseAppBase * FuseAppBase::fuseApp; - -FuseAppBase::FuseAppBase() -{ -} -FuseAppBase::~FuseAppBase() -{ -} -void * FuseAppBase::init(fuse_conn_info*) -{ - return NULL; -} -int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) -{ - return 1; -} -int FuseAppBase::access(const char *, int) -{ - return -ENOSYS; -} -int FuseAppBase::chmod(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::chown(const char *, uid_t, gid_t) -{ - return -ENOSYS; -} -int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flush(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::getattr(const char *, struct stat *) -{ - return -ENOSYS; -} -int FuseAppBase::getxattr(const char *, const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::link(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::listxattr(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::mkdir(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::mknod(const char *, mode_t, dev_t) -{ - return -ENOSYS; -} -int FuseAppBase::open(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::opendir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readlink(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::release(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::releasedir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::removexattr(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rename(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rmdir(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) -{ - return -ENOSYS; -} -int FuseAppBase::statfs(const char *, struct statvfs *) -{ - return -ENOSYS; -} -int FuseAppBase::symlink(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::truncate(const char *, off_t) -{ - return -ENOSYS; -} -int FuseAppBase::unlink(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) -{ - return -ENOSYS; -} -int FuseAppBase::utimens(const char *, const struct timespec[2]) -{ - return -ENOSYS; -} -int FuseAppBase::bmap(const char *, size_t, uint64_t *) -{ - return -ENOSYS; -} -int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) -{ - return -ENOSYS; -} -int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) -{ - return -ENOSYS; -} -int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flock(const char *, struct fuse_file_info *, int) -{ - return -ENOSYS; -} -int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::onError(const std::exception & e) throw() -{ - fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); - return -ENOSYS; -} - -void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) -{ - return fuseApp->init(conn); -} -void FuseAppBase::fuseDestroy(void *) -{ - delete fuseApp; -} - -struct fuse_args -FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) -{ - struct fuse_opt fuse_opts[] = { - { NULL, 0, 0 } - }; - fuseApp = fa; - struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - if (fuse_opt_parse(&args, fuseApp, fuse_opts, - fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { - exit(1); - } - return args; -} - diff --git a/libfusepp/fuseapp.h b/libfusepp/fuseapp.h deleted file mode 100644 index a320d36..0000000 --- a/libfusepp/fuseapp.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef FUSEAPP_H -#define FUSEAPP_H - -#define FUSE_USE_VERSION 26 -#include -#include -#include -#include -#include - -class FuseAppBase { - public: - FuseAppBase(); - virtual ~FuseAppBase() = 0; - virtual void * init (struct fuse_conn_info * info); - virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); - virtual int access(const char *, int); - virtual int chmod(const char *, mode_t); - virtual int chown(const char *, uid_t, gid_t); - virtual int create(const char *, mode_t, struct fuse_file_info *); - virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); - virtual int flush(const char *, struct fuse_file_info *); - virtual int fsync(const char *, int, struct fuse_file_info *); - virtual int fsyncdir(const char *, int, struct fuse_file_info *); - virtual int ftruncate(const char *, off_t, struct fuse_file_info *); - virtual int getattr(const char *, struct stat *); - virtual int getxattr(const char *, const char *, char *, size_t); - virtual int link(const char *, const char *); - virtual int listxattr(const char *, char *, size_t); - virtual int mkdir(const char *, mode_t); - virtual int mknod(const char *, mode_t, dev_t); - virtual int open(const char *, struct fuse_file_info *); - virtual int opendir(const char *, struct fuse_file_info *); - virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); - virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); - virtual int readlink(const char *, char *, size_t); - virtual int release(const char *, struct fuse_file_info *); - virtual int releasedir(const char *, struct fuse_file_info *); - virtual int removexattr(const char *, const char *); - virtual int rename(const char *, const char *); - virtual int rmdir(const char *); - virtual int setxattr(const char *, const char *, const char *, size_t, int); - virtual int statfs(const char *, struct statvfs *); - virtual int symlink(const char *, const char *); - virtual int truncate(const char *, off_t); - virtual int unlink(const char *); - virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); - virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); - virtual int utimens(const char *, const struct timespec tv[2]); - virtual int bmap(const char *, size_t blocksize, uint64_t *idx); - virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); - virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); - virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); - virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); - virtual int flock(const char *, struct fuse_file_info *, int op); - virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); - virtual int onError(const std::exception & err) throw(); - -#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) - template - static int run(int & argc, char** & argv, FuseApp * fa) - { - auto args = runint(argc, argv, fa); - struct fuse_operations operations = { - fuseCall::GetHelper(getattr), - fuseCall::GetHelper(readlink), - NULL, // getdir deprecated - fuseCall::GetHelper(mknod), - fuseCall::GetHelper(mkdir), - fuseCall::GetHelper(unlink), - fuseCall::GetHelper(rmdir), - fuseCall::GetHelper(symlink), - fuseCall::GetHelper(rename), - fuseCall::GetHelper(link), - fuseCall::GetHelper(chmod), - fuseCall::GetHelper(chown), - fuseCall::GetHelper(truncate), - NULL, // utime deprecated - fuseCall::GetHelper(open), - fuseCall::GetHelper(read), - fuseCall::GetHelper(write), - fuseCall::GetHelper(statfs), - fuseCall::GetHelper(flush), - fuseCall::GetHelper(release), - fuseCall::GetHelper(fsync), - fuseCall::GetHelper(setxattr), - fuseCall::GetHelper(getxattr), - fuseCall::GetHelper(listxattr), - fuseCall::GetHelper(removexattr), - fuseCall::GetHelper(opendir), - fuseCall::GetHelper(readdir), - fuseCall::GetHelper(releasedir), - fuseCall::GetHelper(fsyncdir), - fuseInit, - fuseDestroy, - fuseCall::GetHelper(access), - fuseCall::GetHelper(create), - fuseCall::GetHelper(ftruncate), - fuseCall::GetHelper(fgetattr), -#if (FUSE_MINOR_VERSION >= 6) - fuseCall::GetHelper(lock), - fuseCall::GetHelper(utimens), - fuseCall::GetHelper(bmap), -#if (FUSE_MINOR_VERSION >= 8) - 0, // flag_nullpath_ok -#if (FUSE_MINOR_VERSION >= 9) - 0, // flag_nopath - 0, // flag_utime_omit_ok -#endif - 0, // flag_reserved - fuseCall::GetHelper(ioctl), - fuseCall::GetHelper(poll), -#if (FUSE_MINOR_VERSION >= 9) - fuseCall::GetHelper(write_buf), - fuseCall::GetHelper(read_buf), - fuseCall::GetHelper(flock), - fuseCall::GetHelper(fallocate), -#endif -#endif -#endif - }; - return fuse_main(args.argc, args.argv, &operations, fa); - } - private: - static struct fuse_args runint(int &, char ** &, FuseAppBase *); - static void * fuseInit(struct fuse_conn_info *conn); - static void fuseDestroy(void *); - - template - class fuseCall { - public: - typedef int (*WrapperFunc)(Args...); - template - static WrapperFunc getHelper(bool implemented) - { - auto func = &helper; - return implemented ? func : NULL; - } - template - static int helper(Args ... a) - { - try { - return (fuseApp->*f)(a...); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return helper(a...); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } - } - }; - - static FuseAppBase * fuseApp; -}; - -#endif - diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index dd8865e..70cd2d9 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -13,7 +13,6 @@ lib Ice : : Ice ; lib IceUtil : : IceUtil ; lib IceBox : : IceBox ; lib pthread : : pthread ; -lib fuse : : fuse ; lib slicer : : : : /usr/include/slicer ; lib slicer-xml : : : : /usr/include/slicer ; diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index e7558f6..acf757d 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,3 +1,4 @@ +lib fuse : : fuse ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -6,7 +7,7 @@ cpp-pch pch : pch.hpp : ../ice//netfsComms ../ice//netfsComms ..//boost_thread - ..//fuse + fuse ..//Ice ; @@ -25,10 +26,10 @@ obj configuration : ..//slicer ; -exe netfs : +lib netfsClient : pch configuration - [ glob *.cpp ] + [ glob *.cpp : netfs.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : _FILE_OFFSET_BITS=64 @@ -40,12 +41,25 @@ exe netfs : ../lib//netfsCommon ..//boost_thread ..//boost_system - ..//fuse + fuse ..//Ice ..//IceUtil ..//pthread ..//slicer ..//libxmlpp ..//slicer-xml + : : + . + ../../libfusepp + ../ice//netfsComms + ../ice//netfsComms + configuration + _FILE_OFFSET_BITS=64 + fuse + ; + +exe netfs : + netfs.cpp : + netfsClient ; diff --git a/netfs/fuse/fuse.cpp b/netfs/fuse/fuse.cpp deleted file mode 100644 index 7f90710..0000000 --- a/netfs/fuse/fuse.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "pch.hpp" -#include -#include "fuse.h" -#include "lockHelpers.h" -#include "cache.impl.h" -#include -#include -#include - -template class Cache>>; -template class OptimisticCallCacheable; - -NetFS::FuseApp::FuseApp(int & argc, char ** argv) : - _argc(argc), - _argv(argv), - openDirID(0), - openFileID(0) -{ -} - -NetFS::FuseApp::~FuseApp() -{ - for (const OpenDirs::value_type & of : openDirs) { - of.second->remote->close(); - } - for (const OpenFiles::value_type & of : openFiles) { - of.second->remote->close(); - } - if (volume) { - volume->disconnect(); - } - if (ic) { - ic->destroy(); - } -} - -void * -NetFS::FuseApp::init(struct fuse_conn_info *) -{ - ic = Ice::initialize(_argc, _argv); - fc = Slicer::Deserialize(configPath); - return NULL; -} - -int -NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) -{ - if (strncmp(arg, "--Ice.", 6) == 0) { - return 0; - } - else if (strncmp(arg, "_netdev", 7) == 0) { - return 0; - } - else if (arg[0] == '-') { - return 1; - } - else if (resourceName.empty()) { - const char * colon = strchr(arg, ':'); - resourceName = colon + 1; - configPath.assign(arg, colon); - return 0; - } - else if (mountPoint.empty()) { - mountPoint = arg; - return 1; - } - return 1; -} - -void -NetFS::FuseApp::connectToService() -{ - if (!service) { - Lock(_lock); - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such resource: " + resourceName); - } - - auto proxyAddr = e->second->ServiceIdentity; - for (const auto & ep : e->second->Endpoints) { - proxyAddr += ":" + ep; - } - service = NetFS::ServicePrx::checkedCast(ic->stringToProxy(proxyAddr)); - if (!service) { - throw std::runtime_error("Invalid service proxy: " + proxyAddr); - } - } -} - -void -NetFS::FuseApp::connectToVolume() -{ - if (!volume) { - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such export: " + resourceName); - } - volume = service->connect(e->second->ExportName, "bar"); - if (!volume) { - throw "Invalid filesystem proxy"; - } - } -} - -void -NetFS::FuseApp::connectHandles() -{ - for (const OpenFiles::value_type & of : openFiles) { - try { - of.second->remote->ice_ping(); - } - catch (const Ice::ObjectNotExistException &) { - of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags); - } - } - for (const OpenDirs::value_type & of : openDirs) { - try { - of.second->remote->ice_ping(); - } - catch (const Ice::ObjectNotExistException &) { - of.second->remote = volume->opendir(reqEnv(), of.second->path); - } - } -} - -void -NetFS::FuseApp::verifyConnection() -{ - Lock(_lock); - if (service) { - try { - service->ice_ping(); - } - catch (const Ice::Exception &) { - service = NULL; - } - } - if (volume) { - try { - volume->ice_ping(); - } - catch (const Ice::Exception &) { - volume = NULL; - } - } -} - -int -NetFS::FuseApp::onError(const std::exception & e) throw() -{ - if (dynamic_cast(&e)) { - verifyConnection(); - connectToService(); - connectToVolume(); - connectHandles(); - return 0; - } - return FuseAppBase::onError(e); -} - -NetFS::ReqEnv -NetFS::FuseApp::reqEnv() -{ - connectToService(); - connectToVolume(); - struct fuse_context * c = fuse_get_context(); - return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; -} - -int -main(int argc, char* argv[]) -{ - return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); -} - diff --git a/netfs/fuse/fuse.h b/netfs/fuse/fuse.h deleted file mode 100644 index 3821285..0000000 --- a/netfs/fuse/fuse.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef NETFS_FUSE_H -#define NETFS_FUSE_H - -#include -#include -#include -#include "fuseapp.h" -#include "configuration.h" -#include "cache.h" - -namespace NetFS { - class FuseApp : public FuseAppBase { - private: - class OpenDir : public IceUtil::Shared { - public: - OpenDir(DirectoryPrx remote, const std::string & path); - - DirectoryPrx remote; - const std::string path; - }; - typedef IceUtil::Handle OpenDirPtr; - typedef std::map OpenDirs; - - class OpenFile : public IceUtil::Shared { - public: - OpenFile(FilePrx remote, const std::string & path, int flags); - - FilePrx remote; - const std::string path; - const int flags; - }; - typedef IceUtil::Handle OpenFilePtr; - typedef std::map OpenFiles; - - public: - FuseApp(int & argc, char ** argv); - ~FuseApp(); - - private: - void * init (struct fuse_conn_info * info); - int opt_parse(void *, const char * arg, int key, struct fuse_args *); - - void connectToService(); - void connectToVolume(); - void connectHandles(); - void verifyConnection(); - - public: - // misc - int access(const char * p, int a); - int getattr(const char * p, struct stat * s); - int fgetattr(const char *, struct stat *, struct fuse_file_info *); - int chmod(const char *, mode_t); - int chown(const char *, uid_t, gid_t); - int link(const char *, const char *); - int readlink(const char *, char *, size_t); - int rename(const char *, const char *); - int symlink(const char *, const char *); - int unlink(const char *); - int utimens(const char *, const struct timespec tv[2]); - int mknod(const char *, mode_t, dev_t); - // dirs - int opendir(const char * p, struct fuse_file_info * fi); - int releasedir(const char *, struct fuse_file_info * fi); - int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi); - int mkdir(const char *, mode_t); - int rmdir(const char *); - // files - int open(const char * p, struct fuse_file_info * fi); - int create(const char *, mode_t, struct fuse_file_info *); - int release(const char *, struct fuse_file_info * fi); - int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi); - int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi); - int truncate(const char *, off_t); - int ftruncate(const char *, off_t, struct fuse_file_info *); - // fs - int statfs(const char *, struct statvfs *); - // stuff - int onError(const std::exception & err) throw(); - - private: - void setProxy(OpenFilePtr, uint64_t & fh); - OpenFilePtr getFileProxy(uint64_t localID) const; - void clearFileProxy(uint64_t localID); - - void setProxy(OpenDirPtr, uint64_t & fh); - OpenDirPtr getDirProxy(uint64_t localID) const; - void clearDirProxy(uint64_t localID); - - ReqEnv reqEnv(); - - int & _argc; - char ** _argv; - Ice::CommunicatorPtr ic; - Client::ConfigurationPtr fc; - mutable boost::shared_mutex _lock; - - NetFS::VolumePrx volume; - NetFS::ServicePrx service; - - std::string mountPoint; - std::string resourceName; - std::string configPath; - - OpenDirs openDirs; - int openDirID; - OpenFiles openFiles; - int openFileID; - - typedef Cache>> StatCache; - StatCache statCache; - }; -} - -#endif diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp new file mode 100644 index 0000000..841d670 --- /dev/null +++ b/netfs/fuse/fuseApp.cpp @@ -0,0 +1,170 @@ +#include "pch.hpp" +#include +#include "fuseApp.h" +#include "lockHelpers.h" +#include "cache.impl.h" +#include +#include +#include + +template class Cache>>; +template class OptimisticCallCacheable; + +NetFS::FuseApp::FuseApp(int & argc, char ** argv) : + _argc(argc), + _argv(argv), + openDirID(0), + openFileID(0) +{ +} + +NetFS::FuseApp::~FuseApp() +{ + for (const OpenDirs::value_type & of : openDirs) { + of.second->remote->close(); + } + for (const OpenFiles::value_type & of : openFiles) { + of.second->remote->close(); + } + if (volume) { + volume->disconnect(); + } + if (ic) { + ic->destroy(); + } +} + +void * +NetFS::FuseApp::init(struct fuse_conn_info *) +{ + ic = Ice::initialize(_argc, _argv); + fc = Slicer::Deserialize(configPath); + return NULL; +} + +int +NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) +{ + if (strncmp(arg, "--Ice.", 6) == 0) { + return 0; + } + else if (strncmp(arg, "_netdev", 7) == 0) { + return 0; + } + else if (arg[0] == '-') { + return 1; + } + else if (resourceName.empty()) { + const char * colon = strchr(arg, ':'); + resourceName = colon + 1; + configPath.assign(arg, colon); + return 0; + } + else if (mountPoint.empty()) { + mountPoint = arg; + return 1; + } + return 1; +} + +void +NetFS::FuseApp::connectToService() +{ + if (!service) { + Lock(_lock); + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such resource: " + resourceName); + } + + auto proxyAddr = e->second->ServiceIdentity; + for (const auto & ep : e->second->Endpoints) { + proxyAddr += ":" + ep; + } + service = NetFS::ServicePrx::checkedCast(ic->stringToProxy(proxyAddr)); + if (!service) { + throw std::runtime_error("Invalid service proxy: " + proxyAddr); + } + } +} + +void +NetFS::FuseApp::connectToVolume() +{ + if (!volume) { + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such export: " + resourceName); + } + volume = service->connect(e->second->ExportName, "bar"); + if (!volume) { + throw "Invalid filesystem proxy"; + } + } +} + +void +NetFS::FuseApp::connectHandles() +{ + for (const OpenFiles::value_type & of : openFiles) { + try { + of.second->remote->ice_ping(); + } + catch (const Ice::ObjectNotExistException &) { + of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags); + } + } + for (const OpenDirs::value_type & of : openDirs) { + try { + of.second->remote->ice_ping(); + } + catch (const Ice::ObjectNotExistException &) { + of.second->remote = volume->opendir(reqEnv(), of.second->path); + } + } +} + +void +NetFS::FuseApp::verifyConnection() +{ + Lock(_lock); + if (service) { + try { + service->ice_ping(); + } + catch (const Ice::Exception &) { + service = NULL; + } + } + if (volume) { + try { + volume->ice_ping(); + } + catch (const Ice::Exception &) { + volume = NULL; + } + } +} + +int +NetFS::FuseApp::onError(const std::exception & e) throw() +{ + if (dynamic_cast(&e)) { + verifyConnection(); + connectToService(); + connectToVolume(); + connectHandles(); + return 0; + } + return FuseAppBase::onError(e); +} + +NetFS::ReqEnv +NetFS::FuseApp::reqEnv() +{ + connectToService(); + connectToVolume(); + struct fuse_context * c = fuse_get_context(); + return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; +} + diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h new file mode 100644 index 0000000..f438910 --- /dev/null +++ b/netfs/fuse/fuseApp.h @@ -0,0 +1,115 @@ +#ifndef NETFS_FUSE_H +#define NETFS_FUSE_H + +#include +#include +#include +#include "fuseAppBase.h" +#include "configuration.h" +#include "cache.h" + +namespace NetFS { + class FuseApp : public FuseAppBase { + private: + class OpenDir : public IceUtil::Shared { + public: + OpenDir(DirectoryPrx remote, const std::string & path); + + DirectoryPrx remote; + const std::string path; + }; + typedef IceUtil::Handle OpenDirPtr; + typedef std::map OpenDirs; + + class OpenFile : public IceUtil::Shared { + public: + OpenFile(FilePrx remote, const std::string & path, int flags); + + FilePrx remote; + const std::string path; + const int flags; + }; + typedef IceUtil::Handle OpenFilePtr; + typedef std::map OpenFiles; + + public: + FuseApp(int & argc, char ** argv); + ~FuseApp(); + + private: + void * init (struct fuse_conn_info * info); + int opt_parse(void *, const char * arg, int key, struct fuse_args *); + + void connectToService(); + void connectToVolume(); + void connectHandles(); + void verifyConnection(); + + public: + // misc + int access(const char * p, int a); + int getattr(const char * p, struct stat * s); + int fgetattr(const char *, struct stat *, struct fuse_file_info *); + int chmod(const char *, mode_t); + int chown(const char *, uid_t, gid_t); + int link(const char *, const char *); + int readlink(const char *, char *, size_t); + int rename(const char *, const char *); + int symlink(const char *, const char *); + int unlink(const char *); + int utimens(const char *, const struct timespec tv[2]); + int mknod(const char *, mode_t, dev_t); + // dirs + int opendir(const char * p, struct fuse_file_info * fi); + int releasedir(const char *, struct fuse_file_info * fi); + int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi); + int mkdir(const char *, mode_t); + int rmdir(const char *); + // files + int open(const char * p, struct fuse_file_info * fi); + int create(const char *, mode_t, struct fuse_file_info *); + int release(const char *, struct fuse_file_info * fi); + int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi); + int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi); + int truncate(const char *, off_t); + int ftruncate(const char *, off_t, struct fuse_file_info *); + // fs + int statfs(const char *, struct statvfs *); + // stuff + int onError(const std::exception & err) throw(); + + private: + void setProxy(OpenFilePtr, uint64_t & fh); + OpenFilePtr getFileProxy(uint64_t localID) const; + void clearFileProxy(uint64_t localID); + + void setProxy(OpenDirPtr, uint64_t & fh); + OpenDirPtr getDirProxy(uint64_t localID) const; + void clearDirProxy(uint64_t localID); + + ReqEnv reqEnv(); + + int & _argc; + char ** _argv; + Ice::CommunicatorPtr ic; + Client::ConfigurationPtr fc; + mutable boost::shared_mutex _lock; + + NetFS::VolumePrx volume; + NetFS::ServicePrx service; + + std::string mountPoint; + std::string resourceName; + std::string configPath; + + OpenDirs openDirs; + int openDirID; + OpenFiles openFiles; + int openFileID; + + typedef Cache>> StatCache; + StatCache statCache; + }; +} + +#endif diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index 75cb5a5..ad3d017 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,5 +1,5 @@ #include "pch.hpp" -#include "fuse.h" +#include "fuseApp.h" #include "misc.h" #include "lockHelpers.h" #include diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index 9ce260c..b6cf8db 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,7 +1,7 @@ #include "pch.hpp" #include #include -#include "fuse.h" +#include "fuseApp.h" #include "lockHelpers.h" #include diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 0e366be..f6c5976 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -1,5 +1,5 @@ #include "pch.hpp" -#include "fuse.h" +#include "fuseApp.h" #include #include #include diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp index 0b29d86..36c6af5 100644 --- a/netfs/fuse/fuseSystem.cpp +++ b/netfs/fuse/fuseSystem.cpp @@ -1,6 +1,6 @@ #include "pch.hpp" #include -#include "fuse.h" +#include "fuseApp.h" int NetFS::FuseApp::statfs(const char * p, struct statvfs * vfs) diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp new file mode 100644 index 0000000..de89660 --- /dev/null +++ b/netfs/fuse/netfs.cpp @@ -0,0 +1,8 @@ +#include "fuseApp.h" + +int +main(int argc, char* argv[]) +{ + return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); +} + diff --git a/netfs/fuse/pch.hpp b/netfs/fuse/pch.hpp index 7cb79ed..b2a0908 100644 --- a/netfs/fuse/pch.hpp +++ b/netfs/fuse/pch.hpp @@ -3,11 +3,9 @@ #define NETFS_FUSE_PCH #include "../lib/pch.hpp" -#include "../../libfusepp/fuseapp.h" +#include "../../libfusepp/fuseAppBase.h" #include #endif #endif - - -- cgit v1.2.3 From f4e91dd5b16470bf6c3b5e6a01ff9e0804335bfc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 16:26:46 +0000 Subject: Rename configs for uniqueness --- netfs/daemon/Jamfile.jam | 2 +- netfs/daemon/configuration.ice | 34 ---------------------------------- netfs/daemon/daemon.h | 2 +- netfs/daemon/daemonConfig.ice | 34 ++++++++++++++++++++++++++++++++++ netfs/daemon/daemonService.h | 2 +- netfs/fuse/Jamfile.jam | 12 +++++++----- netfs/fuse/configuration.ice | 27 --------------------------- netfs/fuse/fuseApp.h | 2 +- netfs/fuse/fuseConfig.ice | 27 +++++++++++++++++++++++++++ 9 files changed, 72 insertions(+), 70 deletions(-) delete mode 100644 netfs/daemon/configuration.ice create mode 100644 netfs/daemon/daemonConfig.ice delete mode 100644 netfs/fuse/configuration.ice create mode 100644 netfs/fuse/fuseConfig.ice diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index 07bdcee..53ac99d 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -11,7 +11,7 @@ cpp-pch pch : pch.hpp : ; lib netfsdConfiguration : - configuration.ice + daemonConfig.ice : ..//Ice ..//IceUtil diff --git a/netfs/daemon/configuration.ice b/netfs/daemon/configuration.ice deleted file mode 100644 index bb77344..0000000 --- a/netfs/daemon/configuration.ice +++ /dev/null @@ -1,34 +0,0 @@ -module NetFS { - module Daemon { - class Host { - ["slicer:name:endpoint"] - string Endpoint; - }; - - ["slicer:key:hostname","slicer:value:host","slicer:item:host"] - dictionary HostMap; - - class Export { - ["slicer:name:root"] - string RootPath; - }; - - ["slicer:key:name","slicer:value:export","slicer:item:export"] - dictionary ExportMap; - - ["slicer:root:config"] - class Configuration { - ["slicer:name:exports"] - ExportMap Exports; - - ["slicer:name:hosts"] - HostMap Hosts; - }; - - ["slicer:ignore"] - class RuntimeConfiguration { - Configuration CurrentConfiguration; - Host Self; - }; - }; -}; diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index 58d9f2f..a43d7cd 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/netfs/daemon/daemonConfig.ice b/netfs/daemon/daemonConfig.ice new file mode 100644 index 0000000..bb77344 --- /dev/null +++ b/netfs/daemon/daemonConfig.ice @@ -0,0 +1,34 @@ +module NetFS { + module Daemon { + class Host { + ["slicer:name:endpoint"] + string Endpoint; + }; + + ["slicer:key:hostname","slicer:value:host","slicer:item:host"] + dictionary HostMap; + + class Export { + ["slicer:name:root"] + string RootPath; + }; + + ["slicer:key:name","slicer:value:export","slicer:item:export"] + dictionary ExportMap; + + ["slicer:root:config"] + class Configuration { + ["slicer:name:exports"] + ExportMap Exports; + + ["slicer:name:hosts"] + HostMap Hosts; + }; + + ["slicer:ignore"] + class RuntimeConfiguration { + Configuration CurrentConfiguration; + Host Self; + }; + }; +}; diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index ab52eee..345df2c 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class ServiceServer : public NetFS::Service { public: diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index acf757d..737c6c8 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -11,8 +11,8 @@ cpp-pch pch : pch.hpp : ..//Ice ; -obj configuration : - configuration.ice +lib netfsClientConfiguration : + fuseConfig.ice : yes ..//Ice @@ -28,7 +28,7 @@ obj configuration : lib netfsClient : pch - configuration + netfsClientConfiguration [ glob *.cpp : netfs.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : @@ -36,7 +36,8 @@ lib netfsClient : ../../libmisc ../../libfusepp ../ice//netfsComms - configuration + netfsClientConfiguration + netfsClientConfiguration ../ice//netfsComms ../lib//netfsCommon ..//boost_thread @@ -53,7 +54,8 @@ lib netfsClient : ../../libfusepp ../ice//netfsComms ../ice//netfsComms - configuration + netfsClientConfiguration + netfsClientConfiguration _FILE_OFFSET_BITS=64 fuse ; diff --git a/netfs/fuse/configuration.ice b/netfs/fuse/configuration.ice deleted file mode 100644 index db37770..0000000 --- a/netfs/fuse/configuration.ice +++ /dev/null @@ -1,27 +0,0 @@ -module NetFS { - module Client { - ["slicer:element:endpoint"] - sequence EndpointList; - - class Resource { - ["slicer:name:export"] - string ExportName; - - ["slicer:name:service"] - string ServiceIdentity = "Service"; - - ["slicer:name:endpoints"] - EndpointList Endpoints; - }; - - ["slicer:key:name","slicer:value:resource","slicer:item:resource"] - dictionary ResourceMap; - - ["slicer:root:config"] - class Configuration { - ["slicer:name:resources"] - ResourceMap Resources; - }; - }; -}; - diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index f438910..4eb01ff 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -5,7 +5,7 @@ #include #include #include "fuseAppBase.h" -#include "configuration.h" +#include "fuseConfig.h" #include "cache.h" namespace NetFS { diff --git a/netfs/fuse/fuseConfig.ice b/netfs/fuse/fuseConfig.ice new file mode 100644 index 0000000..db37770 --- /dev/null +++ b/netfs/fuse/fuseConfig.ice @@ -0,0 +1,27 @@ +module NetFS { + module Client { + ["slicer:element:endpoint"] + sequence EndpointList; + + class Resource { + ["slicer:name:export"] + string ExportName; + + ["slicer:name:service"] + string ServiceIdentity = "Service"; + + ["slicer:name:endpoints"] + EndpointList Endpoints; + }; + + ["slicer:key:name","slicer:value:resource","slicer:item:resource"] + dictionary ResourceMap; + + ["slicer:root:config"] + class Configuration { + ["slicer:name:resources"] + ResourceMap Resources; + }; + }; +}; + -- cgit v1.2.3 From 08d7f2d862ba04aede40546d9721dfe1f6c9a2eb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 17:11:20 +0000 Subject: Refactor fuse lib deps into final exe --- libfusepp/fuseAppBase.h | 6 ++++-- netfs/fuse/Jamfile.jam | 3 +-- netfs/fuse/fuseApp.h | 2 ++ netfs/fuse/netfs.cpp | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index a320d36..91ba22f 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -56,11 +56,13 @@ class FuseAppBase { virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); virtual int onError(const std::exception & err) throw(); + virtual int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc) = 0; + #define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) template static int run(int & argc, char** & argv, FuseApp * fa) { - auto args = runint(argc, argv, fa); + auto args = fa->runint(argc, argv, fa); struct fuse_operations operations = { fuseCall::GetHelper(getattr), fuseCall::GetHelper(readlink), @@ -122,7 +124,7 @@ class FuseAppBase { return fuse_main(args.argc, args.argv, &operations, fa); } private: - static struct fuse_args runint(int &, char ** &, FuseAppBase *); + struct fuse_args runint(int &, char ** &, FuseAppBase *); static void * fuseInit(struct fuse_conn_info *conn); static void fuseDestroy(void *); diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 737c6c8..c5d3a7a 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -42,7 +42,6 @@ lib netfsClient : ../lib//netfsCommon ..//boost_thread ..//boost_system - fuse ..//Ice ..//IceUtil ..//pthread @@ -57,11 +56,11 @@ lib netfsClient : netfsClientConfiguration netfsClientConfiguration _FILE_OFFSET_BITS=64 - fuse ; exe netfs : netfs.cpp : netfsClient + fuse ; diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index 4eb01ff..4786591 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -78,6 +78,8 @@ namespace NetFS { // stuff int onError(const std::exception & err) throw(); + virtual struct fuse_context * fuse_get_context() = 0; + private: void setProxy(OpenFilePtr, uint64_t & fh); OpenFilePtr getFileProxy(uint64_t localID) const; diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp index de89660..21689f2 100644 --- a/netfs/fuse/netfs.cpp +++ b/netfs/fuse/netfs.cpp @@ -1,8 +1,23 @@ #include "fuseApp.h" +class FuseImpl : public NetFS::FuseApp { + public: + FuseImpl(int & argc, char ** argv) : NetFS::FuseApp(argc, argv) { } + + struct fuse_context * fuse_get_context() override + { + return ::fuse_get_context(); + } + + int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt opts[], fuse_opt_proc_t proc) override + { + return ::fuse_opt_parse(args, data, opts, proc); + } +}; + int main(int argc, char* argv[]) { - return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); + return FuseAppBase::run(argc, argv, new FuseImpl(argc, argv)); } -- cgit v1.2.3 From fa4370c5e9b99ed5b8725d69fd25202e86eef347 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:06:53 +0000 Subject: Export the runint function --- libfusepp/fuseAppBase.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index 91ba22f..4b56f2f 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -123,8 +123,9 @@ class FuseAppBase { }; return fuse_main(args.argc, args.argv, &operations, fa); } - private: struct fuse_args runint(int &, char ** &, FuseAppBase *); + + private: static void * fuseInit(struct fuse_conn_info *conn); static void fuseDestroy(void *); -- cgit v1.2.3 From b95c6f132dcd1a1ba6222fe95e5e4bbaa97f4223 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:10:48 +0000 Subject: runint doesn't need a pointer to itself passing in --- libfusepp/fuseAppBase.cpp | 4 ++-- libfusepp/fuseAppBase.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp index 4d9ca97..4e34192 100644 --- a/libfusepp/fuseAppBase.cpp +++ b/libfusepp/fuseAppBase.cpp @@ -198,12 +198,12 @@ void FuseAppBase::fuseDestroy(void *) } struct fuse_args -FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) +FuseAppBase::runint(int & argc, char** & argv) { struct fuse_opt fuse_opts[] = { { NULL, 0, 0 } }; - fuseApp = fa; + fuseApp = this; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, fuseApp, fuse_opts, fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index 4b56f2f..73a809a 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -62,7 +62,7 @@ class FuseAppBase { template static int run(int & argc, char** & argv, FuseApp * fa) { - auto args = fa->runint(argc, argv, fa); + auto args = fa->runint(argc, argv); struct fuse_operations operations = { fuseCall::GetHelper(getattr), fuseCall::GetHelper(readlink), @@ -123,7 +123,7 @@ class FuseAppBase { }; return fuse_main(args.argc, args.argv, &operations, fa); } - struct fuse_args runint(int &, char ** &, FuseAppBase *); + struct fuse_args runint(int &, char ** &); private: static void * fuseInit(struct fuse_conn_info *conn); -- cgit v1.2.3 From b605cf0c2df5449e6ae3015662559edd266abd80 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:12:57 +0000 Subject: Add the start of some test framework, complete with hacky initialisations --- netfs/Jamfile.jam | 1 + netfs/unittests/Jamfile.jam | 28 +++++++++++++ netfs/unittests/client.xml | 14 +++++++ netfs/unittests/daemon.xml | 19 +++++++++ netfs/unittests/testCore.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 netfs/unittests/Jamfile.jam create mode 100644 netfs/unittests/client.xml create mode 100644 netfs/unittests/daemon.xml create mode 100644 netfs/unittests/testCore.cpp diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index 70cd2d9..6df8110 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -18,6 +18,7 @@ lib slicer-xml : : : : /usr/include/slicer ; build-project daemon ; build-project fuse ; +build-project unittests ; explicit install ; package.install install : : fuse//netfs : daemon//netfsd ; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam new file mode 100644 index 0000000..1c16bc7 --- /dev/null +++ b/netfs/unittests/Jamfile.jam @@ -0,0 +1,28 @@ +import testing ; + +lib boost_utf : : boost_unit_test_framework ; +lib boost_system ; +lib boost_filesystem ; +lib IceUtil ; +lib Ice ; + +path-constant me : . ; + +run + testCore.cpp + : : + client.xml + daemon.xml + : + BOOST_TEST_DYN_LINK + IceUtil + Ice + boost_system + boost_filesystem + boost_utf + ../daemon//netfsd + ../fuse//netfsClient + ../ice//netfsComms + ROOT=\"$(me)\" + : testCore ; + diff --git a/netfs/unittests/client.xml b/netfs/unittests/client.xml new file mode 100644 index 0000000..c159a24 --- /dev/null +++ b/netfs/unittests/client.xml @@ -0,0 +1,14 @@ + + + + + testvol + + unittest + + tcp -h localhost -p 4000 + + + + + diff --git a/netfs/unittests/daemon.xml b/netfs/unittests/daemon.xml new file mode 100644 index 0000000..8bf58a9 --- /dev/null +++ b/netfs/unittests/daemon.xml @@ -0,0 +1,19 @@ + + + + + unittest + + tcp -p 4000:udp -p 10000 + + + + + + unittest + + /usr/portage + + + + diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp new file mode 100644 index 0000000..b9a1836 --- /dev/null +++ b/netfs/unittests/testCore.cpp @@ -0,0 +1,95 @@ +#define BOOST_TEST_MODULE TestNetFSCore +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef ROOT +#error "ROOT needs to be defined at compilation time" +#endif + +#define XSTR(s) STR(s) +#define STR(s) #s +const boost::filesystem::path RootDir(XSTR(ROOT)); + +class FuseMock : public NetFS::FuseApp { + public: + FuseMock(int & argc, char ** argv) : + NetFS::FuseApp(argc, argv) + { + ::memset(&context, 0, sizeof(fuse_context)); + } + + struct fuse_context * fuse_get_context() override + { + return &context; + } + + int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override + { + for (int n = 0; n < args->argc; n += 1) { + proc(data, args->argv[n], n, args); + } + return 0; + } + private: + fuse_context context; +}; + +char * argv[] = { + strdup((RootDir / "client.xml:testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + +class Core { + public: + Core() : + params({}), + ic(Ice::initialize(params)), + daemon(ic), + argc(2), + fuse(new FuseMock(argc, argv)) + { + ic->getProperties()->setProperty("NetFSD.ConfigPath", (RootDir / "daemon.xml").string()); + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon.start("NetFSDaemonAdapter", ic, {}); + char ** a = argv; + fuse->runint(argc, a); + fuse->init(NULL); + } + + ~Core() + { + delete fuse; + ic->destroy(); + } + + protected: + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon daemon; + int argc; + FuseAppBase * fuse; +}; + +BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) + +BOOST_AUTO_TEST_CASE ( daemonInitialised ) +{ + auto service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service")); + BOOST_REQUIRE(service); + service->ice_ping(); +} + +BOOST_AUTO_TEST_CASE ( clientInitialised ) +{ + struct statvfs s; + fuse->statfs("/", &s); +} + +BOOST_AUTO_TEST_SUITE_END(); + -- cgit v1.2.3 From adc0ac88b077b8fa4f6545f1591483b918c50a48 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 18:45:06 +0000 Subject: Actually use precompiled headers --- netfs/daemon/daemon.cpp | 2 +- netfs/daemon/daemonDirectory.cpp | 2 +- netfs/daemon/daemonFile.cpp | 2 +- netfs/daemon/daemonService.cpp | 2 +- netfs/daemon/daemonVolume.cpp | 2 +- netfs/daemon/pch.hpp | 2 +- netfs/fuse/fuseApp.cpp | 2 +- netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/fuse/fuseSystem.cpp | 2 +- netfs/fuse/pch.hpp | 1 + netfs/lib/entCache.cpp | 2 +- netfs/lib/pch.hpp | 3 ++- 14 files changed, 15 insertions(+), 13 deletions(-) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index 6c231f9..0b7b64f 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include "daemon.h" #include "daemonService.h" diff --git a/netfs/daemon/daemonDirectory.cpp b/netfs/daemon/daemonDirectory.cpp index b43806f..b61b8be 100644 --- a/netfs/daemon/daemonDirectory.cpp +++ b/netfs/daemon/daemonDirectory.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index 79077a1..3268be8 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp index 4b9e804..fe587f1 100644 --- a/netfs/daemon/daemonService.cpp +++ b/netfs/daemon/daemonService.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "daemon.h" #include "daemonService.h" #include "daemonVolume.h" diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 0caead6..0cad47e 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include diff --git a/netfs/daemon/pch.hpp b/netfs/daemon/pch.hpp index 3229655..adc5ff2 100644 --- a/netfs/daemon/pch.hpp +++ b/netfs/daemon/pch.hpp @@ -6,8 +6,8 @@ #include #include "daemon.h" #include +#include #endif #endif - diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 841d670..2f3b288 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include "fuseApp.h" #include "lockHelpers.h" diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index ad3d017..156dae6 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "fuseApp.h" #include "misc.h" #include "lockHelpers.h" diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index b6cf8db..b8399f0 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include "fuseApp.h" diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index f6c5976..670c9ae 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "fuseApp.h" #include #include diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp index 36c6af5..e2a9ab7 100644 --- a/netfs/fuse/fuseSystem.cpp +++ b/netfs/fuse/fuseSystem.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include "fuseApp.h" diff --git a/netfs/fuse/pch.hpp b/netfs/fuse/pch.hpp index b2a0908..2342973 100644 --- a/netfs/fuse/pch.hpp +++ b/netfs/fuse/pch.hpp @@ -5,6 +5,7 @@ #include "../lib/pch.hpp" #include "../../libfusepp/fuseAppBase.h" #include +#include #endif #endif diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index a4cf27d..b07dda7 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "entCache.h" #include #include "lockHelpers.h" diff --git a/netfs/lib/pch.hpp b/netfs/lib/pch.hpp index ffd9890..fc37faa 100644 --- a/netfs/lib/pch.hpp +++ b/netfs/lib/pch.hpp @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include #include -- cgit v1.2.3 From e3beab35ef8c01bafc36e982dbca234cff44814e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 20:51:59 +0000 Subject: Program defined config files and sandbox --- netfs/daemon/daemon.cpp | 8 +++++++- netfs/daemon/daemon.h | 3 +++ netfs/fuse/fuseApp.cpp | 8 +++++++- netfs/fuse/fuseApp.h | 3 +++ netfs/unittests/Jamfile.jam | 2 -- netfs/unittests/client.xml | 14 ------------- netfs/unittests/daemon.xml | 19 ----------------- netfs/unittests/testCore.cpp | 49 +++++++++++++++++++++++++++++++++++++------- 8 files changed, 62 insertions(+), 44 deletions(-) delete mode 100644 netfs/unittests/client.xml delete mode 100644 netfs/unittests/daemon.xml diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index 0b7b64f..cf312bb 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -38,11 +38,17 @@ NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr &, const adapter->activate(); } +NetFS::Daemon::ConfigurationPtr +NetFSDaemon::ReadConfiguration(const boost::filesystem::path & path) const +{ + return Slicer::Deserialize(path); +} + void NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path) { dc = new NetFS::Daemon::RuntimeConfiguration(); - dc->CurrentConfiguration = Slicer::Deserialize(path); + dc->CurrentConfiguration = ReadConfiguration(path); auto selfItr = dc->CurrentConfiguration->Hosts.find(hostname()); if (selfItr == dc->CurrentConfiguration->Hosts.end()) { throw std::runtime_error("This host is not defined in the configuration."); diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index a43d7cd..8cf4d4a 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -14,6 +14,9 @@ class NetFSDaemon : public IceBox::Service { virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override; virtual void stop() override; + protected: + virtual NetFS::Daemon::ConfigurationPtr ReadConfiguration(const boost::filesystem::path & path) const; + private: void LoadConfiguration(const boost::filesystem::path & path); diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 2f3b288..d579271 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -34,11 +34,17 @@ NetFS::FuseApp::~FuseApp() } } +NetFS::Client::ConfigurationPtr +NetFS::FuseApp::ReadConfiguration(const std::string & path) const +{ + return Slicer::Deserialize(path); +} + void * NetFS::FuseApp::init(struct fuse_conn_info *) { ic = Ice::initialize(_argc, _argv); - fc = Slicer::Deserialize(configPath); + fc = ReadConfiguration(configPath); return NULL; } diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index 4786591..e514b55 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -80,6 +80,9 @@ namespace NetFS { virtual struct fuse_context * fuse_get_context() = 0; + protected: + virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const; + private: void setProxy(OpenFilePtr, uint64_t & fh); OpenFilePtr getFileProxy(uint64_t localID) const; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index 1c16bc7..af02411 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -11,8 +11,6 @@ path-constant me : . ; run testCore.cpp : : - client.xml - daemon.xml : BOOST_TEST_DYN_LINK IceUtil diff --git a/netfs/unittests/client.xml b/netfs/unittests/client.xml deleted file mode 100644 index c159a24..0000000 --- a/netfs/unittests/client.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - testvol - - unittest - - tcp -h localhost -p 4000 - - - - - diff --git a/netfs/unittests/daemon.xml b/netfs/unittests/daemon.xml deleted file mode 100644 index 8bf58a9..0000000 --- a/netfs/unittests/daemon.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - unittest - - tcp -p 4000:udp -p 10000 - - - - - - unittest - - /usr/portage - - - - diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index b9a1836..2262444 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -15,6 +14,26 @@ #define XSTR(s) STR(s) #define STR(s) #s const boost::filesystem::path RootDir(XSTR(ROOT)); +const boost::filesystem::path TestExportRoot(RootDir / "testExport"); + +std::string testEndpoint("tcp -h localhost -p 12012"); + +class MockDaemon : public NetFSDaemon { + public: + MockDaemon(const Ice::CommunicatorPtr & ic) : NetFSDaemon(ic) { } + + protected: + virtual NetFS::Daemon::ConfigurationPtr ReadConfiguration(const boost::filesystem::path &) const override + { + return new NetFS::Daemon::Configuration( + { + { "testvol", new NetFS::Daemon::Export(TestExportRoot.string()) } + }, + { + { "unittest", new NetFS::Daemon::Host(testEndpoint) } + }); + } +}; class FuseMock : public NetFS::FuseApp { public: @@ -36,12 +55,22 @@ class FuseMock : public NetFS::FuseApp { } return 0; } + + protected: + virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override + { + return new NetFS::Client::Configuration( + { + { "testvol", new NetFS::Client::Resource("testvol", "Service", { testEndpoint }) } + }); + } + private: fuse_context context; }; char * argv[] = { - strdup((RootDir / "client.xml:testvol").string().c_str()), + strdup((RootDir / ":testvol").string().c_str()), strdup((RootDir / "test").string().c_str()) }; @@ -50,13 +79,12 @@ class Core { Core() : params({}), ic(Ice::initialize(params)), - daemon(ic), + daemon(new MockDaemon(ic)), argc(2), fuse(new FuseMock(argc, argv)) { - ic->getProperties()->setProperty("NetFSD.ConfigPath", (RootDir / "daemon.xml").string()); ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); - daemon.start("NetFSDaemonAdapter", ic, {}); + daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; fuse->runint(argc, a); fuse->init(NULL); @@ -65,19 +93,26 @@ class Core { ~Core() { delete fuse; + delete daemon; ic->destroy(); } protected: Ice::StringSeq params; Ice::CommunicatorPtr ic; - NetFSDaemon daemon; + NetFSDaemon * daemon; int argc; FuseAppBase * fuse; }; BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) +BOOST_AUTO_TEST_CASE ( initializeSandbox ) +{ + boost::filesystem::remove_all(TestExportRoot); + boost::filesystem::create_directories(TestExportRoot); +} + BOOST_AUTO_TEST_CASE ( daemonInitialised ) { auto service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service")); @@ -88,7 +123,7 @@ BOOST_AUTO_TEST_CASE ( daemonInitialised ) BOOST_AUTO_TEST_CASE ( clientInitialised ) { struct statvfs s; - fuse->statfs("/", &s); + BOOST_REQUIRE_EQUAL(0, fuse->statfs("/", &s)); } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3 From 782535d80e06abe929632141b51023f2d6a179e4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 00:38:13 +0000 Subject: Fix error message --- libfusepp/fuseAppBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp index 4e34192..a1ea491 100644 --- a/libfusepp/fuseAppBase.cpp +++ b/libfusepp/fuseAppBase.cpp @@ -184,7 +184,7 @@ int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_inf } int FuseAppBase::onError(const std::exception & e) throw() { - fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); + fprintf(stderr, "Unknown exception (what: %s)\n", e.what()); return -ENOSYS; } -- cgit v1.2.3 From 1c6cb1da4ee0ff5cb13ae8e2460cf4677833f1bf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 00:39:33 +0000 Subject: Tear down adapter on daemon destruction --- netfs/daemon/daemon.cpp | 5 +++++ netfs/daemon/daemon.h | 1 + 2 files changed, 6 insertions(+) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index cf312bb..b5a2ddd 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -13,6 +13,11 @@ NetFSDaemon::NetFSDaemon(const Ice::CommunicatorPtr & i) : { } +NetFSDaemon::~NetFSDaemon() +{ + adapter->deactivate(); +} + std::string NetFSDaemon::hostname() { diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index 8cf4d4a..7ed5cb4 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -10,6 +10,7 @@ class NetFSDaemon : public IceBox::Service { public: NetFSDaemon(const Ice::CommunicatorPtr &); + virtual ~NetFSDaemon(); virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override; virtual void stop() override; -- cgit v1.2.3 From 2221efe5ca61ab78a0fbeb34954f3874bef0c39e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:14:04 +0000 Subject: Virtualise fues_main so that the ut framework can get access to the operations map --- libfusepp/fuseAppBase.h | 3 ++- netfs/fuse/netfs.cpp | 6 ++++++ netfs/unittests/testCore.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index 73a809a..d76fbff 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -57,6 +57,7 @@ class FuseAppBase { virtual int onError(const std::exception & err) throw(); virtual int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc) = 0; + virtual int main(int &, char **, const struct fuse_operations *) = 0; #define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) template @@ -121,7 +122,7 @@ class FuseAppBase { #endif #endif }; - return fuse_main(args.argc, args.argv, &operations, fa); + return fa->main(args.argc, args.argv, &operations); } struct fuse_args runint(int &, char ** &); diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp index 21689f2..f700a74 100644 --- a/netfs/fuse/netfs.cpp +++ b/netfs/fuse/netfs.cpp @@ -13,6 +13,12 @@ class FuseImpl : public NetFS::FuseApp { { return ::fuse_opt_parse(args, data, opts, proc); } + + int main(int & argc, char ** argv, const struct fuse_operations * ops) override + { + return ::fuse_main(argc, argv, ops, this); + } + }; int diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 2262444..3be4ed0 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -56,6 +56,12 @@ class FuseMock : public NetFS::FuseApp { return 0; } + int main(int &, char **, const struct fuse_operations * o) override + { + o->init(NULL); + return 0; + } + protected: virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override { @@ -86,8 +92,7 @@ class Core { ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; - fuse->runint(argc, a); - fuse->init(NULL); + FuseAppBase::run(argc, a, fuse); } ~Core() -- cgit v1.2.3 From 67cc0d9695b1c5ae5d9c7da16359aca1806556ba Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:16:34 +0000 Subject: Initialise the test context with sensible values --- netfs/unittests/testCore.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 3be4ed0..c1afbe3 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -41,6 +41,9 @@ class FuseMock : public NetFS::FuseApp { NetFS::FuseApp(argc, argv) { ::memset(&context, 0, sizeof(fuse_context)); + context.pid = getpid(); + context.uid = getuid(); + context.gid = getgid(); } struct fuse_context * fuse_get_context() override -- cgit v1.2.3 From 3d3f44390551777ce5d97bd5a206b8365cfc99c7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:17:54 +0000 Subject: Keep a copy of fuse operations map --- netfs/unittests/testCore.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index c1afbe3..0f74925 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -62,9 +62,12 @@ class FuseMock : public NetFS::FuseApp { int main(int &, char **, const struct fuse_operations * o) override { o->init(NULL); + ops = *o; return 0; } + fuse_operations ops; + protected: virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override { -- cgit v1.2.3 From 936bf79d6d5b8c67cf850ef8e510fcdd87622ca9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:19:36 +0000 Subject: Refactor mocked stuff in wrappers for easy setup/teardown and expose the fuse operations map instead of the app instance --- netfs/unittests/testCore.cpp | 72 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 0f74925..495c5a7 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -35,6 +35,35 @@ class MockDaemon : public NetFSDaemon { } }; +class MockDaemonHost { + public: + MockDaemonHost() : + params({}), + ic(Ice::initialize(params)), + daemon(new MockDaemon(ic)) + { + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon->start("NetFSDaemonAdapter", ic, {}); + + } + + ~MockDaemonHost() + { + delete daemon; + ic->destroy(); + } + + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon * daemon; +}; +typedef boost::shared_ptr MockDaemonHostPtr; + +char * argv[] = { + strdup((RootDir / ":testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + class FuseMock : public NetFS::FuseApp { public: FuseMock(int & argc, char ** argv) : @@ -81,39 +110,38 @@ class FuseMock : public NetFS::FuseApp { fuse_context context; }; -char * argv[] = { - strdup((RootDir / ":testvol").string().c_str()), - strdup((RootDir / "test").string().c_str()) -}; - -class Core { +class FuseMockHost { public: - Core() : - params({}), - ic(Ice::initialize(params)), - daemon(new MockDaemon(ic)), + FuseMockHost() : argc(2), - fuse(new FuseMock(argc, argv)) + app(new FuseMock(argc, argv)), + fuse(&app->ops) { - ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); - daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; - FuseAppBase::run(argc, a, fuse); + FuseAppBase::run(argc, a, app); } - ~Core() + int argc; + FuseMock * app; + fuse_operations * fuse; +}; + +class Core { + public: + Core() : + ic(daemonHost.ic), + daemon(daemonHost.daemon), + fuse(fuseHost.fuse) { - delete fuse; - delete daemon; - ic->destroy(); } protected: - Ice::StringSeq params; + MockDaemonHost daemonHost; + FuseMockHost fuseHost; + Ice::CommunicatorPtr ic; - NetFSDaemon * daemon; - int argc; - FuseAppBase * fuse; + NetFSDaemon * const daemon; + fuse_operations * fuse;; }; BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) -- cgit v1.2.3 From 83189328ed50206c7a9f129921af7645ff794146 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Feb 2015 15:27:47 +0000 Subject: Fix exception throwing on invalid fs proxy --- netfs/fuse/fuseApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index d579271..c90cc15 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -104,7 +104,7 @@ NetFS::FuseApp::connectToVolume() } volume = service->connect(e->second->ExportName, "bar"); if (!volume) { - throw "Invalid filesystem proxy"; + throw std::runtime_error("Invalid filesystem proxy"); } } } -- cgit v1.2.3 From ba9d2a97e038dff07d9b6c9ebf127c391122ea43 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Feb 2015 15:29:44 +0000 Subject: Add a test over reconnecting to daemon following a restart with open files --- netfs/unittests/testCore.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 495c5a7..ba330cd 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -167,3 +167,46 @@ BOOST_AUTO_TEST_CASE ( clientInitialised ) BOOST_AUTO_TEST_SUITE_END(); + +BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) +{ + MockDaemonHostPtr daemon(new MockDaemonHost()); + FuseMockHost fuse; + + struct statvfs s; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + + const char * fileName = "/createMe"; + BOOST_CHECKPOINT("Create a new file"); + struct fuse_file_info fh; + memset(&fh, 0, sizeof(fh)); + fh.flags = O_WRONLY | O_CREAT | O_APPEND; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->create(fileName, 0100644, &fh)); + BOOST_REQUIRE(fh.fh); + + BOOST_CHECKPOINT("Fetch file attributes"); + struct stat st; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + BOOST_REQUIRE_EQUAL(st.st_size, 0); + BOOST_REQUIRE_EQUAL(st.st_uid, getuid()); + BOOST_REQUIRE_EQUAL(st.st_gid, getgid()); + + BOOST_CHECKPOINT("Write some data"); + char someData[890]; + BOOST_REQUIRE_EQUAL(sizeof(someData), fuse.fuse->write(fileName, someData, sizeof(someData), 0, &fh)); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + BOOST_REQUIRE_EQUAL(st.st_size, sizeof(someData)); + + BOOST_CHECKPOINT("Delete old daemon object"); + daemon.reset(); + BOOST_CHECKPOINT("Create new daemon object"); + daemon = MockDaemonHostPtr(new MockDaemonHost()); + + BOOST_CHECKPOINT("Fetch file attributes again"); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + + BOOST_CHECKPOINT("Close file"); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); +} + -- cgit v1.2.3 From f5ff7d7c1162b1d8b603675566168d8b2f132141 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Mar 2015 20:04:24 +0000 Subject: Refactor to avoid possible destructed string copy --- netfs/daemon/daemon.cpp | 4 ++-- netfs/daemon/daemonFile.cpp | 2 +- netfs/daemon/daemonVolume.cpp | 2 +- netfs/fuse/fuseApp.cpp | 5 ++++- netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/ice/typeConvert.cpp | 8 ++++---- netfs/ice/typeConvert.h | 8 ++++---- netfs/lib/entCache.cpp | 16 +++++++++------- netfs/lib/entCache.h | 4 ++-- 11 files changed, 30 insertions(+), 25 deletions(-) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index b5a2ddd..3ad6294 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -76,8 +76,8 @@ extern "C" { } TempPrivs::TempPrivs(const NetFS::ReqEnv & re, const boost::filesystem::path & r) : - myu(UserEntCache::instance.getID(re.user)), - myg(GroupEntCache::instance.getID(re.grp)), + myu(UserEntCache::instance.getEntry(re.user)->id), + myg(GroupEntCache::instance.getEntry(re.grp)->id), root(r) { } diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index 3268be8..3acd1ca 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -36,7 +36,7 @@ FileServer::fgetattr(const NetFS::ReqEnv & re, const Ice::Current &) throw NetFS::SystemError(errno); } NetFS::Attr a; - a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1) }; + a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1, _2) }; return a; } diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 0cad47e..0556d9a 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -70,7 +70,7 @@ VolumeServer::getattr(const NetFS::ReqEnv & re, const std::string & path, const throw NetFS::SystemError(errno); } NetFS::Attr a; - a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1) }; + a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1, _2) }; return a; } diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index c90cc15..fdcce57 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -171,6 +171,9 @@ NetFS::FuseApp::reqEnv() connectToService(); connectToVolume(); struct fuse_context * c = fuse_get_context(); - return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; + NetFS::ReqEnv re; + UserEntCache::instance.getName(c->uid, &re.user); + GroupEntCache::instance.getName(c->gid, &re.grp); + return re; } diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index 156dae6..1da9484 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -79,7 +79,7 @@ NetFS::FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_ statCache.Add(new OptimisticCallCacheable( [asga,this]() { struct stat s; - s << AttrSource { volume->end_getattr(asga), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1) }; + s << AttrSource { volume->end_getattr(asga), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1, _2) }; return s; }, epath, time_t(NULL) + 2)); } diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index b8399f0..c6d4283 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -135,7 +135,7 @@ NetFS::FuseApp::fgetattr(const char *, struct stat * s, fuse_file_info * fi) { try { auto remote = getFileProxy(fi->fh)->remote; - *s << AttrSource { remote->fgetattr(reqEnv()), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1) }; + *s << AttrSource { remote->fgetattr(reqEnv()), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1, _2) }; return 0; } catch (NetFS::SystemError & e) { diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 670c9ae..1f999bd 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -19,7 +19,7 @@ NetFS::FuseApp::getattr(const char * p, struct stat * s) *s = *cacehedStat; } else { - *s << AttrSource { volume->getattr(reqEnv(), p), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1) }; + *s << AttrSource { volume->getattr(reqEnv(), p), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1, _2) }; } return 0; } diff --git a/netfs/ice/typeConvert.cpp b/netfs/ice/typeConvert.cpp index 538b894..cc3ee93 100644 --- a/netfs/ice/typeConvert.cpp +++ b/netfs/ice/typeConvert.cpp @@ -7,8 +7,8 @@ operator<<(struct stat & s, const AttrSource & a) s.st_ino = a.attr.inode; s.st_mode = a.attr.mode; s.st_nlink = a.attr.links; - s.st_uid = a.user(a.attr.uid); - s.st_gid = a.group(a.attr.gid); + a.user(a.attr.uid, &s.st_uid); + a.group(a.attr.gid, &s.st_gid); s.st_rdev = a.attr.rdev; s.st_size = a.attr.size; s.st_blksize = a.attr.blockSize; @@ -41,8 +41,8 @@ operator<<(NetFS::Attr & a, const struct StatSource & s) a.inode = s.stat.st_ino; a.mode = s.stat.st_mode; a.links = s.stat.st_nlink; - a.uid = s.user(s.stat.st_uid); - a.gid = s.group(s.stat.st_gid); + s.user(s.stat.st_uid, &a.uid); + s.group(s.stat.st_gid, &a.gid); a.rdev = s.stat.st_rdev; a.size = s.stat.st_size; a.blockSize = s.stat.st_blksize; diff --git a/netfs/ice/typeConvert.h b/netfs/ice/typeConvert.h index dd56a3f..13e2b44 100644 --- a/netfs/ice/typeConvert.h +++ b/netfs/ice/typeConvert.h @@ -3,11 +3,11 @@ #include #include -typedef boost::function UserIdLookup; -typedef boost::function GroupIdLookup; +typedef boost::function UserIdLookup; +typedef boost::function GroupIdLookup; -typedef boost::function UserNameLookup; -typedef boost::function GroupNameLookup; +typedef boost::function UserNameLookup; +typedef boost::function GroupNameLookup; struct AttrSource { const NetFS::Attr & attr; diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index b07dda7..286c017 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -17,17 +17,19 @@ EntCache::~EntCache() } template -const typename EntCache::id_t & -EntCache::getID(const EntCache::name_t & u) const +void +EntCache::getID(const EntCache::name_t & u, EntCache::id_t * target) const { - return getEntry(u)->id; + auto e = getEntry(u); + *target = e->id; } template -const typename EntCache::name_t & -EntCache::getName(const EntCache::id_t & u) const +void +EntCache::getName(const EntCache::id_t & u, EntCache::name_t * target) const { - return getEntry(u)->name; + auto e = getEntry(u); + *target = e->name; } template @@ -107,7 +109,7 @@ EntCache::fillCache() const auto g = new Group(grp->gr_gid, grp->gr_name); for (auto member = grp->gr_mem; *member; member++) { try { - g->members.insert(EntCache::instance.getID(*member)); + g->members.insert(EntCache::instance.getEntry((const name_t &)*member)->id); } catch (const NetFS::SystemError &) { } diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index ea941e8..443474f 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -38,8 +38,8 @@ class EntCache { virtual ~EntCache(); - const id_t & getID(const name_t & ) const; - const name_t & getName(const id_t &) const; + void getID(const name_t &, id_t *) const; + void getName(const id_t &, name_t *) const; template entry_ptr getEntry(const key_t &) const; -- cgit v1.2.3 From 18c02e406764898dfa43e18909285b0f0bb10ff4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 15:12:40 +0000 Subject: Make more testable --- netfs/daemon/Jamfile.jam | 6 ++++++ netfs/daemon/daemon.cpp | 23 ++++++++++++++++------- netfs/daemon/daemon.h | 10 ++++++---- netfs/daemon/daemonService.h | 1 + 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index fd8c463..d42175d 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -50,6 +50,12 @@ lib netfsd : ..//IceBox ..//libxmlpp slicer-xml + : : + . + ../ice//netfsComms + netfsdConfiguration + netfsdConfiguration + ..//IceBox ; diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index d36e63f..6c231f9 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -8,19 +8,28 @@ #include "ioHelpers.h" #include +NetFSDaemon::NetFSDaemon(const Ice::CommunicatorPtr & i) : + ic(i) +{ +} + std::string NetFSDaemon::hostname() { - char buf[128]; - gethostname(buf, sizeof(buf)); - return buf; + auto props = ic->getProperties(); + auto hostNameOverride = props->getProperty("NetFSD.HostNameOverride"); + if (hostNameOverride.empty()) { + char buf[128]; + gethostname(buf, sizeof(buf)); + return buf; + } + return hostNameOverride; } // name = NetFSDaemonAdapter void -NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&) +NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr &, const Ice::StringSeq&) { - this->ic = ic; Ice::PropertiesPtr props = ic->getProperties(); LoadConfiguration(props->getProperty("NetFSD.ConfigPath")); @@ -49,9 +58,9 @@ NetFSDaemon::stop() extern "C" { IceBox::Service * - createNetFSDaemon(Ice::CommunicatorPtr) + createNetFSDaemon(Ice::CommunicatorPtr ic) { - return new NetFSDaemon(); + return new NetFSDaemon(ic); } } diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index 471a296..58d9f2f 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -9,17 +9,19 @@ class NetFSDaemon : public IceBox::Service { public: - virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&); - virtual void stop(); + NetFSDaemon(const Ice::CommunicatorPtr &); + + virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override; + virtual void stop() override; private: void LoadConfiguration(const boost::filesystem::path & path); - Ice::CommunicatorPtr ic; + const Ice::CommunicatorPtr ic; Ice::ObjectAdapterPtr adapter; NetFS::Daemon::RuntimeConfigurationPtr dc; - static std::string hostname(); + std::string hostname(); }; class TempPrivs { diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index 783ad96..ab52eee 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -3,6 +3,7 @@ #include #include +#include class ServiceServer : public NetFS::Service { public: -- cgit v1.2.3 From cd98c8df4158982bcce108fb14bcd3d98b291177 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 15:32:25 +0000 Subject: Centralize slicer lib defs --- netfs/Jamfile.jam | 2 ++ netfs/daemon/Jamfile.jam | 8 +++----- netfs/fuse/Jamfile.jam | 10 ++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index d006225..dd8865e 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -14,6 +14,8 @@ lib IceUtil : : IceUtil ; lib IceBox : : IceBox ; lib pthread : : pthread ; lib fuse : : fuse ; +lib slicer : : : : /usr/include/slicer ; +lib slicer-xml : : : : /usr/include/slicer ; build-project daemon ; build-project fuse ; diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index d42175d..07bdcee 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -1,5 +1,3 @@ -lib slicer : : : : /usr/include/slicer ; -lib slicer-xml : : : : /usr/include/slicer ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -20,14 +18,14 @@ lib netfsdConfiguration : ..//pthread ..//boost_filesystem ..//boost_system - slicer + ..//slicer yes : : . ..//IceUtil ..//Ice ..//boost_system - slicer + ..//slicer ; lib netfsd : @@ -49,7 +47,7 @@ lib netfsd : ..//IceUtil ..//IceBox ..//libxmlpp - slicer-xml + ..//slicer-xml : : . ../ice//netfsComms diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 8223aa7..e7558f6 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,5 +1,3 @@ -lib slicer : : : : /usr/include/slicer ; -lib slicer-xml : : : : /usr/include/slicer ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -19,12 +17,12 @@ obj configuration : ..//Ice ..//IceUtil ..//pthread - slicer + ..//slicer : : ..//IceUtil ..//Ice ..//boost_system - slicer + ..//slicer ; exe netfs : @@ -46,8 +44,8 @@ exe netfs : ..//Ice ..//IceUtil ..//pthread - slicer + ..//slicer ..//libxmlpp - slicer-xml + ..//slicer-xml ; -- cgit v1.2.3 From f46bafac28550d6b0c1ef61d8e3c15d26b40b298 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 16:13:47 +0000 Subject: Refactor to make more testable --- libfusepp/Jamfile.jam | 5 -- libfusepp/fuseAppBase.cpp | 214 ++++++++++++++++++++++++++++++++++++++++++++++ libfusepp/fuseAppBase.h | 162 +++++++++++++++++++++++++++++++++++ libfusepp/fuseapp.cpp | 214 ---------------------------------------------- libfusepp/fuseapp.h | 162 ----------------------------------- netfs/Jamfile.jam | 1 - netfs/fuse/Jamfile.jam | 22 ++++- netfs/fuse/fuse.cpp | 176 -------------------------------------- netfs/fuse/fuse.h | 115 ------------------------- netfs/fuse/fuseApp.cpp | 170 ++++++++++++++++++++++++++++++++++++ netfs/fuse/fuseApp.h | 115 +++++++++++++++++++++++++ netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/fuse/fuseSystem.cpp | 2 +- netfs/fuse/netfs.cpp | 8 ++ netfs/fuse/pch.hpp | 4 +- 17 files changed, 692 insertions(+), 684 deletions(-) delete mode 100644 libfusepp/Jamfile.jam create mode 100644 libfusepp/fuseAppBase.cpp create mode 100644 libfusepp/fuseAppBase.h delete mode 100644 libfusepp/fuseapp.cpp delete mode 100644 libfusepp/fuseapp.h delete mode 100644 netfs/fuse/fuse.cpp delete mode 100644 netfs/fuse/fuse.h create mode 100644 netfs/fuse/fuseApp.cpp create mode 100644 netfs/fuse/fuseApp.h create mode 100644 netfs/fuse/netfs.cpp diff --git a/libfusepp/Jamfile.jam b/libfusepp/Jamfile.jam deleted file mode 100644 index 1ba4a26..0000000 --- a/libfusepp/Jamfile.jam +++ /dev/null @@ -1,5 +0,0 @@ -project - : usage-requirements - . - ; - diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp new file mode 100644 index 0000000..4d9ca97 --- /dev/null +++ b/libfusepp/fuseAppBase.cpp @@ -0,0 +1,214 @@ +#include "fuseAppBase.h" +#include +#include +#include +#include +#include +#include + +FuseAppBase * FuseAppBase::fuseApp; + +FuseAppBase::FuseAppBase() +{ +} +FuseAppBase::~FuseAppBase() +{ +} +void * FuseAppBase::init(fuse_conn_info*) +{ + return NULL; +} +int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) +{ + return 1; +} +int FuseAppBase::access(const char *, int) +{ + return -ENOSYS; +} +int FuseAppBase::chmod(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::chown(const char *, uid_t, gid_t) +{ + return -ENOSYS; +} +int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flush(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::getattr(const char *, struct stat *) +{ + return -ENOSYS; +} +int FuseAppBase::getxattr(const char *, const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::link(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::listxattr(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::mkdir(const char *, mode_t) +{ + return -ENOSYS; +} +int FuseAppBase::mknod(const char *, mode_t, dev_t) +{ + return -ENOSYS; +} +int FuseAppBase::open(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::opendir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::readlink(const char *, char *, size_t) +{ + return -ENOSYS; +} +int FuseAppBase::release(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::releasedir(const char *, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::removexattr(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rename(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::rmdir(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) +{ + return -ENOSYS; +} +int FuseAppBase::statfs(const char *, struct statvfs *) +{ + return -ENOSYS; +} +int FuseAppBase::symlink(const char *, const char *) +{ + return -ENOSYS; +} +int FuseAppBase::truncate(const char *, off_t) +{ + return -ENOSYS; +} +int FuseAppBase::unlink(const char *) +{ + return -ENOSYS; +} +int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) +{ + return -ENOSYS; +} +int FuseAppBase::utimens(const char *, const struct timespec[2]) +{ + return -ENOSYS; +} +int FuseAppBase::bmap(const char *, size_t, uint64_t *) +{ + return -ENOSYS; +} +int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) +{ + return -ENOSYS; +} +int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) +{ + return -ENOSYS; +} +int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::flock(const char *, struct fuse_file_info *, int) +{ + return -ENOSYS; +} +int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) +{ + return -ENOSYS; +} +int FuseAppBase::onError(const std::exception & e) throw() +{ + fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); + return -ENOSYS; +} + +void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) +{ + return fuseApp->init(conn); +} +void FuseAppBase::fuseDestroy(void *) +{ + delete fuseApp; +} + +struct fuse_args +FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) +{ + struct fuse_opt fuse_opts[] = { + { NULL, 0, 0 } + }; + fuseApp = fa; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + if (fuse_opt_parse(&args, fuseApp, fuse_opts, + fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { + exit(1); + } + return args; +} + diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h new file mode 100644 index 0000000..a320d36 --- /dev/null +++ b/libfusepp/fuseAppBase.h @@ -0,0 +1,162 @@ +#ifndef FUSEAPP_H +#define FUSEAPP_H + +#define FUSE_USE_VERSION 26 +#include +#include +#include +#include +#include + +class FuseAppBase { + public: + FuseAppBase(); + virtual ~FuseAppBase() = 0; + virtual void * init (struct fuse_conn_info * info); + virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); + virtual int access(const char *, int); + virtual int chmod(const char *, mode_t); + virtual int chown(const char *, uid_t, gid_t); + virtual int create(const char *, mode_t, struct fuse_file_info *); + virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); + virtual int flush(const char *, struct fuse_file_info *); + virtual int fsync(const char *, int, struct fuse_file_info *); + virtual int fsyncdir(const char *, int, struct fuse_file_info *); + virtual int ftruncate(const char *, off_t, struct fuse_file_info *); + virtual int getattr(const char *, struct stat *); + virtual int getxattr(const char *, const char *, char *, size_t); + virtual int link(const char *, const char *); + virtual int listxattr(const char *, char *, size_t); + virtual int mkdir(const char *, mode_t); + virtual int mknod(const char *, mode_t, dev_t); + virtual int open(const char *, struct fuse_file_info *); + virtual int opendir(const char *, struct fuse_file_info *); + virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); + virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); + virtual int readlink(const char *, char *, size_t); + virtual int release(const char *, struct fuse_file_info *); + virtual int releasedir(const char *, struct fuse_file_info *); + virtual int removexattr(const char *, const char *); + virtual int rename(const char *, const char *); + virtual int rmdir(const char *); + virtual int setxattr(const char *, const char *, const char *, size_t, int); + virtual int statfs(const char *, struct statvfs *); + virtual int symlink(const char *, const char *); + virtual int truncate(const char *, off_t); + virtual int unlink(const char *); + virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); + virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); + virtual int utimens(const char *, const struct timespec tv[2]); + virtual int bmap(const char *, size_t blocksize, uint64_t *idx); + virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); + virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); + virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); + virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); + virtual int flock(const char *, struct fuse_file_info *, int op); + virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); + virtual int onError(const std::exception & err) throw(); + +#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) + template + static int run(int & argc, char** & argv, FuseApp * fa) + { + auto args = runint(argc, argv, fa); + struct fuse_operations operations = { + fuseCall::GetHelper(getattr), + fuseCall::GetHelper(readlink), + NULL, // getdir deprecated + fuseCall::GetHelper(mknod), + fuseCall::GetHelper(mkdir), + fuseCall::GetHelper(unlink), + fuseCall::GetHelper(rmdir), + fuseCall::GetHelper(symlink), + fuseCall::GetHelper(rename), + fuseCall::GetHelper(link), + fuseCall::GetHelper(chmod), + fuseCall::GetHelper(chown), + fuseCall::GetHelper(truncate), + NULL, // utime deprecated + fuseCall::GetHelper(open), + fuseCall::GetHelper(read), + fuseCall::GetHelper(write), + fuseCall::GetHelper(statfs), + fuseCall::GetHelper(flush), + fuseCall::GetHelper(release), + fuseCall::GetHelper(fsync), + fuseCall::GetHelper(setxattr), + fuseCall::GetHelper(getxattr), + fuseCall::GetHelper(listxattr), + fuseCall::GetHelper(removexattr), + fuseCall::GetHelper(opendir), + fuseCall::GetHelper(readdir), + fuseCall::GetHelper(releasedir), + fuseCall::GetHelper(fsyncdir), + fuseInit, + fuseDestroy, + fuseCall::GetHelper(access), + fuseCall::GetHelper(create), + fuseCall::GetHelper(ftruncate), + fuseCall::GetHelper(fgetattr), +#if (FUSE_MINOR_VERSION >= 6) + fuseCall::GetHelper(lock), + fuseCall::GetHelper(utimens), + fuseCall::GetHelper(bmap), +#if (FUSE_MINOR_VERSION >= 8) + 0, // flag_nullpath_ok +#if (FUSE_MINOR_VERSION >= 9) + 0, // flag_nopath + 0, // flag_utime_omit_ok +#endif + 0, // flag_reserved + fuseCall::GetHelper(ioctl), + fuseCall::GetHelper(poll), +#if (FUSE_MINOR_VERSION >= 9) + fuseCall::GetHelper(write_buf), + fuseCall::GetHelper(read_buf), + fuseCall::GetHelper(flock), + fuseCall::GetHelper(fallocate), +#endif +#endif +#endif + }; + return fuse_main(args.argc, args.argv, &operations, fa); + } + private: + static struct fuse_args runint(int &, char ** &, FuseAppBase *); + static void * fuseInit(struct fuse_conn_info *conn); + static void fuseDestroy(void *); + + template + class fuseCall { + public: + typedef int (*WrapperFunc)(Args...); + template + static WrapperFunc getHelper(bool implemented) + { + auto func = &helper; + return implemented ? func : NULL; + } + template + static int helper(Args ... a) + { + try { + return (fuseApp->*f)(a...); + } + catch (const std::exception & ex) { + if (int rtn = fuseApp->onError(ex)) { + return rtn; + } + return helper(a...); + } + catch (...) { + fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); + return -ENOSYS; + } + } + }; + + static FuseAppBase * fuseApp; +}; + +#endif + diff --git a/libfusepp/fuseapp.cpp b/libfusepp/fuseapp.cpp deleted file mode 100644 index 1a6494a..0000000 --- a/libfusepp/fuseapp.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "fuseapp.h" -#include -#include -#include -#include -#include -#include - -FuseAppBase * FuseAppBase::fuseApp; - -FuseAppBase::FuseAppBase() -{ -} -FuseAppBase::~FuseAppBase() -{ -} -void * FuseAppBase::init(fuse_conn_info*) -{ - return NULL; -} -int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*) -{ - return 1; -} -int FuseAppBase::access(const char *, int) -{ - return -ENOSYS; -} -int FuseAppBase::chmod(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::chown(const char *, uid_t, gid_t) -{ - return -ENOSYS; -} -int FuseAppBase::create(const char *, mode_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fgetattr(const char *, struct stat *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flush(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsync(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::fsyncdir(const char *, int, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::ftruncate(const char *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::getattr(const char *, struct stat *) -{ - return -ENOSYS; -} -int FuseAppBase::getxattr(const char *, const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::link(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::listxattr(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::mkdir(const char *, mode_t) -{ - return -ENOSYS; -} -int FuseAppBase::mknod(const char *, mode_t, dev_t) -{ - return -ENOSYS; -} -int FuseAppBase::open(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::opendir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read(const char *, char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::readlink(const char *, char *, size_t) -{ - return -ENOSYS; -} -int FuseAppBase::release(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::releasedir(const char *, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::removexattr(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rename(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::rmdir(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::setxattr(const char *, const char *, const char *, size_t, int) -{ - return -ENOSYS; -} -int FuseAppBase::statfs(const char *, struct statvfs *) -{ - return -ENOSYS; -} -int FuseAppBase::symlink(const char *, const char *) -{ - return -ENOSYS; -} -int FuseAppBase::truncate(const char *, off_t) -{ - return -ENOSYS; -} -int FuseAppBase::unlink(const char *) -{ - return -ENOSYS; -} -int FuseAppBase::write(const char *, const char *, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *) -{ - return -ENOSYS; -} -int FuseAppBase::utimens(const char *, const struct timespec[2]) -{ - return -ENOSYS; -} -int FuseAppBase::bmap(const char *, size_t, uint64_t *) -{ - return -ENOSYS; -} -int FuseAppBase::ioctl(const char *, int, void *, struct fuse_file_info *, unsigned int, void *) -{ - return -ENOSYS; -} -int FuseAppBase::poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *) -{ - return -ENOSYS; -} -int FuseAppBase::write_buf(const char *, struct fuse_bufvec *, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::read_buf(const char *, struct fuse_bufvec **, size_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::flock(const char *, struct fuse_file_info *, int) -{ - return -ENOSYS; -} -int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_info *) -{ - return -ENOSYS; -} -int FuseAppBase::onError(const std::exception & e) throw() -{ - fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); - return -ENOSYS; -} - -void * FuseAppBase::fuseInit (struct fuse_conn_info *conn) -{ - return fuseApp->init(conn); -} -void FuseAppBase::fuseDestroy(void *) -{ - delete fuseApp; -} - -struct fuse_args -FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) -{ - struct fuse_opt fuse_opts[] = { - { NULL, 0, 0 } - }; - fuseApp = fa; - struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - if (fuse_opt_parse(&args, fuseApp, fuse_opts, - fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { - exit(1); - } - return args; -} - diff --git a/libfusepp/fuseapp.h b/libfusepp/fuseapp.h deleted file mode 100644 index a320d36..0000000 --- a/libfusepp/fuseapp.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef FUSEAPP_H -#define FUSEAPP_H - -#define FUSE_USE_VERSION 26 -#include -#include -#include -#include -#include - -class FuseAppBase { - public: - FuseAppBase(); - virtual ~FuseAppBase() = 0; - virtual void * init (struct fuse_conn_info * info); - virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *); - virtual int access(const char *, int); - virtual int chmod(const char *, mode_t); - virtual int chown(const char *, uid_t, gid_t); - virtual int create(const char *, mode_t, struct fuse_file_info *); - virtual int fgetattr(const char *, struct stat *, struct fuse_file_info *); - virtual int flush(const char *, struct fuse_file_info *); - virtual int fsync(const char *, int, struct fuse_file_info *); - virtual int fsyncdir(const char *, int, struct fuse_file_info *); - virtual int ftruncate(const char *, off_t, struct fuse_file_info *); - virtual int getattr(const char *, struct stat *); - virtual int getxattr(const char *, const char *, char *, size_t); - virtual int link(const char *, const char *); - virtual int listxattr(const char *, char *, size_t); - virtual int mkdir(const char *, mode_t); - virtual int mknod(const char *, mode_t, dev_t); - virtual int open(const char *, struct fuse_file_info *); - virtual int opendir(const char *, struct fuse_file_info *); - virtual int read(const char *, char *, size_t, off_t, struct fuse_file_info *); - virtual int readdir(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); - virtual int readlink(const char *, char *, size_t); - virtual int release(const char *, struct fuse_file_info *); - virtual int releasedir(const char *, struct fuse_file_info *); - virtual int removexattr(const char *, const char *); - virtual int rename(const char *, const char *); - virtual int rmdir(const char *); - virtual int setxattr(const char *, const char *, const char *, size_t, int); - virtual int statfs(const char *, struct statvfs *); - virtual int symlink(const char *, const char *); - virtual int truncate(const char *, off_t); - virtual int unlink(const char *); - virtual int write(const char *, const char *, size_t, off_t, struct fuse_file_info *); - virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); - virtual int utimens(const char *, const struct timespec tv[2]); - virtual int bmap(const char *, size_t blocksize, uint64_t *idx); - virtual int ioctl(const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void * data); - virtual int poll(const char *, struct fuse_file_info *, struct fuse_pollhandle *, unsigned *); - virtual int write_buf(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); - virtual int read_buf(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); - virtual int flock(const char *, struct fuse_file_info *, int op); - virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); - virtual int onError(const std::exception & err) throw(); - -#define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) - template - static int run(int & argc, char** & argv, FuseApp * fa) - { - auto args = runint(argc, argv, fa); - struct fuse_operations operations = { - fuseCall::GetHelper(getattr), - fuseCall::GetHelper(readlink), - NULL, // getdir deprecated - fuseCall::GetHelper(mknod), - fuseCall::GetHelper(mkdir), - fuseCall::GetHelper(unlink), - fuseCall::GetHelper(rmdir), - fuseCall::GetHelper(symlink), - fuseCall::GetHelper(rename), - fuseCall::GetHelper(link), - fuseCall::GetHelper(chmod), - fuseCall::GetHelper(chown), - fuseCall::GetHelper(truncate), - NULL, // utime deprecated - fuseCall::GetHelper(open), - fuseCall::GetHelper(read), - fuseCall::GetHelper(write), - fuseCall::GetHelper(statfs), - fuseCall::GetHelper(flush), - fuseCall::GetHelper(release), - fuseCall::GetHelper(fsync), - fuseCall::GetHelper(setxattr), - fuseCall::GetHelper(getxattr), - fuseCall::GetHelper(listxattr), - fuseCall::GetHelper(removexattr), - fuseCall::GetHelper(opendir), - fuseCall::GetHelper(readdir), - fuseCall::GetHelper(releasedir), - fuseCall::GetHelper(fsyncdir), - fuseInit, - fuseDestroy, - fuseCall::GetHelper(access), - fuseCall::GetHelper(create), - fuseCall::GetHelper(ftruncate), - fuseCall::GetHelper(fgetattr), -#if (FUSE_MINOR_VERSION >= 6) - fuseCall::GetHelper(lock), - fuseCall::GetHelper(utimens), - fuseCall::GetHelper(bmap), -#if (FUSE_MINOR_VERSION >= 8) - 0, // flag_nullpath_ok -#if (FUSE_MINOR_VERSION >= 9) - 0, // flag_nopath - 0, // flag_utime_omit_ok -#endif - 0, // flag_reserved - fuseCall::GetHelper(ioctl), - fuseCall::GetHelper(poll), -#if (FUSE_MINOR_VERSION >= 9) - fuseCall::GetHelper(write_buf), - fuseCall::GetHelper(read_buf), - fuseCall::GetHelper(flock), - fuseCall::GetHelper(fallocate), -#endif -#endif -#endif - }; - return fuse_main(args.argc, args.argv, &operations, fa); - } - private: - static struct fuse_args runint(int &, char ** &, FuseAppBase *); - static void * fuseInit(struct fuse_conn_info *conn); - static void fuseDestroy(void *); - - template - class fuseCall { - public: - typedef int (*WrapperFunc)(Args...); - template - static WrapperFunc getHelper(bool implemented) - { - auto func = &helper; - return implemented ? func : NULL; - } - template - static int helper(Args ... a) - { - try { - return (fuseApp->*f)(a...); - } - catch (const std::exception & ex) { - if (int rtn = fuseApp->onError(ex)) { - return rtn; - } - return helper(a...); - } - catch (...) { - fprintf(stderr, "Unknown exception calling %s\n", typeid(f).name()); - return -ENOSYS; - } - } - }; - - static FuseAppBase * fuseApp; -}; - -#endif - diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index dd8865e..70cd2d9 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -13,7 +13,6 @@ lib Ice : : Ice ; lib IceUtil : : IceUtil ; lib IceBox : : IceBox ; lib pthread : : pthread ; -lib fuse : : fuse ; lib slicer : : : : /usr/include/slicer ; lib slicer-xml : : : : /usr/include/slicer ; diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index e7558f6..acf757d 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -1,3 +1,4 @@ +lib fuse : : fuse ; cpp-pch pch : pch.hpp : _FILE_OFFSET_BITS=64 @@ -6,7 +7,7 @@ cpp-pch pch : pch.hpp : ../ice//netfsComms ../ice//netfsComms ..//boost_thread - ..//fuse + fuse ..//Ice ; @@ -25,10 +26,10 @@ obj configuration : ..//slicer ; -exe netfs : +lib netfsClient : pch configuration - [ glob *.cpp ] + [ glob *.cpp : netfs.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : _FILE_OFFSET_BITS=64 @@ -40,12 +41,25 @@ exe netfs : ../lib//netfsCommon ..//boost_thread ..//boost_system - ..//fuse + fuse ..//Ice ..//IceUtil ..//pthread ..//slicer ..//libxmlpp ..//slicer-xml + : : + . + ../../libfusepp + ../ice//netfsComms + ../ice//netfsComms + configuration + _FILE_OFFSET_BITS=64 + fuse + ; + +exe netfs : + netfs.cpp : + netfsClient ; diff --git a/netfs/fuse/fuse.cpp b/netfs/fuse/fuse.cpp deleted file mode 100644 index 7f90710..0000000 --- a/netfs/fuse/fuse.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "pch.hpp" -#include -#include "fuse.h" -#include "lockHelpers.h" -#include "cache.impl.h" -#include -#include -#include - -template class Cache>>; -template class OptimisticCallCacheable; - -NetFS::FuseApp::FuseApp(int & argc, char ** argv) : - _argc(argc), - _argv(argv), - openDirID(0), - openFileID(0) -{ -} - -NetFS::FuseApp::~FuseApp() -{ - for (const OpenDirs::value_type & of : openDirs) { - of.second->remote->close(); - } - for (const OpenFiles::value_type & of : openFiles) { - of.second->remote->close(); - } - if (volume) { - volume->disconnect(); - } - if (ic) { - ic->destroy(); - } -} - -void * -NetFS::FuseApp::init(struct fuse_conn_info *) -{ - ic = Ice::initialize(_argc, _argv); - fc = Slicer::Deserialize(configPath); - return NULL; -} - -int -NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) -{ - if (strncmp(arg, "--Ice.", 6) == 0) { - return 0; - } - else if (strncmp(arg, "_netdev", 7) == 0) { - return 0; - } - else if (arg[0] == '-') { - return 1; - } - else if (resourceName.empty()) { - const char * colon = strchr(arg, ':'); - resourceName = colon + 1; - configPath.assign(arg, colon); - return 0; - } - else if (mountPoint.empty()) { - mountPoint = arg; - return 1; - } - return 1; -} - -void -NetFS::FuseApp::connectToService() -{ - if (!service) { - Lock(_lock); - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such resource: " + resourceName); - } - - auto proxyAddr = e->second->ServiceIdentity; - for (const auto & ep : e->second->Endpoints) { - proxyAddr += ":" + ep; - } - service = NetFS::ServicePrx::checkedCast(ic->stringToProxy(proxyAddr)); - if (!service) { - throw std::runtime_error("Invalid service proxy: " + proxyAddr); - } - } -} - -void -NetFS::FuseApp::connectToVolume() -{ - if (!volume) { - auto e = fc->Resources.find(resourceName); - if (e == fc->Resources.end()) { - throw std::runtime_error("No such export: " + resourceName); - } - volume = service->connect(e->second->ExportName, "bar"); - if (!volume) { - throw "Invalid filesystem proxy"; - } - } -} - -void -NetFS::FuseApp::connectHandles() -{ - for (const OpenFiles::value_type & of : openFiles) { - try { - of.second->remote->ice_ping(); - } - catch (const Ice::ObjectNotExistException &) { - of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags); - } - } - for (const OpenDirs::value_type & of : openDirs) { - try { - of.second->remote->ice_ping(); - } - catch (const Ice::ObjectNotExistException &) { - of.second->remote = volume->opendir(reqEnv(), of.second->path); - } - } -} - -void -NetFS::FuseApp::verifyConnection() -{ - Lock(_lock); - if (service) { - try { - service->ice_ping(); - } - catch (const Ice::Exception &) { - service = NULL; - } - } - if (volume) { - try { - volume->ice_ping(); - } - catch (const Ice::Exception &) { - volume = NULL; - } - } -} - -int -NetFS::FuseApp::onError(const std::exception & e) throw() -{ - if (dynamic_cast(&e)) { - verifyConnection(); - connectToService(); - connectToVolume(); - connectHandles(); - return 0; - } - return FuseAppBase::onError(e); -} - -NetFS::ReqEnv -NetFS::FuseApp::reqEnv() -{ - connectToService(); - connectToVolume(); - struct fuse_context * c = fuse_get_context(); - return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; -} - -int -main(int argc, char* argv[]) -{ - return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); -} - diff --git a/netfs/fuse/fuse.h b/netfs/fuse/fuse.h deleted file mode 100644 index 3821285..0000000 --- a/netfs/fuse/fuse.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef NETFS_FUSE_H -#define NETFS_FUSE_H - -#include -#include -#include -#include "fuseapp.h" -#include "configuration.h" -#include "cache.h" - -namespace NetFS { - class FuseApp : public FuseAppBase { - private: - class OpenDir : public IceUtil::Shared { - public: - OpenDir(DirectoryPrx remote, const std::string & path); - - DirectoryPrx remote; - const std::string path; - }; - typedef IceUtil::Handle OpenDirPtr; - typedef std::map OpenDirs; - - class OpenFile : public IceUtil::Shared { - public: - OpenFile(FilePrx remote, const std::string & path, int flags); - - FilePrx remote; - const std::string path; - const int flags; - }; - typedef IceUtil::Handle OpenFilePtr; - typedef std::map OpenFiles; - - public: - FuseApp(int & argc, char ** argv); - ~FuseApp(); - - private: - void * init (struct fuse_conn_info * info); - int opt_parse(void *, const char * arg, int key, struct fuse_args *); - - void connectToService(); - void connectToVolume(); - void connectHandles(); - void verifyConnection(); - - public: - // misc - int access(const char * p, int a); - int getattr(const char * p, struct stat * s); - int fgetattr(const char *, struct stat *, struct fuse_file_info *); - int chmod(const char *, mode_t); - int chown(const char *, uid_t, gid_t); - int link(const char *, const char *); - int readlink(const char *, char *, size_t); - int rename(const char *, const char *); - int symlink(const char *, const char *); - int unlink(const char *); - int utimens(const char *, const struct timespec tv[2]); - int mknod(const char *, mode_t, dev_t); - // dirs - int opendir(const char * p, struct fuse_file_info * fi); - int releasedir(const char *, struct fuse_file_info * fi); - int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi); - int mkdir(const char *, mode_t); - int rmdir(const char *); - // files - int open(const char * p, struct fuse_file_info * fi); - int create(const char *, mode_t, struct fuse_file_info *); - int release(const char *, struct fuse_file_info * fi); - int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi); - int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi); - int truncate(const char *, off_t); - int ftruncate(const char *, off_t, struct fuse_file_info *); - // fs - int statfs(const char *, struct statvfs *); - // stuff - int onError(const std::exception & err) throw(); - - private: - void setProxy(OpenFilePtr, uint64_t & fh); - OpenFilePtr getFileProxy(uint64_t localID) const; - void clearFileProxy(uint64_t localID); - - void setProxy(OpenDirPtr, uint64_t & fh); - OpenDirPtr getDirProxy(uint64_t localID) const; - void clearDirProxy(uint64_t localID); - - ReqEnv reqEnv(); - - int & _argc; - char ** _argv; - Ice::CommunicatorPtr ic; - Client::ConfigurationPtr fc; - mutable boost::shared_mutex _lock; - - NetFS::VolumePrx volume; - NetFS::ServicePrx service; - - std::string mountPoint; - std::string resourceName; - std::string configPath; - - OpenDirs openDirs; - int openDirID; - OpenFiles openFiles; - int openFileID; - - typedef Cache>> StatCache; - StatCache statCache; - }; -} - -#endif diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp new file mode 100644 index 0000000..841d670 --- /dev/null +++ b/netfs/fuse/fuseApp.cpp @@ -0,0 +1,170 @@ +#include "pch.hpp" +#include +#include "fuseApp.h" +#include "lockHelpers.h" +#include "cache.impl.h" +#include +#include +#include + +template class Cache>>; +template class OptimisticCallCacheable; + +NetFS::FuseApp::FuseApp(int & argc, char ** argv) : + _argc(argc), + _argv(argv), + openDirID(0), + openFileID(0) +{ +} + +NetFS::FuseApp::~FuseApp() +{ + for (const OpenDirs::value_type & of : openDirs) { + of.second->remote->close(); + } + for (const OpenFiles::value_type & of : openFiles) { + of.second->remote->close(); + } + if (volume) { + volume->disconnect(); + } + if (ic) { + ic->destroy(); + } +} + +void * +NetFS::FuseApp::init(struct fuse_conn_info *) +{ + ic = Ice::initialize(_argc, _argv); + fc = Slicer::Deserialize(configPath); + return NULL; +} + +int +NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) +{ + if (strncmp(arg, "--Ice.", 6) == 0) { + return 0; + } + else if (strncmp(arg, "_netdev", 7) == 0) { + return 0; + } + else if (arg[0] == '-') { + return 1; + } + else if (resourceName.empty()) { + const char * colon = strchr(arg, ':'); + resourceName = colon + 1; + configPath.assign(arg, colon); + return 0; + } + else if (mountPoint.empty()) { + mountPoint = arg; + return 1; + } + return 1; +} + +void +NetFS::FuseApp::connectToService() +{ + if (!service) { + Lock(_lock); + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such resource: " + resourceName); + } + + auto proxyAddr = e->second->ServiceIdentity; + for (const auto & ep : e->second->Endpoints) { + proxyAddr += ":" + ep; + } + service = NetFS::ServicePrx::checkedCast(ic->stringToProxy(proxyAddr)); + if (!service) { + throw std::runtime_error("Invalid service proxy: " + proxyAddr); + } + } +} + +void +NetFS::FuseApp::connectToVolume() +{ + if (!volume) { + auto e = fc->Resources.find(resourceName); + if (e == fc->Resources.end()) { + throw std::runtime_error("No such export: " + resourceName); + } + volume = service->connect(e->second->ExportName, "bar"); + if (!volume) { + throw "Invalid filesystem proxy"; + } + } +} + +void +NetFS::FuseApp::connectHandles() +{ + for (const OpenFiles::value_type & of : openFiles) { + try { + of.second->remote->ice_ping(); + } + catch (const Ice::ObjectNotExistException &) { + of.second->remote = volume->open(reqEnv(), of.second->path, of.second->flags); + } + } + for (const OpenDirs::value_type & of : openDirs) { + try { + of.second->remote->ice_ping(); + } + catch (const Ice::ObjectNotExistException &) { + of.second->remote = volume->opendir(reqEnv(), of.second->path); + } + } +} + +void +NetFS::FuseApp::verifyConnection() +{ + Lock(_lock); + if (service) { + try { + service->ice_ping(); + } + catch (const Ice::Exception &) { + service = NULL; + } + } + if (volume) { + try { + volume->ice_ping(); + } + catch (const Ice::Exception &) { + volume = NULL; + } + } +} + +int +NetFS::FuseApp::onError(const std::exception & e) throw() +{ + if (dynamic_cast(&e)) { + verifyConnection(); + connectToService(); + connectToVolume(); + connectHandles(); + return 0; + } + return FuseAppBase::onError(e); +} + +NetFS::ReqEnv +NetFS::FuseApp::reqEnv() +{ + connectToService(); + connectToVolume(); + struct fuse_context * c = fuse_get_context(); + return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; +} + diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h new file mode 100644 index 0000000..f438910 --- /dev/null +++ b/netfs/fuse/fuseApp.h @@ -0,0 +1,115 @@ +#ifndef NETFS_FUSE_H +#define NETFS_FUSE_H + +#include +#include +#include +#include "fuseAppBase.h" +#include "configuration.h" +#include "cache.h" + +namespace NetFS { + class FuseApp : public FuseAppBase { + private: + class OpenDir : public IceUtil::Shared { + public: + OpenDir(DirectoryPrx remote, const std::string & path); + + DirectoryPrx remote; + const std::string path; + }; + typedef IceUtil::Handle OpenDirPtr; + typedef std::map OpenDirs; + + class OpenFile : public IceUtil::Shared { + public: + OpenFile(FilePrx remote, const std::string & path, int flags); + + FilePrx remote; + const std::string path; + const int flags; + }; + typedef IceUtil::Handle OpenFilePtr; + typedef std::map OpenFiles; + + public: + FuseApp(int & argc, char ** argv); + ~FuseApp(); + + private: + void * init (struct fuse_conn_info * info); + int opt_parse(void *, const char * arg, int key, struct fuse_args *); + + void connectToService(); + void connectToVolume(); + void connectHandles(); + void verifyConnection(); + + public: + // misc + int access(const char * p, int a); + int getattr(const char * p, struct stat * s); + int fgetattr(const char *, struct stat *, struct fuse_file_info *); + int chmod(const char *, mode_t); + int chown(const char *, uid_t, gid_t); + int link(const char *, const char *); + int readlink(const char *, char *, size_t); + int rename(const char *, const char *); + int symlink(const char *, const char *); + int unlink(const char *); + int utimens(const char *, const struct timespec tv[2]); + int mknod(const char *, mode_t, dev_t); + // dirs + int opendir(const char * p, struct fuse_file_info * fi); + int releasedir(const char *, struct fuse_file_info * fi); + int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi); + int mkdir(const char *, mode_t); + int rmdir(const char *); + // files + int open(const char * p, struct fuse_file_info * fi); + int create(const char *, mode_t, struct fuse_file_info *); + int release(const char *, struct fuse_file_info * fi); + int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi); + int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi); + int truncate(const char *, off_t); + int ftruncate(const char *, off_t, struct fuse_file_info *); + // fs + int statfs(const char *, struct statvfs *); + // stuff + int onError(const std::exception & err) throw(); + + private: + void setProxy(OpenFilePtr, uint64_t & fh); + OpenFilePtr getFileProxy(uint64_t localID) const; + void clearFileProxy(uint64_t localID); + + void setProxy(OpenDirPtr, uint64_t & fh); + OpenDirPtr getDirProxy(uint64_t localID) const; + void clearDirProxy(uint64_t localID); + + ReqEnv reqEnv(); + + int & _argc; + char ** _argv; + Ice::CommunicatorPtr ic; + Client::ConfigurationPtr fc; + mutable boost::shared_mutex _lock; + + NetFS::VolumePrx volume; + NetFS::ServicePrx service; + + std::string mountPoint; + std::string resourceName; + std::string configPath; + + OpenDirs openDirs; + int openDirID; + OpenFiles openFiles; + int openFileID; + + typedef Cache>> StatCache; + StatCache statCache; + }; +} + +#endif diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index 75cb5a5..ad3d017 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,5 +1,5 @@ #include "pch.hpp" -#include "fuse.h" +#include "fuseApp.h" #include "misc.h" #include "lockHelpers.h" #include diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index 9ce260c..b6cf8db 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,7 +1,7 @@ #include "pch.hpp" #include #include -#include "fuse.h" +#include "fuseApp.h" #include "lockHelpers.h" #include diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 0e366be..f6c5976 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -1,5 +1,5 @@ #include "pch.hpp" -#include "fuse.h" +#include "fuseApp.h" #include #include #include diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp index 0b29d86..36c6af5 100644 --- a/netfs/fuse/fuseSystem.cpp +++ b/netfs/fuse/fuseSystem.cpp @@ -1,6 +1,6 @@ #include "pch.hpp" #include -#include "fuse.h" +#include "fuseApp.h" int NetFS::FuseApp::statfs(const char * p, struct statvfs * vfs) diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp new file mode 100644 index 0000000..de89660 --- /dev/null +++ b/netfs/fuse/netfs.cpp @@ -0,0 +1,8 @@ +#include "fuseApp.h" + +int +main(int argc, char* argv[]) +{ + return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); +} + diff --git a/netfs/fuse/pch.hpp b/netfs/fuse/pch.hpp index 7cb79ed..b2a0908 100644 --- a/netfs/fuse/pch.hpp +++ b/netfs/fuse/pch.hpp @@ -3,11 +3,9 @@ #define NETFS_FUSE_PCH #include "../lib/pch.hpp" -#include "../../libfusepp/fuseapp.h" +#include "../../libfusepp/fuseAppBase.h" #include #endif #endif - - -- cgit v1.2.3 From 03db967ea616989ae1bac5c2bdb7a2e72d98885e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 16:26:46 +0000 Subject: Rename configs for uniqueness --- netfs/daemon/Jamfile.jam | 2 +- netfs/daemon/configuration.ice | 34 ---------------------------------- netfs/daemon/daemon.h | 2 +- netfs/daemon/daemonConfig.ice | 34 ++++++++++++++++++++++++++++++++++ netfs/daemon/daemonService.h | 2 +- netfs/fuse/Jamfile.jam | 12 +++++++----- netfs/fuse/configuration.ice | 27 --------------------------- netfs/fuse/fuseApp.h | 2 +- netfs/fuse/fuseConfig.ice | 27 +++++++++++++++++++++++++++ 9 files changed, 72 insertions(+), 70 deletions(-) delete mode 100644 netfs/daemon/configuration.ice create mode 100644 netfs/daemon/daemonConfig.ice delete mode 100644 netfs/fuse/configuration.ice create mode 100644 netfs/fuse/fuseConfig.ice diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam index 07bdcee..53ac99d 100644 --- a/netfs/daemon/Jamfile.jam +++ b/netfs/daemon/Jamfile.jam @@ -11,7 +11,7 @@ cpp-pch pch : pch.hpp : ; lib netfsdConfiguration : - configuration.ice + daemonConfig.ice : ..//Ice ..//IceUtil diff --git a/netfs/daemon/configuration.ice b/netfs/daemon/configuration.ice deleted file mode 100644 index bb77344..0000000 --- a/netfs/daemon/configuration.ice +++ /dev/null @@ -1,34 +0,0 @@ -module NetFS { - module Daemon { - class Host { - ["slicer:name:endpoint"] - string Endpoint; - }; - - ["slicer:key:hostname","slicer:value:host","slicer:item:host"] - dictionary HostMap; - - class Export { - ["slicer:name:root"] - string RootPath; - }; - - ["slicer:key:name","slicer:value:export","slicer:item:export"] - dictionary ExportMap; - - ["slicer:root:config"] - class Configuration { - ["slicer:name:exports"] - ExportMap Exports; - - ["slicer:name:hosts"] - HostMap Hosts; - }; - - ["slicer:ignore"] - class RuntimeConfiguration { - Configuration CurrentConfiguration; - Host Self; - }; - }; -}; diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index 58d9f2f..a43d7cd 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/netfs/daemon/daemonConfig.ice b/netfs/daemon/daemonConfig.ice new file mode 100644 index 0000000..bb77344 --- /dev/null +++ b/netfs/daemon/daemonConfig.ice @@ -0,0 +1,34 @@ +module NetFS { + module Daemon { + class Host { + ["slicer:name:endpoint"] + string Endpoint; + }; + + ["slicer:key:hostname","slicer:value:host","slicer:item:host"] + dictionary HostMap; + + class Export { + ["slicer:name:root"] + string RootPath; + }; + + ["slicer:key:name","slicer:value:export","slicer:item:export"] + dictionary ExportMap; + + ["slicer:root:config"] + class Configuration { + ["slicer:name:exports"] + ExportMap Exports; + + ["slicer:name:hosts"] + HostMap Hosts; + }; + + ["slicer:ignore"] + class RuntimeConfiguration { + Configuration CurrentConfiguration; + Host Self; + }; + }; +}; diff --git a/netfs/daemon/daemonService.h b/netfs/daemon/daemonService.h index ab52eee..345df2c 100644 --- a/netfs/daemon/daemonService.h +++ b/netfs/daemon/daemonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class ServiceServer : public NetFS::Service { public: diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index acf757d..737c6c8 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -11,8 +11,8 @@ cpp-pch pch : pch.hpp : ..//Ice ; -obj configuration : - configuration.ice +lib netfsClientConfiguration : + fuseConfig.ice : yes ..//Ice @@ -28,7 +28,7 @@ obj configuration : lib netfsClient : pch - configuration + netfsClientConfiguration [ glob *.cpp : netfs.cpp ] [ glob ../../libfusepp/fuse*.cpp ] : @@ -36,7 +36,8 @@ lib netfsClient : ../../libmisc ../../libfusepp ../ice//netfsComms - configuration + netfsClientConfiguration + netfsClientConfiguration ../ice//netfsComms ../lib//netfsCommon ..//boost_thread @@ -53,7 +54,8 @@ lib netfsClient : ../../libfusepp ../ice//netfsComms ../ice//netfsComms - configuration + netfsClientConfiguration + netfsClientConfiguration _FILE_OFFSET_BITS=64 fuse ; diff --git a/netfs/fuse/configuration.ice b/netfs/fuse/configuration.ice deleted file mode 100644 index db37770..0000000 --- a/netfs/fuse/configuration.ice +++ /dev/null @@ -1,27 +0,0 @@ -module NetFS { - module Client { - ["slicer:element:endpoint"] - sequence EndpointList; - - class Resource { - ["slicer:name:export"] - string ExportName; - - ["slicer:name:service"] - string ServiceIdentity = "Service"; - - ["slicer:name:endpoints"] - EndpointList Endpoints; - }; - - ["slicer:key:name","slicer:value:resource","slicer:item:resource"] - dictionary ResourceMap; - - ["slicer:root:config"] - class Configuration { - ["slicer:name:resources"] - ResourceMap Resources; - }; - }; -}; - diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index f438910..4eb01ff 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -5,7 +5,7 @@ #include #include #include "fuseAppBase.h" -#include "configuration.h" +#include "fuseConfig.h" #include "cache.h" namespace NetFS { diff --git a/netfs/fuse/fuseConfig.ice b/netfs/fuse/fuseConfig.ice new file mode 100644 index 0000000..db37770 --- /dev/null +++ b/netfs/fuse/fuseConfig.ice @@ -0,0 +1,27 @@ +module NetFS { + module Client { + ["slicer:element:endpoint"] + sequence EndpointList; + + class Resource { + ["slicer:name:export"] + string ExportName; + + ["slicer:name:service"] + string ServiceIdentity = "Service"; + + ["slicer:name:endpoints"] + EndpointList Endpoints; + }; + + ["slicer:key:name","slicer:value:resource","slicer:item:resource"] + dictionary ResourceMap; + + ["slicer:root:config"] + class Configuration { + ["slicer:name:resources"] + ResourceMap Resources; + }; + }; +}; + -- cgit v1.2.3 From 4b8f75974f7bdce5d68b95ac8d4c2e9979c38057 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 15 Feb 2015 17:11:20 +0000 Subject: Refactor fuse lib deps into final exe --- libfusepp/fuseAppBase.h | 6 ++++-- netfs/fuse/Jamfile.jam | 3 +-- netfs/fuse/fuseApp.h | 2 ++ netfs/fuse/netfs.cpp | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index a320d36..91ba22f 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -56,11 +56,13 @@ class FuseAppBase { virtual int fallocate(const char *, int, off_t, off_t, struct fuse_file_info *); virtual int onError(const std::exception & err) throw(); + virtual int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc) = 0; + #define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) template static int run(int & argc, char** & argv, FuseApp * fa) { - auto args = runint(argc, argv, fa); + auto args = fa->runint(argc, argv, fa); struct fuse_operations operations = { fuseCall::GetHelper(getattr), fuseCall::GetHelper(readlink), @@ -122,7 +124,7 @@ class FuseAppBase { return fuse_main(args.argc, args.argv, &operations, fa); } private: - static struct fuse_args runint(int &, char ** &, FuseAppBase *); + struct fuse_args runint(int &, char ** &, FuseAppBase *); static void * fuseInit(struct fuse_conn_info *conn); static void fuseDestroy(void *); diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam index 737c6c8..c5d3a7a 100644 --- a/netfs/fuse/Jamfile.jam +++ b/netfs/fuse/Jamfile.jam @@ -42,7 +42,6 @@ lib netfsClient : ../lib//netfsCommon ..//boost_thread ..//boost_system - fuse ..//Ice ..//IceUtil ..//pthread @@ -57,11 +56,11 @@ lib netfsClient : netfsClientConfiguration netfsClientConfiguration _FILE_OFFSET_BITS=64 - fuse ; exe netfs : netfs.cpp : netfsClient + fuse ; diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index 4eb01ff..4786591 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -78,6 +78,8 @@ namespace NetFS { // stuff int onError(const std::exception & err) throw(); + virtual struct fuse_context * fuse_get_context() = 0; + private: void setProxy(OpenFilePtr, uint64_t & fh); OpenFilePtr getFileProxy(uint64_t localID) const; diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp index de89660..21689f2 100644 --- a/netfs/fuse/netfs.cpp +++ b/netfs/fuse/netfs.cpp @@ -1,8 +1,23 @@ #include "fuseApp.h" +class FuseImpl : public NetFS::FuseApp { + public: + FuseImpl(int & argc, char ** argv) : NetFS::FuseApp(argc, argv) { } + + struct fuse_context * fuse_get_context() override + { + return ::fuse_get_context(); + } + + int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt opts[], fuse_opt_proc_t proc) override + { + return ::fuse_opt_parse(args, data, opts, proc); + } +}; + int main(int argc, char* argv[]) { - return FuseAppBase::run(argc, argv, new NetFS::FuseApp(argc, argv)); + return FuseAppBase::run(argc, argv, new FuseImpl(argc, argv)); } -- cgit v1.2.3 From 9b229b1360794b3d21e8cf7956bcae5b90d0502f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:06:53 +0000 Subject: Export the runint function --- libfusepp/fuseAppBase.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index 91ba22f..4b56f2f 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -123,8 +123,9 @@ class FuseAppBase { }; return fuse_main(args.argc, args.argv, &operations, fa); } - private: struct fuse_args runint(int &, char ** &, FuseAppBase *); + + private: static void * fuseInit(struct fuse_conn_info *conn); static void fuseDestroy(void *); -- cgit v1.2.3 From 01ab3c40b2cae1a195ab2cd3bfcf8af9d783fac0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:10:48 +0000 Subject: runint doesn't need a pointer to itself passing in --- libfusepp/fuseAppBase.cpp | 4 ++-- libfusepp/fuseAppBase.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp index 4d9ca97..4e34192 100644 --- a/libfusepp/fuseAppBase.cpp +++ b/libfusepp/fuseAppBase.cpp @@ -198,12 +198,12 @@ void FuseAppBase::fuseDestroy(void *) } struct fuse_args -FuseAppBase::runint(int & argc, char** & argv, FuseAppBase * fa) +FuseAppBase::runint(int & argc, char** & argv) { struct fuse_opt fuse_opts[] = { { NULL, 0, 0 } }; - fuseApp = fa; + fuseApp = this; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, fuseApp, fuse_opts, fuseCall::helper<&FuseAppBase::opt_parse>) == -1) { diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index 4b56f2f..73a809a 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -62,7 +62,7 @@ class FuseAppBase { template static int run(int & argc, char** & argv, FuseApp * fa) { - auto args = fa->runint(argc, argv, fa); + auto args = fa->runint(argc, argv); struct fuse_operations operations = { fuseCall::GetHelper(getattr), fuseCall::GetHelper(readlink), @@ -123,7 +123,7 @@ class FuseAppBase { }; return fuse_main(args.argc, args.argv, &operations, fa); } - struct fuse_args runint(int &, char ** &, FuseAppBase *); + struct fuse_args runint(int &, char ** &); private: static void * fuseInit(struct fuse_conn_info *conn); -- cgit v1.2.3 From 221514b72f4214ac2d4383a7381eb970a77a8d2e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:12:57 +0000 Subject: Add the start of some test framework, complete with hacky initialisations --- netfs/Jamfile.jam | 1 + netfs/unittests/Jamfile.jam | 28 +++++++++++++ netfs/unittests/client.xml | 14 +++++++ netfs/unittests/daemon.xml | 19 +++++++++ netfs/unittests/testCore.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 netfs/unittests/Jamfile.jam create mode 100644 netfs/unittests/client.xml create mode 100644 netfs/unittests/daemon.xml create mode 100644 netfs/unittests/testCore.cpp diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index 70cd2d9..6df8110 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -18,6 +18,7 @@ lib slicer-xml : : : : /usr/include/slicer ; build-project daemon ; build-project fuse ; +build-project unittests ; explicit install ; package.install install : : fuse//netfs : daemon//netfsd ; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam new file mode 100644 index 0000000..1c16bc7 --- /dev/null +++ b/netfs/unittests/Jamfile.jam @@ -0,0 +1,28 @@ +import testing ; + +lib boost_utf : : boost_unit_test_framework ; +lib boost_system ; +lib boost_filesystem ; +lib IceUtil ; +lib Ice ; + +path-constant me : . ; + +run + testCore.cpp + : : + client.xml + daemon.xml + : + BOOST_TEST_DYN_LINK + IceUtil + Ice + boost_system + boost_filesystem + boost_utf + ../daemon//netfsd + ../fuse//netfsClient + ../ice//netfsComms + ROOT=\"$(me)\" + : testCore ; + diff --git a/netfs/unittests/client.xml b/netfs/unittests/client.xml new file mode 100644 index 0000000..c159a24 --- /dev/null +++ b/netfs/unittests/client.xml @@ -0,0 +1,14 @@ + + + + + testvol + + unittest + + tcp -h localhost -p 4000 + + + + + diff --git a/netfs/unittests/daemon.xml b/netfs/unittests/daemon.xml new file mode 100644 index 0000000..8bf58a9 --- /dev/null +++ b/netfs/unittests/daemon.xml @@ -0,0 +1,19 @@ + + + + + unittest + + tcp -p 4000:udp -p 10000 + + + + + + unittest + + /usr/portage + + + + diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp new file mode 100644 index 0000000..b9a1836 --- /dev/null +++ b/netfs/unittests/testCore.cpp @@ -0,0 +1,95 @@ +#define BOOST_TEST_MODULE TestNetFSCore +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef ROOT +#error "ROOT needs to be defined at compilation time" +#endif + +#define XSTR(s) STR(s) +#define STR(s) #s +const boost::filesystem::path RootDir(XSTR(ROOT)); + +class FuseMock : public NetFS::FuseApp { + public: + FuseMock(int & argc, char ** argv) : + NetFS::FuseApp(argc, argv) + { + ::memset(&context, 0, sizeof(fuse_context)); + } + + struct fuse_context * fuse_get_context() override + { + return &context; + } + + int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override + { + for (int n = 0; n < args->argc; n += 1) { + proc(data, args->argv[n], n, args); + } + return 0; + } + private: + fuse_context context; +}; + +char * argv[] = { + strdup((RootDir / "client.xml:testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + +class Core { + public: + Core() : + params({}), + ic(Ice::initialize(params)), + daemon(ic), + argc(2), + fuse(new FuseMock(argc, argv)) + { + ic->getProperties()->setProperty("NetFSD.ConfigPath", (RootDir / "daemon.xml").string()); + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon.start("NetFSDaemonAdapter", ic, {}); + char ** a = argv; + fuse->runint(argc, a); + fuse->init(NULL); + } + + ~Core() + { + delete fuse; + ic->destroy(); + } + + protected: + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon daemon; + int argc; + FuseAppBase * fuse; +}; + +BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) + +BOOST_AUTO_TEST_CASE ( daemonInitialised ) +{ + auto service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service")); + BOOST_REQUIRE(service); + service->ice_ping(); +} + +BOOST_AUTO_TEST_CASE ( clientInitialised ) +{ + struct statvfs s; + fuse->statfs("/", &s); +} + +BOOST_AUTO_TEST_SUITE_END(); + -- cgit v1.2.3 From 3bddefde3675a042c7e05af23a1f3cfd52c874ad Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 18:45:06 +0000 Subject: Actually use precompiled headers --- netfs/daemon/daemon.cpp | 2 +- netfs/daemon/daemonDirectory.cpp | 2 +- netfs/daemon/daemonFile.cpp | 2 +- netfs/daemon/daemonService.cpp | 2 +- netfs/daemon/daemonVolume.cpp | 2 +- netfs/daemon/pch.hpp | 2 +- netfs/fuse/fuseApp.cpp | 2 +- netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/fuse/fuseSystem.cpp | 2 +- netfs/fuse/pch.hpp | 1 + netfs/lib/entCache.cpp | 2 +- netfs/lib/pch.hpp | 3 ++- 14 files changed, 15 insertions(+), 13 deletions(-) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index 6c231f9..0b7b64f 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include "daemon.h" #include "daemonService.h" diff --git a/netfs/daemon/daemonDirectory.cpp b/netfs/daemon/daemonDirectory.cpp index b43806f..b61b8be 100644 --- a/netfs/daemon/daemonDirectory.cpp +++ b/netfs/daemon/daemonDirectory.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index 79077a1..3268be8 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp index 4b9e804..fe587f1 100644 --- a/netfs/daemon/daemonService.cpp +++ b/netfs/daemon/daemonService.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "daemon.h" #include "daemonService.h" #include "daemonVolume.h" diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 0caead6..0cad47e 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include diff --git a/netfs/daemon/pch.hpp b/netfs/daemon/pch.hpp index 3229655..adc5ff2 100644 --- a/netfs/daemon/pch.hpp +++ b/netfs/daemon/pch.hpp @@ -6,8 +6,8 @@ #include #include "daemon.h" #include +#include #endif #endif - diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 841d670..2f3b288 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include "fuseApp.h" #include "lockHelpers.h" diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index ad3d017..156dae6 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "fuseApp.h" #include "misc.h" #include "lockHelpers.h" diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index b6cf8db..b8399f0 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include #include "fuseApp.h" diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index f6c5976..670c9ae 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "fuseApp.h" #include #include diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp index 36c6af5..e2a9ab7 100644 --- a/netfs/fuse/fuseSystem.cpp +++ b/netfs/fuse/fuseSystem.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include #include "fuseApp.h" diff --git a/netfs/fuse/pch.hpp b/netfs/fuse/pch.hpp index b2a0908..2342973 100644 --- a/netfs/fuse/pch.hpp +++ b/netfs/fuse/pch.hpp @@ -5,6 +5,7 @@ #include "../lib/pch.hpp" #include "../../libfusepp/fuseAppBase.h" #include +#include #endif #endif diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index a4cf27d..b07dda7 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -1,4 +1,4 @@ -#include "pch.hpp" +#include #include "entCache.h" #include #include "lockHelpers.h" diff --git a/netfs/lib/pch.hpp b/netfs/lib/pch.hpp index ffd9890..fc37faa 100644 --- a/netfs/lib/pch.hpp +++ b/netfs/lib/pch.hpp @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include #include -- cgit v1.2.3 From b6aaaf3bc4e74988fa491e5dd52522ec4431a275 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 20:51:59 +0000 Subject: Program defined config files and sandbox --- netfs/daemon/daemon.cpp | 8 +++++++- netfs/daemon/daemon.h | 3 +++ netfs/fuse/fuseApp.cpp | 8 +++++++- netfs/fuse/fuseApp.h | 3 +++ netfs/unittests/Jamfile.jam | 2 -- netfs/unittests/client.xml | 14 ------------- netfs/unittests/daemon.xml | 19 ----------------- netfs/unittests/testCore.cpp | 49 +++++++++++++++++++++++++++++++++++++------- 8 files changed, 62 insertions(+), 44 deletions(-) delete mode 100644 netfs/unittests/client.xml delete mode 100644 netfs/unittests/daemon.xml diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index 0b7b64f..cf312bb 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -38,11 +38,17 @@ NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr &, const adapter->activate(); } +NetFS::Daemon::ConfigurationPtr +NetFSDaemon::ReadConfiguration(const boost::filesystem::path & path) const +{ + return Slicer::Deserialize(path); +} + void NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path) { dc = new NetFS::Daemon::RuntimeConfiguration(); - dc->CurrentConfiguration = Slicer::Deserialize(path); + dc->CurrentConfiguration = ReadConfiguration(path); auto selfItr = dc->CurrentConfiguration->Hosts.find(hostname()); if (selfItr == dc->CurrentConfiguration->Hosts.end()) { throw std::runtime_error("This host is not defined in the configuration."); diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index a43d7cd..8cf4d4a 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -14,6 +14,9 @@ class NetFSDaemon : public IceBox::Service { virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override; virtual void stop() override; + protected: + virtual NetFS::Daemon::ConfigurationPtr ReadConfiguration(const boost::filesystem::path & path) const; + private: void LoadConfiguration(const boost::filesystem::path & path); diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 2f3b288..d579271 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -34,11 +34,17 @@ NetFS::FuseApp::~FuseApp() } } +NetFS::Client::ConfigurationPtr +NetFS::FuseApp::ReadConfiguration(const std::string & path) const +{ + return Slicer::Deserialize(path); +} + void * NetFS::FuseApp::init(struct fuse_conn_info *) { ic = Ice::initialize(_argc, _argv); - fc = Slicer::Deserialize(configPath); + fc = ReadConfiguration(configPath); return NULL; } diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index 4786591..e514b55 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -80,6 +80,9 @@ namespace NetFS { virtual struct fuse_context * fuse_get_context() = 0; + protected: + virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const; + private: void setProxy(OpenFilePtr, uint64_t & fh); OpenFilePtr getFileProxy(uint64_t localID) const; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index 1c16bc7..af02411 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -11,8 +11,6 @@ path-constant me : . ; run testCore.cpp : : - client.xml - daemon.xml : BOOST_TEST_DYN_LINK IceUtil diff --git a/netfs/unittests/client.xml b/netfs/unittests/client.xml deleted file mode 100644 index c159a24..0000000 --- a/netfs/unittests/client.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - testvol - - unittest - - tcp -h localhost -p 4000 - - - - - diff --git a/netfs/unittests/daemon.xml b/netfs/unittests/daemon.xml deleted file mode 100644 index 8bf58a9..0000000 --- a/netfs/unittests/daemon.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - unittest - - tcp -p 4000:udp -p 10000 - - - - - - unittest - - /usr/portage - - - - diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index b9a1836..2262444 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -15,6 +14,26 @@ #define XSTR(s) STR(s) #define STR(s) #s const boost::filesystem::path RootDir(XSTR(ROOT)); +const boost::filesystem::path TestExportRoot(RootDir / "testExport"); + +std::string testEndpoint("tcp -h localhost -p 12012"); + +class MockDaemon : public NetFSDaemon { + public: + MockDaemon(const Ice::CommunicatorPtr & ic) : NetFSDaemon(ic) { } + + protected: + virtual NetFS::Daemon::ConfigurationPtr ReadConfiguration(const boost::filesystem::path &) const override + { + return new NetFS::Daemon::Configuration( + { + { "testvol", new NetFS::Daemon::Export(TestExportRoot.string()) } + }, + { + { "unittest", new NetFS::Daemon::Host(testEndpoint) } + }); + } +}; class FuseMock : public NetFS::FuseApp { public: @@ -36,12 +55,22 @@ class FuseMock : public NetFS::FuseApp { } return 0; } + + protected: + virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override + { + return new NetFS::Client::Configuration( + { + { "testvol", new NetFS::Client::Resource("testvol", "Service", { testEndpoint }) } + }); + } + private: fuse_context context; }; char * argv[] = { - strdup((RootDir / "client.xml:testvol").string().c_str()), + strdup((RootDir / ":testvol").string().c_str()), strdup((RootDir / "test").string().c_str()) }; @@ -50,13 +79,12 @@ class Core { Core() : params({}), ic(Ice::initialize(params)), - daemon(ic), + daemon(new MockDaemon(ic)), argc(2), fuse(new FuseMock(argc, argv)) { - ic->getProperties()->setProperty("NetFSD.ConfigPath", (RootDir / "daemon.xml").string()); ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); - daemon.start("NetFSDaemonAdapter", ic, {}); + daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; fuse->runint(argc, a); fuse->init(NULL); @@ -65,19 +93,26 @@ class Core { ~Core() { delete fuse; + delete daemon; ic->destroy(); } protected: Ice::StringSeq params; Ice::CommunicatorPtr ic; - NetFSDaemon daemon; + NetFSDaemon * daemon; int argc; FuseAppBase * fuse; }; BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) +BOOST_AUTO_TEST_CASE ( initializeSandbox ) +{ + boost::filesystem::remove_all(TestExportRoot); + boost::filesystem::create_directories(TestExportRoot); +} + BOOST_AUTO_TEST_CASE ( daemonInitialised ) { auto service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service")); @@ -88,7 +123,7 @@ BOOST_AUTO_TEST_CASE ( daemonInitialised ) BOOST_AUTO_TEST_CASE ( clientInitialised ) { struct statvfs s; - fuse->statfs("/", &s); + BOOST_REQUIRE_EQUAL(0, fuse->statfs("/", &s)); } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3 From 3242322e92c841cab905f0352a65b695a318ecd3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 00:38:13 +0000 Subject: Fix error message --- libfusepp/fuseAppBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfusepp/fuseAppBase.cpp b/libfusepp/fuseAppBase.cpp index 4e34192..a1ea491 100644 --- a/libfusepp/fuseAppBase.cpp +++ b/libfusepp/fuseAppBase.cpp @@ -184,7 +184,7 @@ int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_inf } int FuseAppBase::onError(const std::exception & e) throw() { - fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); + fprintf(stderr, "Unknown exception (what: %s)\n", e.what()); return -ENOSYS; } -- cgit v1.2.3 From 2e7664168dcf66a1653d2dab6687fd8714033a79 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 00:39:33 +0000 Subject: Tear down adapter on daemon destruction --- netfs/daemon/daemon.cpp | 5 +++++ netfs/daemon/daemon.h | 1 + 2 files changed, 6 insertions(+) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index cf312bb..b5a2ddd 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -13,6 +13,11 @@ NetFSDaemon::NetFSDaemon(const Ice::CommunicatorPtr & i) : { } +NetFSDaemon::~NetFSDaemon() +{ + adapter->deactivate(); +} + std::string NetFSDaemon::hostname() { diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h index 8cf4d4a..7ed5cb4 100644 --- a/netfs/daemon/daemon.h +++ b/netfs/daemon/daemon.h @@ -10,6 +10,7 @@ class NetFSDaemon : public IceBox::Service { public: NetFSDaemon(const Ice::CommunicatorPtr &); + virtual ~NetFSDaemon(); virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override; virtual void stop() override; -- cgit v1.2.3 From 3523abccb5104d27725e092103b43d75fa2b90d3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:14:04 +0000 Subject: Virtualise fues_main so that the ut framework can get access to the operations map --- libfusepp/fuseAppBase.h | 3 ++- netfs/fuse/netfs.cpp | 6 ++++++ netfs/unittests/testCore.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libfusepp/fuseAppBase.h b/libfusepp/fuseAppBase.h index 73a809a..d76fbff 100644 --- a/libfusepp/fuseAppBase.h +++ b/libfusepp/fuseAppBase.h @@ -57,6 +57,7 @@ class FuseAppBase { virtual int onError(const std::exception & err) throw(); virtual int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc) = 0; + virtual int main(int &, char **, const struct fuse_operations *) = 0; #define GetHelper(func) getHelper<&FuseAppBase::func>(typeid(&FuseAppBase::func) != typeid(&FuseApp::func)) template @@ -121,7 +122,7 @@ class FuseAppBase { #endif #endif }; - return fuse_main(args.argc, args.argv, &operations, fa); + return fa->main(args.argc, args.argv, &operations); } struct fuse_args runint(int &, char ** &); diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp index 21689f2..f700a74 100644 --- a/netfs/fuse/netfs.cpp +++ b/netfs/fuse/netfs.cpp @@ -13,6 +13,12 @@ class FuseImpl : public NetFS::FuseApp { { return ::fuse_opt_parse(args, data, opts, proc); } + + int main(int & argc, char ** argv, const struct fuse_operations * ops) override + { + return ::fuse_main(argc, argv, ops, this); + } + }; int diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 2262444..3be4ed0 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -56,6 +56,12 @@ class FuseMock : public NetFS::FuseApp { return 0; } + int main(int &, char **, const struct fuse_operations * o) override + { + o->init(NULL); + return 0; + } + protected: virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override { @@ -86,8 +92,7 @@ class Core { ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; - fuse->runint(argc, a); - fuse->init(NULL); + FuseAppBase::run(argc, a, fuse); } ~Core() -- cgit v1.2.3 From 74bdd300cb43aef4f8d3898eecdf20c58d5bf26d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:16:34 +0000 Subject: Initialise the test context with sensible values --- netfs/unittests/testCore.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 3be4ed0..c1afbe3 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -41,6 +41,9 @@ class FuseMock : public NetFS::FuseApp { NetFS::FuseApp(argc, argv) { ::memset(&context, 0, sizeof(fuse_context)); + context.pid = getpid(); + context.uid = getuid(); + context.gid = getgid(); } struct fuse_context * fuse_get_context() override -- cgit v1.2.3 From 161b1e5f69a9bf2b1ec7480ea439405c3597976c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:17:54 +0000 Subject: Keep a copy of fuse operations map --- netfs/unittests/testCore.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index c1afbe3..0f74925 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -62,9 +62,12 @@ class FuseMock : public NetFS::FuseApp { int main(int &, char **, const struct fuse_operations * o) override { o->init(NULL); + ops = *o; return 0; } + fuse_operations ops; + protected: virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override { -- cgit v1.2.3 From 0e8a82f89a5293411cb877deb87703a352f8e421 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Feb 2015 01:19:36 +0000 Subject: Refactor mocked stuff in wrappers for easy setup/teardown and expose the fuse operations map instead of the app instance --- netfs/unittests/testCore.cpp | 72 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 0f74925..495c5a7 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -35,6 +35,35 @@ class MockDaemon : public NetFSDaemon { } }; +class MockDaemonHost { + public: + MockDaemonHost() : + params({}), + ic(Ice::initialize(params)), + daemon(new MockDaemon(ic)) + { + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon->start("NetFSDaemonAdapter", ic, {}); + + } + + ~MockDaemonHost() + { + delete daemon; + ic->destroy(); + } + + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon * daemon; +}; +typedef boost::shared_ptr MockDaemonHostPtr; + +char * argv[] = { + strdup((RootDir / ":testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + class FuseMock : public NetFS::FuseApp { public: FuseMock(int & argc, char ** argv) : @@ -81,39 +110,38 @@ class FuseMock : public NetFS::FuseApp { fuse_context context; }; -char * argv[] = { - strdup((RootDir / ":testvol").string().c_str()), - strdup((RootDir / "test").string().c_str()) -}; - -class Core { +class FuseMockHost { public: - Core() : - params({}), - ic(Ice::initialize(params)), - daemon(new MockDaemon(ic)), + FuseMockHost() : argc(2), - fuse(new FuseMock(argc, argv)) + app(new FuseMock(argc, argv)), + fuse(&app->ops) { - ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); - daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; - FuseAppBase::run(argc, a, fuse); + FuseAppBase::run(argc, a, app); } - ~Core() + int argc; + FuseMock * app; + fuse_operations * fuse; +}; + +class Core { + public: + Core() : + ic(daemonHost.ic), + daemon(daemonHost.daemon), + fuse(fuseHost.fuse) { - delete fuse; - delete daemon; - ic->destroy(); } protected: - Ice::StringSeq params; + MockDaemonHost daemonHost; + FuseMockHost fuseHost; + Ice::CommunicatorPtr ic; - NetFSDaemon * daemon; - int argc; - FuseAppBase * fuse; + NetFSDaemon * const daemon; + fuse_operations * fuse;; }; BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) -- cgit v1.2.3 From 997f3c025f09de9912640f22ed236d0e74794211 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Feb 2015 15:27:47 +0000 Subject: Fix exception throwing on invalid fs proxy --- netfs/fuse/fuseApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index d579271..c90cc15 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -104,7 +104,7 @@ NetFS::FuseApp::connectToVolume() } volume = service->connect(e->second->ExportName, "bar"); if (!volume) { - throw "Invalid filesystem proxy"; + throw std::runtime_error("Invalid filesystem proxy"); } } } -- cgit v1.2.3 From 382659a30d8ace7e01fe1a90abf4b43b90663da3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Feb 2015 15:29:44 +0000 Subject: Add a test over reconnecting to daemon following a restart with open files --- netfs/unittests/testCore.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 495c5a7..ba330cd 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -167,3 +167,46 @@ BOOST_AUTO_TEST_CASE ( clientInitialised ) BOOST_AUTO_TEST_SUITE_END(); + +BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) +{ + MockDaemonHostPtr daemon(new MockDaemonHost()); + FuseMockHost fuse; + + struct statvfs s; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + + const char * fileName = "/createMe"; + BOOST_CHECKPOINT("Create a new file"); + struct fuse_file_info fh; + memset(&fh, 0, sizeof(fh)); + fh.flags = O_WRONLY | O_CREAT | O_APPEND; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->create(fileName, 0100644, &fh)); + BOOST_REQUIRE(fh.fh); + + BOOST_CHECKPOINT("Fetch file attributes"); + struct stat st; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + BOOST_REQUIRE_EQUAL(st.st_size, 0); + BOOST_REQUIRE_EQUAL(st.st_uid, getuid()); + BOOST_REQUIRE_EQUAL(st.st_gid, getgid()); + + BOOST_CHECKPOINT("Write some data"); + char someData[890]; + BOOST_REQUIRE_EQUAL(sizeof(someData), fuse.fuse->write(fileName, someData, sizeof(someData), 0, &fh)); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + BOOST_REQUIRE_EQUAL(st.st_size, sizeof(someData)); + + BOOST_CHECKPOINT("Delete old daemon object"); + daemon.reset(); + BOOST_CHECKPOINT("Create new daemon object"); + daemon = MockDaemonHostPtr(new MockDaemonHost()); + + BOOST_CHECKPOINT("Fetch file attributes again"); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + + BOOST_CHECKPOINT("Close file"); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); +} + -- cgit v1.2.3 From 88f0c774c88237eaf82124cc1fc4f012697eb9e4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Mar 2015 20:04:24 +0000 Subject: Refactor to avoid possible destructed string copy --- netfs/daemon/daemon.cpp | 4 ++-- netfs/daemon/daemonFile.cpp | 2 +- netfs/daemon/daemonVolume.cpp | 2 +- netfs/fuse/fuseApp.cpp | 5 ++++- netfs/fuse/fuseDirs.cpp | 2 +- netfs/fuse/fuseFiles.cpp | 2 +- netfs/fuse/fuseMisc.cpp | 2 +- netfs/ice/typeConvert.cpp | 8 ++++---- netfs/ice/typeConvert.h | 8 ++++---- netfs/lib/entCache.cpp | 16 +++++++++------- netfs/lib/entCache.h | 4 ++-- 11 files changed, 30 insertions(+), 25 deletions(-) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index b5a2ddd..3ad6294 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -76,8 +76,8 @@ extern "C" { } TempPrivs::TempPrivs(const NetFS::ReqEnv & re, const boost::filesystem::path & r) : - myu(UserEntCache::instance.getID(re.user)), - myg(GroupEntCache::instance.getID(re.grp)), + myu(UserEntCache::instance.getEntry(re.user)->id), + myg(GroupEntCache::instance.getEntry(re.grp)->id), root(r) { } diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index 3268be8..3acd1ca 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -36,7 +36,7 @@ FileServer::fgetattr(const NetFS::ReqEnv & re, const Ice::Current &) throw NetFS::SystemError(errno); } NetFS::Attr a; - a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1) }; + a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1, _2) }; return a; } diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 0cad47e..0556d9a 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -70,7 +70,7 @@ VolumeServer::getattr(const NetFS::ReqEnv & re, const std::string & path, const throw NetFS::SystemError(errno); } NetFS::Attr a; - a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1) }; + a << StatSource { s, boost::bind(&UserEntCache::getName, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getName, &GroupEntCache::instance, _1, _2) }; return a; } diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index c90cc15..fdcce57 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -171,6 +171,9 @@ NetFS::FuseApp::reqEnv() connectToService(); connectToVolume(); struct fuse_context * c = fuse_get_context(); - return { UserEntCache::instance.getName(c->uid), GroupEntCache::instance.getName(c->gid) }; + NetFS::ReqEnv re; + UserEntCache::instance.getName(c->uid, &re.user); + GroupEntCache::instance.getName(c->gid, &re.grp); + return re; } diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index 156dae6..1da9484 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -79,7 +79,7 @@ NetFS::FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_ statCache.Add(new OptimisticCallCacheable( [asga,this]() { struct stat s; - s << AttrSource { volume->end_getattr(asga), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1) }; + s << AttrSource { volume->end_getattr(asga), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1, _2) }; return s; }, epath, time_t(NULL) + 2)); } diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index b8399f0..c6d4283 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -135,7 +135,7 @@ NetFS::FuseApp::fgetattr(const char *, struct stat * s, fuse_file_info * fi) { try { auto remote = getFileProxy(fi->fh)->remote; - *s << AttrSource { remote->fgetattr(reqEnv()), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1) }; + *s << AttrSource { remote->fgetattr(reqEnv()), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1, _2) }; return 0; } catch (NetFS::SystemError & e) { diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 670c9ae..1f999bd 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -19,7 +19,7 @@ NetFS::FuseApp::getattr(const char * p, struct stat * s) *s = *cacehedStat; } else { - *s << AttrSource { volume->getattr(reqEnv(), p), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1) }; + *s << AttrSource { volume->getattr(reqEnv(), p), boost::bind(&UserEntCache::getID, &UserEntCache::instance, _1, _2), boost::bind(&GroupEntCache::getID, &GroupEntCache::instance, _1, _2) }; } return 0; } diff --git a/netfs/ice/typeConvert.cpp b/netfs/ice/typeConvert.cpp index 538b894..cc3ee93 100644 --- a/netfs/ice/typeConvert.cpp +++ b/netfs/ice/typeConvert.cpp @@ -7,8 +7,8 @@ operator<<(struct stat & s, const AttrSource & a) s.st_ino = a.attr.inode; s.st_mode = a.attr.mode; s.st_nlink = a.attr.links; - s.st_uid = a.user(a.attr.uid); - s.st_gid = a.group(a.attr.gid); + a.user(a.attr.uid, &s.st_uid); + a.group(a.attr.gid, &s.st_gid); s.st_rdev = a.attr.rdev; s.st_size = a.attr.size; s.st_blksize = a.attr.blockSize; @@ -41,8 +41,8 @@ operator<<(NetFS::Attr & a, const struct StatSource & s) a.inode = s.stat.st_ino; a.mode = s.stat.st_mode; a.links = s.stat.st_nlink; - a.uid = s.user(s.stat.st_uid); - a.gid = s.group(s.stat.st_gid); + s.user(s.stat.st_uid, &a.uid); + s.group(s.stat.st_gid, &a.gid); a.rdev = s.stat.st_rdev; a.size = s.stat.st_size; a.blockSize = s.stat.st_blksize; diff --git a/netfs/ice/typeConvert.h b/netfs/ice/typeConvert.h index dd56a3f..13e2b44 100644 --- a/netfs/ice/typeConvert.h +++ b/netfs/ice/typeConvert.h @@ -3,11 +3,11 @@ #include #include -typedef boost::function UserIdLookup; -typedef boost::function GroupIdLookup; +typedef boost::function UserIdLookup; +typedef boost::function GroupIdLookup; -typedef boost::function UserNameLookup; -typedef boost::function GroupNameLookup; +typedef boost::function UserNameLookup; +typedef boost::function GroupNameLookup; struct AttrSource { const NetFS::Attr & attr; diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index b07dda7..286c017 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -17,17 +17,19 @@ EntCache::~EntCache() } template -const typename EntCache::id_t & -EntCache::getID(const EntCache::name_t & u) const +void +EntCache::getID(const EntCache::name_t & u, EntCache::id_t * target) const { - return getEntry(u)->id; + auto e = getEntry(u); + *target = e->id; } template -const typename EntCache::name_t & -EntCache::getName(const EntCache::id_t & u) const +void +EntCache::getName(const EntCache::id_t & u, EntCache::name_t * target) const { - return getEntry(u)->name; + auto e = getEntry(u); + *target = e->name; } template @@ -107,7 +109,7 @@ EntCache::fillCache() const auto g = new Group(grp->gr_gid, grp->gr_name); for (auto member = grp->gr_mem; *member; member++) { try { - g->members.insert(EntCache::instance.getID(*member)); + g->members.insert(EntCache::instance.getEntry((const name_t &)*member)->id); } catch (const NetFS::SystemError &) { } diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index ea941e8..443474f 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -38,8 +38,8 @@ class EntCache { virtual ~EntCache(); - const id_t & getID(const name_t & ) const; - const name_t & getName(const id_t &) const; + void getID(const name_t &, id_t *) const; + void getName(const id_t &, name_t *) const; template entry_ptr getEntry(const key_t &) const; -- cgit v1.2.3 From 799cd0410bc2c4180876b96a0c2fc179c6ca114a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 6 May 2015 21:15:07 +0100 Subject: Move sandbox setup/teardown into a global fixture. --- netfs/unittests/testCore.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index ba330cd..1fc1817 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -144,13 +144,22 @@ class Core { fuse_operations * fuse;; }; -BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) +class GlobalSandBox { + public: + GlobalSandBox() + { + boost::filesystem::remove_all(TestExportRoot); + boost::filesystem::create_directories(TestExportRoot); + } + ~GlobalSandBox() + { + boost::filesystem::remove_all(TestExportRoot); + } +}; -BOOST_AUTO_TEST_CASE ( initializeSandbox ) -{ - boost::filesystem::remove_all(TestExportRoot); - boost::filesystem::create_directories(TestExportRoot); -} +BOOST_GLOBAL_FIXTURE(GlobalSandBox); + +BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) BOOST_AUTO_TEST_CASE ( daemonInitialised ) { -- cgit v1.2.3